From 4e0a62113fcddf9b2ac23911e6b2db800b147477 Mon Sep 17 00:00:00 2001 From: Krystian Jandy Date: Thu, 31 Aug 2023 22:16:50 +0200 Subject: [PATCH] chore: pr changes --- entity/object/agent/Agent.gd | 8 -------- ui.tscn | 1 + ui/AgentOptions.gd | 22 ++++++++++++++++++---- ui/UI.gd | 3 ++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/entity/object/agent/Agent.gd b/entity/object/agent/Agent.gd index e4f2dc34..640e8d77 100644 --- a/entity/object/agent/Agent.gd +++ b/entity/object/agent/Agent.gd @@ -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(): diff --git a/ui.tscn b/ui.tscn index f6a6beae..3ca63732 100644 --- a/ui.tscn +++ b/ui.tscn @@ -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 diff --git a/ui/AgentOptions.gd b/ui/AgentOptions.gd index 85038e98..043484a4 100644 --- a/ui/AgentOptions.gd +++ b/ui/AgentOptions.gd @@ -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 diff --git a/ui/UI.gd b/ui/UI.gd index a870d7cd..8a0ee59a 100644 --- a/ui/UI.gd +++ b/ui/UI.gd @@ -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()