Use C&C world tooltips in RA and D2K. Fixes #2382.
This commit is contained in:
@@ -71,7 +71,7 @@ namespace OpenRA.Widgets
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs() {{ "world", world }, { "wic", this }});
|
||||
new WidgetArgs() {{ "world", world }, { "viewport", this }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
|
||||
@@ -102,7 +102,6 @@
|
||||
<Compile Include="Widgets\Logic\CncSettingsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\ProductionPaletteWidget.cs" />
|
||||
<Compile Include="Widgets\ProductionTabsWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
|
||||
@@ -413,7 +413,6 @@
|
||||
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowerBinWidget.cs" />
|
||||
<Compile Include="Widgets\WorldCommandWidget.cs" />
|
||||
<Compile Include="Widgets\WorldTooltipWidget.cs" />
|
||||
<Compile Include="World\ChooseBuildTabOnSelect.cs" />
|
||||
<Compile Include="World\DebugOverlay.cs" />
|
||||
<Compile Include="World\ResourceClaim.cs" />
|
||||
@@ -462,6 +461,7 @@
|
||||
<Compile Include="MPStartUnits.cs" />
|
||||
<Compile Include="Orders\SetChronoTankDestination.cs" />
|
||||
<Compile Include="Effects\FrozenActorProxy.cs" />
|
||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -12,14 +12,14 @@ using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class WorldTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ViewportControllerWidget wic)
|
||||
public WorldTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ViewportControllerWidget viewport)
|
||||
{
|
||||
widget.IsVisible = () => wic.TooltipType != WorldTooltipType.None;
|
||||
widget.IsVisible = () => viewport.TooltipType != WorldTooltipType.None;
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var flag = widget.Get<ImageWidget>("FLAG");
|
||||
var owner = widget.Get<LabelWidget>("OWNER");
|
||||
@@ -32,24 +32,25 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var flagRace = "";
|
||||
var ownerName = "";
|
||||
var ownerColor = Color.White;
|
||||
var doubleHeight = 45;
|
||||
var singleHeight = 25;
|
||||
|
||||
var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
|
||||
var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
|
||||
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
if (wic == null || wic.TooltipType == WorldTooltipType.None)
|
||||
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
||||
return;
|
||||
|
||||
labelText = wic.TooltipType == WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||
wic.ActorTooltip.Name();
|
||||
labelText = viewport.TooltipType == WorldTooltipType.Unexplored ? "Unexplored Terrain" :
|
||||
viewport.ActorTooltip.Name();
|
||||
var textWidth = font.Measure(labelText).X;
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||
}
|
||||
var o = wic.ActorTooltip != null ? wic.ActorTooltip.Owner() : null;
|
||||
showOwner = wic.TooltipType == WorldTooltipType.Actor && o != null && !o.NonCombatant;
|
||||
var o = viewport.ActorTooltip != null ? viewport.ActorTooltip.Owner() : null;
|
||||
showOwner = viewport.TooltipType == WorldTooltipType.Actor && o != null && !o.NonCombatant;
|
||||
|
||||
if (showOwner)
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
ownerColor = o.Color.RGB;
|
||||
widget.Bounds.Height = doubleHeight;
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + 5);
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
|
||||
}
|
||||
else
|
||||
widget.Bounds.Height = singleHeight;
|
||||
@@ -1,94 +0,0 @@
|
||||
#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 System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class WorldTooltipWidget : Widget
|
||||
{
|
||||
public int TooltipDelay = 10;
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public WorldTooltipWidget(World world) { this.world = world; }
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (Viewport.TicksSinceLastMove < TooltipDelay || world == null)
|
||||
return;
|
||||
|
||||
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
if (!world.Map.IsInMap(cell))
|
||||
return;
|
||||
|
||||
if (world.ShroudObscures(cell))
|
||||
{
|
||||
var utext = "Unexplored Terrain";
|
||||
var usz = Game.Renderer.Fonts["Bold"].Measure(utext) + new int2(20, 24);
|
||||
|
||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
|
||||
Viewport.LastMousePos.X + usz.X + 20, Viewport.LastMousePos.Y + usz.Y + 20));
|
||||
|
||||
Game.Renderer.Fonts["Bold"].DrawText(utext,
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault();
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
var itt = actor.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
if (itt == null)
|
||||
return;
|
||||
|
||||
var owner = itt.Owner();
|
||||
var nameText = itt.Name();
|
||||
var ownerText = !owner.NonCombatant ? owner.PlayerName : "";
|
||||
var stanceText = (world.LocalPlayer != null && owner != actor.World.LocalPlayer
|
||||
&& !owner.NonCombatant) ? " ({0})".F(itt.Stance()) : "";
|
||||
|
||||
var nameSize = Game.Renderer.Fonts["Bold"].Measure(nameText);
|
||||
var ownerSize = Game.Renderer.Fonts["Regular"].Measure(ownerText);
|
||||
var stanceSize = Game.Renderer.Fonts["Regular"].Measure(stanceText);
|
||||
var panelSize = new int2(Math.Max(nameSize.X, ownerSize.X + stanceSize.X + 35) + 20, nameSize.Y + 24);
|
||||
|
||||
if (ownerText != "") panelSize.Y += ownerSize.Y + 2;
|
||||
|
||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
|
||||
Viewport.LastMousePos.X + panelSize.X + 20, Viewport.LastMousePos.Y + panelSize.Y + 20));
|
||||
|
||||
Game.Renderer.Fonts["Bold"].DrawText(nameText,
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
|
||||
|
||||
if (ownerText != "")
|
||||
{
|
||||
Game.Renderer.Fonts["Regular"].DrawText(ownerText,
|
||||
new float2(Viewport.LastMousePos.X + 65, Viewport.LastMousePos.Y + 50), actor.Owner.Color.RGB);
|
||||
|
||||
Game.Renderer.Fonts["Regular"].DrawText(stanceText,
|
||||
new float2(Viewport.LastMousePos.X + 65 + ownerSize.X, Viewport.LastMousePos.Y + 50), Color.White);
|
||||
|
||||
WidgetUtils.DrawRGBA(
|
||||
ChromeProvider.GetImage("flags", actor.Owner.Country.Race),
|
||||
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 50));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,11 @@ Background@BUTTON_TOOLTIP:
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:panel-black
|
||||
Width:141
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:25
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:45
|
||||
Label@LABEL:
|
||||
X:5
|
||||
Height:23
|
||||
|
||||
@@ -9,6 +9,30 @@ Background@SIMPLE_TOOLTIP:
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:dialog3
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:31
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:56
|
||||
Label@LABEL:
|
||||
X:7
|
||||
Y:2
|
||||
Height:23
|
||||
Font:Bold
|
||||
Image@FLAG:
|
||||
X:7
|
||||
Y:27
|
||||
Width:23
|
||||
Height:23
|
||||
Label@OWNER:
|
||||
X:35
|
||||
Y:25
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog3
|
||||
|
||||
@@ -11,6 +11,7 @@ Container@INGAME_ROOT:
|
||||
Y:0
|
||||
Width:WINDOW_RIGHT
|
||||
Height:WINDOW_BOTTOM
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
WorldCommand:
|
||||
X:0
|
||||
Y:0
|
||||
@@ -31,7 +32,6 @@ Container@INGAME_ROOT:
|
||||
Text:Options (ESC)
|
||||
Font:Bold
|
||||
Key: escape
|
||||
WorldTooltip:
|
||||
Background@PERF_BG:
|
||||
ClickThrough:true
|
||||
Background:dialog4
|
||||
|
||||
@@ -9,6 +9,30 @@ Background@SIMPLE_TOOLTIP:
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@WORLD_TOOLTIP:
|
||||
Logic:WorldTooltipLogic
|
||||
Background:dialog4
|
||||
Children:
|
||||
Container@SINGLE_HEIGHT:
|
||||
Height:29
|
||||
Container@DOUBLE_HEIGHT:
|
||||
Height:50
|
||||
Label@LABEL:
|
||||
X:7
|
||||
Y:2
|
||||
Height:23
|
||||
Font:Bold
|
||||
Image@FLAG:
|
||||
X:7
|
||||
Y:27
|
||||
Width:32
|
||||
Height:16
|
||||
Label@OWNER:
|
||||
X:45
|
||||
Y:22
|
||||
Height:23
|
||||
Font:Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:dialog4
|
||||
|
||||
Reference in New Issue
Block a user