IChromeButton support & RA rules change for it
This commit is contained in:
@@ -685,50 +685,22 @@ namespace OpenRa
|
|||||||
rgbaRenderer.Flush();
|
rgbaRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int chromeButtonGap = 2;
|
||||||
|
|
||||||
void DrawButtons( World world )
|
void DrawButtons( World world )
|
||||||
{
|
{
|
||||||
int2 buttonOrigin = new int2(Game.viewport.Width - 320, 2);
|
var origin = new int2(Game.viewport.Width - 200, 2);
|
||||||
// Repair
|
|
||||||
Rectangle repairRect = new Rectangle(buttonOrigin.X, buttonOrigin.Y, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
|
||||||
var repairDrawPos = new float2(repairRect.Location);
|
|
||||||
|
|
||||||
var hasFact = world.Queries.OwnedBy[world.LocalPlayer].WithTrait<ConstructionYard>().Any();
|
|
||||||
|
|
||||||
if (Game.Settings.RepairRequiresConyard && !hasFact)
|
|
||||||
repairButton.ReplaceAnim("disabled");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
|
||||||
AddButton(repairRect, isLmb => Game.controller.ToggleInputMode<RepairOrderGenerator>());
|
|
||||||
}
|
|
||||||
shpRenderer.DrawSprite(repairButton.Image, repairDrawPos, "chrome");
|
|
||||||
|
|
||||||
// Sell
|
foreach (var cb in world.WorldActor.traits.WithInterface<IChromeButton>())
|
||||||
Rectangle sellRect = new Rectangle(buttonOrigin.X+40, buttonOrigin.Y,
|
|
||||||
sellButton.Image.bounds.Width, sellButton.Image.bounds.Height);
|
|
||||||
|
|
||||||
var sellDrawPos = new float2(sellRect.Location);
|
|
||||||
|
|
||||||
sellButton.ReplaceAnim(Game.controller.orderGenerator is SellOrderGenerator ? "pressed" : "normal");
|
|
||||||
|
|
||||||
AddButton(sellRect, isLmb => Game.controller.ToggleInputMode<SellOrderGenerator>());
|
|
||||||
shpRenderer.DrawSprite(sellButton.Image, sellDrawPos, "chrome");
|
|
||||||
shpRenderer.Flush();
|
|
||||||
|
|
||||||
if (Game.Settings.PowerDownBuildings)
|
|
||||||
{
|
{
|
||||||
// Power Down
|
var button = cb;
|
||||||
Rectangle pwrdownRect = new Rectangle(buttonOrigin.X+80, buttonOrigin.Y,
|
var anim = new Animation(cb.Image);
|
||||||
pwrdownButton.Image.bounds.Width, pwrdownButton.Image.bounds.Height);
|
anim.Play(cb.Enabled ? cb.Pressed ? "pressed" : "normal" : "disabled");
|
||||||
|
origin.X -= (int)anim.Image.size.X + chromeButtonGap;
|
||||||
var pwrdownDrawPos = new float2(pwrdownRect.Location);
|
shpRenderer.DrawSprite(anim.Image, origin, "chrome");
|
||||||
|
AddButton(new RectangleF(origin.X, origin.Y, anim.Image.size.X, anim.Image.size.Y),
|
||||||
pwrdownButton.ReplaceAnim(Game.controller.orderGenerator is PowerDownOrderGenerator ? "pressed" : "normal");
|
_ => { if (button.Enabled) button.OnClick(); });
|
||||||
|
|
||||||
AddButton(pwrdownRect, isLmb => Game.controller.ToggleInputMode<PowerDownOrderGenerator>());
|
|
||||||
shpRenderer.DrawSprite(pwrdownButton.Image, pwrdownDrawPos, "chrome");
|
|
||||||
}
|
}
|
||||||
shpRenderer.Flush();
|
|
||||||
|
|
||||||
//Options
|
//Options
|
||||||
Rectangle optionsRect = new Rectangle(0,0, optionsButton.Image.bounds.Width,
|
Rectangle optionsRect = new Rectangle(0,0, optionsButton.Image.bounds.Width,
|
||||||
|
|||||||
@@ -108,6 +108,7 @@
|
|||||||
<Compile Include="Support\PerfHistory.cs" />
|
<Compile Include="Support\PerfHistory.cs" />
|
||||||
<Compile Include="Sync.cs" />
|
<Compile Include="Sync.cs" />
|
||||||
<Compile Include="Traits\Attack\AttackOmni.cs" />
|
<Compile Include="Traits\Attack\AttackOmni.cs" />
|
||||||
|
<Compile Include="Traits\Chrome\PowerDownButton.cs" />
|
||||||
<Compile Include="Traits\CustomSellValue.cs" />
|
<Compile Include="Traits\CustomSellValue.cs" />
|
||||||
<Compile Include="Traits\Player\SpawnDefaultUnits.cs" />
|
<Compile Include="Traits\Player\SpawnDefaultUnits.cs" />
|
||||||
<Compile Include="Traits\World\BridgeLoadHook.cs" />
|
<Compile Include="Traits\World\BridgeLoadHook.cs" />
|
||||||
|
|||||||
47
OpenRa.Game/Traits/Chrome/PowerDownButton.cs
Normal file
47
OpenRa.Game/Traits/Chrome/PowerDownButton.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRa.Orders;
|
||||||
|
|
||||||
|
namespace OpenRa.Traits
|
||||||
|
{
|
||||||
|
class PowerDownButtonInfo : StatelessTraitInfo<PowerDownButton> { }
|
||||||
|
|
||||||
|
class PowerDownButton : IChromeButton
|
||||||
|
{
|
||||||
|
public string Image { get { return "repair"; } } // todo: art
|
||||||
|
public bool Enabled { get { return true; } }
|
||||||
|
public bool Pressed { get { return Game.controller.orderGenerator is PowerDownOrderGenerator; } }
|
||||||
|
public void OnClick() { Game.controller.ToggleInputMode<PowerDownOrderGenerator>(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class SellButtonInfo : StatelessTraitInfo<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>(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class RepairButtonInfo : StatelessTraitInfo<RepairButton> { }
|
||||||
|
|
||||||
|
class RepairButton : IChromeButton
|
||||||
|
{
|
||||||
|
public string Image { get { return "repair"; } } // todo: art
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!Game.Settings.RepairRequiresConyard)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return Game.world.Queries.OwnedBy[Game.world.LocalPlayer]
|
||||||
|
.WithTrait<ConstructionYard>().Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Pressed { get { return Game.controller.orderGenerator is RepairOrderGenerator; } }
|
||||||
|
public void OnClick() { Game.controller.ToggleInputMode<RepairOrderGenerator>(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -132,4 +132,12 @@ namespace OpenRa.Traits
|
|||||||
IActivity Tick(Actor self);
|
IActivity Tick(Actor self);
|
||||||
void Cancel(Actor self);
|
void Cancel(Actor self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IChromeButton
|
||||||
|
{
|
||||||
|
string Image { get; }
|
||||||
|
bool Enabled { get; }
|
||||||
|
bool Pressed { get; }
|
||||||
|
void OnClick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,9 @@ World:
|
|||||||
Country@7:
|
Country@7:
|
||||||
Name: Spain
|
Name: Spain
|
||||||
Race: allies
|
Race: allies
|
||||||
|
SellButton:
|
||||||
|
RepairButton:
|
||||||
|
PowerDownButton:
|
||||||
|
|
||||||
MGG:
|
MGG:
|
||||||
GeneratesGap:
|
GeneratesGap:
|
||||||
|
|||||||
Reference in New Issue
Block a user