Support for displaying item details now.
支持显示物品详情了。
This commit is contained in:
parent
e204aae56a
commit
a1d40d09b1
|
@ -11,4 +11,4 @@ use_item,使用,Use
|
|||
jump_down,跳下平台,Jump off platform
|
||||
de,的,'s
|
||||
default_player_name,白纸,blankPaper
|
||||
item_prompt_debug,ID:{0}\n名称:{1}\n数量:{2}\n最大叠加数量:{3}\n数据类型:{4},ID: {0}\n Name: {1}\n Quantity: {2}\n Maximum stacking quantity: {3}\n Data type: {4}
|
||||
item_prompt_debug,ID:{0}\n名称:{1}\n数量:{2}\n最大叠加数量:{3}\n数据类型:{4}\n描述:{5},ID: {0}\nName: {1}\nQuantity: {2}\nMaximum stacking quantity: {3}\nData type: {4}\nDescription:{5}
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,2 +1,3 @@
|
|||
id,zh,en
|
||||
staff_of_the_undead,死灵法杖,StaffOfTheUndead
|
||||
staff_of_the_undead,死灵法杖,StaffOfTheUndead
|
||||
staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.
|
|
Binary file not shown.
Binary file not shown.
|
@ -19,6 +19,8 @@ metadata/Name = "staff_of_the_undead"
|
|||
metadata/FiringIntervalArray = PackedInt64Array(5000, 500, 250)
|
||||
metadata/Icon = ExtResource("2_l5lni")
|
||||
metadata/ID = "StaffOfTheUndead"
|
||||
metadata/MaxStackQuantity = 1
|
||||
metadata/Description = "staff_of_the_undead_desc"
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -92,6 +92,7 @@ use_item={
|
|||
[internationalization]
|
||||
|
||||
locale/translations=PackedStringArray("res://locals/UI.en.translation", "res://locals/UI.zh.translation", "res://locals/Error.zh.translation", "res://locals/Error.en.translation", "res://locals/slogan.en.translation", "res://locals/slogan.zh.translation", "res://locals/Log.en.translation", "res://locals/Log.zh.translation", "res://locals/Weapon.en.translation", "res://locals/Weapon.zh.translation", "res://locals/InputMapping.en.translation", "res://locals/InputMapping.zh.translation")
|
||||
locale/test="en"
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Godot;
|
||||
using Environment = System.Environment;
|
||||
|
||||
|
@ -107,8 +108,26 @@ public static class Config
|
|||
///<para>在禁用版本隔离时用的</para>
|
||||
/// </remarks>
|
||||
public const string DefaultVersionName = "Default";
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>IsDebug</para>
|
||||
/// <para>是否为Debug模式</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsDebug()
|
||||
{
|
||||
return OS.HasFeature("debug");
|
||||
}
|
||||
|
||||
public static string GetVersion()
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(ProjectSettings.GetSetting("application/config/version").AsString());
|
||||
stringBuilder.Append(IsDebug() ? "_debug" : "_release");
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>GetGameDataDirectory</para>
|
||||
/// <para>获取游戏数据目录</para>
|
||||
|
|
|
@ -34,6 +34,12 @@ public interface IItem
|
|||
/// <para>物品有名称</para>
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Description</para>
|
||||
/// <para>描述</para>
|
||||
/// </summary>
|
||||
string Description { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -8,99 +8,107 @@ namespace ColdMint.scripts.inventory;
|
|||
/// </summary>
|
||||
public partial class ItemSlotNode : MarginContainer
|
||||
{
|
||||
private IItem? _item;
|
||||
private TextureRect _backgroundTextureRect;
|
||||
private TextureButton _iconTextureRect;
|
||||
private Label _quantityLabel;
|
||||
private Control _control;
|
||||
private IItem? _item;
|
||||
private TextureRect _backgroundTextureRect;
|
||||
private TextureButton _iconTextureRect;
|
||||
private Label _quantityLabel;
|
||||
private Control _control;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Sets items for the item slot</para>
|
||||
/// <para>为物品槽设置物品</para>
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool SetItem(IItem item)
|
||||
{
|
||||
if (_item == null)
|
||||
{
|
||||
if (item.Icon != null)
|
||||
{
|
||||
_iconTextureRect.TextureNormal = item.Icon;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>Sets items for the item slot</para>
|
||||
/// <para>为物品槽设置物品</para>
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool SetItem(IItem item)
|
||||
{
|
||||
if (_item == null)
|
||||
{
|
||||
if (item.Icon != null)
|
||||
{
|
||||
_iconTextureRect.TextureNormal = item.Icon;
|
||||
}
|
||||
|
||||
_item = item;
|
||||
UpdateTooltipText(item);
|
||||
UpdateQuantityLabel(item.Quantity);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//This inventory already has items, but the items in this inventory are not the same as the incoming items
|
||||
//这个物品栏已经有物品了,但是这个物品栏的物品和传入的物品不一样
|
||||
if (_item.Id != item.Id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_item = item;
|
||||
UpdateTooltipText(item);
|
||||
UpdateQuantityLabel(item.Quantity);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//This inventory already has items, but the items in this inventory are not the same as the incoming items
|
||||
//这个物品栏已经有物品了,但是这个物品栏的物品和传入的物品不一样
|
||||
if (_item.Id != item.Id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var newQuantity = _item.Quantity + item.Quantity;
|
||||
if (newQuantity > item.MaxStackQuantity)
|
||||
{
|
||||
//If the amount of the current item exceeds the maximum stack amount after placing it in this inventory
|
||||
//如果将当前物品放置到这个物品栏后,数量超过了最大叠加数量
|
||||
return false;
|
||||
}
|
||||
var newQuantity = _item.Quantity + item.Quantity;
|
||||
if (newQuantity > item.MaxStackQuantity)
|
||||
{
|
||||
//If the amount of the current item exceeds the maximum stack amount after placing it in this inventory
|
||||
//如果将当前物品放置到这个物品栏后,数量超过了最大叠加数量
|
||||
return false;
|
||||
}
|
||||
|
||||
_item.Quantity = newQuantity;
|
||||
UpdateTooltipText(item);
|
||||
UpdateQuantityLabel(newQuantity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_item.Quantity = newQuantity;
|
||||
UpdateTooltipText(item);
|
||||
UpdateQuantityLabel(newQuantity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Update item tips</para>
|
||||
/// <para>更新物品的提示内容</para>
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
private void UpdateTooltipText(IItem item)
|
||||
{
|
||||
_control.TooltipText = string.Format(TranslationServer.Translate("item_prompt_debug"), item.Id,
|
||||
TranslationServer.Translate(item.Name),
|
||||
item.Quantity, item.MaxStackQuantity, item.GetType().Name);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>Update item tips</para>
|
||||
/// <para>更新物品的提示内容</para>
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
private void UpdateTooltipText(IItem item)
|
||||
{
|
||||
if (Config.IsDebug())
|
||||
{
|
||||
_control.TooltipText = string.Format(TranslationServer.Translate("item_prompt_debug"), item.Id,
|
||||
TranslationServer.Translate(item.Name),
|
||||
item.Quantity, item.MaxStackQuantity, item.GetType().Name, TranslationServer.Translate(item.Description));
|
||||
}
|
||||
else
|
||||
{
|
||||
_control.TooltipText = TranslationServer.Translate(item.Name) + "\n" +
|
||||
TranslationServer.Translate(item.Description);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Update quantity label</para>
|
||||
/// <para>更新数量标签</para>
|
||||
/// </summary>
|
||||
/// <param name="quantity"></param>
|
||||
private void UpdateQuantityLabel(int? quantity)
|
||||
{
|
||||
switch (quantity)
|
||||
{
|
||||
case null:
|
||||
_quantityLabel.Visible = false;
|
||||
return;
|
||||
case > 1:
|
||||
//When the quantity is greater than 1, we display the quantity.
|
||||
//当数量大于1时,我们显示数量
|
||||
_quantityLabel.Text = quantity.ToString();
|
||||
_quantityLabel.Visible = true;
|
||||
break;
|
||||
default:
|
||||
_quantityLabel.Visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>Update quantity label</para>
|
||||
/// <para>更新数量标签</para>
|
||||
/// </summary>
|
||||
/// <param name="quantity"></param>
|
||||
private void UpdateQuantityLabel(int? quantity)
|
||||
{
|
||||
switch (quantity)
|
||||
{
|
||||
case null:
|
||||
_quantityLabel.Visible = false;
|
||||
return;
|
||||
case > 1:
|
||||
//When the quantity is greater than 1, we display the quantity.
|
||||
//当数量大于1时,我们显示数量
|
||||
_quantityLabel.Text = quantity.ToString();
|
||||
_quantityLabel.Visible = true;
|
||||
break;
|
||||
default:
|
||||
_quantityLabel.Visible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_backgroundTextureRect =
|
||||
GetNode<TextureRect>("BackgroundTexture");
|
||||
_iconTextureRect = GetNode<TextureButton>("BackgroundTexture/CenterContainer/IconTextureRect");
|
||||
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
|
||||
_control = GetNode<Control>("Control");
|
||||
_quantityLabel.Visible = false;
|
||||
}
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
_backgroundTextureRect =
|
||||
GetNode<TextureRect>("BackgroundTexture");
|
||||
_iconTextureRect = GetNode<TextureButton>("BackgroundTexture/CenterContainer/IconTextureRect");
|
||||
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
|
||||
_control = GetNode<Control>("Control");
|
||||
_quantityLabel.Visible = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
|||
{
|
||||
//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();
|
||||
if (dataPath != null && !Directory.Exists(dataPath))
|
||||
|
@ -72,7 +72,7 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
|||
_copyrightBuilder.Append(Config.CompanyName);
|
||||
_copyrightBuilder.Append(" all rights reserved.");
|
||||
_copyrightLabel.Text = _copyrightBuilder.ToString();
|
||||
_versionLabel.Text = "ver." + ProjectSettings.GetSetting("application/config/version").AsString();
|
||||
_versionLabel.Text = "ver." + Config.GetVersion();
|
||||
_sloganLabel.Text = SloganProvider.GetSlogan();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ public partial class WeaponTemplate : RigidBody2D, IItem
|
|||
public int MaxStackQuantity { get; set; }
|
||||
public Texture2D Icon { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Action<IItem> OnUse { get; set; }
|
||||
public Func<IItem, Node> OnInstantiation { get; set; }
|
||||
|
||||
|
@ -72,6 +73,7 @@ public partial class WeaponTemplate : RigidBody2D, IItem
|
|||
MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
|
||||
Icon = GetMeta("Icon", "").As<Texture2D>();
|
||||
Name = GetMeta("Name", "").AsString();
|
||||
Description =GetMeta("Description", "").AsString();
|
||||
_firingInterval = TimeSpan.FromMilliseconds(GetMeta("FiringInterval", "100").AsInt64());
|
||||
_minContactInjury = GetMeta("MinContactInjury", "1").AsInt32();
|
||||
_maxContactInjury = GetMeta("MaxContactInjury", "2").AsInt32();
|
||||
|
|
Loading…
Reference in New Issue
Block a user