diff --git a/scripts/Config.cs b/scripts/Config.cs index 7672413..54694cb 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -86,7 +86,7 @@ public static class Config /// Scale of the room preview view /// 房间预览图的缩放 /// - public const float RoomPreviewScale = 5f; + public const float RoomPreviewScale = 3f; /// /// How much blood does a heart represent @@ -100,12 +100,6 @@ public static class Config /// public const string ModManifestFileName = "ModManifest.yaml"; - /// - /// The maximum number of stacked items in a single inventory - /// 单个物品栏最大堆叠的物品数量 - /// - public const int MaxStackQuantity = 99; - /// /// 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 /// 当添加了文本改变监听器的事件被触发后,多长时间后执行实际事件?(防抖处理时长),单位:毫秒 diff --git a/scripts/GameSceneDepend.cs b/scripts/GameSceneDepend.cs index e5d25e8..2b1b4dc 100644 --- a/scripts/GameSceneDepend.cs +++ b/scripts/GameSceneDepend.cs @@ -44,12 +44,6 @@ public static class GameSceneDepend /// public static Node2D? TemporaryTargetNode { get; set; } - /// - /// MiniMapContainerNode - /// 迷你地图容器节点 - /// - public static Node2D? MiniMapContainerNode { get; set; } - /// /// ProjectileContainer /// 抛射体容器 diff --git a/scripts/loader/sceneLoader/GameSceneLoader.cs b/scripts/loader/sceneLoader/GameSceneLoader.cs index 0c3303b..2db575f 100644 --- a/scripts/loader/sceneLoader/GameSceneLoader.cs +++ b/scripts/loader/sceneLoader/GameSceneLoader.cs @@ -57,10 +57,6 @@ public partial class GameSceneLoader : SceneLoaderTemplate //加载玩家容器 var playerContainer = GetNode("PlayerContainer"); GameSceneDepend.PlayerContainer = playerContainer; - //Load the room container node - //加载房间容器节点 - var miniMapContainerNode = GetNode("CanvasLayer/Control/MapContainer/MiniMap/RoomPreviewContainer"); - GameSceneDepend.MiniMapContainerNode = miniMapContainerNode; //Setting up the mini map //设置迷你地图 var miniMap = GetNode("CanvasLayer/Control/MapContainer/MiniMap"); diff --git a/scripts/map/MapGenerator.cs b/scripts/map/MapGenerator.cs index 1ac9397..d2b1b6d 100644 --- a/scripts/map/MapGenerator.cs +++ b/scripts/map/MapGenerator.cs @@ -148,9 +148,9 @@ public static class MapGenerator return; } - if (GameSceneDepend.MiniMapContainerNode != null) + if (GameSceneDepend.MiniMap != null) { - NodeUtils.DeleteAllChild(GameSceneDepend.MiniMapContainerNode); + GameSceneDepend.MiniMap.Clear(); } if (GameSceneDepend.AiCharacterContainer != null) diff --git a/scripts/map/events/MapGenerationPlaceRoomFinishEvent.cs b/scripts/map/events/MapGenerationPlaceRoomFinishEvent.cs index 28b4645..ddb3e6e 100644 --- a/scripts/map/events/MapGenerationPlaceRoomFinishEvent.cs +++ b/scripts/map/events/MapGenerationPlaceRoomFinishEvent.cs @@ -2,6 +2,10 @@ using ColdMint.scripts.map.dateBean; namespace ColdMint.scripts.map.events; +/// +/// MapGenerationPlaceRoomFinishEvent +/// 地图生成器放置房间完成后执行的事件 +/// public class MapGenerationPlaceRoomFinishEvent { public string? RoomNodeDataId { get; set; } diff --git a/scripts/map/miniMap/MiniMap.cs b/scripts/map/miniMap/MiniMap.cs index 77a7910..796665a 100644 --- a/scripts/map/miniMap/MiniMap.cs +++ b/scripts/map/miniMap/MiniMap.cs @@ -1,7 +1,9 @@ +using System.Collections.Generic; using ColdMint.scripts.debug; using ColdMint.scripts.map.dateBean; using ColdMint.scripts.map.events; using ColdMint.scripts.map.preview; +using ColdMint.scripts.map.room; using ColdMint.scripts.utils; using Godot; @@ -14,13 +16,18 @@ namespace ColdMint.scripts.map.miniMap; public partial class MiniMap : NinePatchRect { private Node2D? _roomPreviewContainer; - private Vector2 _miniMapMidpointCoordinate; /// /// The midpoint coordinates of the mini map /// 迷你地图的中点坐标 /// - public Vector2 MiniMapMidpointCoordinate => _miniMapMidpointCoordinate; + private Vector2 _miniMapMidpointCoordinate; + + /// + /// Mapping of rooms and room preview images + /// 房间和房间预览图的映射 + /// + private readonly Dictionary _roomToRoomPreviews = []; /// /// The master node of the map @@ -35,6 +42,32 @@ public partial class MiniMap : NinePatchRect EventBus.MapGenerationPlaceRoomFinishEvent += MapGenerationPlaceRoomFinishEvent; } + /// + /// Clean up all room preview images in the mini map + /// 清理迷你地图内的所有房间预览图 + /// + public void Clear() + { + _roomToRoomPreviews.Clear(); + if (_roomPreviewContainer != null) + { + NodeUtils.DeleteAllChild(_roomPreviewContainer); + } + } + + /// + /// Display room preview image + /// 显示房间预览图 + /// + /// + public void ShowRoomPreview(Room room) + { + if (_roomToRoomPreviews.TryGetValue(room, out var roomPreview)) + { + roomPreview.Show(); + } + } + /// /// After the map generator completes placing the room /// 地图生成器放置房间完成后 @@ -49,12 +82,17 @@ public partial class MiniMap : NinePatchRect } var tileMapLayer = roomPlacementData.NewRoom.GetTileMapLayer(Config.TileMapLayerName.Ground); - if (!CreateRoomPreview(tileMapLayer, - CalculateRelativePositionOnTheMinimap(tileMapLayer, roomPlacementData))) + var textureRect = CreateRoomPreview(tileMapLayer, + CalculateRelativePositionOnTheMinimap(tileMapLayer, roomPlacementData)); + if (textureRect == null) { LogCat.LogWithFormat("failed_to_create_room_preview", LogCat.LogLabel.Default, LogCat.UploadFormat, mapGenerationPlaceRoomFinishEvent.RoomNodeDataId); } + else + { + _roomToRoomPreviews[roomPlacementData.NewRoom] = textureRect; + } } @@ -90,29 +128,26 @@ public partial class MiniMap : NinePatchRect ///相对于迷你地图容器中点的位置 /// /// - 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); if (image == null) { - return false; + return null; } - var sprite = new TextureRect(); - sprite.Scale = new Vector2(Config.RoomPreviewScale, Config.RoomPreviewScale); - sprite.Texture = image; - if (GameSceneDepend.MiniMap != null) - { - sprite.Position = GameSceneDepend.MiniMap.MiniMapMidpointCoordinate + position.Value; - } - - NodeUtils.CallDeferredAddChild(GameSceneDepend.MiniMapContainerNode, sprite); - return true; + var textureRect = new TextureRect(); + textureRect.Scale = new Vector2(Config.RoomPreviewScale, Config.RoomPreviewScale); + textureRect.Texture = image; + textureRect.Position = _miniMapMidpointCoordinate + position.Value; + textureRect.Hide(); + NodeUtils.CallDeferredAddChild(_roomPreviewContainer, textureRect); + return textureRect; } public override void _Process(double delta) diff --git a/scripts/map/room/Room.cs b/scripts/map/room/Room.cs index 8882826..e0e1098 100644 --- a/scripts/map/room/Room.cs +++ b/scripts/map/room/Room.cs @@ -103,8 +103,10 @@ public class Room _pointLight2D.Texture = AssetHolder.White100; } + GameSceneDepend.MiniMap?.ShowRoomPreview(this); ShowAllCharacterTemplate(); - }else if (node is CharacterTemplate characterTemplate) + } + else if (node is CharacterTemplate characterTemplate) { if (_hasPlayer) {