using Dalamud.Interface.Windowing; using ImGuiNET; using Ktisis.Structs.Env.Weather; using System; using System.Numerics; namespace VoidBox.Windows; public class ConfigWindow : Window, IDisposable { private string? _renamingName; private SavedEnv? _renaming; public ConfigWindow() : base( "VoidBox", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) { SizeConstraints = new() { MinimumSize = new Vector2(430, 184) }; Size = SizeConstraints.Value.MinimumSize; SizeCondition = ImGuiCond.FirstUseEver; } public void Dispose() { } public override void Draw() { var config = Service.Config; if (ImGui.Checkbox("Enabled", ref config.IsEnabled)) { config.Save(); } ImGui.Columns(2, "", false); if (ImGui.BeginListBox("", new Vector2(-1f, ImGui.GetContentRegionAvail().Y - ImGui.CalcTextSize("").Y - ImGui.GetStyle().ItemSpacing.Y * 2f))) { foreach (var entry in Service.Envs.Copy()) { AddMainEntry(entry); } ImGui.EndListBox(); } if (ImGui.Button("Add current")) { config.Envs.Add(new SavedEnv($"Saved #{config.Envs.Count + 1}", Service.Plugin.Current)); config.Save(); } ImGui.NextColumn(); if (ImGui.BeginCombo("Login", (config.LoginEnv ?? SavedEnv.Unchanged).Name)) { var env = config.LoginEnv; foreach (var entry in Service.Envs) { if (AddComboEntry(entry, ref env)) { config.LoginEnv = env; config.Save(); } } ImGui.EndCombo(); } if (ImGui.BeginCombo("Housing", (config.HousingEnv ?? SavedEnv.Unchanged).Name)) { var env = config.HousingEnv; foreach (var entry in Service.Envs) { if (AddComboEntry(entry, ref env)) { config.HousingEnv = env; config.Save(); } } ImGui.EndCombo(); } void AddMainEntry(EnvCollectionEntry entry) { (SavedEnv env, bool isBuiltin) = entry; bool isPreview = Service.Plugin.Preview == env; bool isDefault = env.Env == null; bool isRenaming = _renaming == env; bool isStyled = false; if (isPreview) { ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.8f, 0.3f, 0.9f, 1f)); isStyled = true; } else if (isDefault) { ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.8f, 0.3f, 0.3f, 1f)); isStyled = true; } else if (isBuiltin) { ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.6f, 0.7f, 0.8f, 1f)); isStyled = true; } if (_renaming == env) { ImGui.PushItemWidth(ImGui.GetContentRegionAvail().X); if (ImGui.InputText("", ref _renamingName, 128, ImGuiInputTextFlags.EnterReturnsTrue)) { _renaming.Name = _renamingName; _renaming = null; config.Save(); } ImGui.PopItemWidth(); } else { ImGui.Selectable(env.Name, false, ImGuiSelectableFlags.None); } if (isStyled) { ImGui.PopStyleColor(); } bool isHovered = ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled); bool isLMB = isHovered && ImGui.IsMouseClicked(ImGuiMouseButton.Left); bool isRMB = isHovered && ImGui.IsMouseClicked(ImGuiMouseButton.Right); if (isHovered) { if (isDefault) { ImGui.SetTooltip("LMB to disable preview."); } else if (isBuiltin) { ImGui.SetTooltip("LMB to toggle preview. Built-in preset."); } else { ImGui.SetTooltip("LMB to toggle preview, RMB to rename, CTRL-RMB to remove."); } } if (isLMB && !isRenaming) { Service.Plugin.Preview = isPreview ? null : isDefault ? null : env; } if (!isBuiltin && isRMB) { if (ImGui.IsKeyDown(ImGuiKey.ModCtrl)) { if (isRenaming) { _renaming = null; } else { if (isPreview) { Service.Plugin.Preview = null; } config.Envs.Remove(env); config.Save(); } } else { _renamingName = env.Name; _renaming = env; } } } bool AddComboEntry(EnvCollectionEntry entry, ref SavedEnv? curr) { (SavedEnv env, bool isBuiltin) = entry; SavedEnv? set = env.Env == null ? null : env; if (ImGui.Selectable(env.Name, set == curr, ImGuiSelectableFlags.None)) { curr = set; return true; } return false; } } }