Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display icons in tab headers, bump Eto SDK to 2.7.3 #5

Merged
merged 5 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- task: DotNetCoreCLI@2
inputs:
comand: 'test'
command: 'test'
projects: $(Build.SourcesDirectory)/test/SerialLoops.Tests/SerialLoops.Tests.csproj
publishTestResults: true
displayName: Run tests
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public enum ItemType
Chess,
Chibi,
Dialogue_Config,
Event,
Group_Selection,
Map,
Puzzle,
Scenario,
Script,
System_Texture,
Topic,
Transition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace SerialLoops.Lib.Items
{
public class EventItem : Item
public class ScriptItem : Item
{
public EventFile Event { get; set; }
public EventItem(string name) : base(name, ItemType.Event)
public ScriptItem(string name) : base(name, ItemType.Script)
{
}
public EventItem(EventFile evt) : base(evt.Name[0..^1], ItemType.Event)
public ScriptItem(EventFile evt) : base(evt.Name[0..^1], ItemType.Script)
{
Event = evt;
}
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -67,7 +66,7 @@ public void LoadArchives(ILogger log)

Items.AddRange(_evt.Files
.Where(e => !new string[] { "CHESSS", "EVTTBLS", "TOPICS", "SCENARIOS", "TUTORIALS", "VOICEMAPS" }.Contains(e.Name))
.Select(e => new EventItem(e)));
.Select(e => new ScriptItem(e)));
QMapFile qmap = _dat.Files.First(f => f.Name == "QMAPS").CastTo<QMapFile>();
Items.AddRange(_dat.Files
.Where(d => qmap.QMaps.Select(q => q.Name.Replace(".", "")).Contains(d.Name))
Expand Down
20 changes: 9 additions & 11 deletions src/SerialLoops/EditorTabsPanel.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.Editors;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
Expand Down Expand Up @@ -46,12 +47,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").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 +63,21 @@ 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));
case ItemDescription.ItemType.Event:
return new EventEditor((EventItem)project.Items.First(i => i.Name == item.Name));
return new MapEditor((MapItem)project.Items.First(i => i.Name == item.Name), log);
case ItemDescription.ItemType.Script:
return new ScriptEditor((ScriptItem)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
10 changes: 4 additions & 6 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
public class ScriptEditor : Editor
{
private EventItem _event;

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

public override Panel GetEditorPanel()
Expand All @@ -19,7 +17,7 @@ public override Panel GetEditorPanel()
Orientation = Orientation.Vertical,
Items =
{
new Label { Text = "Dialogue Editor..todo" }
new Label { Text = "Script Editor..todo" }
}
};
}
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
16 changes: 15 additions & 1 deletion src/SerialLoops/SerialLoops.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Eto.Forms/2.7.1">
<Project Sdk="Eto.Forms/2.7.3">

<!--
Set the BuildPlatform property to the Eto platform you wish to build for.
Expand All @@ -12,6 +12,20 @@

</PropertyGroup>

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

<ItemGroup>
<EmbeddedResource Include="Icons\Script.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
13 changes: 4 additions & 9 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,21 +30,18 @@ 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);
ScriptItem eventItem = new(evt);

Assert.That(evt.Name[0..^1], Is.EqualTo(eventItem.Name));
}

[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