unhacking IChromeButton.
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
// TODO: Migrate these to be real widgets, and kill all the weird infrastructure that's holding these up.
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class PowerDownButtonInfo : TraitInfo<PowerDownButton> { }
|
||||
|
||||
class PowerDownButton : IChromeButton
|
||||
{
|
||||
public string Image { get { return "power"; } }
|
||||
public bool Enabled { get { return true; } }
|
||||
public bool Pressed { get { return Game.controller.orderGenerator is PowerDownOrderGenerator; } }
|
||||
public void OnClick() { Game.controller.ToggleInputMode<PowerDownOrderGenerator>(); }
|
||||
|
||||
public string Description { get { return "Powerdown"; } }
|
||||
public string LongDesc { get { return "Disable unneeded structures so their \npower can be used elsewhere"; } }
|
||||
}
|
||||
|
||||
class SellButtonInfo : TraitInfo<SellButton> { }
|
||||
|
||||
class SellButton : IChromeButton
|
||||
{
|
||||
public string Image { get { return "sell"; } }
|
||||
public bool Enabled { get { return true; } }
|
||||
public bool Pressed { get { return Game.controller.orderGenerator is SellOrderGenerator; } }
|
||||
public void OnClick() { Game.controller.ToggleInputMode<SellOrderGenerator>(); }
|
||||
|
||||
public string Description { get { return "Sell"; } }
|
||||
public string LongDesc { get { return "Sell buildings, reclaiming a \nproportion of their build cost"; } }
|
||||
}
|
||||
|
||||
class RepairButtonInfo : ITraitInfo
|
||||
{
|
||||
public readonly bool RequiresConstructionYard = true;
|
||||
public object Create(ActorInitializer init) { return new RepairButton(); }
|
||||
}
|
||||
|
||||
class RepairButton : IChromeButton
|
||||
{
|
||||
public RepairButton() { }
|
||||
|
||||
public string Image { get { return "repair"; } }
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
// WTF: why are these buttons even traits?
|
||||
return RepairOrderGenerator.PlayerIsAllowedToRepair( Game.world );
|
||||
}
|
||||
}
|
||||
|
||||
public bool Pressed { get { return Game.controller.orderGenerator is RepairOrderGenerator; } }
|
||||
public void OnClick() { Game.controller.ToggleInputMode<RepairOrderGenerator>(); }
|
||||
|
||||
public string Description { get { return "Repair"; } }
|
||||
public string LongDesc
|
||||
{
|
||||
get
|
||||
{
|
||||
var s = "Repair damaged buildings";
|
||||
return Enabled ? s : s + "\n\nRequires: Construction Yard";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -107,7 +107,6 @@
|
||||
<Compile Include="CanPowerDown.cs" />
|
||||
<Compile Include="Cargo.cs" />
|
||||
<Compile Include="CarpetBomb.cs" />
|
||||
<Compile Include="Chrome\PowerDownButton.cs" />
|
||||
<Compile Include="Crates\LevelUpCrateAction.cs" />
|
||||
<Compile Include="Orders\PowerDownOrderGenerator.cs" />
|
||||
<Compile Include="Orders\RepairOrderGenerator.cs" />
|
||||
@@ -208,6 +207,7 @@
|
||||
<Compile Include="TransformsOnDeploy.cs" />
|
||||
<Compile Include="Activities\TransformIntoActor.cs" />
|
||||
<Compile Include="PaletteFromCurrentTheatre.cs" />
|
||||
<Compile Include="Widgets\Delegates\OrderButtonsChromeDelegate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
@@ -236,6 +236,6 @@ ralint ra</PostBuildEvent>
|
||||
<ItemGroup>
|
||||
<Folder Include="Widgets\" />
|
||||
<Folder Include="Widgets\Delegates\" />
|
||||
<Folder Include="Widgets\Delegates\" />
|
||||
<Folder Include="Chrome\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -48,9 +48,6 @@ namespace OpenRA.Mods.RA.Orders
|
||||
|
||||
public static bool PlayerIsAllowedToRepair( World world )
|
||||
{
|
||||
if( !world.WorldActor.Info.Traits.Get<RepairButtonInfo>().RequiresConstructionYard )
|
||||
return true;
|
||||
|
||||
return Game.world.Queries.OwnedBy[ Game.world.LocalPlayer ]
|
||||
.WithTrait<Production>().Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( "Building" ) )
|
||||
.Any();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Widgets;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class OrderButtonsChromeDelegate : IWidgetDelegate
|
||||
{
|
||||
public OrderButtonsChromeDelegate()
|
||||
{
|
||||
var r = Game.RootWidget;
|
||||
var gameRoot = r.GetWidget("INGAME_ROOT");
|
||||
|
||||
var moneybin = gameRoot.GetWidget("INGAME_MONEY_BIN");
|
||||
|
||||
var sell = moneybin.GetWidget<OrderButtonWidget>("SELL");
|
||||
if (sell != null)
|
||||
{
|
||||
sell.Pressed = () => Game.controller.orderGenerator is SellOrderGenerator;
|
||||
sell.OnMouseDown = mi => { Game.controller.ToggleInputMode<SellOrderGenerator>(); return true; };
|
||||
}
|
||||
|
||||
var powerdown = moneybin.GetWidget<OrderButtonWidget>("POWER_DOWN");
|
||||
if (powerdown != null)
|
||||
{
|
||||
powerdown.Pressed = () => Game.controller.orderGenerator is PowerDownOrderGenerator;
|
||||
powerdown.OnMouseDown = mi => { Game.controller.ToggleInputMode<PowerDownOrderGenerator>(); return true; };
|
||||
}
|
||||
|
||||
var repair = moneybin.GetWidget<OrderButtonWidget>("REPAIR");
|
||||
if (repair != null)
|
||||
{
|
||||
repair.Enabled = () => { return RepairOrderGenerator.PlayerIsAllowedToRepair( Game.world ); };
|
||||
repair.Pressed = () => Game.controller.orderGenerator is RepairOrderGenerator;
|
||||
repair.OnMouseDown = mi => { Game.controller.ToggleInputMode<RepairOrderGenerator>(); return true; };
|
||||
repair.GetLongDesc = () => { return repair.Enabled() ? repair.LongDesc : repair.LongDesc + "\n\nRequires: Construction Yard"; };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user