Better support for dynamic tooltip sizes
This commit is contained in:
@@ -42,11 +42,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null) return;
|
||||||
return;
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "world", world }, { "wic", this }});
|
||||||
|
|
||||||
tooltipContainer.Value.SetTooltip(
|
|
||||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "world", world }, { "wic", this }}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -18,22 +18,26 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public SimpleTooltipLogic([ObjectCreator.Param] Widget widget,
|
public SimpleTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||||
|
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
|
||||||
[ObjectCreator.Param] Func<string> getText)
|
[ObjectCreator.Param] Func<string> getText)
|
||||||
{
|
{
|
||||||
var label = widget.GetWidget<LabelWidget>("LABEL");
|
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||||
var cachedWidth = 0;
|
|
||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
label.GetText = () =>
|
var cachedWidth = 0;
|
||||||
|
var labelText = "";
|
||||||
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
var text = getText();
|
labelText = getText();
|
||||||
var textWidth = font.Measure(text).X;
|
var textWidth = font.Measure(labelText).X;
|
||||||
if (textWidth != cachedWidth)
|
if (textWidth != cachedWidth)
|
||||||
{
|
{
|
||||||
label.Bounds.Width = textWidth;
|
label.Bounds.Width = textWidth;
|
||||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
label.GetText = () => labelText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,25 +18,28 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public WorldTooltipLogic([ObjectCreator.Param] Widget widget,
|
public WorldTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||||
|
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
|
||||||
[ObjectCreator.Param] CncWorldInteractionControllerWidget wic)
|
[ObjectCreator.Param] CncWorldInteractionControllerWidget wic)
|
||||||
{
|
{
|
||||||
widget.IsVisible = () => wic.TooltipType != T.WorldTooltipType.None;
|
widget.IsVisible = () => wic.TooltipType != T.WorldTooltipType.None;
|
||||||
|
|
||||||
var label = widget.GetWidget<LabelWidget>("LABEL");
|
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||||
|
|
||||||
var font = Game.Renderer.Fonts[label.Font];
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
var cachedWidth = 0;
|
var cachedWidth = 0;
|
||||||
label.GetText = () =>
|
var labelText = "";
|
||||||
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
var text = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
labelText = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||||
wic.ActorTooltip.Name();
|
wic.ActorTooltip.Name();
|
||||||
var textWidth = font.Measure(text).X;
|
var textWidth = font.Measure(labelText).X;
|
||||||
if (textWidth != cachedWidth)
|
if (textWidth != cachedWidth)
|
||||||
{
|
{
|
||||||
label.Bounds.Width = textWidth;
|
label.Bounds.Width = textWidth;
|
||||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
label.GetText = () => labelText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
if (TooltipContainer == null) return;
|
if (TooltipContainer == null) return;
|
||||||
Func<string> getText = () => "Power Usage: {0}/{1}".F(pm.PowerDrained, pm.PowerProvided);
|
Func<string> getText = () => "Power Usage: {0}/{1}".F(pm.PowerDrained, pm.PowerProvided);
|
||||||
tooltipContainer.Value.SetTooltip(
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }});
|
||||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "getText", getText }}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -92,11 +92,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null) return;
|
||||||
return;
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "palette", this }});
|
||||||
|
|
||||||
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "palette", this }});
|
|
||||||
tooltipContainer.Value.SetTooltip(panel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
if (TooltipContainer == null) return;
|
if (TooltipContainer == null) return;
|
||||||
Func<string> getText = () => "Silo Usage: {0}/{1}".F(pr.Ore, pr.OreCapacity);
|
Func<string> getText = () => "Silo Usage: {0}/{1}".F(pr.Ore, pr.OreCapacity);
|
||||||
tooltipContainer.Value.SetTooltip(
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", getText }});
|
||||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "getText", getText }}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -122,11 +122,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null) return;
|
||||||
return;
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "palette", this }});
|
||||||
|
|
||||||
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "palette", this }});
|
|
||||||
tooltipContainer.Value.SetTooltip(panel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -39,11 +39,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null) return;
|
||||||
return;
|
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "button", this }});
|
||||||
|
|
||||||
tooltipContainer.Value.SetTooltip(
|
|
||||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseExited()
|
public override void MouseExited()
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ using System;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
class TooltipContainerWidget : Widget
|
public class TooltipContainerWidget : Widget
|
||||||
{
|
{
|
||||||
|
static readonly Action Nothing = () => {};
|
||||||
public int2 CursorOffset = new int2(0, 20);
|
public int2 CursorOffset = new int2(0, 20);
|
||||||
|
public Action BeforeRender = Nothing;
|
||||||
public int TooltipDelay = 10;
|
public int TooltipDelay = 10;
|
||||||
Widget tooltip;
|
Widget tooltip;
|
||||||
|
|
||||||
@@ -30,18 +32,19 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
IsVisible = () => Viewport.TicksSinceLastMove >= TooltipDelay;
|
IsVisible = () => Viewport.TicksSinceLastMove >= TooltipDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTooltip(Widget tooltip)
|
public void SetTooltip(string id, WidgetArgs args)
|
||||||
{
|
{
|
||||||
this.tooltip = tooltip;
|
RemoveTooltip();
|
||||||
RemoveChildren();
|
tooltip = Widget.LoadWidget(id, this, new WidgetArgs(args) {{ "tooltipContainer", this }});
|
||||||
AddChild(tooltip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveTooltip()
|
public void RemoveTooltip()
|
||||||
{
|
{
|
||||||
RemoveChildren();
|
RemoveChildren();
|
||||||
|
BeforeRender = Nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Draw() { BeforeRender(); }
|
||||||
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
|
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
|
||||||
public override int2 ChildOrigin
|
public override int2 ChildOrigin
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user