Consolidate the production icons into a single widget. Add income tracking for players.
This commit is contained in:
@@ -86,6 +86,10 @@ namespace OpenRA.Traits
|
|||||||
public int DisplayCash;
|
public int DisplayCash;
|
||||||
public int DisplayOre;
|
public int DisplayOre;
|
||||||
|
|
||||||
|
public int IncomePerMin;
|
||||||
|
public double IncomeChange;
|
||||||
|
int incomeCounter;
|
||||||
|
|
||||||
public bool CanGiveOre(int amount)
|
public bool CanGiveOre(int amount)
|
||||||
{
|
{
|
||||||
return Ore + amount <= OreCapacity;
|
return Ore + amount <= OreCapacity;
|
||||||
@@ -100,6 +104,8 @@ namespace OpenRA.Traits
|
|||||||
nextSiloAdviceTime = 0;
|
nextSiloAdviceTime = 0;
|
||||||
Ore = OreCapacity;
|
Ore = OreCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
incomeCounter += num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TakeOre(int num)
|
public bool TakeOre(int num)
|
||||||
@@ -113,6 +119,7 @@ namespace OpenRA.Traits
|
|||||||
public void GiveCash(int num)
|
public void GiveCash(int num)
|
||||||
{
|
{
|
||||||
Cash += num;
|
Cash += num;
|
||||||
|
incomeCounter += num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TakeCash(int num)
|
public bool TakeCash(int num)
|
||||||
@@ -184,7 +191,14 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
DisplayOre -= move;
|
DisplayOre -= move;
|
||||||
playCashTickDown(self);
|
playCashTickDown(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.World.FrameNumber % 1500 == 0)
|
||||||
|
{
|
||||||
|
IncomeChange = IncomePerMin == 0 ? 0 : (double)(incomeCounter - IncomePerMin) / IncomePerMin;
|
||||||
|
IncomePerMin = incomeCounter;
|
||||||
|
incomeCounter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -382,7 +382,7 @@
|
|||||||
<Compile Include="Widgets\Logic\ServerCreationLogic.cs" />
|
<Compile Include="Widgets\Logic\ServerCreationLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
|
<Compile Include="Widgets\Logic\SettingsMenuLogic.cs" />
|
||||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||||
<Compile Include="Widgets\ObserverBuildIconWidget.cs" />
|
<Compile Include="Widgets\ObserverBuildIconsWidget.cs" />
|
||||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||||
<Compile Include="Widgets\RadarBinWidget.cs" />
|
<Compile Include="Widgets\RadarBinWidget.cs" />
|
||||||
|
|||||||
@@ -71,6 +71,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
var res = player.PlayerActor.Trait<PlayerResources>();
|
var res = player.PlayerActor.Trait<PlayerResources>();
|
||||||
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
|
template.Get<LabelWidget>("CASH").GetText = () => "$" + (res.DisplayCash + res.DisplayOre);
|
||||||
|
template.Get<LabelWidget>("INCOME").GetText = () => "$" + res.IncomePerMin;
|
||||||
|
var change = template.Get<LabelWidget>("INCOME_CHANGE");
|
||||||
|
change.GetText = () => Math.Round(res.IncomeChange * 100, 1, MidpointRounding.AwayFromZero) + "%";
|
||||||
|
change.GetColor = () =>
|
||||||
|
{
|
||||||
|
if (res.IncomeChange < 0) return Color.Red;
|
||||||
|
if (res.IncomeChange > 0) return Color.LimeGreen;
|
||||||
|
else return Color.White;
|
||||||
|
};
|
||||||
|
|
||||||
var powerRes = player.PlayerActor.Trait<PowerManager>();
|
var powerRes = player.PlayerActor.Trait<PowerManager>();
|
||||||
var power = template.Get<LabelWidget>("POWER");
|
var power = template.Get<LabelWidget>("POWER");
|
||||||
@@ -80,29 +89,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString();
|
template.Get<LabelWidget>("KILLS").GetText = () => player.Kills.ToString();
|
||||||
template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString();
|
template.Get<LabelWidget>("DEATHS").GetText = () => player.Deaths.ToString();
|
||||||
|
|
||||||
var building = template.Get<ObserverBuildIconWidget>("BUILDING_ICON");
|
var production = template.Get<ObserverBuildIconsWidget>("PRODUCTION_ICONS");
|
||||||
building.GetPlayer = () => player;
|
production.GetPlayer = () => player;
|
||||||
building.GetQueue = () => "Building";
|
|
||||||
|
|
||||||
var defense = template.Get<ObserverBuildIconWidget>("DEFENSE_ICON");
|
|
||||||
defense.GetPlayer = () => player;
|
|
||||||
defense.GetQueue = () => "Defense";
|
|
||||||
|
|
||||||
var vehicle = template.Get<ObserverBuildIconWidget>("VEHICLE_ICON");
|
|
||||||
vehicle.GetPlayer = () => player;
|
|
||||||
vehicle.GetQueue = () => "Vehicle";
|
|
||||||
|
|
||||||
var infantry = template.Get<ObserverBuildIconWidget>("INFANTRY_ICON");
|
|
||||||
infantry.GetPlayer = () => player;
|
|
||||||
infantry.GetQueue = () => "Infantry";
|
|
||||||
|
|
||||||
var ship = template.Get<ObserverBuildIconWidget>("SHIP_ICON");
|
|
||||||
ship.GetPlayer = () => player;
|
|
||||||
ship.GetQueue = () => "Ship";
|
|
||||||
|
|
||||||
var plane = template.Get<ObserverBuildIconWidget>("PLANE_ICON");
|
|
||||||
plane.GetPlayer = () => player;
|
|
||||||
plane.GetQueue = () => "Plane";
|
|
||||||
|
|
||||||
playersPanel.AddChild(template);
|
playersPanel.AddChild(template);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,19 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets
|
namespace OpenRA.Mods.RA.Widgets
|
||||||
{
|
{
|
||||||
public class ObserverBuildIconWidget : Widget
|
public class ObserverBuildIconsWidget : Widget
|
||||||
{
|
{
|
||||||
public Func<Player> GetPlayer;
|
public Func<Player> GetPlayer;
|
||||||
public Func<string> GetQueue;
|
|
||||||
Dictionary<string, Sprite> iconSprites;
|
Dictionary<string, Sprite> iconSprites;
|
||||||
World world;
|
World world;
|
||||||
WorldRenderer worldRenderer;
|
WorldRenderer worldRenderer;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ObserverBuildIconWidget(World world, WorldRenderer worldRenderer)
|
public ObserverBuildIconsWidget(World world, WorldRenderer worldRenderer)
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
iconSprites = Rules.Info.Values.Where(u => u.Traits.Contains<BuildableInfo>() && u.Name[0] != '^')
|
iconSprites = Rules.Info.Values.Where(u => u.Traits.Contains<BuildableInfo>() && u.Name[0] != '^')
|
||||||
@@ -36,11 +36,10 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObserverBuildIconWidget(ObserverBuildIconWidget other)
|
protected ObserverBuildIconsWidget(ObserverBuildIconsWidget other)
|
||||||
: base(other)
|
: base(other)
|
||||||
{
|
{
|
||||||
GetPlayer = other.GetPlayer;
|
GetPlayer = other.GetPlayer;
|
||||||
GetQueue = other.GetQueue;
|
|
||||||
iconSprites = other.iconSprites;
|
iconSprites = other.iconSprites;
|
||||||
world = other.world;
|
world = other.world;
|
||||||
worldRenderer = other.worldRenderer;
|
worldRenderer = other.worldRenderer;
|
||||||
@@ -49,32 +48,30 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
var player = GetPlayer();
|
var player = GetPlayer();
|
||||||
var queue = GetQueue();
|
if (player == null)
|
||||||
if (player == null || queue == null)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var production = world.ActorsWithTrait<ProductionQueue>()
|
var queues = world.ActorsWithTrait<ProductionQueue>()
|
||||||
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == queue)
|
.Where(a => a.Actor.Owner == player)
|
||||||
.Select(a => a.Trait)
|
.Select((a, i) => new { a.Trait, i });
|
||||||
.FirstOrDefault();
|
foreach (var queue in queues)
|
||||||
if (production == null)
|
|
||||||
{
|
{
|
||||||
return;
|
var item = queue.Trait.CurrentItem();
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var sprite = iconSprites[item.Item];
|
||||||
|
var size = sprite.size / new float2(2, 2);
|
||||||
|
var location = new float2(RenderBounds.Location) + new float2(queue.i * (int)size.Length, 0);
|
||||||
|
WidgetUtils.DrawSHP(sprite, location, worldRenderer, size);
|
||||||
}
|
}
|
||||||
var item = production.CurrentItem();
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var location = new float2(RenderBounds.Location);
|
|
||||||
var sprite = iconSprites[item.Item];
|
|
||||||
WidgetUtils.DrawSHP(sprite, location, worldRenderer, sprite.size / new float2(2, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone()
|
public override Widget Clone()
|
||||||
{
|
{
|
||||||
return new ObserverBuildIconWidget(this);
|
return new ObserverBuildIconsWidget(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -395,7 +395,7 @@ Container@OBSERVER_ROOT:
|
|||||||
Logic:ObserverStatsLogic
|
Logic:ObserverStatsLogic
|
||||||
X:25
|
X:25
|
||||||
Y:50
|
Y:50
|
||||||
Width:805
|
Width:950
|
||||||
Height:400
|
Height:400
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
Children:
|
||||||
@@ -426,15 +426,22 @@ Container@OBSERVER_ROOT:
|
|||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Text:Cash
|
Text:Cash
|
||||||
Label@POWER_HEADER
|
Label@INCOME_HEADER:
|
||||||
X:325
|
X:325
|
||||||
Y:40
|
Y:40
|
||||||
|
Width:160
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Text:Income
|
||||||
|
Label@POWER_HEADER
|
||||||
|
X:445
|
||||||
|
Y:40
|
||||||
Width:80
|
Width:80
|
||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Text:Power
|
Text:Power
|
||||||
Label@KILLS_HEADER:
|
Label@KILLS_HEADER:
|
||||||
X:385
|
X:525
|
||||||
Y:40
|
Y:40
|
||||||
Width:40
|
Width:40
|
||||||
Height:25
|
Height:25
|
||||||
@@ -442,7 +449,7 @@ Container@OBSERVER_ROOT:
|
|||||||
Text:Kills
|
Text:Kills
|
||||||
Align:Right
|
Align:Right
|
||||||
Label@DEATHS_HEADER:
|
Label@DEATHS_HEADER:
|
||||||
X:445
|
X:585
|
||||||
Y:40
|
Y:40
|
||||||
Width:40
|
Width:40
|
||||||
Height:25
|
Height:25
|
||||||
@@ -450,9 +457,9 @@ Container@OBSERVER_ROOT:
|
|||||||
Text:Deaths
|
Text:Deaths
|
||||||
Align:Right
|
Align:Right
|
||||||
Label@PRODUCTION_HEADER
|
Label@PRODUCTION_HEADER
|
||||||
X:485
|
X:625
|
||||||
Y:40
|
Y:40
|
||||||
Width:PARENT_RIGHT-525
|
Width:PARENT_RIGHT-625
|
||||||
Height:25
|
Height:25
|
||||||
Font:Bold
|
Font:Bold
|
||||||
Text:Production
|
Text:Production
|
||||||
@@ -500,52 +507,37 @@ Container@OBSERVER_ROOT:
|
|||||||
Y:0
|
Y:0
|
||||||
Width:80
|
Width:80
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Label@POWER:
|
Label@INCOME:
|
||||||
X:295
|
X:295
|
||||||
Y:0
|
Y:0
|
||||||
|
Width:60
|
||||||
|
Height:PARENT_BOTTOM
|
||||||
|
Label@INCOME_CHANGE
|
||||||
|
X:355
|
||||||
|
Y:0
|
||||||
|
Width:40
|
||||||
|
Height:PARENT_BOTTOM
|
||||||
|
Label@POWER:
|
||||||
|
X:415
|
||||||
|
Y:0
|
||||||
Width:80
|
Width:80
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Label@KILLS:
|
Label@KILLS:
|
||||||
X:355
|
X:495
|
||||||
Y:0
|
Y:0
|
||||||
Width:40
|
Width:40
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Align:Right
|
Align:Right
|
||||||
Label@DEATHS:
|
Label@DEATHS:
|
||||||
X:415
|
X:555
|
||||||
Y:0
|
Y:0
|
||||||
Width:40
|
Width:40
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Align:Right
|
Align:Right
|
||||||
ObserverBuildIcon@BUILDING_ICON:
|
ObserverBuildIcons@PRODUCTION_ICONS:
|
||||||
X:480
|
X:615
|
||||||
Y:0
|
Y:0
|
||||||
Width:40
|
Width:240
|
||||||
Height:PARENT_BOTTOM
|
|
||||||
ObserverBuildIcon@DEFENSE_ICON:
|
|
||||||
X:520
|
|
||||||
Y:0
|
|
||||||
Width:40
|
|
||||||
Height:PARENT_BOTTOM
|
|
||||||
ObserverBuildIcon@VEHICLE_ICON:
|
|
||||||
X:560
|
|
||||||
Y:0
|
|
||||||
Width:40
|
|
||||||
Height:PARENT_BOTTOM
|
|
||||||
ObserverBuildIcon@INFANTRY_ICON:
|
|
||||||
X:600
|
|
||||||
Y:0
|
|
||||||
Width:40
|
|
||||||
Height:PARENT_BOTTOM
|
|
||||||
ObserverBuildIcon@SHIP_ICON:
|
|
||||||
X:640
|
|
||||||
Y:0
|
|
||||||
Width:40
|
|
||||||
Height:PARENT_BOTTOM
|
|
||||||
ObserverBuildIcon@PLANE_ICON:
|
|
||||||
X:680
|
|
||||||
Y:0
|
|
||||||
Width:40
|
|
||||||
Height:PARENT_BOTTOM
|
Height:PARENT_BOTTOM
|
||||||
Background@FMVPLAYER:
|
Background@FMVPLAYER:
|
||||||
Width:WINDOW_RIGHT
|
Width:WINDOW_RIGHT
|
||||||
|
|||||||
Reference in New Issue
Block a user