diff --git a/DungeonShooting_Godot/prefab/ui/Main.tscn b/DungeonShooting_Godot/prefab/ui/Main.tscn index 3138727..6bae01b 100644 --- a/DungeonShooting_Godot/prefab/ui/Main.tscn +++ b/DungeonShooting_Godot/prefab/ui/Main.tscn @@ -12,6 +12,15 @@ grow_vertical = 2 script = ExtResource("1_s44xr") +[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="Title" type="Label" parent="."] layout_mode = 1 anchors_preset = 10 diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index c36c7b6..4fb326f 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -211,7 +211,7 @@ [rendering] textures/canvas_textures/default_texture_filter=0 -environment/defaults/default_clear_color=Color(0.109804, 0.0666667, 0.0901961, 1) +environment/defaults/default_clear_color=Color(0, 0, 0, 1) 2d/snapping/use_gpu_pixel_snap=true environment/default_environment="res://default_env.tres" diff --git a/DungeonShooting_Godot/scene/World.tscn b/DungeonShooting_Godot/scene/World.tscn index 23a0ef2..cb92956 100644 --- a/DungeonShooting_Godot/scene/World.tscn +++ b/DungeonShooting_Godot/scene/World.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://src/game/room/World.cs" id="1_kt3mm"] [ext_resource type="TileSet" uid="uid://b00g22o1cqhe8" path="res://resource/map/tileSet/TileSet1.tres" id="2_p6iui"] -[node name="World" type="Node2D" node_paths=PackedStringArray("NormalLayer", "YSortLayer", "TileRoot", "StaticSpriteRoot", "AffiliationAreaRoot")] +[node name="World" type="CanvasModulate" node_paths=PackedStringArray("NormalLayer", "YSortLayer", "TileRoot", "StaticSpriteRoot", "AffiliationAreaRoot")] script = ExtResource("1_kt3mm") NormalLayer = NodePath("NormalLayer") YSortLayer = NodePath("YSortLayer") diff --git a/DungeonShooting_Godot/scene/test/TestRoomFog.tscn b/DungeonShooting_Godot/scene/test/TestRoomFog.tscn new file mode 100644 index 0000000..32caf1e --- /dev/null +++ b/DungeonShooting_Godot/scene/test/TestRoomFog.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://bgbjg8virrams"] + +[ext_resource type="Texture2D" uid="uid://h7hkgbwj1li" path="res://resource/sprite/effects/common/Smoke.png" id="1_bty2r"] +[ext_resource type="Texture2D" uid="uid://uhhfgdhpk7i4" path="res://icon.png" id="1_d62vx"] + +[node name="TestRoomFog" type="Node2D"] + +[node name="PointLight2D" type="PointLight2D" parent="."] +position = Vector2(369, 280) +scale = Vector2(5, 5) +texture = ExtResource("1_bty2r") + +[node name="CanvasModulate" type="CanvasModulate" parent="."] +position = Vector2(-16, 33) +color = Color(0.352941, 0.352941, 0.352941, 1) + +[node name="Sprite2D" type="Sprite2D" parent="CanvasModulate"] +position = Vector2(368, 326) +scale = Vector2(9.17187, 8.46875) +texture = ExtResource("1_d62vx") diff --git a/DungeonShooting_Godot/src/framework/coroutine/ProxyCoroutineHandler.cs b/DungeonShooting_Godot/src/framework/coroutine/ProxyCoroutineHandler.cs index 97abea5..ed04749 100644 --- a/DungeonShooting_Godot/src/framework/coroutine/ProxyCoroutineHandler.cs +++ b/DungeonShooting_Godot/src/framework/coroutine/ProxyCoroutineHandler.cs @@ -81,17 +81,7 @@ if (item.Enumerator.MoveNext()) { var next = item.Enumerator.Current; - if (next is IEnumerable enumerable) //嵌套协程 - { - if (item.EnumeratorStack == null) - { - item.EnumeratorStack = new Stack(); - } - - item.EnumeratorStack.Push(item.Enumerator); - item.Enumerator = enumerable.GetEnumerator(); - } - else if (next is IEnumerator enumerator) //嵌套协程 + if (next is IEnumerator enumerator) //嵌套协程 { if (item.EnumeratorStack == null) { @@ -101,6 +91,16 @@ item.EnumeratorStack.Push(item.Enumerator); item.Enumerator = enumerator; } + else if (next is IEnumerable enumerable) //嵌套协程 + { + if (item.EnumeratorStack == null) + { + item.EnumeratorStack = new Stack(); + } + + item.EnumeratorStack.Push(item.Enumerator); + item.Enumerator = enumerable.GetEnumerator(); + } else if (next is WaitForSeconds seconds) //等待秒数 { item.WaitFor(seconds); diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs index 5c83e0b..fbec68a 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -1,5 +1,6 @@ using System; +using System.Collections; using System.Collections.Generic; using Godot; @@ -124,6 +125,28 @@ EachRoom(next, cb); } } + + /// + /// 用于协程中的遍历所有房间 + /// + public IEnumerator EachRoomCoroutine(Action cb) + { + return EachRoomCoroutine(StartRoomInfo, cb); + } + + private IEnumerator EachRoomCoroutine(RoomInfo roomInfo, Action cb) + { + if (roomInfo == null) + { + yield break; + } + + cb(roomInfo); + foreach (var next in roomInfo.Next) + { + yield return EachRoomCoroutine(next, cb); + } + } /// /// 生成房间 diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs index c0b9834..64e7742 100644 --- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs +++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs @@ -191,7 +191,7 @@ yield return 0; //创建世界场景 World = GameApplication.Instance.CreateNewWorld(); - yield return new WaitForFixedProcess(10); + yield return 0; //生成地牢房间 _dungeonGenerator = new DungeonGenerator(CurrConfig); _dungeonGenerator.Generate(); @@ -215,14 +215,17 @@ yield return 0; //门导航区域数据 _roomStaticNavigationList.AddRange(_dungeonTileMap.GetConnectDoorPolygonData()); - yield return new WaitForFixedProcess(10); + yield return 0; //初始化所有房间 - _dungeonGenerator.EachRoom(InitRoom); - yield return new WaitForFixedProcess(10); + yield return _dungeonGenerator.EachRoomCoroutine(InitRoom); + yield return 0; //播放bgm //SoundManager.PlayMusic(ResourcePath.resource_sound_bgm_Intro_ogg, -17f); + //地牢加载即将完成 + yield return _dungeonGenerator.EachRoomCoroutine(info => info.OnReady()); + //初始房间创建玩家标记 var playerBirthMark = StartRoomInfo.RoomPreinstall.GetPlayerBirthMark(); //创建玩家 @@ -235,9 +238,7 @@ player.Name = "Player"; player.PutDown(RoomLayerEnum.YSortLayer); Player.SetCurrentPlayer(player); - - //地牢加载即将完成 - _dungeonGenerator.EachRoom(info => info.OnReady()); + yield return 0; //玩家手上添加武器 //player.PickUpWeapon(ActivityObject.Create(ActivityObject.Ids.Id_weapon0001)); @@ -269,6 +270,7 @@ } } + //执行退出地牢流程 private IEnumerator RunExitDungeonCoroutine(Action finish) { //打开 loading UI @@ -285,11 +287,11 @@ _roomStaticNavigationList = null; UiManager.Hide_RoomUI(); - yield return new WaitForFixedProcess(10); + yield return 0; Player.SetCurrentPlayer(null); World = null; GameApplication.Instance.DestroyWorld(); - yield return new WaitForFixedProcess(10); + yield return 0; QueueRedraw(); //鼠标还原 GameApplication.Instance.Cursor.SetGuiMode(true); @@ -315,6 +317,8 @@ CreateRoomAffiliation(roomInfo); //创建静态精灵画布 CreateRoomStaticSpriteCanvas(roomInfo); + //创建迷雾遮罩 + } //挂载房间导航区域 diff --git a/DungeonShooting_Godot/src/game/room/World.cs b/DungeonShooting_Godot/src/game/room/World.cs index a11e2fd..c44799f 100644 --- a/DungeonShooting_Godot/src/game/room/World.cs +++ b/DungeonShooting_Godot/src/game/room/World.cs @@ -5,7 +5,7 @@ /// /// 游戏世界 /// -public partial class World : Node2D, ICoroutine +public partial class World : CanvasModulate, ICoroutine { /// /// //对象根节点 diff --git a/DungeonShooting_Godot/src/game/ui/main/Main.cs b/DungeonShooting_Godot/src/game/ui/main/Main.cs index fe49dfb..3db6d93 100644 --- a/DungeonShooting_Godot/src/game/ui/main/Main.cs +++ b/DungeonShooting_Godot/src/game/ui/main/Main.cs @@ -6,198 +6,230 @@ public abstract partial class Main : UiBase { /// - /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Title + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.ColorRect /// - public Main_Title L_Title + public ColorRect L_ColorRect { get { - if (_L_Title == null) _L_Title = new Main_Title(this, GetNodeOrNull("Title")); + if (_L_ColorRect == null) _L_ColorRect = new ColorRect((MainPanel)this, GetNode("ColorRect")); + return _L_ColorRect; + } + } + private ColorRect _L_ColorRect; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Title + /// + public Title L_Title + { + get + { + if (_L_Title == null) _L_Title = new Title((MainPanel)this, GetNode("Title")); return _L_Title; } } - private Main_Title _L_Title; + private Title _L_Title; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.ButtonList /// - public Main_ButtonList L_ButtonList + public ButtonList L_ButtonList { get { - if (_L_ButtonList == null) _L_ButtonList = new Main_ButtonList(this, GetNodeOrNull("ButtonList")); + if (_L_ButtonList == null) _L_ButtonList = new ButtonList((MainPanel)this, GetNode("ButtonList")); return _L_ButtonList; } } - private Main_ButtonList _L_ButtonList; + private ButtonList _L_ButtonList; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Version /// - public Main_Version L_Version + public Version L_Version { get { - if (_L_Version == null) _L_Version = new Main_Version(this, GetNodeOrNull("Version")); + if (_L_Version == null) _L_Version = new Version((MainPanel)this, GetNode("Version")); return _L_Version; } } - private Main_Version _L_Version; + private Version _L_Version; public Main() : base(nameof(Main)) { } + public sealed override void OnInitNestedUi() + { + + } + + /// + /// 类型: , 路径: Main.ColorRect + /// + public class ColorRect : UiNode + { + public ColorRect(MainPanel uiPanel, Godot.ColorRect node) : base(uiPanel, node) { } + public override ColorRect Clone() => new (UiPanel, (Godot.ColorRect)Instance.Duplicate()); + } + /// /// 类型: , 路径: Main.Title /// - public class Main_Title : UiNode + public class Title : UiNode { - public Main_Title(Main uiPanel, Godot.Label node) : base(uiPanel, node) { } - public override Main_Title Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); + public Title(MainPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } + public override Title Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); } /// /// 类型: , 路径: Main.ButtonList.Start /// - public class Main_Start : UiNode + public class Start : UiNode { - public Main_Start(Main uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override Main_Start Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + public Start(MainPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override Start Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); } /// /// 类型: , 路径: Main.ButtonList.Tools /// - public class Main_Tools : UiNode + public class Tools : UiNode { - public Main_Tools(Main uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override Main_Tools Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + public Tools(MainPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override Tools Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); } /// /// 类型: , 路径: Main.ButtonList.Setting /// - public class Main_Setting : UiNode + public class Setting : UiNode { - public Main_Setting(Main uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override Main_Setting Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + public Setting(MainPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override Setting Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); } /// /// 类型: , 路径: Main.ButtonList.Exit /// - public class Main_Exit : UiNode + public class Exit : UiNode { - public Main_Exit(Main uiPanel, Godot.Button node) : base(uiPanel, node) { } - public override Main_Exit Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); + public Exit(MainPanel uiPanel, Godot.Button node) : base(uiPanel, node) { } + public override Exit Clone() => new (UiPanel, (Godot.Button)Instance.Duplicate()); } /// /// 类型: , 路径: Main.ButtonList /// - public class Main_ButtonList : UiNode + public class ButtonList : UiNode { /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Start /// - public Main_Start L_Start + public Start L_Start { get { - if (_L_Start == null) _L_Start = new Main_Start(UiPanel, Instance.GetNodeOrNull("Start")); + if (_L_Start == null) _L_Start = new Start(UiPanel, Instance.GetNode("Start")); return _L_Start; } } - private Main_Start _L_Start; + private Start _L_Start; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Tools /// - public Main_Tools L_Tools + public Tools L_Tools { get { - if (_L_Tools == null) _L_Tools = new Main_Tools(UiPanel, Instance.GetNodeOrNull("Tools")); + if (_L_Tools == null) _L_Tools = new Tools(UiPanel, Instance.GetNode("Tools")); return _L_Tools; } } - private Main_Tools _L_Tools; + private Tools _L_Tools; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Setting /// - public Main_Setting L_Setting + public Setting L_Setting { get { - if (_L_Setting == null) _L_Setting = new Main_Setting(UiPanel, Instance.GetNode("Setting")); + if (_L_Setting == null) _L_Setting = new Setting(UiPanel, Instance.GetNode("Setting")); return _L_Setting; } } - private Main_Setting _L_Setting; + private Setting _L_Setting; /// /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: Main.Exit /// - public Main_Exit L_Exit + public Exit L_Exit { get { - if (_L_Exit == null) _L_Exit = new Main_Exit(UiPanel, Instance.GetNodeOrNull("Exit")); + if (_L_Exit == null) _L_Exit = new Exit(UiPanel, Instance.GetNode("Exit")); return _L_Exit; } } - private Main_Exit _L_Exit; + private Exit _L_Exit; - public Main_ButtonList(Main uiPanel, Godot.VBoxContainer node) : base(uiPanel, node) { } - public override Main_ButtonList Clone() => new (UiPanel, (Godot.VBoxContainer)Instance.Duplicate()); + public ButtonList(MainPanel uiPanel, Godot.VBoxContainer node) : base(uiPanel, node) { } + public override ButtonList Clone() => new (UiPanel, (Godot.VBoxContainer)Instance.Duplicate()); } /// /// 类型: , 路径: Main.Version /// - public class Main_Version : UiNode + public class Version : UiNode { - public Main_Version(Main uiPanel, Godot.Label node) : base(uiPanel, node) { } - public override Main_Version Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); + public Version(MainPanel uiPanel, Godot.Label node) : base(uiPanel, node) { } + public override Version Clone() => new (UiPanel, (Godot.Label)Instance.Duplicate()); } /// + /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ColorRect + /// + public ColorRect S_ColorRect => L_ColorRect; + + /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.Title /// - public Main_Title S_Title => L_Title; + public Title S_Title => L_Title; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ButtonList.Start /// - public Main_Start S_Start => L_ButtonList.L_Start; + public Start S_Start => L_ButtonList.L_Start; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ButtonList.Tools /// - public Main_Tools S_Tools => L_ButtonList.L_Tools; + public Tools S_Tools => L_ButtonList.L_Tools; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ButtonList.Setting /// - public Main_Setting S_Setting => L_ButtonList.L_Setting; + public Setting S_Setting => L_ButtonList.L_Setting; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ButtonList.Exit /// - public Main_Exit S_Exit => L_ButtonList.L_Exit; + public Exit S_Exit => L_ButtonList.L_Exit; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.ButtonList /// - public Main_ButtonList S_ButtonList => L_ButtonList; + public ButtonList S_ButtonList => L_ButtonList; /// /// 场景中唯一名称的节点, 节点类型: , 节点路径: Main.Version /// - public Main_Version S_Version => L_Version; + public Version S_Version => L_Version; }