feat: add new settings ui

Also add window display options.
This commit is contained in:
Anna
2022-01-15 14:27:56 -05:00
parent c835167e33
commit b34a855a92
8 changed files with 239 additions and 156 deletions
+32 -153
View File
@@ -1,8 +1,6 @@
using System.Numerics;
using ChatTwo.Code;
using ChatTwo.Util;
using ChatTwo.Ui.SettingsTabs;
using Dalamud.Game.Command;
using Dalamud.Interface;
using ImGuiNET;
namespace ChatTwo.Ui;
@@ -10,17 +8,19 @@ namespace ChatTwo.Ui;
internal sealed class Settings : IUiComponent {
private PluginUi Ui { get; }
private bool _hideChat;
private bool _nativeItemTooltips;
private bool _sidebarTabView;
private bool _prettierTimestamps;
private bool _moreCompactPretty;
private float _fontSize;
private Dictionary<ChatType, uint> _chatColours = new();
private List<Tab> _tabs = new();
private Configuration Mutable { get; }
private List<ISettingsTab> Tabs { get; }
internal Settings(PluginUi ui) {
this.Ui = ui;
this.Mutable = new Configuration();
this.Tabs = new List<ISettingsTab> {
new Display(this.Mutable),
new ChatColours(this.Mutable),
new Tabs(this.Mutable),
};
this.Ui.Plugin.CommandManager.AddHandler("/chat2", new CommandInfo(this.Command) {
HelpMessage = "Toggle the Chat 2 settings",
});
@@ -35,15 +35,7 @@ internal sealed class Settings : IUiComponent {
}
private void Initialise() {
var config = this.Ui.Plugin.Config;
this._hideChat = config.HideChat;
this._nativeItemTooltips = config.NativeItemTooltips;
this._sidebarTabView = config.SidebarTabView;
this._prettierTimestamps = config.PrettierTimestamps;
this._moreCompactPretty = config.MoreCompactPretty;
this._fontSize = config.FontSize;
this._chatColours = config.ChatColours.ToDictionary(entry => entry.Key, entry => entry.Value);
this._tabs = config.Tabs.Select(tab => tab.Clone()).ToList();
this.Mutable.UpdateFrom(this.Ui.Plugin.Config);
}
public void Draw() {
@@ -60,132 +52,26 @@ internal sealed class Settings : IUiComponent {
this.Initialise();
}
var height = ImGui.GetContentRegionAvail().Y
- ImGui.GetStyle().FramePadding.Y * 2
- ImGui.GetStyle().ItemSpacing.Y
- ImGui.GetStyle().ItemInnerSpacing.Y * 2
- ImGui.CalcTextSize("A").Y;
if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) {
ImGui.Checkbox("Hide chat", ref this._hideChat);
ImGui.Checkbox("Show native item tooltips", ref this._nativeItemTooltips);
ImGui.Checkbox("Show tabs in a sidebar", ref this._sidebarTabView);
ImGui.Checkbox("Use modern timestamp layout", ref this._prettierTimestamps);
if (this._prettierTimestamps) {
ImGui.Checkbox("More compact modern layout", ref this._moreCompactPretty);
}
ImGui.DragFloat("Font size", ref this._fontSize, .0125f, 12f, 36f, "%.1f");
if (ImGui.TreeNodeEx("Chat colours")) {
foreach (var type in Enum.GetValues<ChatType>()) {
if (ImGui.Button($"Default##{type}")) {
this._chatColours.Remove(type);
}
ImGui.SameLine();
var vec = this._chatColours.TryGetValue(type, out var colour)
? ColourUtil.RgbaToVector3(colour)
: ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0);
if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) {
this._chatColours[type] = ColourUtil.Vector3ToRgba(vec);
}
if (ImGui.BeginTabBar("settings-tabs")) {
foreach (var settingsTab in this.Tabs) {
if (!ImGui.BeginTabItem(settingsTab.Name)) {
continue;
}
ImGui.TreePop();
var height = ImGui.GetContentRegionAvail().Y
- ImGui.GetStyle().FramePadding.Y * 2
- ImGui.GetStyle().ItemSpacing.Y
- ImGui.GetStyle().ItemInnerSpacing.Y * 2
- ImGui.CalcTextSize("A").Y;
if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) {
settingsTab.Draw();
ImGui.EndChild();
}
ImGui.EndTabItem();
}
if (ImGui.TreeNodeEx("Tabs")) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) {
this._tabs.Add(new Tab());
}
var toRemove = -1;
for (var i = 0; i < this._tabs.Count; i++) {
var tab = this._tabs[i];
if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) {
ImGui.PushID($"tab-{i}");
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) {
toRemove = i;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) {
(this._tabs[i - 1], this._tabs[i]) = (this._tabs[i], this._tabs[i - 1]);
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this._tabs.Count - 1) {
(this._tabs[i + 1], this._tabs[i]) = (this._tabs[i], this._tabs[i + 1]);
}
ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue);
ImGui.Checkbox("Show unread count", ref tab.DisplayUnread);
ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp);
var input = tab.Channel?.ToChatType().Name() ?? "<None>";
if (ImGui.BeginCombo("Input channel", input)) {
if (ImGui.Selectable("<None>", tab.Channel == null)) {
tab.Channel = null;
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) {
tab.Channel = channel;
}
}
ImGui.EndCombo();
}
if (ImGui.TreeNodeEx("Channels")) {
foreach (var type in Enum.GetValues<ChatType>()) {
var enabled = tab.ChatCodes.ContainsKey(type);
if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) {
if (enabled) {
tab.ChatCodes[type] = ChatSourceExt.All;
} else {
tab.ChatCodes.Remove(type);
}
}
ImGui.SameLine();
if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) {
tab.ChatCodes.TryGetValue(type, out var sourcesEnum);
var sources = (uint) sourcesEnum;
foreach (var source in Enum.GetValues<ChatSource>()) {
if (ImGui.CheckboxFlags(source.ToString(), ref sources, (uint) source)) {
tab.ChatCodes[type] = (ChatSource) sources;
}
}
ImGui.TreePop();
}
}
ImGui.TreePop();
}
ImGui.TreePop();
ImGui.PopID();
}
}
if (toRemove > -1) {
this._tabs.RemoveAt(toRemove);
}
}
ImGui.EndChild();
ImGui.EndTabBar();
}
ImGui.Separator();
@@ -210,17 +96,10 @@ internal sealed class Settings : IUiComponent {
if (save) {
var config = this.Ui.Plugin.Config;
var hideChatChanged = this._hideChat != this.Ui.Plugin.Config.HideChat;
var fontSizeChanged = Math.Abs(this._fontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon;
var hideChatChanged = this.Mutable.HideChat != this.Ui.Plugin.Config.HideChat;
var fontSizeChanged = Math.Abs(this.Mutable.FontSize - this.Ui.Plugin.Config.FontSize) > float.Epsilon;
config.HideChat = this._hideChat;
config.NativeItemTooltips = this._nativeItemTooltips;
config.SidebarTabView = this._sidebarTabView;
config.PrettierTimestamps = this._prettierTimestamps;
config.MoreCompactPretty = this._moreCompactPretty;
config.FontSize = this._fontSize;
config.ChatColours = this._chatColours;
config.Tabs = this._tabs;
config.UpdateFrom(this.Mutable);
this.Ui.Plugin.SaveConfig();
@@ -230,7 +109,7 @@ internal sealed class Settings : IUiComponent {
this.Ui.Plugin.Interface.UiBuilder.RebuildFonts();
}
if (!this._hideChat && hideChatChanged) {
if (!this.Mutable.HideChat && hideChatChanged) {
GameFunctions.GameFunctions.SetChatInteractable(true);
}