From 8a00dbd7a6e5903c84e280e20e6c258c38186461 Mon Sep 17 00:00:00 2001 From: Rampastring Date: Thu, 2 May 2024 18:35:58 +0300 Subject: [PATCH] Skip rendering InvisibleInGame=yes objects and building foundation lines when extracting megamap --- src/TSMapEditor/Config/EditorRules.ini | 16 ++++++++++++++++ src/TSMapEditor/Models/GameObject.cs | 2 ++ src/TSMapEditor/Models/GameObjectType.cs | 2 ++ src/TSMapEditor/Models/Overlay.cs | 2 ++ src/TSMapEditor/Models/Techno.cs | 2 ++ src/TSMapEditor/Models/TerrainObject.cs | 2 ++ src/TSMapEditor/Rendering/EditorState.cs | 2 ++ src/TSMapEditor/Rendering/MapView.cs | 7 +++++++ .../ObjectRenderers/BuildingRenderer.cs | 3 ++- 9 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/TSMapEditor/Config/EditorRules.ini b/src/TSMapEditor/Config/EditorRules.ini index 4ae7c67b..cf0b42cb 100644 --- a/src/TSMapEditor/Config/EditorRules.ini +++ b/src/TSMapEditor/Config/EditorRules.ini @@ -13,6 +13,22 @@ RenderInEditor=no [RAAPWR_S] RenderInEditor=no +; Hide editor-only overlay and terrain objects from map previews +[IMOV] +InvisibleInGame=yes + +[NOVERLAY] +InvisibleInGame=yes + +[TUNENT] +InvisibleInGame=yes + +[NOBUILD] +InvisibleInGame=yes + +[IMTO] +InvisibleInGame=yes + [ObjectOwnerOverrides] GDI1=GDI GDI2=GDI diff --git a/src/TSMapEditor/Models/GameObject.cs b/src/TSMapEditor/Models/GameObject.cs index 8709a305..cdbc12fa 100644 --- a/src/TSMapEditor/Models/GameObject.cs +++ b/src/TSMapEditor/Models/GameObject.cs @@ -47,6 +47,8 @@ public override int GetHashCode() public virtual bool Remapable() => false; + public virtual bool IsInvisibleInGame() => false; + public virtual Color GetRemapColor() => Color.White; } } diff --git a/src/TSMapEditor/Models/GameObjectType.cs b/src/TSMapEditor/Models/GameObjectType.cs index 35c8c4a7..d524ba78 100644 --- a/src/TSMapEditor/Models/GameObjectType.cs +++ b/src/TSMapEditor/Models/GameObjectType.cs @@ -21,6 +21,8 @@ public GameObjectType(string iniName) public string EditorCategory { get; set; } public bool EditorVisible { get; set; } = true; + public bool InvisibleInGame { get; set; } + /// /// Specifies which theaters this terrain object type can be placed down in. /// If empty, it is considered valid for all theaters. diff --git a/src/TSMapEditor/Models/Overlay.cs b/src/TSMapEditor/Models/Overlay.cs index 026d8461..fa051fc7 100644 --- a/src/TSMapEditor/Models/Overlay.cs +++ b/src/TSMapEditor/Models/Overlay.cs @@ -18,6 +18,8 @@ public override int GetShadowFrameIndex(int frameCount) return 100; } + public override bool IsInvisibleInGame() => OverlayType.InvisibleInGame; + public override int GetYDrawOffset() { if (OverlayType.IsVeinholeMonster) diff --git a/src/TSMapEditor/Models/Techno.cs b/src/TSMapEditor/Models/Techno.cs index 64c07184..2f436c9e 100644 --- a/src/TSMapEditor/Models/Techno.cs +++ b/src/TSMapEditor/Models/Techno.cs @@ -27,6 +27,8 @@ public override double GetGapGeneratorRange() public override Color GetRadialColor() => Owner?.XNAColor ?? Color.White; + public override bool IsInvisibleInGame() => ObjectType.InvisibleInGame; + public T ObjectType { get; } } diff --git a/src/TSMapEditor/Models/TerrainObject.cs b/src/TSMapEditor/Models/TerrainObject.cs index bec5c62d..d8089506 100644 --- a/src/TSMapEditor/Models/TerrainObject.cs +++ b/src/TSMapEditor/Models/TerrainObject.cs @@ -21,6 +21,8 @@ public TerrainObject(TerrainType terrainType, Point2D position) : this(terrainTy public TerrainType TerrainType { get; private set; } + public override bool IsInvisibleInGame() => TerrainType.InvisibleInGame; + public override int GetYDrawOffset() { if (TerrainType.SpawnsTiberium) diff --git a/src/TSMapEditor/Rendering/EditorState.cs b/src/TSMapEditor/Rendering/EditorState.cs index a5ec7ce4..4527712c 100644 --- a/src/TSMapEditor/Rendering/EditorState.cs +++ b/src/TSMapEditor/Rendering/EditorState.cs @@ -251,6 +251,8 @@ public RenderObjectFlags RenderObjectFlags } } + public bool RenderInvisibleInGameObjects { get; set; } = true; + public CopiedMapData CopiedMapData { get; set; } } } diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index 311b85df..69b1ef89 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -983,6 +983,9 @@ private void DrawObjects() private void DrawObject(GameObject gameObject) { + if (!EditorState.RenderInvisibleInGameObjects && gameObject.IsInvisibleInGame()) + return; + switch (gameObject.WhatAmI()) { case RTTIType.Aircraft: @@ -1962,6 +1965,8 @@ public void ExtractMegamapTo(string path) private void InstantRenderMinimap() { + EditorState.RenderInvisibleInGameObjects = false; + // Register ourselves as a minimap user so the minimap texture gets refreshed MinimapUsers.Add(this); @@ -1990,6 +1995,8 @@ private void InstantRenderMinimap() Renderer.EndDraw(); MinimapUsers.Remove(this); + + EditorState.RenderInvisibleInGameObjects = true; } } } diff --git a/src/TSMapEditor/Rendering/ObjectRenderers/BuildingRenderer.cs b/src/TSMapEditor/Rendering/ObjectRenderers/BuildingRenderer.cs index a78d544b..e8a582ad 100644 --- a/src/TSMapEditor/Rendering/ObjectRenderers/BuildingRenderer.cs +++ b/src/TSMapEditor/Rendering/ObjectRenderers/BuildingRenderer.cs @@ -91,7 +91,8 @@ private void DrawBibGraphics(Structure gameObject, ShapeImage bibGraphics, int h protected override void Render(Structure gameObject, int heightOffset, Point2D drawPoint, in CommonDrawParams drawParams) { - DrawFoundationLines(gameObject); + if (RenderDependencies.EditorState.RenderInvisibleInGameObjects) + DrawFoundationLines(gameObject); bool affectedByLighting = RenderDependencies.EditorState.IsLighting && (drawParams.ShapeImage != null && drawParams.ShapeImage.SubjectToLighting);