From fea59346a50abfe8879d41855b48f4b8604cf292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 23 Aug 2015 09:55:46 +0200 Subject: [PATCH] add a total resource cash counter to the map editor --- OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs | 10 ++++++++++ .../Widgets/Logic/Editor/MapEditorLogic.cs | 9 +++++++++ mods/cnc/chrome/editor.yaml | 7 +++++++ mods/ra/chrome/editor.yaml | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index c9e1618d1f..2772bdc16f 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -38,6 +38,8 @@ namespace OpenRA.Mods.Common.Traits readonly Dictionary spriteLayers = new Dictionary(); + public int NetWorth { get; private set; } + public EditorResourceLayer(Actor self) { if (self.World.Type != WorldType.Editor) @@ -89,6 +91,10 @@ namespace OpenRA.Mods.Common.Traits var uv = cell.ToMPos(Map); var tile = Map.MapResources.Value[uv]; + var t = Tiles[cell]; + if (t.Density > 0) + NetWorth -= t.Density * t.Type.Info.ValuePerUnit; + ResourceType type; if (Resources.TryGetValue(tile.Type, out type)) { @@ -149,9 +155,13 @@ namespace OpenRA.Mods.Common.Traits return t; } + NetWorth -= t.Density * type.Info.ValuePerUnit; + // Set density based on the number of neighboring resources t.Density = ResourceDensityAt(c); + NetWorth += t.Density * type.Info.ValuePerUnit; + var sprites = type.Variants[t.Variant]; var frame = int2.Lerp(0, sprites.Length - 1, t.Density - 1, type.Info.MaxDensity); t.Sprite = sprites[frame]; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs index 662331f366..61ef32c50e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs @@ -9,6 +9,7 @@ #endregion using System; +using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -65,6 +66,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var coordinateLabel = widget.GetOrNull("COORDINATE_LABEL"); if (coordinateLabel != null) coordinateLabel.GetText = () => worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos).ToString(); + + var cashLabel = widget.GetOrNull("CASH_LABEL"); + if (cashLabel != null) + { + var reslayer = worldRenderer.World.WorldActor.TraitsImplementing().FirstOrDefault(); + if (reslayer != null) + cashLabel.GetText = () => "$ {0}".F(reslayer.NetWorth); + } } } } diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 2ec26880ee..6cd9541264 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -393,3 +393,10 @@ Container@EDITOR_WORLD_ROOT: Align: Left Font: Bold Contrast: true + Label@CASH_LABEL: + X: 95 + Width: 50 + Height: 25 + Align: Left + Font: Bold + Contrast: true diff --git a/mods/ra/chrome/editor.yaml b/mods/ra/chrome/editor.yaml index 306be8f0aa..e9cd601998 100644 --- a/mods/ra/chrome/editor.yaml +++ b/mods/ra/chrome/editor.yaml @@ -380,3 +380,10 @@ Container@EDITOR_WORLD_ROOT: Align: Left Font: Bold Contrast: true + Label@CASH_LABEL: + X: 570 + Width: 50 + Height: 25 + Align: Left + Font: Bold + Contrast: true