mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-22 00:19:18 +01:00
Merge pull request #306 from kalilistic/imgui-colors
feat: add imgui color helper
This commit is contained in:
commit
542bda4dfb
6 changed files with 166 additions and 17 deletions
61
Dalamud/Interface/Colors/ColorDemoWindow.cs
Normal file
61
Dalamud/Interface/Colors/ColorDemoWindow.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
using Dalamud.Interface.Windowing;
|
||||||
|
using ImGuiNET;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface.Colors
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// color Demo Window to view custom ImGui colors.
|
||||||
|
/// </summary>
|
||||||
|
internal class ColorDemoWindow : Window
|
||||||
|
{
|
||||||
|
private readonly List<KeyValuePair<string, Vector4>> colors;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ColorDemoWindow"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public ColorDemoWindow()
|
||||||
|
: base("Dalamud Colors Demo")
|
||||||
|
{
|
||||||
|
this.Size = new Vector2(600, 500);
|
||||||
|
this.SizeCondition = ImGuiCond.FirstUseEver;
|
||||||
|
this.colors = new List<KeyValuePair<string, Vector4>>
|
||||||
|
{
|
||||||
|
Demo("White", ImGuiColors.White),
|
||||||
|
Demo("DalamudRed", ImGuiColors.DalamudRed),
|
||||||
|
Demo("DalamudGrey", ImGuiColors.DalamudGrey),
|
||||||
|
Demo("DalamudGrey2", ImGuiColors.DalamudGrey2),
|
||||||
|
Demo("DalamudGrey3", ImGuiColors.DalamudGrey3),
|
||||||
|
Demo("DalamudWhite", ImGuiColors.DalamudWhite),
|
||||||
|
Demo("DalamudWhite2", ImGuiColors.DalamudWhite2),
|
||||||
|
Demo("DalamudOrange", ImGuiColors.DalamudOrange),
|
||||||
|
Demo("TankBlue", ImGuiColors.TankBlue),
|
||||||
|
Demo("HealerGreen", ImGuiColors.HealerGreen),
|
||||||
|
Demo("DPSRed", ImGuiColors.DPSRed),
|
||||||
|
};
|
||||||
|
this.colors = this.colors.OrderBy(colorDemo => colorDemo.Key).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Draw()
|
||||||
|
{
|
||||||
|
ImGui.BeginChild("color_scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.AlwaysVerticalScrollbar | ImGuiWindowFlags.HorizontalScrollbar);
|
||||||
|
ImGui.Text("This is a collection of UI colors you can use in your plugin.");
|
||||||
|
ImGui.Separator();
|
||||||
|
foreach (var color in this.colors)
|
||||||
|
{
|
||||||
|
ImGui.TextColored(color.Value, color.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static KeyValuePair<string, Vector4> Demo(string name, Vector4 color)
|
||||||
|
{
|
||||||
|
return new KeyValuePair<string, Vector4>(name, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Dalamud/Interface/Colors/ImGuiColors.cs
Normal file
65
Dalamud/Interface/Colors/ImGuiColors.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface.Colors
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class containing frequently used colors for easier reference.
|
||||||
|
/// </summary>
|
||||||
|
public static class ImGuiColors
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets white color.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 White { get; } = new Vector4(255, 255, 255, 1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets red used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudRed { get; } = new Vector4(1f, 0f, 0f, 1f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets grey used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudGrey { get; } = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets grey used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudGrey2 { get; } = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets grey used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudGrey3 { get; } = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets white used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudWhite { get; } = new Vector4(1f, 1f, 1f, 1f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets white used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudWhite2 { get; } = new Vector4(0.878f, 0.878f, 0.878f, 1f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets orange used in dalamud.
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DalamudOrange { get; } = new Vector4(1f, 0.709f, 0f, 1f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets tank blue (UIColor37).
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 TankBlue { get; } = new Vector4(0, 0.6f, 1, 1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets healer green (UIColor504).
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 HealerGreen { get; } = new Vector4(0, 0.8f, 0.1333333f, 1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets dps red (UIColor545).
|
||||||
|
/// </summary>
|
||||||
|
public static Vector4 DPSRed { get; } = new Vector4(0.7058824f, 0, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
|
|
@ -31,6 +32,7 @@ namespace Dalamud.Interface
|
||||||
private readonly DalamudPluginStatWindow pluginStatWindow;
|
private readonly DalamudPluginStatWindow pluginStatWindow;
|
||||||
private readonly DalamudChangelogWindow changelogWindow;
|
private readonly DalamudChangelogWindow changelogWindow;
|
||||||
private readonly ComponentDemoWindow componentDemoWindow;
|
private readonly ComponentDemoWindow componentDemoWindow;
|
||||||
|
private readonly ColorDemoWindow colorDemoWindow;
|
||||||
|
|
||||||
private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore");
|
private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore");
|
||||||
|
|
||||||
|
|
@ -100,6 +102,12 @@ namespace Dalamud.Interface
|
||||||
};
|
};
|
||||||
this.windowSystem.AddWindow(this.componentDemoWindow);
|
this.windowSystem.AddWindow(this.componentDemoWindow);
|
||||||
|
|
||||||
|
this.colorDemoWindow = new ColorDemoWindow()
|
||||||
|
{
|
||||||
|
IsOpen = false,
|
||||||
|
};
|
||||||
|
this.windowSystem.AddWindow(this.colorDemoWindow);
|
||||||
|
|
||||||
Log.Information("[DUI] Windows added");
|
Log.Information("[DUI] Windows added");
|
||||||
|
|
||||||
if (dalamud.Configuration.LogOpenAtStartup)
|
if (dalamud.Configuration.LogOpenAtStartup)
|
||||||
|
|
@ -208,6 +216,11 @@ namespace Dalamud.Interface
|
||||||
this.OpenComponentDemo();
|
this.OpenComponentDemo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui.MenuItem("Open Colors Demo"))
|
||||||
|
{
|
||||||
|
this.OpenColorsDemo();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
|
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
@ -420,6 +433,14 @@ namespace Dalamud.Interface
|
||||||
this.componentDemoWindow.IsOpen = true;
|
this.componentDemoWindow.IsOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open the colors test window.
|
||||||
|
/// </summary>
|
||||||
|
internal void OpenColorsDemo()
|
||||||
|
{
|
||||||
|
this.colorDemoWindow.IsOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Toggle the Plugin Installer window.
|
/// Toggle the Plugin Installer window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -46,13 +47,13 @@ namespace Dalamud.Interface
|
||||||
{
|
{
|
||||||
var color = logEvent.level switch
|
var color = logEvent.level switch
|
||||||
{
|
{
|
||||||
LogEventLevel.Error => new Vector4(1f, 0f, 0f, 1f),
|
LogEventLevel.Error => ImGuiColors.DalamudRed,
|
||||||
LogEventLevel.Verbose => new Vector4(1f, 1f, 1f, 1f),
|
LogEventLevel.Verbose => ImGuiColors.DalamudWhite,
|
||||||
LogEventLevel.Debug => new Vector4(0.878f, 0.878f, 0.878f, 1f),
|
LogEventLevel.Debug => ImGuiColors.DalamudWhite2,
|
||||||
LogEventLevel.Information => new Vector4(1f, 1f, 1f, 1f),
|
LogEventLevel.Information => ImGuiColors.DalamudWhite,
|
||||||
LogEventLevel.Warning => new Vector4(1f, 0.709f, 0f, 1f),
|
LogEventLevel.Warning => ImGuiColors.DalamudOrange,
|
||||||
LogEventLevel.Fatal => new Vector4(1f, 0f, 0f, 1f),
|
LogEventLevel.Fatal => ImGuiColors.DalamudRed,
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
_ => throw new ArgumentOutOfRangeException(),
|
||||||
};
|
};
|
||||||
|
|
||||||
AddLog(logEvent.line, color);
|
AddLog(logEvent.line, color);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Windows.Forms.VisualStyles;
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -114,8 +115,8 @@ namespace Dalamud.Interface
|
||||||
private string[] locLanguages;
|
private string[] locLanguages;
|
||||||
private int langIndex;
|
private int langIndex;
|
||||||
|
|
||||||
private Vector4 hintTextColor = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
|
private Vector4 hintTextColor = ImGuiColors.DalamudGrey;
|
||||||
private Vector4 warnTextColor = new Vector4(1.0f, 0.0f, 0.0f, 1.00f);
|
private Vector4 warnTextColor = ImGuiColors.DalamudRed;
|
||||||
|
|
||||||
private XivChatType dalamudMessagesChatType;
|
private XivChatType dalamudMessagesChatType;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -19,7 +20,6 @@ namespace Dalamud.Plugin
|
||||||
internal class PluginInstallerWindow : Window
|
internal class PluginInstallerWindow : Window
|
||||||
{
|
{
|
||||||
private readonly Dalamud dalamud;
|
private readonly Dalamud dalamud;
|
||||||
private readonly Vector4 colorGrey = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
|
|
||||||
|
|
||||||
private string gameVersion;
|
private string gameVersion;
|
||||||
|
|
||||||
|
|
@ -326,7 +326,7 @@ namespace Dalamud.Plugin
|
||||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5);
|
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5);
|
||||||
|
|
||||||
if (statusText != null)
|
if (statusText != null)
|
||||||
ImGui.TextColored(this.colorGrey, statusText);
|
ImGui.TextColored(ImGuiColors.DalamudGrey, statusText);
|
||||||
else
|
else
|
||||||
this.DrawPluginList(installed ? this.pluginListInstalled : this.pluginListAvailable, installed);
|
this.DrawPluginList(installed ? this.pluginListInstalled : this.pluginListAvailable, installed);
|
||||||
|
|
||||||
|
|
@ -422,7 +422,7 @@ namespace Dalamud.Plugin
|
||||||
: ", download count unavailable";
|
: ", download count unavailable";
|
||||||
if (pluginDefinition.RepoNumber != 0)
|
if (pluginDefinition.RepoNumber != 0)
|
||||||
info += $", from custom plugin repository #{pluginDefinition.RepoNumber}";
|
info += $", from custom plugin repository #{pluginDefinition.RepoNumber}";
|
||||||
ImGui.TextColored(new Vector4(0.5f, 0.5f, 0.5f, 1.0f), info);
|
ImGui.TextColored(ImGuiColors.DalamudGrey3, info);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(pluginDefinition.Description))
|
if (!string.IsNullOrWhiteSpace(pluginDefinition.Description))
|
||||||
ImGui.TextWrapped(pluginDefinition.Description);
|
ImGui.TextWrapped(pluginDefinition.Description);
|
||||||
|
|
@ -526,13 +526,13 @@ namespace Dalamud.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.TextColored(new Vector4(0.5f, 0.5f, 0.5f, 1.0f), $" v{installedPlugin.Definition.AssemblyVersion}");
|
ImGui.TextColored(ImGuiColors.DalamudGrey3, $" v{installedPlugin.Definition.AssemblyVersion}");
|
||||||
|
|
||||||
if (installedPlugin.IsRaw)
|
if (installedPlugin.IsRaw)
|
||||||
{
|
{
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.TextColored(
|
ImGui.TextColored(
|
||||||
new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
|
ImGuiColors.DalamudRed,
|
||||||
this.dalamud.PluginRepository.PluginMaster.Any(x => x.InternalName == installedPlugin.Definition.InternalName)
|
this.dalamud.PluginRepository.PluginMaster.Any(x => x.InternalName == installedPlugin.Definition.InternalName)
|
||||||
? " This plugin is available in one of your repos, please remove it from the devPlugins folder."
|
? " This plugin is available in one of your repos, please remove it from the devPlugins folder."
|
||||||
: " To disable this plugin, please remove it from the devPlugins folder.");
|
: " To disable this plugin, please remove it from the devPlugins folder.");
|
||||||
|
|
@ -557,7 +557,7 @@ namespace Dalamud.Plugin
|
||||||
if (installed)
|
if (installed)
|
||||||
{
|
{
|
||||||
ImGui.TextColored(
|
ImGui.TextColored(
|
||||||
this.colorGrey,
|
ImGuiColors.DalamudGrey,
|
||||||
Loc.Localize(
|
Loc.Localize(
|
||||||
"InstallerNoInstalled",
|
"InstallerNoInstalled",
|
||||||
"No plugins are currently installed. You can install them from the Available Plugins tab."));
|
"No plugins are currently installed. You can install them from the Available Plugins tab."));
|
||||||
|
|
@ -565,7 +565,7 @@ namespace Dalamud.Plugin
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui.TextColored(
|
ImGui.TextColored(
|
||||||
this.colorGrey,
|
ImGuiColors.DalamudGrey,
|
||||||
Loc.Localize(
|
Loc.Localize(
|
||||||
"InstallerNoCompatible",
|
"InstallerNoCompatible",
|
||||||
"No compatible plugins were found :( Please restart your game and try again."));
|
"No compatible plugins were found :( Please restart your game and try again."));
|
||||||
|
|
@ -574,7 +574,7 @@ namespace Dalamud.Plugin
|
||||||
else if (!didAnyWithSearch)
|
else if (!didAnyWithSearch)
|
||||||
{
|
{
|
||||||
ImGui.TextColored(
|
ImGui.TextColored(
|
||||||
new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
|
ImGuiColors.DalamudGrey2,
|
||||||
Loc.Localize("InstallNoMatching", "No plugins were found matching your search."));
|
Loc.Localize("InstallNoMatching", "No plugins were found matching your search."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue