From a9f7437d01b807fdd7e7e77eeb000210c2e9c85e Mon Sep 17 00:00:00 2001 From: kayomn Date: Sat, 28 Jan 2023 00:13:49 +0000 Subject: [PATCH] Add logic to right-click delete tiles --- local_player.scn | 2 +- map_editor.scn | 4 ++-- player_controller.gd | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/local_player.scn b/local_player.scn index 6e357be..870c0e9 100644 --- a/local_player.scn +++ b/local_player.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ee55ead59320730db7e2a7a301107fcf35900e9398f8f51e690849c51d59c295 +oid sha256:15a2f8163652823e89dab5479d8d6c1ad1270cbb2fbd612c120c5ea1fdfdb275 size 679 diff --git a/map_editor.scn b/map_editor.scn index 72f8168..2356e63 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0ba76d6fec225724ee1822d1cceaf41eba72051c84aa03e4c0d149fdabc2a0e0 -size 10986 +oid sha256:087dc406cd7608983cdc48a7e702b252d8576d102b8cbdac11dc83a8799b9cda +size 11169 diff --git a/player_controller.gd b/player_controller.gd index e9acec7..6e0185a 100644 --- a/player_controller.gd +++ b/player_controller.gd @@ -1,5 +1,14 @@ class_name PlayerController extends Node3D +## +## +## +enum SelectAction { + NONE, + PRIMARY, + SECONDARY, +} + ## ## Supported selection input devices. ## @@ -54,7 +63,7 @@ var _cursor_point := Vector2.ZERO var _is_drag_panning := false -var _is_selecting := false +var _select_action := SelectAction.NONE var _select_mode := SelectMode.NONE @@ -77,12 +86,25 @@ func _input(event: InputEvent) -> void: _is_drag_panning else Input.MOUSE_MODE_VISIBLE MOUSE_BUTTON_LEFT: - _is_selecting = event.is_pressed() + if event.is_pressed(): + _select_action = SelectAction.PRIMARY - if _is_selecting: selection_started.emit() else: + _select_action = SelectAction.NONE + + selection_stopped.emit() + + MOUSE_BUTTON_RIGHT: + if event.is_pressed(): + _select_action = SelectAction.SECONDARY + + selection_started.emit() + + else: + _select_action = SelectAction.NONE + selection_stopped.emit() return @@ -173,14 +195,11 @@ func in_select_area() -> bool: return _select_mode != SelectMode.NONE ## -## Returns [code]true[/code] if the player controller is currently selecting a location on the -## screen, otherwise [code]false[/code]. +## Returns the [code]SelectAction[/code] currently being performed, or +## [code]SelectAction.NONE[/code] if no action is currently being performed. ## -## *Note* that it is discouraged that this be continuously polled for single-fire events. Instead, -## see [signal selection_started] and [signal selection_stopped]. -## -func is_selecting() -> bool: - return _is_selecting +func get_select_action() -> SelectAction: + return _select_action ## ##