Skip to content

Commit

Permalink
Initial project editing UI/workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jan 31, 2023
1 parent 200c18b commit bd17f8c
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/SerialLoops.Lib/Items/DialogueItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
{
public class DialogueItem : Item
{
public DialogueItem(string name) : base(name, ItemType.Dialogue)
{
}

}
}
20 changes: 20 additions & 0 deletions src/SerialLoops.Lib/Items/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using SerialLoops.Lib.Items;

namespace SerialLoops.Lib.Items
{
public abstract class Item : ItemDescription
{

public Item(string name, ItemDescription.ItemType type) : base(name, type)
{
}

}

}
35 changes: 35 additions & 0 deletions src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
{
public class ItemDescription
{

public string Name { get; private set; }
public ItemType Type { get; private set; }

public ItemDescription(string name, ItemType type)
{
Name = name;
Type = type;
}

// Load an item from an ItemDescription
public Item Load()
{
throw new NotImplementedException();
}

// Enum with values for each type of item
public enum ItemType
{
Map,
Dialogue
}

}
}
16 changes: 16 additions & 0 deletions src/SerialLoops.Lib/Items/MapItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Lib.Items
{
public class MapItem : Item
{
public MapItem(string name) : base(name, ItemType.Map)
{
}

}
}
18 changes: 17 additions & 1 deletion src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using SerialLoops.Lib.Logging;
using SerialLoops.Lib.Items;
using SerialLoops.Lib.Logging;
using System;
using System.Collections.Generic;
using System.IO;

namespace SerialLoops.Lib
Expand Down Expand Up @@ -32,6 +34,20 @@ public Project(string name, Config config, ILogger log, bool createDirectories =
}
}

public List<ItemDescription> GetItems()
{
//todo Return list of items (representing editable project parts, like maps, etc)
List<ItemDescription> items = new()
{
new ItemDescription("map_1", ItemDescription.ItemType.Map),
new ItemDescription("map_2", ItemDescription.ItemType.Map),
new ItemDescription("dialogue_1", ItemDescription.ItemType.Dialogue),
new ItemDescription("dialogue_2", ItemDescription.ItemType.Dialogue),
new ItemDescription("dialogue_3", ItemDescription.ItemType.Dialogue)
};
return items;
}

public static Project OpenProject(string name, Config config, ILogger log)
{
Project project = new(name, config, log, createDirectories: false);
Expand Down
80 changes: 80 additions & 0 deletions src/SerialLoops/EditorTabsPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Eto.Drawing;
using Eto.Forms;
using SerialLoops.Editors;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SerialLoops
{
internal class EditorTabsPanel : Panel
{

public static readonly Size EDITOR_BASE_SIZE = new(500, 420);

public TabControl Tabs { get; private set; }

private readonly Project _project;

public EditorTabsPanel(Project project)
{
_project = project;
InitializeComponent();
}

void InitializeComponent()
{
MinimumSize = EDITOR_BASE_SIZE;
Padding = 0;

Tabs = new();
Content = new StackLayout
{
Orientation = Orientation.Vertical,
MinimumSize = EDITOR_BASE_SIZE,
Items =
{
Tabs
}
};
}

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();
}

internal void OpenTab(ItemDescription item)
{
// If a tab page with the name and type exists, switch to it
foreach (TabPage page in Tabs.Pages)
{
if (page.Text.Equals(item.Name))
{
Tabs.SelectedPage = page;
return;
}
}

// Open a new editor for the item -- This is where the item can be loaded from the project files
switch (item.Type)
{
case ItemDescription.ItemType.Map:
Tabs.Pages.Add(new MapEditor(new MapItem(item.Name)));
break;
case ItemDescription.ItemType.Dialogue:
Tabs.Pages.Add(new DialogueEditor(new DialogueItem(item.Name)));
break;
}
}
}
}
32 changes: 32 additions & 0 deletions src/SerialLoops/Editors/DialogueEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Eto.Forms;
using SerialLoops.Lib.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Editors
{
internal class DialogueEditor : Editor
{
private DialogueItem _item;

public DialogueEditor(DialogueItem item) : base(item)
{
_item = item;
}

public override Panel GetEditorPanel()
{
return new StackLayout
{
Orientation = Orientation.Vertical,
Items =
{
new Label { Text = "Dialogue Editor..todo" }
}
};
}
}
}
33 changes: 33 additions & 0 deletions src/SerialLoops/Editors/Editor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Eto.Forms;
using Eto.Drawing;
using SerialLoops.Lib.Items;

namespace SerialLoops.Editors
{
internal abstract class Editor : TabPage
{

public readonly ItemDescription Description;

public Editor(ItemDescription description)
{
Description = description;
InitializeComponent();
}

void InitializeComponent()
{
Text = Description.Name;
MinimumSize = EditorTabsPanel.EDITOR_BASE_SIZE;
//Image = EditorTabsPanel.GetItemIcon(Description.Type);
Padding = 10;

Panel panel = GetEditorPanel();
panel.MinimumSize = EditorTabsPanel.EDITOR_BASE_SIZE;
Content = panel;
}

public abstract Panel GetEditorPanel();

}
}
33 changes: 33 additions & 0 deletions src/SerialLoops/Editors/MapEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Eto.Forms;
using SerialLoops.Lib.Items;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SerialLoops.Editors
{
internal class MapEditor : Editor
{

private MapItem _item;

public MapEditor(MapItem map) : base(map)
{
_item = map;
}

public override Panel GetEditorPanel()
{
return new StackLayout
{
Orientation = Orientation.Vertical,
Items =
{
new Label { Text = "Map Editor..todo!" }
}
};
}
}
}
Binary file added src/SerialLoops/Icons/Dialogue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/SerialLoops/Icons/Map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions src/SerialLoops/ItemExplorerPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Eto.Drawing;
using Eto.Forms;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;

namespace SerialLoops
{
internal class ItemExplorerPanel : Scrollable
{

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

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

public ItemExplorerPanel(Project project, EditorTabsPanel tabs)
{
_project = project;
_tabs = tabs;
InitializeComponent();
}

void InitializeComponent()
{
MinimumSize = ITEM_EXPLORER_BASE_SIZE;
Padding = 0;

_items = new ListBox
{
Size = ITEM_EXPLORER_BASE_SIZE
};
_items.Activated += ItemList_ItemSelected;

Content = new StackLayout
{
Orientation = Orientation.Vertical,
Items =
{
_items
}
};

// Test items
foreach (ItemDescription item in _project.GetItems())
{
_items.Items.Add(item.Name);
}
}

private void ItemList_ItemSelected(object sender, EventArgs e)
{
if (_items.SelectedIndex != -1)
{
ItemDescription item = _project.GetItems()[_items.SelectedIndex];
_tabs.OpenTab(item);
}

}
}
}
Loading

0 comments on commit bd17f8c

Please sign in to comment.