Skip to content

Commit

Permalink
Adjust chibi editor, add orphan item dialog, add bgm names to Display…
Browse files Browse the repository at this point in the history
…Name, add child item counts in tree (#41)
  • Loading branch information
WiIIiam278 authored Feb 22, 2023
1 parent 27797a3 commit 6e8950f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 114 deletions.
1 change: 1 addition & 0 deletions src/SerialLoops.Lib/Items/BackgroundMusicItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public BackgroundMusicItem(string bgmFile, int index, ExtraFile extras, Project
BgmFile = bgmFile;
Index = index;
BgmName = extras.Bgms.FirstOrDefault(b => b.Index == Index).Name ?? "";
DisplayName = string.IsNullOrEmpty(BgmName) ? Name : BgmName;
PopulateScriptUses(project);
}

Expand Down
10 changes: 0 additions & 10 deletions src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,5 @@ public List<ItemDescription> GetReferencesTo(Project project)
}
}

public List<ItemDescription> GetReferencedBy(Project project)
{
List<ItemDescription> references = new();

switch (Type)
{
default:
return references;
}
}
}
}
16 changes: 1 addition & 15 deletions src/SerialLoops/Controls/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public ItemContextMenu(Project project, ItemExplorerPanel explorer, EditorTabsPa
Command findReferences = new();
findReferences.Executed += FindReferences_OnClick;
Items.Add(new ButtonMenuItem { Text = "Find References...", Command = findReferences });

Command findReferencedBy = new();
findReferencedBy.Executed += FindReferencedBy_OnClick;
Items.Add(new ButtonMenuItem { Text = "Find Referenced By...", Command = findReferencedBy });
}

private void OpenCommand_OnClick(object sender, EventArgs args)
Expand All @@ -50,21 +46,11 @@ private void OpenCommand_OnClick(object sender, EventArgs args)
}

private void FindReferences_OnClick(object sender, EventArgs args)
{
ShowReferences(ReferenceDialog.ReferenceMode.REFERENCES_TO);
}

private void FindReferencedBy_OnClick(object sender, EventArgs args)
{
ShowReferences(ReferenceDialog.ReferenceMode.REFERENCED_BY);
}

private void ShowReferences(ReferenceDialog.ReferenceMode mode)
{
ItemDescription item = _project.FindItem(_explorer.Viewer.SelectedItem?.Text);
if (item != null)
{
ReferenceDialog referenceDialog = new(item, mode, _project, _explorer, _tabs, _log);
ReferencesDialog referenceDialog = new(item, _project, _explorer, _tabs, _log);
referenceDialog.ShowModal(_explorer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/Controls/ItemResultsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SerialLoops.Controls
public class ItemResultsPanel : ItemListPanel
{
public FindItemsDialog Dialog;
public ItemResultsPanel(List<ItemDescription> results, ILogger log) : base(results, new Size(280, 185), true, log) { }
public ItemResultsPanel(List<ItemDescription> results, ILogger log, bool expandItems = true) : base(results, new Size(280, 185), expandItems, log) { }

protected override void ItemList_ItemClicked(object sender, EventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/Controls/SectionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class SectionTreeItem : List<SectionTreeItem>, ITreeGridItem<SectionTreeI
{
public Section Section { get; private set; }
public Icon SectionIcon => Section.SectionIcon;
public string Text => Section.Text;
public string Text => Count > 1 ? $"{Section.Text} ({Count})" : Section.Text;
public bool Expanded { get; set; }
public bool Expandable => Count > 0;
public ITreeGridItem Parent { get; set; }
Expand Down
13 changes: 3 additions & 10 deletions src/SerialLoops/Editors/ChibiEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using SerialLoops.Lib.Items;
using SerialLoops.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;

namespace SerialLoops.Editors
{
Expand All @@ -25,11 +23,7 @@ public ChibiEditor(ChibiItem chibi, ILogger log) : base(chibi, log)
public override Container GetEditorPanel()
{
_chibi = (ChibiItem)Description;

TableRow row = new(GetAnimationEditor(), GetChibiSelector());
row.ScaleHeight = false;

return new TableLayout(row);
return new TableLayout(GetAnimationEditor(), GetChibiSelector());
}

private Container GetChibiSelector()
Expand All @@ -49,7 +43,7 @@ private Container GetChibiSelector()

return new TableLayout
{
Width = 200,
Height = 250,
Padding = 10,
Rows =
{
Expand All @@ -76,8 +70,7 @@ private Container GetAnimationEditor()

_framesStack = new() {
Orientation = Orientation.Horizontal,
Spacing = 15,
MinimumSize = new(300, 100)
Spacing = 15
};
UpdateFramesStack();

Expand Down
87 changes: 87 additions & 0 deletions src/SerialLoops/ItemReferenceDialogs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Eto.Drawing;
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Controls;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System.Collections.Generic;
using System.Linq;

namespace SerialLoops
{
public class ReferencesDialog : FindItemsDialog
{
public ItemDescription Item;

public ReferencesDialog(ItemDescription item, Project project, ItemExplorerPanel explorer, EditorTabsPanel tabs, ILogger log)
{
Item = item;
Project = project;
Explorer = explorer;
Tabs = tabs;
Log = log;
InitializeComponent();
}

private void InitializeComponent()
{
Title = $"References to {Item.DisplayName}";
MinimumSize = new Size(400, 275);
Padding = 10;

List<ItemDescription> results = Item.GetReferencesTo(Project);
Content = new StackLayout
{
Orientation = Orientation.Vertical,
HorizontalContentAlignment = HorizontalAlignment.Center,
Spacing = 10,
Padding = 10,
Items =
{
$"{results.Count} items that reference {Item.Name}:",
new ItemResultsPanel(results, Log) { Dialog = this }
}
};
}

}

public class OrphanedItemsDialog : FindItemsDialog
{
private static readonly ItemDescription.ItemType[] IGNORED_ORPHAN_TYPES = {
ItemDescription.ItemType.Scenario,
ItemDescription.ItemType.Dialogue_Config
};

public OrphanedItemsDialog(Project project, ItemExplorerPanel explorer, EditorTabsPanel tabs, ILogger log)
{
Project = project;
Explorer = explorer;
Tabs = tabs;
Log = log;
InitializeComponent();
}

private void InitializeComponent()
{
Title = "Orphaned Items";
MinimumSize = new Size(400, 275);
Padding = 10;

List<ItemDescription> results = Project.Items.FindAll(i => !IGNORED_ORPHAN_TYPES.Contains(i.Type) && i.GetReferencesTo(Project).Count == 0);
Content = new StackLayout
{
Orientation = Orientation.Vertical,
HorizontalContentAlignment = HorizontalAlignment.Center,
Spacing = 10,
Padding = 10,
Items =
{
$"{results.Count} items found that are not referenced by other items:",
new ItemResultsPanel(results, Log, false) { Dialog = this }
}
};
}
}

}
29 changes: 28 additions & 1 deletion src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void InitializeComponent()
Command searchProject = new() { MenuText = "Search", ToolBarText = "Search", Shortcut = Application.Instance.CommonModifier | Keys.F, Image = ControlGenerator.GetIcon("Search", _log) };
searchProject.Executed += Search_Executed;

Command findOrphanedItems = new() { MenuText = "Find Orphaned Items" };
findOrphanedItems.Executed += FindOrphanedItems_Executed;

// Build
Command buildIterativeProject = new() { MenuText = "Build", ToolBarText = "Build", Image = ControlGenerator.GetIcon("Build", _log) };
buildIterativeProject.Executed += BuildIterativeProject_Executed;
Expand All @@ -78,7 +81,7 @@ void InitializeComponent()
{
// File submenu
new SubMenuItem { Text = "&File", Items = { newProject, openProject, _recentProjects, saveProject } },
new SubMenuItem { Text = "&Tools", Items = { searchProject } },
new SubMenuItem { Text = "&Tools", Items = { searchProject, findOrphanedItems } },
// new SubMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
// new SubMenuItem { Text = "&View", Items = { /* commands/items */ } },
new SubMenuItem { Text = "&Build", Items = { buildIterativeProject, buildBaseProject, buildAndRunProject } },
Expand Down Expand Up @@ -271,6 +274,30 @@ private void Search_Executed(object sender, EventArgs e)
}
}

private void FindOrphanedItems_Executed(object sender, EventArgs e)
{
if (OpenProject is not null)
{
OrphanedItemsDialog orphanedItemsDialog = null;
LoopyProgressTracker tracker = new("");
((IProgressTracker)tracker).Focus("Finding orphaned items...", 1);

ProgressDialog _ = new(() =>
{
Application.Instance.Invoke(() =>
{
orphanedItemsDialog = new(OpenProject, ItemExplorer, EditorTabs, _log);
tracker.Finished++;
});
}, () => {
Application.Instance.Invoke(() =>
{
orphanedItemsDialog?.ShowModal(this);
});
}, tracker, "Finding orphaned items");
}
}

private void BuildIterativeProject_Executed(object sender, EventArgs e)
{
if (OpenProject is not null)
Expand Down
15 changes: 0 additions & 15 deletions src/SerialLoops/ReferenceDialog.cs

This file was deleted.

58 changes: 0 additions & 58 deletions src/SerialLoops/ReferenceDialog.eto.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/SerialLoops/SerialLoops.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
</ItemGroup>

<ItemGroup>
<Compile Update="ReferenceDialog.eto.cs">
<DependentUpon>$([System.String]::Copy('%(Filename)').Replace('.eto', ''))%(Extension)</DependentUpon>
</Compile>
<Compile Update="SearchDialog.eto.cs">
<DependentUpon>$([System.String]::Copy('%(Filename)').Replace('.eto', ''))%(Extension)</DependentUpon>
</Compile>
Expand Down

0 comments on commit 6e8950f

Please sign in to comment.