临时保存
This commit is contained in:
parent
61618c13a9
commit
750e7860ec
|
@ -223,15 +223,8 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Node>? exclude = null;
|
return NodeUtils.GetTheNearestNode(this, PickingRangeBodiesList.ToArray(), true,
|
||||||
if (_currentItem != null)
|
node => !CanPickItem(node));
|
||||||
{
|
|
||||||
//Prevent picking up objects in your hands again.
|
|
||||||
//防止再次捡起自己手上的物品。
|
|
||||||
exclude = new HashSet<Node> { _currentItem };
|
|
||||||
}
|
|
||||||
|
|
||||||
return NodeUtils.GetTheNearestNode(this, PickingRangeBodiesList.ToArray(), exclude);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,25 +301,53 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Whether you can pick up specified items</para>
|
||||||
|
/// <para>是否能捡起指定物品</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="node"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Pick up the specified items</para>
|
/// <para>Pick up the specified items</para>
|
||||||
/// <para>将指定物品拾起来</para>
|
/// <para>将指定物品拾起来</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pickAbleItem"></param>
|
/// <param name="pickAbleItemNode2D"></param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///<para>Whether successfully picked up</para>
|
///<para>Whether successfully picked up</para>
|
||||||
///<para>是否成功拾起</para>
|
///<para>是否成功拾起</para>
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool PickItem(Node2D? pickAbleItem)
|
protected bool PickItem(Node2D? pickAbleItemNode2D)
|
||||||
{
|
{
|
||||||
//Empty reference checking is implicitly performed here.
|
//Empty reference checking is implicitly performed here.
|
||||||
//此处隐式的执行了空引用检查。
|
//此处隐式的执行了空引用检查。
|
||||||
if (pickAbleItem is not IItem item)
|
if (pickAbleItemNode2D is not IItem item)
|
||||||
{
|
{
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -339,10 +360,10 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//First check if we can pick up the item.
|
//Check to see if you can fit the item into the container first.
|
||||||
//先检查我们能否拾起此物品。
|
//先检查是否能将物品放入容器。
|
||||||
var canPick = ItemContainer.CanAddItem(item);
|
var canAddItem = ItemContainer.CanAddItem(item);
|
||||||
if (!canPick)
|
if (!canAddItem)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -359,7 +380,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
//设置捡起物品的常规处理。
|
//设置捡起物品的常规处理。
|
||||||
//You can supplement picking up state handling for more types of objects here.
|
//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.Owner = this;
|
||||||
pickAbleTemplate.Picked = true;
|
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.
|
//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
|
else
|
||||||
{
|
{
|
||||||
pickAbleItem.Hide();
|
pickAbleItemNode2D.Hide();
|
||||||
pickAbleItem.ProcessMode = ProcessModeEnum.Disabled;
|
pickAbleItemNode2D.ProcessMode = ProcessModeEnum.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
pickAbleItem.Reparent(ItemMarker2D);
|
NodeUtils.CallDeferredReparent(ItemMarker2D, pickAbleItemNode2D);
|
||||||
pickAbleItem.Position = Vector2.Zero;
|
pickAbleItemNode2D.Position = Vector2.Zero;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,148 +20,148 @@ namespace ColdMint.scripts.loader.uiLoader;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainMenuLoader : UiLoaderTemplate
|
public partial class MainMenuLoader : UiLoaderTemplate
|
||||||
{
|
{
|
||||||
private Button? _startGameButton;
|
private Button? _startGameButton;
|
||||||
private Label? _copyrightLabel;
|
private Label? _copyrightLabel;
|
||||||
private StringBuilder? _copyrightBuilder;
|
private StringBuilder? _copyrightBuilder;
|
||||||
private PackedScene? _gameScene;
|
private PackedScene? _gameScene;
|
||||||
private PackedScene? _contributor;
|
private PackedScene? _contributor;
|
||||||
private PackedScene? _levelGraphEditor;
|
private PackedScene? _levelGraphEditor;
|
||||||
private Label? _sloganLabel;
|
private Label? _sloganLabel;
|
||||||
private Label? _versionLabel;
|
private Label? _versionLabel;
|
||||||
private Button? _levelGraphEditorButton;
|
private Button? _levelGraphEditorButton;
|
||||||
private LinkButton? _contributorButton;
|
private LinkButton? _contributorButton;
|
||||||
|
|
||||||
public override void InitializeData()
|
public override void InitializeData()
|
||||||
{
|
{
|
||||||
if (Config.IsDebug())
|
if (Config.IsDebug())
|
||||||
{
|
{
|
||||||
//Set the minimum log level to Info in debug mode.(Print all logs)
|
//Set the minimum log level to Info in debug mode.(Print all logs)
|
||||||
//在调试模式下将最小日志等级设置为Info。(打印全部日志)
|
//在调试模式下将最小日志等级设置为Info。(打印全部日志)
|
||||||
LogCat.MinLogLevel = LogCat.InfoLogLevel;
|
LogCat.MinLogLevel = LogCat.InfoLogLevel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Disable all logs in the release version.
|
//Disable all logs in the release version.
|
||||||
//在发行版禁用所有日志。
|
//在发行版禁用所有日志。
|
||||||
LogCat.MinLogLevel = LogCat.DisableAllLogLevel;
|
LogCat.MinLogLevel = LogCat.DisableAllLogLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContributorDataManager.RegisterAllContributorData();
|
ContributorDataManager.RegisterAllContributorData();
|
||||||
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
||||||
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
||||||
MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor());
|
MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor());
|
||||||
//Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package
|
//Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package
|
||||||
//注册对应的编码提供程序,解决压缩包中文路径乱码问题
|
//注册对应的编码提供程序,解决压缩包中文路径乱码问题
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
//创建游戏数据文件夹
|
//创建游戏数据文件夹
|
||||||
var dataPath = Config.GetGameDataDirectory();
|
var dataPath = Config.GetGameDataDirectory();
|
||||||
if (!Directory.Exists(dataPath))
|
if (!Directory.Exists(dataPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dataPath);
|
Directory.CreateDirectory(dataPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Registered camp
|
//Registered camp
|
||||||
//注册阵营
|
//注册阵营
|
||||||
var defaultCamp = new Camp(Config.CampId.Default)
|
var defaultCamp = new Camp(Config.CampId.Default)
|
||||||
{
|
{
|
||||||
FriendInjury = true
|
FriendInjury = true
|
||||||
};
|
};
|
||||||
CampManager.SetDefaultCamp(defaultCamp);
|
CampManager.SetDefaultCamp(defaultCamp);
|
||||||
var mazoku = new Camp(Config.CampId.Mazoku);
|
var mazoku = new Camp(Config.CampId.Mazoku);
|
||||||
CampManager.AddCamp(mazoku);
|
CampManager.AddCamp(mazoku);
|
||||||
var aborigines = new Camp(Config.CampId.Aborigines);
|
var aborigines = new Camp(Config.CampId.Aborigines);
|
||||||
CampManager.AddCamp(aborigines);
|
CampManager.AddCamp(aborigines);
|
||||||
_gameScene = GD.Load<PackedScene>("res://scenes/game.tscn");
|
_gameScene = GD.Load<PackedScene>("res://scenes/game.tscn");
|
||||||
_contributor = GD.Load<PackedScene>("res://scenes/contributor.tscn");
|
_contributor = GD.Load<PackedScene>("res://scenes/contributor.tscn");
|
||||||
_levelGraphEditor = GD.Load<PackedScene>("res://scenes/levelGraphEditor.tscn");
|
_levelGraphEditor = GD.Load<PackedScene>("res://scenes/levelGraphEditor.tscn");
|
||||||
|
|
||||||
//Register ItemTypes from file
|
//Register ItemTypes from file
|
||||||
//从文件注册物品类型
|
//从文件注册物品类型
|
||||||
ItemTypeRegister.RegisterFromFile();
|
ItemTypeRegister.RegisterFromFile();
|
||||||
//Hardcoded ItemTypes Register
|
//Hardcoded ItemTypes Register
|
||||||
//硬编码注册物品类型
|
//硬编码注册物品类型
|
||||||
ItemTypeRegister.StaticRegister();
|
ItemTypeRegister.StaticRegister();
|
||||||
|
|
||||||
//静态注册掉落表
|
//静态注册掉落表
|
||||||
LootRegister.StaticRegister();
|
LootRegister.StaticRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitializeUi()
|
public override void InitializeUi()
|
||||||
{
|
{
|
||||||
_contributorButton = GetNode<LinkButton>("VBoxContainer2/ContributorButton");
|
_contributorButton = GetNode<LinkButton>("VBoxContainer2/ContributorButton");
|
||||||
_startGameButton = GetNode<Button>("StartGameButton");
|
_startGameButton = GetNode<Button>("StartGameButton");
|
||||||
_levelGraphEditorButton = GetNode<Button>("levelGraphEditorButton");
|
_levelGraphEditorButton = GetNode<Button>("levelGraphEditorButton");
|
||||||
//The level map editor is only available in debug mode.
|
//The level map editor is only available in debug mode.
|
||||||
//关卡图编辑器仅在调试模式可用。
|
//关卡图编辑器仅在调试模式可用。
|
||||||
_levelGraphEditorButton.Visible = Config.IsDebug();
|
_levelGraphEditorButton.Visible = Config.IsDebug();
|
||||||
_startGameButton.GrabFocus();
|
_startGameButton.GrabFocus();
|
||||||
_versionLabel = GetNode<Label>("VBoxContainer2/VersionLabel");
|
_versionLabel = GetNode<Label>("VBoxContainer2/VersionLabel");
|
||||||
//Generative copyright
|
//Generative copyright
|
||||||
//生成版权
|
//生成版权
|
||||||
_copyrightLabel = GetNode<Label>("VBoxContainer/CopyrightLabel");
|
_copyrightLabel = GetNode<Label>("VBoxContainer/CopyrightLabel");
|
||||||
_sloganLabel = GetNode<Label>("CenterContainer2/SloganLabel");
|
_sloganLabel = GetNode<Label>("CenterContainer2/SloganLabel");
|
||||||
_copyrightBuilder = new StringBuilder();
|
_copyrightBuilder = new StringBuilder();
|
||||||
_copyrightBuilder.Append('\u00a9');
|
_copyrightBuilder.Append('\u00a9');
|
||||||
var currentYear = DateTime.Now.Year;
|
var currentYear = DateTime.Now.Year;
|
||||||
_copyrightBuilder.Append(Config.CreationYear);
|
_copyrightBuilder.Append(Config.CreationYear);
|
||||||
if (currentYear != Config.CreationYear)
|
if (currentYear != Config.CreationYear)
|
||||||
{
|
{
|
||||||
_copyrightBuilder.Append('-');
|
_copyrightBuilder.Append('-');
|
||||||
_copyrightBuilder.Append(currentYear);
|
_copyrightBuilder.Append(currentYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
_copyrightBuilder.Append(' ');
|
_copyrightBuilder.Append(' ');
|
||||||
_copyrightBuilder.Append(Config.CompanyName);
|
_copyrightBuilder.Append(Config.CompanyName);
|
||||||
_copyrightBuilder.Append(" all rights reserved.");
|
_copyrightBuilder.Append(" all rights reserved.");
|
||||||
_copyrightLabel.Text = _copyrightBuilder.ToString();
|
_copyrightLabel.Text = _copyrightBuilder.ToString();
|
||||||
_versionLabel.Text = "ver." + Config.GetVersion();
|
_versionLabel.Text = "ver." + Config.GetVersion();
|
||||||
_sloganLabel.Text = SloganProvider.GetSlogan();
|
_sloganLabel.Text = SloganProvider.GetSlogan();
|
||||||
_contributorButton.Text =
|
_contributorButton.Text =
|
||||||
TranslationServerUtils.TranslateWithFormat("ui_contributor_tips",
|
TranslationServerUtils.TranslateWithFormat("ui_contributor_tips",
|
||||||
ContributorDataManager.GetContributorTotals());
|
ContributorDataManager.GetContributorTotals());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadUiActions()
|
public override void LoadUiActions()
|
||||||
{
|
{
|
||||||
if (_startGameButton != null)
|
if (_startGameButton != null)
|
||||||
{
|
{
|
||||||
_startGameButton.Pressed += () =>
|
_startGameButton.Pressed += () =>
|
||||||
{
|
{
|
||||||
if (_gameScene == null)
|
if (_gameScene == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetTree().ChangeSceneToPacked(_gameScene);
|
GetTree().ChangeSceneToPacked(_gameScene);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_contributorButton != null)
|
if (_contributorButton != null)
|
||||||
{
|
{
|
||||||
_contributorButton.Pressed += () =>
|
_contributorButton.Pressed += () =>
|
||||||
{
|
{
|
||||||
if (_contributor == null)
|
if (_contributor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetTree().ChangeSceneToPacked(_contributor);
|
GetTree().ChangeSceneToPacked(_contributor);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_levelGraphEditorButton != null)
|
if (_levelGraphEditorButton != null)
|
||||||
{
|
{
|
||||||
_levelGraphEditorButton.Pressed += () =>
|
_levelGraphEditorButton.Pressed += () =>
|
||||||
{
|
{
|
||||||
LogCat.Log("level_graph_editor");
|
LogCat.Log("level_graph_editor");
|
||||||
if (_levelGraphEditor == null)
|
if (_levelGraphEditor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetTree().ChangeSceneToPacked(_levelGraphEditor);
|
GetTree().ChangeSceneToPacked(_levelGraphEditor);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,17 +175,17 @@ public static class NodeUtils
|
||||||
///<para>Node array</para>
|
///<para>Node array</para>
|
||||||
///<para>节点数组</para>
|
///<para>节点数组</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="exclude">
|
|
||||||
///<para>Which nodes are excluded</para>
|
|
||||||
///<para>排除哪些节点</para>
|
|
||||||
/// </param>
|
|
||||||
/// <param name="excludeInvisibleNodes">
|
/// <param name="excludeInvisibleNodes">
|
||||||
///<para>Whether or not unseen nodes should be excluded</para>
|
///<para>Whether or not unseen nodes should be excluded</para>
|
||||||
///<para>是否排除不可见的节点</para>
|
///<para>是否排除不可见的节点</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
|
/// <param name="filter">
|
||||||
|
///<para>Filter, which returns true within the function to filter the specified node.</para>
|
||||||
|
///<para>过滤器,在函数内返回true,则过滤指定节点。</para>
|
||||||
|
/// </param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Node2D? GetTheNearestNode(Node2D origin, Node[] array, HashSet<Node>? exclude = null,
|
public static Node2D? GetTheNearestNode(Node2D origin, Node[] array,
|
||||||
bool excludeInvisibleNodes = true)
|
bool excludeInvisibleNodes = true, Func<Node2D, bool>? filter = null)
|
||||||
{
|
{
|
||||||
var closestDistance = float.MaxValue;
|
var closestDistance = float.MaxValue;
|
||||||
Node2D? closestNode = null;
|
Node2D? closestNode = null;
|
||||||
|
@ -199,10 +199,10 @@ public static class NodeUtils
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exclude != null && exclude.Contains(node))
|
if (filter != null && filter.Invoke(node2D))
|
||||||
{
|
{
|
||||||
//If the current node, is within our exclusion project. So the next one.
|
//If there is a filter, and the filter returns true, then the next.
|
||||||
//如果当前节点,在我们的排除项目内。那么下一个。
|
//如果有过滤器,且过滤器返回true,那么下一个。
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user