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 DisplayOre;
|
||||
|
||||
public int IncomePerMin;
|
||||
public double IncomeChange;
|
||||
int incomeCounter;
|
||||
|
||||
public bool CanGiveOre(int amount)
|
||||
{
|
||||
return Ore + amount <= OreCapacity;
|
||||
@@ -100,6 +104,8 @@ namespace OpenRA.Traits
|
||||
nextSiloAdviceTime = 0;
|
||||
Ore = OreCapacity;
|
||||
}
|
||||
|
||||
incomeCounter += num;
|
||||
}
|
||||
|
||||
public bool TakeOre(int num)
|
||||
@@ -113,6 +119,7 @@ namespace OpenRA.Traits
|
||||
public void GiveCash(int num)
|
||||
{
|
||||
Cash += num;
|
||||
incomeCounter += num;
|
||||
}
|
||||
|
||||
public bool TakeCash(int num)
|
||||
@@ -185,6 +192,13 @@ namespace OpenRA.Traits
|
||||
DisplayOre -= move;
|
||||
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\SettingsMenuLogic.cs" />
|
||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||
<Compile Include="Widgets\ObserverBuildIconWidget.cs" />
|
||||
<Compile Include="Widgets\ObserverBuildIconsWidget.cs" />
|
||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||
<Compile Include="Widgets\RadarBinWidget.cs" />
|
||||
|
||||
@@ -71,6 +71,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var res = player.PlayerActor.Trait<PlayerResources>();
|
||||
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 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>("DEATHS").GetText = () => player.Deaths.ToString();
|
||||
|
||||
var building = template.Get<ObserverBuildIconWidget>("BUILDING_ICON");
|
||||
building.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";
|
||||
var production = template.Get<ObserverBuildIconsWidget>("PRODUCTION_ICONS");
|
||||
production.GetPlayer = () => player;
|
||||
|
||||
playersPanel.AddChild(template);
|
||||
}
|
||||
|
||||
@@ -13,19 +13,19 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class ObserverBuildIconWidget : Widget
|
||||
public class ObserverBuildIconsWidget : Widget
|
||||
{
|
||||
public Func<Player> GetPlayer;
|
||||
public Func<string> GetQueue;
|
||||
Dictionary<string, Sprite> iconSprites;
|
||||
World world;
|
||||
WorldRenderer worldRenderer;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ObserverBuildIconWidget(World world, WorldRenderer worldRenderer)
|
||||
public ObserverBuildIconsWidget(World world, WorldRenderer worldRenderer)
|
||||
: base()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
protected ObserverBuildIconWidget(ObserverBuildIconWidget other)
|
||||
protected ObserverBuildIconsWidget(ObserverBuildIconsWidget other)
|
||||
: base(other)
|
||||
{
|
||||
GetPlayer = other.GetPlayer;
|
||||
GetQueue = other.GetQueue;
|
||||
iconSprites = other.iconSprites;
|
||||
world = other.world;
|
||||
worldRenderer = other.worldRenderer;
|
||||
@@ -49,32 +48,30 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
public override void Draw()
|
||||
{
|
||||
var player = GetPlayer();
|
||||
var queue = GetQueue();
|
||||
if (player == null || queue == null)
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var production = world.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == queue)
|
||||
.Select(a => a.Trait)
|
||||
.FirstOrDefault();
|
||||
if (production == null)
|
||||
var queues = world.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == player)
|
||||
.Select((a, i) => new { a.Trait, i });
|
||||
foreach (var queue in queues)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var item = production.CurrentItem();
|
||||
var item = queue.Trait.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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
{
|
||||
return new ObserverBuildIconWidget(this);
|
||||
return new ObserverBuildIconsWidget(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,7 +395,7 @@ Container@OBSERVER_ROOT:
|
||||
Logic:ObserverStatsLogic
|
||||
X:25
|
||||
Y:50
|
||||
Width:805
|
||||
Width:950
|
||||
Height:400
|
||||
Visible:false
|
||||
Children:
|
||||
@@ -426,15 +426,22 @@ Container@OBSERVER_ROOT:
|
||||
Height:25
|
||||
Font:Bold
|
||||
Text:Cash
|
||||
Label@POWER_HEADER
|
||||
Label@INCOME_HEADER:
|
||||
X:325
|
||||
Y:40
|
||||
Width:160
|
||||
Height:25
|
||||
Font:Bold
|
||||
Text:Income
|
||||
Label@POWER_HEADER
|
||||
X:445
|
||||
Y:40
|
||||
Width:80
|
||||
Height:25
|
||||
Font:Bold
|
||||
Text:Power
|
||||
Label@KILLS_HEADER:
|
||||
X:385
|
||||
X:525
|
||||
Y:40
|
||||
Width:40
|
||||
Height:25
|
||||
@@ -442,7 +449,7 @@ Container@OBSERVER_ROOT:
|
||||
Text:Kills
|
||||
Align:Right
|
||||
Label@DEATHS_HEADER:
|
||||
X:445
|
||||
X:585
|
||||
Y:40
|
||||
Width:40
|
||||
Height:25
|
||||
@@ -450,9 +457,9 @@ Container@OBSERVER_ROOT:
|
||||
Text:Deaths
|
||||
Align:Right
|
||||
Label@PRODUCTION_HEADER
|
||||
X:485
|
||||
X:625
|
||||
Y:40
|
||||
Width:PARENT_RIGHT-525
|
||||
Width:PARENT_RIGHT-625
|
||||
Height:25
|
||||
Font:Bold
|
||||
Text:Production
|
||||
@@ -500,52 +507,37 @@ Container@OBSERVER_ROOT:
|
||||
Y:0
|
||||
Width:80
|
||||
Height:PARENT_BOTTOM
|
||||
Label@POWER:
|
||||
Label@INCOME:
|
||||
X:295
|
||||
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
|
||||
Height:PARENT_BOTTOM
|
||||
Label@KILLS:
|
||||
X:355
|
||||
X:495
|
||||
Y:0
|
||||
Width:40
|
||||
Height:PARENT_BOTTOM
|
||||
Align:Right
|
||||
Label@DEATHS:
|
||||
X:415
|
||||
X:555
|
||||
Y:0
|
||||
Width:40
|
||||
Height:PARENT_BOTTOM
|
||||
Align:Right
|
||||
ObserverBuildIcon@BUILDING_ICON:
|
||||
X:480
|
||||
ObserverBuildIcons@PRODUCTION_ICONS:
|
||||
X:615
|
||||
Y:0
|
||||
Width:40
|
||||
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
|
||||
Width:240
|
||||
Height:PARENT_BOTTOM
|
||||
Background@FMVPLAYER:
|
||||
Width:WINDOW_RIGHT
|
||||
|
||||
Reference in New Issue
Block a user