diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-10-13 11:14:43 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-10-13 11:14:43 +0200 |
commit | e82990eeafdf0be5d42d8aaa9b7fb6091e0d8435 (patch) | |
tree | ced53c3ec6168c68e63ae1083f6c6a34f99f4fa1 /UI | |
parent | 0697f674ec33f8381ba68cf064732ee40e6e584f (diff) |
next commit
Diffstat (limited to 'UI')
-rw-r--r-- | UI/Camera.gd | 13 | ||||
-rw-r--r-- | UI/players_list.gd | 14 |
2 files changed, 20 insertions, 7 deletions
diff --git a/UI/Camera.gd b/UI/Camera.gd index 6c22d44..926ab36 100644 --- a/UI/Camera.gd +++ b/UI/Camera.gd @@ -2,6 +2,8 @@ class_name Camera extends Camera2D +signal zoomed(zoom: Vector2) + var is_in_drag_mode = false var drag_anchor = Vector2.ZERO @@ -17,28 +19,31 @@ func _ready(): get_viewport().size_changed.connect(func(): set_new_position(global_position) var new_zoom = Vector2( - get_rect().size.x / limit_right, - get_rect().size.y / limit_bottom + (limit_right - limit_left) / get_viewport_rect().size.x, + (limit_bottom - limit_top) / get_viewport_rect().size.y ) zoom = Vector2( new_zoom[new_zoom.max_axis_index()], new_zoom[new_zoom.max_axis_index()] ) + zoomed.emit(zoom) ) func _input(event): if event.is_action("camera_zoom_out"): var can_zoom_out = ( - limit_right / get_rect().end.x > 1.0 and - limit_bottom / get_rect().end.y > 1.0 + (limit_right - limit_left) / get_rect().size.x > 1.0 and + (limit_bottom - limit_top) / get_rect().size.y > 1.0 ) if can_zoom_out: var new_zoom = max(zoom.x - zoom_step, zoom_min) zoom = Vector2(new_zoom, new_zoom) + zoomed.emit(zoom) if event.is_action("camera_zoom_in"): var new_zoom = min(zoom.x + zoom_step, zoom_max) zoom = Vector2(new_zoom, new_zoom) + zoomed.emit(zoom) if event.is_action_pressed("camera_drag"): is_in_drag_mode = true diff --git a/UI/players_list.gd b/UI/players_list.gd index 6bb7e14..24df945 100644 --- a/UI/players_list.gd +++ b/UI/players_list.gd @@ -29,9 +29,17 @@ func update_players(): control.get_node("%ID").text = str(player.username) control.get_node("%ID").tooltip_text = str(player.id) control.get_node("%Score").text = str(player.income) - list.move_child(control, Network.get_ordered_player_ids().find(player.id) + 1) + list.move_child(control, Network.get_ordered_player_ids(players).find(player.id) + 1) func remove_player(id): - list.remove_child(list.get_node(str(id))) - #players.remove_at(players.filter(func(item): return item.id == id)[0]) TODO + # TODO: function is called twice for some reason? + + var node = list.get_node_or_null(str(id)) + if node: + list.remove_child(node) + + for idx in players.size(): + if players[idx].id == id: + players.remove_at(idx) + break |