Skip to content

Commit

Permalink
chore: pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Jandy committed Aug 31, 2023
1 parent 9f54972 commit 4e0a621
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 0 additions & 8 deletions entity/object/agent/Agent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ func init(_position, _id, _owner, _tick):
self._id = _id
self._owner = _owner
self._tick = _tick

func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
var tile_position: Vector2 = Globals.WORLD_UPDATER.tilemap.local_to_map(get_global_mouse_position())
if tile_position.is_equal_approx(self._position):
agent_options.on_agent_clicked(self._id)
elif agent_options.panel_is_visible():
agent_options.hide_panel()

# TODO: move to Entity
func serialize():
Expand Down
1 change: 1 addition & 0 deletions ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ offset_bottom = 68.0
text = "Delete"

[node name="VBoxContainer" type="VBoxContainer" parent="AgentOptions/AgentOptionsPanel"]
layout_mode = 0
offset_left = 2.0
offset_top = 1.0
offset_right = 142.0
Expand Down
22 changes: 18 additions & 4 deletions ui/AgentOptions.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
extends Control

@onready var agent_id_to_delete: int = -1
@onready var id_of_agent_to_delete: int = -1


func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
var tooltips = get_owner().tooltips
var objects_on_tile = Globals.WORLD_UPDATER.objects_container.get_objects_by_position(tooltips.tile_position)
var agent = objects_on_tile.filter(func(obj): return obj["_type"] == "Agent")
if agent.size() > 0:
# Get the first agent object (assuming there's only one)
agent = agent[0]
self.show_panel(agent._id)
elif self.panel_is_visible():
# If no agent is found and the panel is currently visible we hide the panel
self.hide_panel()

func _ready():
get_node("AgentOptionsPanel").hide()

func on_agent_clicked(agent_id_to_delete):
self.agent_id_to_delete = agent_id_to_delete
func show_panel(id_of_agent_to_delete):
self.id_of_agent_to_delete = id_of_agent_to_delete
get_node("AgentOptionsPanel").visible = true
get_node("AgentOptionsPanel/VBoxContainer/AgentIdLabel").text = "Agent {id}".format({"id": str(agent_id_to_delete)})
get_node("AgentOptionsPanel/VBoxContainer/AgentIdLabel").text = "Agent {id}".format({"id": str(id_of_agent_to_delete)})

func panel_is_visible():
return get_node("AgentOptionsPanel").visible
Expand Down
3 changes: 2 additions & 1 deletion ui/UI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func _on_mouse_exited():
self.enable_camera_movement.emit()

func _on_delete_agent_button_up():
self.delete_agent_requested.emit(int(self.agent_options.agent_id_to_delete))
var id_of_agent_to_delete = int(self.agent_options.id_of_agent_to_delete)
self.delete_agent_requested.emit(id_of_agent_to_delete)
self.agent_options.hide_panel()

0 comments on commit 4e0a621

Please sign in to comment.