初次提交
This commit is contained in:
45
Script/UI/BagItemUI.cs
Normal file
45
Script/UI/BagItemUI.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
using System;
|
||||
namespace Cosmobox
|
||||
{
|
||||
public partial class BagItemUI : Button
|
||||
{
|
||||
[Export] public TextureRect icon;
|
||||
[Export] public Label count, itemName;
|
||||
[Export] public Control itemNamePanel;
|
||||
[Export] public Texture2D emptyIcon;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
itemNamePanel.Visible = false;
|
||||
}
|
||||
|
||||
public void SetItem(BagItem bagItem)
|
||||
{
|
||||
if (bagItem == null || bagItem.itemResource == null)
|
||||
{
|
||||
SetEmpty();
|
||||
return;
|
||||
}
|
||||
itemName.Text = bagItem.itemResource.ItemName;
|
||||
icon.Texture = bagItem.itemResource.Icon ?? emptyIcon;
|
||||
count.Text = bagItem.amount > 0 ? bagItem.amount.ToString() : "空";
|
||||
}
|
||||
|
||||
public void SetEmpty()
|
||||
{
|
||||
icon.Texture = emptyIcon;
|
||||
count.Text = "空";
|
||||
}
|
||||
void _on_mouse_entered()
|
||||
{
|
||||
itemNamePanel.Visible = true;
|
||||
// GD.Print("鼠标进入");
|
||||
}
|
||||
void _on_mouse_exited()
|
||||
{
|
||||
itemNamePanel.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user