Add hover hints to items.
为物品添加悬浮提示。
This commit is contained in:
parent
159d3a7017
commit
e204aae56a
|
@ -11,4 +11,4 @@ use_item,使用,Use
|
||||||
jump_down,跳下平台,Jump off platform
|
jump_down,跳下平台,Jump off platform
|
||||||
de,的,'s
|
de,的,'s
|
||||||
default_player_name,白纸,blankPaper
|
default_player_name,白纸,blankPaper
|
||||||
unknown,未知,Unknown
|
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}
|
|
Binary file not shown.
Binary file not shown.
|
@ -24,8 +24,9 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
scale = Vector2(0.2, 0.2)
|
scale = Vector2(0.2, 0.2)
|
||||||
|
|
||||||
[node name="IconTextureRect" type="TextureRect" parent="BackgroundTexture/CenterContainer"]
|
[node name="IconTextureRect" type="TextureButton" parent="BackgroundTexture/CenterContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
tooltip_text = "老婆"
|
||||||
|
|
||||||
[node name="Control" type="Control" parent="."]
|
[node name="Control" type="Control" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://dnnn2xyayiehk"]
|
[gd_scene load_steps=6 format=3 uid="uid://dnnn2xyayiehk"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://e6670ykyq145" path="res://sprites/weapon/staffOfTheUndead.png" id="1_ms3us"]
|
[ext_resource type="Texture2D" uid="uid://e6670ykyq145" path="res://sprites/weapon/staffOfTheUndead.png" id="1_ms3us"]
|
||||||
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
|
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b2blj0yf4ohx3" path="res://icon.svg" id="2_l5lni"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
|
||||||
size = Vector2(49, 5)
|
size = Vector2(49, 5)
|
||||||
|
@ -16,6 +17,8 @@ script = ExtResource("1_w8hhv")
|
||||||
metadata/Projectiles = PackedStringArray("res://prefab/projectile/curseOfTheUndead.tscn")
|
metadata/Projectiles = PackedStringArray("res://prefab/projectile/curseOfTheUndead.tscn")
|
||||||
metadata/Name = "staff_of_the_undead"
|
metadata/Name = "staff_of_the_undead"
|
||||||
metadata/FiringIntervalArray = PackedInt64Array(5000, 500, 250)
|
metadata/FiringIntervalArray = PackedInt64Array(5000, 500, 250)
|
||||||
|
metadata/Icon = ExtResource("2_l5lni")
|
||||||
|
metadata/ID = "StaffOfTheUndead"
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
collision_layer = 8
|
collision_layer = 8
|
||||||
|
|
|
@ -196,7 +196,23 @@ public partial class Player : CharacterTemplate
|
||||||
//捡起物品
|
//捡起物品
|
||||||
if (Input.IsActionJustPressed("pick_up"))
|
if (Input.IsActionJustPressed("pick_up"))
|
||||||
{
|
{
|
||||||
PickUpAction();
|
var success = PickItem(PickAbleItem);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
if (PickAbleItem is WeaponTemplate weaponTemplate)
|
||||||
|
{
|
||||||
|
GameSceneNodeHolder.HotBar.AddItem(weaponTemplate);
|
||||||
|
}
|
||||||
|
PickAbleItem = null;
|
||||||
|
TotalNumberOfPickups--;
|
||||||
|
if (FloatLabel != null)
|
||||||
|
{
|
||||||
|
FloatLabel.QueueFree();
|
||||||
|
FloatLabel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateOperationTip();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_down"))
|
if (Input.IsActionJustPressed("ui_down"))
|
||||||
|
@ -273,22 +289,7 @@ public partial class Player : CharacterTemplate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PickUpAction()
|
|
||||||
{
|
|
||||||
var success = PickItem(PickAbleItem);
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
PickAbleItem = null;
|
|
||||||
TotalNumberOfPickups--;
|
|
||||||
if (FloatLabel != null)
|
|
||||||
{
|
|
||||||
FloatLabel.QueueFree();
|
|
||||||
FloatLabel = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateOperationTip();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Vector2 GetThrowVelocity()
|
private Vector2 GetThrowVelocity()
|
||||||
{
|
{
|
||||||
|
|
20
scripts/inventory/CommonItem.cs
Normal file
20
scripts/inventory/CommonItem.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace ColdMint.scripts.inventory;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Common goods</para>
|
||||||
|
/// <para>普通的物品</para>
|
||||||
|
/// </summary>
|
||||||
|
public class CommonItem : IItem
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
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; }
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ public interface IItem
|
||||||
/// <para>Item and ID</para>
|
/// <para>Item and ID</para>
|
||||||
/// <para>物品还有ID</para>
|
/// <para>物品还有ID</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Id { get; }
|
string Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Represents the quantity of this item</para>
|
/// <para>Represents the quantity of this item</para>
|
||||||
|
@ -21,21 +21,20 @@ public interface IItem
|
||||||
/// <para>How many can this item stack up to</para>
|
/// <para>How many can this item stack up to</para>
|
||||||
/// <para>这个物品最多叠加到多少个</para>
|
/// <para>这个物品最多叠加到多少个</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int MaxStackQuantity { get; }
|
int MaxStackQuantity { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Items can be set with Icon</para>
|
/// <para>Items can be set with Icon</para>
|
||||||
/// <para>物品可以设置图标</para>
|
/// <para>物品可以设置图标</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Texture2D Icon { get; }
|
Texture2D Icon { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Item has a name</para>
|
/// <para>Item has a name</para>
|
||||||
/// <para>物品有名称</para>
|
/// <para>物品有名称</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
string Name { get; set; }
|
||||||
|
|
||||||
string Namespace { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>When using items</para>
|
/// <para>When using items</para>
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
namespace ColdMint.scripts.inventory;
|
namespace ColdMint.scripts.inventory;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Item manager</para>
|
||||||
|
/// <para>物品管理器</para>
|
||||||
|
/// </summary>
|
||||||
public static class ItemManager
|
public static class ItemManager
|
||||||
{
|
{
|
||||||
private static Dictionary<string, IItem> _dictionary = new Dictionary<string, IItem>();
|
private static Dictionary<string, IItem> _dictionary = new Dictionary<string, IItem>();
|
||||||
|
@ -13,17 +17,10 @@ public static class ItemManager
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
public static void AddItem(IItem item)
|
public static void AddItem(IItem item)
|
||||||
{
|
{
|
||||||
var key = GetKey(item);
|
if (_dictionary.ContainsKey(item.Id))
|
||||||
if (_dictionary.ContainsKey(key))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_dictionary.Add(item.Id, item);
|
||||||
_dictionary.Add(key, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetKey(IItem item)
|
|
||||||
{
|
|
||||||
return item.Namespace + item.Id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,83 +8,99 @@ namespace ColdMint.scripts.inventory;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class ItemSlotNode : MarginContainer
|
public partial class ItemSlotNode : MarginContainer
|
||||||
{
|
{
|
||||||
private IItem? _item;
|
private IItem? _item;
|
||||||
private TextureRect _backgroundTextureRect;
|
private TextureRect _backgroundTextureRect;
|
||||||
private TextureRect _iconTextureRect;
|
private TextureButton _iconTextureRect;
|
||||||
private Label _quantityLabel;
|
private Label _quantityLabel;
|
||||||
|
private Control _control;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Sets items for the item slot</para>
|
/// <para>Sets items for the item slot</para>
|
||||||
/// <para>为物品槽设置物品</para>
|
/// <para>为物品槽设置物品</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool SetItem(IItem item)
|
public bool SetItem(IItem item)
|
||||||
{
|
{
|
||||||
if (_item == null)
|
if (_item == null)
|
||||||
{
|
{
|
||||||
if (item.Icon != null)
|
if (item.Icon != null)
|
||||||
{
|
{
|
||||||
_iconTextureRect.Texture = item.Icon;
|
_iconTextureRect.TextureNormal = item.Icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
_item = item;
|
_item = item;
|
||||||
UpdateQuantityLabel(item.Quantity);
|
UpdateTooltipText(item);
|
||||||
return true;
|
UpdateQuantityLabel(item.Quantity);
|
||||||
}
|
return true;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
//This inventory already has items, but the items in this inventory are not the same as the incoming items
|
{
|
||||||
//这个物品栏已经有物品了,但是这个物品栏的物品和传入的物品不一样
|
//This inventory already has items, but the items in this inventory are not the same as the incoming items
|
||||||
if (_item.Id != item.Id)
|
//这个物品栏已经有物品了,但是这个物品栏的物品和传入的物品不一样
|
||||||
{
|
if (_item.Id != item.Id)
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var newQuantity = _item.Quantity + item.Quantity;
|
var newQuantity = _item.Quantity + item.Quantity;
|
||||||
if (newQuantity > item.MaxStackQuantity)
|
if (newQuantity > item.MaxStackQuantity)
|
||||||
{
|
{
|
||||||
//If the amount of the current item exceeds the maximum stack amount after placing it in this inventory
|
//If the amount of the current item exceeds the maximum stack amount after placing it in this inventory
|
||||||
//如果将当前物品放置到这个物品栏后,数量超过了最大叠加数量
|
//如果将当前物品放置到这个物品栏后,数量超过了最大叠加数量
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_item.Quantity = newQuantity;
|
_item.Quantity = newQuantity;
|
||||||
UpdateQuantityLabel(newQuantity);
|
UpdateTooltipText(item);
|
||||||
return true;
|
UpdateQuantityLabel(newQuantity);
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Update quantity label</para>
|
/// <para>Update item tips</para>
|
||||||
/// <para>更新数量标签</para>
|
/// <para>更新物品的提示内容</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="quantity"></param>
|
/// <param name="item"></param>
|
||||||
private void UpdateQuantityLabel(int? quantity)
|
private void UpdateTooltipText(IItem item)
|
||||||
{
|
{
|
||||||
switch (quantity)
|
_control.TooltipText = string.Format(TranslationServer.Translate("item_prompt_debug"), item.Id,
|
||||||
{
|
TranslationServer.Translate(item.Name),
|
||||||
case null:
|
item.Quantity, item.MaxStackQuantity, item.GetType().Name);
|
||||||
_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()
|
/// <summary>
|
||||||
{
|
/// <para>Update quantity label</para>
|
||||||
_backgroundTextureRect =
|
/// <para>更新数量标签</para>
|
||||||
GetNode<TextureRect>("BackgroundTexture");
|
/// </summary>
|
||||||
_iconTextureRect = GetNode<TextureRect>("BackgroundTexture/CenterContainer/IconTextureRect");
|
/// <param name="quantity"></param>
|
||||||
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
|
private void UpdateQuantityLabel(int? quantity)
|
||||||
_quantityLabel.Visible = false;
|
{
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ColdMint.scripts.camp;
|
using ColdMint.scripts.camp;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
|
using ColdMint.scripts.inventory;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.loader.uiLoader;
|
namespace ColdMint.scripts.loader.uiLoader;
|
||||||
|
@ -31,7 +32,12 @@ public partial class MainMenuLoader : UiLoaderTemplate
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(dataPath);
|
Directory.CreateDirectory(dataPath);
|
||||||
}
|
}
|
||||||
|
//Registered article
|
||||||
|
//注册物品
|
||||||
|
// var staffOfTheUndead = new CommonItem();
|
||||||
|
// staffOfTheUndead.Name = "item_staff_of_the_undead";
|
||||||
|
// staffOfTheUndead.Id = "staff_of_the_undead";
|
||||||
|
// staffOfTheUndead.Description = "";
|
||||||
//Registered camp
|
//Registered camp
|
||||||
//注册阵营
|
//注册阵营
|
||||||
var defaultCamp = new Camp(Config.CampId.Default);
|
var defaultCamp = new Camp(Config.CampId.Default);
|
||||||
|
|
|
@ -13,11 +13,17 @@ namespace ColdMint.scripts.weapon;
|
||||||
/// <para>WeaponTemplate</para>
|
/// <para>WeaponTemplate</para>
|
||||||
/// <para>武器模板</para>
|
/// <para>武器模板</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class WeaponTemplate : RigidBody2D
|
public partial class WeaponTemplate : RigidBody2D, IItem
|
||||||
{
|
{
|
||||||
public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
|
public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
|
||||||
|
|
||||||
public string Name => GetMeta("Name", "").AsString();
|
public string Id { get; set; }
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
public int MaxStackQuantity { get; set; }
|
||||||
|
public Texture2D Icon { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public Action<IItem> OnUse { get; set; }
|
||||||
|
public Func<IItem, Node> OnInstantiation { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Owner</para>
|
/// <para>Owner</para>
|
||||||
|
@ -39,7 +45,7 @@ public partial class WeaponTemplate : RigidBody2D
|
||||||
|
|
||||||
//开火间隔
|
//开火间隔
|
||||||
private TimeSpan _firingInterval;
|
private TimeSpan _firingInterval;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>The recoil of the weapon</para>
|
/// <para>The recoil of the weapon</para>
|
||||||
|
@ -61,6 +67,11 @@ public partial class WeaponTemplate : RigidBody2D
|
||||||
_rayCast2D = GetNode<RayCast2D>("RayCast2D");
|
_rayCast2D = GetNode<RayCast2D>("RayCast2D");
|
||||||
_area2D = GetNode<Area2D>("Area2D");
|
_area2D = GetNode<Area2D>("Area2D");
|
||||||
_area2D.BodyEntered += OnBodyEnter;
|
_area2D.BodyEntered += OnBodyEnter;
|
||||||
|
Id = GetMeta("ID", "1").AsString();
|
||||||
|
Quantity = GetMeta("Quantity", "1").AsInt32();
|
||||||
|
MaxStackQuantity = GetMeta("MaxStackQuantity", Config.MaxStackQuantity).AsInt32();
|
||||||
|
Icon = GetMeta("Icon", "").As<Texture2D>();
|
||||||
|
Name = GetMeta("Name", "").AsString();
|
||||||
_firingInterval = TimeSpan.FromMilliseconds(GetMeta("FiringInterval", "100").AsInt64());
|
_firingInterval = TimeSpan.FromMilliseconds(GetMeta("FiringInterval", "100").AsInt64());
|
||||||
_minContactInjury = GetMeta("MinContactInjury", "1").AsInt32();
|
_minContactInjury = GetMeta("MinContactInjury", "1").AsInt32();
|
||||||
_maxContactInjury = GetMeta("MaxContactInjury", "2").AsInt32();
|
_maxContactInjury = GetMeta("MaxContactInjury", "2").AsInt32();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user