You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
using System; |
|
using Equip; |
|
using JetBrains.Annotations; |
|
using TMPro; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
namespace Dialogs |
|
{ |
|
public class WeaponDialog : BaseDialog |
|
{ |
|
|
|
[SerializeField] private TextMeshProUGUI _title; |
|
[SerializeField] private TextMeshProUGUI _type; |
|
[SerializeField] private Image _icon; |
|
[SerializeField] private Button _equipButton; |
|
[SerializeField] private WeaponStatItem _item; |
|
[SerializeField] private RectTransform _itemContainer; |
|
|
|
private Action _callback; |
|
|
|
void Start () |
|
{ |
|
m_type = DialogType.WEAPON_DIALOG; |
|
} |
|
|
|
public void Init(EquipItem item, string itemType, bool equipped, Action callback) |
|
{ |
|
_title.text = item.Name; |
|
_type.text = string.Format("{0} - {1}", itemType, GetRarity(item.Rarity)); |
|
_icon.sprite = Resources.Load<Sprite>(string.Format("Equipment/{0}", item.Icon)); |
|
AddStat("DMG +{0}", item.AddDamage); |
|
AddStat("HP +{0}", item.AddHp); |
|
AddStat("CRIT +{0}", item.AddCrit); |
|
|
|
_equipButton.gameObject.SetActive(!equipped); |
|
_callback = callback; |
|
} |
|
|
|
private void AddStat(string format, float stat) |
|
{ |
|
var item = Instantiate(_item, _itemContainer); |
|
item.SetText(string.Format(format, stat)); |
|
} |
|
|
|
private string GetRarity(string itemRarity) |
|
{ |
|
switch (itemRarity) |
|
{ |
|
case "blue": |
|
return "Rare"; |
|
case "violet": |
|
return "Epic"; |
|
default: |
|
return "Normal"; |
|
} |
|
} |
|
|
|
[UsedImplicitly] |
|
public void Callback() |
|
{ |
|
if (_callback != null) |
|
_callback(); |
|
} |
|
} |
|
}
|
|
|