mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-14 20:54:16 +01:00
Add Turn Permanent button for temporary settings and improve buttons, make secure.
This commit is contained in:
parent
9a457a1a95
commit
756537c776
1 changed files with 58 additions and 24 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
using OtterGui.Text;
|
using OtterGui.Text;
|
||||||
|
|
@ -19,7 +20,8 @@ public class ModPanelSettingsTab(
|
||||||
ModSelection selection,
|
ModSelection selection,
|
||||||
TutorialService tutorial,
|
TutorialService tutorial,
|
||||||
CommunicatorService communicator,
|
CommunicatorService communicator,
|
||||||
ModGroupDrawer modGroupDrawer)
|
ModGroupDrawer modGroupDrawer,
|
||||||
|
Configuration config)
|
||||||
: ITab, IUiService
|
: ITab, IUiService
|
||||||
{
|
{
|
||||||
private bool _inherited;
|
private bool _inherited;
|
||||||
|
|
@ -180,32 +182,28 @@ public class ModPanelSettingsTab(
|
||||||
private void DrawRemoveSettings()
|
private void DrawRemoveSettings()
|
||||||
{
|
{
|
||||||
var drawInherited = !_inherited && selection.Settings != ModSettings.Empty;
|
var drawInherited = !_inherited && selection.Settings != ModSettings.Empty;
|
||||||
if (!drawInherited && _temporary)
|
var scroll = ImGui.GetScrollMaxY() > 0 ? ImGui.GetStyle().ScrollbarSize + ImGui.GetStyle().ItemInnerSpacing.X : 0;
|
||||||
return;
|
var buttonSize = ImUtf8.CalcTextSize("Turn Permanent_"u8).X;
|
||||||
|
var offset = drawInherited
|
||||||
var scroll = ImGui.GetScrollMaxY() > 0 ? ImGui.GetStyle().ScrollbarSize + ImGui.GetStyle().ItemInnerSpacing.X: 0;
|
? buttonSize + ImUtf8.CalcTextSize("Inherit Settings"u8).X + ImGui.GetStyle().FramePadding.X * 4 + ImGui.GetStyle().ItemSpacing.X
|
||||||
var offset = (drawInherited, _temporary) switch
|
: buttonSize + ImGui.GetStyle().FramePadding.X * 2;
|
||||||
{
|
|
||||||
(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);
|
ImGui.SameLine(ImGui.GetWindowWidth() - offset - scroll);
|
||||||
if (!_temporary
|
var enabled = config.DeleteModModifier.IsActive();
|
||||||
&& 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)
|
if (drawInherited)
|
||||||
{
|
{
|
||||||
if (!_temporary)
|
var inherit = (enabled, _locked) switch
|
||||||
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
|
(true, false) => ImUtf8.ButtonEx("Inherit Settings"u8,
|
||||||
+ "If no inherited collection has settings for this mod, it will be disabled."u8, default, _locked))
|
"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, false),
|
||||||
|
(false, false) => ImUtf8.ButtonEx("Inherit Settings"u8,
|
||||||
|
$"Remove current settings from this collection so that it can inherit them.\nHold {config.DeleteModModifier} to inherit.",
|
||||||
|
default, true),
|
||||||
|
(_, true) => ImUtf8.ButtonEx("Inherit Settings"u8,
|
||||||
|
"Remove current settings from this collection so that it can inherit them.\nThe settings are currently locked and can not be changed."u8,
|
||||||
|
default, true),
|
||||||
|
};
|
||||||
|
if (inherit)
|
||||||
{
|
{
|
||||||
if (_temporary)
|
if (_temporary)
|
||||||
{
|
{
|
||||||
|
|
@ -218,6 +216,42 @@ public class ModPanelSettingsTab(
|
||||||
collectionManager.Editor.SetModInheritance(collectionManager.Active.Current, selection.Mod!, true);
|
collectionManager.Editor.SetModInheritance(collectionManager.Active.Current, selection.Mod!, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_temporary)
|
||||||
|
{
|
||||||
|
var overwrite = enabled
|
||||||
|
? ImUtf8.ButtonEx("Turn Permanent"u8,
|
||||||
|
"Overwrite the actual settings for this mod in this collection with the current temporary settings."u8,
|
||||||
|
new Vector2(buttonSize, 0))
|
||||||
|
: ImUtf8.ButtonEx("Turn Permanent"u8,
|
||||||
|
$"Overwrite the actual settings for this mod in this collection with the current temporary settings.\nHold {config.DeleteModModifier} to overwrite.",
|
||||||
|
new Vector2(buttonSize, 0), true);
|
||||||
|
if (overwrite)
|
||||||
|
{
|
||||||
|
var settings = collectionManager.Active.Current.GetTempSettings(selection.Mod!.Index)!;
|
||||||
|
if (settings.ForceInherit)
|
||||||
|
{
|
||||||
|
collectionManager.Editor.SetModInheritance(collectionManager.Active.Current, selection.Mod, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collectionManager.Editor.SetModState(collectionManager.Active.Current, selection.Mod, settings.Enabled);
|
||||||
|
collectionManager.Editor.SetModPriority(collectionManager.Active.Current, selection.Mod, settings.Priority);
|
||||||
|
foreach (var (setting, index) in settings.Settings.WithIndex())
|
||||||
|
collectionManager.Editor.SetModSetting(collectionManager.Active.Current, selection.Mod, index, setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionManager.Editor.SetTemporarySettings(collectionManager.Active.Current, selection.Mod, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue