Skip to content

Commit

Permalink
Somewhat working selection state
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Aug 23, 2024
1 parent 13340d1 commit 4b63ed7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
75 changes: 33 additions & 42 deletions galaxy/map/galaxy_map.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,35 @@ var hyperdrive_system: HyperdriveSystem
## Maps from each [member StarSystem.name] to the [GalaxyMapSystem] used to represent it.
var _system_nodes: Dictionary = {}

## Line used to display the jump path
#var _jump_path_line: ImmediateGeometry3D
## Maps from a hyperlane's name to the [GalaxyMapHyperlane] used to represent it.
##
## Hyperlane names are formatted as "from > to".
var _hyperlane_nodes: Dictionary = {}

func _ready() -> void:
self.hyperdrive_system.jumping_changed.connect(_on_jumping_changed)
self.hyperdrive_system.jump_path_changed.connect(_on_jump_path_changed)

#_jump_path_line = ImmediateGeometry3D.new()
#_jump_path_line.material_override = StandardMaterial3D.new()
#_jump_path_line.material_override.albedo_color = Color(0, 1, 0, 0.5) # Semi-transparent green
#_jump_path_line.material_override.flags_unshaded = true
#_jump_path_line.material_override.flags_transparent = true
#galaxy_map_3d.add_child(_jump_path_line)

var current_system := self.hyperdrive_system.current_system()

for system in galaxy.systems:
var system_node: GalaxyMapSystem = self.galaxy_map_system.instantiate()
self._system_nodes[system.name] = system_node
system_node.clicked.connect(func(node: GalaxyMapSystem) -> void: self._on_system_clicked(system, node))

system_node.name = system.name
system_node.current = (system == current_system)
self._system_nodes[system.name] = system_node
self.galaxy_map_3d.add_child(system_node)

system_node.transform.origin = system.position

for connection in system.connections:
var connected_system := self.galaxy.get_system(connection)
var hyperlane: GalaxyMapHyperlane = self.galaxy_map_hyperlane.instantiate()
hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node))

# hyperlane.clicked.connect(func(node: GalaxyMapHyperlane) -> void: self._on_hyperlane_clicked(system, connected_system, node))
hyperlane.name = "%s > %s" % [system.name, connection]
hyperlane.starting_position = system.position
hyperlane.ending_position = connected_system.position
self._hyperlane_nodes[hyperlane.name] = hyperlane
self.galaxy_map_3d.add_child(hyperlane)

self._update_selection_state()
Expand All @@ -88,27 +82,24 @@ func _on_jump_path_changed(_hyperdrive_system: HyperdriveSystem) -> void:
assert(self.hyperdrive_system == _hyperdrive_system)
self._update_selection_state()

#func _update_jump_path_line() -> void:
# _jump_path_line.clear()
# _jump_path_line.begin(Mesh.PRIMITIVE_LINE_STRIP)
#
# var current_system = self.hyperdrive_system.current_system()
# _jump_path_line.add_vertex(current_system.position)
#
# for system in self.hyperdrive_system.jump_path:
# _jump_path_line.add_vertex(system.position)
#
# _jump_path_line.end()

func _update_selection_state() -> void:
var jump_path := self.hyperdrive_system.get_jump_path()
var jump_names := jump_path.map(func(system: StarSystem) -> StringName: return system.name)
for system_name: String in self._system_nodes:
var node: GalaxyMapSystem = self._system_nodes[system_name]
node.selected = system_name in jump_names

for hyperlane_name: String in self._hyperlane_nodes:
var node: GalaxyMapHyperlane = self._hyperlane_nodes[hyperlane_name]
node.selected = false

var presented_system: StarSystem
if jump_path:
for i in range(0, jump_path.size()):
var last_name := jump_path[i - 1].name if i > 0 else self.hyperdrive_system.current_system().name
var hyperlane_name := "%s > %s" % [last_name, jump_path[i].name]
self._hyperlane_nodes[hyperlane_name].selected = true

presented_system = jump_path[-1]
self.current_or_destination_heading.text = "Destination system"
else:
Expand Down Expand Up @@ -213,20 +204,20 @@ func _replace_single_path(star_system: StarSystem) -> void:

self.hyperdrive_system.set_jump_path([star_system])

func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void:
if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping:
return

var current_system := self.hyperdrive_system.current_system()
var connection: StarSystem
if from_system == current_system:
connection = to_system
elif to_system == current_system:
connection = from_system
else:
return

if Input.is_key_pressed(KEY_SHIFT):
self.hyperdrive_system.add_to_jump_path(connection)
else:
self.hyperdrive_system.set_jump_path([connection])
# func _on_hyperlane_clicked(from_system: StarSystem, to_system: StarSystem, _hyperlane_node: GalaxyMapHyperlane) -> void:
# if not is_instance_valid(self.hyperdrive_system) or self.hyperdrive_system.jumping:
# return

# var current_system := self.hyperdrive_system.current_system()
# var connection: StarSystem
# if from_system == current_system:
# connection = to_system
# elif to_system == current_system:
# connection = from_system
# else:
# return

# if Input.is_key_pressed(KEY_SHIFT):
# self.hyperdrive_system.add_to_jump_path(connection)
# else:
# self.hyperdrive_system.set_jump_path([connection])
9 changes: 9 additions & 0 deletions galaxy/map/galaxy_map_hyperlane.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class_name GalaxyMapHyperlane
## This is expected to have a [CylinderMesh] attached.
@export var mesh: MeshInstance3D

## When [member selected] is true, this material overrides the [member mesh]'s material.
@export var selected_material: Material

## Whether this hyperlane is selected.
@export var selected: bool:
set(value):
selected = value
self.mesh.material_override = self.selected_material if value else null

## The shape defining the clickable region of this hyperlane.
##
## This is expected to have a [CylinderShape3D] attached.
Expand Down
4 changes: 3 additions & 1 deletion galaxy/map/galaxy_map_hyperlane.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://d3lphosly5y8b"]
[gd_scene load_steps=6 format=3 uid="uid://d3lphosly5y8b"]

[ext_resource type="Script" path="res://galaxy/map/galaxy_map_hyperlane.gd" id="1_qtr5l"]
[ext_resource type="Material" uid="uid://wjykkjty1dt5" path="res://galaxy/map/galaxy_map_current_mat.tres" id="2_xrjew"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_futeo"]
emission = Color(1, 1, 1, 1)
Expand All @@ -20,6 +21,7 @@ radius = 0.1
[node name="Hyperlane" type="StaticBody3D" node_paths=PackedStringArray("mesh", "collision_shape", "debugging_label")]
script = ExtResource("1_qtr5l")
mesh = NodePath("MeshInstance3D")
selected_material = ExtResource("2_xrjew")
collision_shape = NodePath("CollisionShape3D")
debugging_label = NodePath("DebuggingLabel")
node_radius = 0.1
Expand Down
4 changes: 2 additions & 2 deletions screens/game/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ script = ExtResource("11_ag0i7")
max_volume = 10.0
commodities = {}

[sub_resource type="Resource" id="Resource_kn2lj"]
[sub_resource type="Resource" id="Resource_0g6jc"]
resource_local_to_scene = true
script = ExtResource("13_q2g24")
max_fuel = 6.0
Expand Down Expand Up @@ -183,7 +183,7 @@ hull = SubResource("Resource_ffax2")
shield = SubResource("Resource_75c8j")
battery = SubResource("Resource_xpwk4")
cargo_hold = SubResource("Resource_bsv1l")
hyperdrive = SubResource("Resource_kn2lj")
hyperdrive = SubResource("Resource_0g6jc")

[node name="CombatObject" parent="HyperspaceSceneSwitcher/Sol/PlayerCorvette" index="3" node_paths=PackedStringArray("targeted_sound")]
targeted_sound = NodePath("../Player/TargetedSound")
Expand Down

0 comments on commit 4b63ed7

Please sign in to comment.