diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index aa060ae850..b0b4d063c4 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -182,6 +182,24 @@ namespace OpenRA.Mods.Common.Traits NetWorth += (newDensity + 1) * newResourceValue; } + public int CalculateRegionValue(CellRegion sourceRegion) + { + var resourceValueInRegion = 0; + foreach (var cell in sourceRegion) + { + var mcell = cell.ToMPos(Map); + if (Map.Resources.Contains(mcell) && Map.Resources[mcell].Type != 0) + { + resourceValueInRegion++; + var rcell = Map.Resources[mcell]; + if (ResourceTypesByIndex.TryGetValue(rcell.Type, out var resourceType) && resourceValues.TryGetValue(resourceType, out var resourceValuePerUnit)) + resourceValueInRegion += Tiles[mcell].Density * resourceValuePerUnit; + } + } + + return resourceValueInRegion; + } + protected virtual int CalculateCellDensity(ResourceLayerContents contents, CPos c) { var resources = Map.Resources; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorSelectionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorSelectionLogic.cs index 32aebff021..2b6225c89d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorSelectionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorSelectionLogic.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -31,11 +32,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly CheckboxWidget copyActorsCheckbox; readonly EditorActorLayer editorActorLayer; + public LabelWidget RegionLabel; + public LabelWidget DimensionsLabel; + public LabelWidget DiagonalLabel; + public LabelWidget ResourceCounterLabel; + MapCopyFilters copyFilters = MapCopyFilters.All; EditorClipboard? clipboard; readonly IResourceLayer resourceLayer; + readonly EditorResourceLayer editorResourceLayer; + [ObjectCreator.UseCtor] public MapEditorSelectionLogic(Widget widget, World world, WorldRenderer worldRenderer) { @@ -43,9 +51,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic editorActorLayer = world.WorldActor.Trait(); resourceLayer = world.WorldActor.Trait(); + editorResourceLayer = world.WorldActor.Trait(); editor = widget.Get("MAP_EDITOR"); - + editor.DefaultBrush.SelectionChanged += HandleSelectionChanged; var selectTabContainer = widget.Get("SELECT_WIDGETS"); actorEditPanel = selectTabContainer.Get("ACTOR_EDIT_PANEL"); areaEditPanel = selectTabContainer.Get("AREA_EDIT_PANEL"); @@ -65,6 +74,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic copyButton.OnClick = () => clipboard = CopySelectionContents(); copyButton.IsDisabled = () => editor.DefaultBrush.Selection.Area == null; + RegionLabel = areaEditPanel.Get("REGION_COUNTER_LABEL"); + DimensionsLabel = areaEditPanel.Get("DIMENSION_COUNTER_LABEL"); + DiagonalLabel = areaEditPanel.Get("DIAGONAL_COUNTER_LABEL"); + ResourceCounterLabel = areaEditPanel.Get("RESOURCES_COUNTER_LABEL"); + var pasteButton = widget.Get("PASTE_BUTTON"); pasteButton.OnClick = () => { @@ -124,5 +138,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic checkbox.IsVisible = () => true; checkbox.OnClick = () => copyFilters ^= copyFilter; } + + protected override void Dispose(bool disposing) + { + editor.DefaultBrush.SelectionChanged -= HandleSelectionChanged; + base.Dispose(disposing); + } + + void HandleSelectionChanged() + { + var selectedRegion = editor.DefaultBrush.Selection.Area; + if (selectedRegion == null) + return; + var selectionSize = selectedRegion.BottomRight - selectedRegion.TopLeft + new CPos(1, 1); + var diagonalLength = Math.Round(Math.Sqrt(Math.Pow(selectionSize.X, 2) + Math.Pow(selectionSize.Y, 2)), 3); + var resourceValueInRegion = editorResourceLayer.CalculateRegionValue(selectedRegion); + RegionLabel.GetText = () => $"{PositionAsString(selectedRegion.TopLeft)} : {PositionAsString(selectedRegion.BottomRight)}"; + DimensionsLabel.GetText = () => PositionAsString(selectionSize); + DiagonalLabel.GetText = () => $"{diagonalLength}"; + ResourceCounterLabel.GetText = () => $"{resourceValueInRegion}$"; + } + + static string PositionAsString(CPos cell) + { + return $"{cell.X},{cell.Y}"; + } } } diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index 46f2683175..1cbfe6e182 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -537,9 +537,73 @@ Container@EDITOR_WORLD_ROOT: Width: PARENT_RIGHT - 29 Height: 20 Text: label-filter-actors + Label@AREA_INFO_TITLE: + X: 15 + Y: 150 + Width: 281 + Height: 24 + Align: Center + Font: Bold + Text: label-area-info + Label@REGION_LABEL: + X: 15 + Y: 175 + Width: 55 + Height: 20 + Font: Bold + Align: Left + Text: label-selected-area-selected-region + Label@DIMENSION_LABEL: + X: 15 + Y: 200 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-dimension + Label@DIAGONAL_LABEL: + X: 15 + Y: 225 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-diagonal + Label@RESOURCE_LABEL: + X: 15 + Y: 250 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-resources + Label@REGION_COUNTER_LABEL: + X: 150 + Y: 175 + Width: 55 + Height: 22 + Align: Left + Label@DIMENSION_COUNTER_LABEL: + X: 150 + Y: 200 + Width: 55 + Height: 22 + Align: Left + Label@DIAGONAL_COUNTER_LABEL: + X: 150 + Y: 225 + Width: 55 + Height: 22 + Align: Left + Label@RESOURCES_COUNTER_LABEL: + X: 150 + Y: 250 + Width: 55 + Height: 22 + Align: Left Button@SELECTION_CANCEL_BUTTON: - X: 209 - Y: 136 + X: 107 + Y: 275 Width: 75 Height: 25 Text: button-selection-cancel diff --git a/mods/cnc/languages/chrome/en.ftl b/mods/cnc/languages/chrome/en.ftl index f3de0e9b52..9af8cd941f 100644 --- a/mods/cnc/languages/chrome/en.ftl +++ b/mods/cnc/languages/chrome/en.ftl @@ -73,6 +73,11 @@ label-actors-bg-search = Search: label-actors-bg-categories = Filter: label-actors-bg-owners = Owner: label-area-selection = Area Selection +label-area-info = Area Info +label-selected-area-selected-region = Region: +label-selected-area-dimension = Dimensions: +label-selected-area-diagonal = Diagonal: +label-selected-area-resources= Resources: label-copy-filters = Copy Filters label-filter-terrain = Terrain label-filter-resources = Resources diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index e6f892b8ef..eaf58aa7df 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -481,9 +481,73 @@ Container@EDITOR_WORLD_ROOT: Width: PARENT_RIGHT - 29 Height: 20 Text: label-filter-actors + Label@AREA_INFO_TITLE: + X: 15 + Y: 150 + Width: 281 + Height: 24 + Align: Center + Font: Bold + Text: label-area-info + Label@REGION_LABEL: + X: 15 + Y: 175 + Width: 55 + Height: 20 + Font: Bold + Align: Left + Text: label-selected-area-selected-region + Label@DIMENSION_LABEL: + X: 15 + Y: 200 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-dimension + Label@DIAGONAL_LABEL: + X: 15 + Y: 225 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-diagonal + Label@RESOURCE_LABEL: + X: 15 + Y: 250 + Width: 55 + Height: 25 + Font: Bold + Align: Left + Text: label-selected-area-resources + Label@REGION_COUNTER_LABEL: + X: 150 + Y: 175 + Width: 55 + Height: 22 + Align: Left + Label@DIMENSION_COUNTER_LABEL: + X: 150 + Y: 200 + Width: 55 + Height: 22 + Align: Left + Label@DIAGONAL_COUNTER_LABEL: + X: 150 + Y: 225 + Width: 55 + Height: 22 + Align: Left + Label@RESOURCES_COUNTER_LABEL: + X: 150 + Y: 250 + Width: 55 + Height: 22 + Align: Left Button@SELECTION_CANCEL_BUTTON: - X: 222 - Y: 145 + X: 117 + Y: 275 Width: 75 Height: 25 Text: button-selection-cancel diff --git a/mods/common/languages/chrome/en.ftl b/mods/common/languages/chrome/en.ftl index 8628972562..9bc0562367 100644 --- a/mods/common/languages/chrome/en.ftl +++ b/mods/common/languages/chrome/en.ftl @@ -73,6 +73,11 @@ label-actors-bg-search = Search: label-actors-bg-categories = Filter: label-actors-bg-owners = Owner: label-area-selection = Area Selection +label-area-info = Area Info +label-selected-area-selected-region = Region: +label-selected-area-dimension = Dimensions: +label-selected-area-diagonal = Diagonal: +label-selected-area-resources= Resources: label-copy-filters = Copy Filters label-filter-terrain = Terrain label-filter-resources = Resources