Allow mods to customise the default rendering scale.

This commit is contained in:
Paul Chote
2022-12-22 08:40:59 +13:00
committed by Matthias Mailänder
parent e21f94f36a
commit 6d438a9d61
8 changed files with 59 additions and 50 deletions

View File

@@ -41,8 +41,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void IntializeLayerPreview()
{
layerTemplateList.RemoveChildren();
var rules = worldRenderer.World.Map.Rules;
var tileSize = worldRenderer.World.Map.Grid.TileSize;
foreach (var resourceRenderer in worldRenderer.World.WorldActor.TraitsImplementing<IResourceRenderer>())
{
foreach (var resourceType in resourceRenderer.ResourceTypes)
@@ -55,12 +53,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
newResourcePreviewTemplate.Bounds.Y = 0;
var layerPreview = newResourcePreviewTemplate.Get<ResourcePreviewWidget>("LAYER_PREVIEW");
var size = layerPreview.IdealPreviewSize;
layerPreview.IsVisible = () => true;
layerPreview.ResourceType = resourceType;
layerPreview.Bounds.Width = tileSize.Width;
layerPreview.Bounds.Height = tileSize.Height;
newResourcePreviewTemplate.Bounds.Width = tileSize.Width + (layerPreview.Bounds.X * 2);
newResourcePreviewTemplate.Bounds.Height = tileSize.Height + (layerPreview.Bounds.Y * 2);
layerPreview.Bounds.Width = size.Width;
layerPreview.Bounds.Height = size.Height;
newResourcePreviewTemplate.Bounds.Width = size.Width + (layerPreview.Bounds.X * 2);
newResourcePreviewTemplate.Bounds.Height = size.Height + (layerPreview.Bounds.Y * 2);
newResourcePreviewTemplate.IsVisible = () => true;
newResourcePreviewTemplate.GetTooltipText = () => resourceType;

View File

@@ -38,7 +38,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
readonly ITemplatedTerrainInfo terrainInfo;
readonly ITiledTerrainRenderer terrainRenderer;
readonly TileSelectorTemplate[] allTemplates;
readonly EditorCursorLayer editorCursor;
@@ -50,10 +49,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (terrainInfo == null)
throw new InvalidDataException("TileSelectorLogic requires a template-based tileset.");
terrainRenderer = world.WorldActor.TraitOrDefault<ITiledTerrainRenderer>();
if (terrainRenderer == null)
throw new InvalidDataException("TileSelectorLogic requires a tile-based terrain renderer.");
allTemplates = terrainInfo.Templates.Values.Select(t => new TileSelectorTemplate(t)).ToArray();
editorCursor = world.WorldActor.Trait<EditorCursorLayer>();
@@ -115,18 +110,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
() => Editor.SetBrush(new EditorTileBrush(Editor, tileId, WorldRenderer)));
var preview = item.Get<TerrainTemplatePreviewWidget>("TILE_PREVIEW");
var template = terrainInfo.Templates[tileId];
var bounds = terrainRenderer.TemplateBounds(template);
preview.SetTemplate(terrainInfo.Templates[tileId]);
// Scale templates to fit within the panel
var scale = 1f;
while (scale * bounds.Width > ItemTemplate.Bounds.Width)
scale /= 2;
if (scale * preview.IdealPreviewSize.X > ItemTemplate.Bounds.Width)
scale = (ItemTemplate.Bounds.Width - Panel.ItemSpacing) / (float)preview.IdealPreviewSize.X;
preview.Template = template;
preview.GetScale = () => scale;
preview.Bounds.Width = (int)(scale * bounds.Width);
preview.Bounds.Height = (int)(scale * bounds.Height);
preview.Bounds.Width = (int)(scale * preview.IdealPreviewSize.X);
preview.Bounds.Height = (int)(scale * preview.IdealPreviewSize.Y);
item.Bounds.Width = preview.Bounds.Width + 2 * preview.Bounds.X;
item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;