1- using System . Collections ;
1+ using System . Collections ;
22using System . Collections . Generic ;
33using System . Reflection ;
44using UnityEngine ;
@@ -33,9 +33,10 @@ public class UIManager : MonoBehaviour
3333 private Text _selectedUnitTitleText ;
3434 private Text _selectedUnitLevelText ;
3535 private Transform _selectedUnitResourcesProductionParent ;
36+ private Transform _selectedUnitAttackParametersParent ;
3637 private Transform _selectedUnitActionButtonsParent ;
3738 private Unit _selectedUnit ;
38- private List < ResourceValue > _selectedUnitNextLevelCost ;
39+ public GameObject uiLabelPrefab ;
3940 public GameObject unitSkillButtonPrefab ;
4041
4142 public Transform selectionGroupsParent ;
@@ -76,9 +77,9 @@ private void Awake()
7677 _selectedUnitTitleText = selectedUnitMenuTransform . Find ( "UnitSpecific/Content/GeneralInfo/Title" ) . GetComponent < Text > ( ) ;
7778 _selectedUnitLevelText = selectedUnitMenuTransform . Find ( "UnitSpecific/Content/GeneralInfo/Level" ) . GetComponent < Text > ( ) ;
7879 _selectedUnitResourcesProductionParent = selectedUnitMenuTransform . Find ( "UnitSpecific/Content/ResourcesProduction" ) ;
80+ _selectedUnitAttackParametersParent = selectedUnitMenuTransform . Find ( "UnitSpecific/Content/AttackParameters" ) ;
7981 _selectedUnitActionButtonsParent = selectedUnitMenuTransform . Find ( "UnitSpecific/SpecificActions" ) ;
8082
81-
8283 placedBuildingProductionRectTransform . gameObject . SetActive ( false ) ;
8384
8485 gameSettingsPanel . SetActive ( false ) ;
@@ -189,17 +190,20 @@ public void HoverLevelUpButton()
189190 if ( _selectedUnit . LevelMaxedOut ) return ;
190191 _UpdateSelectedUnitLevelUpInfoPanel ( ) ;
191192 ShowInfoPanel ( true ) ;
193+ _SetSelectedUnitMenu ( _selectedUnit , true ) ;
192194 }
193195
194196 public void UnhoverLevelUpButton ( )
195197 {
198+ if ( _selectedUnit . LevelMaxedOut ) return ;
196199 ShowInfoPanel ( false ) ;
200+ _SetSelectedUnitMenu ( _selectedUnit ) ;
197201 }
198202
199203 public void ClickLevelUpButton ( )
200204 {
201205 _selectedUnit . LevelUp ( ) ;
202- _SetSelectedUnitMenu ( _selectedUnit ) ;
206+ _SetSelectedUnitMenu ( _selectedUnit , ! _selectedUnit . LevelMaxedOut ) ;
203207 if ( _selectedUnit . LevelMaxedOut )
204208 {
205209 selectedUnitMenuUpgradeButton . transform . Find ( "Text" ) . GetComponent < Text > ( ) . text = "Maxed out" ;
@@ -251,7 +255,7 @@ private void _CheckBuyLimits()
251255 _selectedUnit != null &&
252256 _selectedUnit . Owner == GameManager . instance . gamePlayersParameters . myPlayerId &&
253257 ! _selectedUnit . LevelMaxedOut &&
254- Globals . CanBuy ( _selectedUnitNextLevelCost )
258+ Globals . CanBuy ( _selectedUnit . LevelUpData . cost )
255259 )
256260 selectedUnitMenuUpgradeButton . GetComponent < Button > ( ) . interactable = true ;
257261
@@ -280,7 +284,11 @@ private void _CheckBuyLimits()
280284 private void _UpdateSelectedUnitLevelUpInfoPanel ( )
281285 {
282286 int nextLevel = _selectedUnit . Level + 1 ;
283- SetInfoPanel ( "Level up" , $ "Upgrade unit to level { nextLevel } ", _selectedUnitNextLevelCost ) ;
287+ SetInfoPanel (
288+ "Level up" ,
289+ $ "Upgrade unit to level { nextLevel } ",
290+ _selectedUnit . LevelUpData . cost
291+ ) ;
284292 }
285293
286294 private void _SetResourceText ( InGameResource resource , int value )
@@ -446,16 +454,17 @@ public void RemoveSelectedUnitFromUIList(string code)
446454 t . text = count . ToString ( ) ;
447455 }
448456
449- private void _SetSelectedUnitMenu ( Unit unit )
457+ private void _SetSelectedUnitMenu ( Unit unit , bool showUpgrade = false )
450458 {
451459 _selectedUnit = unit ;
452- _selectedUnitNextLevelCost = _selectedUnit . GetLevelUpCost ( ) ;
453460
454461 bool unitIsMine = unit . Owner == GameManager . instance . gamePlayersParameters . myPlayerId ;
455462
456463 // update texts
457464 _selectedUnitTitleText . text = unit . Data . unitName ;
458465 _selectedUnitLevelText . text = $ "Level { unit . Level } ";
466+
467+ // RESOURCE PRODUCTION --------------------------------------------
459468 // clear resource production
460469 foreach ( Transform child in _selectedUnitResourcesProductionParent )
461470 Destroy ( child . gameObject ) ;
@@ -467,11 +476,36 @@ private void _SetSelectedUnitMenu(Unit unit)
467476 {
468477 g = Instantiate ( gameResourceCostPrefab ) ;
469478 t = g . transform ;
470- t . Find ( "Text" ) . GetComponent < Text > ( ) . text = $ "+{ resource . Value } ";
479+ t . Find ( "Text" ) . GetComponent < Text > ( ) . text = showUpgrade
480+ ? $ "<color=#00ff00>+{ _selectedUnit . LevelUpData . newProduction [ resource . Key ] } </color>"
481+ : $ "+{ resource . Value } ";
471482 t . Find ( "Icon" ) . GetComponent < Image > ( ) . sprite = Resources . Load < Sprite > ( $ "Textures/GameResources/{ resource . Key } ") ;
472- t . SetParent ( _selectedUnitResourcesProductionParent ) ;
483+ t . SetParent ( _selectedUnitResourcesProductionParent , false ) ;
473484 }
474485 }
486+
487+ // ATTACK PARAMETERS ----------------------------------------------
488+ // clear attack parameters
489+ foreach ( Transform child in _selectedUnitAttackParametersParent )
490+ Destroy ( child . gameObject ) ;
491+ // reinstantiate new ones (if I own the unit)
492+ if ( unitIsMine )
493+ {
494+ GameObject g ;
495+ g = Instantiate ( uiLabelPrefab ) ;
496+ g . GetComponent < Text > ( ) . text = showUpgrade
497+ ? $ "Damage: <color=#00ff00>{ _selectedUnit . LevelUpData . newAttackDamage } </color>"
498+ : $ "Damage: { unit . AttackDamage } ";
499+ g . transform . SetParent ( _selectedUnitAttackParametersParent , false ) ;
500+
501+ g = Instantiate ( uiLabelPrefab ) ;
502+ g . GetComponent < Text > ( ) . text = showUpgrade
503+ ? $ "Range: <color=#00ff00>{ ( int ) _selectedUnit . LevelUpData . newAttackRange } </color>"
504+ : $ "Range: { ( int ) unit . AttackRange } ";
505+ g . transform . SetParent ( _selectedUnitAttackParametersParent , false ) ;
506+ }
507+
508+ // SKILLS ---------------------------------------------------------
475509 // clear skills
476510 foreach ( Transform child in _selectedUnitActionButtonsParent )
477511 Destroy ( child . gameObject ) ;
@@ -486,14 +520,14 @@ private void _SetSelectedUnitMenu(Unit unit)
486520 b = g . GetComponent < Button > ( ) ;
487521 unit . SkillManagers [ i ] . SetButton ( b ) ;
488522 t . Find ( "Text" ) . GetComponent < Text > ( ) . text = unit . SkillManagers [ i ] . skill . skillName ;
489- t . SetParent ( _selectedUnitActionButtonsParent ) ;
523+ t . SetParent ( _selectedUnitActionButtonsParent , false ) ;
490524 _AddUnitSkillButtonListener ( b , i ) ;
491525 }
492526 }
493527
494528 // if unit is mine, check if it can level up
495529 if ( unitIsMine )
496- selectedUnitMenuUpgradeButton . GetComponent < Button > ( ) . interactable = Globals . CanBuy ( _selectedUnitNextLevelCost ) ;
530+ selectedUnitMenuUpgradeButton . GetComponent < Button > ( ) . interactable = Globals . CanBuy ( _selectedUnit . LevelUpData . cost ) ;
497531
498532 // hide upgrade/destroy buttons if I don't own the building
499533 selectedUnitMenuUpgradeButton . SetActive ( unitIsMine ) ;
0 commit comments