Selection info into Area selection tab
Selection info into Area selection tab add Resource counter and measure info into Area selection tab
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<EditorActorLayer>();
|
||||
resourceLayer = world.WorldActor.Trait<IResourceLayer>();
|
||||
editorResourceLayer = world.WorldActor.Trait<EditorResourceLayer>();
|
||||
|
||||
editor = widget.Get<EditorViewportControllerWidget>("MAP_EDITOR");
|
||||
|
||||
editor.DefaultBrush.SelectionChanged += HandleSelectionChanged;
|
||||
var selectTabContainer = widget.Get("SELECT_WIDGETS");
|
||||
actorEditPanel = selectTabContainer.Get<ContainerWidget>("ACTOR_EDIT_PANEL");
|
||||
areaEditPanel = selectTabContainer.Get<ContainerWidget>("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<LabelWidget>("REGION_COUNTER_LABEL");
|
||||
DimensionsLabel = areaEditPanel.Get<LabelWidget>("DIMENSION_COUNTER_LABEL");
|
||||
DiagonalLabel = areaEditPanel.Get<LabelWidget>("DIAGONAL_COUNTER_LABEL");
|
||||
ResourceCounterLabel = areaEditPanel.Get<LabelWidget>("RESOURCES_COUNTER_LABEL");
|
||||
|
||||
var pasteButton = widget.Get<ButtonWidget>("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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user