From b4772546b3228e8acc0a4f54388879aeea79b52d Mon Sep 17 00:00:00 2001 From: kayomn Date: Sat, 21 Jan 2023 15:03:12 +0000 Subject: [PATCH 1/4] Add editor warnings to ButtonSelection --- user_interface/button_selection.gd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/user_interface/button_selection.gd b/user_interface/button_selection.gd index d94a691..0d9e0f8 100644 --- a/user_interface/button_selection.gd +++ b/user_interface/button_selection.gd @@ -16,7 +16,14 @@ var item_count: int: return _button_group.get_buttons().size() func _get_configuration_warnings() -> PackedStringArray: - return PackedStringArray() + var warnings := PackedStringArray() + + for child in get_children(): + warnings.append( + "ItemSelection can only have children of type Button, but {0} is of type {1}".format( + [child.name, child.get_class()])) + + return warnings ## ## Adds a new item with no text and only [code]icon[/code] as the icon to the selection. From 5d02cd16c7105ffebc59a7ae2f2798f9ebfb021f Mon Sep 17 00:00:00 2001 From: kayomn Date: Sat, 21 Jan 2023 15:05:37 +0000 Subject: [PATCH 2/4] Reword editor warning for ItemSelection --- user_interface/button_selection.gd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/user_interface/button_selection.gd b/user_interface/button_selection.gd index 0d9e0f8..f79eb5c 100644 --- a/user_interface/button_selection.gd +++ b/user_interface/button_selection.gd @@ -17,11 +17,15 @@ var item_count: int: func _get_configuration_warnings() -> PackedStringArray: var warnings := PackedStringArray() + var children := get_children() - for child in get_children(): - warnings.append( - "ItemSelection can only have children of type Button, but {0} is of type {1}".format( - [child.name, child.get_class()])) + if not(children.is_empty()): + var self_class_name := get_class() + + for child in get_children(): + warnings.append( + "{0} can only have Button children, but {1} is of type {2}".format( + [self_class_name, child.name, child.get_class()])) return warnings From 01e5a5dbdb550021a5f3309b2e70817e965973fa Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 22 Jan 2023 15:41:37 +0000 Subject: [PATCH 3/4] Add world boundaries for player camera --- editor.scn | 3 - editor/brush_hard_circle_mask.png.import | 14 -- editor/brush_soft_circle_mask.png.import | 14 -- editor/menus_theme.res | 3 - map_editor.scn | 3 + map_editor/boundary.gdshader | 12 ++ .../brush_hard_circle_mask.png | 0 map_editor/brush_hard_circle_mask.png.import | 14 ++ .../brush_soft_circle_mask.png | 0 map_editor/brush_soft_circle_mask.png.import | 14 ++ map_editor/camera_boundary_mesh.res | 3 + .../edit_mode_button_group.res | 0 map_editor/map_editor_controller.gd | 143 ++++++++++++++++++ map_editor/menus_theme.res | 3 + player_controller.gd | 21 +-- project.godot | 8 +- 16 files changed, 206 insertions(+), 49 deletions(-) delete mode 100644 editor.scn delete mode 100644 editor/brush_hard_circle_mask.png.import delete mode 100644 editor/brush_soft_circle_mask.png.import delete mode 100644 editor/menus_theme.res create mode 100644 map_editor.scn create mode 100644 map_editor/boundary.gdshader rename {editor => map_editor}/brush_hard_circle_mask.png (100%) create mode 100644 map_editor/brush_hard_circle_mask.png.import rename {editor => map_editor}/brush_soft_circle_mask.png (100%) create mode 100644 map_editor/brush_soft_circle_mask.png.import create mode 100644 map_editor/camera_boundary_mesh.res rename {editor => map_editor}/edit_mode_button_group.res (100%) create mode 100644 map_editor/map_editor_controller.gd create mode 100644 map_editor/menus_theme.res diff --git a/editor.scn b/editor.scn deleted file mode 100644 index a04e07e..0000000 --- a/editor.scn +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f440fd5671e8668e3c627d3447cecb4d8b508cdd4590805726edadf663e4c6e7 -size 7923 diff --git a/editor/brush_hard_circle_mask.png.import b/editor/brush_hard_circle_mask.png.import deleted file mode 100644 index 0c12c25..0000000 --- a/editor/brush_hard_circle_mask.png.import +++ /dev/null @@ -1,14 +0,0 @@ -[remap] - -importer="image" -type="Image" -uid="uid://drok88h02tdre" -path="res://.godot/imported/brush_hard_circle_mask.png-e647df7b970f00cdf2f3f2ac38ad8257.image" - -[deps] - -source_file="res://editor/brush_hard_circle_mask.png" -dest_files=["res://.godot/imported/brush_hard_circle_mask.png-e647df7b970f00cdf2f3f2ac38ad8257.image"] - -[params] - diff --git a/editor/brush_soft_circle_mask.png.import b/editor/brush_soft_circle_mask.png.import deleted file mode 100644 index 6b453bf..0000000 --- a/editor/brush_soft_circle_mask.png.import +++ /dev/null @@ -1,14 +0,0 @@ -[remap] - -importer="image" -type="Image" -uid="uid://bbdh4btpg08do" -path="res://.godot/imported/brush_soft_circle_mask.png-5af527bedd556c2d7ed38b029e34527e.image" - -[deps] - -source_file="res://editor/brush_soft_circle_mask.png" -dest_files=["res://.godot/imported/brush_soft_circle_mask.png-5af527bedd556c2d7ed38b029e34527e.image"] - -[params] - diff --git a/editor/menus_theme.res b/editor/menus_theme.res deleted file mode 100644 index e4ae784..0000000 --- a/editor/menus_theme.res +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6abf7dfa9a4e3b0da93384cd5600a50cb553a18f337dcb9b5aeaf5a52b871271 -size 825 diff --git a/map_editor.scn b/map_editor.scn new file mode 100644 index 0000000..3fa6998 --- /dev/null +++ b/map_editor.scn @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73d0e215a4fc6ca80730171ff8b9c539a22e39f1d75767ce74b3f581cf41475b +size 8315 diff --git a/map_editor/boundary.gdshader b/map_editor/boundary.gdshader new file mode 100644 index 0000000..50ae102 --- /dev/null +++ b/map_editor/boundary.gdshader @@ -0,0 +1,12 @@ +shader_type spatial; +render_mode shadows_disabled, unshaded, cull_disabled; + +void fragment() { + if (FRONT_FACING) { + ALBEDO = vec3(1.0, 0.0, 0.0); + ALPHA = 0.5; + } else { + ALBEDO = vec3(0.0, 1.0, 0.0); + ALPHA = 0.1; + } +} diff --git a/editor/brush_hard_circle_mask.png b/map_editor/brush_hard_circle_mask.png similarity index 100% rename from editor/brush_hard_circle_mask.png rename to map_editor/brush_hard_circle_mask.png diff --git a/map_editor/brush_hard_circle_mask.png.import b/map_editor/brush_hard_circle_mask.png.import new file mode 100644 index 0000000..e29c1dd --- /dev/null +++ b/map_editor/brush_hard_circle_mask.png.import @@ -0,0 +1,14 @@ +[remap] + +importer="image" +type="Image" +uid="uid://drok88h02tdre" +path="res://.godot/imported/brush_hard_circle_mask.png-b5b7b3c7aa50923306e69fd4680a2d65.image" + +[deps] + +source_file="res://map_editor/brush_hard_circle_mask.png" +dest_files=["res://.godot/imported/brush_hard_circle_mask.png-b5b7b3c7aa50923306e69fd4680a2d65.image"] + +[params] + diff --git a/editor/brush_soft_circle_mask.png b/map_editor/brush_soft_circle_mask.png similarity index 100% rename from editor/brush_soft_circle_mask.png rename to map_editor/brush_soft_circle_mask.png diff --git a/map_editor/brush_soft_circle_mask.png.import b/map_editor/brush_soft_circle_mask.png.import new file mode 100644 index 0000000..65a4ec4 --- /dev/null +++ b/map_editor/brush_soft_circle_mask.png.import @@ -0,0 +1,14 @@ +[remap] + +importer="image" +type="Image" +uid="uid://bbdh4btpg08do" +path="res://.godot/imported/brush_soft_circle_mask.png-f4362d74cca7ee83b36212049a3b11fb.image" + +[deps] + +source_file="res://map_editor/brush_soft_circle_mask.png" +dest_files=["res://.godot/imported/brush_soft_circle_mask.png-f4362d74cca7ee83b36212049a3b11fb.image"] + +[params] + diff --git a/map_editor/camera_boundary_mesh.res b/map_editor/camera_boundary_mesh.res new file mode 100644 index 0000000..dcbce3c --- /dev/null +++ b/map_editor/camera_boundary_mesh.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1bfd8ad50f3db5aafadc5fb8278b2b7d597fad0d8f0fb2e2fcb4834db07c8336 +size 647 diff --git a/editor/edit_mode_button_group.res b/map_editor/edit_mode_button_group.res similarity index 100% rename from editor/edit_mode_button_group.res rename to map_editor/edit_mode_button_group.res diff --git a/map_editor/map_editor_controller.gd b/map_editor/map_editor_controller.gd new file mode 100644 index 0000000..2162752 --- /dev/null +++ b/map_editor/map_editor_controller.gd @@ -0,0 +1,143 @@ +class_name MapEditorController extends Node + +## +## Default elevation height for terrain. +## +const DEFAULT_ELEVATION := 0.5 + +var _brush_selected := 0 + +@export +var _registered_brushes: Array[Image] = [] + +@export +var _registered_paints: Array[TerrainPaint] = [] + +var _paint_selected_erase := 0 + +var _paint_selected_blue := 0 + +var _paint_selected_green := 0 + +var _paint_selected_red := 0 + +## +## +## +var smooth_elevation := DEFAULT_ELEVATION + +## +## +## +func disable_controls() -> void: + set_process(false) + +## +## +## +func enable_controls() -> void: + set_process(true) + +## +## +## +func get_registered_brushes() -> Array[Image]: + return _registered_brushes + +## +## +## +func get_registered_paints() -> Array[TerrainPaint]: + return _registered_paints + +## +## +## +func get_selected_brush() -> int: + return _brush_selected + +## +## +## +func get_selected_paint_blue() -> int: + return _paint_selected_blue + +## +## +## +func get_selected_paint_erase() -> int: + return _paint_selected_erase + +## +## +## +func get_selected_paint_green() -> int: + return _paint_selected_green + +## +## +## +func get_selected_paint_red() -> int: + return _paint_selected_red + +## +## Registers [code]brush_mask[/code] as a usable brush option in the editor. +## +func register_brush(brush_mask: Image) -> void: + _registered_brushes.append(brush_mask) + +## +## Registers [code]terrain_paint[/code] as a usable paint option in the editor. +## +func register_paint(terrain_paint: TerrainPaint) -> void: + _registered_paints.append(terrain_paint) + +## +## Resets the editor settings to their initial values. +## +func reset() -> void: + select_brush(0) + select_paint_erase(0) + select_paint_red(0) + select_paint_green(0) + select_paint_blue(0) + +## +## +## +func select_brush(selected_index: int) -> void: + assert((selected_index >= 0) or (selected_index < _registered_brushes.size())) + + _brush_selected = selected_index + +## +## +## +func select_paint_blue(selected_index: int) -> void: + assert((selected_index >= 0) or (selected_index < _registered_paints.size())) + + _paint_selected_blue = selected_index + +## +## +## +func select_paint_erase(selected_index: int) -> void: + assert((selected_index >= 0) or (selected_index < _registered_paints.size())) + + _paint_selected_erase = selected_index + +## +## +## +func select_paint_green(selected_index: int) -> void: + assert((selected_index >= 0) or (selected_index < _registered_paints.size())) + + _paint_selected_green = selected_index + +## +## +## +func select_paint_red(selected_index: int) -> void: + assert((selected_index >= 0) or (selected_index < _registered_paints.size())) + + _paint_selected_red = selected_index diff --git a/map_editor/menus_theme.res b/map_editor/menus_theme.res new file mode 100644 index 0000000..a643e43 --- /dev/null +++ b/map_editor/menus_theme.res @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14d3249a6f33398063da6cb0d061b5c602cca68946b607ff5b06e428d3a24d72 +size 842 diff --git a/player_controller.gd b/player_controller.gd index c7f6114..5eb9353 100644 --- a/player_controller.gd +++ b/player_controller.gd @@ -98,9 +98,7 @@ func _input(event: InputEvent) -> void: if (event is InputEventMouseMotion) and self._is_drag_panning: var global_basis := self.global_transform.basis var camera_settings := GameSettings.camera_settings - - var dampened_speed :=\ - camera_settings.movement_speed_modifier * _DRAG_SPEED_BASE_MODIFIER + var dampened_speed := camera_settings.movement_speed_modifier * _DRAG_SPEED_BASE_MODIFIER self._target_position += dampened_speed.y * (-global_basis.z) *\ event.relative.y * (-1.0 if camera_settings.is_y_inverted else 1.0) @@ -161,6 +159,12 @@ func _ready() -> void: self.select_mode_changed.emit(SelectMode.NONE)) +## +## +## +func in_select_area() -> bool: + return self._select_mode != SelectMode.NONE + ## ## Returns [code]true[/code] if the player controller is currently selecting a location on the ## screen, otherwise [code]false[/code]. @@ -181,17 +185,6 @@ func is_selecting() -> bool: 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 - ## ## 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]. diff --git a/project.godot b/project.godot index b065f79..96efcf4 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ _global_script_classes=[{ "language": &"GDScript", "path": "res://user_interface/button_selection.gd" }, { +"base": "Node", +"class": &"MapEditorController", +"language": &"GDScript", +"path": "res://map_editor/map_editor_controller.gd" +}, { "base": "Node3D", "class": &"PlayerController", "language": &"GDScript", @@ -42,6 +47,7 @@ _global_script_classes=[{ _global_script_class_icons={ "DynamicTerrainInstance3D": "", "ItemSelection": "", +"MapEditorController": "", "PlayerController": "", "Settings": "", "TerrainInstance3D": "", @@ -51,7 +57,7 @@ _global_script_class_icons={ [application] config/name="Protectorate" -run/main_scene="res://editor.scn" +run/main_scene="res://map_editor.scn" config/use_custom_user_dir=true config/features=PackedStringArray("4.0", "Forward Plus") config/icon="res://icon.png" From 17d0130d4fb3530b0aac3689f370bfc327dbb6ca Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 22 Jan 2023 22:51:16 +0000 Subject: [PATCH 4/4] Always show player camera boundary marker --- map_editor.scn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map_editor.scn b/map_editor.scn index 3fa6998..118300a 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:73d0e215a4fc6ca80730171ff8b9c539a22e39f1d75767ce74b3f581cf41475b -size 8315 +oid sha256:f38a006102be993f6ba2186510f9fd83fcd207ba6f20dc4cc8fac509e48a7485 +size 8229