Implement Meditate

This commit is contained in:
henriquenakashima 2020-09-22 01:09:20 -04:00
parent 03ca23d484
commit ceb46f98b2
14 changed files with 207 additions and 28 deletions

View file

@ -18,6 +18,7 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
private GameObject cardPrefab;
private HandControlsPosition position;
private List<BaseCardT> hand;
private List<GameObject> cardsInHandUIs;
private int insightLevel;
@ -30,27 +31,8 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
}
public void SetHand(List<BaseCardT> hand) {
if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
GameObject.Destroy(cardInHandUI);
}
}
this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < hand.Count; i++) {
BaseCardT card = hand[i];
GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);
CardUI cardUIScript = cardUI.GetComponent<CardUI>();
if (i < this.insightLevel) {
cardUIScript.Init(card);
} else {
cardUIScript.InitHidden();
}
int cardIndex = i;
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
}
this.hand = hand;
DrawHand();
}
private Vector3 CalculateHandCardPosition(int index, int count) {
@ -65,5 +47,39 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
return new Vector3(x, y, 0);
}
public int InsightLevel {get => this.insightLevel; set => this.insightLevel = value;}
public int InsightLevel {
get => this.insightLevel;
set {
this.insightLevel = value;
DrawHand();
}
}
private void DrawHand() {
if (this.hand == null) {
return;
}
if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
GameObject.Destroy(cardInHandUI);
}
}
this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < this.hand.Count; i++) {
BaseCardT card = this.hand[i];
GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, this.hand.Count);
CardUI cardUIScript = cardUI.GetComponent<CardUI>();
if (i < this.insightLevel) {
cardUIScript.Init(card);
} else {
cardUIScript.InitHidden();
}
int cardIndex = i;
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
}
}
}