world tooltips as widget
This commit is contained in:
@@ -68,8 +68,7 @@ namespace OpenRA
|
|||||||
if (!world.GameHasStarted) return;
|
if (!world.GameHasStarted) return;
|
||||||
if (world.LocalPlayer == null) return;
|
if (world.LocalPlayer == null) return;
|
||||||
|
|
||||||
if (worldTooltipTicks < worldTooltipDelay)
|
++ticksSinceLastMove;
|
||||||
++worldTooltipTicks;
|
|
||||||
|
|
||||||
rootWidget.Tick(world);
|
rootWidget.Tick(world);
|
||||||
}
|
}
|
||||||
@@ -82,37 +81,6 @@ namespace OpenRA
|
|||||||
var typingArea = new Rectangle(240, Game.viewport.Height - 30, Game.viewport.Width - 420, 30);
|
var typingArea = new Rectangle(240, Game.viewport.Height - 30, Game.viewport.Width - 420, 30);
|
||||||
var chatLogArea = new Rectangle(240, Game.viewport.Height - 500, Game.viewport.Width - 420, 500 - 40);
|
var chatLogArea = new Rectangle(240, Game.viewport.Height - 500, Game.viewport.Width - 420, 500 - 40);
|
||||||
DrawChat(typingArea, chatLogArea);
|
DrawChat(typingArea, chatLogArea);
|
||||||
|
|
||||||
DrawWorldTooltip(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawWorldTooltip(World world)
|
|
||||||
{
|
|
||||||
if (worldTooltipTicks < worldTooltipDelay || world == null || world.LocalPlayer == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var actor = world.FindUnitsAtMouse(lastMousePos).FirstOrDefault();
|
|
||||||
if (actor == null) return;
|
|
||||||
|
|
||||||
var text = actor.Info.Traits.Contains<ValuedInfo>() ? actor.Info.Traits.Get<ValuedInfo>().Description : actor.Info.Name;
|
|
||||||
var text2 = (actor.Owner == world.LocalPlayer)
|
|
||||||
? "" : (actor.Owner == world.NeutralPlayer ? "{0}" : "{0} ({1})").F(actor.Owner.PlayerName, world.LocalPlayer.Stances[actor.Owner]);
|
|
||||||
|
|
||||||
var sz = renderer.BoldFont.Measure(text);
|
|
||||||
var sz2 = renderer.RegularFont.Measure(text2);
|
|
||||||
|
|
||||||
sz.X = Math.Max(sz.X, sz2.X);
|
|
||||||
|
|
||||||
if (text2 != "") sz.Y += sz2.Y + 2;
|
|
||||||
|
|
||||||
sz.X += 20;
|
|
||||||
sz.Y += 24;
|
|
||||||
|
|
||||||
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
|
||||||
lastMousePos.X + 20, lastMousePos.Y + 20, lastMousePos.X + sz.X + 20, lastMousePos.Y + sz.Y + 20));
|
|
||||||
|
|
||||||
renderer.BoldFont.DrawText(text, new float2(lastMousePos.X + 30, lastMousePos.Y + 30), Color.White);
|
|
||||||
renderer.RegularFont.DrawText(text2, new float2(lastMousePos.X + 30, lastMousePos.Y + 50), Color.White);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddUiButton(int2 pos, string text, Action<bool> a)
|
void AddUiButton(int2 pos, string text, Action<bool> a)
|
||||||
@@ -385,9 +353,7 @@ namespace OpenRA
|
|||||||
renderer.RegularFont.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
|
renderer.RegularFont.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int worldTooltipDelay = 10; /* ticks */
|
public int ticksSinceLastMove = 0;
|
||||||
|
|
||||||
public int worldTooltipTicks = 0;
|
|
||||||
public int2 lastMousePos;
|
public int2 lastMousePos;
|
||||||
public bool HandleInput(World world, MouseInput mi)
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
@@ -400,7 +366,7 @@ namespace OpenRA
|
|||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
{
|
{
|
||||||
lastMousePos = mi.Location;
|
lastMousePos = mi.Location;
|
||||||
worldTooltipTicks = 0;
|
ticksSinceLastMove = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
var action = buttons.Where(a => a.First.Contains(mi.Location.ToPoint()))
|
||||||
|
|||||||
@@ -277,6 +277,7 @@
|
|||||||
<Compile Include="Graphics\Util.cs" />
|
<Compile Include="Graphics\Util.cs" />
|
||||||
<Compile Include="Graphics\Viewport.cs" />
|
<Compile Include="Graphics\Viewport.cs" />
|
||||||
<Compile Include="Orders\UnitOrderGenerator.cs" />
|
<Compile Include="Orders\UnitOrderGenerator.cs" />
|
||||||
|
<Compile Include="Widgets\WorldTooltipWidget.cs" />
|
||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
<Compile Include="WorldUtils.cs" />
|
<Compile Include="WorldUtils.cs" />
|
||||||
<Compile Include="Traits\Wall.cs" />
|
<Compile Include="Traits\Wall.cs" />
|
||||||
|
|||||||
50
OpenRA.Game/Widgets/WorldTooltipWidget.cs
Normal file
50
OpenRA.Game/Widgets/WorldTooltipWidget.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets
|
||||||
|
{
|
||||||
|
public class WorldTooltipWidget : Widget
|
||||||
|
{
|
||||||
|
const int worldTooltipDelay = 10; /* ticks */
|
||||||
|
|
||||||
|
public override void Draw(World world)
|
||||||
|
{
|
||||||
|
if (Game.chrome.ticksSinceLastMove < worldTooltipDelay || world == null || world.LocalPlayer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var actor = world.FindUnitsAtMouse(Game.chrome.lastMousePos).FirstOrDefault();
|
||||||
|
if (actor == null) return;
|
||||||
|
|
||||||
|
var text = actor.Info.Traits.Contains<ValuedInfo>()
|
||||||
|
? actor.Info.Traits.Get<ValuedInfo>().Description
|
||||||
|
: actor.Info.Name;
|
||||||
|
var text2 = (actor.Owner == world.LocalPlayer)
|
||||||
|
? "" : (actor.Owner == world.NeutralPlayer ? "{0}" : "{0} ({1})").F(actor.Owner.PlayerName, world.LocalPlayer.Stances[actor.Owner]);
|
||||||
|
|
||||||
|
var renderer = Game.chrome.renderer;
|
||||||
|
|
||||||
|
var sz = renderer.BoldFont.Measure(text);
|
||||||
|
var sz2 = renderer.RegularFont.Measure(text2);
|
||||||
|
|
||||||
|
sz.X = Math.Max(sz.X, sz2.X);
|
||||||
|
|
||||||
|
if (text2 != "") sz.Y += sz2.Y + 2;
|
||||||
|
|
||||||
|
sz.X += 20;
|
||||||
|
sz.Y += 24;
|
||||||
|
|
||||||
|
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
|
||||||
|
Game.chrome.lastMousePos.X + 20, Game.chrome.lastMousePos.Y + 20,
|
||||||
|
Game.chrome.lastMousePos.X + sz.X + 20, Game.chrome.lastMousePos.Y + sz.Y + 20));
|
||||||
|
|
||||||
|
renderer.BoldFont.DrawText(text,
|
||||||
|
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 30), Color.White);
|
||||||
|
renderer.RegularFont.DrawText(text2,
|
||||||
|
new float2(Game.chrome.lastMousePos.X + 30, Game.chrome.lastMousePos.Y + 50), Color.White);
|
||||||
|
|
||||||
|
renderer.RgbaSpriteRenderer.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -343,10 +343,10 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Diplomacy
|
Text:Diplomacy
|
||||||
|
WorldTooltip@INGAME_WORLD_TOOLTIP:
|
||||||
|
Id:INGAME_WORLD_TOOLTIP
|
||||||
RadarBin@INGAME_RADAR_BIN:
|
RadarBin@INGAME_RADAR_BIN:
|
||||||
Id:INGAME_RADAR_BIN
|
Id:INGAME_RADAR_BIN
|
||||||
X:WINDOW_RIGHT - WIDTH
|
|
||||||
Y:0
|
|
||||||
MoneyBin@INGAME_MONEY_BIN:
|
MoneyBin@INGAME_MONEY_BIN:
|
||||||
Id:INGAME_MONEY_BIN
|
Id:INGAME_MONEY_BIN
|
||||||
X:WINDOW_RIGHT - WIDTH
|
X:WINDOW_RIGHT - WIDTH
|
||||||
|
|||||||
@@ -343,10 +343,10 @@ Container:
|
|||||||
Width:160
|
Width:160
|
||||||
Height:25
|
Height:25
|
||||||
Text:Diplomacy
|
Text:Diplomacy
|
||||||
|
WorldTooltip@INGAME_WORLD_TOOLTIP:
|
||||||
|
Id:INGAME_WORLD_TOOLTIP
|
||||||
RadarBin@INGAME_RADAR_BIN:
|
RadarBin@INGAME_RADAR_BIN:
|
||||||
Id:INGAME_RADAR_BIN
|
Id:INGAME_RADAR_BIN
|
||||||
X:WINDOW_RIGHT - WIDTH
|
|
||||||
Y:0
|
|
||||||
MoneyBin@INGAME_MONEY_BIN:
|
MoneyBin@INGAME_MONEY_BIN:
|
||||||
Id:INGAME_MONEY_BIN
|
Id:INGAME_MONEY_BIN
|
||||||
X:WINDOW_RIGHT - WIDTH
|
X:WINDOW_RIGHT - WIDTH
|
||||||
|
|||||||
Reference in New Issue
Block a user