From 176b18866f00b5bcd9fef613263591e9bff63efa Mon Sep 17 00:00:00 2001 From: kayomn Date: Tue, 31 Jan 2023 00:07:44 +0000 Subject: [PATCH] Add fill rect tool to interior map editor --- local_player.scn | 2 +- map_editor.scn | 4 +- map_editor/map_editor_menu.gd | 12 -- map_editor/selection_area_mesh.res | 3 + map_editor/tile_cursor.gdshader | 12 -- map_editor/tile_cursor.res | 3 - map_editor/tile_cursor_object_material.res | 3 + player_controller.gd | 136 ++++++++------------- 8 files changed, 63 insertions(+), 112 deletions(-) create mode 100644 map_editor/selection_area_mesh.res delete mode 100644 map_editor/tile_cursor.gdshader delete mode 100644 map_editor/tile_cursor.res create mode 100644 map_editor/tile_cursor_object_material.res diff --git a/local_player.scn b/local_player.scn index 870c0e9..f21c4f3 100644 --- a/local_player.scn +++ b/local_player.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15a2f8163652823e89dab5479d8d6c1ad1270cbb2fbd612c120c5ea1fdfdb275 +oid sha256:b4f0319e09b163eb3c6519b5c72c18ebfa85aac35304cf6b3530f2c0d679c73b size 679 diff --git a/map_editor.scn b/map_editor.scn index 2356e63..2cca5f0 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:087dc406cd7608983cdc48a7e702b252d8576d102b8cbdac11dc83a8799b9cda -size 11169 +oid sha256:50a5242649107880385206657657a9e77a285eef6a1c683e22210646cd97b7de +size 12700 diff --git a/map_editor/map_editor_menu.gd b/map_editor/map_editor_menu.gd index f4c15ca..38eddfd 100644 --- a/map_editor/map_editor_menu.gd +++ b/map_editor/map_editor_menu.gd @@ -1,17 +1,5 @@ class_name MapEditorMenu extends VBoxContainer -## -## [code]edit_action[/code] has been activated for use when the player interacts with the map -## editor. -## -signal edit_activated(edit_action: Callable) - -## -## Emits [signal edit_activated]. -## -func activate_editor(edit_action: Callable) -> void: - edit_activated.emit(edit_action) - ## ## Resets the state of the menu. ## diff --git a/map_editor/selection_area_mesh.res b/map_editor/selection_area_mesh.res new file mode 100644 index 0000000..d0f15ee --- /dev/null +++ b/map_editor/selection_area_mesh.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d30d1595da7c7bab44c9e72b88f8e0bfe946dff33e1a4903ab772104cd43657d +size 894 diff --git a/map_editor/tile_cursor.gdshader b/map_editor/tile_cursor.gdshader deleted file mode 100644 index e41f94c..0000000 --- a/map_editor/tile_cursor.gdshader +++ /dev/null @@ -1,12 +0,0 @@ -shader_type spatial; -render_mode unshaded, blend_add, cull_disabled; - -uniform sampler2D source_texture; - -uniform vec4 modulate: source_color = vec4(1.0); - -void fragment() { - vec4 source = texture(source_texture, UV); - ALBEDO = (source.rgb * modulate.rgb); - ALPHA = source.a; -} \ No newline at end of file diff --git a/map_editor/tile_cursor.res b/map_editor/tile_cursor.res deleted file mode 100644 index 2d23433..0000000 --- a/map_editor/tile_cursor.res +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1b9240206e13ccff017900a7262637147f1931f9e950e2c1b0efb45523e03bd5 -size 901 diff --git a/map_editor/tile_cursor_object_material.res b/map_editor/tile_cursor_object_material.res new file mode 100644 index 0000000..b053994 --- /dev/null +++ b/map_editor/tile_cursor_object_material.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be95f7bcacaedc1e942b999a970ce648cb7e4efdf04a16b5c9c4f6ff95039f54 +size 708 diff --git a/player_controller.gd b/player_controller.gd index 6e0185a..5f16ecc 100644 --- a/player_controller.gd +++ b/player_controller.gd @@ -4,7 +4,6 @@ class_name PlayerController extends Node3D ## ## enum SelectAction { - NONE, PRIMARY, SECONDARY, } @@ -25,7 +24,7 @@ signal select_mode_changed(mode: SelectMode) ## ## Selection of a point on screenspace has started happening. ## -signal selection_started() +signal selection_started(select_action: SelectAction) ## ## Selection of a point on screenspace has stopped happening. @@ -63,8 +62,6 @@ var _cursor_point := Vector2.ZERO var _is_drag_panning := false -var _select_action := SelectAction.NONE - var _select_mode := SelectMode.NONE @export @@ -76,58 +73,6 @@ var _target_position := position @onready var _target_orientation := global_rotation.y -func _input(event: InputEvent) -> void: - if event is InputEventMouseButton: - match event.button_index: - MOUSE_BUTTON_MIDDLE: - _is_drag_panning = event.is_pressed() and not(is_frozen()) - - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if\ - _is_drag_panning else Input.MOUSE_MODE_VISIBLE - - MOUSE_BUTTON_LEFT: - if event.is_pressed(): - _select_action = SelectAction.PRIMARY - - 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 - - if (event is InputEventMouseMotion) and _is_drag_panning: - var global_basis := global_transform.basis - var camera_settings := GameSettings.camera_settings - var dampened_speed := camera_settings.movement_speed_modifier * _DRAG_SPEED_BASE_MODIFIER - - _target_position += dampened_speed.y * (-global_basis.z) *\ - event.relative.y * (-1.0 if camera_settings.is_y_inverted else 1.0) - - _target_position += dampened_speed.x * (-global_basis.x) *\ - event.relative.x * (-1.0 if camera_settings.is_x_inverted else 1.0) - - return - - if event is InputEventScreenDrag: - return - - if event is InputEventScreenTouch: - return - func _process(delta: float) -> void: if not(is_frozen()): var global_basis := global_transform.basis @@ -173,6 +118,50 @@ func _ready() -> void: select_mode_changed.emit(SelectMode.NONE)) + _selection_area.gui_input.connect(func (event: InputEvent) -> void: + if event is InputEventMouseButton: + match event.button_index: + MOUSE_BUTTON_MIDDLE: + _is_drag_panning = event.is_pressed() and not(is_frozen()) + + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if\ + _is_drag_panning else Input.MOUSE_MODE_VISIBLE + + MOUSE_BUTTON_LEFT: + if event.is_pressed(): + selection_started.emit(SelectAction.PRIMARY) + + else: + selection_stopped.emit() + + MOUSE_BUTTON_RIGHT: + if event.is_pressed(): + selection_started.emit(SelectAction.SECONDARY) + + else: + selection_stopped.emit() + + return + + if (event is InputEventMouseMotion) and _is_drag_panning: + var global_basis := global_transform.basis + var camera_settings := GameSettings.camera_settings + var dampened_speed := camera_settings.movement_speed_modifier * _DRAG_SPEED_BASE_MODIFIER + + _target_position += dampened_speed.y * (-global_basis.z) *\ + event.relative.y * (-1.0 if camera_settings.is_y_inverted else 1.0) + + _target_position += dampened_speed.x * (-global_basis.x) *\ + event.relative.x * (-1.0 if camera_settings.is_x_inverted else 1.0) + + return + + if event is InputEventScreenDrag: + return + + if event is InputEventScreenTouch: + return) + ## ## Returns the position of the selection cursor with respect to the select current mode being used. ## @@ -180,8 +169,15 @@ func _ready() -> void: ## touchscreen interactions, this will be the location of an active gesture. Finally, for all other ## states - including gamepad - this will be the middle of screenspace at all times. ## -func get_cursor_point() -> Vector2: - return _cursor_point +func get_plane_cursor() -> Vector2: + if _camera != null: + var plane_cursor = Plane(Vector3.UP, 0.0).intersects_ray( + _camera.global_position, _camera.project_ray_normal(_cursor_point)) + + if plane_cursor is Vector3: + return Vector2(plane_cursor.x, plane_cursor.z) + + return Vector2.ZERO func is_frozen() -> bool: assert(_control_override_count > -1, "control override count cannot be less than 0") @@ -194,13 +190,6 @@ func is_frozen() -> bool: func in_select_area() -> bool: return _select_mode != SelectMode.NONE -## -## Returns the [code]SelectAction[/code] currently being performed, or -## [code]SelectAction.NONE[/code] if no action is currently being performed. -## -func get_select_action() -> SelectAction: - return _select_action - ## ## ## @@ -212,20 +201,3 @@ func override_controls(unlock_signal: Signal) -> void: unlock_signal.connect(func () -> void: assert(_control_override_count > 0, "control override count cannot be less than 1") _control_override_count -= 1, Object.CONNECT_ONE_SHOT) - -## -## Attempts to convert the screen coordinates in [code]screen_point[/code] into 2D worldspace -## coordinate relative to an infinite ground plane at y offset [code]0.0[/code]. -## -## Successful point intersection will return the plane coordinates in a [class Vector2], otherwise -## [code]null[/code] is returned. -## -func screen_to_plane(screen_point: Vector2) -> Variant: - if _camera != null: - var plane_target = Plane(Vector3.UP, 0.0).intersects_ray( - _camera.global_position, _camera.project_ray_normal(screen_point)) - - if plane_target is Vector3: - return Vector2(plane_target.x, plane_target.z) - - return null