Make HeroHandControls into generic HandControls

This commit is contained in:
henriquenakashima 2020-09-20 14:17:54 -04:00
parent 5456958651
commit fb453702ba
3 changed files with 8 additions and 8 deletions

View file

@ -21,7 +21,7 @@ public class BattlePlayerControls : MonoBehaviour
private BattleDeck<MonsterCard> monsterDeck; private BattleDeck<MonsterCard> monsterDeck;
private PlayArea playArea; private PlayArea playArea;
private HeroHandControls heroHandControls; private HandControls<HeroCard> heroHandControls;
private Dictionary<BaseCard, GameObject> cardsInPlayUIs; private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
public void Init( public void Init(
@ -30,7 +30,7 @@ public class BattlePlayerControls : MonoBehaviour
this.monsterDeck = monsterDeck; this.monsterDeck = monsterDeck;
this.playArea = playArea; this.playArea = playArea;
this.heroHandControls = new HeroHandControls(this, this.uiCanvas, this.cardPrefab); this.heroHandControls = new HandControls<HeroCard>(this.uiCanvas, this.cardPrefab);
this.heroHandControls.OnCardClicked += OnCardClicked; this.heroHandControls.OnCardClicked += OnCardClicked;
this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>(); this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>();
} }

View file

@ -4,9 +4,9 @@ using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class HeroHandControls public class HandControls<BaseCardT> where BaseCardT : BaseCard
{ {
public delegate void CardClickedAction(HeroCard card); public delegate void CardClickedAction(BaseCardT card);
public event CardClickedAction OnCardClicked; public event CardClickedAction OnCardClicked;
private GameObject uiCanvas; private GameObject uiCanvas;
@ -14,12 +14,12 @@ public class HeroHandControls
private List<GameObject> cardsInHandUIs; private List<GameObject> cardsInHandUIs;
public HeroHandControls(GameObject uiCanvas, GameObject cardPrefab) { public HandControls(GameObject uiCanvas, GameObject cardPrefab) {
this.uiCanvas = uiCanvas; this.uiCanvas = uiCanvas;
this.cardPrefab = cardPrefab; this.cardPrefab = cardPrefab;
} }
public void SetHeroHand(List<HeroCard> hand) { public void SetHeroHand(List<BaseCardT> hand) {
if (this.cardsInHandUIs != null) { if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) { foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
GameObject.Destroy(cardInHandUI); GameObject.Destroy(cardInHandUI);
@ -28,7 +28,7 @@ public class HeroHandControls
this.cardsInHandUIs = new List<GameObject>(); this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < hand.Count; i++) { for (int i = 0; i < hand.Count; i++) {
HeroCard card = hand[i]; BaseCardT card = hand[i];
GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform); GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI); this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: ca9b72ece27ba0c44890f16beba3bbbb guid: 69de07a1c92b9ac48be57f4c81189075
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2