Unify all mods on the C&C order button logic.

This commit is contained in:
Paul Chote
2014-03-21 19:10:46 +13:00
parent 255bfc70d1
commit 0bc3a68e9f
15 changed files with 148 additions and 217 deletions

View File

@@ -84,7 +84,6 @@
<Compile Include="SpawnViceroid.cs" />
<Compile Include="TiberiumRefinery.cs" />
<Compile Include="Widgets\CncWidgetUtils.cs" />
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />

View File

@@ -24,17 +24,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget ingameRoot;
World world;
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
where T : IOrderGenerator, new()
{
var w = parent.Get<ButtonWidget>(button);
w.OnClick = () => world.ToggleInputMode<T>();
w.IsHighlighted = () => world.OrderGenerator is T;
w.Get<ImageWidget>("ICON").GetImageName =
() => world.OrderGenerator is T ? icon + "-active" : icon;
}
[ObjectCreator.UseCtor]
public CncIngameChromeLogic(Widget widget, World world)
{
@@ -87,13 +76,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
playerWidgets.IsVisible = () => true;
var sidebarRoot = playerWidgets.Get("SIDEBAR_BACKGROUND");
BindOrderButton<SellOrderGenerator>(world, sidebarRoot, "SELL_BUTTON", "sell");
BindOrderButton<RepairOrderGenerator>(world, sidebarRoot, "REPAIR_BUTTON", "repair");
sidebarRoot.Get<ButtonWidget>("SELL_BUTTON").Key = Game.Settings.Keys.SellKey;
sidebarRoot.Get<ButtonWidget>("REPAIR_BUTTON").Key = Game.Settings.Keys.RepairKey;
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>

View File

@@ -406,7 +406,6 @@
<Compile Include="Widgets\MoneyBinWidget.cs" />
<Compile Include="Widgets\ObserverProductionIconsWidget.cs" />
<Compile Include="Widgets\ObserverSupportPowerIconsWidget.cs" />
<Compile Include="Widgets\OrderButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="Widgets\StrategicProgressWidget.cs" />
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
@@ -488,6 +487,7 @@
<Compile Include="Attack\AttackFollow.cs" />
<Compile Include="Attack\AttackGarrisoned.cs" />
<Compile Include="Widgets\Logic\LobbyMapPreviewLogic.cs" />
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 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,
@@ -10,7 +10,7 @@
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ButtonTooltipLogic
{

View File

@@ -111,11 +111,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
objectivesButton.OnClick += () => objectivesWidget.Visible ^= true;
}
var moneyBin = playerWidgets.Get("INGAME_MONEY_BIN");
moneyBin.Get<OrderButtonWidget>("SELL").GetKey = _ => Game.Settings.Keys.SellKey;
moneyBin.Get<OrderButtonWidget>("POWER_DOWN").GetKey = _ => Game.Settings.Keys.PowerDownKey;
moneyBin.Get<OrderButtonWidget>("REPAIR").GetKey = _ => Game.Settings.Keys.RepairKey;
bool radarActive = false;
RadarBinState binState = RadarBinState.Closed;
var radarBin = playerWidgets.Get<SlidingContainerWidget>("INGAME_RADAR_BIN");

View File

@@ -16,32 +16,38 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public class OrderButtonsChromeLogic
{
[ObjectCreator.UseCtor]
public OrderButtonsChromeLogic(World world)
public OrderButtonsChromeLogic(Widget widget, World world)
{
/* TODO: attach this to the correct widget, to remove the lookups below */
var r = Ui.Root;
var gameRoot = r.Get("INGAME_ROOT");
var moneybin = gameRoot.Get("INGAME_MONEY_BIN");
moneybin.IsVisible = () => {
return world.LocalPlayer.WinState == WinState.Undefined;
};
BindOrderButton<SellOrderGenerator>(world, moneybin, "SELL");
BindOrderButton<PowerDownOrderGenerator>(world, moneybin, "POWER_DOWN");
BindOrderButton<RepairOrderGenerator>(world, moneybin, "REPAIR");
var sell = widget.GetOrNull<ButtonWidget>("SELL_BUTTON");
if (sell != null)
{
sell.GetKey = _ => Game.Settings.Keys.SellKey;
BindOrderButton<SellOrderGenerator>(world, sell, "sell");
}
static void BindOrderButton<T>(World world, Widget parent, string button)
var repair = widget.GetOrNull<ButtonWidget>("REPAIR_BUTTON");
if (repair != null)
{
repair.GetKey = _ => Game.Settings.Keys.RepairKey;
BindOrderButton<RepairOrderGenerator>(world, repair, "repair");
}
var power = widget.GetOrNull<ButtonWidget>("POWER_BUTTON");
if (power != null)
{
power.GetKey = _ => Game.Settings.Keys.PowerDownKey;
BindOrderButton<PowerDownOrderGenerator>(world, power, "power");
}
}
static void BindOrderButton<T>(World world, ButtonWidget w, string icon)
where T : IOrderGenerator, new()
{
var w = parent.GetOrNull<OrderButtonWidget>(button);
if (w != null)
{
w.Pressed = () => world.OrderGenerator is T;
w.OnMouseDown = mi => world.ToggleInputMode<T>();
w.OnKeyPress = ki => world.ToggleInputMode<T>();
}
w.OnClick = () => world.ToggleInputMode<T>();
w.IsHighlighted = () => world.OrderGenerator is T;
w.Get<ImageWidget>("ICON").GetImageName =
() => world.OrderGenerator is T ? icon + "-active" : icon;
}
}
}

View File

@@ -1,78 +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 OpenRA.Graphics;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
{
public class OrderButtonWidget : ButtonWidget
{
public Func<bool> Enabled = () => true;
public Func<bool> Pressed = () => false;
public string Image, Description, LongDesc = "";
public Func<string> GetImage, GetDescription, GetLongDesc;
public OrderButtonWidget()
{
GetImage = () => Enabled() ? Pressed() ? "pressed" : "normal" : "disabled";
GetDescription = () => Key.IsValid() ? "{0} ({1})".F(Description, Key.DisplayString()) : Description;
GetLongDesc = () => LongDesc;
}
public override void Draw()
{
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);
if (rect.Contains(Viewport.LastMousePos))
{
rect = rect.InflateBy(3, 3, 3, 3);
var pos = new int2(rect.Left, rect.Top);
var m = pos + new int2(rect.Width, rect.Height);
var br = pos + new int2(rect.Width, rect.Height + 20);
var u = Game.Renderer.Fonts["Regular"].Measure(GetLongDesc().Replace("\\n", "\n"));
br.X -= u.X;
br.Y += u.Y;
br += new int2(-15, 25);
var border = WidgetUtils.GetBorderSizes("dialog4");
WidgetUtils.DrawPanelPartial("dialog4", rect
.InflateBy(0, 0, 0, border[1]),
PanelSides.Top | PanelSides.Left | PanelSides.Right | PanelSides.Center);
WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(br.X, m.Y, pos.X - br.X, br.Y - m.Y)
.InflateBy(0, 0, border[3], 0),
PanelSides.Top | PanelSides.Left | PanelSides.Bottom | PanelSides.Center);
WidgetUtils.DrawPanelPartial("dialog4", new Rectangle(pos.X, m.Y, m.X - pos.X, br.Y - m.Y)
.InflateBy(border[2], border[0], 0, 0),
PanelSides.Right | PanelSides.Bottom | PanelSides.Center);
pos.X = br.X + 8;
pos.Y = m.Y + 8;
Game.Renderer.Fonts["Bold"].DrawText(GetDescription(), pos, Color.White);
pos += new int2(0, 20);
Game.Renderer.Fonts["Regular"].DrawText(GetLongDesc().Replace("\\n", "\n"), pos, Color.White);
}
Game.Renderer.RgbaSpriteRenderer.DrawSprite(image, new int2(RenderBounds.X, RenderBounds.Y));
}
}
}

View File

@@ -172,6 +172,7 @@ Container@PLAYER_WIDGETS:
ReadyText:Ready
HoldText:On Hold
Background@SIDEBAR_BACKGROUND:
Logic:OrderButtonsChromeLogic
X:WINDOW_RIGHT - 204
Y:30
Width:194

View File

@@ -237,20 +237,16 @@ strategic: strategic.png
enemy_owned: 32,32,32,32
player_owned: 96,0,32,32
sell-button: buttons.png
normal: 0,0,34,28
pressed: 34,0,34,28
disabled: 68,0,34,28
repair-button: buttons.png
normal: 0,28,34,28
pressed: 34,28,34,28
disabled: 68,28,34,28
power-button: buttons.png
normal: 0,56,34,28
pressed: 34,56,34,28
disabled: 68,56,34,28
order-icons: buttons.png
sell: 0,0,34,28
sell-disabled: 68,0,34,28
sell-active: 34,0,34,28
repair: 0,28,34,28
repair-disabled: 68,28,34,28
repair-active: 34,28,34,28
power: 0,56,34,28
power-disabled: 68,56,34,28
power-active: 34,56,34,28
music: musicplayer.png
pause: 0,0,25,25

View File

@@ -51,38 +51,41 @@ Container@PLAYER_WIDGETS:
Orientation:Horizontal
Style:Bevelled
MoneyBin@INGAME_MONEY_BIN:
Logic:OrderButtonsChromeLogic
X:WINDOW_RIGHT - WIDTH
Y:0
Width:320
Height: 32
Children:
OrderButton@SELL:
Logic:OrderButtonsChromeLogic
Button@SELL_BUTTON:
X:3
Y:0
Width:30
Height:30
Image:sell
Description:Sell
LongDesc:Sell buildings, reclaiming a \nproportion of their build cost
OrderButton@POWER_DOWN:
Logic:OrderButtonsChromeLogic
Width:34
Height:28
TooltipText: Sell
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
Button@POWER_BUTTON:
X:39
Y:0
Width:30
Height:30
Image:power
Description:Powerdown
LongDesc:Disable unneeded structures so their \npower can be used elsewhere
OrderButton@REPAIR:
Logic:OrderButtonsChromeLogic
Width:34
Height:28
TooltipText: Power Down
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
Button@REPAIR_BUTTON:
X:75
Y:0
Width:30
Height:30
Image:repair
Description:Repair
LongDesc:Repair damaged buildings
Width:34
Height:28
TooltipText: Repair
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
SupportPowerBin@INGAME_POWERS_BIN:
X:0
Y:25

View File

@@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP:
Height:23
Font:Bold
Background@BUTTON_TOOLTIP:
Logic:ButtonTooltipLogic
Background:dialog3
Height:31
Children:
Label@LABEL:
X:5
Y:3
Height:23
Font:Bold
Label@HOTKEY:
Y:3
Height:23
TextColor:255,255,0
Font:Bold
Background@WORLD_TOOLTIP:
Logic:WorldTooltipLogic
Background:dialog3

View File

@@ -181,20 +181,16 @@ strategic: strategic.png
enemy_owned: 32,32,32,32
player_owned: 96,0,32,32
sell-button: buttons.png
normal: 0,0,34,28
pressed: 34,0,34,28
disabled: 68,0,34,28
repair-button: buttons.png
normal: 0,28,34,28
pressed: 34,28,34,28
disabled: 68,28,34,28
power-button: buttons.png
normal: 0,56,34,28
pressed: 34,56,34,28
disabled: 68,56,34,28
order-icons: buttons.png
sell: 0,0,34,28
sell-disabled: 68,0,34,28
sell-active: 34,0,34,28
repair: 0,28,34,28
repair-disabled: 68,28,34,28
repair-active: 34,28,34,28
power: 0,56,34,28
power-disabled: 68,56,34,28
power-active: 34,56,34,28
flags: buttons.png
allies: 30,84,30,15

View File

@@ -51,38 +51,41 @@ Container@PLAYER_WIDGETS:
Orientation:Horizontal
Style:Bevelled
MoneyBin@INGAME_MONEY_BIN:
Logic:OrderButtonsChromeLogic
X:WINDOW_RIGHT - WIDTH
Y:0
Width:320
Height: 32
Height:32
Children:
OrderButton@SELL:
Logic:OrderButtonsChromeLogic
Button@SELL_BUTTON:
X:3
Y:0
Width:30
Height:30
Image:sell
Description:Sell
LongDesc:Sell buildings, reclaiming a \nproportion of their build cost
OrderButton@POWER_DOWN:
Logic:OrderButtonsChromeLogic
Width:34
Height:28
TooltipText: Sell
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
Button@POWER_BUTTON:
X:39
Y:0
Width:30
Height:30
Image:power
Description:Powerdown
LongDesc:Disable unneeded structures so their \npower can be used elsewhere
OrderButton@REPAIR:
Logic:OrderButtonsChromeLogic
Width:34
Height:28
TooltipText: Power Down
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
Button@REPAIR_BUTTON:
X:75
Y:0
Width:30
Height:30
Image:repair
Description:Repair
LongDesc:Repair damaged buildings
Width:34
Height:28
TooltipText: Repair
TooltipContainer:TOOLTIP_CONTAINER
VisualHeight:0
Children:
Image@ICON:
ImageCollection:order-icons
SupportPowerBin@INGAME_POWERS_BIN:
X:0
Y:25

View File

@@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP:
Height:23
Font:Bold
Background@BUTTON_TOOLTIP:
Logic:ButtonTooltipLogic
Background:dialog4
Height:29
Children:
Label@LABEL:
X:7
Y:2
Height:23
Font:Bold
Label@HOTKEY:
Y:2
Height:23
TextColor:255,255,0
Font:Bold
Background@WORLD_TOOLTIP:
Logic:WorldTooltipLogic
Background:dialog4

View File

@@ -175,20 +175,16 @@ strategic: strategic.png
enemy_owned: 32,32,32,32
player_owned: 96,0,32,32
sell-button: buttons.png
normal: 0,0,34,28
pressed: 34,0,34,28
disabled: 68,0,34,28
repair-button: buttons.png
normal: 0,28,34,28
pressed: 34,28,34,28
disabled: 68,28,34,28
power-button: buttons.png
normal: 0,56,34,28
pressed: 34,56,34,28
disabled: 68,56,34,28
order-icons: buttons.png
sell: 0,0,34,28
sell-disabled: 68,0,34,28
sell-active: 34,0,34,28
repair: 0,28,34,28
repair-disabled: 68,28,34,28
repair-active: 34,28,34,28
power: 0,56,34,28
power-disabled: 68,56,34,28
power-active: 34,56,34,28
flags: buttons.png
gdi: 30,84,30,15