Simple world tooltip.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public class WorldInteractionControllerWidget : Widget
|
||||
{
|
||||
readonly World world;
|
||||
protected readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
|
||||
@@ -101,6 +101,8 @@
|
||||
<Compile Include="Widgets\TooltipButtonWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\TooltipWorldInteractionControllerWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
43
OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs
Normal file
43
OpenRA.Mods.Cnc/Widgets/Logic/WorldTooltipLogic.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#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 OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
using T = OpenRA.Mods.Cnc.Widgets.TooltipWorldInteractionControllerWidget;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class WorldTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] TooltipWorldInteractionControllerWidget wic)
|
||||
{
|
||||
widget.IsVisible = () => wic.TooltipType != T.WorldTooltipType.None;
|
||||
|
||||
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||
var font = Game.Renderer.Fonts[label.Font];
|
||||
var cachedWidth = 0;
|
||||
label.GetText = () =>
|
||||
{
|
||||
var text = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||
wic.ActorTooltip.Name();
|
||||
var textWidth = font.Measure(text).X;
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||
}
|
||||
return text;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#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 OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class TooltipWorldInteractionControllerWidget : WorldInteractionControllerWidget
|
||||
{
|
||||
public readonly string TooltipTemplate = "WORLD_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public enum WorldTooltipType { None, Unexplored, Actor }
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public TooltipWorldInteractionControllerWidget([ObjectCreator.Param] World world,
|
||||
[ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||
: base(world, worldRenderer)
|
||||
{
|
||||
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(
|
||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "world", world }, { "wic", this }}));
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public void UpdateMouseover()
|
||||
{
|
||||
TooltipType = WorldTooltipType.None;
|
||||
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
|
||||
if (!world.Map.IsInMap(cell))
|
||||
return;
|
||||
|
||||
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(cell))
|
||||
{
|
||||
TooltipType = WorldTooltipType.Unexplored;
|
||||
return;
|
||||
}
|
||||
|
||||
var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
ActorTooltip = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
if (ActorTooltip != null)
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
UpdateMouseover();
|
||||
|
||||
return base.HandleMouseInput(mi);
|
||||
}
|
||||
|
||||
float2 cachedLocation;
|
||||
public override void Tick()
|
||||
{
|
||||
if (Game.viewport.Location != cachedLocation)
|
||||
{
|
||||
UpdateMouseover();
|
||||
cachedLocation = Game.viewport.Location;
|
||||
}
|
||||
base.Tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
}
|
||||
|
||||
public override string GetCursor(int2 pos) { return null; }
|
||||
|
||||
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (World == null) return false;
|
||||
|
||||
@@ -2,10 +2,6 @@ Container@INGAME_ROOT:
|
||||
Id:INGAME_ROOT
|
||||
Logic:CncIngameChromeLogic
|
||||
Children:
|
||||
WorldInteractionController:
|
||||
Id:INTERACTION_CONTROLLER
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
ViewportScrollController:
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
@@ -17,6 +13,11 @@ Container@INGAME_ROOT:
|
||||
Id:STRATEGIC_PROGRESS
|
||||
X: WINDOW_RIGHT/2
|
||||
Y: 40
|
||||
TooltipWorldInteractionController:
|
||||
Id:INTERACTION_CONTROLLER
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
Button@CHEATS_BUTTON:
|
||||
Id:CHEATS_BUTTON
|
||||
X:WINDOW_RIGHT-400
|
||||
|
||||
@@ -2,7 +2,36 @@ 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@BUTTON_TOOLTIP:
|
||||
Id:BUTTON_TOOLTIP
|
||||
Logic:ButtonTooltipLogic
|
||||
Background:panel-black
|
||||
Height:25
|
||||
Children:
|
||||
Label@LABEL:
|
||||
Id:LABEL
|
||||
X:5
|
||||
Height:23
|
||||
Font:Bold
|
||||
Label@HOTKEY:
|
||||
Id:HOTKEY
|
||||
Color:255,255,0
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@WORLD_TOOLTIP:
|
||||
Id:WORLD_TOOLTIP
|
||||
Logic:WorldTooltipLogic
|
||||
Background:panel-black
|
||||
Width:141
|
||||
Height:25
|
||||
Children:
|
||||
Label@LABEL:
|
||||
@@ -24,20 +53,3 @@ Background@PRODUCTION_TOOLTIP:
|
||||
Width:PARENT_RIGHT-10
|
||||
Height:23
|
||||
Font:Bold
|
||||
Background@BUTTON_TOOLTIP:
|
||||
Id:BUTTON_TOOLTIP
|
||||
Logic:ButtonTooltipLogic
|
||||
Background:panel-black
|
||||
Width:100
|
||||
Height:25
|
||||
Children:
|
||||
Label@LABEL:
|
||||
Id:LABEL
|
||||
X:5
|
||||
Height:23
|
||||
Font:Bold
|
||||
Label@HOTKEY:
|
||||
Id:HOTKEY
|
||||
Color:255,255,0
|
||||
Height:23
|
||||
Font:Bold
|
||||
Reference in New Issue
Block a user