No more drawing unexplored rooms.

不再绘制未探索过的房间了。
This commit is contained in:
Cold-Mint 2024-09-08 09:45:14 +08:00
parent 26c0843202
commit ce8f9121a5
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
7 changed files with 63 additions and 38 deletions

View File

@ -86,7 +86,7 @@ public static class Config
/// <para>Scale of the room preview view</para> /// <para>Scale of the room preview view</para>
/// <para>房间预览图的缩放</para> /// <para>房间预览图的缩放</para>
/// </summary> /// </summary>
public const float RoomPreviewScale = 5f; public const float RoomPreviewScale = 3f;
/// <summary> /// <summary>
/// <para>How much blood does a heart represent</para> /// <para>How much blood does a heart represent</para>
@ -100,12 +100,6 @@ public static class Config
/// </summary> /// </summary>
public const string ModManifestFileName = "ModManifest.yaml"; public const string ModManifestFileName = "ModManifest.yaml";
/// <summary>
/// <para>The maximum number of stacked items in a single inventory</para>
/// <para>单个物品栏最大堆叠的物品数量</para>
/// </summary>
public const int MaxStackQuantity = 99;
/// <summary> /// <summary>
/// <para>Text change buffering Time How long does it take to execute the actual event after an event with a text change listener is triggered? (Anti-shake processing time), unit: milliseconds</para> /// <para>Text change buffering Time How long does it take to execute the actual event after an event with a text change listener is triggered? (Anti-shake processing time), unit: milliseconds</para>
/// <para>当添加了文本改变监听器的事件被触发后,多长时间后执行实际事件?(防抖处理时长),单位:毫秒</para> /// <para>当添加了文本改变监听器的事件被触发后,多长时间后执行实际事件?(防抖处理时长),单位:毫秒</para>

View File

@ -44,12 +44,6 @@ public static class GameSceneDepend
/// </summary> /// </summary>
public static Node2D? TemporaryTargetNode { get; set; } public static Node2D? TemporaryTargetNode { get; set; }
/// <summary>
/// <para>MiniMapContainerNode</para>
/// <para>迷你地图容器节点</para>
/// </summary>
public static Node2D? MiniMapContainerNode { get; set; }
/// <summary> /// <summary>
/// <para>ProjectileContainer</para> /// <para>ProjectileContainer</para>
/// <para>抛射体容器</para> /// <para>抛射体容器</para>

View File

@ -57,10 +57,6 @@ public partial class GameSceneLoader : SceneLoaderTemplate
//加载玩家容器 //加载玩家容器
var playerContainer = GetNode<Node2D>("PlayerContainer"); var playerContainer = GetNode<Node2D>("PlayerContainer");
GameSceneDepend.PlayerContainer = playerContainer; GameSceneDepend.PlayerContainer = playerContainer;
//Load the room container node
//加载房间容器节点
var miniMapContainerNode = GetNode<Node2D>("CanvasLayer/Control/MapContainer/MiniMap/RoomPreviewContainer");
GameSceneDepend.MiniMapContainerNode = miniMapContainerNode;
//Setting up the mini map //Setting up the mini map
//设置迷你地图 //设置迷你地图
var miniMap = GetNode<MiniMap>("CanvasLayer/Control/MapContainer/MiniMap"); var miniMap = GetNode<MiniMap>("CanvasLayer/Control/MapContainer/MiniMap");

View File

@ -148,9 +148,9 @@ public static class MapGenerator
return; return;
} }
if (GameSceneDepend.MiniMapContainerNode != null) if (GameSceneDepend.MiniMap != null)
{ {
NodeUtils.DeleteAllChild(GameSceneDepend.MiniMapContainerNode); GameSceneDepend.MiniMap.Clear();
} }
if (GameSceneDepend.AiCharacterContainer != null) if (GameSceneDepend.AiCharacterContainer != null)

View File

@ -2,6 +2,10 @@ using ColdMint.scripts.map.dateBean;
namespace ColdMint.scripts.map.events; namespace ColdMint.scripts.map.events;
/// <summary>
/// <para>MapGenerationPlaceRoomFinishEvent</para>
/// <para>地图生成器放置房间完成后执行的事件</para>
/// </summary>
public class MapGenerationPlaceRoomFinishEvent public class MapGenerationPlaceRoomFinishEvent
{ {
public string? RoomNodeDataId { get; set; } public string? RoomNodeDataId { get; set; }

View File

@ -1,7 +1,9 @@
using System.Collections.Generic;
using ColdMint.scripts.debug; using ColdMint.scripts.debug;
using ColdMint.scripts.map.dateBean; using ColdMint.scripts.map.dateBean;
using ColdMint.scripts.map.events; using ColdMint.scripts.map.events;
using ColdMint.scripts.map.preview; using ColdMint.scripts.map.preview;
using ColdMint.scripts.map.room;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using Godot; using Godot;
@ -14,13 +16,18 @@ namespace ColdMint.scripts.map.miniMap;
public partial class MiniMap : NinePatchRect public partial class MiniMap : NinePatchRect
{ {
private Node2D? _roomPreviewContainer; private Node2D? _roomPreviewContainer;
private Vector2 _miniMapMidpointCoordinate;
/// <summary> /// <summary>
/// <para>The midpoint coordinates of the mini map</para> /// <para>The midpoint coordinates of the mini map</para>
/// <para>迷你地图的中点坐标</para> /// <para>迷你地图的中点坐标</para>
/// </summary> /// </summary>
public Vector2 MiniMapMidpointCoordinate => _miniMapMidpointCoordinate; private Vector2 _miniMapMidpointCoordinate;
/// <summary>
/// <para>Mapping of rooms and room preview images</para>
/// <para>房间和房间预览图的映射</para>
/// </summary>
private readonly Dictionary<Room, TextureRect> _roomToRoomPreviews = [];
/// <summary> /// <summary>
/// <para>The master node of the map</para> /// <para>The master node of the map</para>
@ -35,6 +42,32 @@ public partial class MiniMap : NinePatchRect
EventBus.MapGenerationPlaceRoomFinishEvent += MapGenerationPlaceRoomFinishEvent; EventBus.MapGenerationPlaceRoomFinishEvent += MapGenerationPlaceRoomFinishEvent;
} }
/// <summary>
/// <para>Clean up all room preview images in the mini map</para>
/// <para>清理迷你地图内的所有房间预览图</para>
/// </summary>
public void Clear()
{
_roomToRoomPreviews.Clear();
if (_roomPreviewContainer != null)
{
NodeUtils.DeleteAllChild(_roomPreviewContainer);
}
}
/// <summary>
/// <para>Display room preview image</para>
/// <para>显示房间预览图</para>
/// </summary>
/// <param name="room"></param>
public void ShowRoomPreview(Room room)
{
if (_roomToRoomPreviews.TryGetValue(room, out var roomPreview))
{
roomPreview.Show();
}
}
/// <summary> /// <summary>
/// <para>After the map generator completes placing the room</para> /// <para>After the map generator completes placing the room</para>
/// <para>地图生成器放置房间完成后</para> /// <para>地图生成器放置房间完成后</para>
@ -49,12 +82,17 @@ public partial class MiniMap : NinePatchRect
} }
var tileMapLayer = roomPlacementData.NewRoom.GetTileMapLayer(Config.TileMapLayerName.Ground); var tileMapLayer = roomPlacementData.NewRoom.GetTileMapLayer(Config.TileMapLayerName.Ground);
if (!CreateRoomPreview(tileMapLayer, var textureRect = CreateRoomPreview(tileMapLayer,
CalculateRelativePositionOnTheMinimap(tileMapLayer, roomPlacementData))) CalculateRelativePositionOnTheMinimap(tileMapLayer, roomPlacementData));
if (textureRect == null)
{ {
LogCat.LogWithFormat("failed_to_create_room_preview", LogCat.LogLabel.Default, LogCat.UploadFormat, LogCat.LogWithFormat("failed_to_create_room_preview", LogCat.LogLabel.Default, LogCat.UploadFormat,
mapGenerationPlaceRoomFinishEvent.RoomNodeDataId); mapGenerationPlaceRoomFinishEvent.RoomNodeDataId);
} }
else
{
_roomToRoomPreviews[roomPlacementData.NewRoom] = textureRect;
}
} }
@ -90,29 +128,26 @@ public partial class MiniMap : NinePatchRect
///<para>相对于迷你地图容器中点的位置</para> ///<para>相对于迷你地图容器中点的位置</para>
/// </param> /// </param>
/// <returns></returns> /// <returns></returns>
private bool CreateRoomPreview(TileMapLayer? groundTileMapLayer, Vector2? position) private TextureRect? CreateRoomPreview(TileMapLayer? groundTileMapLayer, Vector2? position)
{ {
if (GameSceneDepend.MiniMapContainerNode == null || position == null) if (_roomPreviewContainer == null || position == null)
{ {
return false; return null;
} }
var image = RoomPreview.CreateImage(groundTileMapLayer); var image = RoomPreview.CreateImage(groundTileMapLayer);
if (image == null) if (image == null)
{ {
return false; return null;
} }
var sprite = new TextureRect(); var textureRect = new TextureRect();
sprite.Scale = new Vector2(Config.RoomPreviewScale, Config.RoomPreviewScale); textureRect.Scale = new Vector2(Config.RoomPreviewScale, Config.RoomPreviewScale);
sprite.Texture = image; textureRect.Texture = image;
if (GameSceneDepend.MiniMap != null) textureRect.Position = _miniMapMidpointCoordinate + position.Value;
{ textureRect.Hide();
sprite.Position = GameSceneDepend.MiniMap.MiniMapMidpointCoordinate + position.Value; NodeUtils.CallDeferredAddChild(_roomPreviewContainer, textureRect);
} return textureRect;
NodeUtils.CallDeferredAddChild(GameSceneDepend.MiniMapContainerNode, sprite);
return true;
} }
public override void _Process(double delta) public override void _Process(double delta)

View File

@ -103,8 +103,10 @@ public class Room
_pointLight2D.Texture = AssetHolder.White100; _pointLight2D.Texture = AssetHolder.White100;
} }
GameSceneDepend.MiniMap?.ShowRoomPreview(this);
ShowAllCharacterTemplate(); ShowAllCharacterTemplate();
}else if (node is CharacterTemplate characterTemplate) }
else if (node is CharacterTemplate characterTemplate)
{ {
if (_hasPlayer) if (_hasPlayer)
{ {