8.30
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Definition;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
@@ -11,10 +11,57 @@ namespace SepCore.UI
|
||||
[SerializeField] private Image bg;
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private TextMeshProUGUI characterName;
|
||||
[SerializeField] private TextMeshProUGUI hpText;
|
||||
[SerializeField] private TextMeshProUGUI mpText;
|
||||
[SerializeField] private TextMeshProUGUI speedText;
|
||||
[SerializeField] private TextMeshProUGUI atkText;
|
||||
[SerializeField] private TextMeshProUGUI matText;
|
||||
[SerializeField] private FormatTextUI hpText;
|
||||
[SerializeField] private FormatTextUI mpText;
|
||||
[SerializeField] private FormatTextUI speedText;
|
||||
[SerializeField] private FormatTextUI atkText;
|
||||
[SerializeField] private FormatTextUI matText;
|
||||
|
||||
/// <summary>
|
||||
/// 用存档角色填充格子;角色配置不存在时按空格子显示。
|
||||
/// </summary>
|
||||
public void SetCharacter(CharacterSave save)
|
||||
{
|
||||
CharacterConfig config = GameEntry.Luban.Get<CharacterConfig>(save.characterId);
|
||||
if (config == null)
|
||||
{
|
||||
Log.Warning("Can not find character config '{0}' for squad slot.", save.characterId);
|
||||
SetEmpty();
|
||||
return;
|
||||
}
|
||||
|
||||
characterName.text = config.Name;
|
||||
hpText.Set(config.MaxHp);
|
||||
mpText.Set(config.MaxMp);
|
||||
speedText.Set(config.Speed);
|
||||
atkText.Set(config.Atk);
|
||||
matText.Set(config.Mat);
|
||||
HideIcon();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示为空格子。
|
||||
/// </summary>
|
||||
public void SetEmpty()
|
||||
{
|
||||
characterName.text = string.Empty;
|
||||
hpText.Clear();
|
||||
mpText.Clear();
|
||||
speedText.Clear();
|
||||
atkText.Clear();
|
||||
matText.Clear();
|
||||
HideIcon();
|
||||
}
|
||||
|
||||
private void HideIcon()
|
||||
{
|
||||
if (icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
icon.sprite = null;
|
||||
icon.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,137 @@
|
||||
using SepCore.Base;
|
||||
using SepCore.Definition;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class WarehouseSlotItem : MonoBehaviour
|
||||
{
|
||||
private static readonly Color RarityWhite = new Color32(245, 247, 248, 255);
|
||||
private static readonly Color RarityGreen = new Color32(93, 155, 97, 255);
|
||||
private static readonly Color RarityBlue = new Color32(52, 127, 168, 255);
|
||||
private static readonly Color RarityGold = new Color32(214, 169, 61, 255);
|
||||
private static readonly Color RarityRed = new Color32(185, 87, 79, 255);
|
||||
private static readonly Color RarityEmpty = new Color32(111, 101, 90, 255);
|
||||
private static readonly Color SelectedBgColor = new Color(0.86f, 0.95f, 1f, 1f);
|
||||
|
||||
[SerializeField] private Image bg;
|
||||
[SerializeField] private Button button;
|
||||
[SerializeField] private Image icon;
|
||||
[SerializeField] private Image rarity;
|
||||
[SerializeField] private TextMeshProUGUI quantityText;
|
||||
|
||||
private int _slotId = 0;
|
||||
private bool _filled = false;
|
||||
private bool _clickBound = false;
|
||||
|
||||
/// <summary>
|
||||
/// 设置格子在固定网格中的索引,点击事件以此作为唯一标识。
|
||||
/// </summary>
|
||||
public void SetSlotId(int slotId)
|
||||
{
|
||||
_slotId = slotId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用物品堆叠填充格子;物品配置不存在时按空格子显示。
|
||||
/// </summary>
|
||||
public void SetItem(ItemStack stack)
|
||||
{
|
||||
ItemConfig config = GameEntry.Luban.Get<ItemConfig>(stack.itemId);
|
||||
if (config == null)
|
||||
{
|
||||
Log.Warning("Can not find item config '{0}' for warehouse slot.", stack.itemId);
|
||||
SetEmpty();
|
||||
return;
|
||||
}
|
||||
|
||||
_filled = true;
|
||||
rarity.color = GetRarityColor(config.Rarity);
|
||||
quantityText.text = stack.count.ToString();
|
||||
HideIcon();
|
||||
BindClick();
|
||||
if (button != null)
|
||||
{
|
||||
button.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示为空格子。
|
||||
/// </summary>
|
||||
public void SetEmpty()
|
||||
{
|
||||
_filled = false;
|
||||
rarity.color = RarityEmpty;
|
||||
quantityText.text = string.Empty;
|
||||
HideIcon();
|
||||
if (button != null)
|
||||
{
|
||||
button.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置选中高亮。
|
||||
/// </summary>
|
||||
public void SetSelected(bool selected)
|
||||
{
|
||||
if (bg != null)
|
||||
{
|
||||
bg.color = selected ? SelectedBgColor : Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
private void BindClick()
|
||||
{
|
||||
if (_clickBound || button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_clickBound = true;
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
if (!_filled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Event.Fire(this, WarehouseSlotItemClickEventArgs.Create(_slotId));
|
||||
}
|
||||
|
||||
private void HideIcon()
|
||||
{
|
||||
if (icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
icon.sprite = null;
|
||||
icon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private static Color GetRarityColor(Rarity rarity)
|
||||
{
|
||||
switch (rarity)
|
||||
{
|
||||
case Rarity.Green:
|
||||
return RarityGreen;
|
||||
case Rarity.Blue:
|
||||
return RarityBlue;
|
||||
case Rarity.Gold:
|
||||
return RarityGold;
|
||||
case Rarity.Red:
|
||||
return RarityRed;
|
||||
default:
|
||||
return RarityWhite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user