Skip to content

Commit a2258e6

Browse files
committed
Add some temporary context menu things.
1 parent dbef1cc commit a2258e6

File tree

2 files changed

+87
-78
lines changed

2 files changed

+87
-78
lines changed

OtterGui

Penumbra/UI/ModsTab/ModFileSystemSelector.cs

Lines changed: 86 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public ModFileSystemSelector(IKeyState keyState, CommunicatorService communicato
6262
SubscribeRightClickFolder(f => SetQuickMove(f, 1, _config.QuickMoveFolder2, s => { _config.QuickMoveFolder2 = s; _config.Save(); }), 120);
6363
SubscribeRightClickFolder(f => SetQuickMove(f, 2, _config.QuickMoveFolder3, s => { _config.QuickMoveFolder3 = s; _config.Save(); }), 130);
6464
SubscribeRightClickLeaf(ToggleLeafFavorite);
65-
SubscribeRightClickLeaf(RemoveTemporarySettings);
66-
SubscribeRightClickLeaf(DisableTemporarily);
65+
SubscribeRightClickLeaf(DrawTemporaryOptions);
6766
SubscribeRightClickLeaf(l => QuickMove(l, _config.QuickMoveFolder1, _config.QuickMoveFolder2, _config.QuickMoveFolder3));
6867
SubscribeRightClickMain(ClearDefaultImportFolder, 100);
6968
SubscribeRightClickMain(() => ClearQuickMove(0, _config.QuickMoveFolder1, () => {_config.QuickMoveFolder1 = string.Empty; _config.Save();}), 110);
@@ -135,7 +134,7 @@ public void SetRenameSearchPath(RenameField value)
135134
{
136135
_dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m =>
137136
{
138-
ImGui.TextUnformatted($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
137+
ImUtf8.Text($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
139138
return true;
140139
});
141140
base.Draw(width);
@@ -198,8 +197,8 @@ protected override void DrawLeafName(FileSystem<Mod>.Leaf leaf, in ModState stat
198197
var flags = selected ? ImGuiTreeNodeFlags.Selected | LeafFlags : LeafFlags;
199198
using var c = ImRaii.PushColor(ImGuiCol.Text, state.Color.Tinted(state.Tint))
200199
.Push(ImGuiCol.HeaderHovered, 0x4000FFFF, leaf.Value.Favorite);
201-
using var id = ImRaii.PushId(leaf.Value.Index);
202-
ImRaii.TreeNode(leaf.Value.Name, flags).Dispose();
200+
using var id = ImUtf8.PushId(leaf.Value.Index);
201+
ImUtf8.TreeNode(leaf.Value.Name.Text, flags).Dispose();
203202
if (ImGui.IsItemClicked(ImGuiMouseButton.Middle))
204203
{
205204
_modManager.SetKnown(leaf.Value);
@@ -244,48 +243,58 @@ private void EnableDescendants(ModFileSystem.Folder folder)
244243

245244
private void DisableDescendants(ModFileSystem.Folder folder)
246245
{
247-
if (ImGui.MenuItem("Disable Descendants"))
246+
if (ImUtf8.MenuItem("Disable Descendants"u8))
248247
SetDescendants(folder, false);
249248
}
250249

251250
private void InheritDescendants(ModFileSystem.Folder folder)
252251
{
253-
if (ImGui.MenuItem("Inherit Descendants"))
252+
if (ImUtf8.MenuItem("Inherit Descendants"u8))
254253
SetDescendants(folder, true, true);
255254
}
256255

257256
private void OwnDescendants(ModFileSystem.Folder folder)
258257
{
259-
if (ImGui.MenuItem("Stop Inheriting Descendants"))
258+
if (ImUtf8.MenuItem("Stop Inheriting Descendants"u8))
260259
SetDescendants(folder, false, true);
261260
}
262261

263262
private void ToggleLeafFavorite(FileSystem<Mod>.Leaf mod)
264263
{
265-
if (ImGui.MenuItem(mod.Value.Favorite ? "Remove Favorite" : "Mark as Favorite"))
264+
if (ImUtf8.MenuItem(mod.Value.Favorite ? "Remove Favorite"u8 : "Mark as Favorite"u8))
266265
_modManager.DataEditor.ChangeModFavorite(mod.Value, !mod.Value.Favorite);
267266
}
268267

269-
private void RemoveTemporarySettings(FileSystem<Mod>.Leaf mod)
268+
private void DrawTemporaryOptions(FileSystem<Mod>.Leaf mod)
270269
{
271-
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
272-
if (tempSettings is { Lock: <= 0 })
273-
if (ImUtf8.MenuItem("Remove Temporary Settings"))
274-
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, null);
275-
}
270+
const string source = "yourself";
271+
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
272+
if (tempSettings is { Lock: > 0 })
273+
return;
276274

277-
private void DisableTemporarily(FileSystem<Mod>.Leaf mod)
278-
{
279-
var tempSettings = _collectionManager.Active.Current.GetTempSettings(mod.Value.Index);
280-
if (tempSettings is not { Lock: > 0 })
281-
if (ImUtf8.MenuItem("Disable Temporarily"))
282-
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
283-
TemporaryModSettings.DefaultSettings(mod.Value, "User Context-Menu"));
275+
if (tempSettings is { Lock: <= 0 } && ImUtf8.MenuItem("Remove Temporary Settings"u8))
276+
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, null);
277+
var actual = _collectionManager.Active.Current.GetActualSettings(mod.Value.Index).Settings;
278+
if (actual?.Enabled is true && ImUtf8.MenuItem("Disable Temporarily"u8))
279+
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
280+
new TemporaryModSettings(actual, source) { Enabled = false });
281+
282+
if (actual is not { Enabled: true } && ImUtf8.MenuItem("Enable Temporarily"u8))
283+
{
284+
var newSettings = actual is null
285+
? TemporaryModSettings.DefaultSettings(mod.Value, source, true)
286+
: new TemporaryModSettings(actual, source) { Enabled = true };
287+
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value, newSettings);
288+
}
289+
290+
if (tempSettings is null && ImUtf8.MenuItem("Turn Temporary"u8))
291+
_collectionManager.Editor.SetTemporarySettings(_collectionManager.Active.Current, mod.Value,
292+
new TemporaryModSettings(actual, source));
284293
}
285294

286295
private void SetDefaultImportFolder(ModFileSystem.Folder folder)
287296
{
288-
if (!ImGui.MenuItem("Set As Default Import Folder"))
297+
if (!ImUtf8.MenuItem("Set As Default Import Folder"u8))
289298
return;
290299

291300
var newName = folder.FullName();
@@ -298,7 +307,7 @@ private void SetDefaultImportFolder(ModFileSystem.Folder folder)
298307

299308
private void ClearDefaultImportFolder()
300309
{
301-
if (!ImGui.MenuItem("Clear Default Import Folder") || _config.DefaultImportFolder.Length <= 0)
310+
if (!ImUtf8.MenuItem("Clear Default Import Folder"u8) || _config.DefaultImportFolder.Length <= 0)
302311
return;
303312

304313
_config.DefaultImportFolder = string.Empty;
@@ -309,16 +318,15 @@ private void ClearDefaultImportFolder()
309318

310319
private void AddNewModButton(Vector2 size)
311320
{
312-
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), size, "Create a new, empty mod of a given name.",
313-
!_modManager.Valid, true))
314-
ImGui.OpenPopup("Create New Mod");
321+
if (ImUtf8.IconButton(FontAwesomeIcon.Plus, "Create a new, empty mod of a given name."u8, size, !_modManager.Valid))
322+
ImUtf8.OpenPopup("Create New Mod"u8);
315323
}
316324

317325
/// <summary> Add an import mods button that opens a file selector. </summary>
318326
private void AddImportModButton(Vector2 size)
319327
{
320-
var button = ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.FileImport.ToIconString(), size,
321-
"Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files.", !_modManager.Valid, true);
328+
var button = ImUtf8.IconButton(FontAwesomeIcon.FileImport,
329+
"Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files."u8, size, !_modManager.Valid);
322330
_tutorial.OpenTutorial(BasicTutorialSteps.ModImport);
323331
if (!button)
324332
return;
@@ -351,23 +359,23 @@ private void RenameMod(ModFileSystem.Leaf leaf)
351359
var currentName = leaf.Value.Name.Text;
352360
if (ImGui.IsWindowAppearing())
353361
ImGui.SetKeyboardFocusHere(0);
354-
ImGui.TextUnformatted("Rename Mod:");
355-
if (ImGui.InputText("##RenameMod", ref currentName, 256, ImGuiInputTextFlags.EnterReturnsTrue))
362+
ImUtf8.Text("Rename Mod:"u8);
363+
if (ImUtf8.InputText("##RenameMod"u8, ref currentName, flags: ImGuiInputTextFlags.EnterReturnsTrue))
356364
{
357365
_modManager.DataEditor.ChangeModName(leaf.Value, currentName);
358366
ImGui.CloseCurrentPopup();
359367
}
360368

361-
ImGuiUtil.HoverTooltip("Enter a new name here to rename the changed mod.");
369+
ImUtf8.HoverTooltip("Enter a new name here to rename the changed mod."u8);
362370
}
363371

364372
private void DeleteModButton(Vector2 size)
365373
=> DeleteSelectionButton(size, _config.DeleteModModifier, "mod", "mods", _modManager.DeleteMod);
366374

367375
private void AddHelpButton(Vector2 size)
368376
{
369-
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.QuestionCircle.ToIconString(), size, "Open extended help.", false, true))
370-
ImGui.OpenPopup("ExtendedHelp");
377+
if (ImUtf8.IconButton(FontAwesomeIcon.QuestionCircle, "Open extended help."u8, size, false))
378+
ImUtf8.OpenPopup("ExtendedHelp"u8);
371379

372380
_tutorial.OpenTutorial(BasicTutorialSteps.AdvancedHelp);
373381
}
@@ -392,60 +400,61 @@ private void DrawHelpPopup()
392400
ImGuiUtil.HelpPopup("ExtendedHelp", new Vector2(1000 * UiHelpers.Scale, 38.5f * ImGui.GetTextLineHeightWithSpacing()), () =>
393401
{
394402
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight());
395-
ImGui.TextUnformatted("Mod Management");
396-
ImGui.BulletText("You can create empty mods or import mods with the buttons in this row.");
403+
ImUtf8.Text("Mod Management"u8);
404+
ImUtf8.BulletText("You can create empty mods or import mods with the buttons in this row."u8);
397405
using var indent = ImRaii.PushIndent();
398-
ImGui.BulletText("Supported formats for import are: .ttmp, .ttmp2, .pmp.");
399-
ImGui.BulletText(
400-
"You can also support .zip, .7z or .rar archives, but only if they already contain Penumbra-styled mods with appropriate metadata.");
406+
ImUtf8.BulletText("Supported formats for import are: .ttmp, .ttmp2, .pmp."u8);
407+
ImUtf8.BulletText(
408+
"You can also support .zip, .7z or .rar archives, but only if they already contain Penumbra-styled mods with appropriate metadata."u8);
401409
indent.Pop(1);
402-
ImGui.BulletText("You can also create empty mod folders and delete mods.");
403-
ImGui.BulletText("For further editing of mods, select them and use the Edit Mod tab in the panel or the Advanced Editing popup.");
410+
ImUtf8.BulletText("You can also create empty mod folders and delete mods."u8);
411+
ImUtf8.BulletText(
412+
"For further editing of mods, select them and use the Edit Mod tab in the panel or the Advanced Editing popup."u8);
404413
ImGui.Dummy(Vector2.UnitY * ImGui.GetTextLineHeight());
405-
ImGui.TextUnformatted("Mod Selector");
406-
ImGui.BulletText("Select a mod to obtain more information or change settings.");
407-
ImGui.BulletText("Names are colored according to your config and their current state in the collection:");
414+
ImUtf8.Text("Mod Selector"u8);
415+
ImUtf8.BulletText("Select a mod to obtain more information or change settings."u8);
416+
ImUtf8.BulletText("Names are colored according to your config and their current state in the collection:"u8);
408417
indent.Push();
409-
ImGuiUtil.BulletTextColored(ColorId.EnabledMod.Value(), "enabled in the current collection.");
410-
ImGuiUtil.BulletTextColored(ColorId.DisabledMod.Value(), "disabled in the current collection.");
411-
ImGuiUtil.BulletTextColored(ColorId.InheritedMod.Value(), "enabled due to inheritance from another collection.");
412-
ImGuiUtil.BulletTextColored(ColorId.InheritedDisabledMod.Value(), "disabled due to inheritance from another collection.");
413-
ImGuiUtil.BulletTextColored(ColorId.UndefinedMod.Value(), "unconfigured in all inherited collections.");
414-
ImGuiUtil.BulletTextColored(ColorId.HandledConflictMod.Value(),
415-
"enabled and conflicting with another enabled Mod, but on different priorities (i.e. the conflict is solved).");
416-
ImGuiUtil.BulletTextColored(ColorId.ConflictingMod.Value(),
417-
"enabled and conflicting with another enabled Mod on the same priority.");
418-
ImGuiUtil.BulletTextColored(ColorId.FolderExpanded.Value(), "expanded mod folder.");
419-
ImGuiUtil.BulletTextColored(ColorId.FolderCollapsed.Value(), "collapsed mod folder");
418+
ImUtf8.BulletTextColored(ColorId.EnabledMod.Value(), "enabled in the current collection."u8);
419+
ImUtf8.BulletTextColored(ColorId.DisabledMod.Value(), "disabled in the current collection."u8);
420+
ImUtf8.BulletTextColored(ColorId.InheritedMod.Value(), "enabled due to inheritance from another collection."u8);
421+
ImUtf8.BulletTextColored(ColorId.InheritedDisabledMod.Value(), "disabled due to inheritance from another collection."u8);
422+
ImUtf8.BulletTextColored(ColorId.UndefinedMod.Value(), "unconfigured in all inherited collections."u8);
423+
ImUtf8.BulletTextColored(ColorId.HandledConflictMod.Value(),
424+
"enabled and conflicting with another enabled Mod, but on different priorities (i.e. the conflict is solved)."u8);
425+
ImUtf8.BulletTextColored(ColorId.ConflictingMod.Value(),
426+
"enabled and conflicting with another enabled Mod on the same priority."u8);
427+
ImUtf8.BulletTextColored(ColorId.FolderExpanded.Value(), "expanded mod folder."u8);
428+
ImUtf8.BulletTextColored(ColorId.FolderCollapsed.Value(), "collapsed mod folder"u8);
420429
indent.Pop(1);
421-
ImGui.BulletText("Middle-click a mod to disable it if it is enabled or enable it if it is disabled.");
430+
ImUtf8.BulletText("Middle-click a mod to disable it if it is enabled or enable it if it is disabled."u8);
422431
indent.Push();
423-
ImGui.BulletText(
432+
ImUtf8.BulletText(
424433
$"Holding {_config.DeleteModModifier.ForcedModifier(new DoubleModifier(ModifierHotkey.Control, ModifierHotkey.Shift))} while middle-clicking lets it inherit, discarding settings.");
425434
indent.Pop(1);
426-
ImGui.BulletText("Right-click a mod to enter its sort order, which is its name by default, possibly with a duplicate number.");
435+
ImUtf8.BulletText("Right-click a mod to enter its sort order, which is its name by default, possibly with a duplicate number."u8);
427436
indent.Push();
428-
ImGui.BulletText("A sort order differing from the mods name will not be displayed, it will just be used for ordering.");
429-
ImGui.BulletText(
430-
"If the sort order string contains Forward-Slashes ('/'), the preceding substring will be turned into folders automatically.");
437+
ImUtf8.BulletText("A sort order differing from the mods name will not be displayed, it will just be used for ordering."u8);
438+
ImUtf8.BulletText(
439+
"If the sort order string contains Forward-Slashes ('/'), the preceding substring will be turned into folders automatically."u8);
431440
indent.Pop(1);
432-
ImGui.BulletText(
433-
"You can drag and drop mods and subfolders into existing folders. Dropping them onto mods is the same as dropping them onto the parent of the mod.");
441+
ImUtf8.BulletText(
442+
"You can drag and drop mods and subfolders into existing folders. Dropping them onto mods is the same as dropping them onto the parent of the mod."u8);
434443
indent.Push();
435-
ImGui.BulletText(
436-
"You can select multiple mods and folders by holding Control while clicking them, and then drag all of them at once.");
437-
ImGui.BulletText(
438-
"Selected mods inside an also selected folder will be ignored when dragging and move inside their folder instead of directly into the target.");
444+
ImUtf8.BulletText(
445+
"You can select multiple mods and folders by holding Control while clicking them, and then drag all of them at once."u8);
446+
ImUtf8.BulletText(
447+
"Selected mods inside an also selected folder will be ignored when dragging and move inside their folder instead of directly into the target."u8);
439448
indent.Pop(1);
440-
ImGui.BulletText("Right-clicking a folder opens a context menu.");
441-
ImGui.BulletText("Right-clicking empty space allows you to expand or collapse all folders at once.");
442-
ImGui.BulletText("Use the Filter Mods... input at the top to filter the list for mods whose name or path contain the text.");
449+
ImUtf8.BulletText("Right-clicking a folder opens a context menu."u8);
450+
ImUtf8.BulletText("Right-clicking empty space allows you to expand or collapse all folders at once."u8);
451+
ImUtf8.BulletText("Use the Filter Mods... input at the top to filter the list for mods whose name or path contain the text."u8);
443452
indent.Push();
444-
ImGui.BulletText("You can enter n:[string] to filter only for names, without path.");
445-
ImGui.BulletText("You can enter c:[string] to filter for Changed Items instead.");
446-
ImGui.BulletText("You can enter a:[string] to filter for Mod Authors instead.");
453+
ImUtf8.BulletText("You can enter n:[string] to filter only for names, without path."u8);
454+
ImUtf8.BulletText("You can enter c:[string] to filter for Changed Items instead."u8);
455+
ImUtf8.BulletText("You can enter a:[string] to filter for Mod Authors instead."u8);
447456
indent.Pop(1);
448-
ImGui.BulletText("Use the expandable menu beside the input to filter for mods fulfilling specific criteria.");
457+
ImUtf8.BulletText("Use the expandable menu beside the input to filter for mods fulfilling specific criteria."u8);
449458
});
450459
}
451460

@@ -729,7 +738,7 @@ private bool ApplyFiltersAndState(ModFileSystem.Leaf leaf, out ModState state)
729738

730739
private bool DrawFilterCombo(ref bool everything)
731740
{
732-
using var combo = ImRaii.Combo("##filterCombo", string.Empty,
741+
using var combo = ImUtf8.Combo("##filterCombo"u8, ""u8,
733742
ImGuiComboFlags.NoPreview | ImGuiComboFlags.PopupAlignLeft | ImGuiComboFlags.HeightLargest);
734743
var ret = ImGui.IsItemClicked(ImGuiMouseButton.Right);
735744
if (!combo)
@@ -738,7 +747,7 @@ private bool DrawFilterCombo(ref bool everything)
738747
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
739748
ImGui.GetStyle().ItemSpacing with { Y = 3 * UiHelpers.Scale });
740749

741-
if (ImGui.Checkbox("Everything", ref everything))
750+
if (ImUtf8.Checkbox("Everything"u8, ref everything))
742751
{
743752
_stateFilter = everything ? ModFilterExtensions.UnfilteredStateMods : 0;
744753
SetFilterDirty();
@@ -784,7 +793,7 @@ protected override (float, bool) CustomFilters(float width)
784793
SetFilterDirty();
785794
}
786795

787-
ImGuiUtil.HoverTooltip("Filter mods for their activation status.\nRight-Click to clear all filters.");
796+
ImUtf8.HoverTooltip("Filter mods for their activation status.\nRight-Click to clear all filters."u8);
788797
ImGui.SetCursorPos(pos);
789798
return (remainingWidth, rightClick);
790799
}

0 commit comments

Comments
 (0)