Skip to content

Commit

Permalink
New icons for camera origin and pathing, new buttons for adding/remov…
Browse files Browse the repository at this point in the history
…ing commands/sections in scripts (#50)

Co-authored-by: jonko0493 <[email protected]>
  • Loading branch information
WiIIiam278 and jonko0493 authored Mar 28, 2023
1 parent ce950d1 commit 5668e55
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 34 deletions.
19 changes: 15 additions & 4 deletions src/SerialLoops.Lib/Items/MapItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ public SKBitmap GetMapImage(ArchiveFile<GraphicsFile> grp, bool displayPathingMa

if (displayMapStart)
{
SKBitmap icon;
SKPoint start;
if (Map.Settings.SlgMode)
{
SKPoint start = new(gridZero.X - Map.Settings.StartingPosition.x * 32 + Map.Settings.StartingPosition.y * 32, gridZero.Y + Map.Settings.StartingPosition.x * 16 + Map.Settings.StartingPosition.y * 16 + 16);
canvas.DrawCircle(start, 3, new SKPaint() { Color = SKColors.Pink });
start = new(gridZero.X - Map.Settings.StartingPosition.x * 32 + Map.Settings.StartingPosition.y * 32, gridZero.Y + Map.Settings.StartingPosition.x * 16 + Map.Settings.StartingPosition.y * 16 + 16);
icon = GetMapIcon("Origin_Point", 32);
}
else
{
SKPoint start = new(gridZero.X - Map.Settings.StartingPosition.x * 16 + Map.Settings.StartingPosition.y * 16, gridZero.Y + Map.Settings.StartingPosition.x * 8 + Map.Settings.StartingPosition.y * 8 + 8);
canvas.DrawCircle(start, 3, new SKPaint() { Color = SKColors.Pink });
start = new(gridZero.X - Map.Settings.StartingPosition.x * 16 + Map.Settings.StartingPosition.y * 16, gridZero.Y + Map.Settings.StartingPosition.x * 8 + Map.Settings.StartingPosition.y * 8 + 8);
icon = GetMapIcon("Origin_Point", 16);
}
canvas.DrawBitmap(icon, start);
}

canvas.Flush();
Expand Down Expand Up @@ -127,6 +130,14 @@ public void PopulateScriptUses(ArchiveFile<EventFile> evt)
ScriptUses = list.ToArray();
}

private static SKBitmap GetMapIcon(string name, int size)
{
SKBitmap icon = new(size, size);
SKImage image = SKImage.FromEncodedData($"MapIcons/{name}.png");
SKBitmap.FromImage(image).ScalePixels(icon, SKFilterQuality.Medium);
return icon;
}

public override void Refresh(Project project)
{
PopulateScriptUses(project.Evt);
Expand Down
Binary file added src/SerialLoops.Lib/MapIcons/Origin_Point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 27 additions & 5 deletions src/SerialLoops.Lib/Script/ScriptItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
using System.Collections.Generic;
using System.Linq;
using static HaruhiChokuretsuLib.Archive.Event.EventFile;
using static SerialLoops.Lib.Script.Parameters.BgmModeScriptParameter;
using static SerialLoops.Lib.Script.Parameters.BgScrollDirectionScriptParameter;
using static SerialLoops.Lib.Script.Parameters.ChibiEmoteScriptParameter;
using static SerialLoops.Lib.Script.Parameters.ChibiEnterExitScriptParameter;
using static SerialLoops.Lib.Script.Parameters.ColorMonochromeScriptParameter;
using static SerialLoops.Lib.Script.Parameters.EpisodeHeaderScriptParameter;
using static SerialLoops.Lib.Script.Parameters.PaletteEffectScriptParameter;
using static SerialLoops.Lib.Script.Parameters.ScreenScriptParameter;
using static SerialLoops.Lib.Script.Parameters.SfxModeScriptParameter;
using static SerialLoops.Lib.Script.Parameters.SpriteEntranceScriptParameter;
using static SerialLoops.Lib.Script.Parameters.SpriteExitScriptParameter;
using static SerialLoops.Lib.Script.Parameters.SpriteShakeScriptParameter;
using static SerialLoops.Lib.Script.Parameters.TextEntranceEffectScriptParameter;
using static SerialLoops.Lib.Script.Parameters.TransitionScriptParameter;

namespace SerialLoops.Lib.Script
{
Expand All @@ -20,8 +34,7 @@ public class ScriptItemCommand
public ScriptSection Section { get; set; }
public EventFile Script { get; set; }
public int Index { get; set; }

private Project _project;
public Project Project { get; set; }

public static ScriptItemCommand FromInvocation(ScriptCommandInvocation invocation, ScriptSection section, int index, EventFile eventFile, Project project)
{
Expand All @@ -32,7 +45,7 @@ public static ScriptItemCommand FromInvocation(ScriptCommandInvocation invocatio
Section = section,
Index = index,
Script = eventFile,
_project = project,
Project = project,
};
}

Expand Down Expand Up @@ -499,6 +512,7 @@ private static List<ScriptParameter> GetScriptParameters(ScriptCommandInvocation
break;
case CommandVerb.CHESS_LOAD:
if (i == 0)

{
parameters.Add(new ChessFileScriptParameter("Chess File", parameter));
}
Expand Down Expand Up @@ -565,12 +579,14 @@ private static List<ScriptParameter> GetScriptParameters(ScriptCommandInvocation
break;
case CommandVerb.EPHEADER:
if (i == 0)

{
parameters.Add(new EpisodeHeaderScriptParameter("Episode Header", parameter));
}
break;
case CommandVerb.CONFETTI:
if (i == 0)

{
parameters.Add(new BoolScriptParameter("Visible?", parameter == 1));
}
Expand Down Expand Up @@ -614,7 +630,7 @@ public override string ToString()
string str = $"{Verb}";
if (Verb == CommandVerb.DIALOGUE)
{
str += $" {((DialogueScriptParameter)Parameters[0]).Line.Text.GetSubstitutedString(_project)[0..Math.Min(((DialogueScriptParameter)Parameters[0]).Line.Text.Length, 10)]}...";
str += $" {((DialogueScriptParameter)Parameters[0]).Line.Text.GetSubstitutedString(Project)[0..Math.Min(((DialogueScriptParameter)Parameters[0]).Line.Text.Length, 10)]}...";
}
else if (Verb == CommandVerb.GOTO)
{
Expand All @@ -632,6 +648,11 @@ private static DialogueLine GetDialogueLine(short index, EventFile eventFile)
return eventFile.DialogueLines[index];
}

private static DialogueLine CreateDialogueLine(EventFile eventFile)
{
return eventFile.DialogueLines[0]; // todo
}

public ScriptItemCommand Clone()
{
return new()
Expand All @@ -640,8 +661,9 @@ public ScriptItemCommand Clone()
Parameters = Parameters.Select(p => p.Clone()).ToList(),
Section = Section,
Index = Index,
_project = _project,
Project = Project,
};
}

}
}
10 changes: 8 additions & 2 deletions src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HaruhiChokuretsuLib" Version="0.22.1" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.23.6" />
<PackageReference Include="NitroPacker.Core" Version="2.0.1" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
</ItemGroup>
Expand All @@ -18,4 +18,10 @@
</None>
</ItemGroup>

</Project>
<ItemGroup>
<EmbeddedResource Include="MapIcons\*.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/SerialLoops/Controls/ScriptCommandListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ void InitializeComponent()
}
_editor.UpdateTabTitle(false);
};
Viewer.AddCommand += (o, e) =>
{
// todo
};
}

private IEnumerable<ScriptCommandSectionEntry> GetSections()
Expand Down
41 changes: 36 additions & 5 deletions src/SerialLoops/Controls/ScriptCommandSectionTree.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Eto.Drawing;
using Eto.Forms;
using HaruhiChokuretsuLib.Archive.Event;
using SerialLoops.Lib.Items;
using SerialLoops.Lib.Script;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class ScriptCommandSectionTreeGridView : SectionList
private ScriptCommandSectionTreeItem _cursorItem;
public event EventHandler RepositionCommand;
public event EventHandler DeleteCommand;
public event EventHandler AddCommand;
public override Control Control => _treeView;

public override void Focus()
Expand Down Expand Up @@ -202,24 +204,53 @@ internal void DeleteItem(ScriptCommandSectionTreeItem item)
parent.Remove(item);
DeleteCommand?.Invoke(this, EventArgs.Empty);
_treeView.DataStore = _treeView.DataStore;
if (newIndex >= parent.Count)
{
newIndex = parent.Count - 1;
}
if (newIndex < 0) return;
_treeView.SelectedItem = parent[newIndex];
}

internal void AddItem(ScriptCommandSectionTreeItem item)
{
if (SelectedCommandTreeItem is null) return;
if (SelectedCommandTreeItem.Parent is not ScriptCommandSectionTreeItem parent) return;
var index = parent.IndexOf(SelectedCommandTreeItem);
if (index == -1) return;
parent.Insert(index + 1, item);
item.Parent = parent;
if (SelectedCommandTreeItem.Parent is ScriptCommandSectionTreeItem parent && !parent.Text.Equals("Top"))
{
int index = parent.IndexOf(SelectedCommandTreeItem);
if (index == -1) return;
parent.Insert(index + 1, item);
}
else
{
SelectedCommandTreeItem.Insert(0, item);
}

AddCommand?.Invoke(this, EventArgs.Empty); //todo invoke this with the new item args
_treeView.SelectedItem = item;
_treeView.DataStore = _treeView.DataStore;
}

internal void AddSection(ScriptCommandSectionTreeItem section)
{
ScriptCommandSectionTreeItem rootNode = (ScriptCommandSectionTreeItem)_treeView.DataStore;
if (rootNode is null) return;
rootNode.Add(section);

AddCommand?.Invoke(this, EventArgs.Empty); //todo invoke this with the new script section args
_treeView.SelectedItem = section;
_treeView.DataStore = rootNode;
}

public void SetContents(IEnumerable<ScriptCommandSectionEntry> topNodes, bool expanded)
{
_treeView.DataStore = new ScriptCommandSectionTreeItem(new ScriptCommandSectionEntry("Top", topNodes, null), expanded);
}

public ScriptCommandSectionEntry FindSection(string text)
{
ScriptCommandSectionTreeItem rootNode = (ScriptCommandSectionTreeItem)_treeView.DataStore;
return rootNode.Find(s => s.Text.Equals(text))?.Section;
}
}
}
2 changes: 1 addition & 1 deletion src/SerialLoops/Controls/SectionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public SectionTreeItem(Section section, bool expanded)
}

/// <summary>
/// The base class for views that display the set of tests.
/// The base class for nested section lists.
/// </summary>
public abstract class SectionList
{
Expand Down
5 changes: 3 additions & 2 deletions src/SerialLoops/Editors/MapEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ void redrawMap(object obj, EventArgs args)
Items =
{
mapLayout,
drawPathingMapBox,
drawStartingPointBox,
ControlGenerator.GetControlWithIcon(drawPathingMapBox, "Pathing", _log),
ControlGenerator.GetControlWithIcon(drawStartingPointBox, "Camera", _log)
,
}
};
}
Expand Down
Loading

0 comments on commit 5668e55

Please sign in to comment.