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="SpawnViceroid.cs" />
<Compile Include="TiberiumRefinery.cs" /> <Compile Include="TiberiumRefinery.cs" />
<Compile Include="Widgets\CncWidgetUtils.cs" /> <Compile Include="Widgets\CncWidgetUtils.cs" />
<Compile Include="Widgets\Logic\ButtonTooltipLogic.cs" />
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" /> <Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" /> <Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" /> <Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />

View File

@@ -24,17 +24,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget ingameRoot; Widget ingameRoot;
World world; 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] [ObjectCreator.UseCtor]
public CncIngameChromeLogic(Widget widget, World world) public CncIngameChromeLogic(Widget widget, World world)
{ {
@@ -87,13 +76,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
playerWidgets.IsVisible = () => true; playerWidgets.IsVisible = () => true;
var sidebarRoot = playerWidgets.Get("SIDEBAR_BACKGROUND"); 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 powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>(); var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
sidebarRoot.Get<LabelWidget>("CASH").GetText = () => sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>

View File

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

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -10,7 +10,7 @@
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
{ {
public class ButtonTooltipLogic public class ButtonTooltipLogic
{ {

View File

@@ -111,11 +111,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
objectivesButton.OnClick += () => objectivesWidget.Visible ^= true; 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; bool radarActive = false;
RadarBinState binState = RadarBinState.Closed; RadarBinState binState = RadarBinState.Closed;
var radarBin = playerWidgets.Get<SlidingContainerWidget>("INGAME_RADAR_BIN"); var radarBin = playerWidgets.Get<SlidingContainerWidget>("INGAME_RADAR_BIN");

View File

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

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 ReadyText:Ready
HoldText:On Hold HoldText:On Hold
Background@SIDEBAR_BACKGROUND: Background@SIDEBAR_BACKGROUND:
Logic:OrderButtonsChromeLogic
X:WINDOW_RIGHT - 204 X:WINDOW_RIGHT - 204
Y:30 Y:30
Width:194 Width:194

View File

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

View File

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

View File

@@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP:
Height:23 Height:23
Font:Bold 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: Background@WORLD_TOOLTIP:
Logic:WorldTooltipLogic Logic:WorldTooltipLogic
Background:dialog3 Background:dialog3

View File

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

View File

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

View File

@@ -9,6 +9,22 @@ Background@SIMPLE_TOOLTIP:
Height:23 Height:23
Font:Bold 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: Background@WORLD_TOOLTIP:
Logic:WorldTooltipLogic Logic:WorldTooltipLogic
Background:dialog4 Background:dialog4

View File

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