Skip to content

Commit

Permalink
Finalize updates to target info view
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 3, 2024
1 parent 3161c06 commit 481f570
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 97 deletions.
35 changes: 15 additions & 20 deletions gui/hud/target_info.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extends VBoxContainer
extends PanelContainer

## Displays information and vitals about the ship that the player is targeting, if any.

@export var target_label: Label
@export var vitals_container: Container
@export var hull_bar: ProgressBar
@export var shield_bar: ProgressBar
@export var energy_bar: ProgressBar
@export var target_view: TargetView
@export var target_viewport: SubViewport
@export var hull_bar: TargetFillBar
@export var shield_bar: TargetFillBar
@export var pick_sound: AudioStreamPlayer

var _target: Ship = null
Expand All @@ -18,24 +18,27 @@ func _on_player_ship_target_changed(_player_ship: Ship, targeted_ship: Ship) ->
if self._target != null:
self._target.ship_hull_changed.disconnect(_on_target_ship_hull_changed)
self._target.ship_shield_changed.disconnect(_on_target_ship_shield_changed)
self._target.ship_energy_changed.disconnect(_on_target_ship_energy_changed)

self._target = targeted_ship

if targeted_ship == null:
self.target_label.text = "No target"
self.vitals_container.visible = false
self.target_label.text = "None"
self.target_view.visible = false
self.hull_bar.visible = false
self.shield_bar.visible = false
else:
self.pick_sound.play()
self.target_label.text = "Targeting: %s" % targeted_ship.name
self.vitals_container.visible = true
self.target_label.text = targeted_ship.name
self.target_view.mesh = targeted_ship.mesh_instance
self.target_viewport.render_target_update_mode = SubViewport.UPDATE_ONCE
self.target_view.visible = true
self.hull_bar.visible = true
self.shield_bar.visible = true

targeted_ship.ship_hull_changed.connect(_on_target_ship_hull_changed)
targeted_ship.ship_shield_changed.connect(_on_target_ship_shield_changed)
targeted_ship.ship_energy_changed.connect(_on_target_ship_energy_changed)
self._update_hull()
self._update_shield()
self._update_energy()

func _on_target_ship_hull_changed(ship: Ship) -> void:
assert(ship == self._target, "Should only be notified about changes to the target")
Expand All @@ -45,10 +48,6 @@ func _on_target_ship_shield_changed(ship: Ship) -> void:
assert(ship == self._target, "Should only be notified about changes to the target")
self._update_shield()

func _on_target_ship_energy_changed(ship: Ship) -> void:
assert(ship == self._target, "Should only be notified about changes to the target")
self._update_energy()

func _update_hull() -> void:
assert(self._target.ship_def.hull > 0.0, "Ship definition should not have 0 hull")
self.hull_bar.max_value = self._target.ship_def.hull
Expand All @@ -57,7 +56,3 @@ func _update_hull() -> void:
func _update_shield() -> void:
self.shield_bar.max_value = 1.0 if is_zero_approx(self._target.ship_def.shield) else self._target.ship_def.shield
self.shield_bar.value = self._target.shield

func _update_energy() -> void:
self.energy_bar.max_value = 1.0 if is_zero_approx(self._target.ship_def.energy) else self._target.ship_def.energy
self.energy_bar.value = self._target.energy
4 changes: 4 additions & 0 deletions gui/hud/target_view.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Node3D
class_name TargetView

@export var mesh: MeshInstance3D
6 changes: 4 additions & 2 deletions gui/hud/target_view.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://boit6owlfi3h"]
[gd_scene load_steps=6 format=3 uid="uid://boit6owlfi3h"]

[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="1_a2vil"]
[ext_resource type="Shader" path="res://fx/wireframe.gdshader" id="2_uts7q"]
[ext_resource type="Script" path="res://gui/hud/target_view.gd" id="1_bqomq"]
[ext_resource type="Shader" path="res://gui/hud/wireframe.gdshader" id="2_uts7q"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_yvqgq"]
render_priority = 0
Expand All @@ -15,6 +16,7 @@ ambient_light_color = Color(1, 1, 1, 1)
reflected_light_source = 1

[node name="TargetView" type="Node3D"]
script = ExtResource("1_bqomq")

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
Expand Down
File renamed without changes.
93 changes: 18 additions & 75 deletions main/game.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=50 format=3 uid="uid://sunhu71swcs2"]
[gd_scene load_steps=47 format=3 uid="uid://sunhu71swcs2"]

[ext_resource type="Script" path="res://utils/shader_precompiler.gd" id="1_kgmvv"]
[ext_resource type="Script" path="res://main/hyperspace_controller.gd" id="2_5gj7y"]
Expand All @@ -23,14 +23,11 @@
[ext_resource type="Shader" path="res://gui/shaders/circular_mask.gdshader" id="17_7nttd"]
[ext_resource type="Script" path="res://gui/hud/player_vitals.gd" id="17_kyl4x"]
[ext_resource type="Texture2D" uid="uid://cmyn742dooo0n" path="res://gui/hud/images/radar/radar_circles.png" id="17_qcub0"]
[ext_resource type="Texture2D" uid="uid://if0dthunxkns" path="res://gui/hud/images/IconHull.png" id="18_ie1l8"]
[ext_resource type="Texture2D" uid="uid://b1kk3dhk5ak4u" path="res://gui/hud/images/IconShield.png" id="19_0m5x5"]
[ext_resource type="Script" path="res://gui/hud/target_info.gd" id="20_4ebat"]
[ext_resource type="Texture2D" uid="uid://22uk26e8fbc0" path="res://gui/hud/images/player_vitals/bg.png" id="21_jwbi2"]
[ext_resource type="Script" path="res://gui/game_over.gd" id="22_g1tis"]
[ext_resource type="Script" path="res://gui/fps_counter.gd" id="23_ncnr7"]
[ext_resource type="Texture2D" uid="uid://c2nr462gj84yf" path="res://gui/hud/images/player_vitals/heading_bg.png" id="24_1nebg"]
[ext_resource type="Texture2D" uid="uid://dif27wf74itjw" path="res://gui/hud/images/IconEnergy.png" id="24_iwm5p"]
[ext_resource type="PackedScene" uid="uid://dl3xau7i06twf" path="res://gui/hud/vitals_fill_bar.tscn" id="25_qonn8"]
[ext_resource type="PackedScene" uid="uid://kqong7nrl4p2" path="res://galaxy/map/galaxy_map.tscn" id="28_oyaod"]
[ext_resource type="Texture2D" uid="uid://s173r8o180gv" path="res://gui/hud/images/target_info/target_bg.png" id="31_s52vq"]
Expand Down Expand Up @@ -348,78 +345,17 @@ layout_mode = 2
[node name="EnergyBar" parent="HUD/Sidebar/PlayerVitalsContainer/VBoxContainer/PlayerVitals" instance=ExtResource("25_qonn8")]
layout_mode = 2

[node name="TargetInfo" type="VBoxContainer" parent="HUD/Sidebar" node_paths=PackedStringArray("target_label", "vitals_container", "hull_bar", "shield_bar", "energy_bar", "pick_sound")]
layout_mode = 2
script = ExtResource("20_4ebat")
target_label = NodePath("TargetedShipName")
vitals_container = NodePath("TargetVitals")
hull_bar = NodePath("TargetVitals/HullBar")
shield_bar = NodePath("TargetVitals/ShieldBar")
energy_bar = NodePath("TargetVitals/EnergyBar")
pick_sound = NodePath("PickSound")

[node name="PickSound" type="AudioStreamPlayer" parent="HUD/Sidebar/TargetInfo"]
stream = ExtResource("16_q8d2x")
volume_db = -10.0

[node name="TargetedShipName" type="Label" parent="HUD/Sidebar/TargetInfo"]
layout_mode = 2
tooltip_text = "Targeted ship"
mouse_filter = 1
theme_type_variation = &"HUDLabel"
text = "No target"
horizontal_alignment = 1
text_overrun_behavior = 3
uppercase = true

[node name="TargetVitals" type="GridContainer" parent="HUD/Sidebar/TargetInfo"]
layout_mode = 2
columns = 2

[node name="HullIcon" type="TextureRect" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
tooltip_text = "Hull"
texture = ExtResource("18_ie1l8")
expand_mode = 2
stretch_mode = 4

[node name="HullBar" type="ProgressBar" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
size_flags_horizontal = 3
mouse_filter = 2
step = 2.08165e-12
value = 40.0

[node name="ShieldIcon" type="TextureRect" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
tooltip_text = "Shield"
texture = ExtResource("19_0m5x5")
expand_mode = 2
stretch_mode = 4

[node name="ShieldBar" type="ProgressBar" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
size_flags_horizontal = 3
mouse_filter = 2
step = 2.08165e-12

[node name="EnergyIcon" type="TextureRect" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
tooltip_text = "Shield"
texture = ExtResource("24_iwm5p")
expand_mode = 2
stretch_mode = 4

[node name="EnergyBar" type="ProgressBar" parent="HUD/Sidebar/TargetInfo/TargetVitals"]
layout_mode = 2
size_flags_horizontal = 3
mouse_filter = 2
step = 2.08165e-12

[node name="TargetInfoContainer" type="PanelContainer" parent="HUD/Sidebar"]
[node name="TargetInfoContainer" type="PanelContainer" parent="HUD/Sidebar" node_paths=PackedStringArray("target_label", "target_view", "target_viewport", "hull_bar", "shield_bar", "pick_sound")]
custom_minimum_size = Vector2(200, 194)
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxTexture_lc8il")
script = ExtResource("20_4ebat")
target_label = NodePath("VBoxContainer/HBoxContainer/TargetedShipLabel")
target_view = NodePath("VBoxContainer/SubViewportContainer/SubViewport/TargetView")
target_viewport = NodePath("VBoxContainer/SubViewportContainer/SubViewport")
hull_bar = NodePath("VBoxContainer/HullBar")
shield_bar = NodePath("VBoxContainer/ShieldBar")
pick_sound = NodePath("PickSound")

[node name="VBoxContainer" type="VBoxContainer" parent="HUD/Sidebar/TargetInfoContainer"]
layout_mode = 2
Expand Down Expand Up @@ -460,12 +396,14 @@ transparent_bg = true
handle_input_locally = false
msaa_3d = 2
gui_disable_input = true
size = Vector2i(171, 118)
size = Vector2i(171, 140)
render_target_update_mode = 4

[node name="TargetView" parent="HUD/Sidebar/TargetInfoContainer/VBoxContainer/SubViewportContainer/SubViewport" instance=ExtResource("33_v8kjk")]
visible = false

[node name="ShieldBar" parent="HUD/Sidebar/TargetInfoContainer/VBoxContainer" instance=ExtResource("33_oq34c")]
visible = false
layout_mode = 2
size_flags_vertical = 8

Expand All @@ -474,8 +412,13 @@ offset_right = 89.0
texture = ExtResource("34_ajn47")

[node name="HullBar" parent="HUD/Sidebar/TargetInfoContainer/VBoxContainer" instance=ExtResource("33_oq34c")]
visible = false
layout_mode = 2

[node name="PickSound" type="AudioStreamPlayer" parent="HUD/Sidebar/TargetInfoContainer"]
stream = ExtResource("16_q8d2x")
volume_db = -10.0

[node name="GameOverDialog" type="AcceptDialog" parent="HUD"]
scaling_3d_scale = 2.0
title = "Game Over"
Expand Down Expand Up @@ -537,7 +480,7 @@ galaxy = ExtResource("3_j76v0")
[connection signal="ship_energy_changed" from="Player" to="HUD/Sidebar/PlayerVitalsContainer/VBoxContainer/PlayerVitals" method="_on_player_ship_energy_changed"]
[connection signal="ship_hull_changed" from="Player" to="HUD/Sidebar/PlayerVitalsContainer/VBoxContainer/PlayerVitals" method="_on_player_ship_hull_changed"]
[connection signal="ship_shield_changed" from="Player" to="HUD/Sidebar/PlayerVitalsContainer/VBoxContainer/PlayerVitals" method="_on_player_ship_shield_changed"]
[connection signal="ship_target_changed" from="Player" to="HUD/Sidebar/TargetInfo" method="_on_player_ship_target_changed"]
[connection signal="ship_target_changed" from="Player" to="HUD/Sidebar/TargetInfoContainer" method="_on_player_ship_target_changed"]
[connection signal="item_selected" from="HUD/Sidebar/ControlSchemeButton" to="HUD/Sidebar/ControlSchemeButton" method="_on_item_selected"]
[connection signal="confirmed" from="HUD/GameOverDialog" to="HUD/GameOverDialog" method="_on_confirmed"]
[connection signal="close_requested" from="HUD/GalaxyMapWindow" to="HUD/GalaxyMapWindow/SubViewportContainer/SubViewport/GalaxyMap" method="_on_window_close_requested"]
Expand Down

0 comments on commit 481f570

Please sign in to comment.