From 1e0b7fdfce62e770da391708f1338358ba738a00 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 28 Jul 2024 01:33:37 +0200 Subject: [PATCH] Improve respecting of design write protection. --- Glamourer/Gui/Customization/CustomizationDrawer.Color.cs | 6 ++++-- Glamourer/Gui/Materials/MaterialDrawer.cs | 9 +++++---- Glamourer/Gui/Tabs/DesignTab/DesignPanel.cs | 7 ++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs b/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs index fb50f55..4d34a05 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs @@ -22,8 +22,10 @@ public partial class CustomizationDrawer using (_ = ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, 2 * ImGuiHelpers.GlobalScale, current < 0)) { if (ImGui.ColorButton($"{_customize[index].Value}##color", color, ImGuiColorEditFlags.None, _framedIconSize)) + { ImGui.OpenPopup(ColorPickerPopupName); - else if (current >= 0 && CaptureMouseWheel(ref current, 0, _currentCount)) + } + else if (current >= 0 && !_locked && CaptureMouseWheel(ref current, 0, _currentCount)) { var data = _set.Data(_currentIndex, current, _customize.Face); UpdateValue(data.Value); @@ -70,7 +72,7 @@ public partial class CustomizationDrawer for (var i = 0; i < _currentCount; ++i) { var custom = _set.Data(_currentIndex, i, _customize[CustomizeIndex.Face]); - if (ImGui.ColorButton(custom.Value.ToString(), ImGui.ColorConvertU32ToFloat4(custom.Color))) + if (ImGui.ColorButton(custom.Value.ToString(), ImGui.ColorConvertU32ToFloat4(custom.Color)) && !_locked) { UpdateValue(custom.Value); ImGui.CloseCurrentPopup(); diff --git a/Glamourer/Gui/Materials/MaterialDrawer.cs b/Glamourer/Gui/Materials/MaterialDrawer.cs index 445184d..50cfb36 100644 --- a/Glamourer/Gui/Materials/MaterialDrawer.cs +++ b/Glamourer/Gui/Materials/MaterialDrawer.cs @@ -27,7 +27,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) public void Draw(Design design) { - var available = ImGui.GetContentRegionAvail().X; + var available = ImGui.GetContentRegionAvail().X; _spacing = ImGui.GetStyle().ItemInnerSpacing.X; _buttonSize = new Vector2(ImGui.GetFrameHeight()); var colorWidth = 4 * _buttonSize.X @@ -64,6 +64,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) ImGui.SameLine(0, _spacing); PasteButton(design, key); ImGui.SameLine(0, _spacing); + using var disabled = ImRaii.Disabled(design.WriteProtected()); EnabledToggle(design, key, value.Enabled); ImGui.SameLine(0, _spacing); DrawRow(design, key, value.Value, value.Revert); @@ -103,7 +104,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) var deleteEnabled = _config.DeleteDesignModifier.IsActive(); if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), _buttonSize, $"Delete this color row.{(deleteEnabled ? string.Empty : $"\nHold {_config.DeleteDesignModifier} to delete.")}", - !deleteEnabled, true)) + !deleteEnabled || design.WriteProtected(), true)) return; _designManager.ChangeMaterialValue(design, index, null); @@ -121,7 +122,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) private void PasteButton(Design design, MaterialValueIndex index) { if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Paste.ToIconString(), _buttonSize, - "Import an exported row from your clipboard onto this row.", !ColorRowClipboard.IsSet, true)) + "Import an exported row from your clipboard onto this row.", !ColorRowClipboard.IsSet || design.WriteProtected(), true)) _designManager.ChangeMaterialValue(design, index, ColorRowClipboard.Row); } @@ -154,7 +155,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X); var exists = design.GetMaterialDataRef().TryGetValue(_newKey, out _); if (ImGuiUtil.DrawDisabledButton("Add New Row", Vector2.Zero, - exists ? "The selected advanced dye row already exists." : "Add the selected advanced dye row.", exists, false)) + exists ? "The selected advanced dye row already exists." : "Add the selected advanced dye row.", exists || design.WriteProtected())) _designManager.ChangeMaterialValue(design, _newKey, ColorRow.Empty); } diff --git a/Glamourer/Gui/Tabs/DesignTab/DesignPanel.cs b/Glamourer/Gui/Tabs/DesignTab/DesignPanel.cs index 3fa8e74..1a072cb 100644 --- a/Glamourer/Gui/Tabs/DesignTab/DesignPanel.cs +++ b/Glamourer/Gui/Tabs/DesignTab/DesignPanel.cs @@ -248,6 +248,8 @@ public class DesignPanel if (!h) return; + using var disabled = ImRaii.Disabled(_selector.Selected!.WriteProtected()); + using (var _ = ImRaii.Group()) { DrawCustomizeApplication(); @@ -548,7 +550,7 @@ public class DesignPanel => panel._selector.Selected != null; protected override bool Disabled - => !panel._manager.CanUndo(panel._selector.Selected); + => !panel._manager.CanUndo(panel._selector.Selected) || (panel._selector.Selected?.WriteProtected() ?? true); protected override string Description => "Undo the last change if you accidentally overwrote your design with a different one."; @@ -604,6 +606,9 @@ public class DesignPanel protected override string Description => "Overwrite this design with your character's current state."; + + protected override bool Disabled + => panel._selector.Selected?.WriteProtected() ?? true; protected override FontAwesomeIcon Icon => FontAwesomeIcon.UserEdit;