feat: allow selective window fields
This commit is contained in:
parent
0b483d5af8
commit
8b1d7aee19
|
@ -4,10 +4,23 @@ using Newtonsoft.Json;
|
||||||
namespace HUD_Manager.Configuration {
|
namespace HUD_Manager.Configuration {
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Window {
|
public class Window {
|
||||||
|
public const WindowComponent AllEnabled = WindowComponent.X | WindowComponent.Y;
|
||||||
|
|
||||||
public WindowComponent Enabled { get; set; } = WindowComponent.X | WindowComponent.Y;
|
public WindowComponent Enabled { get; set; } = WindowComponent.X | WindowComponent.Y;
|
||||||
|
|
||||||
public Vector2<short> Position { get; set; }
|
public Vector2<short> Position { get; set; }
|
||||||
|
|
||||||
|
public bool this[WindowComponent component] {
|
||||||
|
get => (this.Enabled & component) > 0;
|
||||||
|
set {
|
||||||
|
if (value) {
|
||||||
|
this.Enabled |= component;
|
||||||
|
} else {
|
||||||
|
this.Enabled &= ~component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Window(WindowComponent enabled, Vector2<short> position) {
|
public Window(WindowComponent enabled, Vector2<short> position) {
|
||||||
this.Enabled = enabled;
|
this.Enabled = enabled;
|
||||||
|
@ -17,11 +30,25 @@ namespace HUD_Manager.Configuration {
|
||||||
public Window(Vector2<short> position) {
|
public Window(Vector2<short> position) {
|
||||||
this.Position = position;
|
this.Position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Window Clone() {
|
||||||
|
return new Window(this.Enabled, new Vector2<short>(this.Position.X, this.Position.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateEnabled(Window other) {
|
||||||
|
if (other[WindowComponent.X]) {
|
||||||
|
this.Position.X = other.Position.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other[WindowComponent.Y]) {
|
||||||
|
this.Position.Y = other.Position.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum WindowComponent {
|
public enum WindowComponent {
|
||||||
X,
|
X = 1 << 0,
|
||||||
Y,
|
Y = 1 << 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,15 +161,16 @@ namespace HUD_Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteEffectiveLayout(HudSlot slot, Guid id) {
|
private SavedLayout? GetEffectiveLayout(Guid id) {
|
||||||
// find the node for this id
|
// find the node for this id
|
||||||
var nodes = Node<SavedLayout>.BuildTree(this.Plugin.Config.Layouts);
|
var nodes = Node<SavedLayout>.BuildTree(this.Plugin.Config.Layouts);
|
||||||
var node = nodes.Find(id);
|
var node = nodes.Find(id);
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var elements = new Dictionary<ElementKind, Element>();
|
var elements = new Dictionary<ElementKind, Element>();
|
||||||
|
var windows = new Dictionary<string, Window>();
|
||||||
|
|
||||||
// get the ancestors and their elements for this node
|
// get the ancestors and their elements for this node
|
||||||
foreach (var ancestor in node.Ancestors().Reverse()) {
|
foreach (var ancestor in node.Ancestors().Reverse()) {
|
||||||
|
@ -181,6 +182,15 @@ namespace HUD_Manager {
|
||||||
|
|
||||||
elements[element.Key].UpdateEnabled(element.Value);
|
elements[element.Key].UpdateEnabled(element.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var window in ancestor.Value.Windows) {
|
||||||
|
if (window.Value.Enabled == Window.AllEnabled || !windows.ContainsKey(window.Key)) {
|
||||||
|
windows[window.Key] = window.Value.Clone();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
windows[window.Key].UpdateEnabled(window.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply this node's elements
|
// apply this node's elements
|
||||||
|
@ -193,7 +203,29 @@ namespace HUD_Manager {
|
||||||
elements[element.Key].UpdateEnabled(element.Value);
|
elements[element.Key].UpdateEnabled(element.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.WriteLayout(slot, elements);
|
foreach (var window in node.Value.Windows) {
|
||||||
|
if (window.Value.Enabled == Window.AllEnabled || !windows.ContainsKey(window.Key)) {
|
||||||
|
windows[window.Key] = window.Value.Clone();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
windows[window.Key].UpdateEnabled(window.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SavedLayout($"Effective {id}", elements, windows, Guid.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteEffectiveLayout(HudSlot slot, Guid id) {
|
||||||
|
var effective = this.GetEffectiveLayout(id);
|
||||||
|
if (effective == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.WriteLayout(slot, effective.Elements);
|
||||||
|
|
||||||
|
foreach (var window in effective.Windows) {
|
||||||
|
this.Plugin.GameFunctions.SetAddonPosition(window.Key, window.Value.Position.X, window.Value.Position.Y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ImportSlot(string name, HudSlot slot, bool save = true) {
|
internal void ImportSlot(string name, HudSlot slot, bool save = true) {
|
||||||
|
|
|
@ -82,16 +82,12 @@ namespace HUD_Manager {
|
||||||
return; // FIXME: do something better
|
return; // FIXME: do something better
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.Plugin.Config.Layouts.TryGetValue(layoutId, out var layout)) {
|
if (!this.Plugin.Config.Layouts.ContainsKey(layoutId)) {
|
||||||
return; // FIXME: do something better
|
return; // FIXME: do something better
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Plugin.Hud.WriteEffectiveLayout(this.Plugin.Config.StagingSlot, layoutId);
|
this.Plugin.Hud.WriteEffectiveLayout(this.Plugin.Config.StagingSlot, layoutId);
|
||||||
this.Plugin.Hud.SelectSlot(this.Plugin.Config.StagingSlot, true);
|
this.Plugin.Hud.SelectSlot(this.Plugin.Config.StagingSlot, true);
|
||||||
|
|
||||||
foreach (var entry in layout.Windows) {
|
|
||||||
this.Plugin.GameFunctions.SetAddonPosition(entry.Key, entry.Value.Position.X, entry.Value.Position.Y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using HUD_Manager.Configuration;
|
using HUD_Manager.Configuration;
|
||||||
|
@ -52,24 +53,68 @@ namespace HUD_Manager.Ui.Editor.Tabs {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pos = entry.Value.Position;
|
var maxSettingWidth = ImGui.CalcTextSize("Setting").X;
|
||||||
|
|
||||||
var x = (int) pos.X;
|
void DrawSettingName(string name) {
|
||||||
if (ImGui.InputInt($"X##uimanager-window-{entry.Key}", ref x)) {
|
maxSettingWidth = Math.Max(maxSettingWidth, ImGui.CalcTextSize(name).X);
|
||||||
pos.X = (short) x;
|
ImGui.TextUnformatted(name);
|
||||||
this.Plugin.GameFunctions.SetAddonPosition(entry.Key, pos.X, pos.Y);
|
ImGui.NextColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.Columns(3);
|
||||||
|
ImGui.SetColumnWidth(0, ImGui.CalcTextSize("Enabled").X + ImGui.GetStyle().ItemSpacing.X * 2);
|
||||||
|
|
||||||
|
ImGui.TextUnformatted("Enabled");
|
||||||
|
ImGui.NextColumn();
|
||||||
|
|
||||||
|
DrawSettingName("Setting");
|
||||||
|
|
||||||
|
ImGui.TextUnformatted("Control");
|
||||||
|
|
||||||
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X * 3);
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X * 3);
|
||||||
if (ImGuiExt.IconButton(FontAwesomeIcon.Trash, $"uimanager-remove-window-{entry.Key}")) {
|
if (ImGuiExt.IconButton(FontAwesomeIcon.Trash, $"uimanager-remove-window-{entry.Key}")) {
|
||||||
toRemove.Add(entry.Key);
|
toRemove.Add(entry.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.Separator();
|
||||||
|
|
||||||
|
void DrawEnabledCheckbox(string kind, WindowComponent component) {
|
||||||
|
ImGui.NextColumn();
|
||||||
|
|
||||||
|
var enabled = entry.Value[component];
|
||||||
|
if (ImGui.Checkbox($"###{component}-enabled-{kind}", ref enabled)) {
|
||||||
|
entry.Value[component] = enabled;
|
||||||
|
this.Plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.NextColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
var pos = entry.Value.Position;
|
||||||
|
|
||||||
|
DrawEnabledCheckbox(entry.Key, WindowComponent.X);
|
||||||
|
|
||||||
|
DrawSettingName("X");
|
||||||
|
|
||||||
|
var x = (int) pos.X;
|
||||||
|
if (ImGui.InputInt($"##uimanager-x-window-{entry.Key}", ref x)) {
|
||||||
|
pos.X = (short) x;
|
||||||
|
this.Plugin.GameFunctions.SetAddonPosition(entry.Key, pos.X, pos.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawEnabledCheckbox(entry.Key, WindowComponent.Y);
|
||||||
|
|
||||||
|
DrawSettingName("Y");
|
||||||
|
|
||||||
var y = (int) pos.Y;
|
var y = (int) pos.Y;
|
||||||
if (ImGui.InputInt($"Y##uimanager-window-{entry.Key}", ref y)) {
|
if (ImGui.InputInt($"##uimanager-y-window-{entry.Key}", ref y)) {
|
||||||
pos.Y = (short) y;
|
pos.Y = (short) y;
|
||||||
this.Plugin.GameFunctions.SetAddonPosition(entry.Key, pos.X, pos.Y);
|
this.Plugin.GameFunctions.SetAddonPosition(entry.Key, pos.X, pos.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.SetColumnWidth(1, maxSettingWidth + ImGui.GetStyle().ItemSpacing.X * 2);
|
||||||
|
|
||||||
|
ImGui.Columns();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var remove in toRemove) {
|
foreach (var remove in toRemove) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user