Makes the map follow the player's movements.
使地图跟随玩家移动。
This commit is contained in:
parent
ed4339f390
commit
ab0d05d16d
|
@ -1,6 +1,8 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c74180dtf7j7a"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c74180dtf7j7a"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c35bsle7thcnh" path="res://sprites/ui/MiniMapBg.png" id="1_h88bi"]
|
||||
[ext_resource type="Script" path="res://scripts/map/miniMap/MiniMap.cs" id="2_ltp8b"]
|
||||
[ext_resource type="Texture2D" uid="uid://cfpcm0hkmpu38" path="res://sprites/ui/mark.png" id="3_x80y0"]
|
||||
|
||||
[node name="MapContainer" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -28,10 +30,10 @@ anchor_left = 1.0
|
|||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -1102.0
|
||||
offset_top = -525.0
|
||||
offset_right = -952.0
|
||||
offset_bottom = -375.0
|
||||
offset_left = -169.0
|
||||
offset_top = -168.0
|
||||
offset_right = -19.0
|
||||
offset_bottom = -18.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
texture = ExtResource("1_h88bi")
|
||||
|
@ -39,5 +41,10 @@ patch_margin_left = 7
|
|||
patch_margin_top = 7
|
||||
patch_margin_right = 7
|
||||
patch_margin_bottom = 7
|
||||
script = ExtResource("2_ltp8b")
|
||||
|
||||
[node name="RoomPreviewContainer" type="Node2D" parent="MiniMap"]
|
||||
|
||||
[node name="Mark" type="Sprite2D" parent="MiniMap"]
|
||||
position = Vector2(75, 75)
|
||||
texture = ExtResource("3_x80y0")
|
||||
|
|
|
@ -86,7 +86,7 @@ public static class Config
|
|||
/// <para>Scale of the room preview view</para>
|
||||
/// <para>房间预览图的缩放</para>
|
||||
/// </summary>
|
||||
public const float RoomPreviewScale = 1f;
|
||||
public const float RoomPreviewScale = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// <para>How much blood does a heart represent</para>
|
||||
|
|
|
@ -38,10 +38,4 @@ public static class EventManager
|
|||
/// <para>地图生成完成事件</para>
|
||||
/// </summary>
|
||||
public static Action<MapGenerationCompleteEvent>? MapGenerationCompleteEvent;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Player Instance Change Event</para>
|
||||
/// <para>玩家实例改变事件</para>
|
||||
/// </summary>
|
||||
public static Action<PlayerInstanceChangeEvent>? PlayerInstanceChangeEvent;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using ColdMint.scripts.character;
|
||||
using ColdMint.scripts.inventory;
|
||||
using ColdMint.scripts.loader.uiLoader;
|
||||
using ColdMint.scripts.map.events;
|
||||
using ColdMint.scripts.map.miniMap;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
|
||||
|
@ -14,11 +14,11 @@ namespace ColdMint.scripts;
|
|||
public static class GameSceneDepend
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>The midpoint of the minimap</para>
|
||||
/// <para>迷你地图的中点</para>
|
||||
/// <para>MiniMap</para>
|
||||
/// <para>迷你地图</para>
|
||||
/// </summary>
|
||||
public static Vector2 MiniMapMidpointCoordinate;
|
||||
|
||||
public static MiniMap? MiniMap { get; set; }
|
||||
|
||||
private static Player? _player;
|
||||
|
||||
/// <summary>
|
||||
|
@ -31,13 +31,10 @@ public static class GameSceneDepend
|
|||
set
|
||||
{
|
||||
_player = value;
|
||||
//Broadcast the event to the outside when the player instance changes.
|
||||
//当玩家实例改变时,向外广播事件。
|
||||
var playerInstanceChangeEvent = new PlayerInstanceChangeEvent
|
||||
if (MiniMap != null)
|
||||
{
|
||||
PlayerInstance = _player
|
||||
};
|
||||
EventManager.PlayerInstanceChangeEvent?.Invoke(playerInstanceChangeEvent);
|
||||
MiniMap.OwnerNode = _player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +43,7 @@ public static class GameSceneDepend
|
|||
/// <para>鼠标进入到某个角色的范围内时,会将其视作目标</para>
|
||||
/// </summary>
|
||||
public static Node2D? TemporaryTargetNode { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>MiniMapContainerNode</para>
|
||||
/// <para>迷你地图容器节点</para>
|
||||
|
|
|
@ -3,6 +3,7 @@ using ColdMint.scripts.inventory;
|
|||
using ColdMint.scripts.map;
|
||||
using ColdMint.scripts.map.LayoutParsingStrategy;
|
||||
using ColdMint.scripts.map.layoutStrategy;
|
||||
using ColdMint.scripts.map.miniMap;
|
||||
using ColdMint.scripts.map.RoomPlacer;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
|
@ -60,9 +61,10 @@ public partial class GameSceneLoader : SceneLoaderTemplate
|
|||
//加载房间容器节点
|
||||
var miniMapContainerNode = GetNode<Node2D>("CanvasLayer/Control/MapContainer/MiniMap/RoomPreviewContainer");
|
||||
GameSceneDepend.MiniMapContainerNode = miniMapContainerNode;
|
||||
//计算迷你地图的中点
|
||||
var mapContainer = GetNode<NinePatchRect>("CanvasLayer/Control/MapContainer/MiniMap");
|
||||
GameSceneDepend.MiniMapMidpointCoordinate = mapContainer.Size / 2;
|
||||
//Setting up the mini map
|
||||
//设置迷你地图
|
||||
var miniMap = GetNode<MiniMap>("CanvasLayer/Control/MapContainer/MiniMap");
|
||||
GameSceneDepend.MiniMap = miniMap;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
|
@ -373,8 +373,6 @@ public static class MapGenerator
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return roomPlacementData.Position.Value / Config.CellSize * Config.RoomPreviewScale;
|
||||
}
|
||||
|
@ -408,7 +406,11 @@ public static class MapGenerator
|
|||
var sprite = new TextureRect();
|
||||
sprite.Scale = new Vector2(Config.RoomPreviewScale, Config.RoomPreviewScale);
|
||||
sprite.Texture = image;
|
||||
sprite.Position = GameSceneDepend.MiniMapMidpointCoordinate + position.Value;
|
||||
if (GameSceneDepend.MiniMap != null)
|
||||
{
|
||||
sprite.Position = GameSceneDepend.MiniMap.MiniMapMidpointCoordinate + position.Value;
|
||||
}
|
||||
|
||||
NodeUtils.CallDeferredAddChild(GameSceneDepend.MiniMapContainerNode, sprite);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
using ColdMint.scripts.character;
|
||||
|
||||
namespace ColdMint.scripts.map.events;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Player instance change event</para>
|
||||
/// <para>玩家实例改变事件</para>
|
||||
/// </summary>
|
||||
public class PlayerInstanceChangeEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>New player instance</para>
|
||||
/// <para>新的玩家实例</para>
|
||||
/// </summary>
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
public Player? PlayerInstance { get; set; }
|
||||
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
||||
}
|
44
scripts/map/miniMap/MiniMap.cs
Normal file
44
scripts/map/miniMap/MiniMap.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.map.miniMap;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Mini Map</para>
|
||||
/// <para>迷你地图</para>
|
||||
/// </summary>
|
||||
public partial class MiniMap : NinePatchRect
|
||||
{
|
||||
private Node2D? _roomPreviewContainer;
|
||||
private Vector2 _miniMapMidpointCoordinate;
|
||||
|
||||
/// <summary>
|
||||
/// <para>The midpoint coordinates of the mini map</para>
|
||||
/// <para>迷你地图的中点坐标</para>
|
||||
/// </summary>
|
||||
public Vector2 MiniMapMidpointCoordinate => _miniMapMidpointCoordinate;
|
||||
|
||||
/// <summary>
|
||||
/// <para>The master node of the map</para>
|
||||
/// <para>地图的主人节点</para>
|
||||
/// </summary>
|
||||
public Node2D? OwnerNode { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_roomPreviewContainer = GetNode<Node2D>("RoomPreviewContainer");
|
||||
_miniMapMidpointCoordinate = Size / 2;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_roomPreviewContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerNode != null)
|
||||
{
|
||||
_roomPreviewContainer.Position = -OwnerNode.GlobalPosition / Config.CellSize * Config.RoomPreviewScale;
|
||||
}
|
||||
}
|
||||
}
|
BIN
sprites/ui/mark.png
Normal file
BIN
sprites/ui/mark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 B |
34
sprites/ui/mark.png.import
Normal file
34
sprites/ui/mark.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cfpcm0hkmpu38"
|
||||
path="res://.godot/imported/mark.png-81a29d16cd3553688c08d78ed11d42ca.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/ui/mark.png"
|
||||
dest_files=["res://.godot/imported/mark.png-81a29d16cd3553688c08d78ed11d42ca.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
Loading…
Reference in New Issue
Block a user