Skip to content

Commit 6ac6218

Browse files
committed
Refactor HUD UI to use inline content areas
Removed separate UXML files for building details and integrated all building-specific content areas directly into GameHUD. Updated BuildingHUDController to show/hide inline content areas instead of instantiating templates. Improved picking logic and UI styles for better interaction. Added Hangar prefab to BluePlanetArea scene.
1 parent af6e870 commit 6ac6218

13 files changed

+248
-160
lines changed

Red Strike/Assets/InputController/InputController.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ private bool IsPointerOverUI()
7777
{
7878
if (gameUIDocument == null) return false;
7979

80-
Vector2 mousePosition = Input.mousePosition;
81-
Vector2 pointerPosition = new Vector2(mousePosition.x, Screen.height - mousePosition.y);
82-
VisualElement pickedElement = gameUIDocument.rootVisualElement.panel.Pick(pointerPosition);
80+
Vector2 panelLocalPos = RuntimePanelUtils.ScreenToPanel(gameUIDocument.rootVisualElement.panel, Input.mousePosition);
81+
VisualElement pickedElement = gameUIDocument.rootVisualElement.panel.Pick(panelLocalPos);
8382

8483
if (pickedElement == null) return false;
8584
if (pickedElement.name == "root-container") return false;

Red Strike/Assets/Scenes/BluePlanetArea.unity

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,6 +5662,63 @@ ParticleSystem:
56625662
m_PostInfinity: 2
56635663
m_RotationOrder: 4
56645664
vectorLabel1_3: W
5665+
--- !u!1001 &1769253995
5666+
PrefabInstance:
5667+
m_ObjectHideFlags: 0
5668+
serializedVersion: 2
5669+
m_Modification:
5670+
serializedVersion: 3
5671+
m_TransformParent: {fileID: 0}
5672+
m_Modifications:
5673+
- target: {fileID: 2490931318532185407, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5674+
propertyPath: m_Name
5675+
value: Hangar
5676+
objectReference: {fileID: 0}
5677+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5678+
propertyPath: m_LocalPosition.x
5679+
value: 273.18265
5680+
objectReference: {fileID: 0}
5681+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5682+
propertyPath: m_LocalPosition.y
5683+
value: 0.000015258789
5684+
objectReference: {fileID: 0}
5685+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5686+
propertyPath: m_LocalPosition.z
5687+
value: 2.567276
5688+
objectReference: {fileID: 0}
5689+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5690+
propertyPath: m_LocalRotation.w
5691+
value: 1
5692+
objectReference: {fileID: 0}
5693+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5694+
propertyPath: m_LocalRotation.x
5695+
value: 0
5696+
objectReference: {fileID: 0}
5697+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5698+
propertyPath: m_LocalRotation.y
5699+
value: 0
5700+
objectReference: {fileID: 0}
5701+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5702+
propertyPath: m_LocalRotation.z
5703+
value: 0
5704+
objectReference: {fileID: 0}
5705+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5706+
propertyPath: m_LocalEulerAnglesHint.x
5707+
value: 0
5708+
objectReference: {fileID: 0}
5709+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5710+
propertyPath: m_LocalEulerAnglesHint.y
5711+
value: 0
5712+
objectReference: {fileID: 0}
5713+
- target: {fileID: 8996551972402132310, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
5714+
propertyPath: m_LocalEulerAnglesHint.z
5715+
value: 0
5716+
objectReference: {fileID: 0}
5717+
m_RemovedComponents: []
5718+
m_RemovedGameObjects: []
5719+
m_AddedGameObjects: []
5720+
m_AddedComponents: []
5721+
m_SourcePrefab: {fileID: 100100000, guid: 4b5c1b1b00d4a804aaaa616ab88ccd5f, type: 3}
56655722
--- !u!1 &1936849618
56665723
GameObject:
56675724
m_ObjectHideFlags: 0
@@ -5914,3 +5971,4 @@ SceneRoots:
59145971
- {fileID: 2126698098}
59155972
- {fileID: 1454141292}
59165973
- {fileID: 387184704}
5974+
- {fileID: 1769253995}

Red Strike/Assets/UISystem/BuildingHUDController.cs

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using UnityEngine;
21
using UnityEngine.UIElements;
32
using BuildingPlacement.Buildings;
43
using 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)

Red Strike/Assets/UISystem/EnergyTowerDetailsContent.uxml

Lines changed: 0 additions & 7 deletions
This file was deleted.

Red Strike/Assets/UISystem/EnergyTowerDetailsContent.uxml.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

Red Strike/Assets/UISystem/GameHUD.uxml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,78 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:engine="UnityEngine.UIElements" editor-extension-mode="False">
2+
<!-- Stil Dosyası Bağlantısı -->
23
<Style src="project://database/Assets/UI%20Toolkit/GameHUDStyles.uss?fileID=7433441132597879392&amp;guid=76481a45a761bb147acf1059658d7ddd&amp;type=3#GameHUDStyles" />
3-
<ui:VisualElement name="root-container" style="width: 100%; height: 100%;">
4+
5+
<!-- ROOT CONTAINER -->
6+
<!-- picking-mode="Ignore" yaptık ki ekrandaki boş yerlere tıklayınca oyun algılasın. -->
7+
<ui:VisualElement name="root-container" picking-mode="Ignore" style="width: 100%; height: 100%;">
48

59
<!-- TOP BAR -->
6-
<ui:VisualElement name="top-bar-container" class="top-bar" />
10+
<ui:VisualElement name="top-bar-container" class="top-bar" picking-mode="Position" />
711

8-
<!-- SIDE PANEL (LEFT) -->
9-
<ui:VisualElement name="left-panel" class="side-panel">
12+
<!-- LEFT PANEL (Bina Seçim Menüsü) -->
13+
<!-- picking-mode="Position" sayesinde buraya tıklayınca arkaya geçmez -->
14+
<ui:VisualElement name="left-panel" class="side-panel" picking-mode="Position">
1015
<ui:Button text="Main Station" name="main-station-button" class="build-button" />
1116
<ui:Button text="Hangar" name="hangar-button" class="build-button" />
1217
<ui:Button text="Energy Tower" name="energy-tower-button" class="build-button" />
1318
</ui:VisualElement>
1419

15-
<!-- BUILDING DETAILS PANEL (RIGHT) -->
16-
<ui:VisualElement name="building-details-panel" class="info-panel" visible="false">
20+
<!-- RIGHT PANEL 1: BUILDING DETAILS (Bina Bilgi Paneli) -->
21+
<!-- picking-mode="Position" eklendi. Panele tıklayınca kapanmaz. -->
22+
<ui:VisualElement name="building-details-panel" class="info-panel" visible="false" picking-mode="Position">
23+
24+
<!-- Ortak Başlıklar -->
1725
<ui:Label text="Build Type:" name="shared-build-type-label" class="details-title" />
1826
<ui:Label text="Health:" name="shared-health-label" class="details-text" />
27+
28+
<!-- AYIRICI ÇİZGİ (Opsiyonel) -->
29+
<ui:VisualElement style="height: 1px; background-color: rgb(100, 100, 100); margin-top: 5px; margin-bottom: 5px;" />
30+
31+
<!-- İÇERİK ALANI (Tüm bina türleri burada, kod ile açıp kapatacağız) -->
32+
<ui:VisualElement name="building-dynamic-content-container">
33+
34+
<!-- 1. MAIN STATION CONTENT -->
35+
<!-- Varsayılan olarak gizli (display: none) -->
36+
<ui:VisualElement name="main-station-content-area" style="display: none;">
37+
<ui:Label text="Shield:" name="shield-label" class="details-text" />
38+
</ui:VisualElement>
1939

20-
<!-- CONTENT AREA (dynamic) -->
21-
<ui:VisualElement name="building-dynamic-content-container" class="dynamic-content" />
40+
<!-- 2. ENERGY TOWER CONTENT -->
41+
<ui:VisualElement name="energy-tower-content-area" style="display: none;">
42+
<ui:Label text="Capacity:" name="capacity-label" class="details-text" />
43+
<ui:Label text="Density:" name="density-label" class="details-text" />
44+
</ui:VisualElement>
45+
46+
<!-- 3. HANGAR CONTENT -->
47+
<ui:VisualElement name="hangar-content-area" style="display: none;">
48+
<ui:Label text="Is Ready:" name="is-ready-label" class="details-text" />
49+
<ui:Label text="In production:" name="in-production-label" class="details-text" />
50+
51+
<ui:ScrollView mode="Vertical" style="max-height: 300px;">
52+
<ui:Button text="Create Infantry" name="infantry-create-button" class="action-button" />
53+
<ui:Button text="Create Trike" name="trike-create-button" class="action-button" />
54+
<ui:Button text="Create Quad" name="quad-create-button" class="action-button" />
55+
<ui:Button text="Create Tank Combat" name="tank-combat-create-button" class="action-button" />
56+
<ui:Button text="Create Tank Heavy A" name="tank-heavy-a-create-button" class="action-button" />
57+
<ui:Button text="Create Tank Heavy B" name="tank-heavy-b-create-button" class="action-button" />
58+
<ui:Button text="Create Ornithopter A" name="ornithopter-a-create-button" class="action-button" />
59+
<ui:Button text="Create Ornithopter B" name="ornithopter-b-create-button" class="action-button" />
60+
</ui:ScrollView>
61+
</ui:VisualElement>
62+
63+
</ui:VisualElement>
2264
</ui:VisualElement>
2365

24-
<!-- VEHICLE DETAILS PANEL (RIGHT) -->
25-
<ui:VisualElement name="vehicle-details-panel" class="info-panel" visible="false">
66+
67+
<!-- RIGHT PANEL 2: VEHICLE DETAILS (Araç Bilgi Paneli) -->
68+
<ui:VisualElement name="vehicle-details-panel" class="info-panel" visible="false" picking-mode="Position">
2669
<ui:Label text="Vehicle:" name="shared-vehicle-name-label" class="details-title" />
2770
<ui:Label text="Health:" name="shared-vehicle-health-label" class="details-text" />
2871
<ui:Label text="Fuel:" name="shared-vehicle-fuel-label" class="details-text" />
2972
<ui:Label text="Ammunition:" name="shared-vehicle-ammo-label" class="details-text" />
3073
<ui:Label text="Target:" name="shared-vehicle-target-label" class="details-text" />
3174

32-
<!-- CONTENT AREA (dynamic) -->
75+
<!-- Araçlara özel ekstra içerik gerekirse buraya eklenebilir -->
3376
<ui:VisualElement name="vehicle-dynamic-content-container" class="dynamic-content" />
3477
</ui:VisualElement>
3578

0 commit comments

Comments
 (0)