diff --git a/LICENSE_JP b/LICENSE_JA
similarity index 100%
rename from LICENSE_JP
rename to LICENSE_JA
diff --git a/README.md b/README.md
index 9e29c12..f0952d6 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
[![Star History Chart](https://api.star-history.com/svg?repos=Cold-Mint/Traveller&type=Date)](https://star-history.com/#Cold-Mint/Traveller&Date)
-English [简体中文](README_ZH.md) [にほんご](README_JP.md)
+English [简体中文](README_ZH.md) [にほんご](README_JA.md)
## Intro
@@ -13,8 +13,8 @@ A pixel cross-platform roguelite game.
| Task | status |
| ----------------------------------------------------------- | ------------------ |
| Randomly generated map | complete |
-| loot | In progress |
-| Support still out of the knapsack system | await |
+| loot | complete |
+| Support still out of the knapsack system | In progress |
| Add AI agents to creatures | await |
## Screenshot
diff --git a/README_JP.md b/README_JA.md
similarity index 94%
rename from README_JP.md
rename to README_JA.md
index b7f5240..ad8205a 100644
--- a/README_JP.md
+++ b/README_JA.md
@@ -13,8 +13,8 @@
| ミッション | じょうたい |
| ----------------------------------------------------------- | ------------------ |
| マップをランダムに生成します | 成し遂げる |
-| 戦利品 | 進行中です |
-| バックパックのシステムをサポートしています | すたんばい |
+| 戦利品 | 成し遂げる |
+| バックパックのシステムをサポートしています | 進行中です |
| 生物にAIエージェントを追加します | すたんばい |
## スクリーンショットです
@@ -50,7 +50,7 @@ git clone https://github.com/Cold-Mint/Traveller.git
[GPL-3.0 license](LICENSE)
-プロトコルの日本語訳を見ます:[GPL-3.0 license にほんご](LICENSE_JP)
+プロトコルの日本語訳を見ます:[GPL-3.0 license にほんご](LICENSE_JA)
商用に対応しており、誰でも修正、構築、販売、無料配布が可能です。このプロジェクトのすべての派生バージョンについて、GPLプロトコルに基づいて、あなたは**作者の著作権**を保持し、**ソースコードの修正を公開します**。
diff --git a/README_ZH.md b/README_ZH.md
index 787780d..bab1dc0 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -1,6 +1,6 @@
[![Star History Chart](https://api.star-history.com/svg?repos=Cold-Mint/Traveller&type=Date)](https://star-history.com/#Cold-Mint/Traveller&Date)
-[English](README.md) 简体中文 [にほんご](README_JP.md)
+[English](README.md) 简体中文 [にほんご](README_JA.md)
## 简介
@@ -10,11 +10,11 @@
## 近期研发进度
-| 任务 | 状态 |
-| ----------------------------------------------------------- | ------------------ |
-| 随机生成地图 | 完成 |
-| 战利品 | 进行中 |
-| 支持仍出的背包系统 | 等待 |
+| 任务 | 状态 |
+| ----------------------------------------------------------- |----|
+| 随机生成地图 | 完成 |
+| 战利品 | 完成 |
+| 支持仍出的背包系统 | 进行中 |
| 为生物添加AI代理 | 等待 |
## 屏幕截图
diff --git a/project.godot b/project.godot
index e991cd5..74595e4 100644
--- a/project.godot
+++ b/project.godot
@@ -161,7 +161,3 @@ locale/translations=PackedStringArray("res://locals/DeathInfo.en.translation", "
[physics]
2d/default_gravity=480.0
-
-[rendering]
-
-renderer/rendering_method="mobile"
diff --git a/scripts/inventory/HotBar.cs b/scripts/inventory/HotBar.cs
index 1bc88ed..08c4315 100644
--- a/scripts/inventory/HotBar.cs
+++ b/scripts/inventory/HotBar.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using ColdMint.scripts.character;
using ColdMint.scripts.utils;
using Godot;
@@ -8,87 +8,24 @@ namespace ColdMint.scripts.inventory;
/// HotBar
/// 快捷物品栏
///
-public partial class HotBar : HBoxContainer, IItemContainer
+public partial class HotBar : HBoxContainer
{
- private PackedScene? _itemSlotPackedScene;
-
- private List? _itemSlotNodes;
-
- ///
- /// UnknownIndex
- /// 未知位置
- ///
- private const int UnknownIndex = -1;
-
- //_selectIndex默认为0.
- private int _selectIndex;
+ private UniversalItemContainer? _universalItemContainer;
public override void _Ready()
{
base._Ready();
+ _universalItemContainer = new UniversalItemContainer
+ {
+ CharacterTemplate = new Player()
+ };
NodeUtils.DeleteAllChild(this);
- _itemSlotNodes = new List();
- _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn");
for (var i = 0; i < Config.HotBarSize; i++)
{
- AddItemSlot(i);
+ _universalItemContainer.AddItemSlot(this, i);
}
}
- ///
- /// Select the next item slot
- /// 选择下一个物品槽
- ///
- private void SelectTheNextItemSlot()
- {
- if (_itemSlotNodes == null)
- {
- return;
- }
-
- var count = _itemSlotNodes.Count;
- if (count == 0)
- {
- return;
- }
-
- var oldSelectIndex = _selectIndex;
- _selectIndex++;
- if (_selectIndex >= count)
- {
- _selectIndex = 0;
- }
-
- SelectItemSlot(oldSelectIndex, _selectIndex);
- }
-
- ///
- /// Select the previous item slot
- /// 选择上一个物品槽
- ///
- private void SelectThePreviousItemSlot()
- {
- if (_itemSlotNodes == null)
- {
- return;
- }
-
- var count = _itemSlotNodes.Count;
- if (count == 0)
- {
- return;
- }
-
- var oldSelectIndex = _selectIndex;
- _selectIndex--;
- if (_selectIndex < 0)
- {
- _selectIndex = count - 1;
- }
-
- SelectItemSlot(oldSelectIndex, _selectIndex);
- }
-
public override void _Process(double delta)
{
base._Process(delta);
@@ -96,14 +33,14 @@ public partial class HotBar : HBoxContainer, IItemContainer
{
//Mouse wheel down
//鼠标滚轮向下
- SelectTheNextItemSlot();
+ _universalItemContainer?.SelectTheNextItemSlot();
}
if (Input.IsActionJustPressed("hotbar_previous"))
{
//Mouse wheel up
//鼠标滚轮向上
- SelectThePreviousItemSlot();
+ _universalItemContainer?.SelectThePreviousItemSlot();
}
if (Input.IsActionJustPressed("hotbar_1"))
@@ -161,250 +98,15 @@ public partial class HotBar : HBoxContainer, IItemContainer
///
private void SelectItemSlotByHotBarShortcutKey(int shortcutKeyIndex)
{
- if (_itemSlotNodes == null)
+ if (_universalItemContainer == null)
{
return;
}
-
- var safeIndex = GetSafeIndex(shortcutKeyIndex);
- if (safeIndex == UnknownIndex)
- {
- return;
- }
-
- SelectItemSlot(_selectIndex, safeIndex);
- _selectIndex = safeIndex;
+ _universalItemContainer.SelectItemSlot(shortcutKeyIndex);
}
-
- ///
- /// Removes an item from the currently selected inventory
- /// 移除当前选中的物品栏内的物品
- ///
- ///
- ///
- public bool RemoveItemFromItemSlotBySelectIndex(int number)
+ public IItemContainer? GetItemContainer()
{
- return RemoveItemFromItemSlot(_selectIndex, number);
- }
-
- public int GetItemSlotCount()
- {
- if (_itemSlotNodes == null)
- {
- return 0;
- }
-
- return _itemSlotNodes.Count;
- }
-
- public ItemSlotNode? GetItemSlotNode(int index)
- {
- if (_itemSlotNodes == null)
- {
- return null;
- }
-
- var safeIndex = GetSafeIndex(index);
- return _itemSlotNodes[safeIndex];
- }
-
- ///
- /// Remove items from the item slot
- /// 从物品槽内移除物品
- ///
- ///
- ///When this number is greater than the number of item slots, residual filtering is used.
- ///当此数量大于物品槽的数量时,会使用余数筛选。
- ///
- ///
- ///The number of items removed
- ///移除物品的数量
- ///
- public bool RemoveItemFromItemSlot(int itemSlotIndex, int number)
- {
- if (_itemSlotNodes == null)
- {
- return false;
- }
-
- var safeIndex = GetSafeIndex(itemSlotIndex);
- if (safeIndex == UnknownIndex)
- {
- return false;
- }
-
- var itemSlot = _itemSlotNodes[safeIndex];
- return itemSlot.RemoveItem(number);
- }
-
- ///
- /// Gets a secure subscript index
- /// 获取安全的下标索引
- ///
- ///
- ///
- ///-1 is returned on failure, and the index that does not result in an out-of-bounds subscript is returned on success
- ///失败返回-1,成功返回不会导致下标越界的索引
- ///
- private int GetSafeIndex(int itemSlotIndex)
- {
- if (_itemSlotNodes == null)
- {
- return UnknownIndex;
- }
-
- var count = _itemSlotNodes.Count;
- if (count == 0)
- {
- //Prevents the dividend from being 0
- //防止被除数为0
- return UnknownIndex;
- }
-
- return itemSlotIndex % count;
- }
-
- ///
- /// Select an item slot
- /// 选中某个物品槽
- ///
- private void SelectItemSlot(int oldSelectIndex, int newSelectIndex)
- {
- if (oldSelectIndex == newSelectIndex)
- {
- return;
- }
-
- if (_itemSlotNodes == null)
- {
- return;
- }
-
- _itemSlotNodes[oldSelectIndex].IsSelect = false;
- _itemSlotNodes[newSelectIndex].IsSelect = true;
- var oldItem = _itemSlotNodes[oldSelectIndex].GetItem();
- if (oldItem != null && oldItem is Node2D oldNode2D)
- {
- oldNode2D.ProcessMode = ProcessModeEnum.Disabled;
- oldNode2D.Hide();
- }
-
- var item = _itemSlotNodes[newSelectIndex].GetItem();
- if (item == null)
- {
- if (GameSceneNodeHolder.Player != null)
- {
- GameSceneNodeHolder.Player.CurrentItem = null;
- }
- }
- else
- {
- if (item is Node2D node2D)
- {
- node2D.ProcessMode = ProcessModeEnum.Inherit;
- node2D.Show();
- if (GameSceneNodeHolder.Player != null)
- {
- GameSceneNodeHolder.Player.CurrentItem = node2D;
- }
- }
- else
- {
- if (GameSceneNodeHolder.Player != null)
- {
- GameSceneNodeHolder.Player.CurrentItem = null;
- }
- }
- }
- }
-
-
- public bool CanAddItem(IItem item)
- {
- return Matching(item) != null;
- }
-
-
- ///
- /// Add an item to the HotBar
- /// 在HotBar内添加一个物品
- ///
- ///
- ///
- public bool AddItem(IItem item)
- {
- var itemSlotNode = Matching(item);
- if (itemSlotNode == null)
- {
- return false;
- }
-
- return itemSlotNode.SetItem(item);
- }
-
- public int GetSelectIndex()
- {
- return _selectIndex;
- }
-
- public ItemSlotNode? GetSelectItemSlotNode()
- {
- if (_itemSlotNodes == null || _itemSlotNodes.Count == 0)
- {
- return null;
- }
-
- if (_selectIndex < _itemSlotNodes.Count)
- {
- //Prevent subscripts from going out of bounds.
- //防止下标越界。
- return _itemSlotNodes[_selectIndex];
- }
-
- return null;
- }
-
- public ItemSlotNode? Matching(IItem item)
- {
- if (_itemSlotNodes == null || _itemSlotNodes.Count == 0)
- {
- return null;
- }
-
-
- foreach (var itemSlotNode in _itemSlotNodes)
- {
- if (itemSlotNode.CanSetItem(item))
- {
- //If there is an item slot to put this item in, then we return it.
- //如果有物品槽可放置此物品,那么我们返回它。
- return itemSlotNode;
- }
- }
-
- return null;
- }
-
- ///
- /// Add items tank
- /// 添加物品槽
- ///
- private void AddItemSlot(int index)
- {
- if (_itemSlotNodes == null || _itemSlotPackedScene == null)
- {
- return;
- }
-
- var itemSlotNode = NodeUtils.InstantiatePackedScene(_itemSlotPackedScene);
- if (itemSlotNode == null)
- {
- return;
- }
-
- AddChild(itemSlotNode);
- itemSlotNode.IsSelect = index == _selectIndex;
- _itemSlotNodes.Add(itemSlotNode);
+ return _universalItemContainer;
}
}
\ No newline at end of file
diff --git a/scripts/inventory/IItemContainer.cs b/scripts/inventory/IItemContainer.cs
index c275c7d..2903a08 100644
--- a/scripts/inventory/IItemContainer.cs
+++ b/scripts/inventory/IItemContainer.cs
@@ -1,4 +1,6 @@
-namespace ColdMint.scripts.inventory;
+using Godot;
+
+namespace ColdMint.scripts.inventory;
///
/// item container
@@ -54,7 +56,7 @@ public interface IItemContainer
///
///
int GetItemSlotCount();
-
+
///
/// Gets the item slot for the specified location
/// 获取指定位置的物品槽
@@ -82,4 +84,31 @@ public interface IItemContainer
///若没有槽可放置此物品,则返回null
///
ItemSlotNode? Matching(IItem item);
+
+ ///
+ /// AddItemSlot
+ /// 添加物品槽
+ ///
+ ///
+ ///
+ void AddItemSlot(Node rootNode, int index);
+
+ ///
+ /// SelectTheNextItemSlot
+ /// 选择下一个物品槽
+ ///
+ void SelectTheNextItemSlot();
+
+ ///
+ /// SelectThePreviousItemSlot
+ /// 选择上一个物品槽
+ ///
+ void SelectThePreviousItemSlot();
+
+ ///
+ /// 选择物品槽
+ /// SelectItemSlot
+ ///
+ ///
+ void SelectItemSlot(int newSelectIndex);
}
\ No newline at end of file
diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs
new file mode 100644
index 0000000..538b695
--- /dev/null
+++ b/scripts/inventory/UniversalItemContainer.cs
@@ -0,0 +1,307 @@
+using System.Collections.Generic;
+using ColdMint.scripts.character;
+using ColdMint.scripts.utils;
+using Godot;
+
+namespace ColdMint.scripts.inventory;
+
+///
+/// UniversalItemContainer
+/// 通用的物品容器
+///
+public class UniversalItemContainer : IItemContainer
+{
+ private readonly PackedScene? _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn");
+
+ private readonly List? _itemSlotNodes = new();
+
+ ///
+ /// Character
+ /// 角色
+ ///
+ public CharacterTemplate? CharacterTemplate { get; set; }
+
+ ///
+ /// UnknownIndex
+ /// 未知位置
+ ///
+ private const int UnknownIndex = -1;
+
+ //_selectIndex默认为0.
+ private int _selectIndex;
+
+ public bool CanAddItem(IItem item)
+ {
+ return Matching(item) != null;
+ }
+
+ public bool AddItem(IItem item)
+ {
+ var itemSlotNode = Matching(item);
+ if (itemSlotNode == null)
+ {
+ return false;
+ }
+
+ return itemSlotNode.SetItem(item);
+ }
+
+ public int GetSelectIndex()
+ {
+ return _selectIndex;
+ }
+
+ public ItemSlotNode? GetSelectItemSlotNode()
+ {
+ if (_itemSlotNodes == null || _itemSlotNodes.Count == 0)
+ {
+ return null;
+ }
+
+ if (_selectIndex < _itemSlotNodes.Count)
+ {
+ //Prevent subscripts from going out of bounds.
+ //防止下标越界。
+ return _itemSlotNodes[_selectIndex];
+ }
+
+ return null;
+ }
+
+ public bool RemoveItemFromItemSlotBySelectIndex(int number)
+ {
+ return RemoveItemFromItemSlot(_selectIndex, number);
+ }
+
+ public int GetItemSlotCount()
+ {
+ if (_itemSlotNodes == null)
+ {
+ return 0;
+ }
+
+ return _itemSlotNodes.Count;
+ }
+
+ public ItemSlotNode? GetItemSlotNode(int index)
+ {
+ if (_itemSlotNodes == null)
+ {
+ return null;
+ }
+
+ var safeIndex = GetSafeIndex(index);
+ return _itemSlotNodes[safeIndex];
+ }
+
+ public bool RemoveItemFromItemSlot(int itemSlotIndex, int number)
+ {
+ if (_itemSlotNodes == null)
+ {
+ return false;
+ }
+
+ var safeIndex = GetSafeIndex(itemSlotIndex);
+ if (safeIndex == UnknownIndex)
+ {
+ return false;
+ }
+
+ var itemSlot = _itemSlotNodes[safeIndex];
+ return itemSlot.RemoveItem(number);
+ }
+
+ public ItemSlotNode? Matching(IItem item)
+ {
+ if (_itemSlotNodes == null || _itemSlotNodes.Count == 0)
+ {
+ return null;
+ }
+
+
+ foreach (var itemSlotNode in _itemSlotNodes)
+ {
+ if (itemSlotNode.CanSetItem(item))
+ {
+ //If there is an item slot to put this item in, then we return it.
+ //如果有物品槽可放置此物品,那么我们返回它。
+ return itemSlotNode;
+ }
+ }
+
+ return null;
+ }
+
+
+ ///
+ /// Gets a secure subscript index
+ /// 获取安全的下标索引
+ ///
+ ///
+ ///
+ ///-1 is returned on failure, and the index that does not result in an out-of-bounds subscript is returned on success
+ ///失败返回-1,成功返回不会导致下标越界的索引
+ ///
+ private int GetSafeIndex(int itemSlotIndex)
+ {
+ if (_itemSlotNodes == null)
+ {
+ return UnknownIndex;
+ }
+
+ var count = _itemSlotNodes.Count;
+ if (count == 0)
+ {
+ //Prevents the dividend from being 0
+ //防止被除数为0
+ return UnknownIndex;
+ }
+
+ return itemSlotIndex % count;
+ }
+
+ ///
+ /// Add items tank
+ /// 添加物品槽
+ ///
+ public void AddItemSlot(Node rootNode, int index)
+ {
+ if (_itemSlotNodes == null || _itemSlotPackedScene == null)
+ {
+ return;
+ }
+
+ var itemSlotNode = NodeUtils.InstantiatePackedScene(_itemSlotPackedScene, rootNode);
+ if (itemSlotNode == null)
+ {
+ return;
+ }
+
+ itemSlotNode.IsSelect = index == _selectIndex;
+ _itemSlotNodes.Add(itemSlotNode);
+ }
+
+ public void SelectTheNextItemSlot()
+ {
+ if (_itemSlotNodes == null)
+ {
+ return;
+ }
+
+ var count = _itemSlotNodes.Count;
+ if (count == 0)
+ {
+ return;
+ }
+
+ var oldSelectIndex = _selectIndex;
+ var newSelectIndex = _selectIndex + 1;
+ if (newSelectIndex >= count)
+ {
+ newSelectIndex = 0;
+ }
+
+ PrivateSelectItemSlot(oldSelectIndex, newSelectIndex);
+ }
+
+ public void SelectThePreviousItemSlot()
+ {
+ if (_itemSlotNodes == null)
+ {
+ return;
+ }
+
+ var count = _itemSlotNodes.Count;
+ if (count == 0)
+ {
+ return;
+ }
+
+ var oldSelectIndex = _selectIndex;
+ var newSelectIndex = _selectIndex - 1;
+ if (newSelectIndex < 0)
+ {
+ newSelectIndex = count - 1;
+ }
+
+ PrivateSelectItemSlot(oldSelectIndex, newSelectIndex);
+ }
+
+ public void SelectItemSlot(int newSelectIndex)
+ {
+ if (newSelectIndex == _selectIndex)
+ {
+ return;
+ }
+
+ var safeIndex = GetSafeIndex(newSelectIndex);
+ if (safeIndex == UnknownIndex)
+ {
+ return;
+ }
+
+ PrivateSelectItemSlot(_selectIndex, newSelectIndex);
+ }
+
+ ///
+ /// Select an item slot
+ /// 选中某个物品槽
+ ///
+ private void PrivateSelectItemSlot(int oldSelectIndex, int newSelectIndex)
+ {
+ if (oldSelectIndex == newSelectIndex)
+ {
+ return;
+ }
+
+ if (_itemSlotNodes == null)
+ {
+ return;
+ }
+
+ _itemSlotNodes[oldSelectIndex].IsSelect = false;
+ _itemSlotNodes[newSelectIndex].IsSelect = true;
+ var oldItem = _itemSlotNodes[oldSelectIndex].GetItem();
+ if (oldItem is Node2D oldNode2D)
+ {
+ oldNode2D.ProcessMode = Node.ProcessModeEnum.Disabled;
+ oldNode2D.Hide();
+ }
+
+ var item = _itemSlotNodes[newSelectIndex].GetItem();
+ switch (item)
+ {
+ case null:
+ {
+ if (CharacterTemplate != null)
+ {
+ CharacterTemplate.CurrentItem = null;
+ }
+
+ break;
+ }
+ case Node2D node2D:
+ {
+ node2D.ProcessMode = Node.ProcessModeEnum.Inherit;
+ node2D.Show();
+ if (CharacterTemplate != null)
+ {
+ CharacterTemplate.CurrentItem = node2D;
+ }
+
+ break;
+ }
+ default:
+ {
+ if (CharacterTemplate != null)
+ {
+ CharacterTemplate.CurrentItem = null;
+ }
+
+ break;
+ }
+ }
+
+ _selectIndex = newSelectIndex;
+ }
+}
\ No newline at end of file
diff --git a/scripts/map/PlayerSpawn.cs b/scripts/map/PlayerSpawn.cs
index 08d2d30..de6f76f 100644
--- a/scripts/map/PlayerSpawn.cs
+++ b/scripts/map/PlayerSpawn.cs
@@ -58,7 +58,7 @@ public partial class PlayerSpawn : Marker2D
{
return;
}
- playerNode.ItemContainer = GameSceneNodeHolder.HotBar;
+ playerNode.ItemContainer = GameSceneNodeHolder.HotBar?.GetItemContainer();
GameSceneNodeHolder.Player = playerNode;
playerNode.Position = GlobalPosition;
LogCat.LogWithFormat("player_spawn_debug", playerNode.ReadOnlyCharacterName, playerNode.Position);
diff --git a/scripts/weapon/WeaponTemplate.cs b/scripts/weapon/WeaponTemplate.cs
index 0a713fa..438a5db 100644
--- a/scripts/weapon/WeaponTemplate.cs
+++ b/scripts/weapon/WeaponTemplate.cs
@@ -2,7 +2,6 @@ using System;
using ColdMint.scripts.camp;
using ColdMint.scripts.character;
using ColdMint.scripts.damage;
-using ColdMint.scripts.debug;
using ColdMint.scripts.inventory;
using Godot;