From 30beb963973ea9b637e0b617259a51a77b075478 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Sat, 26 Sep 2020 16:43:30 -0400 Subject: [PATCH] Scale UI correctly --- Assets/Battle/BattleController.cs | 4 ++-- Assets/Battle/BattlePlayerControls.cs | 21 ++++++++++++--------- Assets/Battle/HandControls.cs | 15 +++++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 8819f66..cd395b3 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -179,14 +179,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.monsterCardDatabase, mCardIds.Cast().ToArray(), mCardOwners); this.playArea = new PlayArea(); - + this.heroHandPlayability = new HandPlayability( this.state, this.heroEnergy, TeamChoice.Heroes, this.heroDeck); this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged; this.battlePlayerControls.Init( this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel, - this.heroHandPlayability); + this.heroHandPlayability, this.uiCanvas.transform.localScale.x); this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed; this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed; this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged; diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 75f2dd4..2adffeb 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -21,6 +21,7 @@ public class BattlePlayerControls : MonoBehaviour private BattleDeck monsterDeck; private PlayArea playArea; private InsightLevel insightLevel; + private float scale; private HandControls heroHandControls; private HandControls monsterHandControls; @@ -28,18 +29,20 @@ public class BattlePlayerControls : MonoBehaviour public void Init( BattleDeck heroDeck, BattleDeck monsterDeck, PlayArea playArea, - InsightLevel insightLevel, HandPlayability heroHandPlayability) { + InsightLevel insightLevel, HandPlayability heroHandPlayability, float scale) { this.heroDeck = heroDeck; this.monsterDeck = monsterDeck; this.playArea = playArea; this.insightLevel = insightLevel; + this.scale = scale; this.heroHandControls = new HandControls( - heroDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom, TeamChoice.Heroes, - int.MaxValue, heroHandPlayability); + heroDeck, this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom, + TeamChoice.Heroes, int.MaxValue, heroHandPlayability, this.scale); this.heroHandControls.OnCardClicked += OnHeroCardClicked; this.monsterHandControls = new HandControls( - 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.cardsInPlayUIs = new Dictionary(); @@ -135,12 +138,12 @@ public class BattlePlayerControls : MonoBehaviour } private Vector3 CalculatePlayAreaCardPosition(int index, int count) { - const int SPACING = 8; - const int DELTA = BattleCardPrefabConstants.CARD_HEIGHT + SPACING; - const int PADDING = 8; + float SPACING = 8 * this.scale; + float DELTA = (BattleCardPrefabConstants.CARD_HEIGHT + SPACING) * this.scale; + float PADDING = 8 * this.scale; - return new Vector3(PADDING + BattleCardPrefabConstants.CARD_WIDTH / 2, - Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT / 2, + return new Vector3(PADDING + BattleCardPrefabConstants.CARD_WIDTH * this.scale / 2, + Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2, 0); } diff --git a/Assets/Battle/HandControls.cs b/Assets/Battle/HandControls.cs index 1a2ae93..d6cd921 100644 --- a/Assets/Battle/HandControls.cs +++ b/Assets/Battle/HandControls.cs @@ -24,9 +24,11 @@ public class HandControls where BaseCardT : BaseCard private TeamChoice team; private int insightLevel; private HandPlayability playability; + private float scale; - public HandControls(BattleDeck deck, GameObject uiCanvas, GameObject cardPrefab, HandControlsPosition position, - TeamChoice team, int insightLevel, HandPlayability playability) { + public HandControls(BattleDeck deck, GameObject uiCanvas, GameObject cardPrefab, + HandControlsPosition position, TeamChoice team, int insightLevel, + HandPlayability playability, float scale) { this.deck = deck; this.uiCanvas = uiCanvas; this.cardPrefab = cardPrefab; @@ -34,6 +36,7 @@ public class HandControls where BaseCardT : BaseCard this.team = team; this.insightLevel = insightLevel; this.playability = playability; + this.scale = scale; deck.OnHandPileChanged += this.UpdateState; @@ -43,13 +46,13 @@ public class HandControls where BaseCardT : BaseCard } private Vector3 CalculateHandCardPosition(int index, int count) { - const int SPACING = 8; - const int DELTA = BattleCardPrefabConstants.CARD_WIDTH + SPACING; + float SPACING = 0 * this.scale; + float DELTA = BattleCardPrefabConstants.CARD_WIDTH * this.scale + SPACING; float x = Screen.width * 0.5f - DELTA / 2 * (count - 1) + DELTA * index; float y = (this.position == HandControlsPosition.Bottom - ? SPACING + BattleCardPrefabConstants.CARD_HEIGHT / 2 - : Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT / 2); + ? SPACING + BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2 + : Screen.height - SPACING - BattleCardPrefabConstants.CARD_HEIGHT * this.scale / 2); return new Vector3(x, y, 0); }