mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
chore: some imraii conversion
This commit is contained in:
parent
14ce85627d
commit
1ce98a2350
8 changed files with 115 additions and 109 deletions
|
|
@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Numerics;
|
||||
|
||||
using Dalamud.Game.ClientState.Keys;
|
||||
using Dalamud.Interface.Raii;
|
||||
using ImGuiNET;
|
||||
using ImGuiScene;
|
||||
|
||||
|
|
@ -161,9 +162,10 @@ public static class ImGuiHelpers
|
|||
/// <param name="text">The text to write.</param>
|
||||
public static void SafeTextColoredWrapped(Vector4 color, string text)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, color);
|
||||
ImGui.TextWrapped(text.Replace("%", "%%"));
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, color))
|
||||
{
|
||||
ImGui.TextWrapped(text.Replace("%", "%%"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using Dalamud.Interface.Internal.Windows.PluginInstaller;
|
|||
using Dalamud.Interface.Internal.Windows.SelfTest;
|
||||
using Dalamud.Interface.Internal.Windows.Settings;
|
||||
using Dalamud.Interface.Internal.Windows.StyleEditor;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Interface.Style;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Logging;
|
||||
|
|
@ -522,7 +523,8 @@ internal class DalamudInterface : IDisposable, IServiceType
|
|||
|
||||
private void DrawCreditsDarkeningAnimation()
|
||||
{
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0f);
|
||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.WindowRounding, 0f);
|
||||
|
||||
ImGui.SetNextWindowPos(new Vector2(0, 0));
|
||||
ImGui.SetNextWindowSize(ImGuiHelpers.MainViewport.Size);
|
||||
ImGuiHelpers.ForceNextWindowMainViewport();
|
||||
|
|
@ -536,8 +538,6 @@ internal class DalamudInterface : IDisposable, IServiceType
|
|||
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags.NoNav);
|
||||
ImGui.End();
|
||||
|
||||
ImGui.PopStyleVar();
|
||||
}
|
||||
|
||||
private void DrawHiddenDevMenuOpener()
|
||||
|
|
@ -546,18 +546,17 @@ internal class DalamudInterface : IDisposable, IServiceType
|
|||
|
||||
if (!this.isImGuiDrawDevMenu && !condition.Any())
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero);
|
||||
ImGui.PushStyleColor(ImGuiCol.TextSelectedBg, new Vector4(0, 0, 0, 1));
|
||||
ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(0, 0, 0, 1));
|
||||
ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 1));
|
||||
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 1));
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Button, Vector4.Zero);
|
||||
color.Push(ImGuiCol.ButtonActive, Vector4.Zero);
|
||||
color.Push(ImGuiCol.ButtonHovered, Vector4.Zero);
|
||||
color.Push(ImGuiCol.TextSelectedBg, new Vector4(0, 0, 0, 1));
|
||||
color.Push(ImGuiCol.Border, new Vector4(0, 0, 0, 1));
|
||||
color.Push(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 1));
|
||||
color.Push(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 1));
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 0);
|
||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, Vector2.Zero);
|
||||
style.Push(ImGuiStyleVar.WindowBorderSize, 0);
|
||||
style.Push(ImGuiStyleVar.FrameBorderSize, 0);
|
||||
|
||||
var windowPos = ImGui.GetMainViewport().Pos + new Vector2(20);
|
||||
ImGui.SetNextWindowPos(windowPos, ImGuiCond.Always);
|
||||
|
|
@ -589,9 +588,6 @@ internal class DalamudInterface : IDisposable, IServiceType
|
|||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
ImGui.PopStyleVar(4);
|
||||
ImGui.PopStyleColor(7);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using CheapLoc;
|
|||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Internal.Windows.Settings.Tabs;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Utility;
|
||||
|
|
@ -159,33 +160,27 @@ internal class SettingsWindow : Window
|
|||
|
||||
if (ImGui.BeginChild("###settingsFinishButton"))
|
||||
{
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 100f);
|
||||
ImGui.PushFont(InterfaceManager.IconFont);
|
||||
using var disabled = ImRaii.Disabled(this.tabs.Any(x => x.Entries.Any(y => !y.IsValid)));
|
||||
|
||||
var invalid = this.tabs.Any(x => x.Entries.Any(y => !y.IsValid));
|
||||
if (invalid)
|
||||
ImGui.BeginDisabled();
|
||||
|
||||
if (ImGui.Button(FontAwesomeIcon.Save.ToIconString(), new Vector2(40)))
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 100f))
|
||||
{
|
||||
this.Save();
|
||||
using var font = ImRaii.PushFont(InterfaceManager.IconFont);
|
||||
|
||||
if (!ImGui.IsKeyDown(ImGuiKey.ModShift))
|
||||
this.IsOpen = false;
|
||||
if (ImGui.Button(FontAwesomeIcon.Save.ToIconString(), new Vector2(40)))
|
||||
{
|
||||
this.Save();
|
||||
|
||||
if (!ImGui.IsKeyDown(ImGuiKey.ModShift))
|
||||
this.IsOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopStyleVar();
|
||||
ImGui.PopFont();
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.SetTooltip(!ImGui.IsKeyDown(ImGuiKey.ModShift)
|
||||
? Loc.Localize("DalamudSettingsSaveAndExit", "Save changes and close")
|
||||
: Loc.Localize("DalamudSettingsSaveAndExit", "Save changes"));
|
||||
}
|
||||
|
||||
if (invalid)
|
||||
ImGui.EndDisabled();
|
||||
}
|
||||
|
||||
ImGui.EndChild();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Numerics;
|
|||
using CheapLoc;
|
||||
using Dalamud.Game.Gui;
|
||||
using Dalamud.Interface.GameFonts;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Utility;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.UI;
|
||||
|
|
@ -243,46 +244,45 @@ Contribute at: https://github.com/goatcorp/Dalamud
|
|||
this.resetNow = false;
|
||||
}
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 20f);
|
||||
ImGui.Text(string.Empty);
|
||||
|
||||
const float imageSize = 190f;
|
||||
ImGui.SameLine((ImGui.GetWindowWidth() / 2) - (imageSize / 2));
|
||||
ImGui.Image(this.logoTexture.ImGuiHandle, ImGuiHelpers.ScaledVector2(imageSize));
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, 20f);
|
||||
|
||||
var windowX = ImGui.GetWindowSize().X;
|
||||
|
||||
foreach (var creditsLine in this.creditsText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None))
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
|
||||
{
|
||||
var lineLenX = ImGui.CalcTextSize(creditsLine).X;
|
||||
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 20f);
|
||||
ImGui.Text(string.Empty);
|
||||
|
||||
ImGui.Dummy(new Vector2((windowX / 2) - (lineLenX / 2), 0f));
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted(creditsLine);
|
||||
const float imageSize = 190f;
|
||||
ImGui.SameLine((ImGui.GetWindowWidth() / 2) - (imageSize / 2));
|
||||
ImGui.Image(this.logoTexture.ImGuiHandle, ImGuiHelpers.ScaledVector2(imageSize));
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, 20f);
|
||||
|
||||
var windowX = ImGui.GetWindowSize().X;
|
||||
|
||||
foreach (var creditsLine in this.creditsText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None))
|
||||
{
|
||||
var lineLenX = ImGui.CalcTextSize(creditsLine).X;
|
||||
|
||||
ImGui.Dummy(new Vector2((windowX / 2) - (lineLenX / 2), 0f));
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted(creditsLine);
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, 40f);
|
||||
|
||||
if (this.thankYouFont != null)
|
||||
{
|
||||
ImGui.PushFont(this.thankYouFont.ImFont);
|
||||
var thankYouLenX = ImGui.CalcTextSize(ThankYouText).X;
|
||||
|
||||
ImGui.Dummy(new Vector2((windowX / 2) - (thankYouLenX / 2), 0f));
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted(ThankYouText);
|
||||
|
||||
ImGui.PopFont();
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 50f);
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, 40f);
|
||||
|
||||
if (this.thankYouFont != null)
|
||||
{
|
||||
ImGui.PushFont(this.thankYouFont.ImFont);
|
||||
var thankYouLenX = ImGui.CalcTextSize(ThankYouText).X;
|
||||
|
||||
ImGui.Dummy(new Vector2((windowX / 2) - (thankYouLenX / 2), 0f));
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted(ThankYouText);
|
||||
|
||||
ImGui.PopFont();
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 50f);
|
||||
|
||||
ImGui.PopStyleVar();
|
||||
|
||||
if (this.creditsThrottler.Elapsed.TotalMilliseconds > (1000.0f / CreditFps))
|
||||
{
|
||||
var curY = ImGui.GetScrollY();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Dalamud.Configuration;
|
|||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -57,10 +58,11 @@ public class DevPluginsSettingsEntry : SettingsEntry
|
|||
ImGui.Text(this.Name);
|
||||
if (this.devPluginLocationsChanged)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen))
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add additional dev plugin load locations.\nThese can be either the directory or DLL path."));
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||
using Dalamud.Configuration.Internal;
|
||||
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -121,9 +122,11 @@ internal sealed class SettingsEntry<T> : SettingsEntry
|
|||
}
|
||||
}
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey);
|
||||
ImGuiHelpers.SafeTextWrapped(this.Description);
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudGrey))
|
||||
{
|
||||
ImGuiHelpers.SafeTextWrapped(this.Description);
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
if (this.CheckValidity != null)
|
||||
{
|
||||
|
|
@ -132,9 +135,11 @@ internal sealed class SettingsEntry<T> : SettingsEntry
|
|||
|
||||
if (!this.IsValid)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
ImGui.Text(validityMsg);
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed))
|
||||
{
|
||||
ImGui.Text(validityMsg);
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -146,9 +151,11 @@ internal sealed class SettingsEntry<T> : SettingsEntry
|
|||
|
||||
if (warningMessage != null)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||
ImGui.Text(warningMessage);
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed))
|
||||
{
|
||||
ImGui.Text(warningMessage);
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Dalamud.Configuration;
|
|||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -53,10 +54,11 @@ public class ThirdRepoSettingsEntry : SettingsEntry
|
|||
ImGui.Text(Loc.Localize("DalamudSettingsCustomRepo", "Custom Plugin Repositories"));
|
||||
if (this.thirdRepoListChanged)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
|
||||
ImGui.PopStyleColor();
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen))
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingCustomRepoHint", "Add custom plugin repositories."));
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Dalamud.Game;
|
|||
using Dalamud.Game.ClientState;
|
||||
using Dalamud.Game.Gui;
|
||||
using Dalamud.Interface.Animation.EasingFunctions;
|
||||
using Dalamud.Interface.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using ImGuiNET;
|
||||
using ImGuiScene;
|
||||
|
|
@ -169,23 +170,22 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
|
||||
this.fadeOutEasing.Update();
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value);
|
||||
|
||||
for (var i = 0; i < tsm.Entries.Count; i++)
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
|
||||
{
|
||||
var entry = tsm.Entries[i];
|
||||
for (var i = 0; i < tsm.Entries.Count; i++)
|
||||
{
|
||||
var entry = tsm.Entries[i];
|
||||
|
||||
var finalPos = (i + 1) * this.shadeTexture.Height * scale;
|
||||
var finalPos = (i + 1) * this.shadeTexture.Height * scale;
|
||||
|
||||
this.DrawEntry(entry, i != 0, true, i == 0, false, false);
|
||||
this.DrawEntry(entry, i != 0, true, i == 0, false, false);
|
||||
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
cursor.Y = finalPos;
|
||||
ImGui.SetCursorPos(cursor);
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
cursor.Y = finalPos;
|
||||
ImGui.SetCursorPos(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopStyleVar();
|
||||
|
||||
var isHover = ImGui.IsWindowHovered(ImGuiHoveredFlags.RootAndChildWindows |
|
||||
ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
|
||||
|
||||
|
|
@ -254,9 +254,11 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
|
||||
var initialCursor = ImGui.GetCursorPos();
|
||||
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)shadeEasing.Value);
|
||||
ImGui.Image(this.shadeTexture.ImGuiHandle, new Vector2(this.shadeTexture.Width * scale, this.shadeTexture.Height * scale));
|
||||
ImGui.PopStyleVar();
|
||||
|
||||
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.Value))
|
||||
{
|
||||
ImGui.Image(this.shadeTexture.ImGuiHandle, new Vector2(this.shadeTexture.Width * scale, this.shadeTexture.Height * scale));
|
||||
}
|
||||
|
||||
var isHover = ImGui.IsItemHovered();
|
||||
if (isHover && (!shadeEasing.IsRunning || (shadeEasing.IsDone && shadeEasing.IsInverse)) && !inhibitFadeout)
|
||||
|
|
@ -331,15 +333,15 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
}
|
||||
|
||||
// Drop shadow
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, 0xFF000000);
|
||||
for (int i = 0, i_ = (int)Math.Ceiling(1 * scale); i < i_; i++)
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, 0xFF000000))
|
||||
{
|
||||
ImGui.SetCursorPos(new Vector2(cursor.X, cursor.Y + i));
|
||||
ImGui.Text(entry.Name);
|
||||
for (int i = 0, i_ = (int)Math.Ceiling(1 * scale); i < i_; i++)
|
||||
{
|
||||
ImGui.SetCursorPos(new Vector2(cursor.X, cursor.Y + i));
|
||||
ImGui.Text(entry.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGui.SetCursorPos(cursor);
|
||||
ImGui.Text(entry.Name);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue