Let SubMods know their location in a mod.

This commit is contained in:
Ottermandias 2022-07-27 10:37:45 +02:00
parent 0b2b0d1beb
commit d6c0362404
18 changed files with 223 additions and 121 deletions

View file

@ -31,7 +31,7 @@ public partial class ModEditWindow : Window, IDisposable
}
_editor?.Dispose();
_editor = new Editor( mod, -1, 0 );
_editor = new Editor( mod, mod.Default );
_mod = mod;
SizeConstraints = new WindowSizeConstraints
@ -42,8 +42,8 @@ public partial class ModEditWindow : Window, IDisposable
_selectedFiles.Clear();
}
public void ChangeOption( int groupIdx, int optionIdx )
=> _editor?.SetSubMod( groupIdx, optionIdx );
public void ChangeOption( ISubMod? subMod )
=> _editor?.SetSubMod( subMod );
public override bool DrawConditions()
=> _editor != null;
@ -437,56 +437,34 @@ public partial class ModEditWindow : Window, IDisposable
private void DrawOptionSelectHeader()
{
const string defaultOption = "Default Option";
using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, Vector2.Zero ).Push( ImGuiStyleVar.FrameRounding, 0 );
var width = new Vector2( ImGui.GetWindowWidth() / 3, 0 );
var isDefaultOption = _editor!.GroupIdx == -1 && _editor!.OptionIdx == 0;
const string defaultOption = "Default Option";
using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, Vector2.Zero ).Push( ImGuiStyleVar.FrameRounding, 0 );
var width = new Vector2( ImGui.GetWindowWidth() / 3, 0 );
if( ImGuiUtil.DrawDisabledButton( defaultOption, width, "Switch to the default option for the mod.\nThis resets unsaved changes.",
isDefaultOption ) )
_editor!.CurrentOption.IsDefault ) )
{
_editor.SetSubMod( -1, 0 );
isDefaultOption = true;
_editor.SetSubMod( _mod!.Default );
}
ImGui.SameLine();
if( ImGuiUtil.DrawDisabledButton( "Refresh Data", width, "Refresh data for the current option.\nThis resets unsaved changes.", false ) )
{
_editor.SetSubMod( _editor.GroupIdx, _editor.OptionIdx );
_editor.SetSubMod( _editor.CurrentOption );
}
ImGui.SameLine();
string GetLabel()
{
if( isDefaultOption )
{
return defaultOption;
}
var group = _mod!.Groups[ _editor!.GroupIdx ];
return $"{group.Name}: {group[ _editor.OptionIdx ].Name}";
}
using var combo = ImRaii.Combo( "##optionSelector", GetLabel(), ImGuiComboFlags.NoArrowButton );
using var combo = ImRaii.Combo( "##optionSelector", _editor.CurrentOption.FullName, ImGuiComboFlags.NoArrowButton );
if( !combo )
{
return;
}
if( ImGui.Selectable( $"{defaultOption}###-1_0", isDefaultOption ) )
foreach( var option in _mod!.AllSubMods )
{
_editor.SetSubMod( -1, 0 );
}
foreach( var (group, groupIdx) in _mod!.Groups.WithIndex() )
{
foreach( var (option, optionIdx) in group.WithIndex() )
if( ImGui.Selectable( option.FullName, option == _editor.CurrentOption ) )
{
var name = $"{group.Name}: {option.Name}###{groupIdx}_{optionIdx}";
if( ImGui.Selectable( name, groupIdx == _editor.GroupIdx && optionIdx == _editor.OptionIdx ) )
{
_editor.SetSubMod( groupIdx, optionIdx );
}
_editor.SetSubMod( option );
}
}
}