Skip to content

Commit

Permalink
Keep enabled and priority at the top of settings, add button to turn …
Browse files Browse the repository at this point in the history
…temporary.
  • Loading branch information
Ottermandias committed Dec 31, 2024
1 parent a2258e6 commit 7da5d73
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions Penumbra/UI/ModsTab/ModPanelSettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ public void Reset()

public void DrawContent()
{
using var child = ImUtf8.Child("##settings"u8, default);
if (!child)
using var table = ImUtf8.Table("##settings"u8, 1, ImGuiTableFlags.ScrollY, ImGui.GetContentRegionAvail());
if (!table)
return;

_inherited = selection.Collection != collectionManager.Active.Current;
_temporary = selection.TemporarySettings != null;
_locked = (selection.TemporarySettings?.Lock ?? 0) > 0;

ImGui.TableSetupScrollFreeze(0, 1);
ImGui.TableNextColumn();
DrawTemporaryWarning();
DrawInheritedWarning();
UiHelpers.DefaultLineSpace();
ImGui.Dummy(Vector2.Zero);
communicator.PreSettingsPanelDraw.Invoke(selection.Mod!.Identifier);
DrawEnabledInput();
tutorial.OpenTutorial(BasicTutorialSteps.EnablingMods);
Expand All @@ -56,6 +59,7 @@ public void DrawContent()
tutorial.OpenTutorial(BasicTutorialSteps.Priority);
DrawRemoveSettings();

ImGui.TableNextColumn();
communicator.PostEnabledDraw.Invoke(selection.Mod!.Identifier);

modGroupDrawer.Draw(selection.Mod!, selection.Settings, selection.TemporarySettings);
Expand All @@ -71,7 +75,8 @@ private void DrawTemporaryWarning()

using var color = ImRaii.PushColor(ImGuiCol.Button, ImGuiCol.Button.Tinted(ColorId.TemporaryModSettingsTint));
var width = new Vector2(ImGui.GetContentRegionAvail().X, 0);
if (ImUtf8.ButtonEx($"These settings are temporary from {selection.TemporarySettings!.Source}{(_locked ? " and locked." : ".")}", width,
if (ImUtf8.ButtonEx($"These settings are temporarily set by {selection.TemporarySettings!.Source}{(_locked ? " and locked." : ".")}",
width,
_locked))
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!, null);

Expand Down Expand Up @@ -174,23 +179,45 @@ private void DrawPriorityInput()
/// </summary>
private void DrawRemoveSettings()
{
if (_inherited || selection.Settings == ModSettings.Empty)
var drawInherited = !_inherited && selection.Settings != ModSettings.Empty;
if (!drawInherited && _temporary)
return;

var scroll = ImGui.GetScrollMaxY() > 0 ? ImGui.GetStyle().ScrollbarSize : 0;
ImGui.SameLine(ImGui.GetWindowWidth() - ImUtf8.CalcTextSize("Inherit Settings"u8).X - ImGui.GetStyle().FramePadding.X * 2 - scroll);
if (!ImUtf8.ButtonEx("Inherit Settings"u8, "Remove current settings from this collection so that it can inherit them.\n"u8
+ "If no inherited collection has settings for this mod, it will be disabled."u8, default, _locked))
return;

if (_temporary)
var scroll = ImGui.GetScrollMaxY() > 0 ? ImGui.GetStyle().ScrollbarSize + ImGui.GetStyle().ItemInnerSpacing.X: 0;
var offset = (drawInherited, _temporary) switch
{
selection.TemporarySettings!.ForceInherit = true;
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!, selection.TemporarySettings);
}
else
(true, true) => ImUtf8.CalcTextSize("Inherit Settings"u8).X + ImGui.GetStyle().FramePadding.X * 2,
(false, false) => ImUtf8.CalcTextSize("Turn Temporary"u8).X + ImGui.GetStyle().FramePadding.X * 2,
(true, false) => ImUtf8.CalcTextSize("Inherit Settings"u8).X
+ ImUtf8.CalcTextSize("Turn Temporary"u8).X
+ ImGui.GetStyle().FramePadding.X * 4
+ ImGui.GetStyle().ItemSpacing.X,
(false, true) => 0, // can not happen
};

ImGui.SameLine(ImGui.GetWindowWidth() - offset - scroll);
if (!_temporary
&& ImUtf8.ButtonEx("Turn Temporary"u8, "Copy the current settings over to temporary settings to experiment with them."u8))
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!,
new TemporaryModSettings(selection.Settings, "yourself"));
if (drawInherited)
{
collectionManager.Editor.SetModInheritance(collectionManager.Active.Current, selection.Mod!, true);
if (!_temporary)
ImGui.SameLine(0, ImGui.GetStyle().ItemSpacing.X);
if (ImUtf8.ButtonEx("Inherit Settings"u8, "Remove current settings from this collection so that it can inherit them.\n"u8
+ "If no inherited collection has settings for this mod, it will be disabled."u8, default, _locked))
{
if (_temporary)
{
selection.TemporarySettings!.ForceInherit = true;
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod!,
selection.TemporarySettings);
}
else
{
collectionManager.Editor.SetModInheritance(collectionManager.Active.Current, selection.Mod!, true);
}
}
}
}
}

0 comments on commit 7da5d73

Please sign in to comment.