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="WithRoof.cs" />
|
||||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||||
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\ProductionTabsLogic.cs" />
|
||||||
|
<Compile Include="Widgets\ProductionTypeButtonWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
public class CncIngameChromeLogic
|
public class CncIngameChromeLogic
|
||||||
{
|
{
|
||||||
Widget ingameRoot;
|
Widget ingameRoot;
|
||||||
ProductionTabsWidget queueTabs;
|
|
||||||
World world;
|
World world;
|
||||||
|
|
||||||
void AddChatLine(Color c, string from, string text)
|
void AddChatLine(Color c, string from, string text)
|
||||||
@@ -32,32 +31,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
Game.AddChatLine -= AddChatLine;
|
Game.AddChatLine -= AddChatLine;
|
||||||
Game.BeforeGameStart -= UnregisterEvents;
|
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]
|
[ObjectCreator.UseCtor]
|
||||||
@@ -125,17 +98,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>
|
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>
|
||||||
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
|
"${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;
|
playerWidgets.Get<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
|
||||||
|
|
||||||
var winLossWatcher = playerWidgets.Get<LogicTickerWidget>("WIN_LOSS_WATCHER");
|
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
|
class ProductionTabsWidget : Widget
|
||||||
{
|
{
|
||||||
public readonly string PaletteWidget = null;
|
public readonly string PaletteWidget = null;
|
||||||
|
public readonly string TypesContainer = null;
|
||||||
|
|
||||||
public readonly float ScrollVelocity = 4f;
|
public readonly float ScrollVelocity = 4f;
|
||||||
public readonly int TabWidth = 30;
|
public readonly int TabWidth = 30;
|
||||||
public readonly int ArrowWidth = 20;
|
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
|
Width:170
|
||||||
Height:30
|
Height:30
|
||||||
Children:
|
Children:
|
||||||
ToggleButton@BUILDING:
|
ProductionTypeButton@BUILDING:
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Key: q
|
Key: q
|
||||||
TooltipText: Buildings
|
TooltipText: Buildings
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
|
ProductionGroup:Building
|
||||||
Children:
|
Children:
|
||||||
Image@ICON:
|
Image@ICON:
|
||||||
X:7
|
X:7
|
||||||
Y:7
|
Y:7
|
||||||
ImageCollection:production-icons
|
ImageCollection:production-icons
|
||||||
ToggleButton@DEFENSE:
|
ProductionTypeButton@DEFENSE:
|
||||||
X:35
|
X:35
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Key: w
|
Key: w
|
||||||
TooltipText: Defense
|
TooltipText: Defense
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
|
ProductionGroup:Defense
|
||||||
Children:
|
Children:
|
||||||
Image@ICON:
|
Image@ICON:
|
||||||
X:7
|
X:7
|
||||||
Y:7
|
Y:7
|
||||||
ImageCollection:production-icons
|
ImageCollection:production-icons
|
||||||
ToggleButton@INFANTRY:
|
ProductionTypeButton@INFANTRY:
|
||||||
X:70
|
X:70
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Key: e
|
Key: e
|
||||||
TooltipText: Infantry
|
TooltipText: Infantry
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
|
ProductionGroup:Infantry
|
||||||
Children:
|
Children:
|
||||||
Image@ICON:
|
Image@ICON:
|
||||||
X:7
|
X:7
|
||||||
Y:7
|
Y:7
|
||||||
ImageCollection:production-icons
|
ImageCollection:production-icons
|
||||||
ToggleButton@VEHICLE:
|
ProductionTypeButton@VEHICLE:
|
||||||
X:105
|
X:105
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Key: r
|
Key: r
|
||||||
TooltipText: Vehicles
|
TooltipText: Vehicles
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
|
ProductionGroup:Vehicle
|
||||||
Children:
|
Children:
|
||||||
Image@ICON:
|
Image@ICON:
|
||||||
X:7
|
X:7
|
||||||
Y:7
|
Y:7
|
||||||
ImageCollection:production-icons
|
ImageCollection:production-icons
|
||||||
ToggleButton@AIRCRAFT:
|
ProductionTypeButton@AIRCRAFT:
|
||||||
X:140
|
X:140
|
||||||
Width:30
|
Width:30
|
||||||
Height:30
|
Height:30
|
||||||
Key: t
|
Key: t
|
||||||
TooltipText: Aircraft
|
TooltipText: Aircraft
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
|
ProductionGroup:Aircraft
|
||||||
Children:
|
Children:
|
||||||
Image@ICON:
|
Image@ICON:
|
||||||
X:7
|
X:7
|
||||||
Y:7
|
Y:7
|
||||||
ImageCollection:production-icons
|
ImageCollection:production-icons
|
||||||
ProductionTabs@PRODUCTION_TABS:
|
ProductionTabs@PRODUCTION_TABS:
|
||||||
|
Logic:ProductionTabsLogic
|
||||||
PaletteWidget:PRODUCTION_PALETTE
|
PaletteWidget:PRODUCTION_PALETTE
|
||||||
|
TypesContainer:PRODUCTION_TYPES
|
||||||
X:WINDOW_RIGHT - 204
|
X:WINDOW_RIGHT - 204
|
||||||
Y:268
|
Y:268
|
||||||
Width:194
|
Width:194
|
||||||
|
|||||||
Reference in New Issue
Block a user