Display power buffs
This commit is contained in:
parent
515602b670
commit
034e6beca6
8 changed files with 86 additions and 25 deletions
|
|
@ -7,6 +7,8 @@ public class HeroInfoUI : MonoBehaviour
|
|||
{
|
||||
protected GameObject target;
|
||||
protected BattleParticipant battleParticipant;
|
||||
protected BattleState battleState;
|
||||
|
||||
public Text nameText;
|
||||
public Image healthBarBgImage;
|
||||
public Image healthBarFgImage;
|
||||
|
|
@ -24,11 +26,13 @@ public class HeroInfoUI : MonoBehaviour
|
|||
private static Color MED_HP_COLOR = new Color(0.8f, 0.8f, 0f);
|
||||
private static Color LOW_HP_COLOR = new Color(0.8f, 0f, 0f);
|
||||
|
||||
public void Init(GameObject sprite, BattleParticipant battleParticipant) {
|
||||
public void Init(
|
||||
GameObject sprite, BattleParticipant battleParticipant, BattleState battleState) {
|
||||
this.target = sprite;
|
||||
this.battleParticipant = battleParticipant;
|
||||
this.battleState = battleState;
|
||||
|
||||
this.statusUI.Init(battleParticipant);
|
||||
this.statusUI.Init(battleParticipant, battleState);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
|
|||
|
|
@ -11,16 +11,24 @@ public class StatusIconUI : MonoBehaviour
|
|||
|
||||
private BattleStatus status;
|
||||
|
||||
public void Init(BattleStatus status) {
|
||||
this.status = status;
|
||||
public void InitStatus(BattleStatus status) {
|
||||
Sprite sprite = Resources.Load<Sprite>(GetStatusResourcePath(status));
|
||||
this.statusImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void InitBuff(BuffType buffType) {
|
||||
Sprite sprite = Resources.Load<Sprite>(GetBuffResourcePath(buffType));
|
||||
this.statusImage.sprite = sprite;
|
||||
}
|
||||
|
||||
private static string GetStatusResourcePath(BattleStatus status) {
|
||||
return "BattleIcons/StatusIcon" + status;
|
||||
}
|
||||
|
||||
private static string GetBuffResourcePath(BuffType buffType) {
|
||||
return "BattleIcons/BuffIcon" + buffType;
|
||||
}
|
||||
|
||||
public void SetAmount(int amount, int index) {
|
||||
this.turnsText.text = "" + amount;
|
||||
this.transform.localPosition = new Vector2(-index * 22, 0);
|
||||
|
|
|
|||
|
|
@ -10,14 +10,20 @@ public class StatusUI : MonoBehaviour
|
|||
public StatusIconUI iconPrefab;
|
||||
|
||||
private BattleParticipant battleParticipant;
|
||||
private BattleState battleState;
|
||||
|
||||
private Dictionary<BattleStatus, StatusIconUI> icons;
|
||||
private Dictionary<BattleStatus, StatusIconUI> statusIcons;
|
||||
|
||||
public void Init(BattleParticipant battleParticipant) {
|
||||
private Dictionary<BuffType, StatusIconUI> buffIcons;
|
||||
|
||||
public void Init(BattleParticipant battleParticipant, BattleState battleState) {
|
||||
this.battleParticipant = battleParticipant;
|
||||
this.battleState = battleState;
|
||||
|
||||
this.icons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusChanged;
|
||||
this.statusIcons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||
this.buffIcons = new Dictionary<BuffType, StatusIconUI>();
|
||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||
this.battleParticipant.OnBuffsChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
@ -25,10 +31,10 @@ public class StatusUI : MonoBehaviour
|
|||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public void NotifyBattleStatusChanged(BattleParticipant updatedParticipant) {
|
||||
public void NotifyBattleStatusOrBuffsChanged(BattleParticipant updatedParticipant) {
|
||||
if (updatedParticipant != this.battleParticipant) {
|
||||
throw new System.InvalidOperationException(
|
||||
"NotifyBattleStatusChanged was notified about a different participant.");
|
||||
"NotifyBattleStatusOrBuffsChanged was notified about a different participant.");
|
||||
}
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
|
@ -41,21 +47,44 @@ public class StatusUI : MonoBehaviour
|
|||
}
|
||||
|
||||
StatusIconUI iconUI = null;
|
||||
this.icons.TryGetValue(status, out iconUI);
|
||||
this.statusIcons.TryGetValue(status, out iconUI);
|
||||
if (this.battleParticipant.HasStatus(status)) {
|
||||
if (iconUI == null) {
|
||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||
iconUI.Init(status);
|
||||
this.icons[status] = iconUI;
|
||||
iconUI.InitStatus(status);
|
||||
this.statusIcons[status] = iconUI;
|
||||
}
|
||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index);
|
||||
index++;
|
||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index++);
|
||||
} else {
|
||||
if (iconUI != null) {
|
||||
Destroy(iconUI.gameObject);
|
||||
this.icons.Remove(status);
|
||||
this.statusIcons.Remove(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<BuffType, StatusIconUI> previousBuffIcons = new Dictionary<BuffType, StatusIconUI>(this.buffIcons);
|
||||
List<Buff> currentBuffs = this.battleState.BuffManager.GetAllBuffsFor(this.battleParticipant);
|
||||
|
||||
foreach (Buff buff in currentBuffs) {
|
||||
StatusIconUI iconUI = null;
|
||||
previousBuffIcons.TryGetValue(buff.Type, out iconUI);
|
||||
if (iconUI == null) {
|
||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||
iconUI.InitBuff(buff.Type);
|
||||
this.buffIcons[buff.Type] = iconUI;
|
||||
} else {
|
||||
previousBuffIcons.Remove(buff.Type);
|
||||
}
|
||||
iconUI.SetAmount(buff.Amount, index++);
|
||||
}
|
||||
|
||||
// If a buff is left in previousBuffIcons, it has been removed.
|
||||
foreach (KeyValuePair<BuffType, StatusIconUI> p in previousBuffIcons) {
|
||||
BuffType buffType = p.Key;
|
||||
StatusIconUI iconUI = p.Value;
|
||||
Destroy(iconUI.gameObject);
|
||||
this.buffIcons.Remove(buffType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue