1- using UnityEngine ;
21using UnityEngine . UIElements ;
32using BuildingPlacement . Buildings ;
43using VehicleSystem ;
@@ -7,22 +6,20 @@ namespace UISystem
76{
87 public class BuildingHUDController : GameHUDController
98 {
10- [ Header ( "Templates (UXML)" ) ]
11- public VisualTreeAsset mainStationTemplate ;
12- public VisualTreeAsset hangarTemplate ;
13- public VisualTreeAsset energyTowerTemplate ;
14-
15- protected VisualElement buildingDetailsPanel ;
9+ private VisualElement buildingDetailsPanel ;
10+
1611 private Label sharedBuildTypeLabel ;
1712 private Label sharedHealthLabel ;
1813
19- private Label msShieldLabel ;
14+ private VisualElement mainStationContent ;
15+ private VisualElement hangarContent ;
16+ private VisualElement energyTowerContent ;
2017
18+ private Label msShieldLabel ;
2119 private Label hIsReadyLabel ;
2220 private Label hProductionLabel ;
23-
2421 private Label etCapacityLabel ;
25- private Label etDensityLabel ;
22+ private Label etDensityLabel ;
2623
2724 protected Building currentlySelectedBuilding ;
2825
@@ -34,6 +31,27 @@ protected override void OnEnable()
3431 sharedBuildTypeLabel = root . Q < Label > ( "shared-build-type-label" ) ;
3532 sharedHealthLabel = root . Q < Label > ( "shared-health-label" ) ;
3633
34+ mainStationContent = root . Q < VisualElement > ( "main-station-content-area" ) ;
35+ hangarContent = root . Q < VisualElement > ( "hangar-content-area" ) ;
36+ energyTowerContent = root . Q < VisualElement > ( "energy-tower-content-area" ) ;
37+
38+ if ( mainStationContent != null )
39+ msShieldLabel = mainStationContent . Q < Label > ( "shield-label" ) ;
40+
41+ if ( energyTowerContent != null )
42+ {
43+ etCapacityLabel = energyTowerContent . Q < Label > ( "capacity-label" ) ;
44+ etDensityLabel = energyTowerContent . Q < Label > ( "density-label" ) ;
45+ }
46+
47+ if ( hangarContent != null )
48+ {
49+ hIsReadyLabel = hangarContent . Q < Label > ( "is-ready-label" ) ;
50+ hProductionLabel = hangarContent . Q < Label > ( "in-production-label" ) ;
51+
52+ BindHangarButtons ( ) ;
53+ }
54+
3755 var mainStationBtn = root . Q < Button > ( "main-station-button" ) ;
3856 var hangarBtn = root . Q < Button > ( "hangar-button" ) ;
3957 var energyTowerBtn = root . Q < Button > ( "energy-tower-button" ) ;
@@ -48,7 +66,6 @@ protected override void OnEnable()
4866 protected override void Update ( )
4967 {
5068 base . Update ( ) ;
51-
5269 if ( currentlySelectedBuilding != null && buildingDetailsPanel . style . display == DisplayStyle . Flex )
5370 {
5471 UpdateBuildingData ( ) ;
@@ -61,28 +78,20 @@ public void ShowBuildingDetails(Building building)
6178
6279 currentlySelectedBuilding = building ;
6380 sharedBuildTypeLabel . text = building . BuildingName ;
64-
65- buildingDynamicContentContainer . Clear ( ) ;
66-
81+
82+ HideAllContents ( ) ;
83+
6784 if ( building is MainStation )
6885 {
69- InstantiateTemplate ( mainStationTemplate ) ;
70- msShieldLabel = buildingDynamicContentContainer . Q < Label > ( "shield-label" ) ;
86+ if ( mainStationContent != null ) mainStationContent . style . display = DisplayStyle . Flex ;
7187 }
72- else if ( building is Hangar hangarScript )
88+ else if ( building is Hangar )
7389 {
74- InstantiateTemplate ( hangarTemplate ) ;
75-
76- hIsReadyLabel = buildingDynamicContentContainer . Q < Label > ( "is-ready-label" ) ;
77- hProductionLabel = buildingDynamicContentContainer . Q < Label > ( "in-production-label" ) ;
78-
79- SetupHangarButtons ( hangarScript ) ;
90+ if ( hangarContent != null ) hangarContent . style . display = DisplayStyle . Flex ;
8091 }
8192 else if ( building is EnergyTower )
8293 {
83- InstantiateTemplate ( energyTowerTemplate ) ;
84- etCapacityLabel = buildingDynamicContentContainer . Q < Label > ( "capacity-label" ) ;
85- etDensityLabel = buildingDynamicContentContainer . Q < Label > ( "density-label" ) ;
94+ if ( energyTowerContent != null ) energyTowerContent . style . display = DisplayStyle . Flex ;
8695 }
8796
8897 buildingDetailsPanel . style . display = DisplayStyle . Flex ;
@@ -95,6 +104,13 @@ public void HideBuildingDetails()
95104 buildingDetailsPanel . style . display = DisplayStyle . None ;
96105 }
97106
107+ private void HideAllContents ( )
108+ {
109+ if ( mainStationContent != null ) mainStationContent . style . display = DisplayStyle . None ;
110+ if ( hangarContent != null ) hangarContent . style . display = DisplayStyle . None ;
111+ if ( energyTowerContent != null ) energyTowerContent . style . display = DisplayStyle . None ;
112+ }
113+
98114 private void UpdateBuildingData ( )
99115 {
100116 if ( currentlySelectedBuilding == null ) return ;
@@ -103,56 +119,47 @@ private void UpdateBuildingData()
103119
104120 if ( currentlySelectedBuilding is MainStation ms )
105121 {
106- if ( msShieldLabel != null )
107- msShieldLabel . text = $ "Shield: { ms . ShieldAmount : F0} %";
122+ if ( msShieldLabel != null ) msShieldLabel . text = $ "Shield: { ms . ShieldAmount : F0} %";
108123 }
109124 else if ( currentlySelectedBuilding is Hangar hg )
110125 {
111- if ( hIsReadyLabel != null )
112- hIsReadyLabel . text = $ "Is Ready: { hg . IsReady } ";
113- if ( hProductionLabel != null )
114- hProductionLabel . text = $ "Prod: { hg . InProductionUnitName } ";
126+ if ( hIsReadyLabel != null ) hIsReadyLabel . text = $ "Is Ready: { hg . IsReady } ";
127+ if ( hProductionLabel != null ) hProductionLabel . text = $ "Prod: { hg . InProductionUnitName } ";
115128 }
116129 else if ( currentlySelectedBuilding is EnergyTower et )
117130 {
118- if ( etCapacityLabel != null )
119- etCapacityLabel . text = $ "Capacity: { et . GetStatus ( ) . current : F0} / { et . GetStatus ( ) . max : F0} ";
120- if ( etDensityLabel != null )
121- etDensityLabel . text = $ "Density: { et . GetStatus ( ) . count : F0} / { et . GetStatus ( ) . limit : F0} ";
131+ if ( etCapacityLabel != null ) etCapacityLabel . text = $ "Capacity: { et . GetStatus ( ) . current : F0} / { et . GetStatus ( ) . max : F0} ";
132+ if ( etDensityLabel != null ) etDensityLabel . text = $ "Density: { et . GetStatus ( ) . count : F0} / { et . GetStatus ( ) . limit : F0} ";
122133 }
123134 }
124135
125- private void SetupHangarButtons ( Hangar hangar )
136+ private void BindHangarButtons ( )
126137 {
127- void BindVehicleBtn ( string btnName , VehicleTypes type )
138+ if ( hangarContent == null ) return ;
139+
140+ void BindBtn ( string btnName , VehicleTypes type )
128141 {
129- Button btn = buildingDynamicContentContainer . Q < Button > ( btnName ) ;
130-
142+ Button btn = hangarContent . Q < Button > ( btnName ) ;
131143 if ( btn != null )
132144 {
133145 btn . clicked += ( ) =>
134146 {
135- hangar . CreateVehicle ( type ) ;
147+ if ( currentlySelectedBuilding is Hangar currentHangar )
148+ {
149+ currentHangar . CreateVehicle ( type ) ;
150+ }
136151 } ;
137152 }
138153 }
139154
140- BindVehicleBtn ( "infantry-create-button" , VehicleTypes . Infantry ) ;
141- BindVehicleBtn ( "trike-create-button" , VehicleTypes . Trike ) ;
142- BindVehicleBtn ( "quad-create-button" , VehicleTypes . Quad ) ;
143- BindVehicleBtn ( "tank-combat-create-button" , VehicleTypes . Tank_Combat ) ;
144- BindVehicleBtn ( "tank-heavy-a-create-button" , VehicleTypes . Tank_Heavy_A ) ;
145- BindVehicleBtn ( "tank-heavy-b-create-button" , VehicleTypes . Tank_Heavy_B ) ;
146- BindVehicleBtn ( "ornithopter-a-create-button" , VehicleTypes . Ornithopter_A ) ;
147- BindVehicleBtn ( "ornithopter-b-create-button" , VehicleTypes . Ornithopter_B ) ;
148- }
149-
150- private void InstantiateTemplate ( VisualTreeAsset template )
151- {
152- if ( template != null )
153- {
154- template . CloneTree ( buildingDynamicContentContainer ) ;
155- }
155+ BindBtn ( "infantry-create-button" , VehicleTypes . Infantry ) ;
156+ BindBtn ( "trike-create-button" , VehicleTypes . Trike ) ;
157+ BindBtn ( "quad-create-button" , VehicleTypes . Quad ) ;
158+ BindBtn ( "tank-combat-create-button" , VehicleTypes . Tank_Combat ) ;
159+ BindBtn ( "tank-heavy-a-create-button" , VehicleTypes . Tank_Heavy_A ) ;
160+ BindBtn ( "tank-heavy-b-create-button" , VehicleTypes . Tank_Heavy_B ) ;
161+ BindBtn ( "ornithopter-a-create-button" , VehicleTypes . Ornithopter_A ) ;
162+ BindBtn ( "ornithopter-b-create-button" , VehicleTypes . Ornithopter_B ) ;
156163 }
157164
158165 private void OnBuildingCategoryClicked ( string buildingName )
0 commit comments