临时保存

This commit is contained in:
Cold-Mint 2024-07-11 20:29:04 +08:00
parent 61618c13a9
commit 750e7860ec
3 changed files with 184 additions and 163 deletions

View File

@ -223,15 +223,8 @@ public partial class CharacterTemplate : CharacterBody2D
return null;
}
HashSet<Node>? exclude = null;
if (_currentItem != null)
{
//Prevent picking up objects in your hands again.
//防止再次捡起自己手上的物品。
exclude = new HashSet<Node> { _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
}
}
/// <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>
/// <para>Pick up the specified items</para>
/// <para>将指定物品拾起来</para>
/// </summary>
/// <param name="pickAbleItem"></param>
/// <param name="pickAbleItemNode2D"></param>
/// <returns>
///<para>Whether successfully picked up</para>
///<para>是否成功拾起</para>
/// </returns>
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;
}

View File

@ -20,148 +20,148 @@ namespace ColdMint.scripts.loader.uiLoader;
/// </summary>
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<PackedScene>("res://scenes/game.tscn");
_contributor = GD.Load<PackedScene>("res://scenes/contributor.tscn");
_levelGraphEditor = GD.Load<PackedScene>("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<PackedScene>("res://scenes/game.tscn");
_contributor = GD.Load<PackedScene>("res://scenes/contributor.tscn");
_levelGraphEditor = GD.Load<PackedScene>("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<LinkButton>("VBoxContainer2/ContributorButton");
_startGameButton = GetNode<Button>("StartGameButton");
_levelGraphEditorButton = GetNode<Button>("levelGraphEditorButton");
//The level map editor is only available in debug mode.
//关卡图编辑器仅在调试模式可用。
_levelGraphEditorButton.Visible = Config.IsDebug();
_startGameButton.GrabFocus();
_versionLabel = GetNode<Label>("VBoxContainer2/VersionLabel");
//Generative copyright
//生成版权
_copyrightLabel = GetNode<Label>("VBoxContainer/CopyrightLabel");
_sloganLabel = GetNode<Label>("CenterContainer2/SloganLabel");
_copyrightBuilder = new StringBuilder();
_copyrightBuilder.Append('\u00a9');
var currentYear = DateTime.Now.Year;
_copyrightBuilder.Append(Config.CreationYear);
if (currentYear != Config.CreationYear)
{
_copyrightBuilder.Append('-');
_copyrightBuilder.Append(currentYear);
}
public override void InitializeUi()
{
_contributorButton = GetNode<LinkButton>("VBoxContainer2/ContributorButton");
_startGameButton = GetNode<Button>("StartGameButton");
_levelGraphEditorButton = GetNode<Button>("levelGraphEditorButton");
//The level map editor is only available in debug mode.
//关卡图编辑器仅在调试模式可用。
_levelGraphEditorButton.Visible = Config.IsDebug();
_startGameButton.GrabFocus();
_versionLabel = GetNode<Label>("VBoxContainer2/VersionLabel");
//Generative copyright
//生成版权
_copyrightLabel = GetNode<Label>("VBoxContainer/CopyrightLabel");
_sloganLabel = GetNode<Label>("CenterContainer2/SloganLabel");
_copyrightBuilder = new StringBuilder();
_copyrightBuilder.Append('\u00a9');
var currentYear = DateTime.Now.Year;
_copyrightBuilder.Append(Config.CreationYear);
if (currentYear != Config.CreationYear)
{
_copyrightBuilder.Append('-');
_copyrightBuilder.Append(currentYear);
}
_copyrightBuilder.Append(' ');
_copyrightBuilder.Append(Config.CompanyName);
_copyrightBuilder.Append(" all rights reserved.");
_copyrightLabel.Text = _copyrightBuilder.ToString();
_versionLabel.Text = "ver." + Config.GetVersion();
_sloganLabel.Text = SloganProvider.GetSlogan();
_contributorButton.Text =
TranslationServerUtils.TranslateWithFormat("ui_contributor_tips",
ContributorDataManager.GetContributorTotals());
}
_copyrightBuilder.Append(' ');
_copyrightBuilder.Append(Config.CompanyName);
_copyrightBuilder.Append(" all rights reserved.");
_copyrightLabel.Text = _copyrightBuilder.ToString();
_versionLabel.Text = "ver." + Config.GetVersion();
_sloganLabel.Text = SloganProvider.GetSlogan();
_contributorButton.Text =
TranslationServerUtils.TranslateWithFormat("ui_contributor_tips",
ContributorDataManager.GetContributorTotals());
}
public override void LoadUiActions()
{
if (_startGameButton != null)
{
_startGameButton.Pressed += () =>
{
if (_gameScene == null)
{
return;
}
public override void LoadUiActions()
{
if (_startGameButton != null)
{
_startGameButton.Pressed += () =>
{
if (_gameScene == null)
{
return;
}
GetTree().ChangeSceneToPacked(_gameScene);
};
}
GetTree().ChangeSceneToPacked(_gameScene);
};
}
if (_contributorButton != null)
{
_contributorButton.Pressed += () =>
{
if (_contributor == null)
{
return;
}
if (_contributorButton != null)
{
_contributorButton.Pressed += () =>
{
if (_contributor == null)
{
return;
}
GetTree().ChangeSceneToPacked(_contributor);
};
}
GetTree().ChangeSceneToPacked(_contributor);
};
}
if (_levelGraphEditorButton != null)
{
_levelGraphEditorButton.Pressed += () =>
{
LogCat.Log("level_graph_editor");
if (_levelGraphEditor == null)
{
return;
}
if (_levelGraphEditorButton != null)
{
_levelGraphEditorButton.Pressed += () =>
{
LogCat.Log("level_graph_editor");
if (_levelGraphEditor == null)
{
return;
}
GetTree().ChangeSceneToPacked(_levelGraphEditor);
};
}
}
}
GetTree().ChangeSceneToPacked(_levelGraphEditor);
};
}
}
}

View File

@ -175,17 +175,17 @@ public static class NodeUtils
///<para>Node array</para>
///<para>节点数组</para>
/// </param>
/// <param name="exclude">
///<para>Which nodes are excluded</para>
///<para>排除哪些节点</para>
/// </param>
/// <param name="excludeInvisibleNodes">
///<para>Whether or not unseen nodes should be excluded</para>
///<para>是否排除不可见的节点</para>
/// </param>
/// <param name="filter">
///<para>Filter, which returns true within the function to filter the specified node.</para>
///<para>过滤器在函数内返回true则过滤指定节点。</para>
/// </param>
/// <returns></returns>
public static Node2D? GetTheNearestNode(Node2D origin, Node[] array, HashSet<Node>? exclude = null,
bool excludeInvisibleNodes = true)
public static Node2D? GetTheNearestNode(Node2D origin, Node[] array,
bool excludeInvisibleNodes = true, Func<Node2D, bool>? filter = null)
{
var closestDistance = float.MaxValue;
Node2D? closestNode = null;
@ -199,10 +199,10 @@ public static class NodeUtils
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;
}