From a1d40d09b11c605ae8a62645bccec17b46345a32 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Thu, 2 May 2024 16:28:22 +0800 Subject: [PATCH] =?UTF-8?q?Support=20for=20displaying=20item=20details=20n?= =?UTF-8?q?ow.=20=E6=94=AF=E6=8C=81=E6=98=BE=E7=A4=BA=E7=89=A9=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/UI.csv | 2 +- locals/UI.en.translation | Bin 998 -> 1010 bytes locals/UI.zh.translation | Bin 1013 -> 1025 bytes locals/Weapon.csv | 3 +- locals/Weapon.en.translation | Bin 434 -> 494 bytes locals/Weapon.zh.translation | Bin 449 -> 525 bytes prefab/weapons/staffOfTheUndead.tscn | 2 + project.godot | 1 + scripts/Config.cs | 21 ++- scripts/inventory/IItem.cs | 6 + scripts/inventory/ItemSlotNode.cs | 186 +++++++++++----------- scripts/loader/uiLoader/MainMenuLoader.cs | 4 +- scripts/weapon/WeaponTemplate.cs | 2 + 13 files changed, 133 insertions(+), 94 deletions(-) diff --git a/locals/UI.csv b/locals/UI.csv index eb013c5..7d24eeb 100644 --- a/locals/UI.csv +++ b/locals/UI.csv @@ -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} \ No newline at end of file +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} \ No newline at end of file diff --git a/locals/UI.en.translation b/locals/UI.en.translation index 8de5552e5801d1838250493b2ee6f7dc5f6cb563..251b4295c6cb015a36a2e4fdb2a311b015aaf9ac 100644 GIT binary patch delta 109 zcmaFH{)v5qG$U({iFsbxW(CG9M%Dxd28M*m{Y=@6FDCzHnk?a$n44;)P;FSt6 zSCUy$3FH~oa!p>zEU)X5SdyqvQds~}VN%QGl3JWxlvz-cnVuTk P0_E6&m=TDBf`gm^f}#^T delta 51 zcmZqV_{zRPnvpd*$)uoYvjSr!Bdb3H1B3tMc}&@iHz#v3-xdIJ8Q6iC5r~6=gPZ|g Cjtgi2 diff --git a/locals/Weapon.csv b/locals/Weapon.csv index 2c9bf13..61dcf12 100644 --- a/locals/Weapon.csv +++ b/locals/Weapon.csv @@ -1,2 +1,3 @@ id,zh,en -staff_of_the_undead,死灵法杖,StaffOfTheUndead \ No newline at end of file +staff_of_the_undead,死灵法杖,StaffOfTheUndead +staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters. \ No newline at end of file diff --git a/locals/Weapon.en.translation b/locals/Weapon.en.translation index 9452a22cf8056b4164097358d3d32556eddf3fc1..2940b55bb45954fb6583636f5c66aec18d8da563 100644 GIT binary patch delta 140 zcmdnQ{Em5pG$X5dv0=8!WCcbuLk1xD4+LybniWVZ05J~`GeU9vscqKL zsO(|{Wc>?1p`-K9U&rHLsBMMBKZbwKddiDsrp5ENAC}^B(G@pl(&eb*k7UaIP%ZB( T&6W2LsD~YhL8b-;2RQ=(q>?24 delta 80 zcmaFIyoq^(G$U(js(G2|WCcbu$^THm00bZ=E09(IVz$ZcjLHfEK-RzD6FNHo{B=D3 Uh1ym~{9|ATiZKFlP;ihl0Oh(HMgRZ+ diff --git a/locals/Weapon.zh.translation b/locals/Weapon.zh.translation index 8c1237292aaa8539d4e2a25be5eca685a6561b97..415e422e952432e3de477478fe57f05a9238e88e 100644 GIT binary patch delta 156 zcmX@e+{>~-nvvC@)GQ@;vI3*4Ap;Qn2Ld)I%?hLyfS3n}8KF4-)VAxqK(;vuPp)HB z4sijpo~_;eym9NZ%~PMvoyPFAf8x^(Eicx$KAkk_{hpqu{p+7@XnQub=gF>JFZQl^ m+B5CRj$JRCRy}Ln_Iy^$vxZgAJ6Aq#XkuW8+7J{RuJ9abFg diff --git a/prefab/weapons/staffOfTheUndead.tscn b/prefab/weapons/staffOfTheUndead.tscn index 54c212b..54bad3f 100644 --- a/prefab/weapons/staffOfTheUndead.tscn +++ b/prefab/weapons/staffOfTheUndead.tscn @@ -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 diff --git a/project.godot b/project.godot index 2e5a996..d9fc5bd 100644 --- a/project.godot +++ b/project.godot @@ -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] diff --git a/scripts/Config.cs b/scripts/Config.cs index 1bb80c4..c1f36c5 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -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 ///在禁用版本隔离时用的 /// public const string DefaultVersionName = "Default"; - + + /// + /// IsDebug + /// 是否为Debug模式 + /// + /// + 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(); + } + /// /// GetGameDataDirectory /// 获取游戏数据目录 diff --git a/scripts/inventory/IItem.cs b/scripts/inventory/IItem.cs index f245017..60ad524 100644 --- a/scripts/inventory/IItem.cs +++ b/scripts/inventory/IItem.cs @@ -34,6 +34,12 @@ public interface IItem /// 物品有名称 /// string Name { get; set; } + + /// + /// Description + /// 描述 + /// + string Description { get; set; } /// diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index df95877..2f8b279 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -8,99 +8,107 @@ namespace ColdMint.scripts.inventory; /// 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; - /// - /// Sets items for the item slot - /// 为物品槽设置物品 - /// - /// - /// - public bool SetItem(IItem item) - { - if (_item == null) - { - if (item.Icon != null) - { - _iconTextureRect.TextureNormal = item.Icon; - } + /// + /// Sets items for the item slot + /// 为物品槽设置物品 + /// + /// + /// + 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; + } + } - /// - /// Update item tips - /// 更新物品的提示内容 - /// - /// - 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); - } + /// + /// Update item tips + /// 更新物品的提示内容 + /// + /// + 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); + } + } - /// - /// Update quantity label - /// 更新数量标签 - /// - /// - 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; - } - } + /// + /// Update quantity label + /// 更新数量标签 + /// + /// + 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("BackgroundTexture"); - _iconTextureRect = GetNode("BackgroundTexture/CenterContainer/IconTextureRect"); - _quantityLabel = GetNode