Skip to content

Commit

Permalink
Add tutorial items (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jun 30, 2023
1 parent 1f207e8 commit 2b31079
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public enum ItemType
System_Texture,
Topic,
Transition,
Tutorial,
Voice,
}

Expand All @@ -69,6 +68,9 @@ public List<ItemDescription> GetReferencesTo(Project project)
case ItemType.BGM:
BackgroundMusicItem bgm = (BackgroundMusicItem)this;
return project.Items.Where(i => bgm.ScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();
case ItemType.Character:
CharacterItem character = (CharacterItem)this;
return project.Items.Where(i => i.Type == ItemType.Script && ((ScriptItem)i).Event.DialogueSection.Objects.Any(l => l.Speaker == character.MessageInfo.Character)).ToList();
case ItemType.Character_Sprite:
CharacterSpriteItem sprite = (CharacterSpriteItem)this;
return project.Items.Where(i => sprite.ScriptUses.Select(s => s.ScriptName).Contains(i.Name)).ToList();
Expand Down
14 changes: 14 additions & 0 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class Project
[JsonIgnore]
public EventFile TopicFile { get; set; }
[JsonIgnore]
public EventFile TutorialFile { get; set; }
[JsonIgnore]
public MessageFile UiText { get; set; }
[JsonIgnore]
public MessageInfoFile MessInfo { get; set; }
Expand Down Expand Up @@ -555,6 +557,18 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
return new(LoadProjectState.FAILED);
}


try
{
TutorialFile = Evt.Files.First(t => t.Name == "TUTORIALS");
TutorialFile.InitializeTutorialFile();
}
catch (Exception ex)
{
log.LogException("Failed to load tutorials", ex);
return new(LoadProjectState.FAILED);
}

try
{
tracker.Focus("Maps", 1);
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.3" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="2.8.2.3" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.32.1" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.33.0" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="NitroPacker.Core" Version="2.2.5" />
<PackageReference Include="NLayer" Version="1.14.0" />
Expand Down
121 changes: 121 additions & 0 deletions src/SerialLoops/Dialogs/EditTutorialMappingsDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Controls;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using SerialLoops.Utility;
using System.IO;
using System.Linq;

namespace SerialLoops.Dialogs
{
internal class EditTutorialMappingsDialog : FloatingForm
{
private readonly ILogger _log;
private readonly Project _project;
private readonly EditorTabsPanel _tabs;

public EditTutorialMappingsDialog(Project project, EditorTabsPanel tabs, ILogger log)
{
_project = project;
_tabs = tabs;
_log = log;

Title = "Edit Tutorial Mappings";
MinimumSize = new(400, 600);
Size = new(400, 600);
Padding = 10;
InitializeComponent();
}

public void InitializeComponent()
{
StackLayout tutorialsLayout = new()
{
Orientation = Orientation.Vertical,
Spacing = 10,
};
for (int i = 0; i < _project.TutorialFile.Tutorials.Count - 1; i++) // Minus one to avoid the padding
{
int currentIndex = i;

Label idLabel = new() { Text = (_project.TutorialFile.Tutorials[currentIndex].Id - 1).ToString() };
DropDown associatedScriptDropDown = new();
associatedScriptDropDown.Items.AddRange(_project.Items.Where(i => i.Type == ItemDescription.ItemType.Script).Select(s => new ListItem { Key = s.DisplayName, Text = s.DisplayName }));
ScriptItem associatedScript = (ScriptItem)_project.Items.First(i => i.Type == ItemDescription.ItemType.Script && ((ScriptItem)i).Event.Index == _project.TutorialFile.Tutorials[currentIndex].AssociatedScript);
associatedScriptDropDown.SelectedKey = associatedScript.DisplayName;
StackLayout associatedLink = ControlGenerator.GetFileLink(associatedScript, _tabs, _log);

StackLayout scriptLayout = new()
{
Orientation = Orientation.Horizontal,
Spacing = 3,
Items =
{
ControlGenerator.GetControlWithLabel("Associated Script", associatedScriptDropDown),
associatedLink,
}
};

associatedScriptDropDown.SelectedKeyChanged += (sender, args) =>
{
ScriptItem newAssociatedScript = (ScriptItem)_project.Items.First(i => i.DisplayName == associatedScriptDropDown.SelectedKey);
_project.TutorialFile.Tutorials[currentIndex].AssociatedScript = (short)newAssociatedScript.Event.Index;
scriptLayout.Items.RemoveAt(1);
scriptLayout.Items.Add(ControlGenerator.GetFileLink(newAssociatedScript, _tabs, _log));
};

tutorialsLayout.Items.Add(new GroupBox
{
Text = $"Tutorial {idLabel.Text}",
Content = new StackLayout
{
Orientation = Orientation.Vertical,
Spacing = 5,
Items =
{
ControlGenerator.GetControlWithLabel("ID", idLabel),
scriptLayout,
}
}
});
}

Button saveButton = new() { Text = "Save" };
saveButton.Click += (sender, args) =>
{
_log.Log("Attempting to save tutorial mappings...");
Lib.IO.WriteStringFile(Path.Combine("assets", "events", $"{_project.TutorialFile.Index:X3}.s"), _project.TutorialFile.GetSource(new()), _project, _log);
Close();
};

Button cancelButton = new() { Text = "Cancel" };
cancelButton.Click += (sender, args) =>
{
Close();
};

StackLayout buttonsLayout = new()
{
Orientation = Orientation.Horizontal,
Spacing = 3,
HorizontalContentAlignment = HorizontalAlignment.Right,
Items =
{
saveButton,
cancelButton,
}
};

Content = new TableLayout
{
Spacing = new(5, 5),
Rows =
{
new(new Scrollable { Content = tutorialsLayout, Height = 500 }),
new(buttonsLayout),
},
};
}
}
}
3 changes: 1 addition & 2 deletions src/SerialLoops/Dialogs/ItemReferenceDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ private void InitializeComponent()
public class OrphanedItemsDialog : FindItemsWindow
{
private static readonly ItemDescription.ItemType[] IGNORED_ORPHAN_TYPES = {
ItemDescription.ItemType.Scenario,
ItemDescription.ItemType.Character
ItemDescription.ItemType.Scenario
};

public OrphanedItemsDialog(Project project, ItemExplorerPanel explorer, EditorTabsPanel tabs, ILogger log)
Expand Down
1 change: 0 additions & 1 deletion src/SerialLoops/Dialogs/ItemRenameDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ private void InitializeComponent()
ItemDescription.ItemType.Puzzle => "PZL_",
ItemDescription.ItemType.SFX => "SFX_",
ItemDescription.ItemType.Transition => "TRN_",
ItemDescription.ItemType.Tutorial => "TUT_",
_ => "",
};

Expand Down
13 changes: 13 additions & 0 deletions src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ private void InitializeProjectMenu()
Command editUiTextCommand = new() { MenuText = "Edit UI Text...", Image = ControlGenerator.GetIcon("Edit_UI_Text", Log) };
editUiTextCommand.Executed += EditUiTextCommand_Executed;

Command editTutorialMappingsCommand = new() { MenuText = "Edit Tutorial Mappings...", Image = ControlGenerator.GetIcon("Tutorial", Log) };
editTutorialMappingsCommand.Executed += EditTutorialMappingsCommand_Executed;

Command searchProjectCommand = new()
{
MenuText = "Search...",
Expand Down Expand Up @@ -351,6 +354,7 @@ private void InitializeProjectMenu()
applyHacksCommand,
renameItemCommand,
editUiTextCommand,
editTutorialMappingsCommand,
searchProjectCommand,
findOrphanedItemsCommand,
}
Expand Down Expand Up @@ -759,6 +763,15 @@ private void EditUiTextCommand_Executed(object sender, EventArgs e)
}
}

private void EditTutorialMappingsCommand_Executed(object sender, EventArgs e)
{
if (OpenProject is not null)
{
EditTutorialMappingsDialog editTutorialMappingsDialog = new(OpenProject, EditorTabs, Log);
editTutorialMappingsDialog.Show();
}
}

private void Search_Executed(object sender, EventArgs e)
{
if (OpenProject is not null)
Expand Down

0 comments on commit 2b31079

Please sign in to comment.