Do not bundle multiple buffs in UI
This commit is contained in:
parent
034e6beca6
commit
58da527ad5
3 changed files with 32 additions and 16 deletions
|
|
@ -10,15 +10,19 @@ public class StatusIconUI : MonoBehaviour
|
||||||
public Text turnsText;
|
public Text turnsText;
|
||||||
|
|
||||||
private BattleStatus status;
|
private BattleStatus status;
|
||||||
|
private Buff buff;
|
||||||
|
|
||||||
public void InitStatus(BattleStatus status) {
|
public void InitStatus(BattleStatus status) {
|
||||||
|
this.status = status;
|
||||||
Sprite sprite = Resources.Load<Sprite>(GetStatusResourcePath(status));
|
Sprite sprite = Resources.Load<Sprite>(GetStatusResourcePath(status));
|
||||||
this.statusImage.sprite = sprite;
|
this.statusImage.sprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitBuff(BuffType buffType) {
|
public void InitBuff(Buff buff) {
|
||||||
Sprite sprite = Resources.Load<Sprite>(GetBuffResourcePath(buffType));
|
this.buff = buff;
|
||||||
|
Sprite sprite = Resources.Load<Sprite>(GetBuffResourcePath(buff.Type));
|
||||||
this.statusImage.sprite = sprite;
|
this.statusImage.sprite = sprite;
|
||||||
|
this.SetNumber(buff.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetStatusResourcePath(BattleStatus status) {
|
private static string GetStatusResourcePath(BattleStatus status) {
|
||||||
|
|
@ -29,8 +33,18 @@ public class StatusIconUI : MonoBehaviour
|
||||||
return "BattleIcons/BuffIcon" + buffType;
|
return "BattleIcons/BuffIcon" + buffType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAmount(int amount, int index) {
|
public void UpdateStatusAmount(int amount) {
|
||||||
this.turnsText.text = "" + amount;
|
if (this.status == BattleStatus.None) {
|
||||||
|
throw new System.Exception();
|
||||||
|
}
|
||||||
|
this.SetNumber(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int index) {
|
||||||
this.transform.localPosition = new Vector2(-index * 22, 0);
|
this.transform.localPosition = new Vector2(-index * 22, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetNumber(int number) {
|
||||||
|
this.turnsText.text = "" + number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ public class StatusUI : MonoBehaviour
|
||||||
|
|
||||||
private Dictionary<BattleStatus, StatusIconUI> statusIcons;
|
private Dictionary<BattleStatus, StatusIconUI> statusIcons;
|
||||||
|
|
||||||
private Dictionary<BuffType, StatusIconUI> buffIcons;
|
private Dictionary<Buff, StatusIconUI> buffIcons;
|
||||||
|
|
||||||
public void Init(BattleParticipant battleParticipant, BattleState battleState) {
|
public void Init(BattleParticipant battleParticipant, BattleState battleState) {
|
||||||
this.battleParticipant = battleParticipant;
|
this.battleParticipant = battleParticipant;
|
||||||
this.battleState = battleState;
|
this.battleState = battleState;
|
||||||
|
|
||||||
this.statusIcons = new Dictionary<BattleStatus, StatusIconUI>();
|
this.statusIcons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||||
this.buffIcons = new Dictionary<BuffType, StatusIconUI>();
|
this.buffIcons = new Dictionary<Buff, StatusIconUI>();
|
||||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusOrBuffsChanged;
|
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||||
this.battleParticipant.OnBuffsChanged += this.NotifyBattleStatusOrBuffsChanged;
|
this.battleParticipant.OnBuffsChanged += this.NotifyBattleStatusOrBuffsChanged;
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,8 @@ public class StatusUI : MonoBehaviour
|
||||||
iconUI.InitStatus(status);
|
iconUI.InitStatus(status);
|
||||||
this.statusIcons[status] = iconUI;
|
this.statusIcons[status] = iconUI;
|
||||||
}
|
}
|
||||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index++);
|
iconUI.UpdateStatusAmount(this.battleParticipant.GetStatusAmount(status));
|
||||||
|
iconUI.SetPosition(index++);
|
||||||
} else {
|
} else {
|
||||||
if (iconUI != null) {
|
if (iconUI != null) {
|
||||||
Destroy(iconUI.gameObject);
|
Destroy(iconUI.gameObject);
|
||||||
|
|
@ -63,28 +64,28 @@ public class StatusUI : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<BuffType, StatusIconUI> previousBuffIcons = new Dictionary<BuffType, StatusIconUI>(this.buffIcons);
|
Dictionary<Buff, StatusIconUI> previousBuffIcons = new Dictionary<Buff, StatusIconUI>(this.buffIcons);
|
||||||
List<Buff> currentBuffs = this.battleState.BuffManager.GetAllBuffsFor(this.battleParticipant);
|
List<Buff> currentBuffs = this.battleState.BuffManager.GetAllBuffsFor(this.battleParticipant);
|
||||||
|
|
||||||
foreach (Buff buff in currentBuffs) {
|
foreach (Buff buff in currentBuffs) {
|
||||||
StatusIconUI iconUI = null;
|
StatusIconUI iconUI = null;
|
||||||
previousBuffIcons.TryGetValue(buff.Type, out iconUI);
|
previousBuffIcons.TryGetValue(buff, out iconUI);
|
||||||
if (iconUI == null) {
|
if (iconUI == null) {
|
||||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||||
iconUI.InitBuff(buff.Type);
|
iconUI.InitBuff(buff);
|
||||||
this.buffIcons[buff.Type] = iconUI;
|
this.buffIcons[buff] = iconUI;
|
||||||
} else {
|
} else {
|
||||||
previousBuffIcons.Remove(buff.Type);
|
previousBuffIcons.Remove(buff);
|
||||||
}
|
}
|
||||||
iconUI.SetAmount(buff.Amount, index++);
|
iconUI.SetPosition(index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a buff is left in previousBuffIcons, it has been removed.
|
// If a buff is left in previousBuffIcons, it has been removed.
|
||||||
foreach (KeyValuePair<BuffType, StatusIconUI> p in previousBuffIcons) {
|
foreach (KeyValuePair<Buff, StatusIconUI> p in previousBuffIcons) {
|
||||||
BuffType buffType = p.Key;
|
Buff buff = p.Key;
|
||||||
StatusIconUI iconUI = p.Value;
|
StatusIconUI iconUI = p.Value;
|
||||||
Destroy(iconUI.gameObject);
|
Destroy(iconUI.gameObject);
|
||||||
this.buffIcons.Remove(buffType);
|
this.buffIcons.Remove(buff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
TODO.txt
1
TODO.txt
|
|
@ -12,6 +12,7 @@ Battle
|
||||||
- No need to start coroutine for targeting
|
- No need to start coroutine for targeting
|
||||||
- Indicate which Default is triggering
|
- Indicate which Default is triggering
|
||||||
- Merge BattleClock with BattleState
|
- Merge BattleClock with BattleState
|
||||||
|
- Do not bundle together buffs of the same type that have different durations
|
||||||
|
|
||||||
Story
|
Story
|
||||||
- Make dialogue show letter by letter.
|
- Make dialogue show letter by letter.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue