Skip to content

Commit

Permalink
Make icons display in tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 committed Feb 1, 2023
1 parent a8daa03 commit c0cce27
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;

namespace SerialLoops.Lib
{
Expand Down
18 changes: 9 additions & 9 deletions src/SerialLoops/EditorTabsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Eto.Drawing;
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Editors;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;
using System.Linq;
using System.Reflection;

namespace SerialLoops
{
Expand Down Expand Up @@ -46,12 +48,10 @@ void InitializeComponent()

public static Icon GetItemIcon(ItemDescription.ItemType type)
{
//todo battle with this and figure out loading from a resx?
//return Icon.FromResource($"SerialLoops.Icons.{type}.png", Assembly.GetExecutingAssembly());
throw new NotImplementedException();
return Icon.FromResource($"SerialLoops.Icons.{type}.png", Assembly.GetExecutingAssembly()).WithSize(16, 16);
}

internal void OpenTab(ItemDescription item)
internal void OpenTab(ItemDescription item, ILogger log)
{
// If a tab page with the name and type exists, switch to it
foreach (DocumentPage page in Tabs.Pages)
Expand All @@ -64,22 +64,22 @@ internal void OpenTab(ItemDescription item)
}

// Open a new editor for the item -- This is where the item can be loaded from the project files
DocumentPage newPage = CreateTab(item, _project);
DocumentPage newPage = CreateTab(item, _project, log);
Tabs.Pages.Add(newPage);
Tabs.SelectedPage = newPage;

}

internal static DocumentPage CreateTab(ItemDescription item, Project project)
internal static DocumentPage CreateTab(ItemDescription item, Project project, ILogger log)
{
switch (item.Type)
{
case ItemDescription.ItemType.Background:
return new BackgroundEditor((BackgroundItem)project.Items.First(i => i.Name == item.Name));
return new BackgroundEditor((BackgroundItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Map:
return new MapEditor((MapItem)project.Items.First(i => i.Name == item.Name));
return new MapEditor((MapItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Event:
return new EventEditor((EventItem)project.Items.First(i => i.Name == item.Name));
return new EventEditor((EventItem)project.Items.First(i => i.Name == item.Name), log);
default:
throw new ArgumentException("Invalid item type");
}
Expand Down
11 changes: 3 additions & 8 deletions src/SerialLoops/Editors/BackgroundEditor.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using Eto.Drawing;
using Eto.Forms;
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Editors
{
public class BackgroundEditor : Editor
{
public BackgroundEditor(BackgroundItem item) : base(item)
public BackgroundEditor(BackgroundItem item, ILogger log) : base(item, log)
{
}

Expand Down
16 changes: 13 additions & 3 deletions src/SerialLoops/Editors/Editor.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib.Items;
using System;

namespace SerialLoops.Editors
{
public abstract class Editor : DocumentPage
{

private ILogger _log;
public ItemDescription Description { get; private set; }

public Editor(ItemDescription description)
public Editor(ItemDescription description, ILogger log)
{
Description = description;
_log = log;
InitializeComponent();
}

void InitializeComponent()
{
Text = Description.Name;
MinimumSize = EditorTabsPanel.EDITOR_BASE_SIZE;
//Image = EditorTabsPanel.GetItemIcon(Description.Type);
try
{
Image = EditorTabsPanel.GetItemIcon(Description.Type);
}
catch (Exception exc)
{
_log.LogWarning($"Failed to load icon.\n{exc.Message}\n\n{exc.StackTrace}");
}
Padding = 10;

Panel panel = GetEditorPanel();
Expand Down
6 changes: 2 additions & 4 deletions src/SerialLoops/Editors/EventEditor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib.Items;

namespace SerialLoops.Editors
{
public class EventEditor : Editor
{
private EventItem _event;

public EventEditor(EventItem item) : base(item)
public EventEditor(EventItem item, ILogger log) : base(item, log)
{
_event = item;
}

public override Panel GetEditorPanel()
Expand Down
7 changes: 2 additions & 5 deletions src/SerialLoops/Editors/MapEditor.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib.Items;

namespace SerialLoops.Editors
{
public class MapEditor : Editor
{

private MapItem _map;

public MapEditor(MapItem map) : base(map)
public MapEditor(MapItem map, ILogger log) : base(map, log)
{
_map = map;
}

public override Panel GetEditorPanel()
Expand Down
File renamed without changes
8 changes: 5 additions & 3 deletions src/SerialLoops/ItemExplorerPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Eto.Drawing;
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;
Expand All @@ -9,15 +10,16 @@ namespace SerialLoops
{
public class ItemExplorerPanel : Scrollable
{

private ILogger _log;
public static readonly Size ITEM_EXPLORER_BASE_SIZE = new(200, 420);

private SectionListTreeGridView _items;
private readonly Project _project;
private readonly EditorTabsPanel _tabs;

public ItemExplorerPanel(Project project, EditorTabsPanel tabs)
public ItemExplorerPanel(Project project, EditorTabsPanel tabs, ILogger log)
{
_log = log;
_project = project;
_tabs = tabs;
InitializeComponent();
Expand Down Expand Up @@ -71,7 +73,7 @@ private void ItemList_ItemClicked(object sender, EventArgs e)
ItemDescription item = _project.FindItem(view.SelectedItem?.Text);
if (item != null)
{
_tabs.OpenTab(item);
_tabs.OpenTab(item, _log);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void InitializeComponent()
private void OpenProjectView(Project project)
{
EditorTabsPanel tabs = new(project);
ItemExplorerPanel items = new(project, tabs);
ItemExplorerPanel items = new(project, tabs, _log);
Title = $"{BASE_TITLE} - {project.Name}";
Content = new StackLayout
{
Expand Down
14 changes: 14 additions & 0 deletions src/SerialLoops/SerialLoops.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

</PropertyGroup>

<ItemGroup>
<None Remove="Icons\Event.png" />
<None Remove="Icons\Map.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Icons\Event.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Icons\Map.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup>
Expand Down
11 changes: 3 additions & 8 deletions test/SerialLoops.Tests/ItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using SerialLoops.Lib.Items;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SerialLoops.Tests
{
Expand All @@ -32,8 +30,7 @@ private static string[] EventFiles()
[Parallelizable(ParallelScope.All)]
public void EventItemCreationTest(string evtFile)
{
EventFile evt = new();
evt.Name = $"{Path.GetFileNameWithoutExtension(evtFile)}S";
EventFile evt = new() { Name = $"{Path.GetFileNameWithoutExtension(evtFile)}S" };
evt.Initialize(File.ReadAllBytes(evtFile), 0, _log);
EventItem eventItem = new(evt);

Expand All @@ -43,10 +40,8 @@ public void EventItemCreationTest(string evtFile)
[Test]
public void BackgroundItemCreationTest()
{
GraphicsFile grp1 = new();
GraphicsFile grp2 = new();
grp1.Name = "KBG00_128DNX";
grp2.Name = "KBG00BNS";
GraphicsFile grp1 = new() { Name = "KBG00_128DNX" };
GraphicsFile grp2 = new() { Name = "KBG00BNS" };
grp1.Initialize(File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inputs", "graphics", "KBG00_128.bin")), 0, _log);
grp2.Initialize(File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inputs", "graphics", "KBG00.bin")), 0, _log);
BackgroundItem item = new($"BG_{grp2.Name}") { Graphic1 = grp1, Graphic2 = grp2, BackgroundType = BgType.KINETIC_SCREEN };
Expand Down

0 comments on commit c0cce27

Please sign in to comment.