Improve respecting of design write protection.

This commit is contained in:
Ottermandias 2024-07-28 01:33:37 +02:00
parent 1bee5c680b
commit 1e0b7fdfce
3 changed files with 15 additions and 7 deletions

View file

@ -22,8 +22,10 @@ public partial class CustomizationDrawer
using (_ = ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, 2 * ImGuiHelpers.GlobalScale, current < 0)) using (_ = ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, 2 * ImGuiHelpers.GlobalScale, current < 0))
{ {
if (ImGui.ColorButton($"{_customize[index].Value}##color", color, ImGuiColorEditFlags.None, _framedIconSize)) if (ImGui.ColorButton($"{_customize[index].Value}##color", color, ImGuiColorEditFlags.None, _framedIconSize))
{
ImGui.OpenPopup(ColorPickerPopupName); 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); var data = _set.Data(_currentIndex, current, _customize.Face);
UpdateValue(data.Value); UpdateValue(data.Value);
@ -70,7 +72,7 @@ public partial class CustomizationDrawer
for (var i = 0; i < _currentCount; ++i) for (var i = 0; i < _currentCount; ++i)
{ {
var custom = _set.Data(_currentIndex, i, _customize[CustomizeIndex.Face]); 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); UpdateValue(custom.Value);
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();

View file

@ -27,7 +27,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config)
public void Draw(Design design) public void Draw(Design design)
{ {
var available = ImGui.GetContentRegionAvail().X; var available = ImGui.GetContentRegionAvail().X;
_spacing = ImGui.GetStyle().ItemInnerSpacing.X; _spacing = ImGui.GetStyle().ItemInnerSpacing.X;
_buttonSize = new Vector2(ImGui.GetFrameHeight()); _buttonSize = new Vector2(ImGui.GetFrameHeight());
var colorWidth = 4 * _buttonSize.X var colorWidth = 4 * _buttonSize.X
@ -64,6 +64,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config)
ImGui.SameLine(0, _spacing); ImGui.SameLine(0, _spacing);
PasteButton(design, key); PasteButton(design, key);
ImGui.SameLine(0, _spacing); ImGui.SameLine(0, _spacing);
using var disabled = ImRaii.Disabled(design.WriteProtected());
EnabledToggle(design, key, value.Enabled); EnabledToggle(design, key, value.Enabled);
ImGui.SameLine(0, _spacing); ImGui.SameLine(0, _spacing);
DrawRow(design, key, value.Value, value.Revert); DrawRow(design, key, value.Value, value.Revert);
@ -103,7 +104,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config)
var deleteEnabled = _config.DeleteDesignModifier.IsActive(); var deleteEnabled = _config.DeleteDesignModifier.IsActive();
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), _buttonSize, if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), _buttonSize,
$"Delete this color row.{(deleteEnabled ? string.Empty : $"\nHold {_config.DeleteDesignModifier} to delete.")}", $"Delete this color row.{(deleteEnabled ? string.Empty : $"\nHold {_config.DeleteDesignModifier} to delete.")}",
!deleteEnabled, true)) !deleteEnabled || design.WriteProtected(), true))
return; return;
_designManager.ChangeMaterialValue(design, index, null); _designManager.ChangeMaterialValue(design, index, null);
@ -121,7 +122,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config)
private void PasteButton(Design design, MaterialValueIndex index) private void PasteButton(Design design, MaterialValueIndex index)
{ {
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Paste.ToIconString(), _buttonSize, 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); _designManager.ChangeMaterialValue(design, index, ColorRowClipboard.Row);
} }
@ -154,7 +155,7 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config)
ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X); ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X);
var exists = design.GetMaterialDataRef().TryGetValue(_newKey, out _); var exists = design.GetMaterialDataRef().TryGetValue(_newKey, out _);
if (ImGuiUtil.DrawDisabledButton("Add New Row", Vector2.Zero, 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); _designManager.ChangeMaterialValue(design, _newKey, ColorRow.Empty);
} }

View file

@ -248,6 +248,8 @@ public class DesignPanel
if (!h) if (!h)
return; return;
using var disabled = ImRaii.Disabled(_selector.Selected!.WriteProtected());
using (var _ = ImRaii.Group()) using (var _ = ImRaii.Group())
{ {
DrawCustomizeApplication(); DrawCustomizeApplication();
@ -548,7 +550,7 @@ public class DesignPanel
=> panel._selector.Selected != null; => panel._selector.Selected != null;
protected override bool Disabled 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 protected override string Description
=> "Undo the last change if you accidentally overwrote your design with a different one."; => "Undo the last change if you accidentally overwrote your design with a different one.";
@ -605,6 +607,9 @@ public class DesignPanel
protected override string Description protected override string Description
=> "Overwrite this design with your character's current state."; => "Overwrite this design with your character's current state.";
protected override bool Disabled
=> panel._selector.Selected?.WriteProtected() ?? true;
protected override FontAwesomeIcon Icon protected override FontAwesomeIcon Icon
=> FontAwesomeIcon.UserEdit; => FontAwesomeIcon.UserEdit;