Merge pull request #9139 from Mailaender/editor-cash-counter
Added a total resource cash counter to the map editor
This commit is contained in:
@@ -38,6 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
readonly Dictionary<PaletteReference, TerrainSpriteLayer> spriteLayers = new Dictionary<PaletteReference, TerrainSpriteLayer>();
|
readonly Dictionary<PaletteReference, TerrainSpriteLayer> spriteLayers = new Dictionary<PaletteReference, TerrainSpriteLayer>();
|
||||||
|
|
||||||
|
public int NetWorth { get; private set; }
|
||||||
|
|
||||||
public EditorResourceLayer(Actor self)
|
public EditorResourceLayer(Actor self)
|
||||||
{
|
{
|
||||||
if (self.World.Type != WorldType.Editor)
|
if (self.World.Type != WorldType.Editor)
|
||||||
@@ -89,6 +91,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var uv = cell.ToMPos(Map);
|
var uv = cell.ToMPos(Map);
|
||||||
var tile = Map.MapResources.Value[uv];
|
var tile = Map.MapResources.Value[uv];
|
||||||
|
|
||||||
|
var t = Tiles[cell];
|
||||||
|
if (t.Density > 0)
|
||||||
|
NetWorth -= t.Density * t.Type.Info.ValuePerUnit;
|
||||||
|
|
||||||
ResourceType type;
|
ResourceType type;
|
||||||
if (Resources.TryGetValue(tile.Type, out type))
|
if (Resources.TryGetValue(tile.Type, out type))
|
||||||
{
|
{
|
||||||
@@ -149,9 +155,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetWorth -= t.Density * type.Info.ValuePerUnit;
|
||||||
|
|
||||||
// Set density based on the number of neighboring resources
|
// Set density based on the number of neighboring resources
|
||||||
t.Density = ResourceDensityAt(c);
|
t.Density = ResourceDensityAt(c);
|
||||||
|
|
||||||
|
NetWorth += t.Density * type.Info.ValuePerUnit;
|
||||||
|
|
||||||
var sprites = type.Variants[t.Variant];
|
var sprites = type.Variants[t.Variant];
|
||||||
var frame = int2.Lerp(0, sprites.Length - 1, t.Density - 1, type.Info.MaxDensity);
|
var frame = int2.Lerp(0, sprites.Length - 1, t.Density - 1, type.Info.MaxDensity);
|
||||||
t.Sprite = sprites[frame];
|
t.Sprite = sprites[frame];
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -65,6 +66,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var coordinateLabel = widget.GetOrNull<LabelWidget>("COORDINATE_LABEL");
|
var coordinateLabel = widget.GetOrNull<LabelWidget>("COORDINATE_LABEL");
|
||||||
if (coordinateLabel != null)
|
if (coordinateLabel != null)
|
||||||
coordinateLabel.GetText = () => worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos).ToString();
|
coordinateLabel.GetText = () => worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos).ToString();
|
||||||
|
|
||||||
|
var cashLabel = widget.GetOrNull<LabelWidget>("CASH_LABEL");
|
||||||
|
if (cashLabel != null)
|
||||||
|
{
|
||||||
|
var reslayer = worldRenderer.World.WorldActor.TraitsImplementing<EditorResourceLayer>().FirstOrDefault();
|
||||||
|
if (reslayer != null)
|
||||||
|
cashLabel.GetText = () => "$ {0}".F(reslayer.NetWorth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -393,3 +393,10 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Align: Left
|
Align: Left
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Contrast: true
|
Contrast: true
|
||||||
|
Label@CASH_LABEL:
|
||||||
|
X: 95
|
||||||
|
Width: 50
|
||||||
|
Height: 25
|
||||||
|
Align: Left
|
||||||
|
Font: Bold
|
||||||
|
Contrast: true
|
||||||
|
|||||||
@@ -380,3 +380,10 @@ Container@EDITOR_WORLD_ROOT:
|
|||||||
Align: Left
|
Align: Left
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Contrast: true
|
Contrast: true
|
||||||
|
Label@CASH_LABEL:
|
||||||
|
X: 570
|
||||||
|
Width: 50
|
||||||
|
Height: 25
|
||||||
|
Align: Left
|
||||||
|
Font: Bold
|
||||||
|
Contrast: true
|
||||||
|
|||||||
Reference in New Issue
Block a user