Power/Silo bar tooltips.
This commit is contained in:
@@ -100,6 +100,7 @@
|
|||||||
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
||||||
<Compile Include="Widgets\TooltipButtonWidget.cs" />
|
<Compile Include="Widgets\TooltipButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
40
OpenRA.Mods.Cnc/Widgets/Logic/SimpleTooltipLogic.cs
Normal file
40
OpenRA.Mods.Cnc/Widgets/Logic/SimpleTooltipLogic.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using OpenRA.Support;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||||
|
{
|
||||||
|
public class SimpleTooltipLogic
|
||||||
|
{
|
||||||
|
[ObjectCreator.UseCtor]
|
||||||
|
public SimpleTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||||
|
[ObjectCreator.Param] Func<string> getText)
|
||||||
|
{
|
||||||
|
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||||
|
var cachedWidth = 0;
|
||||||
|
var font = Game.Renderer.Fonts[label.Font];
|
||||||
|
label.GetText = () =>
|
||||||
|
{
|
||||||
|
var text = getText();
|
||||||
|
var textWidth = font.Measure(text).X;
|
||||||
|
if (textWidth != cachedWidth)
|
||||||
|
{
|
||||||
|
label.Bounds.Width = textWidth;
|
||||||
|
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.RA.Buildings;
|
using OpenRA.Mods.RA.Buildings;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -18,14 +19,34 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
public class PowerBarWidget : Widget
|
public class PowerBarWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
|
||||||
|
public readonly string TooltipContainer;
|
||||||
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
float? lastProvidedFrac;
|
float? lastProvidedFrac;
|
||||||
float? lastDrainedFrac;
|
float? lastDrainedFrac;
|
||||||
|
|
||||||
readonly PowerManager pm;
|
readonly PowerManager pm;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public PowerBarWidget( [ObjectCreator.Param] World world )
|
public PowerBarWidget( [ObjectCreator.Param] World world )
|
||||||
{
|
{
|
||||||
pm = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
pm = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||||
|
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||||
|
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseEntered()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
Func<string> getText = () => "Power Usage: {0}/{1}".F(pm.PowerDrained, pm.PowerProvided);
|
||||||
|
tooltipContainer.Value.SetTooltip(
|
||||||
|
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "getText", getText }}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseExited()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -18,6 +19,10 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
public class SiloBarWidget : Widget
|
public class SiloBarWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
|
||||||
|
public readonly string TooltipContainer;
|
||||||
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
public float LowStorageThreshold = 0.8f;
|
public float LowStorageThreshold = 0.8f;
|
||||||
float? lastCapacityFrac;
|
float? lastCapacityFrac;
|
||||||
float? lastStoredFrac;
|
float? lastStoredFrac;
|
||||||
@@ -27,6 +32,22 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
public SiloBarWidget( [ObjectCreator.Param] World world )
|
public SiloBarWidget( [ObjectCreator.Param] World world )
|
||||||
{
|
{
|
||||||
pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
||||||
|
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||||
|
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseEntered()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
Func<string> getText = () => "Silo Usage: {0}/{1}".F(pr.Ore, pr.OreCapacity);
|
||||||
|
tooltipContainer.Value.SetTooltip(
|
||||||
|
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "getText", getText }}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void MouseExited()
|
||||||
|
{
|
||||||
|
if (TooltipContainer == null) return;
|
||||||
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ Container@INGAME_ROOT:
|
|||||||
Y:1
|
Y:1
|
||||||
Width:PARENT_RIGHT-2
|
Width:PARENT_RIGHT-2
|
||||||
Height:PARENT_BOTTOM-2
|
Height:PARENT_BOTTOM-2
|
||||||
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
Label@POWERICON:
|
Label@POWERICON:
|
||||||
X:4
|
X:4
|
||||||
Y:180
|
Y:180
|
||||||
@@ -168,6 +169,7 @@ Container@INGAME_ROOT:
|
|||||||
Y:1
|
Y:1
|
||||||
Width:PARENT_RIGHT-2
|
Width:PARENT_RIGHT-2
|
||||||
Height:PARENT_BOTTOM-2
|
Height:PARENT_BOTTOM-2
|
||||||
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
Label@SILOICON:
|
Label@SILOICON:
|
||||||
X:181
|
X:181
|
||||||
Y:180
|
Y:180
|
||||||
|
|||||||
@@ -1,3 +1,16 @@
|
|||||||
|
Background@SIMPLE_TOOLTIP:
|
||||||
|
Id:SIMPLE_TOOLTIP
|
||||||
|
Logic:SimpleTooltipLogic
|
||||||
|
Background:panel-black
|
||||||
|
Width:100
|
||||||
|
Height:25
|
||||||
|
Children:
|
||||||
|
Label@LABEL:
|
||||||
|
Id:LABEL
|
||||||
|
X:5
|
||||||
|
Height:23
|
||||||
|
Font:Bold
|
||||||
|
|
||||||
Background@PRODUCTION_TOOLTIP:
|
Background@PRODUCTION_TOOLTIP:
|
||||||
Id:PRODUCTION_TOOLTIP
|
Id:PRODUCTION_TOOLTIP
|
||||||
Logic:ProductionTooltipLogic
|
Logic:ProductionTooltipLogic
|
||||||
|
|||||||
Reference in New Issue
Block a user