2024-05-07 09:38:50 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using ColdMint.scripts.inventory;
|
|
|
|
|
using ColdMint.scripts.map;
|
2024-10-17 08:08:21 +00:00
|
|
|
|
using ColdMint.scripts.map.events;
|
2024-05-19 14:32:34 +00:00
|
|
|
|
using ColdMint.scripts.map.LayoutParsingStrategy;
|
|
|
|
|
using ColdMint.scripts.map.layoutStrategy;
|
2024-09-06 14:56:36 +00:00
|
|
|
|
using ColdMint.scripts.map.miniMap;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using ColdMint.scripts.map.RoomPlacer;
|
2024-05-21 14:50:33 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.loader.sceneLoader;
|
|
|
|
|
|
2024-06-05 14:15:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Game scene loader</para>
|
|
|
|
|
/// <para>游戏场景加载器</para>
|
|
|
|
|
/// </summary>
|
2024-04-28 13:55:19 +00:00
|
|
|
|
public partial class GameSceneLoader : SceneLoaderTemplate
|
|
|
|
|
{
|
2024-05-23 13:58:49 +00:00
|
|
|
|
private Label? _seedLabel;
|
|
|
|
|
|
2024-05-07 11:36:06 +00:00
|
|
|
|
public override Task InitializeData()
|
2024-05-07 09:38:50 +00:00
|
|
|
|
{
|
2024-08-24 14:49:59 +00:00
|
|
|
|
RenderingServer.SetDefaultClearColor(Color.FromHsv(0, 0, 0));
|
2024-05-31 14:26:38 +00:00
|
|
|
|
//Loading the blood bar scene
|
2024-05-07 09:38:50 +00:00
|
|
|
|
//加载血条场景
|
2024-05-07 11:36:06 +00:00
|
|
|
|
var healthBarUi = GetNode<HealthBarUi>("CanvasLayer/Control/VBoxContainer/HealthBarUi");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.HealthBarUi = healthBarUi;
|
2024-05-31 14:26:38 +00:00
|
|
|
|
//Load HotBar
|
2024-05-07 09:38:50 +00:00
|
|
|
|
//加载HotBar
|
|
|
|
|
var hotBar = GetNode<HotBar>("CanvasLayer/Control/VBoxContainer/HotBar");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.HotBar = hotBar;
|
2024-06-16 12:18:44 +00:00
|
|
|
|
//Backpack Ui container
|
|
|
|
|
//背包Ui容器
|
2024-09-18 12:20:02 +00:00
|
|
|
|
var backpackUiContainer = GetNode<UiGroup>("CanvasLayer/DynamicUiGroup");
|
|
|
|
|
GameSceneDepend.DynamicUiGroup = backpackUiContainer;
|
2024-05-31 14:26:38 +00:00
|
|
|
|
//Loaded weapon container
|
2024-05-07 09:38:50 +00:00
|
|
|
|
//加载武器容器
|
|
|
|
|
var weaponContainer = GetNode<Node2D>("WeaponContainer");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.WeaponContainer = weaponContainer;
|
2024-07-24 13:03:24 +00:00
|
|
|
|
//Load projectile container
|
|
|
|
|
//加载抛射体容器
|
|
|
|
|
var projectileContainer = GetNode<Node2D>("ProjectileContainer");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.ProjectileContainer = projectileContainer;
|
2024-10-04 12:53:34 +00:00
|
|
|
|
//Load magic container
|
|
|
|
|
//加载魔术容器
|
2024-10-05 01:13:14 +00:00
|
|
|
|
var magicContainer = GetNode<Node2D>("SpellContainer");
|
|
|
|
|
GameSceneDepend.SpellContainer = magicContainer;
|
2024-06-12 15:42:35 +00:00
|
|
|
|
//Load Packsack container
|
|
|
|
|
//加载背包容器
|
|
|
|
|
var packsackContainer = GetNode<Node2D>("PacksackContainer");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.PacksackContainer = packsackContainer;
|
2024-06-03 14:58:59 +00:00
|
|
|
|
//Load AICharacter container
|
|
|
|
|
//加载AICharacter容器
|
|
|
|
|
var aiCharacterContainer = GetNode<Node2D>("AICharacterContainer");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.AiCharacterContainer = aiCharacterContainer;
|
2024-05-31 14:26:38 +00:00
|
|
|
|
//Load player container
|
|
|
|
|
//加载玩家容器
|
|
|
|
|
var playerContainer = GetNode<Node2D>("PlayerContainer");
|
2024-09-01 15:24:35 +00:00
|
|
|
|
GameSceneDepend.PlayerContainer = playerContainer;
|
2024-10-06 04:04:59 +00:00
|
|
|
|
//Load the pickable container
|
|
|
|
|
//加载可拾捡物容器
|
|
|
|
|
var pickAbleContainer = GetNode<Node2D>("PickAbleContainer");
|
|
|
|
|
GameSceneDepend.PickAbleContainer = pickAbleContainer;
|
2024-09-06 14:56:36 +00:00
|
|
|
|
//Setting up the mini map
|
|
|
|
|
//设置迷你地图
|
2024-10-09 02:21:26 +00:00
|
|
|
|
var miniMap = GetNode<MiniMap>("CanvasLayer/Control/MapContainer/Control/MiniMap");
|
2024-09-06 14:56:36 +00:00
|
|
|
|
GameSceneDepend.MiniMap = miniMap;
|
2024-10-09 02:21:26 +00:00
|
|
|
|
//Set the mini map animation
|
|
|
|
|
//设置迷你地图动画
|
|
|
|
|
var miniMapAnimationPlayer = GetNode<AnimationPlayer>("CanvasLayer/Control/MapContainer/MiniMapAnimationPlayer");
|
|
|
|
|
GameSceneDepend.MiniMapAnimationPlayer = miniMapAnimationPlayer;
|
2024-05-07 11:36:06 +00:00
|
|
|
|
return Task.CompletedTask;
|
2024-05-07 09:38:50 +00:00
|
|
|
|
}
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
2024-05-07 09:38:50 +00:00
|
|
|
|
public override async Task LoadScene()
|
|
|
|
|
{
|
2024-05-23 13:58:49 +00:00
|
|
|
|
var debugMode = Config.IsDebug();
|
|
|
|
|
var recreateMapButton = GetNodeOrNull<Button>("CanvasLayer/Control/RecreateMapButton");
|
|
|
|
|
if (recreateMapButton != null)
|
|
|
|
|
{
|
|
|
|
|
recreateMapButton.Visible = debugMode;
|
|
|
|
|
recreateMapButton.Pressed += () => { _ = GenerateMap(); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_seedLabel = GetNodeOrNull<Label>("CanvasLayer/Control/SeedLabel");
|
|
|
|
|
if (_seedLabel != null)
|
|
|
|
|
{
|
2024-06-05 14:15:23 +00:00
|
|
|
|
_seedLabel.Visible = debugMode;
|
2024-05-23 13:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:38:41 +00:00
|
|
|
|
MapGenerator.MapRoot = GetNode<Node>("MapRoot");
|
2024-05-19 14:32:34 +00:00
|
|
|
|
MapGenerator.LayoutStrategy = new TestLayoutStrategy();
|
|
|
|
|
MapGenerator.LayoutParsingStrategy = new SequenceLayoutParsingStrategy();
|
2024-05-20 14:38:41 +00:00
|
|
|
|
MapGenerator.RoomPlacementStrategy = new PatchworkRoomPlacementStrategy();
|
2024-10-17 08:08:21 +00:00
|
|
|
|
EventBus.GameOverEvent += OnGameOverEvent;
|
2024-05-23 13:58:49 +00:00
|
|
|
|
await GenerateMap();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 08:08:21 +00:00
|
|
|
|
private async void OnGameOverEvent(GameOverEvent gameOverEvent)
|
|
|
|
|
{
|
|
|
|
|
if (GameSceneDepend.WeaponContainer != null)
|
|
|
|
|
{
|
|
|
|
|
NodeUtils.DeleteAllChild(GameSceneDepend.WeaponContainer);
|
|
|
|
|
}
|
|
|
|
|
if (GameSceneDepend.PacksackContainer != null)
|
|
|
|
|
{
|
|
|
|
|
NodeUtils.DeleteAllChild(GameSceneDepend.PacksackContainer);
|
|
|
|
|
}
|
|
|
|
|
if (GameSceneDepend.SpellContainer != null)
|
|
|
|
|
{
|
|
|
|
|
NodeUtils.DeleteAllChild(GameSceneDepend.SpellContainer);
|
|
|
|
|
}
|
|
|
|
|
await GenerateMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
|
{
|
|
|
|
|
EventBus.GameOverEvent -= OnGameOverEvent;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 13:58:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Generate map</para>
|
|
|
|
|
/// <para>生成地图</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task GenerateMap()
|
|
|
|
|
{
|
2024-05-25 16:02:00 +00:00
|
|
|
|
MapGenerator.Seed = GuidUtils.GetGuid();
|
2024-05-23 13:58:49 +00:00
|
|
|
|
if (_seedLabel != null)
|
|
|
|
|
{
|
|
|
|
|
//If you have a seedLabel, then set the seed to it.
|
|
|
|
|
//如果有seedLabel,那么将种子设置上去。
|
2024-06-13 16:12:06 +00:00
|
|
|
|
var seedInfo = TranslationServerUtils.TranslateWithFormat("ui_seed_info", MapGenerator.Seed);
|
2024-06-05 14:15:23 +00:00
|
|
|
|
_seedLabel.Text = seedInfo ?? $"Seed: {MapGenerator.Seed}";
|
2024-05-23 13:58:49 +00:00
|
|
|
|
}
|
2024-09-01 15:24:35 +00:00
|
|
|
|
|
2024-05-20 14:38:41 +00:00
|
|
|
|
await MapGenerator.GenerateMap();
|
2024-05-07 09:38:50 +00:00
|
|
|
|
}
|
2024-09-01 15:24:35 +00:00
|
|
|
|
}
|