Break production tabs logic into a separate file.
Also unhardcodes the production types.
This commit is contained in:
@@ -115,6 +115,8 @@
|
||||
<Compile Include="WithRoof.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTabsLogic.cs" />
|
||||
<Compile Include="Widgets\ProductionTypeButtonWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
public class CncIngameChromeLogic
|
||||
{
|
||||
Widget ingameRoot;
|
||||
ProductionTabsWidget queueTabs;
|
||||
World world;
|
||||
|
||||
void AddChatLine(Color c, string from, string text)
|
||||
@@ -32,32 +31,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
Game.AddChatLine -= AddChatLine;
|
||||
Game.BeforeGameStart -= UnregisterEvents;
|
||||
|
||||
if (queueTabs != null)
|
||||
{
|
||||
world.ActorAdded += queueTabs.ActorChanged;
|
||||
world.ActorRemoved += queueTabs.ActorChanged;
|
||||
}
|
||||
}
|
||||
|
||||
void SetupProductionGroupButton(ToggleButtonWidget button, string group)
|
||||
{
|
||||
Action<bool> selectTab = reverse =>
|
||||
{
|
||||
if (queueTabs.QueueGroup == group)
|
||||
queueTabs.SelectNextTab(reverse);
|
||||
else
|
||||
queueTabs.QueueGroup = group;
|
||||
};
|
||||
|
||||
button.IsDisabled = () => queueTabs.Groups[group].Tabs.Count == 0;
|
||||
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||
button.IsToggled = () => queueTabs.QueueGroup == group;
|
||||
var chromeName = group.ToLowerInvariant();
|
||||
var icon = button.Get<ImageWidget>("ICON");
|
||||
icon.GetImageName = () => button.IsDisabled() ? chromeName+"-disabled" :
|
||||
queueTabs.Groups[group].Alert ? chromeName+"-alert" : chromeName;
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -125,17 +98,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>
|
||||
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
|
||||
|
||||
queueTabs = playerWidgets.Get<ProductionTabsWidget>("PRODUCTION_TABS");
|
||||
world.ActorAdded += queueTabs.ActorChanged;
|
||||
world.ActorRemoved += queueTabs.ActorChanged;
|
||||
|
||||
var queueTypes = sidebarRoot.Get("PRODUCTION_TYPES");
|
||||
SetupProductionGroupButton(queueTypes.Get<ToggleButtonWidget>("BUILDING"), "Building");
|
||||
SetupProductionGroupButton(queueTypes.Get<ToggleButtonWidget>("DEFENSE"), "Defense");
|
||||
SetupProductionGroupButton(queueTypes.Get<ToggleButtonWidget>("INFANTRY"), "Infantry");
|
||||
SetupProductionGroupButton(queueTypes.Get<ToggleButtonWidget>("VEHICLE"), "Vehicle");
|
||||
SetupProductionGroupButton(queueTypes.Get<ToggleButtonWidget>("AIRCRAFT"), "Aircraft");
|
||||
|
||||
playerWidgets.Get<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
|
||||
|
||||
var winLossWatcher = playerWidgets.Get<LogicTickerWidget>("WIN_LOSS_WATCHER");
|
||||
|
||||
70
OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs
Normal file
70
OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
#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.Mods.RA.Orders;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class ProductionTabsLogic
|
||||
{
|
||||
ProductionTabsWidget tabs;
|
||||
World world;
|
||||
|
||||
void SetupProductionGroupButton(ProductionTypeButtonWidget button)
|
||||
{
|
||||
if (button == null)
|
||||
return;
|
||||
|
||||
Action<bool> selectTab = reverse =>
|
||||
{
|
||||
if (tabs.QueueGroup == button.ProductionGroup)
|
||||
tabs.SelectNextTab(reverse);
|
||||
else
|
||||
tabs.QueueGroup = button.ProductionGroup;
|
||||
};
|
||||
|
||||
button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0;
|
||||
button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift));
|
||||
button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||
button.IsToggled = () => tabs.QueueGroup == button.ProductionGroup;
|
||||
|
||||
var chromeName = button.ProductionGroup.ToLowerInvariant();
|
||||
var icon = button.Get<ImageWidget>("ICON");
|
||||
icon.GetImageName = () => button.IsDisabled() ? chromeName+"-disabled" :
|
||||
tabs.Groups[button.ProductionGroup].Alert ? chromeName+"-alert" : chromeName;
|
||||
}
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ProductionTabsLogic(Widget widget, World world)
|
||||
{
|
||||
this.world = world;
|
||||
tabs = widget.Get<ProductionTabsWidget>("PRODUCTION_TABS");
|
||||
world.ActorAdded += tabs.ActorChanged;
|
||||
world.ActorRemoved += tabs.ActorChanged;
|
||||
Game.BeforeGameStart += UnregisterEvents;
|
||||
|
||||
var typesContainer = Ui.Root.Get(tabs.TypesContainer);
|
||||
foreach (var i in typesContainer.Children)
|
||||
SetupProductionGroupButton(i as ProductionTypeButtonWidget);
|
||||
}
|
||||
|
||||
void UnregisterEvents()
|
||||
{
|
||||
Game.BeforeGameStart -= UnregisterEvents;
|
||||
world.ActorAdded -= tabs.ActorChanged;
|
||||
world.ActorRemoved -= tabs.ActorChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
class ProductionTabsWidget : Widget
|
||||
{
|
||||
public readonly string PaletteWidget = null;
|
||||
public readonly string TypesContainer = null;
|
||||
|
||||
public readonly float ScrollVelocity = 4f;
|
||||
public readonly int TabWidth = 30;
|
||||
public readonly int ArrowWidth = 20;
|
||||
|
||||
29
OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs
Normal file
29
OpenRA.Mods.Cnc/Widgets/ProductionTypeButtonWidget.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
#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.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class ProductionTypeButtonWidget : ToggleButtonWidget
|
||||
{
|
||||
public readonly string ProductionGroup;
|
||||
|
||||
public ProductionTypeButtonWidget() : base() {}
|
||||
protected ProductionTypeButtonWidget(ProductionTypeButtonWidget other)
|
||||
: base(other)
|
||||
{
|
||||
ProductionGroup = other.ProductionGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,67 +190,74 @@ Container@PLAYER_WIDGETS:
|
||||
Width:170
|
||||
Height:30
|
||||
Children:
|
||||
ToggleButton@BUILDING:
|
||||
ProductionTypeButton@BUILDING:
|
||||
Width:30
|
||||
Height:30
|
||||
Key: q
|
||||
TooltipText: Buildings
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
ProductionGroup:Building
|
||||
Children:
|
||||
Image@ICON:
|
||||
X:7
|
||||
Y:7
|
||||
ImageCollection:production-icons
|
||||
ToggleButton@DEFENSE:
|
||||
ProductionTypeButton@DEFENSE:
|
||||
X:35
|
||||
Width:30
|
||||
Height:30
|
||||
Key: w
|
||||
TooltipText: Defense
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
ProductionGroup:Defense
|
||||
Children:
|
||||
Image@ICON:
|
||||
X:7
|
||||
Y:7
|
||||
ImageCollection:production-icons
|
||||
ToggleButton@INFANTRY:
|
||||
ProductionTypeButton@INFANTRY:
|
||||
X:70
|
||||
Width:30
|
||||
Height:30
|
||||
Key: e
|
||||
TooltipText: Infantry
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
ProductionGroup:Infantry
|
||||
Children:
|
||||
Image@ICON:
|
||||
X:7
|
||||
Y:7
|
||||
ImageCollection:production-icons
|
||||
ToggleButton@VEHICLE:
|
||||
ProductionTypeButton@VEHICLE:
|
||||
X:105
|
||||
Width:30
|
||||
Height:30
|
||||
Key: r
|
||||
TooltipText: Vehicles
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
ProductionGroup:Vehicle
|
||||
Children:
|
||||
Image@ICON:
|
||||
X:7
|
||||
Y:7
|
||||
ImageCollection:production-icons
|
||||
ToggleButton@AIRCRAFT:
|
||||
ProductionTypeButton@AIRCRAFT:
|
||||
X:140
|
||||
Width:30
|
||||
Height:30
|
||||
Key: t
|
||||
TooltipText: Aircraft
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
ProductionGroup:Aircraft
|
||||
Children:
|
||||
Image@ICON:
|
||||
X:7
|
||||
Y:7
|
||||
ImageCollection:production-icons
|
||||
ProductionTabs@PRODUCTION_TABS:
|
||||
Logic:ProductionTabsLogic
|
||||
PaletteWidget:PRODUCTION_PALETTE
|
||||
TypesContainer:PRODUCTION_TYPES
|
||||
X:WINDOW_RIGHT - 204
|
||||
Y:268
|
||||
Width:194
|
||||
|
||||
Reference in New Issue
Block a user