diff --git a/DungeonShooting_Godot/prefab/ui/RoomMap.tscn b/DungeonShooting_Godot/prefab/ui/RoomMap.tscn index 853dfcf..35e273b 100644 --- a/DungeonShooting_Godot/prefab/ui/RoomMap.tscn +++ b/DungeonShooting_Godot/prefab/ui/RoomMap.tscn @@ -57,7 +57,6 @@ expand_mode = 1 [node name="Root" type="Node2D" parent="MapBar/DrawContainer"] -scale = Vector2(1.5, 1.5) [node name="Mark" type="Sprite2D" parent="MapBar/DrawContainer"] position = Vector2(28, 28) diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index 45be278..d96eb80 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -350,7 +350,9 @@ World = world; ActivityBase = config; +#if TOOLS Name = GetType().Name + (_instanceIndex++); +#endif Id = _instanceIndex; _blendShaderMaterial = AnimatedSprite.Material as ShaderMaterial; diff --git a/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs b/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs index ddec291..d943e6a 100644 --- a/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs +++ b/DungeonShooting_Godot/src/framework/map/AffiliationArea.cs @@ -291,7 +291,6 @@ EventManager.EmitEvent(EventEnum.OnPlayerEnterRoom, RoomInfo); IsFirstEnterFlag = false; } - public void Destroy() { diff --git a/DungeonShooting_Godot/src/framework/map/fog/AisleFogArea.cs b/DungeonShooting_Godot/src/framework/map/fog/AisleFogArea.cs index 3712c8b..308968e 100644 --- a/DungeonShooting_Godot/src/framework/map/fog/AisleFogArea.cs +++ b/DungeonShooting_Godot/src/framework/map/fog/AisleFogArea.cs @@ -66,29 +66,18 @@ if (body == Player.Current) { //注意需要延时调用 - CallDeferred(nameof(InsertItem)); + CallDeferred(nameof(InsertPlayer)); } } - - // private void OnBodyExited(Node2D body) - // { - // if (body == Player.Current) - // { - // //注意需要延时调用 - // CallDeferred(nameof(LeavePlayer)); - // } - // } - private void InsertItem() + private void InsertPlayer() { //Debug.Log("玩家进入过道"); - //RoomDoorInfo.ClearFog(); + if (!RoomDoorInfo.AisleFogMask.IsExplored) + { + EventManager.EmitEvent(EventEnum.OnPlayerFirstEnterAisle, RoomDoorInfo); + } + EventManager.EmitEvent(EventEnum.OnPlayerEnterAisle, RoomDoorInfo); FogMaskHandler.RefreshAisleFog(RoomDoorInfo); } - - // private void LeavePlayer() - // { - // //Debug.Log("玩家离开过道"); - // //RoomDoorInfo.DarkFog(); - // } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs index 56ab624..828fae4 100644 --- a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs @@ -95,6 +95,11 @@ public PreviewFogMask PreviewAisleFogMask; /// + /// 未探索的区域显示的问号 + /// + public Sprite2D UnknownSprite; + + /// /// 世界坐标下的原点坐标, 单位: 像素 /// public Vector2I GetWorldOriginPosition() @@ -106,6 +111,23 @@ } /// + /// 终点坐标, 单位: 格 + /// + public Vector2I GetEndPosition() + { + if (Direction == DoorDirection.E || Direction == DoorDirection.W) + { + return OriginPosition + new Vector2I(0, 4); + } + else if (Direction == DoorDirection.N || Direction == DoorDirection.S) + { + return OriginPosition + new Vector2I(4, 0); + } + + return default; + } + + /// /// 世界坐标下的终点坐标, 单位: 像素 /// public Vector2I GetWorldEndPosition() diff --git a/DungeonShooting_Godot/src/game/event/EventEnum.cs b/DungeonShooting_Godot/src/game/event/EventEnum.cs index 28dd63a..e4e6e99 100644 --- a/DungeonShooting_Godot/src/game/event/EventEnum.cs +++ b/DungeonShooting_Godot/src/game/event/EventEnum.cs @@ -19,6 +19,14 @@ /// OnPlayerFirstEnterRoom, /// + /// 玩家进入过道时调用, 参数类型为进入该过道的门 + /// + OnPlayerEnterAisle, + /// + /// 玩家首次进入过道时调用, 参数类型为进入该过道的门 + /// + OnPlayerFirstEnterAisle, + /// /// 玩家可互动对象改变, 参数类型为 /// OnPlayerChangeInteractiveItem, diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index fd73c61..6314fce 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -241,6 +241,7 @@ public const string resource_sprite_role_enemy0002_Enemy0002_idle_png = "res://resource/sprite/role/enemy0002/Enemy0002_idle.png"; public const string resource_sprite_role_enemy0002_Enemy0002_run_png = "res://resource/sprite/role/enemy0002/Enemy0002_run.png"; public const string resource_sprite_role_role0001_Role0001_png = "res://resource/sprite/role/role0001/Role0001.png"; + public const string resource_sprite_role_role0001_Role0001_head_png = "res://resource/sprite/role/role0001/Role0001_head.png"; public const string resource_sprite_role_role0001_Role0001_Icon_png = "res://resource/sprite/role/role0001/Role0001_Icon.png"; public const string resource_sprite_role_role0001_idle_Sprite0002_png = "res://resource/sprite/role/role0001/idle/Sprite-0002.png"; public const string resource_sprite_role_role0001_idle_Sprite0003_png = "res://resource/sprite/role/role0001/idle/Sprite-0003.png"; @@ -296,6 +297,7 @@ public const string resource_sprite_ui_commonIcon_Select_png = "res://resource/sprite/ui/commonIcon/Select.png"; public const string resource_sprite_ui_commonIcon_Select2_png = "res://resource/sprite/ui/commonIcon/Select2.png"; public const string resource_sprite_ui_commonIcon_Setting_png = "res://resource/sprite/ui/commonIcon/Setting.png"; + public const string resource_sprite_ui_commonIcon_Unknown_png = "res://resource/sprite/ui/commonIcon/Unknown.png"; public const string resource_sprite_ui_commonIcon_Unlock_png = "res://resource/sprite/ui/commonIcon/Unlock.png"; public const string resource_sprite_ui_commonIcon_Visible_png = "res://resource/sprite/ui/commonIcon/Visible.png"; public const string resource_sprite_ui_commonIcon_WaveCell_png = "res://resource/sprite/ui/commonIcon/WaveCell.png"; diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs index fa58a54..daf3368 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -248,22 +248,7 @@ player.Name = "Player"; player.PutDown(RoomLayerEnum.YSortLayer); Player.SetCurrentPlayer(player); - yield return 0; - - //玩家手上添加武器 - //player.PickUpWeapon(ActivityObject.Create(ActivityObject.Ids.Id_weapon0001)); - // var weapon = ActivityObject.Create(ActivityObject.Ids.Id_weapon0001); - // weapon.PutDown(player.Position, RoomLayerEnum.NormalLayer); - // var weapon2 = ActivityObject.Create(ActivityObject.Ids.Id_weapon0002); - // weapon2.PutDown(player.Position, RoomLayerEnum.NormalLayer); - // var weapon3 = ActivityObject.Create(ActivityObject.Ids.Id_weapon0003); - // weapon3.PutDown(player.Position, RoomLayerEnum.NormalLayer); - // var weapon4 = ActivityObject.Create(ActivityObject.Ids.Id_weapon0004); - // weapon4.PutDown(player.Position, RoomLayerEnum.NormalLayer); - GameApplication.Instance.Cursor.SetGuiMode(false); - yield return 0; - //打开游戏中的ui UiManager.Open_RoomUI(); //派发进入地牢事件 diff --git a/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs b/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs index 1871d81..b3efc46 100644 --- a/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using Godot; @@ -6,13 +7,20 @@ public partial class RoomMapPanel : RoomMap { + private EventFactory _factory = EventManager.CreateEventFactory(); + private List _needRefresh = new List(); + public override void OnCreateUi() { InitMap(); + _factory.AddEventListener(EventEnum.OnPlayerFirstEnterRoom, OnPlayerFirstEnterRoom); + _factory.AddEventListener(EventEnum.OnPlayerFirstEnterAisle, OnPlayerFirstEnterAisle); } + public override void OnDestroyUi() { + _factory.RemoveAllEventListener(); } public override void Process(float delta) @@ -28,7 +36,16 @@ // S_RoomMap.Instance.HideUi(); // World.Current.Pause = false; // } - + + if (_needRefresh.Count > 0) + { + foreach (var roomDoorInfo in _needRefresh) + { + HandlerRefreshUnknownSprite(roomDoorInfo); + } + _needRefresh.Clear(); + } + S_Root.Instance.Position = S_DrawContainer.Instance.Size / 2 - Player.Current.Position / 16 * S_Root.Instance.Scale; } @@ -53,6 +70,91 @@ } } }); - } + + private void OnPlayerFirstEnterRoom(object data) + { + var roomInfo = (RoomInfo)data; + roomInfo.PreviewSprite.Visible = true; + + if (roomInfo.Doors!= null) + { + foreach (var roomDoor in roomInfo.Doors) + { + RefreshUnknownSprite(roomDoor); + } + } + } + + private void OnPlayerFirstEnterAisle(object data) + { + var roomDoorInfo = (RoomDoorInfo)data; + roomDoorInfo.AislePreviewSprite.Visible = true; + + RefreshUnknownSprite(roomDoorInfo); + RefreshUnknownSprite(roomDoorInfo.ConnectDoor); + } + + private void RefreshUnknownSprite(RoomDoorInfo roomDoorInfo) + { + if (!_needRefresh.Contains(roomDoorInfo)) + { + _needRefresh.Add(roomDoorInfo); + } + } + + private void HandlerRefreshUnknownSprite(RoomDoorInfo roomDoorInfo) + { + //是否探索房间 + var flag1 = roomDoorInfo.RoomInfo.RoomFogMask.IsExplored; + //是否探索过道 + var flag2 = roomDoorInfo.AisleFogMask.IsExplored; + if (flag1 == flag2) //不显示问号 + { + if (roomDoorInfo.UnknownSprite != null) + { + roomDoorInfo.UnknownSprite.QueueFree(); + roomDoorInfo.UnknownSprite = null; + } + } + else + { + var unknownSprite = roomDoorInfo.UnknownSprite ?? CreateUnknownSprite(roomDoorInfo); + var pos = (roomDoorInfo.OriginPosition + roomDoorInfo.GetEndPosition()) / 2; + if (!flag2) //偏向过道 + { + if (roomDoorInfo.Direction == DoorDirection.N) + pos += new Vector2I(0, -2); + else if (roomDoorInfo.Direction == DoorDirection.S) + pos += new Vector2I(0, 2); + else if (roomDoorInfo.Direction == DoorDirection.E) + pos += new Vector2I(2, 0); + else if (roomDoorInfo.Direction == DoorDirection.W) + pos += new Vector2I(-2, 0); + } + else //偏向房间 + { + if (roomDoorInfo.Direction == DoorDirection.N) + pos -= new Vector2I(0, -2); + else if (roomDoorInfo.Direction == DoorDirection.S) + pos -= new Vector2I(0, 2); + else if (roomDoorInfo.Direction == DoorDirection.E) + pos -= new Vector2I(2, 0); + else if (roomDoorInfo.Direction == DoorDirection.W) + pos -= new Vector2I(-2, 0); + } + unknownSprite.Position = pos; + } + } + + private Sprite2D CreateUnknownSprite(RoomDoorInfo roomInfoDoor) + { + var unknownSprite = new Sprite2D(); + unknownSprite.Texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Unknown_png); + unknownSprite.Scale = new Vector2(0.25f, 0.25f); + roomInfoDoor.UnknownSprite = unknownSprite; + S_Root.AddChild(unknownSprite); + return unknownSprite; + } + }