Scale UI correctly
This commit is contained in:
parent
34aad42ba7
commit
30beb96397
3 changed files with 23 additions and 17 deletions
|
|
@ -179,14 +179,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
this.monsterCardDatabase, mCardIds.Cast<int>().ToArray(), mCardOwners);
|
this.monsterCardDatabase, mCardIds.Cast<int>().ToArray(), mCardOwners);
|
||||||
|
|
||||||
this.playArea = new PlayArea();
|
this.playArea = new PlayArea();
|
||||||
|
|
||||||
this.heroHandPlayability = new HandPlayability<HeroCard>(
|
this.heroHandPlayability = new HandPlayability<HeroCard>(
|
||||||
this.state, this.heroEnergy, TeamChoice.Heroes, this.heroDeck);
|
this.state, this.heroEnergy, TeamChoice.Heroes, this.heroDeck);
|
||||||
this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged;
|
this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged;
|
||||||
|
|
||||||
this.battlePlayerControls.Init(
|
this.battlePlayerControls.Init(
|
||||||
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
|
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
|
||||||
this.heroHandPlayability);
|
this.heroHandPlayability, this.uiCanvas.transform.localScale.x);
|
||||||
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
|
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
|
||||||
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
|
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
|
||||||
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
private BattleDeck<MonsterCard> monsterDeck;
|
private BattleDeck<MonsterCard> monsterDeck;
|
||||||
private PlayArea playArea;
|
private PlayArea playArea;
|
||||||
private InsightLevel insightLevel;
|
private InsightLevel insightLevel;
|
||||||
|
private float scale;
|
||||||
|
|
||||||
private HandControls<HeroCard> heroHandControls;
|
private HandControls<HeroCard> heroHandControls;
|
||||||
private HandControls<MonsterCard> monsterHandControls;
|
private HandControls<MonsterCard> monsterHandControls;
|
||||||
|
|
@ -28,18 +29,20 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
|
|
||||||
public void Init(
|
public void Init(
|
||||||
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
|
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
|
||||||
InsightLevel insightLevel, HandPlayability<HeroCard> heroHandPlayability) {
|
InsightLevel insightLevel, HandPlayability<HeroCard> heroHandPlayability, float scale) {
|
||||||
this.heroDeck = heroDeck;
|
this.heroDeck = heroDeck;
|
||||||
this.monsterDeck = monsterDeck;
|
this.monsterDeck = monsterDeck;
|
||||||
this.playArea = playArea;
|
this.playArea = playArea;
|
||||||
this.insightLevel = insightLevel;
|
this.insightLevel = insightLevel;
|
||||||
|
this.scale = scale;
|
||||||
|
|
||||||
this.heroHandControls = new HandControls<HeroCard>(
|
this.heroHandControls = new HandControls<HeroCard>(
|
||||||
heroDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom, TeamChoice.Heroes,
|
heroDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom,
|
||||||
int.MaxValue, heroHandPlayability);
|
TeamChoice.Heroes, int.MaxValue, heroHandPlayability, this.scale);
|
||||||
this.heroHandControls.OnCardClicked += OnHeroCardClicked;
|
this.heroHandControls.OnCardClicked += OnHeroCardClicked;
|
||||||
this.monsterHandControls = new HandControls<MonsterCard>(
|
this.monsterHandControls = new HandControls<MonsterCard>(
|
||||||
monsterDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Top, TeamChoice.Monsters, 1, null);
|
monsterDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Top,
|
||||||
|
TeamChoice.Monsters, 1, null, this.scale);
|
||||||
this.monsterHandControls.OnCardClicked += OnMonsterCardClicked;
|
this.monsterHandControls.OnCardClicked += OnMonsterCardClicked;
|
||||||
this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>();
|
this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>();
|
||||||
|
|
||||||
|
|
@ -135,12 +138,12 @@ public class BattlePlayerControls : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 CalculatePlayAreaCardPosition(int index, int count) {
|
private Vector3 CalculatePlayAreaCardPosition(int index, int count) {
|
||||||
const int SPACING = 8;
|
float SPACING = 8 * this.scale;
|
||||||
const int DELTA = BattleCardPrefabConstants.CARD_HEIGHT + SPACING;
|
float DELTA = (BattleCardPrefabConstants.CARD_HEIGHT + SPACING) * this.scale;
|
||||||
const int PADDING = 8;
|
float PADDING = 8 * this.scale;
|
||||||
|
|
||||||
return new Vector3(PADDING + BattleCardPrefabConstants.CARD_WIDTH / 2,
|
return new Vector3(PADDING + BattleCardPrefabConstants.CARD_WIDTH * this.scale / 2,
|
||||||
Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT / 2,
|
Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2,
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,11 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
||||||
private TeamChoice team;
|
private TeamChoice team;
|
||||||
private int insightLevel;
|
private int insightLevel;
|
||||||
private HandPlayability<BaseCardT> playability;
|
private HandPlayability<BaseCardT> playability;
|
||||||
|
private float scale;
|
||||||
|
|
||||||
public HandControls(BattleDeck<BaseCardT> deck, GameObject uiCanvas, GameObject cardPrefab, HandControlsPosition position,
|
public HandControls(BattleDeck<BaseCardT> deck, GameObject uiCanvas, GameObject cardPrefab,
|
||||||
TeamChoice team, int insightLevel, HandPlayability<BaseCardT> playability) {
|
HandControlsPosition position, TeamChoice team, int insightLevel,
|
||||||
|
HandPlayability<BaseCardT> playability, float scale) {
|
||||||
this.deck = deck;
|
this.deck = deck;
|
||||||
this.uiCanvas = uiCanvas;
|
this.uiCanvas = uiCanvas;
|
||||||
this.cardPrefab = cardPrefab;
|
this.cardPrefab = cardPrefab;
|
||||||
|
|
@ -34,6 +36,7 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.insightLevel = insightLevel;
|
this.insightLevel = insightLevel;
|
||||||
this.playability = playability;
|
this.playability = playability;
|
||||||
|
this.scale = scale;
|
||||||
|
|
||||||
deck.OnHandPileChanged += this.UpdateState;
|
deck.OnHandPileChanged += this.UpdateState;
|
||||||
|
|
||||||
|
|
@ -43,13 +46,13 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 CalculateHandCardPosition(int index, int count) {
|
private Vector3 CalculateHandCardPosition(int index, int count) {
|
||||||
const int SPACING = 8;
|
float SPACING = 0 * this.scale;
|
||||||
const int DELTA = BattleCardPrefabConstants.CARD_WIDTH + SPACING;
|
float DELTA = BattleCardPrefabConstants.CARD_WIDTH * this.scale + SPACING;
|
||||||
|
|
||||||
float x = Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index;
|
float x = Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index;
|
||||||
float y = (this.position == HandControlsPosition.Bottom
|
float y = (this.position == HandControlsPosition.Bottom
|
||||||
? SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2
|
? SPACING + BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2
|
||||||
: Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT / 2);
|
: Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2);
|
||||||
|
|
||||||
return new Vector3(x, y, 0);
|
return new Vector3(x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue