fix: don't auto-update disabled plugins, don't let styles modify our toggle switch

This commit is contained in:
goat 2022-07-17 15:39:41 +02:00
parent 8c066451ec
commit f65ccca675
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
6 changed files with 112 additions and 18 deletions

View file

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Utility;
using ImGuiNET;
using Newtonsoft.Json;
using Serilog;
@ -15,6 +16,10 @@ namespace Dalamud.Interface.Style
/// </summary>
public abstract class StyleModel
{
private static int NumPushedStyles = 0;
private static int NumPushedColors = 0;
private static bool HasPushedOnce = false;
/// <summary>
/// Gets or sets the name of the style model.
/// </summary>
@ -84,7 +89,7 @@ namespace Dalamud.Interface.Style
configuration.SavedStyles = new List<StyleModel>();
configuration.SavedStyles.AddRange(configuration.SavedStylesOld);
Log.Information("Transferred {0} styles", configuration.SavedStyles.Count);
Log.Information("Transferred {NumStyles} styles", configuration.SavedStyles.Count);
configuration.SavedStylesOld = null;
configuration.Save();
@ -123,6 +128,60 @@ namespace Dalamud.Interface.Style
/// <summary>
/// Pop this style model from the ImGui style/color stack.
/// </summary>
public abstract void Pop();
public void Pop()
{
if (!HasPushedOnce)
throw new InvalidOperationException("Wasn't pushed at least once.");
ImGui.PopStyleVar(NumPushedStyles);
ImGui.PopStyleColor(NumPushedColors);
}
/// <summary>
/// Push a style var.
/// </summary>
/// <param name="style">Style kind.</param>
/// <param name="arg">Style var.</param>
protected void PushStyleHelper(ImGuiStyleVar style, float arg)
{
ImGui.PushStyleVar(style, arg);
if (!HasPushedOnce)
NumPushedStyles++;
}
/// <summary>
/// Push a style var.
/// </summary>
/// <param name="style">Style kind.</param>
/// <param name="arg">Style var.</param>
protected void PushStyleHelper(ImGuiStyleVar style, Vector2 arg)
{
ImGui.PushStyleVar(style, arg);
if (!HasPushedOnce)
NumPushedStyles++;
}
/// <summary>
/// Push a style color.
/// </summary>
/// <param name="color">Color kind.</param>
/// <param name="value">Color value.</param>
protected void PushColorHelper(ImGuiCol color, Vector4 value)
{
ImGui.PushStyleColor(color, value);
if (!HasPushedOnce)
NumPushedColors++;
}
/// <summary>
/// Indicate that you have pushed.
/// </summary>
protected void DonePushing()
{
HasPushedOnce = true;
}
}
}

View file

@ -487,13 +487,41 @@ namespace Dalamud.Interface.Style
/// <inheritdoc/>
public override void Push()
{
throw new NotImplementedException();
}
this.PushStyleHelper(ImGuiStyleVar.Alpha, this.Alpha);
this.PushStyleHelper(ImGuiStyleVar.WindowPadding, this.WindowPadding);
this.PushStyleHelper(ImGuiStyleVar.WindowRounding, this.WindowRounding);
this.PushStyleHelper(ImGuiStyleVar.WindowBorderSize, this.WindowBorderSize);
this.PushStyleHelper(ImGuiStyleVar.WindowTitleAlign, this.WindowTitleAlign);
this.PushStyleHelper(ImGuiStyleVar.ChildRounding, this.ChildRounding);
this.PushStyleHelper(ImGuiStyleVar.ChildBorderSize, this.ChildBorderSize);
this.PushStyleHelper(ImGuiStyleVar.PopupRounding, this.PopupRounding);
this.PushStyleHelper(ImGuiStyleVar.PopupBorderSize, this.PopupBorderSize);
this.PushStyleHelper(ImGuiStyleVar.FramePadding, this.FramePadding);
this.PushStyleHelper(ImGuiStyleVar.FrameRounding, this.FrameRounding);
this.PushStyleHelper(ImGuiStyleVar.FrameBorderSize, this.FrameBorderSize);
this.PushStyleHelper(ImGuiStyleVar.ItemSpacing, this.ItemSpacing);
this.PushStyleHelper(ImGuiStyleVar.ItemInnerSpacing, this.ItemInnerSpacing);
this.PushStyleHelper(ImGuiStyleVar.CellPadding, this.CellPadding);
this.PushStyleHelper(ImGuiStyleVar.IndentSpacing, this.IndentSpacing);
this.PushStyleHelper(ImGuiStyleVar.ScrollbarSize, this.ScrollbarSize);
this.PushStyleHelper(ImGuiStyleVar.ScrollbarRounding, this.ScrollbarRounding);
this.PushStyleHelper(ImGuiStyleVar.GrabMinSize, this.GrabMinSize);
this.PushStyleHelper(ImGuiStyleVar.GrabRounding, this.GrabRounding);
this.PushStyleHelper(ImGuiStyleVar.TabRounding, this.TabRounding);
this.PushStyleHelper(ImGuiStyleVar.ButtonTextAlign, this.ButtonTextAlign);
this.PushStyleHelper(ImGuiStyleVar.SelectableTextAlign, this.SelectableTextAlign);
/// <inheritdoc/>
public override void Pop()
{
throw new NotImplementedException();
foreach (var imGuiCol in Enum.GetValues<ImGuiCol>())
{
if (imGuiCol == ImGuiCol.COUNT)
{
continue;
}
this.PushColorHelper(imGuiCol, this.Colors[imGuiCol.ToString()]);
}
this.DonePushing();
}
}
}