refactoring chrome buttons
This commit is contained in:
@@ -143,6 +143,8 @@ namespace OpenRa.Game
|
|||||||
DrawChat();
|
DrawChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddButton(Rectangle r, Action<bool> b) { buttons.Add(Pair.New(r, b)); }
|
||||||
|
|
||||||
void DrawBuildTabs(int paletteHeight)
|
void DrawBuildTabs(int paletteHeight)
|
||||||
{
|
{
|
||||||
const int tabWidth = 24;
|
const int tabWidth = 24;
|
||||||
@@ -240,66 +242,33 @@ namespace OpenRa.Game
|
|||||||
buildPaletteRenderer.DrawSprite(powerIndicatorSprite, drainedPosition, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(powerIndicatorSprite, drainedPosition, PaletteType.Chrome);
|
||||||
buildPaletteRenderer.Flush();
|
buildPaletteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleButtons(string but)
|
|
||||||
{
|
|
||||||
if (but == "repair" && !(Game.controller.orderGenerator is RepairOrderGenerator))
|
|
||||||
{
|
|
||||||
Game.controller.orderGenerator = new RepairOrderGenerator();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (but == "sell" && !(Game.controller.orderGenerator is SellOrderGenerator))
|
|
||||||
{
|
|
||||||
Game.controller.orderGenerator = new SellOrderGenerator();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Game.controller.orderGenerator = new UnitOrderGenerator(new Actor[] { });
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawButtons()
|
void DrawButtons()
|
||||||
{
|
{
|
||||||
// Repair
|
// Repair
|
||||||
Rectangle repairRect = new Rectangle(Game.viewport.Width - 100, 5,repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
Rectangle repairRect = new Rectangle(Game.viewport.Width - 100, 5,repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
|
||||||
var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location);
|
var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location);
|
||||||
if (!Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains<ConstructionYard>()))
|
|
||||||
{
|
var hasFact = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
||||||
// Player requires a conyard to repair
|
|
||||||
|
if (!hasFact)
|
||||||
repairButton.ReplaceAnim("disabled");
|
repairButton.ReplaceAnim("disabled");
|
||||||
|
|
||||||
// Cancel repair action. Should be handled elsewhere?
|
|
||||||
if (Game.controller.orderGenerator is RepairOrderGenerator)
|
|
||||||
{
|
|
||||||
Game.controller.orderGenerator = new UnitOrderGenerator(new Actor[] { });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Game.controller.orderGenerator is RepairOrderGenerator)
|
repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
|
||||||
{
|
AddButton(repairRect, isLmb => Game.controller.ToggleInputMode<RepairOrderGenerator>());
|
||||||
repairButton.ReplaceAnim("pressed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
repairButton.ReplaceAnim("normal");
|
|
||||||
}
|
|
||||||
buttons.Add(Pair.New(repairRect,(Action<bool>)(isLmb => HandleButtons("repair"))));
|
|
||||||
}
|
}
|
||||||
buildPaletteRenderer.DrawSprite(repairButton.Image, repairDrawPos, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(repairButton.Image, repairDrawPos, PaletteType.Chrome);
|
||||||
|
|
||||||
|
|
||||||
Rectangle sellRect = new Rectangle(Game.viewport.Width - 60, 5, sellButton.Image.bounds.Width, sellButton.Image.bounds.Height);
|
Rectangle sellRect = new Rectangle(Game.viewport.Width - 60, 5,
|
||||||
|
sellButton.Image.bounds.Width, sellButton.Image.bounds.Height);
|
||||||
|
|
||||||
var sellDrawPos = Game.viewport.Location + new float2(sellRect.Location);
|
var sellDrawPos = Game.viewport.Location + new float2(sellRect.Location);
|
||||||
|
|
||||||
if (Game.controller.orderGenerator is SellOrderGenerator)
|
repairButton.ReplaceAnim(Game.controller.orderGenerator is SellOrderGenerator ? "pressed" : "normal");
|
||||||
{
|
|
||||||
sellButton.ReplaceAnim("pressed");
|
AddButton(sellRect, isLmb => Game.controller.ToggleInputMode<SellOrderGenerator>());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sellButton.ReplaceAnim("normal");
|
|
||||||
}
|
|
||||||
|
|
||||||
buttons.Add(Pair.New(sellRect, (Action<bool>)(isLmb => HandleButtons("sell"))));
|
|
||||||
buildPaletteRenderer.DrawSprite(sellButton.Image, sellDrawPos, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(sellButton.Image, sellDrawPos, PaletteType.Chrome);
|
||||||
buildPaletteRenderer.Flush();
|
buildPaletteRenderer.Flush();
|
||||||
}
|
}
|
||||||
@@ -419,8 +388,7 @@ namespace OpenRa.Game
|
|||||||
overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
|
overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
|
||||||
|
|
||||||
var closureItem = item;
|
var closureItem = item;
|
||||||
buttons.Add(Pair.New(rect,
|
AddButton(rect, isLmb => HandleBuildPalette(closureItem, isLmb));
|
||||||
(Action<bool>)(isLmb => HandleBuildPalette(closureItem, isLmb))));
|
|
||||||
if (++x == columns) { x = 0; y++; }
|
if (++x == columns) { x = 0; y++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +397,7 @@ namespace OpenRa.Game
|
|||||||
var rect = new Rectangle(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
|
var rect = new Rectangle(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
|
||||||
var drawPos = Game.viewport.Location + new float2(rect.Location);
|
var drawPos = Game.viewport.Location + new float2(rect.Location);
|
||||||
buildPaletteRenderer.DrawSprite(blank, drawPos, PaletteType.Chrome);
|
buildPaletteRenderer.DrawSprite(blank, drawPos, PaletteType.Chrome);
|
||||||
buttons.Add(Pair.New(rect, (Action<bool>)(_ => { })));
|
AddButton(rect, _ => { });
|
||||||
if (++x == columns) { x = 0; y++; }
|
if (++x == columns) { x = 0; y++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ namespace OpenRa.Game
|
|||||||
orderGenerator = new UnitOrderGenerator(new Actor[] { });
|
orderGenerator = new UnitOrderGenerator(new Actor[] { });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleInputMode<T>() where T : IOrderGenerator, new()
|
||||||
|
{
|
||||||
|
if (orderGenerator is T)
|
||||||
|
CancelInputMode();
|
||||||
|
else
|
||||||
|
orderGenerator = new T();
|
||||||
|
}
|
||||||
|
|
||||||
List<Order> recentOrders = new List<Order>();
|
List<Order> recentOrders = new List<Order>();
|
||||||
|
|
||||||
void ApplyOrders(float2 xy, MouseInput mi)
|
void ApplyOrders(float2 xy, MouseInput mi)
|
||||||
|
|||||||
@@ -34,7 +34,15 @@ namespace OpenRa.Game.Orders
|
|||||||
yield return new Order("Repair", underCursor, null, int2.Zero, null);
|
yield return new Order("Repair", underCursor, null, int2.Zero, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() {}
|
public void Tick()
|
||||||
|
{
|
||||||
|
var hasFact = Game.world.Actors
|
||||||
|
.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains<ConstructionYard>());
|
||||||
|
|
||||||
|
if (!hasFact)
|
||||||
|
Game.controller.CancelInputMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Render() {}
|
public void Render() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user