diff --git a/DungeonShooting_Godot/prefab/ui/Loading.tscn b/DungeonShooting_Godot/prefab/ui/Loading.tscn new file mode 100644 index 0000000..ba23836 --- /dev/null +++ b/DungeonShooting_Godot/prefab/ui/Loading.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=2 format=3 uid="uid://da5kqq45ow5am"] + +[ext_resource type="Script" path="res://src/game/ui/loading/LoadingPanel.cs" id="1_x0t5x"] + +[node name="Loading" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_x0t5x") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.109804, 0.0666667, 0.0901961, 1) + +[node name="Label" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "loading..." +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs index 19efec9..1e2f26f 100644 --- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs +++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs @@ -158,6 +158,14 @@ } } + /// + /// 播放玩家死亡特写镜头 + /// + public void PlayPlayerDieFeatures() + { + + } + //抖动调用 private void _Shake(float delta) { diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index 0c33cc3..df86ac8 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -20,6 +20,7 @@ public const string prefab_test_MoveComponent_tscn = "res://prefab/test/MoveComponent.tscn"; public const string prefab_test_TestActivity_tscn = "res://prefab/test/TestActivity.tscn"; public const string prefab_ui_EditorTools_tscn = "res://prefab/ui/EditorTools.tscn"; + public const string prefab_ui_Loading_tscn = "res://prefab/ui/Loading.tscn"; public const string prefab_ui_Main_tscn = "res://prefab/ui/Main.tscn"; public const string prefab_ui_RoomUI_tscn = "res://prefab/ui/RoomUI.tscn"; public const string prefab_ui_Settlement_tscn = "res://prefab/ui/Settlement.tscn"; diff --git a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs index 3feb3d4..431fc32 100644 --- a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs +++ b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs @@ -7,6 +7,7 @@ public static class UiName { public const string EditorTools = "EditorTools"; + public const string Loading = "Loading"; public const string Main = "Main"; public const string RoomUI = "RoomUI"; public const string Settlement = "Settlement"; @@ -53,6 +54,46 @@ } /// + /// 打开 Loading, 并返回UI实例 + /// + public static UI.Loading.LoadingPanel Open_Loading() + { + return OpenUi(UiName.Loading); + } + + /// + /// 隐藏 Loading 的所有实例 + /// + public static void Hide_Loading() + { + var uiInstance = Get_Loading_Instance(); + foreach (var uiPanel in uiInstance) + { + uiPanel.HideUi(); + } + } + + /// + /// 销毁 Loading 的所有实例 + /// + public static void Dispose_Loading() + { + var uiInstance = Get_Loading_Instance(); + foreach (var uiPanel in uiInstance) + { + uiPanel.DisposeUi(); + } + } + + /// + /// 获取所有 Loading 的实例, 如果没有实例, 则返回一个空数组 + /// + public static UI.Loading.LoadingPanel[] Get_Loading_Instance() + { + return GetUiInstance(nameof(UI.Loading.Loading)); + } + + /// /// 打开 Main, 并返回UI实例 /// public static UI.Main.MainPanel Open_Main() diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs index d5f45e0..aa30394 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -1,5 +1,6 @@  using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using Godot; @@ -28,7 +29,8 @@ /// 是否在地牢里 /// public bool IsInDungeon { get; private set; } - + + private DungeonConfig _config; private DungeonTile _dungeonTile; private AutoTileConfig _autoTileConfig; private DungeonGenerator _dungeonGenerator; @@ -53,55 +55,8 @@ /// public void LoadDungeon(DungeonConfig config) { - IsInDungeon = true; - var nowTicks = DateTime.Now.Ticks; - //创建世界场景 - _world = GameApplication.Instance.CreateNewWorld(); - //生成地牢房间 - _dungeonGenerator = new DungeonGenerator(config); - _dungeonGenerator.Generate(); - - //填充地牢 - _autoTileConfig = new AutoTileConfig(); - _dungeonTile = new DungeonTile(_world.TileRoot); - _dungeonTile.AutoFillRoomTile(_autoTileConfig, _dungeonGenerator.StartRoom); - - //生成寻路网格, 这一步操作只生成过道的导航 - _dungeonTile.GenerateNavigationPolygon(GameConfig.AisleFloorMapLayer); - //挂载过道导航区域 - _dungeonTile.MountNavigationPolygon(_world.TileRoot); - //过道导航区域数据 - _roomStaticNavigationList = new List(); - _roomStaticNavigationList.AddRange(_dungeonTile.GetPolygonData()); - //门导航区域数据 - _roomStaticNavigationList.AddRange(_dungeonTile.GetConnectDoorPolygonData()); - //初始化所有房间 - _dungeonGenerator.EachRoom(InitRoom); - - GD.Print("生成地牢用时: " + (DateTime.Now.Ticks - nowTicks) / 10000 + "毫秒"); - - //播放bgm - //SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f); - - //初始房间创建玩家标记 - var playerBirthMark = StartRoom.ActivityMarks.FirstOrDefault(mark => mark.Type == ActivityIdPrefix.ActivityPrefixType.Player); - //创建玩家 - var player = ActivityObject.Create(ActivityIdPrefix.Role + "0001"); - if (playerBirthMark != null) - { - player.Position = playerBirthMark.Position; - } - player.Name = "Player"; - Player.SetCurrentPlayer(player); - player.PutDown(RoomLayerEnum.YSortLayer); - player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0001")); - - GameApplication.Instance.Cursor.SetGuiMode(false); - //打开游戏中的ui - var roomUi = UiManager.Open_RoomUI(); - roomUi.InitData(player); - //派发进入地牢事件 - EventManager.EmitEvent(EventEnum.OnEnterDungeon); + _config = config; + GameApplication.Instance.StartCoroutine(RunLoadDungeonCoroutine()); } /// @@ -110,22 +65,7 @@ public void ExitDungeon() { IsInDungeon = false; - - _dungeonGenerator.EachRoom(DisposeRoomInfo); - _dungeonTile = null; - _autoTileConfig = null; - _dungeonGenerator = null; - _roomStaticNavigationList.Clear(); - _roomStaticNavigationList = null; - - UiManager.Hide_RoomUI(); - Player.SetCurrentPlayer(null); - _world = null; - GameApplication.Instance.DestroyWorld(); - //鼠标还原 - GameApplication.Instance.Cursor.SetGuiMode(false); - //派发退出地牢事件 - EventManager.EmitEvent(EventEnum.OnExitDungeon); + GameApplication.Instance.StartCoroutine(RunExitDungeonCoroutine()); } public override void _PhysicsProcess(double delta) @@ -153,6 +93,104 @@ } } } + + //执行加载地牢协程 + private IEnumerator RunLoadDungeonCoroutine() + { + yield return 0; + //打开 loading UI + UiManager.Open_Loading(); + //创建世界场景 + _world = GameApplication.Instance.CreateNewWorld(); + yield return new WaitForFixedProcess(10); + //生成地牢房间 + _dungeonGenerator = new DungeonGenerator(_config); + _dungeonGenerator.Generate(); + yield return 0; + + //填充地牢 + _autoTileConfig = new AutoTileConfig(); + _dungeonTile = new DungeonTile(_world.TileRoot); + _dungeonTile.AutoFillRoomTile(_autoTileConfig, _dungeonGenerator.StartRoom); + yield return 0; + + //生成寻路网格, 这一步操作只生成过道的导航 + _dungeonTile.GenerateNavigationPolygon(GameConfig.AisleFloorMapLayer); + yield return 0; + //挂载过道导航区域 + _dungeonTile.MountNavigationPolygon(_world.TileRoot); + yield return 0; + //过道导航区域数据 + _roomStaticNavigationList = new List(); + _roomStaticNavigationList.AddRange(_dungeonTile.GetPolygonData()); + yield return 0; + //门导航区域数据 + _roomStaticNavigationList.AddRange(_dungeonTile.GetConnectDoorPolygonData()); + yield return new WaitForFixedProcess(10); + //初始化所有房间 + _dungeonGenerator.EachRoom(InitRoom); + yield return new WaitForFixedProcess(10); + + //播放bgm + //SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f); + + //初始房间创建玩家标记 + var playerBirthMark = StartRoom.ActivityMarks.FirstOrDefault(mark => mark.Type == ActivityIdPrefix.ActivityPrefixType.Player); + //创建玩家 + var player = ActivityObject.Create(ActivityIdPrefix.Role + "0001"); + if (playerBirthMark != null) + { + player.Position = playerBirthMark.Position; + } + player.Name = "Player"; + Player.SetCurrentPlayer(player); + player.PutDown(RoomLayerEnum.YSortLayer); + player.PickUpWeapon(ActivityObject.Create(ActivityIdPrefix.Weapon + "0001")); + + GameApplication.Instance.Cursor.SetGuiMode(false); + yield return 0; + + //打开游戏中的ui + var roomUi = UiManager.Open_RoomUI(); + roomUi.InitData(player); + //派发进入地牢事件 + EventManager.EmitEvent(EventEnum.OnEnterDungeon); + //关闭 loading UI + UiManager.Dispose_Loading(); + + IsInDungeon = true; + yield return 0; + } + + private IEnumerator RunExitDungeonCoroutine() + { + yield return 0; + _world.Pause = true; + yield return 0; + //打开 loading UI + UiManager.Open_Loading(); + _dungeonGenerator.EachRoom(DisposeRoomInfo); + yield return 0; + _dungeonTile = null; + _autoTileConfig = null; + _dungeonGenerator = null; + _roomStaticNavigationList.Clear(); + _roomStaticNavigationList = null; + + UiManager.Hide_RoomUI(); + yield return new WaitForFixedProcess(10); + Player.SetCurrentPlayer(null); + _world = null; + GameApplication.Instance.DestroyWorld(); + yield return new WaitForFixedProcess(10); + //鼠标还原 + GameApplication.Instance.Cursor.SetGuiMode(false); + //派发退出地牢事件 + EventManager.EmitEvent(EventEnum.OnExitDungeon); + //关闭 loading UI + UiManager.Dispose_Loading(); + yield return 0; + } // 初始化房间 private void InitRoom(RoomInfo roomInfo) diff --git a/DungeonShooting_Godot/src/game/room/World.cs b/DungeonShooting_Godot/src/game/room/World.cs index 74f7c4d..52fa884 100644 --- a/DungeonShooting_Godot/src/game/room/World.cs +++ b/DungeonShooting_Godot/src/game/room/World.cs @@ -34,7 +34,7 @@ _pause = value; if (value) { - ProcessMode = ProcessModeEnum.Pausable; + ProcessMode = ProcessModeEnum.WhenPaused; } else { diff --git a/DungeonShooting_Godot/src/game/ui/loading/Loading.cs b/DungeonShooting_Godot/src/game/ui/loading/Loading.cs new file mode 100644 index 0000000..22bfc38 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/loading/Loading.cs @@ -0,0 +1,57 @@ +namespace UI.Loading; + +/// +/// Ui代码, 该类是根据ui场景自动生成的, 请不要手动编辑该类, 以免造成代码丢失 +/// +public abstract partial class Loading : UiBase +{ + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Loading.ColorRect + /// + public UiNode_ColorRect L_ColorRect + { + get + { + if (_L_ColorRect == null) _L_ColorRect = new UiNode_ColorRect(GetNodeOrNull("ColorRect")); + return _L_ColorRect; + } + } + private UiNode_ColorRect _L_ColorRect; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Loading.Label + /// + public UiNode_Label L_Label + { + get + { + if (_L_Label == null) _L_Label = new UiNode_Label(GetNodeOrNull("Label")); + return _L_Label; + } + } + private UiNode_Label _L_Label; + + + public Loading() : base(nameof(Loading)) + { + } + + /// + /// 类型: , 路径: Loading.ColorRect + /// + public class UiNode_ColorRect : IUiNode + { + public UiNode_ColorRect(Godot.ColorRect node) : base(node) { } + public override UiNode_ColorRect Clone() => new ((Godot.ColorRect)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: Loading.Label + /// + public class UiNode_Label : IUiNode + { + public UiNode_Label(Godot.Label node) : base(node) { } + public override UiNode_Label Clone() => new ((Godot.Label)Instance.Duplicate()); + } + +} diff --git a/DungeonShooting_Godot/src/game/ui/loading/LoadingPanel.cs b/DungeonShooting_Godot/src/game/ui/loading/LoadingPanel.cs new file mode 100644 index 0000000..bb317f7 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/loading/LoadingPanel.cs @@ -0,0 +1,18 @@ +using Godot; + +namespace UI.Loading; + +public partial class LoadingPanel : Loading +{ + + public override void OnShowUi() + { + + } + + public override void OnHideUi() + { + + } + +} diff --git a/DungeonShooting_Godot/src/game/ui/settlement/SettlementPanel.cs b/DungeonShooting_Godot/src/game/ui/settlement/SettlementPanel.cs index d5c8b89..831cd87 100644 --- a/DungeonShooting_Godot/src/game/ui/settlement/SettlementPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/settlement/SettlementPanel.cs @@ -15,12 +15,11 @@ { L_ButtonList.L_Restart.Instance.Pressed -= OnRestartClick; L_ButtonList.L_ToMenu.Instance.Pressed -= OnToMenuClick; - } private void OnRestartClick() { - + GD.Print("重新开始还没做..."); } private void OnToMenuClick()