From 750e7860ecaab4c9a25ecc3db03ea1e9b8c148bc Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Thu, 11 Jul 2024 20:29:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/character/CharacterTemplate.cs | 67 ++++-- scripts/loader/uiLoader/MainMenuLoader.cs | 262 +++++++++++----------- scripts/utils/NodeUtils.cs | 18 +- 3 files changed, 184 insertions(+), 163 deletions(-) diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index cb7417f..10282f1 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -223,15 +223,8 @@ public partial class CharacterTemplate : CharacterBody2D return null; } - HashSet? exclude = null; - if (_currentItem != null) - { - //Prevent picking up objects in your hands again. - //防止再次捡起自己手上的物品。 - exclude = new HashSet { _currentItem }; - } - - return NodeUtils.GetTheNearestNode(this, PickingRangeBodiesList.ToArray(), exclude); + return NodeUtils.GetTheNearestNode(this, PickingRangeBodiesList.ToArray(), true, + node => !CanPickItem(node)); } @@ -308,25 +301,53 @@ public partial class CharacterTemplate : CharacterBody2D } } + /// + /// Whether you can pick up specified items + /// 是否能捡起指定物品 + /// + /// + /// + private bool CanPickItem(Node node) + { + if (_currentItem != null && node == _currentItem) + { + //Do not include your own belongings. + //不包含自己手上的物品。 + return false; + } + + if (node is PickAbleTemplate pickAbleTemplate) + { + //Does not contain items that have been picked up. + //不包含已被捡起的物品。 + return !pickAbleTemplate.Picked; + } + + return false; + } + /// /// Pick up the specified items /// 将指定物品拾起来 /// - /// + /// /// ///Whether successfully picked up ///是否成功拾起 /// - public bool PickItem(Node2D? pickAbleItem) + protected bool PickItem(Node2D? pickAbleItemNode2D) { //Empty reference checking is implicitly performed here. //此处隐式的执行了空引用检查。 - if (pickAbleItem is not IItem item) + if (pickAbleItemNode2D is not IItem item) { return false; } - if (ItemContainer == null) + + //The item store is marked null, or the item container is null. + //物品存放的标记为null,或者物品容器为null。 + if (ItemMarker2D == null || ItemContainer == null) { return false; } @@ -339,10 +360,10 @@ public partial class CharacterTemplate : CharacterBody2D return false; } - //First check if we can pick up the item. - //先检查我们能否拾起此物品。 - var canPick = ItemContainer.CanAddItem(item); - if (!canPick) + //Check to see if you can fit the item into the container first. + //先检查是否能将物品放入容器。 + var canAddItem = ItemContainer.CanAddItem(item); + if (!canAddItem) { return false; } @@ -359,7 +380,7 @@ public partial class CharacterTemplate : CharacterBody2D //设置捡起物品的常规处理。 //You can supplement picking up state handling for more types of objects here. //您可以在这里补充更多类型对象的捡起状态处理。 - if (pickAbleItem is PickAbleTemplate pickAbleTemplate) + if (pickAbleItemNode2D is PickAbleTemplate pickAbleTemplate) { pickAbleTemplate.Owner = this; pickAbleTemplate.Picked = true; @@ -374,16 +395,16 @@ public partial class CharacterTemplate : CharacterBody2D { //If the selected item slot in the item container is a newly picked item, and there is no item in the hand, then we put the selected item into the hand. //如果物品容器内选中的物品槽是刚刚捡到的物品,且手里没有物品持有,那么我们将选中的物品放到手上。 - CurrentItem = pickAbleItem; + CurrentItem = pickAbleItemNode2D; } else { - pickAbleItem.Hide(); - pickAbleItem.ProcessMode = ProcessModeEnum.Disabled; + pickAbleItemNode2D.Hide(); + pickAbleItemNode2D.ProcessMode = ProcessModeEnum.Disabled; } - pickAbleItem.Reparent(ItemMarker2D); - pickAbleItem.Position = Vector2.Zero; + NodeUtils.CallDeferredReparent(ItemMarker2D, pickAbleItemNode2D); + pickAbleItemNode2D.Position = Vector2.Zero; return true; } diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index 5c19867..ef57519 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -20,148 +20,148 @@ namespace ColdMint.scripts.loader.uiLoader; /// public partial class MainMenuLoader : UiLoaderTemplate { - private Button? _startGameButton; - private Label? _copyrightLabel; - private StringBuilder? _copyrightBuilder; - private PackedScene? _gameScene; - private PackedScene? _contributor; - private PackedScene? _levelGraphEditor; - private Label? _sloganLabel; - private Label? _versionLabel; - private Button? _levelGraphEditorButton; - private LinkButton? _contributorButton; + private Button? _startGameButton; + private Label? _copyrightLabel; + private StringBuilder? _copyrightBuilder; + private PackedScene? _gameScene; + private PackedScene? _contributor; + private PackedScene? _levelGraphEditor; + private Label? _sloganLabel; + private Label? _versionLabel; + private Button? _levelGraphEditorButton; + private LinkButton? _contributorButton; - public override void InitializeData() - { - if (Config.IsDebug()) - { - //Set the minimum log level to Info in debug mode.(Print all logs) - //在调试模式下将最小日志等级设置为Info。(打印全部日志) - LogCat.MinLogLevel = LogCat.InfoLogLevel; - } - else - { - //Disable all logs in the release version. - //在发行版禁用所有日志。 - LogCat.MinLogLevel = LogCat.DisableAllLogLevel; - } + public override void InitializeData() + { + if (Config.IsDebug()) + { + //Set the minimum log level to Info in debug mode.(Print all logs) + //在调试模式下将最小日志等级设置为Info。(打印全部日志) + LogCat.MinLogLevel = LogCat.InfoLogLevel; + } + else + { + //Disable all logs in the release version. + //在发行版禁用所有日志。 + LogCat.MinLogLevel = LogCat.DisableAllLogLevel; + } - ContributorDataManager.RegisterAllContributorData(); - DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); - MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); - MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); - //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package - //注册对应的编码提供程序,解决压缩包中文路径乱码问题 - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - //创建游戏数据文件夹 - var dataPath = Config.GetGameDataDirectory(); - if (!Directory.Exists(dataPath)) - { - Directory.CreateDirectory(dataPath); - } + ContributorDataManager.RegisterAllContributorData(); + DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); + MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); + MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); + //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package + //注册对应的编码提供程序,解决压缩包中文路径乱码问题 + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //创建游戏数据文件夹 + var dataPath = Config.GetGameDataDirectory(); + if (!Directory.Exists(dataPath)) + { + Directory.CreateDirectory(dataPath); + } - //Registered camp - //注册阵营 - var defaultCamp = new Camp(Config.CampId.Default) - { - FriendInjury = true - }; - CampManager.SetDefaultCamp(defaultCamp); - var mazoku = new Camp(Config.CampId.Mazoku); - CampManager.AddCamp(mazoku); - var aborigines = new Camp(Config.CampId.Aborigines); - CampManager.AddCamp(aborigines); - _gameScene = GD.Load("res://scenes/game.tscn"); - _contributor = GD.Load("res://scenes/contributor.tscn"); - _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); + //Registered camp + //注册阵营 + var defaultCamp = new Camp(Config.CampId.Default) + { + FriendInjury = true + }; + CampManager.SetDefaultCamp(defaultCamp); + var mazoku = new Camp(Config.CampId.Mazoku); + CampManager.AddCamp(mazoku); + var aborigines = new Camp(Config.CampId.Aborigines); + CampManager.AddCamp(aborigines); + _gameScene = GD.Load("res://scenes/game.tscn"); + _contributor = GD.Load("res://scenes/contributor.tscn"); + _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); - //Register ItemTypes from file - //从文件注册物品类型 - ItemTypeRegister.RegisterFromFile(); - //Hardcoded ItemTypes Register - //硬编码注册物品类型 - ItemTypeRegister.StaticRegister(); + //Register ItemTypes from file + //从文件注册物品类型 + ItemTypeRegister.RegisterFromFile(); + //Hardcoded ItemTypes Register + //硬编码注册物品类型 + ItemTypeRegister.StaticRegister(); - //静态注册掉落表 - LootRegister.StaticRegister(); - } + //静态注册掉落表 + LootRegister.StaticRegister(); + } - public override void InitializeUi() - { - _contributorButton = GetNode("VBoxContainer2/ContributorButton"); - _startGameButton = GetNode