From 26a97984d0977eed6161ec61a8f8111232c73369 Mon Sep 17 00:00:00 2001 From: Justin Brown Date: Mon, 29 Apr 2024 19:50:14 -0700 Subject: [PATCH] Add an optional extension callback for the DescriptiveTooltip --- Pulsar4X/GameEngine/Components/ComponentDesign.cs | 5 +++++ Pulsar4X/GameEngine/Engine/Entities/Entity.cs | 1 - .../DisplayExtensions/ComponentInstancesDBDisplay.cs | 2 +- Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs | 12 ++++-------- .../EmpireManagement/ResearchWindow.cs | 2 +- .../EmpireManagement/ShipDesignWindow.cs | 9 ++++++++- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Pulsar4X/GameEngine/Components/ComponentDesign.cs b/Pulsar4X/GameEngine/Components/ComponentDesign.cs index 1a96587f4..28ecb2533 100644 --- a/Pulsar4X/GameEngine/Components/ComponentDesign.cs +++ b/Pulsar4X/GameEngine/Components/ComponentDesign.cs @@ -7,9 +7,11 @@ using Pulsar4X.Datablobs; using Pulsar4X.DataStructures; using Pulsar4X.Extensions; +using System.Diagnostics; namespace Pulsar4X.Components { + [DebuggerDisplay("{DebuggerDisplay}")] public class ComponentDesign : ICargoable, IConstructableDesign { public ConstructableGuiHints GuiHints { get; set; } @@ -115,5 +117,8 @@ public bool TryGetAttribute(out T attribute) attribute = default(T); return false; } + + [JsonIgnore] + private string DebuggerDisplay => $"({UniqueID}) {Name}"; } } \ No newline at end of file diff --git a/Pulsar4X/GameEngine/Engine/Entities/Entity.cs b/Pulsar4X/GameEngine/Engine/Entities/Entity.cs index f5431a12c..3468fb91b 100644 --- a/Pulsar4X/GameEngine/Engine/Entities/Entity.cs +++ b/Pulsar4X/GameEngine/Engine/Entities/Entity.cs @@ -5,7 +5,6 @@ using Newtonsoft.Json; using Pulsar4X.Components; using Pulsar4X.Datablobs; -using Pulsar4X.Messaging; namespace Pulsar4X.Engine; diff --git a/Pulsar4X/Pulsar4X.Client/DisplayExtensions/ComponentInstancesDBDisplay.cs b/Pulsar4X/Pulsar4X.Client/DisplayExtensions/ComponentInstancesDBDisplay.cs index c43bd7957..a21fefd22 100644 --- a/Pulsar4X/Pulsar4X.Client/DisplayExtensions/ComponentInstancesDBDisplay.cs +++ b/Pulsar4X/Pulsar4X.Client/DisplayExtensions/ComponentInstancesDBDisplay.cs @@ -30,7 +30,7 @@ public static void Display(this ComponentInstancesDB db, EntityState entityState ImGui.TableNextColumn(); ImGui.Text(instance.Name); AddContextMenu(instance, uiState); - DisplayHelpers.DescriptiveTooltip(instance.Name, instance.Design.TypeName, instance.Design.Description, "", true); + DisplayHelpers.DescriptiveTooltip(instance.Name, instance.Design.TypeName, instance.Design.Description, null, true); ImGui.TableNextColumn(); ImGui.Text(listPerDesign.Count.ToString()); ImGui.TableNextColumn(); diff --git a/Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs b/Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs index ee562d72a..442f8f87e 100644 --- a/Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs +++ b/Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs @@ -82,10 +82,10 @@ public static void ShipTooltip(Entity ship, int factionId) meta = "Commanded by: " + commander.GetName(factionId); } - DescriptiveTooltip(ship.GetName(factionId), shipInfo.Design.Name, description, meta); + DescriptiveTooltip(ship.GetName(factionId), shipInfo.Design.Name, description, () => ImGui.Text(meta)); } - public static void DescriptiveTooltip(string name, string type, string description, string metaInfo = "", bool hideTypeIfSameAsName = false) + public static void DescriptiveTooltip(string name, string type, string description, Action? callback = null, bool hideTypeIfSameAsName = false) { if(ImGui.IsItemHovered()) { @@ -103,9 +103,8 @@ public static void DescriptiveTooltip(string name, string type, string descripti ImGui.PopStyleColor(); } var showDescription = description.IsNotNullOrEmpty(); - var showMetaInfo = metaInfo.IsNotNullOrEmpty(); - if(showDescription || showMetaInfo) + if(showDescription || callback != null) { ImGui.Separator(); } @@ -115,10 +114,7 @@ public static void DescriptiveTooltip(string name, string type, string descripti { ImGui.TextWrapped(description); } - if(showMetaInfo) - { - ImGui.Text(metaInfo); - } + callback?.Invoke(); ImGui.PopStyleColor(); ImGui.EndTooltip(); } diff --git a/Pulsar4X/Pulsar4X.Client/EmpireManagement/ResearchWindow.cs b/Pulsar4X/Pulsar4X.Client/EmpireManagement/ResearchWindow.cs index fb28ceb75..5d08eecfc 100644 --- a/Pulsar4X/Pulsar4X.Client/EmpireManagement/ResearchWindow.cs +++ b/Pulsar4X/Pulsar4X.Client/EmpireManagement/ResearchWindow.cs @@ -279,7 +279,7 @@ private void DisplayTechs() _researchableTechs[i].DisplayName(), _uiState.Game.TechCategories[_researchableTechs[i].Category].Name, _researchableTechs[i].Description, - metaInfo); + () => ImGui.Text(metaInfo)); } ImGui.SetCursorPos(new Vector2(pos.X + 2f, pos.Y)); ImGui.Text(_researchableTechs[i].DisplayName()); diff --git a/Pulsar4X/Pulsar4X.Client/EmpireManagement/ShipDesignWindow.cs b/Pulsar4X/Pulsar4X.Client/EmpireManagement/ShipDesignWindow.cs index 62386e2b6..b9a37f622 100644 --- a/Pulsar4X/Pulsar4X.Client/EmpireManagement/ShipDesignWindow.cs +++ b/Pulsar4X/Pulsar4X.Client/EmpireManagement/ShipDesignWindow.cs @@ -510,7 +510,14 @@ internal void DisplayComponentSelection() ImGui.Text(name); if(ImGui.IsItemHovered()) { - DisplayHelpers.DescriptiveTooltip(AvailableShipComponents[i].Name, AvailableShipComponents[i].TypeName, AvailableShipComponents[i].Description); + void TooltipExtension() + { + ImGui.Text("Mass: " + Stringify.Mass(AvailableShipComponents[i].MassPerUnit)); + ImGui.Text("Volume: " + Stringify.Volume(AvailableShipComponents[i].VolumePerUnit)); + ImGui.Text("Crew Required: " + AvailableShipComponents[i].CrewReq); + } + + DisplayHelpers.DescriptiveTooltip(AvailableShipComponents[i].Name, AvailableShipComponents[i].TypeName, AvailableShipComponents[i].Description, TooltipExtension); } ImGui.TableNextColumn(); ImGui.Text(design.ComponentType);