Skip to content

Commit

Permalink
Add an optional extension callback for the DescriptiveTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed Apr 30, 2024
1 parent a2a2c9e commit 26a9798
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Pulsar4X/GameEngine/Components/ComponentDesign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -115,5 +117,8 @@ public bool TryGetAttribute<T>(out T attribute)
attribute = default(T);
return false;
}

[JsonIgnore]
private string DebuggerDisplay => $"({UniqueID}) {Name}";
}
}
1 change: 0 additions & 1 deletion Pulsar4X/GameEngine/Engine/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Newtonsoft.Json;
using Pulsar4X.Components;
using Pulsar4X.Datablobs;
using Pulsar4X.Messaging;

namespace Pulsar4X.Engine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 4 additions & 8 deletions Pulsar4X/Pulsar4X.Client/DisplayHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 26a9798

Please sign in to comment.