style: apply gdformat formatting across the entire project
Auto-format all GDScript files using gdformat from gdtoolkit. This is a baseline formatting pass to ensure consistent style: - Normalizes indentation and spacing - Wraps long lines to 100 characters - Removes trailing whitespace - Standardizes blank lines between functions 68 files reformatted, 8 files left unchanged (3rd-party addon files with parse errors excluded).
This commit is contained in:
@@ -30,11 +30,11 @@ var search_button: Button
|
||||
|
||||
#DEPRECATED 4.5
|
||||
#class EdDock extends EditorDock:
|
||||
#func _update_layout(layout: int) -> void:
|
||||
#layout 1 vertical, 2 horizontal, 4 window
|
||||
#print("Terrain3DAssetDock: _update_layout called with: ", layout)
|
||||
#func _update_layout(layout: int) -> void:
|
||||
#layout 1 vertical, 2 horizontal, 4 window
|
||||
#print("Terrain3DAssetDock: _update_layout called with: ", layout)
|
||||
|
||||
var _dock: MarginContainer #DEPRECATED 4.5 - Use EdDock
|
||||
var _dock: MarginContainer #DEPRECATED 4.5 - Use EdDock
|
||||
var _initialized: bool = false
|
||||
var plugin: EditorPlugin
|
||||
var window: Window
|
||||
@@ -44,18 +44,18 @@ func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_ENTER_TREE:
|
||||
await get_tree().process_frame
|
||||
update_layout()
|
||||
|
||||
|
||||
|
||||
|
||||
func initialize(p_plugin: EditorPlugin) -> void:
|
||||
if p_plugin:
|
||||
plugin = p_plugin
|
||||
|
||||
_dock = ClassDB.instantiate("EditorDock") #DEPRECATED 4.5 - EdDock.new()
|
||||
_dock = ClassDB.instantiate("EditorDock") #DEPRECATED 4.5 - EdDock.new()
|
||||
_dock.title = "Terrain3D"
|
||||
_dock.dock_icon = preload("../icons/terrain3d.svg")
|
||||
_dock.default_slot = 8 #DEPRECATED 4.5 - EditorDock.DockSlot.DOCK_SLOT_BOTTOM
|
||||
_dock.default_slot = 8 #DEPRECATED 4.5 - EditorDock.DockSlot.DOCK_SLOT_BOTTOM
|
||||
_dock.closable = false
|
||||
_dock.available_layouts = 0x7 #DEPRECATED 4.5 - EditorDock.DOCK_LAYOUT_ALL
|
||||
_dock.available_layouts = 0x7 #DEPRECATED 4.5 - EditorDock.DOCK_LAYOUT_ALL
|
||||
_dock.add_child(self)
|
||||
plugin.add_dock(_dock)
|
||||
_dock.open()
|
||||
@@ -75,7 +75,7 @@ func initialize(p_plugin: EditorPlugin) -> void:
|
||||
var editor_scale: float = EditorInterface.get_editor_scale()
|
||||
search_box.custom_minimum_size = Vector2(100. * editor_scale, 30. * editor_scale)
|
||||
search_button = $Box/Buttons/SearchBox/SearchButton
|
||||
|
||||
|
||||
texture_list = ListContainer.new()
|
||||
texture_list.name = "TextureList"
|
||||
texture_list.plugin = plugin
|
||||
@@ -100,21 +100,31 @@ func initialize(p_plugin: EditorPlugin) -> void:
|
||||
size_slider.value_changed.connect(_on_slider_changed)
|
||||
plugin.ui.toolbar.tool_changed.connect(_on_tool_changed)
|
||||
|
||||
meshes_btn.add_theme_font_size_override("font_size", int(16. * EditorInterface.get_editor_scale()))
|
||||
textures_btn.add_theme_font_size_override("font_size", int(16. * EditorInterface.get_editor_scale()))
|
||||
meshes_btn.add_theme_font_size_override(
|
||||
"font_size", int(16. * EditorInterface.get_editor_scale())
|
||||
)
|
||||
textures_btn.add_theme_font_size_override(
|
||||
"font_size", int(16. * EditorInterface.get_editor_scale())
|
||||
)
|
||||
|
||||
search_box.text_changed.connect(_on_search_text_changed)
|
||||
search_button.pressed.connect(_on_search_button_pressed)
|
||||
|
||||
|
||||
confirm_dialog = ConfirmationDialog.new()
|
||||
add_child(confirm_dialog, true)
|
||||
confirm_dialog.hide()
|
||||
confirm_dialog.confirmed.connect(func(): _confirmed = true; \
|
||||
confirmation_closed.emit(); \
|
||||
confirmation_confirmed.emit() )
|
||||
confirm_dialog.canceled.connect(func(): _confirmed = false; \
|
||||
confirmation_closed.emit(); \
|
||||
confirmation_canceled.emit() )
|
||||
confirm_dialog.confirmed.connect(
|
||||
func():
|
||||
_confirmed = true
|
||||
confirmation_closed.emit()
|
||||
confirmation_confirmed.emit()
|
||||
)
|
||||
confirm_dialog.canceled.connect(
|
||||
func():
|
||||
_confirmed = false
|
||||
confirmation_closed.emit()
|
||||
confirmation_canceled.emit()
|
||||
)
|
||||
|
||||
# Setup styles
|
||||
set("theme_override_styles/panel", get_theme_stylebox("panel", "Panel"))
|
||||
@@ -155,7 +165,7 @@ func update_layout() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
if plugin.debug > 1:
|
||||
print("Terrain3DAssetDock: update_layout")
|
||||
print("Terrain3DAssetDock: update_layout")
|
||||
|
||||
## Detect if we have a new window from `Make floating` and grab it
|
||||
if not window:
|
||||
@@ -163,12 +173,12 @@ func update_layout() -> void:
|
||||
window = get_parent().get_parent().get_parent()
|
||||
_on_pin_changed(pinned_btn.button_pressed)
|
||||
plugin.godot_editor_window.mouse_entered.connect(_on_godot_window_entered)
|
||||
return # Displaying will call this function again
|
||||
return # Displaying will call this function again
|
||||
# Check if window was just freed. Freed objects have a different hash than null
|
||||
elif hash(window) != hash(null):
|
||||
window = null
|
||||
plugin.godot_editor_window.mouse_entered.disconnect(_on_godot_window_entered)
|
||||
return # Will call this function again upon display
|
||||
return # Will call this function again upon display
|
||||
|
||||
## Vertical layout: buttons on top
|
||||
if size.x < 700:
|
||||
@@ -180,7 +190,7 @@ func update_layout() -> void:
|
||||
box.move_child(size_slider, 2)
|
||||
pinned_btn.reparent(buttons)
|
||||
else:
|
||||
# Wide layout: buttons on left
|
||||
# Wide layout: buttons on left
|
||||
box.vertical = false
|
||||
buttons.vertical = true
|
||||
search_box.reparent(buttons)
|
||||
@@ -205,8 +215,8 @@ func set_selected_by_asset_id(p_id: int) -> void:
|
||||
search_box.text = ""
|
||||
_on_search_text_changed()
|
||||
current_list.set_selected_id(p_id)
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_search_text_changed() -> void:
|
||||
if plugin.debug:
|
||||
print("Terrain3DAssetDock: _on_search_text_changed: ", search_box.text)
|
||||
@@ -217,7 +227,7 @@ func _on_search_text_changed() -> void:
|
||||
search_button.icon = get_theme_icon("Close", "EditorIcons")
|
||||
else:
|
||||
search_button.icon = get_theme_icon("Search", "EditorIcons")
|
||||
|
||||
|
||||
mesh_list.search_text = search_box.text
|
||||
texture_list.search_text = search_box.text
|
||||
current_list.update_asset_list()
|
||||
@@ -298,7 +308,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
print("Terrain3DAssetDock: _on_tool_changed: ", p_tool, ", ", p_operation)
|
||||
if p_tool == Terrain3DEditor.INSTANCER:
|
||||
_on_meshes_pressed()
|
||||
elif p_tool in [ Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS ]:
|
||||
elif p_tool in [Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS]:
|
||||
_on_textures_pressed()
|
||||
|
||||
|
||||
@@ -307,10 +317,12 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
|
||||
func update_assets() -> void:
|
||||
if plugin.debug:
|
||||
print("Terrain3DAssetDock: update_assets: ", plugin.terrain.assets if plugin.terrain else "")
|
||||
print(
|
||||
"Terrain3DAssetDock: update_assets: ", plugin.terrain.assets if plugin.terrain else ""
|
||||
)
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
|
||||
# Verify signals to individual lists
|
||||
if plugin.is_terrain_valid() and plugin.terrain.assets:
|
||||
if not plugin.terrain.assets.textures_changed.is_connected(texture_list.update_asset_list):
|
||||
@@ -327,7 +339,7 @@ func update_assets() -> void:
|
||||
func load_editor_settings() -> void:
|
||||
# Remove old editor settings
|
||||
const ES_DOCK: String = "terrain3d/dock/"
|
||||
for setting in [ "slot", "floating", "window_position", "window_size" ]:
|
||||
for setting in ["slot", "floating", "window_position", "window_size"]:
|
||||
plugin.erase_setting(ES_DOCK + setting)
|
||||
pinned_btn.button_pressed = plugin.get_setting(ES_DOCK_PINNED, true)
|
||||
size_slider.value = plugin.get_setting(ES_DOCK_TILE_SIZE, 90)
|
||||
@@ -350,8 +362,9 @@ func save_editor_settings() -> void:
|
||||
## class ListContainer
|
||||
##############################################################
|
||||
|
||||
|
||||
class ListContainer extends Container:
|
||||
|
||||
class ListContainer:
|
||||
extends Container
|
||||
var plugin: EditorPlugin
|
||||
var type := Terrain3DAssets.TYPE_TEXTURE
|
||||
var entries: Array[ListEntry]
|
||||
@@ -362,7 +375,6 @@ class ListContainer extends Container:
|
||||
var _clearing_resource: bool = false
|
||||
var search_text: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_v_size_flags(SIZE_EXPAND_FILL)
|
||||
set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
@@ -371,24 +383,22 @@ class ListContainer extends Container:
|
||||
add_theme_constant_override("shadow_offset_x", 1)
|
||||
add_theme_constant_override("shadow_offset_y", 1)
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
for e in entries:
|
||||
e.get_parent().remove_child(e)
|
||||
e.queue_free()
|
||||
entries.clear()
|
||||
|
||||
|
||||
func update_asset_list() -> void:
|
||||
if plugin.debug:
|
||||
print("Terrain3DListContainer ", name, ": update_asset_list")
|
||||
clear()
|
||||
|
||||
|
||||
# Grab terrain
|
||||
var t: Terrain3D = plugin.get_terrain()
|
||||
if not (t and t.assets):
|
||||
return
|
||||
|
||||
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
var texture_count: int = t.assets.get_texture_count()
|
||||
for i in texture_count:
|
||||
@@ -407,7 +417,6 @@ class ListContainer extends Container:
|
||||
add_item()
|
||||
set_selected_id(selected_id)
|
||||
|
||||
|
||||
func add_item(p_resource: Resource = null) -> void:
|
||||
var entry: ListEntry = ListEntry.new()
|
||||
entry.focus_style = focus_style
|
||||
@@ -423,58 +432,79 @@ class ListContainer extends Container:
|
||||
entry.type = type
|
||||
add_child(entry, true)
|
||||
entries.push_back(entry)
|
||||
|
||||
|
||||
if p_resource:
|
||||
if not p_resource.id_changed.is_connected(set_selected_after_swap):
|
||||
p_resource.id_changed.connect(set_selected_after_swap)
|
||||
|
||||
|
||||
func _on_resource_hovered(p_id: int):
|
||||
if type == Terrain3DAssets.TYPE_MESH:
|
||||
if plugin.terrain:
|
||||
plugin.terrain.assets.create_mesh_thumbnails(p_id)
|
||||
|
||||
|
||||
func set_selected_after_swap(p_type: Terrain3DAssets.AssetType, p_old_id: int, p_new_id: int) -> void:
|
||||
func set_selected_after_swap(
|
||||
p_type: Terrain3DAssets.AssetType, p_old_id: int, p_new_id: int
|
||||
) -> void:
|
||||
EditorInterface.mark_scene_as_unsaved()
|
||||
set_selected_id(clamp(p_new_id, 0, entries.size() - 2))
|
||||
|
||||
|
||||
func clicked_id(p_id: int) -> void:
|
||||
# Select Tool if clicking an asset
|
||||
plugin.select_terrain()
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE and \
|
||||
not plugin.editor.get_tool() in [ Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS ]:
|
||||
if (
|
||||
type == Terrain3DAssets.TYPE_TEXTURE
|
||||
and not (
|
||||
plugin.editor.get_tool()
|
||||
in [Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS]
|
||||
)
|
||||
):
|
||||
var paint_btn: Button = plugin.ui.toolbar.get_node_or_null("PaintTexture")
|
||||
if paint_btn:
|
||||
paint_btn.set_pressed(true)
|
||||
plugin.ui._on_tool_changed(Terrain3DEditor.TEXTURE, Terrain3DEditor.REPLACE)
|
||||
elif type == Terrain3DAssets.TYPE_MESH and plugin.editor.get_tool() != Terrain3DEditor.INSTANCER:
|
||||
elif (
|
||||
type == Terrain3DAssets.TYPE_MESH
|
||||
and plugin.editor.get_tool() != Terrain3DEditor.INSTANCER
|
||||
):
|
||||
var instancer_btn: Button = plugin.ui.toolbar.get_node_or_null("InstanceMeshes")
|
||||
if instancer_btn:
|
||||
instancer_btn.set_pressed(true)
|
||||
plugin.ui._on_tool_changed(Terrain3DEditor.INSTANCER, Terrain3DEditor.ADD)
|
||||
set_selected_id(p_id)
|
||||
|
||||
|
||||
func set_selected_id(p_id: int) -> void:
|
||||
# "Add new" is the final entry only when search box is blank
|
||||
var max_id: int = max(0, entries.size() - (1 if search_text else 2))
|
||||
if plugin.debug:
|
||||
print("Terrain3DListContainer ", name, ": set_selected_id: ", selected_id, " to ", clamp(p_id, 0, max_id))
|
||||
print(
|
||||
"Terrain3DListContainer ",
|
||||
name,
|
||||
": set_selected_id: ",
|
||||
selected_id,
|
||||
" to ",
|
||||
clamp(p_id, 0, max_id)
|
||||
)
|
||||
selected_id = clamp(p_id, 0, max_id)
|
||||
for i in entries.size():
|
||||
var entry: ListEntry = entries[i]
|
||||
entry.set_selected(i == selected_id)
|
||||
plugin.ui._on_setting_changed()
|
||||
|
||||
|
||||
func get_selected_asset_id() -> int:
|
||||
# "Add new" is the final entry only when search box is blank
|
||||
var max_id: int = max(0, entries.size() - (1 if search_text else 2))
|
||||
var id: int = clamp(selected_id, 0, max_id)
|
||||
if plugin.debug:
|
||||
print("Terrain3DListContainer ", name, ": get_selected_asset_id: selected_id: ", selected_id, ", clamped: ", id, ", entries: ", entries.size())
|
||||
print(
|
||||
"Terrain3DListContainer ",
|
||||
name,
|
||||
": get_selected_asset_id: selected_id: ",
|
||||
selected_id,
|
||||
", clamped: ",
|
||||
id,
|
||||
", entries: ",
|
||||
entries.size()
|
||||
)
|
||||
if id >= entries.size():
|
||||
return 0
|
||||
var res: Resource = entries[id].resource
|
||||
@@ -485,18 +515,21 @@ class ListContainer extends Container:
|
||||
else:
|
||||
return (res as Terrain3DTextureAsset).id
|
||||
|
||||
|
||||
func _on_resource_inspected(p_resource: Resource) -> void:
|
||||
await get_tree().process_frame
|
||||
EditorInterface.edit_resource(p_resource)
|
||||
|
||||
|
||||
|
||||
func _on_resource_changed(p_resource: Resource, p_id: int) -> void:
|
||||
if not p_resource and _clearing_resource:
|
||||
return
|
||||
if not p_resource:
|
||||
if plugin.debug:
|
||||
print("Terrain3DListContainer ", name, ": _on_resource_changed: removing asset ID: ", p_id)
|
||||
print(
|
||||
"Terrain3DListContainer ",
|
||||
name,
|
||||
": _on_resource_changed: removing asset ID: ",
|
||||
p_id
|
||||
)
|
||||
_clearing_resource = true
|
||||
var asset_dock: Control = get_parent().get_parent().get_parent()
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
@@ -509,7 +542,7 @@ class ListContainer extends Container:
|
||||
update_asset_list()
|
||||
_clearing_resource = false
|
||||
return
|
||||
|
||||
|
||||
if not plugin.is_terrain_valid():
|
||||
plugin.select_terrain()
|
||||
await get_tree().process_frame
|
||||
@@ -522,19 +555,16 @@ class ListContainer extends Container:
|
||||
|
||||
# If removing an entry, clear inspector
|
||||
if not p_resource:
|
||||
EditorInterface.inspect_object(null)
|
||||
EditorInterface.inspect_object(null)
|
||||
_clearing_resource = false
|
||||
|
||||
|
||||
func set_entry_width(value: float) -> void:
|
||||
var min_width: float = 90.0 * max(1.0, EditorInterface.get_editor_scale())
|
||||
width = clamp(value, min_width, 512.0)
|
||||
redraw()
|
||||
|
||||
|
||||
func get_entry_width() -> float:
|
||||
return width
|
||||
|
||||
|
||||
func redraw() -> void:
|
||||
height = 0
|
||||
@@ -543,22 +573,24 @@ class ListContainer extends Container:
|
||||
var columns: int = 3
|
||||
columns = clamp(size.x / width, 1, 100)
|
||||
var tile_size: Vector2 = Vector2(width, width) - Vector2(separation, separation)
|
||||
var name_font_size := int(clamp(tile_size.x/12., 12., 16.) * EditorInterface.get_editor_scale())
|
||||
var name_font_size := int(
|
||||
clamp(tile_size.x / 12., 12., 16.) * EditorInterface.get_editor_scale()
|
||||
)
|
||||
for c in get_children():
|
||||
if is_instance_valid(c):
|
||||
c.size = tile_size
|
||||
c.position = Vector2(id % columns, id / columns) * width + \
|
||||
Vector2(separation / columns, separation / columns)
|
||||
c.position = (
|
||||
Vector2(id % columns, id / columns) * width
|
||||
+ Vector2(separation / columns, separation / columns)
|
||||
)
|
||||
height = max(height, c.position.y + width)
|
||||
id += 1
|
||||
c.name_label.add_theme_font_size_override("font_size", name_font_size)
|
||||
|
||||
|
||||
# Needed to enable ScrollContainer scroll bar
|
||||
func _get_minimum_size() -> Vector2:
|
||||
return Vector2(0, height)
|
||||
|
||||
|
||||
func _notification(p_what) -> void:
|
||||
if p_what == NOTIFICATION_SORT_CHILDREN:
|
||||
redraw()
|
||||
@@ -569,24 +601,25 @@ class ListContainer extends Container:
|
||||
##############################################################
|
||||
|
||||
|
||||
class ListEntry extends MarginContainer:
|
||||
signal hovered()
|
||||
signal clicked()
|
||||
class ListEntry:
|
||||
extends MarginContainer
|
||||
signal hovered
|
||||
signal clicked
|
||||
signal changed(resource: Resource)
|
||||
signal inspected(resource: Resource)
|
||||
|
||||
|
||||
var resource: Resource
|
||||
var type := Terrain3DAssets.TYPE_TEXTURE
|
||||
var _thumbnail: Texture2D
|
||||
var drop_data: bool = false
|
||||
var is_hovered: bool = false
|
||||
var is_selected: bool = false
|
||||
|
||||
|
||||
var name_label: Label
|
||||
var button_row: FlowContainer
|
||||
var button_enabled: TextureButton
|
||||
var button_edit: TextureButton
|
||||
var spacer: Control
|
||||
var spacer: Control
|
||||
var button_clear: TextureButton
|
||||
|
||||
@onready var focus_style: StyleBox = get_theme_stylebox("focus", "Button").duplicate()
|
||||
@@ -597,7 +630,6 @@ class ListEntry extends MarginContainer:
|
||||
@onready var disabled_icon: Texture2D = get_theme_icon("GuiVisibilityHidden", "EditorIcons")
|
||||
@onready var add_icon: Texture2D = get_theme_icon("Add", "EditorIcons")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
name = "ListEntry"
|
||||
custom_minimum_size = Vector2i(86., 86.)
|
||||
@@ -611,18 +643,17 @@ class ListEntry extends MarginContainer:
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
|
||||
|
||||
func setup_buttons() -> void:
|
||||
destroy_buttons()
|
||||
|
||||
|
||||
button_row = FlowContainer.new()
|
||||
button_enabled = TextureButton.new()
|
||||
button_edit = TextureButton.new()
|
||||
button_enabled = TextureButton.new()
|
||||
button_edit = TextureButton.new()
|
||||
spacer = Control.new()
|
||||
button_clear = TextureButton.new()
|
||||
|
||||
|
||||
var icon_size: Vector2 = Vector2(12, 12)
|
||||
|
||||
|
||||
button_row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
button_row.alignment = FlowContainer.ALIGNMENT_CENTER
|
||||
button_row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
@@ -640,7 +671,7 @@ class ListEntry extends MarginContainer:
|
||||
button_enabled.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
button_enabled.pressed.connect(_on_enable)
|
||||
button_row.add_child(button_enabled, true)
|
||||
|
||||
|
||||
button_edit.set_texture_normal(edit_icon)
|
||||
button_edit.set_custom_minimum_size(icon_size)
|
||||
button_edit.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
@@ -654,7 +685,7 @@ class ListEntry extends MarginContainer:
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
spacer.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_row.add_child(spacer, true)
|
||||
|
||||
|
||||
button_clear.set_texture_normal(clear_icon)
|
||||
button_clear.set_custom_minimum_size(icon_size)
|
||||
button_clear.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
@@ -664,7 +695,6 @@ class ListEntry extends MarginContainer:
|
||||
button_clear.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
button_clear.pressed.connect(_on_clear)
|
||||
button_row.add_child(button_clear, true)
|
||||
|
||||
|
||||
func destroy_buttons() -> void:
|
||||
if button_row:
|
||||
@@ -683,7 +713,6 @@ class ListEntry extends MarginContainer:
|
||||
button_clear.free()
|
||||
button_clear = null
|
||||
|
||||
|
||||
func get_resource_name() -> StringName:
|
||||
if resource:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
@@ -692,7 +721,6 @@ class ListEntry extends MarginContainer:
|
||||
return (resource as Terrain3DTextureAsset).get_name()
|
||||
return ""
|
||||
|
||||
|
||||
func setup_label() -> void:
|
||||
name_label = Label.new()
|
||||
name_label.name = "MeshLabel"
|
||||
@@ -700,17 +728,18 @@ class ListEntry extends MarginContainer:
|
||||
name_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
name_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
name_label.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
name_label.add_theme_font_size_override("font_size", int(14. * EditorInterface.get_editor_scale()))
|
||||
name_label.add_theme_font_size_override(
|
||||
"font_size", int(14. * EditorInterface.get_editor_scale())
|
||||
)
|
||||
name_label.add_theme_color_override("font_color", Color.WHITE)
|
||||
name_label.add_theme_color_override("font_shadow_color", Color.BLACK)
|
||||
name_label.add_theme_constant_override("shadow_offset_x", 1)
|
||||
name_label.add_theme_constant_override("shadow_offset_y", 1)
|
||||
name_label.visible = false
|
||||
name_label.autowrap_mode = TextServer.AUTOWRAP_OFF
|
||||
name_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
name_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
add_child(name_label, true)
|
||||
|
||||
|
||||
func _notification(p_what) -> void:
|
||||
match p_what:
|
||||
NOTIFICATION_PREDELETE:
|
||||
@@ -758,7 +787,6 @@ class ListEntry extends MarginContainer:
|
||||
drop_data = false
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _gui_input(p_event: InputEvent) -> void:
|
||||
if p_event is InputEventMouseButton:
|
||||
if p_event.is_pressed():
|
||||
@@ -780,7 +808,6 @@ class ListEntry extends MarginContainer:
|
||||
if resource:
|
||||
_on_clear()
|
||||
|
||||
|
||||
func _can_drop_data(p_at_position: Vector2, p_data: Variant) -> bool:
|
||||
drop_data = false
|
||||
if typeof(p_data) == TYPE_DICTIONARY:
|
||||
@@ -789,7 +816,6 @@ class ListEntry extends MarginContainer:
|
||||
drop_data = true
|
||||
return drop_data
|
||||
|
||||
|
||||
func _drop_data(p_at_position: Vector2, p_data: Variant) -> void:
|
||||
if typeof(p_data) == TYPE_DICTIONARY:
|
||||
var res: Resource = load(p_data.files[0])
|
||||
@@ -806,7 +832,7 @@ class ListEntry extends MarginContainer:
|
||||
set_edited_resource(res, false)
|
||||
elif res is PackedScene and type == Terrain3DAssets.TYPE_MESH:
|
||||
if not resource:
|
||||
resource = Terrain3DMeshAsset.new()
|
||||
resource = Terrain3DMeshAsset.new()
|
||||
set_edited_resource(resource, false)
|
||||
resource.set_scene_file(res)
|
||||
elif res is Terrain3DMeshAsset and type == Terrain3DAssets.TYPE_MESH:
|
||||
@@ -816,7 +842,6 @@ class ListEntry extends MarginContainer:
|
||||
emit_signal("clicked")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
func set_edited_resource(p_res: Resource, p_no_signal: bool = true) -> void:
|
||||
resource = p_res
|
||||
if resource:
|
||||
@@ -828,20 +853,18 @@ class ListEntry extends MarginContainer:
|
||||
elif resource is Terrain3DMeshAsset:
|
||||
if not resource.instancer_setting_changed.is_connected(_on_resource_changed):
|
||||
resource.instancer_setting_changed.connect(_on_resource_changed)
|
||||
|
||||
|
||||
if button_clear:
|
||||
button_clear.set_visible(resource != null)
|
||||
|
||||
|
||||
queue_redraw()
|
||||
if not p_no_signal:
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
func _on_resource_changed(_value: int = 0) -> void:
|
||||
queue_redraw()
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
func set_selected(value: bool) -> void:
|
||||
if not is_inside_tree():
|
||||
#push_error("not in tree")
|
||||
@@ -851,26 +874,24 @@ class ListEntry extends MarginContainer:
|
||||
# Handle scrolling to show the selected item
|
||||
await get_tree().process_frame
|
||||
if is_inside_tree():
|
||||
get_parent().get_parent().get_v_scroll_bar().ratio = position.y / get_parent().size.y
|
||||
get_parent().get_parent().get_v_scroll_bar().ratio = (
|
||||
position.y / get_parent().size.y
|
||||
)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_clear() -> void:
|
||||
if resource:
|
||||
name_label.hide()
|
||||
set_edited_resource(null, false)
|
||||
|
||||
|
||||
func _on_edit() -> void:
|
||||
emit_signal("clicked")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
func _on_enable() -> void:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
resource.set_enabled(!resource.is_enabled())
|
||||
|
||||
|
||||
func _format_number(num: int) -> String:
|
||||
var is_negative: bool = num < 0
|
||||
var str_num: String = str(abs(num))
|
||||
|
||||
@@ -64,7 +64,7 @@ var _godot_last_state: Window.Mode = Window.MODE_FULLSCREEN
|
||||
func initialize(p_plugin: EditorPlugin) -> void:
|
||||
if p_plugin:
|
||||
plugin = p_plugin
|
||||
|
||||
|
||||
_godot_last_state = plugin.godot_editor_window.mode
|
||||
placement_opt = $Box/Buttons/PlacementOpt
|
||||
pinned_btn = $Box/Buttons/Pinned
|
||||
@@ -98,7 +98,7 @@ func initialize(p_plugin: EditorPlugin) -> void:
|
||||
placement_opt.item_selected.connect(set_slot)
|
||||
floating_btn.pressed.connect(make_dock_float)
|
||||
pinned_btn.toggled.connect(_on_pin_changed)
|
||||
pinned_btn.visible = ( window != null )
|
||||
pinned_btn.visible = (window != null)
|
||||
size_slider.value_changed.connect(_on_slider_changed)
|
||||
plugin.ui.toolbar.tool_changed.connect(_on_tool_changed)
|
||||
|
||||
@@ -113,7 +113,7 @@ func initialize(p_plugin: EditorPlugin) -> void:
|
||||
func _ready() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
|
||||
# Setup styles
|
||||
set("theme_override_styles/panel", get_theme_stylebox("panel", "Panel"))
|
||||
# Avoid saving icon resources in tscn when editing w/ a tool script
|
||||
@@ -127,12 +127,18 @@ func _ready() -> void:
|
||||
confirm_dialog = ConfirmationDialog.new()
|
||||
add_child(confirm_dialog)
|
||||
confirm_dialog.hide()
|
||||
confirm_dialog.confirmed.connect(func(): _confirmed = true; \
|
||||
emit_signal("confirmation_closed"); \
|
||||
emit_signal("confirmation_confirmed") )
|
||||
confirm_dialog.canceled.connect(func(): _confirmed = false; \
|
||||
emit_signal("confirmation_closed"); \
|
||||
emit_signal("confirmation_canceled") )
|
||||
confirm_dialog.confirmed.connect(
|
||||
func():
|
||||
_confirmed = true
|
||||
emit_signal("confirmation_closed")
|
||||
emit_signal("confirmation_confirmed")
|
||||
)
|
||||
confirm_dialog.canceled.connect(
|
||||
func():
|
||||
_confirmed = false
|
||||
emit_signal("confirmation_closed")
|
||||
emit_signal("confirmation_canceled")
|
||||
)
|
||||
|
||||
|
||||
func get_current_list() -> ListContainer:
|
||||
@@ -141,9 +147,10 @@ func get_current_list() -> ListContainer:
|
||||
|
||||
## Dock placement
|
||||
|
||||
|
||||
func set_slot(p_slot: int) -> void:
|
||||
p_slot = clamp(p_slot, 0, POS_MAX-1)
|
||||
|
||||
p_slot = clamp(p_slot, 0, POS_MAX - 1)
|
||||
|
||||
if slot != p_slot:
|
||||
slot = p_slot
|
||||
placement_opt.selected = slot
|
||||
@@ -177,7 +184,7 @@ func remove_dock(p_force: bool = false) -> void:
|
||||
pinned_btn.visible = false
|
||||
placement_opt.visible = true
|
||||
state = HIDDEN
|
||||
update_dock() # return window to side/bottom
|
||||
update_dock() # return window to side/bottom
|
||||
|
||||
|
||||
func update_dock() -> void:
|
||||
@@ -207,7 +214,7 @@ func update_layout() -> void:
|
||||
if not window and get_parent() and get_parent().get_parent() is Window:
|
||||
window = get_parent().get_parent()
|
||||
make_dock_float()
|
||||
return # Will call this function again upon display
|
||||
return # Will call this function again upon display
|
||||
|
||||
var size_parent: Control = size_slider.get_parent()
|
||||
# Vertical layout in window / sidebar
|
||||
@@ -238,8 +245,10 @@ func update_layout() -> void:
|
||||
func update_thumbnails() -> void:
|
||||
if not is_instance_valid(plugin.terrain):
|
||||
return
|
||||
if current_list.type == Terrain3DAssets.TYPE_MESH and \
|
||||
Time.get_ticks_msec() - _last_thumb_update_time > MAX_UPDATE_TIME:
|
||||
if (
|
||||
current_list.type == Terrain3DAssets.TYPE_MESH
|
||||
and Time.get_ticks_msec() - _last_thumb_update_time > MAX_UPDATE_TIME
|
||||
):
|
||||
plugin.terrain.assets.create_mesh_thumbnails()
|
||||
_last_thumb_update_time = Time.get_ticks_msec()
|
||||
for mesh_asset in mesh_list.entries:
|
||||
@@ -293,7 +302,7 @@ func _on_meshes_pressed() -> void:
|
||||
func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation) -> void:
|
||||
if p_tool == Terrain3DEditor.INSTANCER:
|
||||
_on_meshes_pressed()
|
||||
elif p_tool in [ Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS ]:
|
||||
elif p_tool in [Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS]:
|
||||
_on_textures_pressed()
|
||||
|
||||
|
||||
@@ -303,7 +312,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
||||
func update_assets() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
|
||||
# Verify signals to individual lists
|
||||
if plugin.is_terrain_valid() and plugin.terrain.assets:
|
||||
if not plugin.terrain.assets.textures_changed.is_connected(texture_list.update_asset_list):
|
||||
@@ -318,13 +327,13 @@ func update_assets() -> void:
|
||||
|
||||
|
||||
func make_dock_float() -> void:
|
||||
# If not already created (eg from editor panel 'Make Floating' button)
|
||||
# If not already created (eg from editor panel 'Make Floating' button)
|
||||
if not window:
|
||||
remove_dock()
|
||||
create_window()
|
||||
|
||||
state = WINDOWED
|
||||
visible = true # Asset dock contents are hidden when popping out of the bottom!
|
||||
visible = true # Asset dock contents are hidden when popping out of the bottom!
|
||||
pinned_btn.visible = true
|
||||
floating_btn.visible = false
|
||||
placement_opt.visible = false
|
||||
@@ -366,13 +375,18 @@ func clamp_window_position() -> void:
|
||||
bounds = DisplayServer.screen_get_position(window.current_screen)
|
||||
bounds += DisplayServer.screen_get_size(window.current_screen)
|
||||
var margin: int = 40
|
||||
window.position.x = clamp(window.position.x, -window.size.x + 2*margin, bounds.x - margin)
|
||||
window.position.x = clamp(window.position.x, -window.size.x + 2 * margin, bounds.x - margin)
|
||||
window.position.y = clamp(window.position.y, 25, bounds.y - margin)
|
||||
|
||||
|
||||
func _on_window_input(event: InputEvent) -> void:
|
||||
# Capture CTRL+S when doc focused to save scene
|
||||
if event is InputEventKey and event.keycode == KEY_S and event.pressed and event.is_command_or_control_pressed():
|
||||
if (
|
||||
event is InputEventKey
|
||||
and event.keycode == KEY_S
|
||||
and event.pressed
|
||||
and event.is_command_or_control_pressed()
|
||||
):
|
||||
save_editor_settings()
|
||||
EditorInterface.save_scene()
|
||||
|
||||
@@ -385,7 +399,10 @@ func _on_godot_window_entered() -> void:
|
||||
func _on_godot_focus_entered() -> void:
|
||||
# If asset dock is windowed, and Godot was minimized, and now is not, restore asset dock window
|
||||
if is_instance_valid(window):
|
||||
if _godot_last_state == Window.MODE_MINIMIZED and plugin.godot_editor_window.mode != Window.MODE_MINIMIZED:
|
||||
if (
|
||||
_godot_last_state == Window.MODE_MINIMIZED
|
||||
and plugin.godot_editor_window.mode != Window.MODE_MINIMIZED
|
||||
):
|
||||
window.show()
|
||||
_godot_last_state = plugin.godot_editor_window.mode
|
||||
plugin.godot_editor_window.grab_focus()
|
||||
@@ -399,6 +416,7 @@ func _on_godot_focus_exited() -> void:
|
||||
|
||||
## Manage Editor Settings
|
||||
|
||||
|
||||
func load_editor_settings() -> void:
|
||||
floating_btn.button_pressed = plugin.get_setting(ES_DOCK_FLOATING, false)
|
||||
pinned_btn.button_pressed = plugin.get_setting(ES_DOCK_PINNED, true)
|
||||
@@ -431,8 +449,9 @@ func save_editor_settings() -> void:
|
||||
## class ListContainer
|
||||
##############################################################
|
||||
|
||||
|
||||
class ListContainer extends Container:
|
||||
|
||||
class ListContainer:
|
||||
extends Container
|
||||
var plugin: EditorPlugin
|
||||
var type := Terrain3DAssets.TYPE_TEXTURE
|
||||
var entries: Array[ListEntry]
|
||||
@@ -441,34 +460,34 @@ class ListContainer extends Container:
|
||||
var width: float = 83
|
||||
var focus_style: StyleBox
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_v_size_flags(SIZE_EXPAND_FILL)
|
||||
set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
for e in entries:
|
||||
e.get_parent().remove_child(e)
|
||||
e.queue_free()
|
||||
entries.clear()
|
||||
|
||||
|
||||
func update_asset_list() -> void:
|
||||
clear()
|
||||
|
||||
|
||||
# Grab terrain
|
||||
var t: Terrain3D
|
||||
if plugin.is_terrain_valid():
|
||||
t = plugin.terrain
|
||||
elif is_instance_valid(plugin._last_terrain) and plugin.is_terrain_valid(plugin._last_terrain):
|
||||
elif (
|
||||
is_instance_valid(plugin._last_terrain)
|
||||
and plugin.is_terrain_valid(plugin._last_terrain)
|
||||
):
|
||||
t = plugin._last_terrain
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
if not t.assets:
|
||||
return
|
||||
|
||||
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
var texture_count: int = t.assets.get_texture_count()
|
||||
for i in texture_count:
|
||||
@@ -486,12 +505,11 @@ class ListContainer extends Container:
|
||||
if selected_id >= mesh_count or selected_id < 0:
|
||||
set_selected_id(0)
|
||||
|
||||
|
||||
func add_item(p_resource: Resource = null, p_assets: Terrain3DAssets = null) -> void:
|
||||
var entry: ListEntry = ListEntry.new()
|
||||
entry.focus_style = focus_style
|
||||
var id: int = entries.size()
|
||||
|
||||
|
||||
entry.set_edited_resource(p_resource)
|
||||
entry.hovered.connect(_on_resource_hovered.bind(id))
|
||||
entry.selected.connect(set_selected_id.bind(id))
|
||||
@@ -501,55 +519,60 @@ class ListContainer extends Container:
|
||||
entry.asset_list = p_assets
|
||||
add_child(entry)
|
||||
entries.push_back(entry)
|
||||
|
||||
|
||||
if p_resource:
|
||||
entry.set_selected(id == selected_id)
|
||||
if not p_resource.id_changed.is_connected(set_selected_after_swap):
|
||||
p_resource.id_changed.connect(set_selected_after_swap)
|
||||
|
||||
|
||||
func _on_resource_hovered(p_id: int):
|
||||
if type == Terrain3DAssets.TYPE_MESH:
|
||||
if plugin.terrain:
|
||||
plugin.terrain.assets.create_mesh_thumbnails(p_id)
|
||||
|
||||
|
||||
func set_selected_after_swap(p_type: Terrain3DAssets.AssetType, p_old_id: int, p_new_id: int) -> void:
|
||||
func set_selected_after_swap(
|
||||
p_type: Terrain3DAssets.AssetType, p_old_id: int, p_new_id: int
|
||||
) -> void:
|
||||
set_selected_id(clamp(p_new_id, 0, entries.size() - 2))
|
||||
|
||||
|
||||
func set_selected_id(p_id: int) -> void:
|
||||
selected_id = p_id
|
||||
|
||||
|
||||
for i in entries.size():
|
||||
var entry: ListEntry = entries[i]
|
||||
entry.set_selected(i == selected_id)
|
||||
|
||||
|
||||
plugin.select_terrain()
|
||||
|
||||
# Select Paint tool if clicking a texture
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE and \
|
||||
not plugin.editor.get_tool() in [ Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS ]:
|
||||
if (
|
||||
type == Terrain3DAssets.TYPE_TEXTURE
|
||||
and not (
|
||||
plugin.editor.get_tool()
|
||||
in [Terrain3DEditor.TEXTURE, Terrain3DEditor.COLOR, Terrain3DEditor.ROUGHNESS]
|
||||
)
|
||||
):
|
||||
var paint_btn: Button = plugin.ui.toolbar.get_node_or_null("PaintTexture")
|
||||
if paint_btn:
|
||||
paint_btn.set_pressed(true)
|
||||
plugin.ui._on_tool_changed(Terrain3DEditor.TEXTURE, Terrain3DEditor.REPLACE)
|
||||
|
||||
elif type == Terrain3DAssets.TYPE_MESH and plugin.editor.get_tool() != Terrain3DEditor.INSTANCER:
|
||||
elif (
|
||||
type == Terrain3DAssets.TYPE_MESH
|
||||
and plugin.editor.get_tool() != Terrain3DEditor.INSTANCER
|
||||
):
|
||||
var instancer_btn: Button = plugin.ui.toolbar.get_node_or_null("InstanceMeshes")
|
||||
if instancer_btn:
|
||||
instancer_btn.set_pressed(true)
|
||||
plugin.ui._on_tool_changed(Terrain3DEditor.INSTANCER, Terrain3DEditor.ADD)
|
||||
|
||||
|
||||
# Update editor with selected brush
|
||||
plugin.ui._on_setting_changed()
|
||||
|
||||
|
||||
func _on_resource_inspected(p_resource: Resource) -> void:
|
||||
await get_tree().create_timer(.01).timeout
|
||||
EditorInterface.edit_resource(p_resource)
|
||||
|
||||
|
||||
|
||||
func _on_resource_changed(p_resource: Resource, p_id: int) -> void:
|
||||
if not p_resource:
|
||||
var asset_dock: Control = get_parent().get_parent().get_parent()
|
||||
@@ -562,7 +585,7 @@ class ListContainer extends Container:
|
||||
if not asset_dock._confirmed:
|
||||
update_asset_list()
|
||||
return
|
||||
|
||||
|
||||
if not plugin.is_terrain_valid():
|
||||
plugin.select_terrain()
|
||||
await get_tree().create_timer(.01).timeout
|
||||
@@ -577,32 +600,27 @@ class ListContainer extends Container:
|
||||
|
||||
# If removing an entry, clear inspector
|
||||
if not p_resource:
|
||||
EditorInterface.inspect_object(null)
|
||||
|
||||
# If null resource, remove last
|
||||
EditorInterface.inspect_object(null)
|
||||
|
||||
# If null resource, remove last
|
||||
if not p_resource:
|
||||
var last_offset: int = 2
|
||||
if p_id == entries.size()-2:
|
||||
if p_id == entries.size() - 2:
|
||||
last_offset = 3
|
||||
set_selected_id(clamp(selected_id, 0, entries.size() - last_offset))
|
||||
|
||||
|
||||
func get_selected_id() -> int:
|
||||
return selected_id
|
||||
|
||||
|
||||
func get_selected_asset_id() -> int:
|
||||
return selected_id
|
||||
|
||||
|
||||
func set_entry_width(value: float) -> void:
|
||||
width = clamp(value, 66, 230)
|
||||
redraw()
|
||||
|
||||
|
||||
func get_entry_width() -> float:
|
||||
return width
|
||||
|
||||
|
||||
func redraw() -> void:
|
||||
height = 0
|
||||
@@ -610,21 +628,21 @@ class ListContainer extends Container:
|
||||
var separation: float = 4
|
||||
var columns: int = 3
|
||||
columns = clamp(size.x / width, 1, 100)
|
||||
|
||||
|
||||
for c in get_children():
|
||||
if is_instance_valid(c):
|
||||
c.size = Vector2(width, width) - Vector2(separation, separation)
|
||||
c.position = Vector2(id % columns, id / columns) * width + \
|
||||
Vector2(separation / columns, separation / columns)
|
||||
c.position = (
|
||||
Vector2(id % columns, id / columns) * width
|
||||
+ Vector2(separation / columns, separation / columns)
|
||||
)
|
||||
height = max(height, c.position.y + width)
|
||||
id += 1
|
||||
|
||||
|
||||
# Needed to enable ScrollContainer scroll bar
|
||||
func _get_minimum_size() -> Vector2:
|
||||
return Vector2(0, height)
|
||||
|
||||
|
||||
func _notification(p_what) -> void:
|
||||
if p_what == NOTIFICATION_SORT_CHILDREN:
|
||||
redraw()
|
||||
@@ -635,12 +653,13 @@ class ListContainer extends Container:
|
||||
##############################################################
|
||||
|
||||
|
||||
class ListEntry extends VBoxContainer:
|
||||
signal hovered()
|
||||
signal selected()
|
||||
class ListEntry:
|
||||
extends VBoxContainer
|
||||
signal hovered
|
||||
signal selected
|
||||
signal changed(resource: Resource)
|
||||
signal inspected(resource: Resource)
|
||||
|
||||
|
||||
var resource: Resource
|
||||
var type := Terrain3DAssets.TYPE_TEXTURE
|
||||
var _thumbnail: Texture2D
|
||||
@@ -648,7 +667,7 @@ class ListEntry extends VBoxContainer:
|
||||
var is_hovered: bool = false
|
||||
var is_selected: bool = false
|
||||
var asset_list: Terrain3DAssets
|
||||
|
||||
|
||||
@onready var button_row := HBoxContainer.new()
|
||||
@onready var button_clear := TextureButton.new()
|
||||
@onready var button_edit := TextureButton.new()
|
||||
@@ -664,14 +683,12 @@ class ListEntry extends VBoxContainer:
|
||||
@onready var background: StyleBox = get_theme_stylebox("pressed", "Button")
|
||||
@onready var focus_style: StyleBox = get_theme_stylebox("focus", "Button").duplicate()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
setup_buttons()
|
||||
setup_label()
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
|
||||
|
||||
func setup_buttons() -> void:
|
||||
var icon_size: Vector2 = Vector2(12, 12)
|
||||
var margin_container := MarginContainer.new()
|
||||
@@ -680,7 +697,7 @@ class ListEntry extends VBoxContainer:
|
||||
margin_container.add_theme_constant_override("margin_left", 5)
|
||||
margin_container.add_theme_constant_override("margin_right", 5)
|
||||
add_child(margin_container)
|
||||
|
||||
|
||||
button_row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
button_row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
button_row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
@@ -696,7 +713,7 @@ class ListEntry extends VBoxContainer:
|
||||
button_enabled.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_enabled.pressed.connect(enable)
|
||||
button_row.add_child(button_enabled)
|
||||
|
||||
|
||||
button_edit.set_texture_normal(edit_icon)
|
||||
button_edit.set_custom_minimum_size(icon_size)
|
||||
button_edit.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
@@ -708,7 +725,7 @@ class ListEntry extends VBoxContainer:
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
spacer.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
button_row.add_child(spacer)
|
||||
|
||||
|
||||
button_clear.set_texture_normal(clear_icon)
|
||||
button_clear.set_custom_minimum_size(icon_size)
|
||||
button_clear.set_h_size_flags(Control.SIZE_SHRINK_END)
|
||||
@@ -717,7 +734,6 @@ class ListEntry extends VBoxContainer:
|
||||
button_clear.pressed.connect(clear)
|
||||
button_row.add_child(button_clear)
|
||||
|
||||
|
||||
func setup_label() -> void:
|
||||
name_label = Label.new()
|
||||
add_child(name_label, true)
|
||||
@@ -737,13 +753,12 @@ class ListEntry extends VBoxContainer:
|
||||
else:
|
||||
name_label.text = "Add Mesh"
|
||||
|
||||
|
||||
func _notification(p_what) -> void:
|
||||
match p_what:
|
||||
NOTIFICATION_DRAW:
|
||||
# Hide spacer if icons are crowding small textures
|
||||
spacer.visible = size.x > 70 or type == Terrain3DAssets.TYPE_TEXTURE
|
||||
|
||||
|
||||
var rect: Rect2 = Rect2(Vector2.ZERO, get_size())
|
||||
if !resource:
|
||||
draw_style_box(background, rect)
|
||||
@@ -766,7 +781,7 @@ class ListEntry extends VBoxContainer:
|
||||
else:
|
||||
draw_rect(rect, Color(.15, .15, .15, 1.))
|
||||
button_enabled.set_pressed_no_signal(!resource.is_enabled())
|
||||
name_label.add_theme_font_size_override("font_size", 4 + rect.size.x/10)
|
||||
name_label.add_theme_font_size_override("font_size", 4 + rect.size.x / 10)
|
||||
if drop_data:
|
||||
draw_style_box(focus_style, rect)
|
||||
if is_hovered:
|
||||
@@ -784,7 +799,6 @@ class ListEntry extends VBoxContainer:
|
||||
drop_data = false
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _gui_input(p_event: InputEvent) -> void:
|
||||
if p_event is InputEventMouseButton:
|
||||
if p_event.is_pressed():
|
||||
@@ -806,7 +820,6 @@ class ListEntry extends VBoxContainer:
|
||||
if resource:
|
||||
clear()
|
||||
|
||||
|
||||
func _can_drop_data(p_at_position: Vector2, p_data: Variant) -> bool:
|
||||
drop_data = false
|
||||
if typeof(p_data) == TYPE_DICTIONARY:
|
||||
@@ -815,7 +828,6 @@ class ListEntry extends VBoxContainer:
|
||||
drop_data = true
|
||||
return drop_data
|
||||
|
||||
|
||||
func _drop_data(p_at_position: Vector2, p_data: Variant) -> void:
|
||||
if typeof(p_data) == TYPE_DICTIONARY:
|
||||
var res: Resource = load(p_data.files[0])
|
||||
@@ -844,8 +856,6 @@ class ListEntry extends VBoxContainer:
|
||||
emit_signal("selected")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
|
||||
func set_edited_resource(p_res: Resource, p_no_signal: bool = true) -> void:
|
||||
resource = p_res
|
||||
if resource:
|
||||
@@ -853,35 +863,30 @@ class ListEntry extends VBoxContainer:
|
||||
resource.file_changed.connect(_on_resource_changed)
|
||||
if resource is Terrain3DMeshAsset:
|
||||
resource.instancer_setting_changed.connect(_on_resource_changed)
|
||||
|
||||
|
||||
if button_clear:
|
||||
button_clear.set_visible(resource != null)
|
||||
|
||||
|
||||
queue_redraw()
|
||||
if !p_no_signal:
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
func _on_resource_changed() -> void:
|
||||
queue_redraw()
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
func set_selected(value: bool) -> void:
|
||||
is_selected = value
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
if resource:
|
||||
set_edited_resource(null, false)
|
||||
|
||||
|
||||
func edit() -> void:
|
||||
emit_signal("selected")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
func enable() -> void:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
resource.set_enabled(!resource.is_enabled())
|
||||
|
||||
@@ -8,11 +8,11 @@ extends Control
|
||||
signal value_changed(Vector2)
|
||||
var label: Label
|
||||
var suffix: String
|
||||
var grabbed_handle: int = 0 # -1 left, 0 none, 1 right
|
||||
var grabbed_handle: int = 0 # -1 left, 0 none, 1 right
|
||||
var min_value: float = 0.0
|
||||
var max_value: float = 100.0
|
||||
var step: float = 1.0
|
||||
var range := Vector2(0, 100)
|
||||
var range := Vector2(0, 100)
|
||||
var display_scale: float = 1.
|
||||
var position_x: float = 0.
|
||||
var minimum_x: float = 60.
|
||||
@@ -43,8 +43,8 @@ func set_min(p_value: float) -> void:
|
||||
|
||||
func get_min() -> float:
|
||||
return min_value
|
||||
|
||||
|
||||
|
||||
|
||||
func set_max(p_value: float) -> void:
|
||||
max_value = p_value
|
||||
if range.y == 0 or range.y >= max_value:
|
||||
@@ -55,15 +55,15 @@ func set_max(p_value: float) -> void:
|
||||
|
||||
func get_max() -> float:
|
||||
return max_value
|
||||
|
||||
|
||||
|
||||
|
||||
func set_step(p_step: float) -> void:
|
||||
step = p_step
|
||||
|
||||
|
||||
|
||||
func get_step() -> float:
|
||||
return step
|
||||
|
||||
|
||||
|
||||
func set_value(p_range: Vector2) -> void:
|
||||
range.x = clamp(p_range.x, min_value, max_value)
|
||||
@@ -99,7 +99,7 @@ func _get_handle() -> int:
|
||||
func _gui_input(p_event: InputEvent) -> void:
|
||||
if p_event is InputEventMouseButton:
|
||||
var button: int = p_event.get_button_index()
|
||||
if button in [ MOUSE_BUTTON_LEFT, MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN ]:
|
||||
if button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN]:
|
||||
if p_event.is_pressed():
|
||||
var mid_point = (range.x + range.y) / 2.0
|
||||
var xpos: float = p_event.get_position().x * 2.0
|
||||
@@ -116,17 +116,19 @@ func _gui_input(p_event: InputEvent) -> void:
|
||||
set_slider(1., true)
|
||||
else:
|
||||
grabbed_handle = 0
|
||||
|
||||
|
||||
if p_event is InputEventMouseMotion:
|
||||
if grabbed_handle != 0:
|
||||
set_slider(p_event.get_position().x)
|
||||
|
||||
|
||||
|
||||
|
||||
func set_slider(p_xpos: float, p_relative: bool = false) -> void:
|
||||
if grabbed_handle == 0:
|
||||
return
|
||||
var xpos_step: float = clamp(snappedf((p_xpos / size.x) * max_value, step), min_value, max_value)
|
||||
if(grabbed_handle < 0):
|
||||
var xpos_step: float = clamp(
|
||||
snappedf((p_xpos / size.x) * max_value, step), min_value, max_value
|
||||
)
|
||||
if grabbed_handle < 0:
|
||||
if p_relative:
|
||||
range.x += p_xpos
|
||||
else:
|
||||
@@ -135,7 +137,7 @@ func set_slider(p_xpos: float, p_relative: bool = false) -> void:
|
||||
if p_relative:
|
||||
range.y += p_xpos
|
||||
else:
|
||||
range.y = xpos_step
|
||||
range.y = xpos_step
|
||||
set_value(range)
|
||||
|
||||
|
||||
@@ -146,19 +148,19 @@ func _notification(p_what: int) -> void:
|
||||
var bg_height: float = bg.get_minimum_size().y
|
||||
var mid_y: float = (size.y - bg_height) / 2.0
|
||||
draw_style_box(bg, Rect2(Vector2(0, mid_y), Vector2(size.x, bg_height)))
|
||||
|
||||
|
||||
# Draw foreground bar
|
||||
var handle: Texture2D = get_theme_icon("grabber", "HSlider")
|
||||
var area: StyleBox = get_theme_stylebox("grabber_area", "HSlider")
|
||||
var startx: float = (range.x / max_value) * size.x
|
||||
var endx: float = (range.y / max_value) * size.x
|
||||
draw_style_box(area, Rect2(Vector2(startx, mid_y), Vector2(endx - startx, bg_height)))
|
||||
|
||||
|
||||
# Draw handles, slightly in so they don't get on the outside edges
|
||||
var handle_pos: Vector2
|
||||
handle_pos.x = clamp(startx - handle.get_size().x/2, -10, size.x)
|
||||
handle_pos.y = clamp(endx - handle.get_size().x/2, 0, size.x - 10)
|
||||
handle_pos.x = clamp(startx - handle.get_size().x / 2, -10, size.x)
|
||||
handle_pos.y = clamp(endx - handle.get_size().x / 2, 0, size.x - 10)
|
||||
draw_texture(handle, Vector2(handle_pos.x, -mid_y - 10 * (display_scale - 1.)))
|
||||
draw_texture(handle, Vector2(handle_pos.y, -mid_y - 10 * (display_scale - 1.)))
|
||||
|
||||
|
||||
update_label()
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
|
||||
# Includes
|
||||
const UI: Script = preload("res://addons/terrain_3d/src/ui.gd")
|
||||
const RegionGizmo: Script = preload("res://addons/terrain_3d/src/region_gizmo.gd")
|
||||
@@ -14,7 +13,7 @@ var modifier_ctrl: bool
|
||||
var modifier_alt: bool
|
||||
var modifier_shift: bool
|
||||
var _last_modifiers: int = 0
|
||||
var _input_mode: int = 0 # -1: camera move, 0: none, 1: operating
|
||||
var _input_mode: int = 0 # -1: camera move, 0: none, 1: operating
|
||||
var rmb_release_time: int = 0
|
||||
var _use_meta: bool = false
|
||||
|
||||
@@ -22,26 +21,26 @@ var terrain: Terrain3D
|
||||
var _last_terrain: Terrain3D
|
||||
var nav_region: NavigationRegion3D
|
||||
|
||||
var debug: int = 0 # Set in _edit()
|
||||
var debug: int = 0 # Set in _edit()
|
||||
var editor: Terrain3DEditor
|
||||
var editor_settings: EditorSettings
|
||||
var ui: Node # Terrain3DUI see Godot #75388
|
||||
var ui: Node # Terrain3DUI see Godot #75388
|
||||
var asset_dock: PanelContainer
|
||||
var region_gizmo: RegionGizmo
|
||||
var current_region_position: Vector2
|
||||
var mouse_global_position: Vector3 = Vector3.ZERO
|
||||
var godot_editor_window: Window # The Godot Editor window
|
||||
var godot_editor_window: Window # The Godot Editor window
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
if OS.get_name() == "macOS":
|
||||
_use_meta = true
|
||||
|
||||
|
||||
# Get the Godot Editor window. Structure is root:Window/EditorNode/Base Control
|
||||
godot_editor_window = EditorInterface.get_base_control().get_parent().get_parent()
|
||||
godot_editor_window.focus_entered.connect(_on_godot_focus_entered)
|
||||
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
editor = Terrain3DEditor.new()
|
||||
setup_editor_settings()
|
||||
@@ -77,7 +76,7 @@ func _on_godot_focus_entered() -> void:
|
||||
|
||||
|
||||
## EditorPlugin selection function call chain isn't consistent. Here's the map of calls:
|
||||
## Assume we handle Terrain3D and NavigationRegion3D
|
||||
## Assume we handle Terrain3D and NavigationRegion3D
|
||||
# Click Terrain3D: _handles(Terrain3D), _make_visible(true), _edit(Terrain3D)
|
||||
# Deselect: _make_visible(false), _edit(null)
|
||||
# Click other node: _handles(OtherNode)
|
||||
@@ -89,14 +88,14 @@ func _handles(p_object: Object) -> bool:
|
||||
return true
|
||||
elif p_object is NavigationRegion3D and is_instance_valid(_last_terrain):
|
||||
return true
|
||||
|
||||
|
||||
# Terrain3DObjects requires access to EditorUndoRedoManager. The only way to make sure it
|
||||
# always has it, is to pass it in here. _edit is NOT called if the node is cut and pasted.
|
||||
elif p_object is Terrain3DObjects:
|
||||
p_object.editor_setup(self)
|
||||
elif p_object is Node3D and p_object.get_parent() is Terrain3DObjects:
|
||||
p_object.get_parent().editor_setup(self)
|
||||
|
||||
|
||||
return false
|
||||
|
||||
|
||||
@@ -119,7 +118,7 @@ func _edit(p_object: Object) -> void:
|
||||
_last_terrain = terrain
|
||||
terrain.set_plugin(self)
|
||||
terrain.set_editor(editor)
|
||||
debug = terrain.debug_level
|
||||
debug = terrain.debug_level
|
||||
editor.set_terrain(terrain)
|
||||
region_gizmo.set_node_3d(terrain)
|
||||
terrain.add_gizmo(region_gizmo)
|
||||
@@ -144,18 +143,18 @@ func _edit(p_object: Object) -> void:
|
||||
else:
|
||||
nav_region = null
|
||||
|
||||
|
||||
|
||||
func _clear() -> void:
|
||||
if is_terrain_valid():
|
||||
if terrain.data.region_map_changed.is_connected(update_region_grid):
|
||||
terrain.data.region_map_changed.disconnect(update_region_grid)
|
||||
|
||||
|
||||
terrain.clear_gizmos()
|
||||
terrain = null
|
||||
editor.set_terrain(null)
|
||||
|
||||
|
||||
ui.clear_picking()
|
||||
|
||||
|
||||
region_gizmo.clear()
|
||||
|
||||
|
||||
@@ -167,13 +166,13 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
|
||||
if continue_input != AFTER_GUI_INPUT_CUSTOM:
|
||||
return continue_input
|
||||
ui.update_decal()
|
||||
|
||||
|
||||
## Setup active camera & viewport
|
||||
# Always update this for all inputs, as the mouse position can move without
|
||||
# necessarily being a InputEventMouseMotion object. get_intersection() also
|
||||
# returns the last frame position, and should be updated more frequently.
|
||||
|
||||
# Snap terrain to current camera
|
||||
|
||||
# Snap terrain to current camera
|
||||
terrain.set_camera(p_viewport_camera)
|
||||
|
||||
# Detect if viewport is set to half_resolution
|
||||
@@ -193,19 +192,23 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
|
||||
var t = -Vector3(0, 1, 0).dot(camera_pos) / Vector3(0, 1, 0).dot(camera_dir)
|
||||
mouse_global_position = (camera_pos + t * camera_dir)
|
||||
else:
|
||||
#Else look for intersection with terrain
|
||||
#Else look for intersection with terrain
|
||||
var intersection_point: Vector3 = terrain.get_intersection(camera_pos, camera_dir, true)
|
||||
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
|
||||
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
mouse_global_position = intersection_point
|
||||
|
||||
|
||||
## Handle mouse movement
|
||||
if p_event is InputEventMouseMotion:
|
||||
|
||||
if _input_mode != -1: # Not cam rotation
|
||||
if _input_mode != -1: # Not cam rotation
|
||||
## Update region highlight
|
||||
var region_position: Vector2 = ( Vector2(mouse_global_position.x, mouse_global_position.z) \
|
||||
/ (terrain.get_region_size() * terrain.get_vertex_spacing()) ).floor()
|
||||
var region_position: Vector2 = (
|
||||
(
|
||||
Vector2(mouse_global_position.x, mouse_global_position.z)
|
||||
/ (terrain.get_region_size() * terrain.get_vertex_spacing())
|
||||
)
|
||||
. floor()
|
||||
)
|
||||
if current_region_position != region_position:
|
||||
current_region_position = region_position
|
||||
update_region_grid()
|
||||
@@ -216,7 +219,7 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
|
||||
|
||||
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
|
||||
if p_event is InputEventMouseButton and _input_mode > 0:
|
||||
@@ -226,31 +229,35 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
|
||||
ui.pick(mouse_global_position)
|
||||
if not ui.operation_builder or not ui.operation_builder.is_ready():
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
|
||||
if modifier_ctrl and editor.get_tool() == Terrain3DEditor.HEIGHT:
|
||||
var height: float = terrain.data.get_height(mouse_global_position)
|
||||
ui.brush_data["height"] = height
|
||||
ui.tool_settings.set_setting("height", height)
|
||||
|
||||
|
||||
# If adjusting regions
|
||||
if editor.get_tool() == Terrain3DEditor.REGION:
|
||||
# Skip regions that already exist or don't
|
||||
var has_region: bool = terrain.data.has_regionp(mouse_global_position)
|
||||
var op: int = editor.get_operation()
|
||||
if ( has_region and op == Terrain3DEditor.ADD) or \
|
||||
( not has_region and op == Terrain3DEditor.SUBTRACT ):
|
||||
if (
|
||||
(has_region and op == Terrain3DEditor.ADD)
|
||||
or (not has_region and op == Terrain3DEditor.SUBTRACT)
|
||||
):
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
|
||||
# If an automatic operation is ready to go (e.g. gradient)
|
||||
if ui.operation_builder and ui.operation_builder.is_ready():
|
||||
ui.operation_builder.apply_operation(editor, mouse_global_position, p_viewport_camera.rotation.y)
|
||||
ui.operation_builder.apply_operation(
|
||||
editor, mouse_global_position, p_viewport_camera.rotation.y
|
||||
)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
|
||||
# Mouse clicked, start editing
|
||||
editor.start_operation(mouse_global_position)
|
||||
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
|
||||
# _input_apply released, save undo data
|
||||
elif editor.is_operating():
|
||||
editor.stop_operation()
|
||||
@@ -261,66 +268,97 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
|
||||
|
||||
func _read_input(p_event: InputEvent = null) -> AfterGUIInput:
|
||||
## Determine if user is moving camera or applying
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or \
|
||||
p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
p_event.get_button_index() == MOUSE_BUTTON_LEFT:
|
||||
_input_mode = 1
|
||||
if (
|
||||
Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
or (
|
||||
p_event is InputEventMouseButton
|
||||
and p_event.is_released()
|
||||
and p_event.get_button_index() == MOUSE_BUTTON_LEFT
|
||||
)
|
||||
):
|
||||
_input_mode = 1
|
||||
else:
|
||||
_input_mode = 0
|
||||
|
||||
_input_mode = 0
|
||||
|
||||
match get_setting("editors/3d/navigation/navigation_scheme", 0):
|
||||
2, 1: # Modo, Maya
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
|
||||
( Input.is_key_pressed(KEY_ALT) and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) ):
|
||||
_input_mode = -1
|
||||
if p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
|
||||
( Input.is_key_pressed(KEY_ALT) and p_event.get_button_index() == MOUSE_BUTTON_LEFT )):
|
||||
rmb_release_time = Time.get_ticks_msec()
|
||||
0, _: # Godot
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
|
||||
Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
|
||||
_input_mode = -1
|
||||
if p_event is InputEventMouseButton and p_event.is_released() and \
|
||||
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
|
||||
p_event.get_button_index() == MOUSE_BUTTON_MIDDLE ):
|
||||
rmb_release_time = Time.get_ticks_msec()
|
||||
2, 1: # Modo, Maya
|
||||
if (
|
||||
Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
|
||||
or (
|
||||
Input.is_key_pressed(KEY_ALT)
|
||||
and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
)
|
||||
):
|
||||
_input_mode = -1
|
||||
if (
|
||||
p_event is InputEventMouseButton
|
||||
and p_event.is_released()
|
||||
and (
|
||||
p_event.get_button_index() == MOUSE_BUTTON_RIGHT
|
||||
or (
|
||||
Input.is_key_pressed(KEY_ALT)
|
||||
and p_event.get_button_index() == MOUSE_BUTTON_LEFT
|
||||
)
|
||||
)
|
||||
):
|
||||
rmb_release_time = Time.get_ticks_msec()
|
||||
0, _: # Godot
|
||||
if (
|
||||
Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
|
||||
or Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)
|
||||
):
|
||||
_input_mode = -1
|
||||
if (
|
||||
p_event is InputEventMouseButton
|
||||
and p_event.is_released()
|
||||
and (
|
||||
p_event.get_button_index() == MOUSE_BUTTON_RIGHT
|
||||
or p_event.get_button_index() == MOUSE_BUTTON_MIDDLE
|
||||
)
|
||||
):
|
||||
rmb_release_time = Time.get_ticks_msec()
|
||||
if _input_mode < 0:
|
||||
# Camera is moving, skip input
|
||||
return AFTER_GUI_INPUT_PASS
|
||||
|
||||
## Determine modifiers pressed
|
||||
modifier_shift = Input.is_key_pressed(KEY_SHIFT)
|
||||
|
||||
# Editor responds to modifier_ctrl so we must register touchscreen Invert
|
||||
|
||||
# Editor responds to modifier_ctrl so we must register touchscreen Invert
|
||||
if _use_meta:
|
||||
modifier_ctrl = Input.is_key_pressed(KEY_META) || ui.inverted_input
|
||||
else:
|
||||
modifier_ctrl = Input.is_key_pressed(KEY_CTRL) || ui.inverted_input
|
||||
|
||||
|
||||
# Keybind enum: Alt,Space,Meta,Capslock
|
||||
var alt_key: int
|
||||
match get_setting("terrain3d/config/alt_key_bind", 0):
|
||||
3: alt_key = KEY_CAPSLOCK
|
||||
2: alt_key = KEY_META
|
||||
1: alt_key = KEY_SPACE
|
||||
0, _: alt_key = KEY_ALT
|
||||
3:
|
||||
alt_key = KEY_CAPSLOCK
|
||||
2:
|
||||
alt_key = KEY_META
|
||||
1:
|
||||
alt_key = KEY_SPACE
|
||||
0, _:
|
||||
alt_key = KEY_ALT
|
||||
modifier_alt = Input.is_key_pressed(alt_key)
|
||||
var current_mods: int = int(modifier_shift) | int(modifier_ctrl) << 1 | int(modifier_alt) << 2
|
||||
|
||||
## Process Hotkeys
|
||||
if p_event is InputEventKey and \
|
||||
current_mods == 0 and \
|
||||
p_event.is_pressed() and \
|
||||
not p_event.is_echo() and \
|
||||
consume_hotkey(p_event.keycode):
|
||||
if (
|
||||
p_event is InputEventKey
|
||||
and current_mods == 0
|
||||
and p_event.is_pressed()
|
||||
and not p_event.is_echo()
|
||||
and consume_hotkey(p_event.keycode)
|
||||
):
|
||||
# Hotkey found, consume event, and stop input processing
|
||||
EditorInterface.get_editor_viewport_3d().set_input_as_handled()
|
||||
return AFTER_GUI_INPUT_STOP
|
||||
|
||||
# Brush data is cleared on set_tool, or clicking textures in the asset dock
|
||||
# Update modifiers if changed or missing
|
||||
if _last_modifiers != current_mods or not ui.brush_data.has("modifier_shift"):
|
||||
if _last_modifiers != current_mods or not ui.brush_data.has("modifier_shift"):
|
||||
_last_modifiers = current_mods
|
||||
ui.brush_data["modifier_shift"] = modifier_shift
|
||||
ui.brush_data["modifier_ctrl"] = modifier_ctrl
|
||||
@@ -337,7 +375,7 @@ func consume_hotkey(keycode: int) -> bool:
|
||||
KEY_1, KEY_KP_1:
|
||||
terrain.material.set_show_region_grid(!terrain.material.get_show_region_grid())
|
||||
KEY_2, KEY_KP_2:
|
||||
terrain.label_distance = 4096.0 if is_zero_approx(terrain.label_distance) else 0.0
|
||||
terrain.label_distance = 4096.0 if is_zero_approx(terrain.label_distance) else 0.0
|
||||
KEY_3, KEY_KP_3:
|
||||
terrain.material.set_show_contours(!terrain.material.get_show_contours())
|
||||
KEY_4, KEY_KP_4:
|
||||
@@ -384,10 +422,10 @@ func update_region_grid() -> void:
|
||||
region_gizmo.region_position = current_region_position
|
||||
region_gizmo.region_size = terrain.get_region_size() * terrain.get_vertex_spacing()
|
||||
region_gizmo.grid = terrain.get_data().get_region_locations()
|
||||
|
||||
|
||||
terrain.update_gizmos()
|
||||
return
|
||||
|
||||
|
||||
region_gizmo.show_rect = false
|
||||
region_gizmo.region_size = 1024
|
||||
region_gizmo.grid = [Vector2i.ZERO]
|
||||
@@ -396,7 +434,7 @@ func update_region_grid() -> void:
|
||||
func _on_scene_changed(scene_root: Node) -> void:
|
||||
if not scene_root:
|
||||
return
|
||||
|
||||
|
||||
for node in scene_root.find_children("", "Terrain3DObjects"):
|
||||
node.editor_setup(self)
|
||||
|
||||
@@ -426,10 +464,15 @@ func is_terrain_valid(p_terrain: Terrain3D = null) -> bool:
|
||||
func is_selected() -> bool:
|
||||
var selected: Array[Node] = EditorInterface.get_selection().get_selected_nodes()
|
||||
for node in selected:
|
||||
if ( is_instance_valid(_last_terrain) and node.get_instance_id() == _last_terrain.get_instance_id() ) or \
|
||||
node is Terrain3D:
|
||||
return true
|
||||
return false
|
||||
if (
|
||||
(
|
||||
is_instance_valid(_last_terrain)
|
||||
and node.get_instance_id() == _last_terrain.get_instance_id()
|
||||
)
|
||||
or node is Terrain3D
|
||||
):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func select_terrain() -> void:
|
||||
@@ -453,7 +496,7 @@ func setup_editor_settings() -> void:
|
||||
"hint_string": "Alt,Space,Meta,Capslock"
|
||||
}
|
||||
editor_settings.add_property_info(property_info)
|
||||
|
||||
|
||||
|
||||
func set_setting(p_str: String, p_value: Variant) -> void:
|
||||
editor_settings.set_setting(p_str, p_value)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Gradient Operation Builder for Terrain3D
|
||||
extends "res://addons/terrain_3d/src/operation_builder.gd"
|
||||
|
||||
|
||||
const MultiPicker: Script = preload("res://addons/terrain_3d/src/multi_picker.gd")
|
||||
|
||||
|
||||
@@ -31,26 +30,28 @@ func is_ready() -> bool:
|
||||
return _get_point_picker().all_points_selected() and not _is_drawable()
|
||||
|
||||
|
||||
func apply_operation(p_editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float) -> void:
|
||||
func apply_operation(
|
||||
p_editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float
|
||||
) -> void:
|
||||
var points: PackedVector3Array = _get_point_picker().get_points()
|
||||
assert(points.size() == 2)
|
||||
assert(not _is_drawable())
|
||||
|
||||
|
||||
var brush_size: float = _get_brush_size()
|
||||
assert(brush_size > 0.0)
|
||||
|
||||
|
||||
var start: Vector3 = points[0]
|
||||
var end: Vector3 = points[1]
|
||||
|
||||
|
||||
p_editor.start_operation(start)
|
||||
|
||||
|
||||
var dir: Vector3 = (end - start).normalized()
|
||||
|
||||
|
||||
var pos: Vector3 = start
|
||||
while dir.dot(end - pos) > 0.0:
|
||||
p_editor.operate(pos, p_camera_direction)
|
||||
pos += dir * brush_size * 0.2
|
||||
|
||||
|
||||
p_editor.stop_operation()
|
||||
|
||||
|
||||
_get_point_picker().clear()
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
# Multipicker for Terrain3D
|
||||
extends HBoxContainer
|
||||
|
||||
|
||||
signal pressed
|
||||
signal value_changed
|
||||
|
||||
|
||||
const ICON_PICKER_CHECKED: String = "res://addons/terrain_3d/icons/picker_checked.svg"
|
||||
const MAX_POINTS: int = 2
|
||||
|
||||
|
||||
var icon_picker: Texture2D
|
||||
var icon_picker_checked: Texture2D
|
||||
var points: PackedVector3Array
|
||||
@@ -20,9 +17,9 @@ var picking_index: int = -1
|
||||
func _enter_tree() -> void:
|
||||
icon_picker = get_theme_icon("ColorPick", "EditorIcons")
|
||||
icon_picker_checked = load(ICON_PICKER_CHECKED)
|
||||
|
||||
|
||||
points.resize(MAX_POINTS)
|
||||
|
||||
|
||||
for i in range(MAX_POINTS):
|
||||
var button := Button.new()
|
||||
button.icon = icon_picker
|
||||
@@ -30,7 +27,7 @@ func _enter_tree() -> void:
|
||||
button.set_meta(&"point_index", i)
|
||||
button.pressed.connect(_on_button_pressed.bind(i))
|
||||
add_child(button)
|
||||
|
||||
|
||||
_update_buttons()
|
||||
|
||||
|
||||
@@ -49,7 +46,7 @@ func _update_buttons() -> void:
|
||||
|
||||
func _update_button(button: Button) -> void:
|
||||
var index: int = button.get_meta(&"point_index")
|
||||
|
||||
|
||||
if points[index] != Vector3.ZERO:
|
||||
button.icon = icon_picker_checked
|
||||
else:
|
||||
@@ -69,7 +66,7 @@ func all_points_selected() -> bool:
|
||||
func add_point(p_value: Vector3) -> void:
|
||||
if points.has(p_value):
|
||||
return
|
||||
|
||||
|
||||
# If manually selecting a point individually
|
||||
if picking_index != -1:
|
||||
points[picking_index] = p_value
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
# Operation Builder for Terrain3D
|
||||
extends RefCounted
|
||||
|
||||
|
||||
const ToolSettings: Script = preload("res://addons/terrain_3d/src/tool_settings.gd")
|
||||
|
||||
|
||||
var tool_settings: ToolSettings
|
||||
|
||||
|
||||
@@ -21,5 +19,7 @@ func is_ready() -> bool:
|
||||
return false
|
||||
|
||||
|
||||
func apply_operation(editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float) -> void:
|
||||
func apply_operation(
|
||||
editor: Terrain3DEditor, p_global_position: Vector3, p_camera_direction: float
|
||||
) -> void:
|
||||
pass
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright © 2023-2026 Cory Petkovsek, Roope Palmroos, and Contributors.
|
||||
# Editor Region Gizmos for Terrain3D
|
||||
extends EditorNode3DGizmo
|
||||
|
||||
|
||||
var material: StandardMaterial3D
|
||||
var selection_material: StandardMaterial3D
|
||||
var region_position: Vector2
|
||||
@@ -22,34 +22,49 @@ func _init() -> void:
|
||||
material.set_flag(BaseMaterial3D.FLAG_ALBEDO_FROM_VERTEX_COLOR, true)
|
||||
material.set_shading_mode(BaseMaterial3D.SHADING_MODE_UNSHADED)
|
||||
material.set_albedo(Color.WHITE)
|
||||
|
||||
|
||||
selection_material = material.duplicate()
|
||||
selection_material.set_render_priority(0)
|
||||
|
||||
|
||||
func _redraw() -> void:
|
||||
clear()
|
||||
|
||||
|
||||
var rect_position = region_position * region_size
|
||||
|
||||
if show_rect:
|
||||
var modulate: Color = main_color if !use_secondary_color else secondary_color
|
||||
if abs(region_position.x) > Terrain3DData.REGION_MAP_SIZE*.5 or abs(region_position.y) > Terrain3DData.REGION_MAP_SIZE*.5:
|
||||
if (
|
||||
abs(region_position.x) > Terrain3DData.REGION_MAP_SIZE * .5
|
||||
or abs(region_position.y) > Terrain3DData.REGION_MAP_SIZE * .5
|
||||
):
|
||||
modulate = Color.GRAY
|
||||
draw_rect(Vector2(region_size,region_size)*.5 + rect_position, region_size, selection_material, modulate)
|
||||
|
||||
draw_rect(
|
||||
Vector2(region_size, region_size) * .5 + rect_position,
|
||||
region_size,
|
||||
selection_material,
|
||||
modulate
|
||||
)
|
||||
|
||||
for pos in grid:
|
||||
var grid_tile_position = Vector2(pos) * region_size
|
||||
if show_rect and grid_tile_position == rect_position:
|
||||
# Skip this one, otherwise focused region borders are not always visible due to draw order
|
||||
continue
|
||||
|
||||
draw_rect(Vector2(region_size,region_size)*.5 + grid_tile_position, region_size, material, grid_color)
|
||||
|
||||
|
||||
draw_rect(
|
||||
Vector2(region_size, region_size) * .5 + grid_tile_position,
|
||||
region_size,
|
||||
material,
|
||||
grid_color
|
||||
)
|
||||
|
||||
draw_rect(Vector2.ZERO, region_size * Terrain3DData.REGION_MAP_SIZE, material, border_color)
|
||||
|
||||
|
||||
func draw_rect(p_pos: Vector2, p_size: float, p_material: StandardMaterial3D, p_modulate: Color) -> void:
|
||||
func draw_rect(
|
||||
p_pos: Vector2, p_size: float, p_material: StandardMaterial3D, p_modulate: Color
|
||||
) -> void:
|
||||
var lines: PackedVector3Array = [
|
||||
Vector3(-1, 0, -1),
|
||||
Vector3(-1, 0, 1),
|
||||
@@ -60,9 +75,8 @@ func draw_rect(p_pos: Vector2, p_size: float, p_material: StandardMaterial3D, p_
|
||||
Vector3(1, 0, -1),
|
||||
Vector3(-1, 0, -1),
|
||||
]
|
||||
|
||||
|
||||
for i in lines.size():
|
||||
lines[i] = ((lines[i] / 2.0) * p_size) + Vector3(p_pos.x, 0, p_pos.y)
|
||||
|
||||
|
||||
add_lines(lines, p_material, false, p_modulate)
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ const ES_TOOL_SETTINGS: String = "terrain3d/tool_settings/"
|
||||
const NONE: int = 0x0
|
||||
const ALLOW_LARGER: int = 0x1
|
||||
const ALLOW_SMALLER: int = 0x2
|
||||
const ALLOW_OUT_OF_BOUNDS: int = 0x3 # LARGER|SMALLER
|
||||
const ALLOW_OUT_OF_BOUNDS: int = 0x3 # LARGER|SMALLER
|
||||
const NO_LABEL: int = 0x4
|
||||
const ADD_SEPARATOR: int = 0x8 # Add a vertical line before this entry
|
||||
const ADD_SPACER: int = 0x10 # Add a space before this entry
|
||||
const NO_SAVE: int = 0x20 # Don't save this in EditorSettings
|
||||
const ADD_SEPARATOR: int = 0x8 # Add a vertical line before this entry
|
||||
const ADD_SPACER: int = 0x10 # Add a space before this entry
|
||||
const NO_SAVE: int = 0x20 # Don't save this in EditorSettings
|
||||
|
||||
var plugin: EditorPlugin # Actually Terrain3DEditorPlugin, but Godot still has CRC errors
|
||||
var plugin: EditorPlugin # Actually Terrain3DEditorPlugin, but Godot still has CRC errors
|
||||
var brush_preview_material: ShaderMaterial
|
||||
var select_brush_button: Button
|
||||
var selected_brush_imgs: Array
|
||||
@@ -56,109 +56,400 @@ func _ready() -> void:
|
||||
for setting in ["lift_floor", "flatten_peaks", "lift_flatten", "automatic_regions"]:
|
||||
plugin.erase_setting(ES_TOOL_SETTINGS + setting)
|
||||
|
||||
# Setup buttons
|
||||
# Setup buttons
|
||||
main_list = HFlowContainer.new()
|
||||
add_child(main_list, true)
|
||||
|
||||
|
||||
add_brushes(main_list)
|
||||
|
||||
add_setting({ "name":"instructions", "label":"Click the terrain to add a region. CTRL+Click to remove. Or select another tool on the left.",
|
||||
"type":SettingType.LABEL, "list":main_list, "flags":NO_LABEL|NO_SAVE })
|
||||
add_setting(
|
||||
{
|
||||
"name": "instructions",
|
||||
"label":
|
||||
"Click the terrain to add a region. CTRL+Click to remove. Or select another tool on the left.",
|
||||
"type": SettingType.LABEL,
|
||||
"list": main_list,
|
||||
"flags": NO_LABEL | NO_SAVE
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"size", "type":SettingType.SLIDER, "list":main_list, "default":20, "unit":"m",
|
||||
"range":Vector3(0.1, 200, 1), "flags":ALLOW_LARGER|ADD_SPACER })
|
||||
|
||||
add_setting({ "name":"strength", "type":SettingType.SLIDER, "list":main_list, "default":33,
|
||||
"unit":"%", "range":Vector3(1, 100, 1), "flags":ALLOW_LARGER })
|
||||
add_setting(
|
||||
{
|
||||
"name": "size",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 20,
|
||||
"unit": "m",
|
||||
"range": Vector3(0.1, 200, 1),
|
||||
"flags": ALLOW_LARGER | ADD_SPACER
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"height", "type":SettingType.SLIDER, "list":main_list, "default":20,
|
||||
"unit":"m", "range":Vector3(-500, 500, 0.1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"height_picker", "type":SettingType.PICKER, "list":main_list,
|
||||
"default":Terrain3DEditor.HEIGHT, "flags":NO_LABEL })
|
||||
|
||||
add_setting({ "name":"color", "type":SettingType.COLOR_SELECT, "list":main_list,
|
||||
"default":Color.WHITE, "flags":ADD_SEPARATOR })
|
||||
add_setting({ "name":"color_picker", "type":SettingType.PICKER, "list":main_list,
|
||||
"default":Terrain3DEditor.COLOR, "flags":NO_LABEL })
|
||||
add_setting(
|
||||
{
|
||||
"name": "strength",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 33,
|
||||
"unit": "%",
|
||||
"range": Vector3(1, 100, 1),
|
||||
"flags": ALLOW_LARGER
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"roughness", "type":SettingType.SLIDER, "list":main_list, "default":-65,
|
||||
"unit":"%", "range":Vector3(-100, 100, 1), "flags":ADD_SEPARATOR })
|
||||
add_setting({ "name":"roughness_picker", "type":SettingType.PICKER, "list":main_list,
|
||||
"default":Terrain3DEditor.ROUGHNESS, "flags":NO_LABEL })
|
||||
add_setting(
|
||||
{
|
||||
"name": "height",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 20,
|
||||
"unit": "m",
|
||||
"range": Vector3(-500, 500, 0.1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "height_picker",
|
||||
"type": SettingType.PICKER,
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.HEIGHT,
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"enable_texture", "label":"Texture", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":true, "flags":ADD_SEPARATOR })
|
||||
add_setting(
|
||||
{
|
||||
"name": "color",
|
||||
"type": SettingType.COLOR_SELECT,
|
||||
"list": main_list,
|
||||
"default": Color.WHITE,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "color_picker",
|
||||
"type": SettingType.PICKER,
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.COLOR,
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"texture_filter", "label":"Texture Filter", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":false, "flags":ADD_SEPARATOR })
|
||||
add_setting(
|
||||
{
|
||||
"name": "roughness",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": -65,
|
||||
"unit": "%",
|
||||
"range": Vector3(-100, 100, 1),
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "roughness_picker",
|
||||
"type": SettingType.PICKER,
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.ROUGHNESS,
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
add_setting({ "name":"margin", "type":SettingType.SLIDER, "list":main_list, "default":0,
|
||||
"unit":"", "range":Vector3(-50, 50, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting(
|
||||
{
|
||||
"name": "enable_texture",
|
||||
"label": "Texture",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": true,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
|
||||
add_setting(
|
||||
{
|
||||
"name": "texture_filter",
|
||||
"label": "Texture Filter",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": false,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
|
||||
add_setting(
|
||||
{
|
||||
"name": "margin",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 0,
|
||||
"unit": "",
|
||||
"range": Vector3(-50, 50, 1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
|
||||
# Slope painting filter
|
||||
add_setting({ "name":"slope", "type":SettingType.DOUBLE_SLIDER, "list":main_list, "default":Vector2(0, 90),
|
||||
"unit":"°", "range":Vector3(0, 90, 1), "flags":ADD_SEPARATOR })
|
||||
|
||||
add_setting({ "name":"enable_angle", "label":"Angle", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":true, "flags":ADD_SEPARATOR })
|
||||
add_setting({ "name":"angle", "type":SettingType.SLIDER, "list":main_list, "default":0,
|
||||
"unit":"%", "range":Vector3(0, 337.5, 22.5), "flags":NO_LABEL })
|
||||
add_setting({ "name":"angle_picker", "type":SettingType.PICKER, "list":main_list,
|
||||
"default":Terrain3DEditor.ANGLE, "flags":NO_LABEL })
|
||||
add_setting({ "name":"dynamic_angle", "label":"Dynamic", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":false, "flags":ADD_SPACER })
|
||||
|
||||
add_setting({ "name":"enable_scale", "label":"Scale", "type":SettingType.CHECKBOX,
|
||||
"list":main_list, "default":true, "flags":ADD_SEPARATOR })
|
||||
add_setting({ "name":"scale", "label":"±", "type":SettingType.SLIDER, "list":main_list, "default":0,
|
||||
"unit":"%", "range":Vector3(-60, 80, 20), "flags":NO_LABEL })
|
||||
add_setting({ "name":"scale_picker", "type":SettingType.PICKER, "list":main_list,
|
||||
"default":Terrain3DEditor.SCALE, "flags":NO_LABEL })
|
||||
add_setting(
|
||||
{
|
||||
"name": "slope",
|
||||
"type": SettingType.DOUBLE_SLIDER,
|
||||
"list": main_list,
|
||||
"default": Vector2(0, 90),
|
||||
"unit": "°",
|
||||
"range": Vector3(0, 90, 1),
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
|
||||
add_setting(
|
||||
{
|
||||
"name": "enable_angle",
|
||||
"label": "Angle",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": true,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "angle",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 0,
|
||||
"unit": "%",
|
||||
"range": Vector3(0, 337.5, 22.5),
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "angle_picker",
|
||||
"type": SettingType.PICKER,
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.ANGLE,
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "dynamic_angle",
|
||||
"label": "Dynamic",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": false,
|
||||
"flags": ADD_SPACER
|
||||
}
|
||||
)
|
||||
|
||||
add_setting(
|
||||
{
|
||||
"name": "enable_scale",
|
||||
"label": "Scale",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": true,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "scale",
|
||||
"label": "±",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": main_list,
|
||||
"default": 0,
|
||||
"unit": "%",
|
||||
"range": Vector3(-60, 80, 20),
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "scale_picker",
|
||||
"type": SettingType.PICKER,
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.SCALE,
|
||||
"flags": NO_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
## Slope sculpting brush
|
||||
add_setting({ "name":"gradient_points", "type":SettingType.MULTI_PICKER, "label":"Points",
|
||||
"list":main_list, "default":Terrain3DEditor.SCULPT, "flags":ADD_SEPARATOR })
|
||||
add_setting({ "name":"drawable", "type":SettingType.CHECKBOX, "list":main_list, "default":false,
|
||||
"flags":ADD_SEPARATOR })
|
||||
add_setting(
|
||||
{
|
||||
"name": "gradient_points",
|
||||
"type": SettingType.MULTI_PICKER,
|
||||
"label": "Points",
|
||||
"list": main_list,
|
||||
"default": Terrain3DEditor.SCULPT,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "drawable",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": false,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
settings["drawable"].toggled.connect(_on_drawable_toggled)
|
||||
|
||||
|
||||
## Instancer
|
||||
height_list = create_submenu(main_list, "Height", Layout.VERTICAL)
|
||||
add_setting({ "name":"height_offset", "type":SettingType.SLIDER, "list":height_list, "default":0,
|
||||
"unit":"m", "range":Vector3(-10, 10, 0.05), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"random_height", "label":"Random Height ±", "type":SettingType.SLIDER,
|
||||
"list":height_list, "default":0, "unit":"m", "range":Vector3(0, 10, 0.05),
|
||||
"flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting(
|
||||
{
|
||||
"name": "height_offset",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": height_list,
|
||||
"default": 0,
|
||||
"unit": "m",
|
||||
"range": Vector3(-10, 10, 0.05),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_height",
|
||||
"label": "Random Height ±",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": height_list,
|
||||
"default": 0,
|
||||
"unit": "m",
|
||||
"range": Vector3(0, 10, 0.05),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
|
||||
scale_list = create_submenu(main_list, "Scale", Layout.VERTICAL)
|
||||
add_setting({ "name":"fixed_scale", "type":SettingType.SLIDER, "list":scale_list, "default":100,
|
||||
"unit":"%", "range":Vector3(1, 1000, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"random_scale", "label":"Random Scale ±", "type":SettingType.SLIDER, "list":scale_list,
|
||||
"default":20, "unit":"%", "range":Vector3(0, 99, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting(
|
||||
{
|
||||
"name": "fixed_scale",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": scale_list,
|
||||
"default": 100,
|
||||
"unit": "%",
|
||||
"range": Vector3(1, 1000, 1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_scale",
|
||||
"label": "Random Scale ±",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": scale_list,
|
||||
"default": 20,
|
||||
"unit": "%",
|
||||
"range": Vector3(0, 99, 1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
|
||||
rotation_list = create_submenu(main_list, "Rotation", Layout.VERTICAL)
|
||||
add_setting({ "name":"fixed_spin", "label":"Fixed Spin (Around Y)", "type":SettingType.SLIDER, "list":rotation_list,
|
||||
"default":0, "unit":"°", "range":Vector3(0, 360, 1) })
|
||||
add_setting({ "name":"random_spin", "type":SettingType.SLIDER, "list":rotation_list, "default":360,
|
||||
"unit":"°", "range":Vector3(0, 360, 1) })
|
||||
add_setting({ "name":"fixed_tilt", "label":"Fixed Tilt", "type":SettingType.SLIDER, "list":rotation_list,
|
||||
"default":0, "unit":"°", "range":Vector3(-85, 85, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"random_tilt", "label":"Random Tilt ±", "type":SettingType.SLIDER, "list":rotation_list,
|
||||
"default":10, "unit":"°", "range":Vector3(0, 85, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"align_to_normal", "type":SettingType.CHECKBOX, "list":rotation_list, "default":false })
|
||||
|
||||
add_setting(
|
||||
{
|
||||
"name": "fixed_spin",
|
||||
"label": "Fixed Spin (Around Y)",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": rotation_list,
|
||||
"default": 0,
|
||||
"unit": "°",
|
||||
"range": Vector3(0, 360, 1)
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_spin",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": rotation_list,
|
||||
"default": 360,
|
||||
"unit": "°",
|
||||
"range": Vector3(0, 360, 1)
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "fixed_tilt",
|
||||
"label": "Fixed Tilt",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": rotation_list,
|
||||
"default": 0,
|
||||
"unit": "°",
|
||||
"range": Vector3(-85, 85, 1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_tilt",
|
||||
"label": "Random Tilt ±",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": rotation_list,
|
||||
"default": 10,
|
||||
"unit": "°",
|
||||
"range": Vector3(0, 85, 1),
|
||||
"flags": ALLOW_OUT_OF_BOUNDS
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "align_to_normal",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": rotation_list,
|
||||
"default": false
|
||||
}
|
||||
)
|
||||
|
||||
color_list = create_submenu(main_list, "Color", Layout.VERTICAL)
|
||||
add_setting({ "name":"vertex_color", "type":SettingType.COLOR_SELECT, "list":color_list,
|
||||
"default":Color.WHITE })
|
||||
add_setting({ "name":"random_hue", "label":"Random Hue Shift ±", "type":SettingType.SLIDER,
|
||||
"list":color_list, "default":0, "unit":"°", "range":Vector3(0, 360, 1) })
|
||||
add_setting({ "name":"random_darken", "type":SettingType.SLIDER, "list":color_list, "default":50,
|
||||
"unit":"%", "range":Vector3(0, 100, 1) })
|
||||
#add_setting({ "name":"blend_mode", "type":SettingType.OPTION, "list":color_list, "default":0,
|
||||
#"range":Vector3(0, 3, 1) })
|
||||
add_setting(
|
||||
{
|
||||
"name": "vertex_color",
|
||||
"type": SettingType.COLOR_SELECT,
|
||||
"list": color_list,
|
||||
"default": Color.WHITE
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_hue",
|
||||
"label": "Random Hue Shift ±",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": color_list,
|
||||
"default": 0,
|
||||
"unit": "°",
|
||||
"range": Vector3(0, 360, 1)
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "random_darken",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": color_list,
|
||||
"default": 50,
|
||||
"unit": "%",
|
||||
"range": Vector3(0, 100, 1)
|
||||
}
|
||||
)
|
||||
#add_setting({ "name":"blend_mode", "type":SettingType.OPTION, "list":color_list, "default":0,
|
||||
#"range":Vector3(0, 3, 1) })
|
||||
|
||||
if DisplayServer.is_touchscreen_available():
|
||||
add_setting({ "name":"invert", "label":"Invert", "type":SettingType.CHECKBOX, "list":main_list, "default":false, "flags":ADD_SEPARATOR })
|
||||
add_setting(
|
||||
{
|
||||
"name": "invert",
|
||||
"label": "Invert",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": main_list,
|
||||
"default": false,
|
||||
"flags": ADD_SEPARATOR
|
||||
}
|
||||
)
|
||||
|
||||
var spacer: Control = Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
@@ -166,22 +457,67 @@ func _ready() -> void:
|
||||
|
||||
## Advanced Settings Menu
|
||||
advanced_list = create_submenu(main_list, "", Layout.VERTICAL, false)
|
||||
add_setting({ "name":"auto_regions", "label":"Add regions while sculpting", "type":SettingType.CHECKBOX,
|
||||
"list":advanced_list, "default":true })
|
||||
add_setting({ "name":"align_to_view", "type":SettingType.CHECKBOX, "list":advanced_list,
|
||||
"default":true })
|
||||
add_setting({ "name":"show_cursor_while_painting", "type":SettingType.CHECKBOX, "list":advanced_list,
|
||||
"default":true })
|
||||
add_setting(
|
||||
{
|
||||
"name": "auto_regions",
|
||||
"label": "Add regions while sculpting",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": advanced_list,
|
||||
"default": true
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "align_to_view",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": advanced_list,
|
||||
"default": true
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "show_cursor_while_painting",
|
||||
"type": SettingType.CHECKBOX,
|
||||
"list": advanced_list,
|
||||
"default": true
|
||||
}
|
||||
)
|
||||
advanced_list.add_child(HSeparator.new(), true)
|
||||
add_setting({ "name":"gamma", "type":SettingType.SLIDER, "list":advanced_list, "default":1.0,
|
||||
"unit":"γ", "range":Vector3(0.1, 2.0, 0.01) })
|
||||
add_setting({ "name":"jitter", "type":SettingType.SLIDER, "list":advanced_list, "default":50,
|
||||
"unit":"%", "range":Vector3(0, 100, 1) })
|
||||
add_setting({ "name":"crosshair_threshold", "type":SettingType.SLIDER, "list":advanced_list, "default":16.,
|
||||
"unit":"m", "range":Vector3(0, 200, 1) })
|
||||
add_setting(
|
||||
{
|
||||
"name": "gamma",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": advanced_list,
|
||||
"default": 1.0,
|
||||
"unit": "γ",
|
||||
"range": Vector3(0.1, 2.0, 0.01)
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "jitter",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": advanced_list,
|
||||
"default": 50,
|
||||
"unit": "%",
|
||||
"range": Vector3(0, 100, 1)
|
||||
}
|
||||
)
|
||||
add_setting(
|
||||
{
|
||||
"name": "crosshair_threshold",
|
||||
"type": SettingType.SLIDER,
|
||||
"list": advanced_list,
|
||||
"default": 16.,
|
||||
"unit": "m",
|
||||
"range": Vector3(0, 200, 1)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func create_submenu(p_parent: Control, p_button_name: String, p_layout: Layout, p_hover_pop: bool = true) -> Container:
|
||||
func create_submenu(
|
||||
p_parent: Control, p_button_name: String, p_layout: Layout, p_hover_pop: bool = true
|
||||
) -> Container:
|
||||
var menu_button: Button = Button.new()
|
||||
if p_button_name.is_empty():
|
||||
menu_button.icon = get_theme_icon("GuiTabMenuHl", "EditorIcons")
|
||||
@@ -190,7 +526,7 @@ func create_submenu(p_parent: Control, p_button_name: String, p_layout: Layout,
|
||||
menu_button.set_toggle_mode(true)
|
||||
menu_button.set_v_size_flags(SIZE_SHRINK_CENTER)
|
||||
menu_button.toggled.connect(_on_show_submenu.bind(menu_button))
|
||||
|
||||
|
||||
var submenu: PopupPanel = PopupPanel.new()
|
||||
submenu.popup_hide.connect(menu_button.set_pressed.bind(false))
|
||||
var panel_style: StyleBox = get_theme_stylebox("panel", "PopupMenu").duplicate()
|
||||
@@ -201,38 +537,40 @@ func create_submenu(p_parent: Control, p_button_name: String, p_layout: Layout,
|
||||
# Pop up menu on hover, hide on exit
|
||||
if p_hover_pop:
|
||||
menu_button.mouse_entered.connect(_on_show_submenu.bind(true, menu_button))
|
||||
|
||||
|
||||
submenu.mouse_entered.connect(func(): submenu.set_meta("mouse_entered", true))
|
||||
|
||||
submenu.mouse_exited.connect(func():
|
||||
# On mouse_exit, hide popup unless LineEdit focused
|
||||
var focused_element: Control = submenu.gui_get_focus_owner()
|
||||
if not focused_element is LineEdit:
|
||||
_on_show_submenu(false, menu_button)
|
||||
submenu.set_meta("mouse_entered", false)
|
||||
return
|
||||
|
||||
focused_element.focus_exited.connect(func():
|
||||
# Close submenu once lineedit loses focus
|
||||
if not submenu.get_meta("mouse_entered"):
|
||||
|
||||
submenu.mouse_exited.connect(
|
||||
func():
|
||||
# On mouse_exit, hide popup unless LineEdit focused
|
||||
var focused_element: Control = submenu.gui_get_focus_owner()
|
||||
if not focused_element is LineEdit:
|
||||
_on_show_submenu(false, menu_button)
|
||||
submenu.set_meta("mouse_entered", false)
|
||||
)
|
||||
return
|
||||
|
||||
focused_element.focus_exited.connect(
|
||||
func():
|
||||
# Close submenu once lineedit loses focus
|
||||
if not submenu.get_meta("mouse_entered"):
|
||||
_on_show_submenu(false, menu_button)
|
||||
submenu.set_meta("mouse_entered", false)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
var sublist: Container
|
||||
match(p_layout):
|
||||
match p_layout:
|
||||
Layout.GRID:
|
||||
sublist = GridContainer.new()
|
||||
Layout.VERTICAL:
|
||||
sublist = VBoxContainer.new()
|
||||
Layout.HORIZONTAL, _:
|
||||
sublist = HBoxContainer.new()
|
||||
|
||||
|
||||
p_parent.add_child(menu_button, true)
|
||||
menu_button.add_child(submenu, true)
|
||||
submenu.add_child(sublist, true)
|
||||
|
||||
|
||||
return sublist
|
||||
|
||||
|
||||
@@ -240,25 +578,27 @@ func _on_show_submenu(p_toggled: bool, p_button: Button) -> void:
|
||||
# Don't show if mouse already down (from painting)
|
||||
if p_toggled and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
|
||||
return
|
||||
|
||||
# Hide menu if mouse is not in button or panel
|
||||
var button_rect: Rect2 = Rect2(p_button.get_screen_transform().origin, p_button.get_global_rect().size)
|
||||
|
||||
# Hide menu if mouse is not in button or panel
|
||||
var button_rect: Rect2 = Rect2(
|
||||
p_button.get_screen_transform().origin, p_button.get_global_rect().size
|
||||
)
|
||||
var in_button: bool = button_rect.has_point(DisplayServer.mouse_get_position())
|
||||
var popup: PopupPanel = p_button.get_child(0)
|
||||
var popup_rect: Rect2 = Rect2(popup.position, popup.size)
|
||||
var in_popup: bool = popup_rect.has_point(DisplayServer.mouse_get_position())
|
||||
if not p_toggled and ( in_button or in_popup ):
|
||||
if not p_toggled and (in_button or in_popup):
|
||||
return
|
||||
|
||||
|
||||
# Hide all submenus before possibly enabling the current one
|
||||
get_tree().call_group("terrain3d_submenus", "set_visible", false)
|
||||
popup.set_visible(p_toggled)
|
||||
var popup_pos: Vector2 = p_button.get_screen_transform().origin
|
||||
popup_pos.y -= popup.size.y
|
||||
if popup.get_child_count()>0 and popup.get_child(0) == advanced_list:
|
||||
if popup.get_child_count() > 0 and popup.get_child(0) == advanced_list:
|
||||
popup_pos.x -= popup.size.x - p_button.size.x
|
||||
popup.set_position(popup_pos)
|
||||
|
||||
|
||||
|
||||
func add_brushes(p_parent: Control) -> void:
|
||||
var brush_list: GridContainer = create_submenu(p_parent, "Brush", Layout.GRID)
|
||||
@@ -267,7 +607,7 @@ func add_brushes(p_parent: Control) -> void:
|
||||
var brush_button_group: ButtonGroup = ButtonGroup.new()
|
||||
brush_button_group.pressed.connect(_on_setting_changed)
|
||||
var default_brush_btn: Button
|
||||
|
||||
|
||||
var dir: DirAccess = DirAccess.open(BRUSH_PATH)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
@@ -283,7 +623,7 @@ func add_brushes(p_parent: Control) -> void:
|
||||
thumbimg = Terrain3DUtil.black_to_alpha(thumbimg)
|
||||
thumbimg.convert(Image.FORMAT_LA8)
|
||||
var thumbtex: ImageTexture = ImageTexture.create_from_image(thumbimg)
|
||||
|
||||
|
||||
var brush_btn: Button = Button.new()
|
||||
brush_btn.set_custom_minimum_size(Vector2.ONE * 100)
|
||||
brush_btn.set_button_icon(thumbtex)
|
||||
@@ -296,8 +636,8 @@ func add_brushes(p_parent: Control) -> void:
|
||||
brush_btn.mouse_exited.connect(_on_brush_hover.bind(false, brush_btn))
|
||||
brush_list.add_child(brush_btn, true)
|
||||
if file_name == DEFAULT_BRUSH:
|
||||
default_brush_btn = brush_btn
|
||||
|
||||
default_brush_btn = brush_btn
|
||||
|
||||
var lbl: Label = Label.new()
|
||||
brush_btn.name = file_name.get_basename().to_pascal_case()
|
||||
brush_btn.add_child(lbl, true)
|
||||
@@ -308,16 +648,16 @@ func add_brushes(p_parent: Control) -> void:
|
||||
lbl.add_theme_constant_override("shadow_offset_x", 1)
|
||||
lbl.add_theme_constant_override("shadow_offset_y", 1)
|
||||
lbl.add_theme_font_size_override("font_size", 16)
|
||||
|
||||
|
||||
file_name = dir.get_next()
|
||||
|
||||
|
||||
brush_list.columns = sqrt(brush_list.get_child_count()) + 2
|
||||
|
||||
|
||||
if not default_brush_btn:
|
||||
default_brush_btn = brush_button_group.get_buttons()[0]
|
||||
default_brush_btn.set_pressed(true)
|
||||
_generate_brush_texture(default_brush_btn)
|
||||
|
||||
|
||||
settings["brush"] = brush_button_group
|
||||
|
||||
select_brush_button = brush_list.get_parent().get_parent()
|
||||
@@ -352,7 +692,11 @@ func _on_picked(p_type: Terrain3DEditor.Tool, p_color: Color, p_global_position:
|
||||
Terrain3DEditor.ROUGHNESS:
|
||||
# This converts 0,1 to -100,100
|
||||
# It also quantizes explicitly so picked values matches painted values
|
||||
settings["roughness"].value = round(200. * float(int(p_color.a * 255.) / 255. - .5)) if not is_nan(p_color.r) else 0.
|
||||
settings["roughness"].value = (
|
||||
round(200. * float(int(p_color.a * 255.) / 255. - .5))
|
||||
if not is_nan(p_color.r)
|
||||
else 0.
|
||||
)
|
||||
Terrain3DEditor.ANGLE:
|
||||
settings["angle"].value = p_color.r
|
||||
Terrain3DEditor.SCALE:
|
||||
@@ -365,7 +709,9 @@ func _on_point_pick(p_type: Terrain3DEditor.Tool, p_name: String) -> void:
|
||||
emit_signal("picking", p_type, _on_point_picked.bind(p_name))
|
||||
|
||||
|
||||
func _on_point_picked(p_type: Terrain3DEditor.Tool, p_color: Color, p_global_position: Vector3, p_name: String) -> void:
|
||||
func _on_point_picked(
|
||||
p_type: Terrain3DEditor.Tool, p_color: Color, p_global_position: Vector3, p_name: String
|
||||
) -> void:
|
||||
assert(p_type == Terrain3DEditor.SCULPT)
|
||||
var point: Vector3 = p_global_position
|
||||
point.y = p_color.r
|
||||
@@ -375,7 +721,7 @@ func _on_point_picked(p_type: Terrain3DEditor.Tool, p_color: Color, p_global_pos
|
||||
|
||||
func add_setting(p_args: Dictionary) -> void:
|
||||
var p_name: StringName = p_args.get("name", "")
|
||||
var p_label: String = p_args.get("label", "") # Optional replacement for name
|
||||
var p_label: String = p_args.get("label", "") # Optional replacement for name
|
||||
var p_type: SettingType = p_args.get("type", SettingType.TYPE_MAX)
|
||||
var p_list: Control = p_args.get("list")
|
||||
var p_default: Variant = p_args.get("default")
|
||||
@@ -385,13 +731,13 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
var p_maximum: float = p_range.y
|
||||
var p_step: float = p_range.z
|
||||
var p_flags: int = p_args.get("flags", NONE)
|
||||
|
||||
|
||||
if p_name.is_empty() or p_type == SettingType.TYPE_MAX:
|
||||
return
|
||||
|
||||
var container: HBoxContainer = HBoxContainer.new()
|
||||
container.set_v_size_flags(SIZE_EXPAND_FILL)
|
||||
var control: Control # Houses the setting to be saved
|
||||
var control: Control # Houses the setting to be saved
|
||||
var pending_children: Array[Control]
|
||||
|
||||
match p_type:
|
||||
@@ -404,17 +750,21 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
SettingType.CHECKBOX:
|
||||
var checkbox := CheckBox.new()
|
||||
if !(p_flags & NO_SAVE):
|
||||
checkbox.set_pressed_no_signal(plugin.get_setting(ES_TOOL_SETTINGS + p_name, p_default))
|
||||
checkbox.toggled.connect( (
|
||||
func(value, path):
|
||||
plugin.set_setting(path, value)
|
||||
).bind(ES_TOOL_SETTINGS + p_name) )
|
||||
checkbox.set_pressed_no_signal(
|
||||
plugin.get_setting(ES_TOOL_SETTINGS + p_name, p_default)
|
||||
)
|
||||
checkbox.toggled.connect(
|
||||
(
|
||||
(func(value, path): plugin.set_setting(path, value))
|
||||
. bind(ES_TOOL_SETTINGS + p_name)
|
||||
)
|
||||
)
|
||||
else:
|
||||
checkbox.set_pressed_no_signal(p_default)
|
||||
checkbox.set_pressed_no_signal(p_default)
|
||||
checkbox.pressed.connect(_on_setting_changed)
|
||||
pending_children.push_back(checkbox)
|
||||
control = checkbox
|
||||
|
||||
|
||||
SettingType.COLOR_SELECT:
|
||||
var picker := ColorPickerButton.new()
|
||||
picker.set_custom_minimum_size(Vector2(100, 25))
|
||||
@@ -422,10 +772,12 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
picker.get_picker().set_color_mode(ColorPicker.MODE_HSV)
|
||||
if !(p_flags & NO_SAVE):
|
||||
picker.set_pick_color(plugin.get_setting(ES_TOOL_SETTINGS + p_name, p_default))
|
||||
picker.color_changed.connect( (
|
||||
func(value, path):
|
||||
plugin.set_setting(path, value)
|
||||
).bind(ES_TOOL_SETTINGS + p_name) )
|
||||
picker.color_changed.connect(
|
||||
(
|
||||
(func(value, path): plugin.set_setting(path, value))
|
||||
. bind(ES_TOOL_SETTINGS + p_name)
|
||||
)
|
||||
)
|
||||
else:
|
||||
picker.set_pick_color(p_default)
|
||||
picker.color_changed.connect(_on_setting_changed)
|
||||
@@ -479,12 +831,12 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
slider.set_allow_greater(true)
|
||||
if p_flags & ALLOW_SMALLER:
|
||||
slider.set_allow_lesser(true)
|
||||
|
||||
|
||||
pending_children.push_back(slider)
|
||||
pending_children.push_back(spin_slider)
|
||||
control = spin_slider
|
||||
|
||||
else: # DOUBLE_SLIDER
|
||||
|
||||
else: # DOUBLE_SLIDER
|
||||
var label := Label.new()
|
||||
label.set_custom_minimum_size(Vector2(60, 0))
|
||||
label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER)
|
||||
@@ -495,7 +847,7 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
pending_children.push_back(slider)
|
||||
pending_children.push_back(label)
|
||||
control = slider
|
||||
|
||||
|
||||
slider.set_min(p_minimum)
|
||||
slider.set_max(p_maximum)
|
||||
slider.set_step(p_step)
|
||||
@@ -505,10 +857,12 @@ func add_setting(p_args: Dictionary) -> void:
|
||||
|
||||
if !(p_flags & NO_SAVE):
|
||||
slider.set_value(plugin.get_setting(ES_TOOL_SETTINGS + p_name, p_default))
|
||||
slider.value_changed.connect( (
|
||||
func(value, path):
|
||||
plugin.set_setting(path, value)
|
||||
).bind(ES_TOOL_SETTINGS + p_name) )
|
||||
slider.value_changed.connect(
|
||||
(
|
||||
(func(value, path): plugin.set_setting(path, value))
|
||||
. bind(ES_TOOL_SETTINGS + p_name)
|
||||
)
|
||||
)
|
||||
else:
|
||||
slider.set_value(p_default)
|
||||
|
||||
@@ -569,11 +923,14 @@ func get_setting(p_setting: String) -> Variant:
|
||||
value = object.get_value()
|
||||
# Adjust widths of all sliders on update of values
|
||||
var digits: float = count_digits(value)
|
||||
var width: float = clamp( (1 + count_digits(value)) * 19., 50, 80) * clamp(EditorInterface.get_editor_scale(), .9, 2)
|
||||
var width: float = (
|
||||
clamp((1 + count_digits(value)) * 19., 50, 80)
|
||||
* clamp(EditorInterface.get_editor_scale(), .9, 2)
|
||||
)
|
||||
object.set_custom_minimum_size(Vector2(width, 0))
|
||||
elif object is DoubleSlider:
|
||||
value = object.get_value()
|
||||
elif object is ButtonGroup: # "brush"
|
||||
elif object is ButtonGroup: # "brush"
|
||||
value = selected_brush_imgs
|
||||
elif object is CheckBox:
|
||||
value = object.is_pressed()
|
||||
@@ -588,11 +945,11 @@ func get_setting(p_setting: String) -> Variant:
|
||||
|
||||
func set_setting(p_setting: String, p_value: Variant) -> void:
|
||||
var object: Object = settings.get(p_setting)
|
||||
if object is DoubleSlider: # Expects p_value is Vector2
|
||||
if object is DoubleSlider: # Expects p_value is Vector2
|
||||
object.set_value(p_value)
|
||||
elif object is Range:
|
||||
object.set_value(p_value)
|
||||
elif object is ButtonGroup: # Expects p_value is Array [ "button name", boolean ]
|
||||
elif object is ButtonGroup: # Expects p_value is Array [ "button name", boolean ]
|
||||
if p_value is Array and p_value.size() == 2:
|
||||
for button in object.get_buttons():
|
||||
if button.name == p_value[0]:
|
||||
@@ -601,8 +958,8 @@ func set_setting(p_setting: String, p_value: Variant) -> void:
|
||||
object.button_pressed = p_value
|
||||
elif object is ColorPickerButton:
|
||||
object.color = p_value
|
||||
plugin.set_setting(ES_TOOL_SETTINGS + p_setting, p_value) # Signal doesn't fire on CPB
|
||||
elif object is MultiPicker: # Expects p_value is PackedVector3Array
|
||||
plugin.set_setting(ES_TOOL_SETTINGS + p_setting, p_value) # Signal doesn't fire on CPB
|
||||
elif object is MultiPicker: # Expects p_value is PackedVector3Array
|
||||
object.points = p_value
|
||||
_on_setting_changed(object)
|
||||
|
||||
@@ -644,7 +1001,7 @@ func _generate_brush_texture(p_btn: Button) -> void:
|
||||
img = img.duplicate()
|
||||
img.resize(1024, 1024, Image.INTERPOLATE_CUBIC)
|
||||
var tex: ImageTexture = ImageTexture.create_from_image(img)
|
||||
selected_brush_imgs = [ img, tex ]
|
||||
selected_brush_imgs = [img, tex]
|
||||
|
||||
|
||||
func _on_drawable_toggled(p_button_pressed: bool) -> void:
|
||||
@@ -671,23 +1028,22 @@ func _get_brush_preview_material() -> ShaderMaterial:
|
||||
return brush_preview_material
|
||||
|
||||
|
||||
# Counts digits of a number including negative sign, decimal points, and up to 3 decimals
|
||||
# Counts digits of a number including negative sign, decimal points, and up to 3 decimals
|
||||
func count_digits(p_value: float) -> int:
|
||||
var count: int = 1
|
||||
for i in range(5, 0, -1):
|
||||
if abs(p_value) >= pow(10, i):
|
||||
count = i+1
|
||||
count = i + 1
|
||||
break
|
||||
if p_value - floor(p_value) >= .1:
|
||||
count += 1 # For the decimal
|
||||
if p_value*10 - floor(p_value*10.) >= .1:
|
||||
count += 1 # For the decimal
|
||||
if p_value * 10 - floor(p_value * 10.) >= .1:
|
||||
count += 1
|
||||
if p_value*100 - floor(p_value*100.) >= .1:
|
||||
if p_value * 100 - floor(p_value * 100.) >= .1:
|
||||
count += 1
|
||||
if p_value*1000 - floor(p_value*1000.) >= .1:
|
||||
if p_value * 1000 - floor(p_value * 1000.) >= .1:
|
||||
count += 1
|
||||
# Negative sign
|
||||
if p_value < 0:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
@@ -33,61 +33,151 @@ func _ready() -> void:
|
||||
add_tool_group.pressed.connect(_on_tool_selected)
|
||||
sub_tool_group.pressed.connect(_on_tool_selected)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.REGION,
|
||||
"add_text":"Add Region (E)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_REGION_ADD,
|
||||
"sub_text":"Remove Region", "sub_op":Terrain3DEditor.SUBTRACT, "sub_icon":ICON_REGION_REMOVE })
|
||||
|
||||
add_child(HSeparator.new())
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.SCULPT,
|
||||
"add_text":"Raise (R)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_HEIGHT_ADD,
|
||||
"sub_text":"Lower (R)", "sub_op":Terrain3DEditor.SUBTRACT, "sub_icon":ICON_HEIGHT_SUB })
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.SCULPT,
|
||||
"add_text":"Smooth (Shift)", "add_op":Terrain3DEditor.AVERAGE, "add_icon":ICON_HEIGHT_SMOOTH })
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.HEIGHT,
|
||||
"add_text":"Height (H)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_HEIGHT_FLAT,
|
||||
"sub_text":"Height (H)", "sub_op":Terrain3DEditor.SUBTRACT, "sub_icon":ICON_HEIGHT_FLAT })
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.SCULPT,
|
||||
"add_text":"Slope (S)", "add_op":Terrain3DEditor.GRADIENT, "add_icon":ICON_HEIGHT_SLOPE })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.REGION,
|
||||
"add_text": "Add Region (E)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_REGION_ADD,
|
||||
"sub_text": "Remove Region",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT,
|
||||
"sub_icon": ICON_REGION_REMOVE
|
||||
}
|
||||
)
|
||||
|
||||
add_child(HSeparator.new())
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.TEXTURE,
|
||||
"add_text":"Paint Texture (B)", "add_op":Terrain3DEditor.REPLACE, "add_icon":ICON_PAINT_TEXTURE })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.SCULPT,
|
||||
"add_text": "Raise (R)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_HEIGHT_ADD,
|
||||
"sub_text": "Lower (R)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT,
|
||||
"sub_icon": ICON_HEIGHT_SUB
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.TEXTURE,
|
||||
"add_text":"Spray Texture (V)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_SPRAY_TEXTURE })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.SCULPT,
|
||||
"add_text": "Smooth (Shift)",
|
||||
"add_op": Terrain3DEditor.AVERAGE,
|
||||
"add_icon": ICON_HEIGHT_SMOOTH
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.AUTOSHADER,
|
||||
"add_text":"Paint Autoshader (A)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_AUTOSHADER,
|
||||
"sub_text":"Disable Autoshader (A)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.HEIGHT,
|
||||
"add_text": "Height (H)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_HEIGHT_FLAT,
|
||||
"sub_text": "Height (H)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT,
|
||||
"sub_icon": ICON_HEIGHT_FLAT
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.SCULPT,
|
||||
"add_text": "Slope (S)",
|
||||
"add_op": Terrain3DEditor.GRADIENT,
|
||||
"add_icon": ICON_HEIGHT_SLOPE
|
||||
}
|
||||
)
|
||||
|
||||
add_child(HSeparator.new())
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.COLOR,
|
||||
"add_text":"Paint Color (C)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_COLOR,
|
||||
"sub_text":"Remove Color (C)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.ROUGHNESS,
|
||||
"add_text":"Paint Wetness (W)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_WETNESS,
|
||||
"sub_text":"Remove Wetness (W)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.TEXTURE,
|
||||
"add_text": "Paint Texture (B)",
|
||||
"add_op": Terrain3DEditor.REPLACE,
|
||||
"add_icon": ICON_PAINT_TEXTURE
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.TEXTURE,
|
||||
"add_text": "Spray Texture (V)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_SPRAY_TEXTURE
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.AUTOSHADER,
|
||||
"add_text": "Paint Autoshader (A)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_AUTOSHADER,
|
||||
"sub_text": "Disable Autoshader (A)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
add_child(HSeparator.new())
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.HOLES,
|
||||
"add_text":"Add Holes (X)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_HOLES,
|
||||
"sub_text":"Remove Holes (X)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.COLOR,
|
||||
"add_text": "Paint Color (C)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_COLOR,
|
||||
"sub_text": "Remove Color (C)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.NAVIGATION,
|
||||
"add_text":"Paint Navigable Area (N)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_NAVIGATION,
|
||||
"sub_text":"Remove Navigable Area (N)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.ROUGHNESS,
|
||||
"add_text": "Paint Wetness (W)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_WETNESS,
|
||||
"sub_text": "Remove Wetness (W)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button({ "tool":Terrain3DEditor.INSTANCER,
|
||||
"add_text":"Instance Meshes (I)", "add_op":Terrain3DEditor.ADD, "add_icon":ICON_INSTANCER,
|
||||
"sub_text":"Remove Meshes (I)", "sub_op":Terrain3DEditor.SUBTRACT })
|
||||
add_child(HSeparator.new())
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.HOLES,
|
||||
"add_text": "Add Holes (X)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_HOLES,
|
||||
"sub_text": "Remove Holes (X)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.NAVIGATION,
|
||||
"add_text": "Paint Navigable Area (N)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_NAVIGATION,
|
||||
"sub_text": "Remove Navigable Area (N)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
add_tool_button(
|
||||
{
|
||||
"tool": Terrain3DEditor.INSTANCER,
|
||||
"add_text": "Instance Meshes (I)",
|
||||
"add_op": Terrain3DEditor.ADD,
|
||||
"add_icon": ICON_INSTANCER,
|
||||
"sub_text": "Remove Meshes (I)",
|
||||
"sub_op": Terrain3DEditor.SUBTRACT
|
||||
}
|
||||
)
|
||||
|
||||
# Select first button
|
||||
var buttons: Array[BaseButton] = add_tool_group.get_buttons()
|
||||
@@ -98,7 +188,7 @@ func _ready() -> void:
|
||||
func add_tool_button(p_params: Dictionary) -> void:
|
||||
# Additive button
|
||||
var button := Button.new()
|
||||
var name_str: String = p_params.get("add_text", "blank").get_slice('(', 0).to_pascal_case()
|
||||
var name_str: String = p_params.get("add_text", "blank").get_slice("(", 0).to_pascal_case()
|
||||
button.set_name(name_str)
|
||||
button.set_meta("Tool", p_params.get("tool", 0))
|
||||
button.set_meta("Operation", p_params.get("add_op", 0))
|
||||
@@ -116,7 +206,7 @@ func add_tool_button(p_params: Dictionary) -> void:
|
||||
var button2: Button
|
||||
if p_params.has("sub_text"):
|
||||
button2 = Button.new()
|
||||
name_str = p_params.get("sub_text", "blank").get_slice('(', 0).to_pascal_case()
|
||||
name_str = p_params.get("sub_text", "blank").get_slice("(", 0).to_pascal_case()
|
||||
button2.set_name(name_str)
|
||||
button2.set_meta("Tool", p_params.get("tool", 0))
|
||||
button2.set_meta("Operation", p_params.get("sub_op", 0))
|
||||
@@ -151,4 +241,8 @@ func _on_tool_selected(p_button: BaseButton) -> void:
|
||||
var id: int = p_button.get_meta("ID", -2)
|
||||
for button in change_group.get_buttons():
|
||||
button.set_pressed_no_signal(button.get_meta("ID", -1) == id)
|
||||
emit_signal("tool_changed", p_button.get_meta("Tool", Terrain3DEditor.TOOL_MAX), p_button.get_meta("Operation", Terrain3DEditor.OP_MAX))
|
||||
emit_signal(
|
||||
"tool_changed",
|
||||
p_button.get_meta("Tool", Terrain3DEditor.TOOL_MAX),
|
||||
p_button.get_meta("Operation", Terrain3DEditor.OP_MAX)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user