diff --git a/Config/ConfigurationManager.cs b/Config/ConfigurationManager.cs index f385aec..52898dc 100644 --- a/Config/ConfigurationManager.cs +++ b/Config/ConfigurationManager.cs @@ -709,6 +709,7 @@ namespace HSUI.Config typeof(LimitBreakConfig), typeof(MPTickerConfig), typeof(DutyListScenarioConfig), + typeof(MainMenuConfig), // Colors typeof(TanksColorConfig), diff --git a/Enums/ElementKind.cs b/Enums/ElementKind.cs index d2efbd0..50f83a1 100644 --- a/Enums/ElementKind.cs +++ b/Enums/ElementKind.cs @@ -40,6 +40,7 @@ public enum ElementKind : uint EnemyList = 0xB8BD6685, // _EnemyList_a // Misc HUD + MainMenu = 0x8AF95A70, // _MainCommand_a (Main Menu) ToDoList = 0xA29100D2, // _ToDoList_a (Duty List) ScenarioTree = 0x88EE6357, // ScenarioTree_a (Scenario Guide) ExperienceBar = 0x21E53CCE, // _Exp_a diff --git a/HSUI.csproj b/HSUI.csproj index 07a2e61..fac4b99 100644 --- a/HSUI.csproj +++ b/HSUI.csproj @@ -9,9 +9,9 @@ HSUI - 1.0.8.22 - 1.0.8.22 - 1.0.8.22 + 1.0.8.23 + 1.0.8.23 + 1.0.8.23 diff --git a/HSUI.json b/HSUI.json index 40d7bf0..780088a 100644 --- a/HSUI.json +++ b/HSUI.json @@ -2,7 +2,7 @@ "Author": "Knack117", "Name": "HSUI", "InternalName": "HSUI", - "AssemblyVersion": "1.0.8.22", + "AssemblyVersion": "1.0.8.23", "Description": "HSUI provides a highly configurable HUD replacement for FFXIV, recreated from DelvUI using KamiToolKit, FFXIVClientStructs, and Dalamud. Features unit frames, castbars, job gauges, nameplates, party frames, status effects, enemy list, configurable hotbars with drag-and-drop, and profiles.", "ApplicableVersion": "any", "RepoUrl": "https://github.com/Knack117/HSUI", diff --git a/Helpers/DrawHelper.cs b/Helpers/DrawHelper.cs index b4da90b..37685b1 100644 --- a/Helpers/DrawHelper.cs +++ b/Helpers/DrawHelper.cs @@ -334,7 +334,7 @@ namespace HSUI.Helpers DrawGradientFilledRect(cursorPos, new Vector2(Math.Max(1, barSize.X * shield), h), color, drawList); } - public static void DrawInWindow(string name, Vector2 pos, Vector2 size, bool needsInput, Action drawAction) + public static void DrawInWindow(string name, Vector2 pos, Vector2 size, bool needsInput, Action drawAction, bool allowInputInClipRect = false) { const ImGuiWindowFlags windowFlags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoScrollbar | @@ -344,7 +344,7 @@ namespace HSUI.Helpers bool inputs = InputsHelper.Instance?.IsProxyEnabled == true ? false : needsInput; - DrawInWindow(name, pos, size, inputs, false, windowFlags, drawAction); + DrawInWindow(name, pos, size, inputs, false, windowFlags, drawAction, allowInputInClipRect); } public static void DrawInWindow( @@ -354,7 +354,8 @@ namespace HSUI.Helpers bool needsInput, bool needsWindow, ImGuiWindowFlags windowFlags, - Action drawAction) + Action drawAction, + bool allowInputInClipRect = false) { if (!ClipRectsHelper.Instance.Enabled || ClipRectsHelper.Instance.Mode == WindowClippingMode.Performance) @@ -408,7 +409,7 @@ namespace HSUI.Helpers if (ClipRectsHelper.Instance.Mode == WindowClippingMode.Hide) { return; } ImGuiWindowFlags flags = windowFlags; - if (needsInput && clipRect.Value.Contains(ImGui.GetMousePos())) + if (needsInput && !allowInputInClipRect && clipRect.Value.Contains(ImGui.GetMousePos())) { flags |= ImGuiWindowFlags.NoInputs; } diff --git a/Helpers/MainMenuHelper.cs b/Helpers/MainMenuHelper.cs new file mode 100644 index 0000000..46de36c --- /dev/null +++ b/Helpers/MainMenuHelper.cs @@ -0,0 +1,434 @@ +using AtkValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; +using FFXIVClientStructs.FFXIV.Client.System.Framework; +using FFXIVClientStructs.FFXIV.Client.UI; +using FFXIVClientStructs.FFXIV.Client.UI.Agent; +using FFXIVClientStructs.FFXIV.Client.UI.Misc; +using FFXIVClientStructs.FFXIV.Component.GUI; +using Lumina.Excel; +using Lumina.Excel.Sheets; +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace HSUI.Helpers +{ + public readonly struct MainMenuEntry + { + public uint CommandId { get; } + public uint IconId { get; } + public string Name { get; } + + public MainMenuEntry(uint commandId, uint iconId, string name) + { + CommandId = commandId; + IconId = iconId; + Name = name ?? ""; + } + } + + public static class MainMenuHelper + { + /// Names of the 7 top-level Main Menu categories. Clicking these opens the context menu, not a direct action. + private static readonly string[] MainMenuCategoryNames = + { + "Character", "Duty", "Logs", "Travel", "Party", "Social", "System" + }; + + /// Fixed icon IDs for categories (from sheet). Used for display; command row is still resolved by name. + private static readonly IReadOnlyDictionary FixedCategoryIconIds = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "Duty", 5 }, + { "Logs", 21 }, + { "Travel", 7 }, + { "Social", 20 } + }; + + /// Categories that must use the category header row (smallest RowId in MainCommandCategory) so the context menu matches the game bar. + private static readonly HashSet UseCategoryHeaderForMenu = new HashSet(StringComparer.OrdinalIgnoreCase) + { + "Logs", + "Travel" + }; + + /// Submenu item names that uniquely identify the Logs category (from default game context menu). + private static readonly string[] LogsCategoryAnchorNames = { "Hunting Log", "Sightseeing Log", "Crafting Log", "Gathering Log", "Fishing Log", "Fish Guide", "Orchestrion List", "Challenge Log" }; + + /// Submenu item names that uniquely identify the Travel category (from default game context menu). + private static readonly string[] TravelCategoryAnchorNames = { "Aether Currents", "Mount Speed", "Shared FATE", "Map", "Teleport", "Return" }; + + /// Get the 7 top-level Main Menu categories (Character, Duty, Logs, Travel, Party, Social, System) that are enabled. Clicking these opens the context menu. + public static List GetEnabledMainCommands() + { + var list = new List(); + try + { + var sheet = Plugin.DataManager.GetExcelSheet(); + if (sheet == null) return list; + + return GetEnabledMainCommandsUnsafe(list, sheet); + } + catch (Exception ex) + { + Plugin.Logger.Warning($"[HSUI] MainMenuHelper.GetEnabledMainCommands: {ex.Message}"); + } + + return list; + } + + /// True if the sheet row name matches the main menu category (exact or flexible). + private static bool MatchesCategoryName(string rowName, string categoryName) + { + if (string.IsNullOrEmpty(rowName)) return false; + string r = rowName.Trim(); + if (string.Equals(r, categoryName, StringComparison.OrdinalIgnoreCase)) + return true; + if (string.Equals(categoryName, "Duty", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("Duty", StringComparison.OrdinalIgnoreCase) >= 0; + if (string.Equals(categoryName, "Travel", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("Travel", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Teleport", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Return", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Aetheryte", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Port", StringComparison.OrdinalIgnoreCase) >= 0; + if (string.Equals(categoryName, "Party", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("Party", StringComparison.OrdinalIgnoreCase) >= 0; + if (string.Equals(categoryName, "Logs", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("Log", StringComparison.OrdinalIgnoreCase) >= 0 + || string.Equals(r, "Journal", StringComparison.OrdinalIgnoreCase) + || r.IndexOf("Quest", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Completion", StringComparison.OrdinalIgnoreCase) >= 0; + if (string.Equals(categoryName, "Social", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("Social", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Friend", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Contact", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Linkshell", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Free Company", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Fellowship", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Group", StringComparison.OrdinalIgnoreCase) >= 0; + if (string.Equals(categoryName, "System", StringComparison.OrdinalIgnoreCase)) + return r.IndexOf("System", StringComparison.OrdinalIgnoreCase) >= 0 + || r.IndexOf("Config", StringComparison.OrdinalIgnoreCase) >= 0; + return false; + } + + /// Get the category header row ID (smallest RowId in the same MainCommandCategory). For Logs/Travel we identify the category by submenu item names from the default game menu. + private static unsafe uint GetCategoryHeaderCommandId(string categoryName, Lumina.Excel.ExcelSheet sheet, AgentHUD* agentHud) + { + uint categoryGroupId = 0; + string[]? anchorNames = null; + if (string.Equals(categoryName, "Logs", StringComparison.OrdinalIgnoreCase)) + anchorNames = LogsCategoryAnchorNames; + else if (string.Equals(categoryName, "Travel", StringComparison.OrdinalIgnoreCase)) + anchorNames = TravelCategoryAnchorNames; + + if (anchorNames != null) + { + // Find category by a row that matches one of the known submenu names (e.g. "Hunting Log", "Aether Currents"). + foreach (var row in sheet) + { + uint id = row.RowId; + if (id == 0) continue; + if (!agentHud->IsMainCommandEnabled(id)) continue; + string name = ""; + try { name = row.Name.ToString(); } + catch { } + name = name?.Trim() ?? ""; + foreach (string anchor in anchorNames) + { + if (name.IndexOf(anchor, StringComparison.OrdinalIgnoreCase) >= 0) + { + try { categoryGroupId = row.MainCommandCategory.RowId; break; } + catch { } + break; + } + } + if (categoryGroupId != 0) break; + } + } + + if (categoryGroupId == 0) + { + // Fallback: exact "Logs"/"Travel" or flexible category name match + bool exactOnly = string.Equals(categoryName, "Logs", StringComparison.OrdinalIgnoreCase) + || string.Equals(categoryName, "Travel", StringComparison.OrdinalIgnoreCase); + foreach (var row in sheet) + { + uint id = row.RowId; + if (id == 0) continue; + string name = ""; + try { name = row.Name.ToString(); } + catch { } + if (exactOnly && !string.Equals(name.Trim(), categoryName, StringComparison.OrdinalIgnoreCase)) + continue; + if (!exactOnly && !MatchesCategoryName(name, categoryName)) + continue; + if (!agentHud->IsMainCommandEnabled(id)) + continue; + try { categoryGroupId = row.MainCommandCategory.RowId; break; } + catch { } + } + } + if (categoryGroupId == 0) + { + foreach (var row in sheet) + { + uint id = row.RowId; + if (id == 0) continue; + string name = ""; + try { name = row.Name.ToString(); } + catch { } + if (!MatchesCategoryName(name, categoryName) || !agentHud->IsMainCommandEnabled(id)) + continue; + try { categoryGroupId = row.MainCommandCategory.RowId; break; } + catch { } + } + } + + if (categoryGroupId == 0) return 0; + uint headerId = 0; + foreach (var row in sheet) + { + if (row.RowId == 0) continue; + try { if (row.MainCommandCategory.RowId != categoryGroupId) continue; } + catch { continue; } + if (!agentHud->IsMainCommandEnabled(row.RowId)) continue; + if (headerId == 0 || row.RowId < headerId) + headerId = row.RowId; + } + return headerId; + } + + private static unsafe List GetEnabledMainCommandsUnsafe(List list, Lumina.Excel.ExcelSheet sheet) + { + var agentHud = AgentHUD.Instance(); + if (agentHud == null) return list; + + foreach (string categoryName in MainMenuCategoryNames) + { + // Logs and Travel: use category header row so context menu matches game bar. + if (UseCategoryHeaderForMenu.Contains(categoryName)) + { + uint headerId = GetCategoryHeaderCommandId(categoryName, sheet, agentHud); + if (headerId != 0) + { + uint iconId = 0; + if (FixedCategoryIconIds.TryGetValue(categoryName, out uint fixedIconId)) + iconId = fixedIconId; + if (iconId == 0) + iconId = GetFallbackIconIdForCategory(categoryName); + list.Add(new MainMenuEntry(headerId, iconId, categoryName)); + continue; + } + } + + foreach (var row in sheet) + { + uint id = row.RowId; + if (id == 0) continue; + + string name = ""; + try { name = row.Name.ToString(); } + catch { } + + if (!MatchesCategoryName(name, categoryName)) + continue; + if (!agentHud->IsMainCommandEnabled(id)) + continue; + + // Icon: use fixed icon ID for Duty/Logs/Travel/Social (from sheet); others use sheet → game → fallback. + uint iconId = 0; + if (FixedCategoryIconIds.TryGetValue(categoryName, out uint fixedIconId)) + iconId = fixedIconId; + if (iconId == 0) + { + try { iconId = (uint)row.Icon; } + catch { } + } + if (iconId == 0) + iconId = GetIconIdForMainCommand(id); + if (iconId == 0) + iconId = GetFallbackIconIdForCategory(categoryName); + + list.Add(new MainMenuEntry(id, iconId, categoryName)); + break; + } + } + + return list; + } + + /// Resolve icon for a Main Command. Uses RaptureHotbarModule when sheet row.Icon is 0. + public static unsafe uint GetIconIdForMainCommand(uint commandId) + { + try + { + var module = RaptureHotbarModule.Instance(); + if (module != null && module->ModuleReady) + { + var bar = module->StandardHotbars[0]; + var slot = bar.GetHotbarSlot(0); + if (slot != null) + { + int gameIcon = slot->GetIconIdForSlot(RaptureHotbarModule.HotbarSlotType.MainCommand, commandId); + if (gameIcon > 0) return (uint)gameIcon; + } + } + } + catch (Exception ex) + { + Plugin.Logger.Warning($"[HSUI] MainMenuHelper.GetIconIdForMainCommand({commandId}): {ex.Message}"); + } + return 0; + } + + /// Fallback icon when game and sheet both return 0. Duty = 61002 (exclamation) to match default bar. + private static uint GetFallbackIconIdForCategory(string categoryName) + { + return (categoryName?.ToLowerInvariant()) switch + { + "character" => 61001, + "duty" => 61002, + "logs" => 61003, + "travel" => 61004, + "party" => 61005, + "social" => 61006, + "system" => 61007, + _ => 0 + }; + } + + /// Execute a main command by ID (e.g. Character, Social, Collection). + public static unsafe void ExecuteMainCommand(uint commandId) + { + try + { + var uiModule = Framework.Instance()->GetUIModule(); + if (uiModule == null) return; + + uiModule->ExecuteMainCommand(commandId); + } + catch (Exception ex) + { + Plugin.Logger.Warning($"[HSUI] MainMenuHelper.ExecuteMainCommand({commandId}): {ex.Message}"); + } + } + + /// Open the context submenu for a category, or execute directly if no submenu. When sub-commands exist, the HUD shows a custom context menu; otherwise executes the command. + public static unsafe void OpenSubmenuOrExecute(uint categoryCommandId) + { + var subIds = GetSubCommandIds(categoryCommandId); + if (subIds != null && subIds.Count > 0) + return; // Caller should use GetSubCommandEntries and show custom menu; we don't call OpenSystemMenu (crashes) + ExecuteMainCommand(categoryCommandId); + } + + /// Get sub-command entries (id + display name) for the category. Same options as the default main menu bar context menu. Returns empty if category has no sub-commands. + public static List<(uint CommandId, string Name)> GetSubCommandEntries(uint categoryCommandId) + { + var list = new List<(uint, string)>(); + try + { + var subIds = GetSubCommandIds(categoryCommandId); + if (subIds == null || subIds.Count == 0) return list; + + var sheet = Plugin.DataManager.GetExcelSheet(); + if (sheet == null) return list; + + foreach (uint id in subIds) + { + string name = ""; + if (sheet.TryGetRow(id, out var row)) + { + try { name = row.Name.ToString(); } + catch { } + } + if (string.IsNullOrEmpty(name)) name = $"#{id}"; + list.Add((id, name)); + } + } + catch (Exception ex) + { + Plugin.Logger.Warning($"[HSUI] MainMenuHelper.GetSubCommandEntries({categoryCommandId}): {ex.Message}"); + } + return list; + } + + /// Get MainCommand IDs that belong to the same category as the given command (for submenu). + private static unsafe List GetSubCommandIds(uint categoryCommandId) + { + var list = new List(); + try + { + var sheet = Plugin.DataManager.GetExcelSheet(); + if (sheet == null) return list; + + var agentHud = AgentHUD.Instance(); + if (agentHud == null) return list; + + if (!sheet.TryGetRow(categoryCommandId, out var categoryRow)) return list; + + uint categoryGroupId; + try + { + categoryGroupId = categoryRow.MainCommandCategory.RowId; + } + catch { return list; } + + foreach (var row in sheet) + { + if (row.RowId == 0) continue; + try + { + if (row.MainCommandCategory.RowId != categoryGroupId) continue; + } + catch { continue; } + if (!agentHud->IsMainCommandEnabled(row.RowId)) continue; + list.Add(row.RowId); + } + } + catch (Exception ex) + { + Plugin.Logger.Warning($"[HSUI] MainMenuHelper.GetSubCommandIds({categoryCommandId}): {ex.Message}"); + } + return list; + } + + /// Open the game's system menu with the given MainCommand IDs (context submenu). + private static unsafe void OpenSystemMenuWithCommands(List commandIds) + { + if (commandIds == null || commandIds.Count == 0) return; + if (commandIds.Count > 17) return; // game limit + + var agentHud = AgentHUD.Instance(); + if (agentHud == null) return; + + int count = commandIds.Count; + int allocSize = 5 + 17 + 18; // atkValueArgs layout: [4]=size, [5..21]=commands, [23..]=optional name strings + var ptr = (AtkValue*)Marshal.AllocHGlobal(allocSize * sizeof(AtkValue)); + try + { + // Zero entire buffer so the game never reads garbage as string pointers (prevents crash in Utf8String.SetString) + for (int i = 0; i < allocSize; i++) + { + ptr[i].Type = AtkValueType.Null; + ptr[i].Int = 0; + } + + ptr[4].ChangeType(AtkValueType.UInt); + ptr[4].UInt = (uint)count; + + for (int i = 0; i < count; i++) + { + ptr[5 + i].ChangeType(AtkValueType.Int); + ptr[5 + i].Int = (int)commandIds[i]; + } + + agentHud->OpenSystemMenu(ptr, (uint)count); + } + finally + { + Marshal.FreeHGlobal(new IntPtr(ptr)); + } + } + } +} diff --git a/Helpers/TooltipsHelper.cs b/Helpers/TooltipsHelper.cs index bcab63f..a4802f2 100644 --- a/Helpers/TooltipsHelper.cs +++ b/Helpers/TooltipsHelper.cs @@ -88,8 +88,17 @@ namespace HSUI.Helpers private bool _dataIsValid = false; + /// Set when an HUD element (e.g. Main Menu) has the mouse over it this frame. World object tooltip will not show. + private bool _mouseOverHudElement = false; + private const float IconSize = 24f; + /// Call when the mouse is over an interactive HUD element so world object tooltip is not shown. + public void NotifyMouseOverHudElement() + { + _mouseOverHudElement = true; + } + public void ShowTooltipOnCursor(string text, string? title = null, uint id = 0, string name = "", uint? iconId = null, TooltipIdKind idKind = TooltipIdKind.None, List? formattedText = null) { ShowTooltip(text, ImGui.GetMousePos(), title, id, name, iconId, idKind, formattedText); @@ -114,7 +123,13 @@ namespace HSUI.Helpers _currentIconId = iconId; _formattedSegments = formattedText; - // calcualte title size + // When showing a simple tooltip with no title (e.g. HUD), clear previous title/body so we don't mix with last frame's world tooltip + if (title == null) + { + _currentTooltipTitle = null; + } + + // calculate title size _titleSize = Vector2.Zero; if (title != null) { @@ -199,19 +214,17 @@ namespace HSUI.Helpers /// public void ShowWorldObjectTooltip() { + // Don't overwrite if an HUD element already set a tooltip this frame (e.g. Main Menu icon) + if (_dataIsValid) + return; + // Don't show world tooltip when mouse is over an interactive HUD element (e.g. Main Menu bar) + if (_mouseOverHudElement) + return; try { _worldTooltipConfig ??= ConfigurationManager.Instance.GetConfigObject(); if (_worldTooltipConfig == null || !_worldTooltipConfig.Enabled) return; - } - catch (Exception ex) - { - // Config not ready yet or not found - silently skip - if (_config.DebugTooltips) - Plugin.Logger.Warning($"[HSUI Tooltip] WorldObjectTooltipConfig not available: {ex.Message}"); - return; - } IGameObject? mouseOverTarget = Plugin.TargetManager.MouseOverTarget; if (mouseOverTarget == null) @@ -294,6 +307,13 @@ namespace HSUI.Helpers { ShowTooltipOnCursor(body, name, 0, "", iconId); } + } + catch (Exception ex) + { + // Config not ready yet or not found - silently skip + if (_config.DebugTooltips) + Plugin.Logger.Warning($"[HSUI Tooltip] WorldObjectTooltipConfig not available: {ex.Message}"); + } } private static unsafe uint? GetWorldObjectIconId(IGameObject gameObject) @@ -310,6 +330,7 @@ namespace HSUI.Helpers public void RemoveTooltip() { _dataIsValid = false; + _mouseOverHudElement = false; _formattedSegments = null; } diff --git a/Interface/GeneralElements/DutyListScenarioConfig.cs b/Interface/GeneralElements/DutyListScenarioConfig.cs index 64bda30..a0c6ff8 100644 --- a/Interface/GeneralElements/DutyListScenarioConfig.cs +++ b/Interface/GeneralElements/DutyListScenarioConfig.cs @@ -32,7 +32,7 @@ namespace HSUI.Interface.GeneralElements [ColorEdit4("Background Color")] [Order(31)] - public PluginConfigColor BackgroundColor = new(new Vector4(0f, 0f, 0f, 0.5f)); + public PluginConfigColor BackgroundColor = new(new Vector4(0f, 0f, 0f, 0f)); [ColorEdit4("Divider Color")] [Order(32)] diff --git a/Interface/GeneralElements/DutyListScenarioHud.cs b/Interface/GeneralElements/DutyListScenarioHud.cs index e190523..12904e8 100644 --- a/Interface/GeneralElements/DutyListScenarioHud.cs +++ b/Interface/GeneralElements/DutyListScenarioHud.cs @@ -57,7 +57,9 @@ namespace HSUI.Interface.GeneralElements { DrawHelper.DrawInWindow(ID, basePos, Config.Size, true, (drawList) => { - drawList.AddRectFilled(basePos, basePos + Config.Size, Config.BackgroundColor.Base, 4); + uint bgColor = Config.BackgroundColor.Base; + if ((bgColor & 0xFF000000) != 0) + drawList.AddRectFilled(basePos, basePos + Config.Size, bgColor, 4); drawList.PushClipRect(basePos, basePos + Config.Size, true); float y = basePos.Y + padding; diff --git a/Interface/GeneralElements/MainMenuConfig.cs b/Interface/GeneralElements/MainMenuConfig.cs new file mode 100644 index 0000000..eed74e7 --- /dev/null +++ b/Interface/GeneralElements/MainMenuConfig.cs @@ -0,0 +1,61 @@ +using Dalamud.Bindings.ImGui; +using HSUI.Config; +using HSUI.Config.Attributes; +using HSUI.Enums; +using System.Numerics; + +namespace HSUI.Interface.GeneralElements +{ + [Section("Other Elements")] + [SubSection("Main Menu", 0)] + public class MainMenuConfig : AnchorablePluginConfigObject + { + [Combo("Layout", new[] { "Horizontal", "Vertical" })] + [Order(18)] + public int LayoutDirection = 0; // 0 = horizontal, 1 = vertical + + [DragInt("Icon Size", min = 16, max = 64)] + [Order(20)] + public int IconSize = 36; + + [DragInt("Spacing", min = 0, max = 24)] + [Order(21)] + public int Spacing = 4; + + [ColorEdit4("Background Color")] + [Order(30)] + public PluginConfigColor BackgroundColor = new(new Vector4(0f, 0f, 0f, 0.6f)); + + [ColorEdit4("Icon Tint")] + [Order(31)] + public PluginConfigColor IconTint = new(new Vector4(1f, 1f, 1f, 1f)); + + [ColorEdit4("Hover Tint")] + [Order(32)] + public PluginConfigColor HoverTint = new(new Vector4(1f, 1f, 1f, 1f)); + + [Checkbox("Show Labels")] + [Order(35)] + public bool ShowLabels = false; + + [NestedConfig("Visibility", 70)] + public VisibilityConfig VisibilityConfig = new(); + + public MainMenuConfig() + { + // Width fits 7 icons (36px) + 6 gaps (4px) + 8 margin = 284 + Size = new Vector2(284, 48); + } + + public new static MainMenuConfig DefaultConfig() + { + var viewport = ImGui.GetMainViewport().Size; + return new MainMenuConfig + { + Position = new Vector2(0, viewport.Y * 0.5f - 24), + Size = new Vector2(284, 48), + Anchor = DrawAnchor.Bottom + }; + } + } +} diff --git a/Interface/GeneralElements/MainMenuHud.cs b/Interface/GeneralElements/MainMenuHud.cs new file mode 100644 index 0000000..d2b0632 --- /dev/null +++ b/Interface/GeneralElements/MainMenuHud.cs @@ -0,0 +1,190 @@ +using Dalamud.Bindings.ImGui; +using HSUI.Config; +using HSUI.Helpers; +using HSUI.Interface; +using System; +using System.Collections.Generic; +using System.Numerics; + +namespace HSUI.Interface.GeneralElements +{ + public class MainMenuHud : DraggableHudElement, IHudElementWithVisibilityConfig + { + private const float BarPadding = 0f; + private const float BackgroundRounding = 6f; + /// Extra padding around content when drawing the background so the bar doesn't extend past the icons. + private const float BackgroundEdgePad = 2f; + + private MainMenuConfig Config => (MainMenuConfig)_config; + public VisibilityConfig VisibilityConfig => Config.VisibilityConfig; + + /// When set, the context menu with these entries should be shown (same frame or next). Cleared when popup closes. + private List<(uint CommandId, string Name)>? _contextMenuEntries = null; + + public MainMenuHud(MainMenuConfig config, string displayName) + : base(config, displayName) { } + + protected override (List, List) ChildrenPositionsAndSizes() + { + return (new List { Config.Position }, new List { Config.Size }); + } + + public override (Vector2 min, Vector2 max) GetScreenBounds(Vector2 origin) + { + Vector2 topLeft = Utils.GetAnchoredPosition(origin + ParentPos() + Config.Position, Config.Size, Config.Anchor); + return (topLeft, topLeft + Config.Size); + } + + public override void DrawChildren(Vector2 origin) + { + if (!Config.Enabled) + return; + + var entries = MainMenuHelper.GetEnabledMainCommands(); + if (entries.Count == 0) + return; + + Vector2 basePos = Utils.GetAnchoredPosition(origin + Config.Position, Config.Size, Config.Anchor); + Vector2 iconSize = new Vector2(Config.IconSize, Config.IconSize); + bool horizontal = Config.LayoutDirection == 0; + + AddDrawAction(Config.StrataLevel, () => + { + DrawHelper.DrawInWindow(ID, basePos, Config.Size, true, (drawListParam) => + { + var drawList = ImGui.GetWindowDrawList(); + + // Compute total content size and starting position so icons are centered in the bar + int count = entries.Count; + float contentW, contentH; + if (horizontal) + { + contentW = count * iconSize.X + (count > 0 ? (count - 1) * Config.Spacing : 0); + if (Config.ShowLabels) + { + for (int i = 0; i < count; i++) + contentW += ImGui.CalcTextSize(entries[i].Name).X + Config.Spacing; + } + contentH = iconSize.Y; + } + else + { + contentW = iconSize.X; + contentH = 0; + foreach (var e in entries) + { + float h = iconSize.Y + Config.Spacing; + if (Config.ShowLabels && !string.IsNullOrEmpty(e.Name)) + h += ImGui.CalcTextSize(e.Name).Y + 2; + contentH += h; + } + if (contentH > 0) contentH -= Config.Spacing; + } + float startX = basePos.X + BarPadding + Math.Max(0, (Config.Size.X - 2f * BarPadding - contentW) / 2f); + float startY = basePos.Y + BarPadding + Math.Max(0, (Config.Size.Y - 2f * BarPadding - contentH) / 2f); + + // Draw background only over the content area so no gray bar shows on left/right + Vector2 bgMin = new Vector2(startX - BackgroundEdgePad, basePos.Y); + Vector2 bgMax = new Vector2(startX + contentW + BackgroundEdgePad, basePos.Y + Config.Size.Y); + if (!horizontal) + { + bgMin = new Vector2(basePos.X, startY - BackgroundEdgePad); + bgMax = new Vector2(basePos.X + Config.Size.X, startY + contentH + BackgroundEdgePad); + } + drawList.AddRectFilled(bgMin, bgMax, Config.BackgroundColor.Base, BackgroundRounding); + drawList.PushClipRect(basePos, basePos + Config.Size, true); + + float x = startX; + float y = startY; + int index = 0; + + foreach (var entry in entries) + { + Vector2 iconPos = horizontal + ? new Vector2(x, basePos.Y + (Config.Size.Y - iconSize.Y) / 2f) + : new Vector2(basePos.X + (Config.Size.X - iconSize.X) / 2f, y); + Vector2 iconEnd = iconPos + iconSize; + + // Use InvisibleButton so ImGui tracks hover/click for this icon + ImGui.SetCursorScreenPos(iconPos); + ImGui.InvisibleButton($"##mainmenu_icon_{ID}_{index}", iconSize); + bool hovered = ImGui.IsItemHovered(); + + uint tint = Config.IconTint.Base; + if (hovered) + { + tint = Config.HoverTint.Base; + TooltipsHelper.Instance.NotifyMouseOverHudElement(); + TooltipsHelper.Instance.ShowTooltipOnCursor(entry.Name); + } + + if (ImGui.IsItemClicked(ImGuiMouseButton.Left) || ImGui.IsItemClicked(ImGuiMouseButton.Right)) + { + var subEntries = MainMenuHelper.GetSubCommandEntries(entry.CommandId); + if (subEntries != null && subEntries.Count > 0) + { + _contextMenuEntries = subEntries; + ImGui.OpenPopup("HSUI_MainMenu_Context"); + ImGui.SetNextWindowPos(ImGui.GetMousePos()); + } + else + { + MainMenuHelper.ExecuteMainCommand(entry.CommandId); + } + } + + if (entry.IconId != 0) + DrawHelper.DrawIcon(entry.IconId, iconPos, iconSize, false, tint, drawList); + + float labelH = 0; + if (Config.ShowLabels && !string.IsNullOrEmpty(entry.Name)) + { + float labelW = ImGui.CalcTextSize(entry.Name).X; + labelH = ImGui.CalcTextSize(entry.Name).Y; + Vector2 labelPos = horizontal + ? new Vector2(iconPos.X + iconSize.X + Config.Spacing, basePos.Y + (Config.Size.Y - labelH) / 2f) + : new Vector2(basePos.X + (Config.Size.X - labelW) / 2f, iconPos.Y + iconSize.Y + 2); + drawList.AddText(labelPos, Config.IconTint.Base, entry.Name); + } + + if (horizontal) + { + float advance = iconSize.X + Config.Spacing; + if (Config.ShowLabels) advance += ImGui.CalcTextSize(entry.Name).X + Config.Spacing; + x += advance; + } + else + { + y += iconSize.Y + 2 + labelH + Config.Spacing; + } + index++; + } + + drawList.PopClipRect(); + + // Draw context menu popup (same options as default main menu bar) + if (ImGui.BeginPopup("HSUI_MainMenu_Context", ImGuiWindowFlags.NoMove)) + { + if (_contextMenuEntries != null) + { + foreach (var (cmdId, name) in _contextMenuEntries) + { + if (ImGui.Selectable(name)) + { + uint commandId = cmdId; + Plugin.Framework.RunOnFrameworkThread(() => MainMenuHelper.ExecuteMainCommand(commandId)); + ImGui.CloseCurrentPopup(); + } + } + } + ImGui.EndPopup(); + } + else + { + _contextMenuEntries = null; + } + }, true); + }); + } + } +} diff --git a/Interface/HudHelper.cs b/Interface/HudHelper.cs index 14184d8..6115476 100644 --- a/Interface/HudHelper.cs +++ b/Interface/HudHelper.cs @@ -264,6 +264,11 @@ namespace HSUI.Interface AddElements(ElementKind.ScenarioTree); } + var mainMenu = ConfigurationManager.Instance?.GetConfigObject(); + // Disabled while troubleshooting: keep game's Main Menu visible so we can compare behavior. + // if (mainMenu?.Enabled == true) + // AddElements(ElementKind.MainMenu); + // NamePlate is not in HUD Layout config; use UpdateDefaultNameplates (IsVisible) for that if (IsCurrentJobHudEnabled()) { diff --git a/Interface/HudManager.cs b/Interface/HudManager.cs index 0bd6b83..af2190a 100644 --- a/Interface/HudManager.cs +++ b/Interface/HudManager.cs @@ -452,6 +452,10 @@ namespace HSUI.Interface var dutyListScenarioConfig = ConfigurationManager.Instance.GetConfigObject(); var dutyListScenarioHud = new DutyListScenarioHud(dutyListScenarioConfig, "Duty List & Scenario Guide"); _hudElements.Add(dutyListScenarioConfig, dutyListScenarioHud); + + var mainMenuConfig = ConfigurationManager.Instance.GetConfigObject(); + var mainMenuHud = new MainMenuHud(mainMenuConfig, "Main Menu"); + _hudElements.Add(mainMenuConfig, mainMenuHud); } public void Draw(uint jobId) diff --git a/changelog.md b/changelog.md index efc0eea..240fd15 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 1.0.8.23 +- **Main Menu**: New customizable main menu bar replacing the game's bar. Correct icons (Duty, Logs, Travel, Social) and context menus; Logs/Travel identified by submenu names. Background drawn only behind icons (no extra side padding). Crash fix when executing from context menu (RunOnFrameworkThread). +- **Duty List & Scenario Guide**: Background transparent by default; optional skip draw when fully transparent. + # 1.0.8.22 - **Duty List & Scenario Guide**: Fix "Hide unless hovered" visibility option — override GetScreenBounds() so hover hit-test matches drawn panel. - **Tooltips**: Job gauge/resource costs (Soul Gauge, Beast Gauge, Lily, Kenki, etc.) now show as section with label color. Fix tooltip break when stats and description share first block. diff --git a/pluginmaster.json b/pluginmaster.json index 5f63ff2..5d7a257 100644 --- a/pluginmaster.json +++ b/pluginmaster.json @@ -1 +1 @@ -[{"Author":"Knack117","Name":"HSUI","Punchline":"A modern HUD replacement built for customization.","Description":"HSUI provides a highly configurable HUD replacement for FFXIV, recreated from DelvUI using KamiToolKit, FFXIVClientStructs, and Dalamud. Features unit frames, castbars, job gauges, nameplates, party frames, status effects, enemy list, configurable hotbars with drag-and-drop, and profiles.","Changelog":"1.0.8.20: Fixed cooldown overlays showing through game UI (dialogue box) when Show HUD during dialogue enabled. 1.0.8.19: Hotbar visibility moved to per-hotbar menus; removed Visibility Hotbars tab. 1.0.8.18: Visibility \"Hide unless hovered\" option. 1.0.8.17: Controller hotbars (cross layout, separate storage, sync with game). 1.0.8.16: Show HUD during dialogue and interaction. 1.0.8.15: Tooltips game-style formatting. 1.0.8.14: Mouse GCD Indicator. 1.0.8.13: Item tooltips now show. 1.0.8.12: Item/HQ icons now draw on hotbar. 1.0.8.11: Hotbar tooltip crash fix. 1.0.8.10: Hotbar crash fix when dragging inventory items. 1.0.8.9: Gearset persists on slot. 1.0.8.8: Gearset drag-drop fix. 1.0.8.7: Fixed Gearset icon clearing. 1.0.8.6: Crafting action tooltips full description. 1.0.8.4: Alliance Frames 1 and 2 fix; Hide in duty no longer hides alliance frames. 1.0.8.3: Fix left-click staying broken after disable. 1.0.8.2: Charge icons stay lit until all charges spent.","InternalName":"HSUI","AssemblyVersion":"1.0.8.20","RepoUrl":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI","ApplicableVersion":"any","Tags":["UI","HUD","Unit Frames","Nameplates","Party Frames","Hotbars"],"CategoryTags":["UI"],"DalamudApiLevel":14,"IconUrl":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/raw/branch/main/Media/Images/icon.png","ImageUrls":[],"DownloadLinkInstall":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.20/latest.zip","IsHide":false,"IsTestingExclusive":false,"DownloadLinkTesting":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.20/latest.zip","DownloadLinkUpdate":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.20/latest.zip","LastUpdate":"1772378453"}] +[{"Author":"Knack117","Name":"HSUI","Punchline":"A modern HUD replacement built for customization.","Description":"HSUI provides a highly configurable HUD replacement for FFXIV, recreated from DelvUI using KamiToolKit, FFXIVClientStructs, and Dalamud. Features unit frames, castbars, job gauges, nameplates, party frames, status effects, enemy list, configurable hotbars with drag-and-drop, and profiles.","Changelog":"1.0.8.23: Main Menu bar; Duty List & Scenario Guide transparent background. 1.0.8.22: Duty List hide-unless-hovered fix; tooltips job gauge costs. 1.0.8.21: Duty List in-duty info. 1.0.8.20: Fixed cooldown overlays showing through game UI (dialogue box) when Show HUD during dialogue enabled. 1.0.8.19: Hotbar visibility moved to per-hotbar menus; removed Visibility Hotbars tab. 1.0.8.18: Visibility \"Hide unless hovered\" option. 1.0.8.17: Controller hotbars (cross layout, separate storage, sync with game). 1.0.8.16: Show HUD during dialogue and interaction. 1.0.8.15: Tooltips game-style formatting. 1.0.8.14: Mouse GCD Indicator. 1.0.8.13: Item tooltips now show. 1.0.8.12: Item/HQ icons now draw on hotbar. 1.0.8.11: Hotbar tooltip crash fix. 1.0.8.10: Hotbar crash fix when dragging inventory items. 1.0.8.9: Gearset persists on slot. 1.0.8.8: Gearset drag-drop fix. 1.0.8.7: Fixed Gearset icon clearing. 1.0.8.6: Crafting action tooltips full description. 1.0.8.4: Alliance Frames 1 and 2 fix; Hide in duty no longer hides alliance frames. 1.0.8.3: Fix left-click staying broken after disable. 1.0.8.2: Charge icons stay lit until all charges spent.","InternalName":"HSUI","AssemblyVersion":"1.0.8.23","RepoUrl":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI","ApplicableVersion":"any","Tags":["UI","HUD","Unit Frames","Nameplates","Party Frames","Hotbars"],"CategoryTags":["UI"],"DalamudApiLevel":14,"IconUrl":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/raw/branch/main/Media/Images/icon.png","ImageUrls":[],"DownloadLinkInstall":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.23/latest.zip","IsHide":false,"IsTestingExclusive":false,"DownloadLinkTesting":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.23/latest.zip","DownloadLinkUpdate":"http://brassnet.ddns.net:33983/KnackAtNite/HSUI/releases/download/v1.0.8.23/latest.zip","LastUpdate":"1772500800"}]