From 422361b278584e9af7f406723d9374dff5965898 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 11:37:49 +0000 Subject: [PATCH 01/12] Fix TerrainInstance size limits --- editor.scn | 4 ++-- project.godot | 9 +++++++++ terrain_instance_3d.gd | 17 +++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/editor.scn b/editor.scn index 0226e59..a239f0b 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4d2a991052e7d0bfb3cb39dbcc6b609a97c192e36c4aa916602edba30e8bcbef -size 5163 +oid sha256:02382b8b2ed646e3bd9a8d0a88db4b36a31ff1c0fa4a865a83d00d676cf80032 +size 5157 diff --git a/project.godot b/project.godot index a9234d7..7e196d1 100644 --- a/project.godot +++ b/project.godot @@ -53,6 +53,15 @@ window/size/viewport_height=800 window/stretch/mode="canvas_items" window/stretch/aspect="keep_height" +[editor] + +version_control/plugin_name="GitPlugin" +version_control/autoload_on_startup=true + +[editor_plugins] + +enabled=PackedStringArray() + [input] player_controller_left={ diff --git a/terrain_instance_3d.gd b/terrain_instance_3d.gd index 9680b6f..4cc1949 100644 --- a/terrain_instance_3d.gd +++ b/terrain_instance_3d.gd @@ -1,6 +1,8 @@ @tool class_name TerrainInstance3D extends GeometryInstance3D +const _TERRAIN_MAX := 1024 + var _mesh := PlaneMesh.new() var _material := ShaderMaterial.new() @@ -14,18 +16,22 @@ var size: Vector2i = Vector2i.ZERO: return size set(value): - var width := value.x - var height := value.y + var width := clampi(value.x, 0, _TERRAIN_MAX) + var height := clampi(value.y, 0, _TERRAIN_MAX) - if (width != 0) and (height != 0): - if (width != size.x) or (height != size.y): + if (width != size.x) or (height != size.y): + if (width == 0) and (height == 0): + RenderingServer.instance_set_base(self.get_instance(), RID()) + + else: self._mesh.subdivide_width = width self._mesh.subdivide_depth = height self._mesh.size = value self._material.set_shader_parameter("SIZE", Vector2(value)) + RenderingServer.instance_set_base(self.get_instance(), self._mesh) - size = value + size = Vector2i(width, height) ## ## @@ -161,4 +167,3 @@ func _init() -> void: self._material.shader = preload("res://terrain_shader.gdshader") self._mesh.surface_set_material(0, self._material) - RenderingServer.instance_set_base(self.get_instance(), self._mesh) From c061864c37707c095cc713d1766daa82a1815bfb Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 11:38:32 +0000 Subject: [PATCH 02/12] Unlock TerrainInstance max limit --- editor.scn | 4 ++-- terrain_instance_3d.gd | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/editor.scn b/editor.scn index a239f0b..3607fde 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:02382b8b2ed646e3bd9a8d0a88db4b36a31ff1c0fa4a865a83d00d676cf80032 -size 5157 +oid sha256:dc85a13d73a13b929c60194ca0d20b1967359cc24ad23c8f21fa0070583ee44a +size 5156 diff --git a/terrain_instance_3d.gd b/terrain_instance_3d.gd index 4cc1949..8fb01b2 100644 --- a/terrain_instance_3d.gd +++ b/terrain_instance_3d.gd @@ -1,8 +1,6 @@ @tool class_name TerrainInstance3D extends GeometryInstance3D -const _TERRAIN_MAX := 1024 - var _mesh := PlaneMesh.new() var _material := ShaderMaterial.new() @@ -16,8 +14,8 @@ var size: Vector2i = Vector2i.ZERO: return size set(value): - var width := clampi(value.x, 0, _TERRAIN_MAX) - var height := clampi(value.y, 0, _TERRAIN_MAX) + var width := maxi(value.x, 0) + var height := maxi(value.y, 0) if (width != size.x) or (height != size.y): if (width == 0) and (height == 0): From c3c9a9dab68d5ef0ce6410027315f92b904c7cb8 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 12:08:25 +0000 Subject: [PATCH 03/12] Add terrain creation wizard --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index 3607fde..cbfdd2e 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dc85a13d73a13b929c60194ca0d20b1967359cc24ad23c8f21fa0070583ee44a -size 5156 +oid sha256:127d9f46e3a8d4754ba357218616196a40017550e8214216f2ea834196722be8 +size 5719 From 9acfdcb16ba34770bca2b629525ea2a435f97ed5 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 13:51:53 +0000 Subject: [PATCH 04/12] Add 'new map' button --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index cbfdd2e..499204a 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:127d9f46e3a8d4754ba357218616196a40017550e8214216f2ea834196722be8 -size 5719 +oid sha256:6830d81cc5265bc7eae2624c302193b0d18be2fa26357ba8e7de5c8dd6f5c53f +size 5699 From a20c7ff70d05fdfbefea46e729d50af1b2e29704 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 16:58:58 +0000 Subject: [PATCH 05/12] Increase detail of terrain geometry --- editor.scn | 4 ++-- terrain_instance_3d.gd | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/editor.scn b/editor.scn index 499204a..22cbbd1 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6830d81cc5265bc7eae2624c302193b0d18be2fa26357ba8e7de5c8dd6f5c53f -size 5699 +oid sha256:1d23430381d6bda8ab5902db48de4e58977a7d35b3733d6051a3dc0f7ad58496 +size 5726 diff --git a/terrain_instance_3d.gd b/terrain_instance_3d.gd index 8fb01b2..f70fcaa 100644 --- a/terrain_instance_3d.gd +++ b/terrain_instance_3d.gd @@ -1,6 +1,8 @@ @tool class_name TerrainInstance3D extends GeometryInstance3D +const _DETAIL := 2 + var _mesh := PlaneMesh.new() var _material := ShaderMaterial.new() @@ -22,14 +24,14 @@ var size: Vector2i = Vector2i.ZERO: RenderingServer.instance_set_base(self.get_instance(), RID()) else: - self._mesh.subdivide_width = width - self._mesh.subdivide_depth = height + self._mesh.subdivide_width = width * _DETAIL + self._mesh.subdivide_depth = height * _DETAIL self._mesh.size = value self._material.set_shader_parameter("SIZE", Vector2(value)) RenderingServer.instance_set_base(self.get_instance(), self._mesh) - size = Vector2i(width, height) + size = value ## ## From 58d9a0b8c55f344a3c006eeccfba33528c3c427d Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 16:59:32 +0000 Subject: [PATCH 06/12] Fix default editor terrain size --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index 22cbbd1..f981287 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1d23430381d6bda8ab5902db48de4e58977a7d35b3733d6051a3dc0f7ad58496 -size 5726 +oid sha256:bc97a5eafcfcdc41b4b8f30c3366395aadcb76856608319e4e96b3af9245ee45 +size 5706 From 0dc5288e452b6a078e3aa28dc6ca08fe91063ef0 Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 00:43:23 +0000 Subject: [PATCH 07/12] Fix player controller incompatibility with editor menus --- editor.scn | 4 +- player_controller.gd | 160 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 139 insertions(+), 25 deletions(-) diff --git a/editor.scn b/editor.scn index f981287..257901e 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bc97a5eafcfcdc41b4b8f30c3366395aadcb76856608319e4e96b3af9245ee45 -size 5706 +oid sha256:392d7f7fd33af54d9027b2455b59f74c54b1629a48ba6a8cab3ab2584c9a9d38 +size 6198 diff --git a/player_controller.gd b/player_controller.gd index 9568283..cb556ca 100644 --- a/player_controller.gd +++ b/player_controller.gd @@ -1,5 +1,28 @@ class_name PlayerController extends Node3D +## +## Supported selection input devices. +## +enum SelectMode { + NONE, + MOUSE, +} + +## +## The device being used for selection has changed. +## +signal select_mode_changed(mode: SelectMode) + +## +## Selection of a point on screenspace has started happening. +## +signal selection_started() + +## +## Selection of a point on screenspace has stopped happening. +## +signal selection_stopped() + const _BACKWARD := "player_controller_backward" const _FORWARD := "player_controller_forward" @@ -20,29 +43,54 @@ const _ROTATE_SPEED_BASE := 5.0 const _TRANSFORM_DELTA := 10.0 +@export +var _camera: Camera3D = null + +var _cursor_point := Vector2.ZERO + var _is_drag_panning := false +var _is_selecting := false + +var _select_mode := SelectMode.NONE + +@export +var _selection_area: Control = null + @onready var _target_position := self.position @onready var _target_orientation := self.global_rotation.y +## +## Smoothness applies to the interpolation toward rotation and movement target values. +## @export var movement_smoothing := 0.5 +## +## Whether or not player movement input processed by the controller should be ignored. +## +var frozen := false + func _input(event: InputEvent) -> void: if event is InputEventMouseButton: match event.button_index: MOUSE_BUTTON_MIDDLE: - self._is_drag_panning = event.is_pressed() - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if self._is_drag_panning else Input.MOUSE_MODE_VISIBLE + self._is_drag_panning = event.is_pressed() and not(self.frozen) - MOUSE_BUTTON_WHEEL_DOWN: - pass + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if\ + self._is_drag_panning else Input.MOUSE_MODE_VISIBLE - MOUSE_BUTTON_WHEEL_UP: - pass + MOUSE_BUTTON_LEFT: + self._is_selecting = event.is_pressed() + + if self._is_selecting: + self.selection_started.emit() + + else: + self.selection_stopped.emit() return @@ -64,29 +112,95 @@ func _input(event: InputEvent) -> void: if event is InputEventScreenDrag: return + if event is InputEventScreenTouch: + return + func _process(delta: float) -> void: - var global_basis := self.global_transform.basis - var camera_settings := GameSettings.camera_settings - var delta_speed := camera_settings.movement_speed_modifier * _MOVE_SPEED_BASE_MODIFIER * delta + if not(self.frozen): + var global_basis := self.global_transform.basis + var camera_settings := GameSettings.camera_settings - self._target_position += delta_speed.y * (-global_basis.z) *\ - (Input.get_action_strength(_FORWARD) - Input.get_action_strength(_BACKWARD)) *\ - (-1.0 if camera_settings.is_y_inverted else 1.0) + var delta_speed :=\ + camera_settings.movement_speed_modifier * _MOVE_SPEED_BASE_MODIFIER * delta - self._target_position += delta_speed.x * (-global_basis.x) *\ - (Input.get_action_strength(_LEFT) - Input.get_action_strength(_RIGHT)) *\ - (-1.0 if camera_settings.is_y_inverted else 1.0) + self._target_position += delta_speed.y * (-global_basis.z) *\ + (Input.get_action_strength(_FORWARD) - Input.get_action_strength(_BACKWARD)) *\ + (-1.0 if camera_settings.is_y_inverted else 1.0) - self._target_orientation += (Input.get_action_strength(_ROTATE_CCW) -\ - Input.get_action_strength(_ROTATE_CW)) * _ROTATE_SPEED_BASE *\ - camera_settings.rotation_speed_modifier * delta + self._target_position += delta_speed.x * (-global_basis.x) *\ + (Input.get_action_strength(_LEFT) - Input.get_action_strength(_RIGHT)) *\ + (-1.0 if camera_settings.is_y_inverted else 1.0) - self.global_transform = self.global_transform.interpolate_with( - Transform3D(Basis(Vector3.UP, self._target_orientation), self._target_position), - delta * _TRANSFORM_DELTA * self.movement_smoothing) + self._target_orientation += (Input.get_action_strength(_ROTATE_CCW) -\ + Input.get_action_strength(_ROTATE_CW)) * _ROTATE_SPEED_BASE *\ + camera_settings.rotation_speed_modifier * delta + + self.global_transform = self.global_transform.interpolate_with( + Transform3D(Basis(Vector3.UP, self._target_orientation), self._target_position), + delta * _TRANSFORM_DELTA * self.movement_smoothing) + + match self._select_mode: + SelectMode.NONE: + self._cursor_point = self.get_viewport().size / 2.0 + + SelectMode.MOUSE: + self._cursor_point = self.get_viewport().get_mouse_position() + +func _ready() -> void: + if self._selection_area != null: + self._selection_area.mouse_entered.connect(func () -> void: + if self._select_mode != SelectMode.MOUSE: + self._select_mode = SelectMode.MOUSE + + self.select_mode_changed.emit(SelectMode.MOUSE)) + + self._selection_area.mouse_exited.connect(func () -> void: + if self._select_mode != SelectMode.NONE: + self._select_mode = SelectMode.NONE + + self.select_mode_changed.emit(SelectMode.NONE)) ## +## Returns [code]true[/code] if the player controller is currently selecting a location on the +## screen, otherwise [code]false[/code]. ## +## *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_drag_panning() -> bool: - return self._is_drag_panning +func is_selecting() -> bool: + return self._is_selecting + +## +## Returns the position of the selection cursor with respect to the select current mode being used. +## +## When a mouse input device is being used, this will be its location in screen coordinates. For +## 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 self._cursor_point + +## +## Returns the current [enum SelectMode] being used for selections. +## +## The general use-case for this function is to peek through the player controller abstraction and +## see what supported hardware interface is currently being used to select in the world. This is +## useful for handling input-specific behaviors, such as showing a mouse cursor when a mouse input +## device is being used. +## +func get_select_mode() -> int: + return self._select_mode + +## +## Converts and returns the screen coordinates in [code]screen_point[/code] into 2D worldspace +## coordinates relative to an infinite ground plane at a y offset of [code]0.0[/code]. +## +func screen_to_plane(screen_point: Vector2): + if self._camera != null: + var plane_target = Plane(Vector3.UP, 0.0).intersects_ray( + self._camera.global_position, self._camera.project_ray_normal(screen_point)) + + if plane_target is Vector3: + return Vector2(plane_target.x, plane_target.z) + + return null From 09fb0e7e0a8281a37b1e13926ca1303db38b1e16 Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 01:15:41 +0000 Subject: [PATCH 08/12] Add new close / cancel icon --- editor.scn | 4 ++-- user_interface/close_icon.res | 3 +++ user_interface/icons_atlas.png | 3 +++ user_interface/icons_atlas.png.import | 34 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 user_interface/close_icon.res create mode 100644 user_interface/icons_atlas.png create mode 100644 user_interface/icons_atlas.png.import diff --git a/editor.scn b/editor.scn index 257901e..9bdc5a0 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:392d7f7fd33af54d9027b2455b59f74c54b1629a48ba6a8cab3ab2584c9a9d38 -size 6198 +oid sha256:856613aeac6a4ec831dae10369835d90b278070470384a45c98de7a77bd6791a +size 6243 diff --git a/user_interface/close_icon.res b/user_interface/close_icon.res new file mode 100644 index 0000000..3eac366 --- /dev/null +++ b/user_interface/close_icon.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d42aa98eb1c95765029fe78fc001124a67b67b91b35435ac92bd0d222a334c01 +size 261 diff --git a/user_interface/icons_atlas.png b/user_interface/icons_atlas.png new file mode 100644 index 0000000..0734a10 --- /dev/null +++ b/user_interface/icons_atlas.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d0ba7358fe835bbf0b9dba2c952a65700016ac76d4cb7886ab2d4dcddef594f +size 847 diff --git a/user_interface/icons_atlas.png.import b/user_interface/icons_atlas.png.import new file mode 100644 index 0000000..8560994 --- /dev/null +++ b/user_interface/icons_atlas.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c3efpk1tcq1ef" +path="res://.godot/imported/icons_atlas.png-636cee87356c05eb2a62c57d569bd94e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://user_interface/icons_atlas.png" +dest_files=["res://.godot/imported/icons_atlas.png-636cee87356c05eb2a62c57d569bd94e.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 From 80724c4f21419857d3859d5ba0ddd1dcc82ce3f2 Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 01:19:17 +0000 Subject: [PATCH 09/12] Split popup overlay from map wizard in editor --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index 9bdc5a0..af36321 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:856613aeac6a4ec831dae10369835d90b278070470384a45c98de7a77bd6791a -size 6243 +oid sha256:ee645f62ca87a521d846b40a6ea9f09b2cb66e6aa96b05420053d81a16401453 +size 6275 From 038d5684a551e827eaa658be0ab9e986cbdbad62 Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 01:28:00 +0000 Subject: [PATCH 10/12] Fix wording of PlayerController.screen_to_plane doc comment --- player_controller.gd | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/player_controller.gd b/player_controller.gd index cb556ca..20a044b 100644 --- a/player_controller.gd +++ b/player_controller.gd @@ -192,8 +192,11 @@ func get_select_mode() -> int: return self._select_mode ## -## Converts and returns the screen coordinates in [code]screen_point[/code] into 2D worldspace -## coordinates relative to an infinite ground plane at a y offset of [code]0.0[/code]. +## 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): if self._camera != null: From fec1ac28b72e67ca5902e41ddd56334d46a8e60a Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 01:30:37 +0000 Subject: [PATCH 11/12] Add missing doc comments to editor-local code --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index af36321..1a2fc2e 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ee645f62ca87a521d846b40a6ea9f09b2cb66e6aa96b05420053d81a16401453 -size 6275 +oid sha256:7f5986d813464cc7199c548780d7ee4fc35df9758afc7ecfb09d7a59eb74ce24 +size 6598 From be2c3852638a30acbcf31c23234096da05d7bb12 Mon Sep 17 00:00:00 2001 From: kayomn Date: Thu, 12 Jan 2023 01:32:42 +0000 Subject: [PATCH 12/12] Fix regression in editor theming --- editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor.scn b/editor.scn index 1a2fc2e..681b5de 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f5986d813464cc7199c548780d7ee4fc35df9758afc7ecfb09d7a59eb74ce24 -size 6598 +oid sha256:b2aa052c695e7875d548df6dc3fa6bf06f4294490d04a82bc4992923e959c4e8 +size 6597