Simple world tooltip.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
public class WorldInteractionControllerWidget : Widget
|
public class WorldInteractionControllerWidget : Widget
|
||||||
{
|
{
|
||||||
readonly World world;
|
protected readonly World world;
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Widgets
|
|||||||
int2 dragStart, dragEnd;
|
int2 dragStart, dragEnd;
|
||||||
|
|
||||||
public override bool HandleMouseInput(MouseInput mi)
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
var xy = Game.viewport.ViewToWorldPx(mi);
|
var xy = Game.viewport.ViewToWorldPx(mi);
|
||||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -101,6 +101,8 @@
|
|||||||
<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" />
|
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||||
|
<Compile Include="Widgets\TooltipWorldInteractionControllerWidget.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<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
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string GetCursor(int2 pos) { return null; }
|
public override string GetCursor(int2 pos) { return null; }
|
||||||
|
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPress(KeyInput e)
|
||||||
{
|
{
|
||||||
if (World == null) return false;
|
if (World == null) return false;
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ Container@INGAME_ROOT:
|
|||||||
Id:INGAME_ROOT
|
Id:INGAME_ROOT
|
||||||
Logic:CncIngameChromeLogic
|
Logic:CncIngameChromeLogic
|
||||||
Children:
|
Children:
|
||||||
WorldInteractionController:
|
|
||||||
Id:INTERACTION_CONTROLLER
|
|
||||||
Width:WINDOW_RIGHT
|
|
||||||
Height:WINDOW_BOTTOM
|
|
||||||
ViewportScrollController:
|
ViewportScrollController:
|
||||||
Width:WINDOW_RIGHT
|
Width:WINDOW_RIGHT
|
||||||
Height:WINDOW_BOTTOM
|
Height:WINDOW_BOTTOM
|
||||||
@@ -17,6 +13,11 @@ Container@INGAME_ROOT:
|
|||||||
Id:STRATEGIC_PROGRESS
|
Id:STRATEGIC_PROGRESS
|
||||||
X: WINDOW_RIGHT/2
|
X: WINDOW_RIGHT/2
|
||||||
Y: 40
|
Y: 40
|
||||||
|
TooltipWorldInteractionController:
|
||||||
|
Id:INTERACTION_CONTROLLER
|
||||||
|
Width:WINDOW_RIGHT
|
||||||
|
Height:WINDOW_BOTTOM
|
||||||
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
Button@CHEATS_BUTTON:
|
Button@CHEATS_BUTTON:
|
||||||
Id:CHEATS_BUTTON
|
Id:CHEATS_BUTTON
|
||||||
X:WINDOW_RIGHT-400
|
X:WINDOW_RIGHT-400
|
||||||
|
|||||||
@@ -2,7 +2,36 @@ Background@SIMPLE_TOOLTIP:
|
|||||||
Id:SIMPLE_TOOLTIP
|
Id:SIMPLE_TOOLTIP
|
||||||
Logic:SimpleTooltipLogic
|
Logic:SimpleTooltipLogic
|
||||||
Background:panel-black
|
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
|
Height:25
|
||||||
Children:
|
Children:
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
@@ -23,21 +52,4 @@ Background@PRODUCTION_TOOLTIP:
|
|||||||
X:5
|
X:5
|
||||||
Width:PARENT_RIGHT-10
|
Width:PARENT_RIGHT-10
|
||||||
Height:23
|
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
|
Font:Bold
|
||||||
Reference in New Issue
Block a user