mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-16 00:44:50 +00:00
✨ upgrade addons
This commit is contained in:
parent
8c2ba0ef2b
commit
e268697974
125 changed files with 1706 additions and 1027 deletions
|
|
@ -1,119 +1,426 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
#class_name Terrain3DAssetDock
|
||||
|
||||
signal placement_changed(index: int)
|
||||
signal resource_changed(resource: Resource, index: int)
|
||||
signal resource_inspected(resource: Resource)
|
||||
signal resource_selected
|
||||
signal confirmation_closed
|
||||
signal confirmation_confirmed
|
||||
signal confirmation_canceled
|
||||
|
||||
var list: ListContainer
|
||||
var entries: Array[ListEntry]
|
||||
var selected_index: int = 0
|
||||
var focus_style: StyleBox
|
||||
const PS_DOCK_SLOT: String = "terrain3d/config/dock_slot"
|
||||
const PS_DOCK_TILE_SIZE: String = "terrain3d/config/dock_tile_size"
|
||||
const PS_DOCK_FLOATING: String = "terrain3d/config/dock_floating"
|
||||
const PS_DOCK_PINNED: String = "terrain3d/config/dock_always_on_top"
|
||||
const PS_DOCK_WINDOW_POSITION: String = "terrain3d/config/dock_window_position"
|
||||
const PS_DOCK_WINDOW_SIZE: String = "terrain3d/config/dock_window_size"
|
||||
|
||||
@onready var placement_option: OptionButton = $VBox/PlacementHBox/Options
|
||||
@onready var placement_pin: Button = $VBox/PlacementHBox/Pinned
|
||||
@onready var size_slider: HSlider = $VBox/SizeSlider
|
||||
var texture_list: ListContainer
|
||||
var mesh_list: ListContainer
|
||||
var _current_list: ListContainer
|
||||
var _last_thumb_update_time: int = 0
|
||||
const MAX_UPDATE_TIME: int = 1000
|
||||
|
||||
var placement_opt: OptionButton
|
||||
var floating_btn: Button
|
||||
var pinned_btn: Button
|
||||
var size_slider: HSlider
|
||||
var box: BoxContainer
|
||||
var buttons: BoxContainer
|
||||
var textures_btn: Button
|
||||
var meshes_btn: Button
|
||||
var asset_container: ScrollContainer
|
||||
var confirm_dialog: ConfirmationDialog
|
||||
var _confirmed: bool = false
|
||||
|
||||
# Used only for editor, so change to single visible/hiddden
|
||||
enum {
|
||||
HIDDEN = -1,
|
||||
SIDEBAR = 0,
|
||||
BOTTOM = 1,
|
||||
WINDOWED = 2,
|
||||
}
|
||||
var state: int = HIDDEN
|
||||
|
||||
var window: Window
|
||||
var _godot_editor_window: Window # The main Godot Editor window
|
||||
var _godot_last_state: Window.Mode = Window.MODE_FULLSCREEN
|
||||
|
||||
enum {
|
||||
POS_LEFT_UL = 0,
|
||||
POS_LEFT_BL = 1,
|
||||
POS_LEFT_UR = 2,
|
||||
POS_LEFT_BR = 3,
|
||||
POS_RIGHT_UL = 4,
|
||||
POS_RIGHT_BL = 5,
|
||||
POS_RIGHT_UR = 6,
|
||||
POS_RIGHT_BR = 7,
|
||||
POS_BOTTOM = 8,
|
||||
POS_MAX = 9,
|
||||
}
|
||||
var slot: int = POS_RIGHT_BR
|
||||
var _initialized: bool = false
|
||||
var plugin: EditorPlugin
|
||||
var editor_settings: EditorSettings
|
||||
|
||||
|
||||
func initialize(p_plugin: EditorPlugin) -> void:
|
||||
if p_plugin:
|
||||
plugin = p_plugin
|
||||
|
||||
# Get editor window. Structure is root:Window/EditorNode/Base Control
|
||||
_godot_editor_window = plugin.get_editor_interface().get_base_control().get_parent().get_parent()
|
||||
_godot_last_state = _godot_editor_window.mode
|
||||
|
||||
placement_opt = $Box/Buttons/PlacementOpt
|
||||
pinned_btn = $Box/Buttons/Pinned
|
||||
floating_btn = $Box/Buttons/Floating
|
||||
floating_btn.owner = null
|
||||
size_slider = $Box/Buttons/SizeSlider
|
||||
size_slider.owner = null
|
||||
box = $Box
|
||||
buttons = $Box/Buttons
|
||||
textures_btn = $Box/Buttons/TexturesBtn
|
||||
meshes_btn = $Box/Buttons/MeshesBtn
|
||||
asset_container = $Box/ScrollContainer
|
||||
|
||||
texture_list = ListContainer.new()
|
||||
texture_list.plugin = plugin
|
||||
texture_list.type = Terrain3DAssets.TYPE_TEXTURE
|
||||
asset_container.add_child(texture_list)
|
||||
mesh_list = ListContainer.new()
|
||||
mesh_list.plugin = plugin
|
||||
mesh_list.type = Terrain3DAssets.TYPE_MESH
|
||||
mesh_list.visible = false
|
||||
asset_container.add_child(mesh_list)
|
||||
_current_list = texture_list
|
||||
|
||||
editor_settings = EditorInterface.get_editor_settings()
|
||||
load_editor_settings()
|
||||
|
||||
# Connect signals
|
||||
resized.connect(update_layout)
|
||||
textures_btn.pressed.connect(_on_textures_pressed)
|
||||
meshes_btn.pressed.connect(_on_meshes_pressed)
|
||||
placement_opt.item_selected.connect(set_slot)
|
||||
floating_btn.pressed.connect(make_dock_float)
|
||||
pinned_btn.toggled.connect(_on_pin_changed)
|
||||
pinned_btn.visible = false
|
||||
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", 16 * EditorInterface.get_editor_scale())
|
||||
textures_btn.add_theme_font_size_override("font_size", 16 * EditorInterface.get_editor_scale())
|
||||
|
||||
_initialized = true
|
||||
update_dock(plugin.visible)
|
||||
update_layout()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
placement_option.item_selected.connect(_on_placement_selected)
|
||||
size_slider.value_changed.connect(_on_slider_changed)
|
||||
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
|
||||
if plugin.get_editor_interface().get_edited_scene_root() != self:
|
||||
pinned_btn.icon = get_theme_icon("Pin", "EditorIcons")
|
||||
pinned_btn.text = ""
|
||||
floating_btn.icon = get_theme_icon("MakeFloating", "EditorIcons")
|
||||
floating_btn.text = ""
|
||||
|
||||
update_thumbnails()
|
||||
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") )
|
||||
|
||||
|
||||
func get_current_list() -> ListContainer:
|
||||
return _current_list
|
||||
|
||||
|
||||
## Dock placement
|
||||
|
||||
func set_slot(p_slot: int) -> void:
|
||||
p_slot = clamp(p_slot, 0, POS_MAX-1)
|
||||
|
||||
list = ListContainer.new()
|
||||
list.set_v_size_flags(SIZE_EXPAND_FILL)
|
||||
list.set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
$VBox/ScrollContainer.add_child(list)
|
||||
|
||||
# Copy theme from the editor, but since its a tool script, avoid saving icon resources in tscn
|
||||
if EditorScript.new().get_editor_interface().get_edited_scene_root() != self:
|
||||
set("theme_override_styles/panel", get_theme_stylebox("panel", "Panel"))
|
||||
$VBox/Label.set("theme_override_styles/normal", get_theme_stylebox("bg", "EditorInspectorCategory"))
|
||||
$VBox/Label.set("theme_override_fonts/font", get_theme_font("bold", "EditorFonts"))
|
||||
$VBox/Label.set("theme_override_font_sizes/font_size",get_theme_font_size("bold_size", "EditorFonts"))
|
||||
placement_pin.icon = get_theme_icon("Pin", "EditorIcons")
|
||||
placement_pin.text = ""
|
||||
|
||||
# Setup style for selected assets
|
||||
focus_style = get_theme_stylebox("focus", "Button").duplicate()
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
if slot != p_slot:
|
||||
slot = p_slot
|
||||
placement_opt.selected = slot
|
||||
save_editor_settings()
|
||||
plugin.select_terrain()
|
||||
update_dock(plugin.visible)
|
||||
|
||||
|
||||
func _on_placement_selected(index: int) -> void:
|
||||
emit_signal("placement_changed", index)
|
||||
func remove_dock(p_force: bool = false) -> void:
|
||||
if state == SIDEBAR:
|
||||
plugin.remove_control_from_docks(self)
|
||||
state = HIDDEN
|
||||
|
||||
elif state == BOTTOM:
|
||||
plugin.remove_control_from_bottom_panel(self)
|
||||
state = HIDDEN
|
||||
|
||||
# If windowed and destination is not window or final exit, otherwise leave
|
||||
elif state == WINDOWED and p_force:
|
||||
if not window:
|
||||
return
|
||||
var parent: Node = get_parent()
|
||||
if parent:
|
||||
parent.remove_child(self)
|
||||
_godot_editor_window.mouse_entered.disconnect(_on_godot_window_entered)
|
||||
_godot_editor_window.focus_entered.disconnect(_on_godot_focus_entered)
|
||||
_godot_editor_window.focus_exited.disconnect(_on_godot_focus_exited)
|
||||
window.hide()
|
||||
window.queue_free()
|
||||
window = null
|
||||
floating_btn.button_pressed = false
|
||||
floating_btn.visible = true
|
||||
pinned_btn.visible = false
|
||||
placement_opt.visible = true
|
||||
state = HIDDEN
|
||||
update_dock(plugin.visible) # return window to side/bottom
|
||||
|
||||
|
||||
func update_dock(p_visible: bool) -> void:
|
||||
update_assets()
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
if window:
|
||||
return
|
||||
elif floating_btn.button_pressed:
|
||||
# No window, but floating button pressed, occurs when from editor settings
|
||||
make_dock_float()
|
||||
return
|
||||
|
||||
remove_dock()
|
||||
# Add dock to new destination
|
||||
# Sidebar
|
||||
if slot < POS_BOTTOM:
|
||||
state = SIDEBAR
|
||||
plugin.add_control_to_dock(slot, self)
|
||||
elif slot == POS_BOTTOM:
|
||||
state = BOTTOM
|
||||
plugin.add_control_to_bottom_panel(self, "Terrain3D")
|
||||
if p_visible:
|
||||
plugin.make_bottom_panel_item_visible(self)
|
||||
|
||||
|
||||
func update_layout() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
# Detect if we have a new window from Make floating, grab it so we can free it properly
|
||||
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
|
||||
|
||||
var size_parent: Control = size_slider.get_parent()
|
||||
# Vertical layout in window / sidebar
|
||||
if window or slot < POS_BOTTOM:
|
||||
box.vertical = true
|
||||
buttons.vertical = false
|
||||
|
||||
if size.x >= 500 and size_parent != buttons:
|
||||
size_slider.reparent(buttons)
|
||||
buttons.move_child(size_slider, 3)
|
||||
elif size.x < 500 and size_parent != box:
|
||||
size_slider.reparent(box)
|
||||
box.move_child(size_slider, 1)
|
||||
floating_btn.reparent(buttons)
|
||||
buttons.move_child(floating_btn, 4)
|
||||
|
||||
# Wide layout on bottom bar
|
||||
else:
|
||||
size_slider.reparent(buttons)
|
||||
buttons.move_child(size_slider, 3)
|
||||
floating_btn.reparent(box)
|
||||
box.vertical = false
|
||||
buttons.vertical = true
|
||||
|
||||
save_editor_settings()
|
||||
|
||||
|
||||
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:
|
||||
plugin.terrain.assets.create_mesh_thumbnails()
|
||||
_last_thumb_update_time = Time.get_ticks_msec()
|
||||
for mesh_asset in mesh_list.entries:
|
||||
mesh_asset.queue_redraw()
|
||||
## Dock Button handlers
|
||||
|
||||
|
||||
func _on_pin_changed(toggled: bool) -> void:
|
||||
if window:
|
||||
window.always_on_top = pinned_btn.button_pressed
|
||||
save_editor_settings()
|
||||
|
||||
|
||||
func _on_slider_changed(value: float) -> void:
|
||||
if list:
|
||||
list.set_entry_size(value)
|
||||
if texture_list:
|
||||
texture_list.set_entry_width(value)
|
||||
if mesh_list:
|
||||
mesh_list.set_entry_width(value)
|
||||
save_editor_settings()
|
||||
|
||||
|
||||
func move_slider(to_side: bool) -> void:
|
||||
if to_side and size_slider.get_parent() != $VBox:
|
||||
size_slider.reparent($VBox)
|
||||
$VBox.move_child(size_slider, 2)
|
||||
size_slider.custom_minimum_size = Vector2(0, 0)
|
||||
elif not to_side and size_slider.get_parent() == $VBox:
|
||||
size_slider.reparent($VBox/PlacementHBox)
|
||||
$VBox/PlacementHBox.move_child(size_slider, 2)
|
||||
size_slider.custom_minimum_size = Vector2(300, 10)
|
||||
func _on_textures_pressed() -> void:
|
||||
_current_list = texture_list
|
||||
texture_list.update_asset_list()
|
||||
texture_list.visible = true
|
||||
mesh_list.visible = false
|
||||
textures_btn.button_pressed = true
|
||||
meshes_btn.button_pressed = false
|
||||
texture_list.set_selected_id(texture_list.selected_id)
|
||||
plugin.get_editor_interface().edit_node(plugin.terrain)
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
for i in entries:
|
||||
i.get_parent().remove_child(i)
|
||||
i.queue_free()
|
||||
entries.clear()
|
||||
func _on_meshes_pressed() -> void:
|
||||
_current_list = mesh_list
|
||||
mesh_list.update_asset_list()
|
||||
mesh_list.visible = true
|
||||
texture_list.visible = false
|
||||
meshes_btn.button_pressed = true
|
||||
textures_btn.button_pressed = false
|
||||
mesh_list.set_selected_id(mesh_list.selected_id)
|
||||
plugin.get_editor_interface().edit_node(plugin.terrain)
|
||||
update_thumbnails()
|
||||
|
||||
|
||||
func add_item(p_resource: Resource = null) -> void:
|
||||
var entry: ListEntry = ListEntry.new()
|
||||
entry.focus_style = focus_style
|
||||
var index: int = entries.size()
|
||||
func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation) -> void:
|
||||
if p_tool == Terrain3DEditor.INSTANCER:
|
||||
_on_meshes_pressed()
|
||||
elif p_tool == Terrain3DEditor.TEXTURE:
|
||||
_on_textures_pressed()
|
||||
|
||||
|
||||
## Update Dock Contents
|
||||
|
||||
|
||||
func update_assets() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
|
||||
entry.set_edited_resource(p_resource)
|
||||
entry.selected.connect(set_selected_index.bind(index))
|
||||
entry.inspected.connect(notify_resource_inspected)
|
||||
entry.changed.connect(notify_resource_changed.bind(index))
|
||||
# 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):
|
||||
plugin.terrain.assets.textures_changed.connect(texture_list.update_asset_list)
|
||||
if not plugin.terrain.assets.meshes_changed.is_connected(mesh_list.update_asset_list):
|
||||
plugin.terrain.assets.meshes_changed.connect(mesh_list.update_asset_list)
|
||||
|
||||
_current_list.update_asset_list()
|
||||
|
||||
## Window Management
|
||||
|
||||
|
||||
func make_dock_float() -> void:
|
||||
# If already created (eg from editor Make Floating)
|
||||
if not window:
|
||||
remove_dock()
|
||||
create_window()
|
||||
|
||||
state = WINDOWED
|
||||
pinned_btn.visible = true
|
||||
floating_btn.visible = false
|
||||
placement_opt.visible = false
|
||||
window.title = "Terrain3D Asset Dock"
|
||||
window.always_on_top = pinned_btn.button_pressed
|
||||
window.close_requested.connect(remove_dock.bind(true))
|
||||
visible = true # Is hidden when pops off of bottom. ??
|
||||
_godot_editor_window.grab_focus()
|
||||
|
||||
|
||||
func create_window() -> void:
|
||||
window = Window.new()
|
||||
window.wrap_controls = true
|
||||
var mc := MarginContainer.new()
|
||||
mc.set_anchors_preset(PRESET_FULL_RECT, false)
|
||||
mc.add_child(self)
|
||||
window.add_child(mc)
|
||||
window.set_transient(false)
|
||||
window.set_size(get_setting(PS_DOCK_WINDOW_SIZE, Vector2i(512, 512)))
|
||||
window.set_position(get_setting(PS_DOCK_WINDOW_POSITION, Vector2i(704, 284)))
|
||||
plugin.add_child(window)
|
||||
window.show()
|
||||
window.window_input.connect(_on_window_input)
|
||||
window.focus_exited.connect(_on_window_focus_exited)
|
||||
_godot_editor_window.mouse_entered.connect(_on_godot_window_entered)
|
||||
_godot_editor_window.focus_entered.connect(_on_godot_focus_entered)
|
||||
_godot_editor_window.focus_exited.connect(_on_godot_focus_exited)
|
||||
|
||||
|
||||
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():
|
||||
save_editor_settings()
|
||||
plugin.get_editor_interface().save_scene()
|
||||
|
||||
|
||||
func _on_window_focus_exited() -> void:
|
||||
# Capture window position w/o other changes
|
||||
save_editor_settings()
|
||||
|
||||
|
||||
func _on_godot_window_entered() -> void:
|
||||
if is_instance_valid(window) and window.has_focus():
|
||||
_godot_editor_window.grab_focus()
|
||||
|
||||
|
||||
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 _godot_editor_window.mode != Window.MODE_MINIMIZED:
|
||||
window.show()
|
||||
_godot_last_state = _godot_editor_window.mode
|
||||
_godot_editor_window.grab_focus()
|
||||
|
||||
|
||||
func _on_godot_focus_exited() -> void:
|
||||
if is_instance_valid(window) and _godot_editor_window.mode == Window.MODE_MINIMIZED:
|
||||
window.hide()
|
||||
_godot_last_state = _godot_editor_window.mode
|
||||
|
||||
|
||||
## Manage Editor Settings
|
||||
|
||||
|
||||
func get_setting(p_str: String, p_default: Variant) -> Variant:
|
||||
if editor_settings.has_setting(p_str):
|
||||
return editor_settings.get_setting(p_str)
|
||||
else:
|
||||
return p_default
|
||||
|
||||
|
||||
func load_editor_settings() -> void:
|
||||
floating_btn.button_pressed = get_setting(PS_DOCK_FLOATING, false)
|
||||
pinned_btn.button_pressed = get_setting(PS_DOCK_PINNED, true)
|
||||
size_slider.value = get_setting(PS_DOCK_TILE_SIZE, 83)
|
||||
set_slot(get_setting(PS_DOCK_SLOT, POS_BOTTOM))
|
||||
_on_slider_changed(size_slider.value)
|
||||
# Window pos/size set on window creation in update_dock
|
||||
update_dock(plugin.visible)
|
||||
|
||||
if p_resource:
|
||||
entry.set_selected(index == selected_index)
|
||||
if not p_resource.id_changed.is_connected(set_selected_after_swap):
|
||||
p_resource.id_changed.connect(set_selected_after_swap)
|
||||
|
||||
list.add_child(entry)
|
||||
entries.push_back(entry)
|
||||
|
||||
|
||||
func set_selected_after_swap(p_old_index: int, p_new_index: int) -> void:
|
||||
set_selected_index(clamp(p_new_index, 0, entries.size() - 2))
|
||||
|
||||
|
||||
func set_selected_index(p_index: int) -> void:
|
||||
selected_index = p_index
|
||||
emit_signal("resource_selected")
|
||||
|
||||
for i in entries.size():
|
||||
var entry: ListEntry = entries[i]
|
||||
entry.set_selected(i == selected_index)
|
||||
|
||||
|
||||
func get_selected_index() -> int:
|
||||
return selected_index
|
||||
|
||||
|
||||
func notify_resource_inspected(p_resource: Resource) -> void:
|
||||
emit_signal("resource_inspected", p_resource)
|
||||
|
||||
|
||||
func notify_resource_changed(p_resource: Resource, p_index: int) -> void:
|
||||
emit_signal("resource_changed", p_resource, p_index)
|
||||
if !p_resource:
|
||||
var last_offset: int = 2
|
||||
if p_index == entries.size()-2:
|
||||
last_offset = 3
|
||||
selected_index = clamp(selected_index, 0, entries.size() - last_offset)
|
||||
func save_editor_settings() -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
editor_settings.set_setting(PS_DOCK_SLOT, slot)
|
||||
editor_settings.set_setting(PS_DOCK_TILE_SIZE, size_slider.value)
|
||||
editor_settings.set_setting(PS_DOCK_FLOATING, floating_btn.button_pressed)
|
||||
editor_settings.set_setting(PS_DOCK_PINNED, pinned_btn.button_pressed)
|
||||
if window:
|
||||
editor_settings.set_setting(PS_DOCK_WINDOW_SIZE, window.size)
|
||||
editor_settings.set_setting(PS_DOCK_WINDOW_POSITION, window.position)
|
||||
|
||||
|
||||
##############################################################
|
||||
|
|
@ -122,18 +429,182 @@ func notify_resource_changed(p_resource: Resource, p_index: int) -> void:
|
|||
|
||||
|
||||
class ListContainer extends Container:
|
||||
var plugin: EditorPlugin
|
||||
var type := Terrain3DAssets.TYPE_TEXTURE
|
||||
var entries: Array[ListEntry]
|
||||
var selected_id: int = 0
|
||||
var height: float = 0
|
||||
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)
|
||||
focus_style = get_theme_stylebox("focus", "Button").duplicate()
|
||||
focus_style.set_border_width_all(2)
|
||||
focus_style.set_border_color(Color(1, 1, 1, .67))
|
||||
|
||||
|
||||
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):
|
||||
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:
|
||||
var texture: Terrain3DTextureAsset = t.assets.get_texture(i)
|
||||
add_item(texture)
|
||||
if texture_count < Terrain3DAssets.MAX_TEXTURES:
|
||||
add_item()
|
||||
else:
|
||||
var mesh_count: int = t.assets.get_mesh_count()
|
||||
for i in mesh_count:
|
||||
var mesh: Terrain3DMeshAsset = t.assets.get_mesh_asset(i)
|
||||
add_item(mesh, t.assets)
|
||||
if mesh_count < Terrain3DAssets.MAX_MESHES:
|
||||
add_item()
|
||||
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))
|
||||
entry.inspected.connect(_on_resource_inspected)
|
||||
entry.changed.connect(_on_resource_changed.bind(id))
|
||||
entry.type = type
|
||||
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:
|
||||
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 plugin.editor.get_tool() != Terrain3DEditor.TEXTURE:
|
||||
var paint_btn: Button = plugin.ui.toolbar.get_node_or_null("PaintBaseTexture")
|
||||
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:
|
||||
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
|
||||
plugin.get_editor_interface().edit_resource(p_resource)
|
||||
|
||||
|
||||
func set_entry_size(value: float) -> void:
|
||||
width = clamp(value, 56, 256)
|
||||
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()
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
asset_dock.confirm_dialog.dialog_text = "Are you sure you want to clear this texture?"
|
||||
else:
|
||||
asset_dock.confirm_dialog.dialog_text = "Are you sure you want to clear this mesh and delete all instances?"
|
||||
asset_dock.confirm_dialog.popup_centered()
|
||||
await asset_dock.confirmation_closed
|
||||
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
|
||||
|
||||
if plugin.is_terrain_valid():
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
plugin.terrain.get_assets().set_texture(p_id, p_resource)
|
||||
else:
|
||||
plugin.terrain.get_assets().set_mesh_asset(p_id, p_resource)
|
||||
await get_tree().create_timer(.01).timeout
|
||||
plugin.terrain.assets.create_mesh_thumbnails(p_id)
|
||||
|
||||
# If removing an entry, clear inspector
|
||||
if not p_resource:
|
||||
plugin.get_editor_interface().inspect_object(null)
|
||||
|
||||
# If null resource, remove last
|
||||
if not p_resource:
|
||||
var last_offset: int = 2
|
||||
if p_id == entries.size()-2:
|
||||
last_offset = 3
|
||||
set_selected_id(clamp(selected_id, 0, entries.size() - last_offset))
|
||||
|
||||
# Update editor with selected brush
|
||||
plugin.ui._on_setting_changed()
|
||||
|
||||
|
||||
func get_selected_id() -> int:
|
||||
return selected_id
|
||||
|
||||
|
||||
|
||||
func set_entry_width(value: float) -> void:
|
||||
width = clamp(value, 56, 230)
|
||||
redraw()
|
||||
|
||||
|
||||
func get_entry_width() -> float:
|
||||
return width
|
||||
|
||||
|
||||
func redraw() -> void:
|
||||
height = 0
|
||||
var index: int = 0
|
||||
var id: int = 0
|
||||
var separation: float = 4
|
||||
var columns: int = 3
|
||||
columns = clamp(size.x / width, 1, 100)
|
||||
|
|
@ -141,12 +612,13 @@ class ListContainer extends Container:
|
|||
for c in get_children():
|
||||
if is_instance_valid(c):
|
||||
c.size = Vector2(width, width) - Vector2(separation, separation)
|
||||
c.position = Vector2(index % columns, index / columns) * width + \
|
||||
c.position = Vector2(id % columns, id / columns) * width + \
|
||||
Vector2(separation / columns, separation / columns)
|
||||
height = max(height, c.position.y + width)
|
||||
index += 1
|
||||
id += 1
|
||||
|
||||
|
||||
# Needed to enable ScrollContainer scroll bar
|
||||
func _get_minimum_size() -> Vector2:
|
||||
return Vector2(0, height)
|
||||
|
||||
|
|
@ -162,14 +634,18 @@ class ListContainer extends Container:
|
|||
|
||||
|
||||
class ListEntry extends VBoxContainer:
|
||||
signal hovered()
|
||||
signal selected()
|
||||
signal changed(resource: Terrain3DTexture)
|
||||
signal inspected(resource: Terrain3DTexture)
|
||||
signal changed(resource: Resource)
|
||||
signal inspected(resource: Resource)
|
||||
|
||||
var resource: Terrain3DTexture
|
||||
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 asset_list: Terrain3DAssets
|
||||
|
||||
var button_clear: TextureButton
|
||||
var button_edit: TextureButton
|
||||
|
|
@ -180,7 +656,7 @@ class ListEntry extends VBoxContainer:
|
|||
@onready var edit_icon: Texture2D = get_theme_icon("Edit", "EditorIcons")
|
||||
@onready var background: StyleBox = get_theme_stylebox("pressed", "Button")
|
||||
var focus_style: StyleBox
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var icon_size: Vector2 = Vector2(12, 12)
|
||||
|
|
@ -213,8 +689,11 @@ class ListEntry extends VBoxContainer:
|
|||
name_label.add_theme_font_size_override("font_size", 15)
|
||||
name_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
name_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
name_label.text = "Add New"
|
||||
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
name_label.text = "Add Texture"
|
||||
else:
|
||||
name_label.text = "Add Mesh"
|
||||
|
||||
|
||||
func _notification(p_what) -> void:
|
||||
match p_what:
|
||||
|
|
@ -224,22 +703,33 @@ class ListEntry extends VBoxContainer:
|
|||
draw_style_box(background, rect)
|
||||
draw_texture(add_icon, (get_size() / 2) - (add_icon.get_size() / 2))
|
||||
else:
|
||||
name_label.text = resource.get_name()
|
||||
self_modulate = resource.get_albedo_color()
|
||||
var texture: Texture2D = resource.get_albedo_texture()
|
||||
if texture:
|
||||
draw_texture_rect(texture, rect, false)
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST_WITH_MIPMAPS
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
name_label.text = (resource as Terrain3DTextureAsset).get_name()
|
||||
self_modulate = resource.get_albedo_color()
|
||||
_thumbnail = resource.get_albedo_texture()
|
||||
if _thumbnail:
|
||||
draw_texture_rect(_thumbnail, rect, false)
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST_WITH_MIPMAPS
|
||||
else:
|
||||
name_label.text = (resource as Terrain3DMeshAsset).get_name()
|
||||
var id: int = (resource as Terrain3DMeshAsset).get_id()
|
||||
_thumbnail = resource.get_thumbnail()
|
||||
if _thumbnail:
|
||||
draw_texture_rect(_thumbnail, rect, false)
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
||||
else:
|
||||
draw_rect(rect, Color(.15, .15, .15, 1.))
|
||||
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:
|
||||
draw_rect(rect, Color(1,1,1,0.2))
|
||||
draw_rect(rect, Color(1, 1, 1, 0.2))
|
||||
if is_selected:
|
||||
draw_style_box(focus_style, rect)
|
||||
NOTIFICATION_MOUSE_ENTER:
|
||||
is_hovered = true
|
||||
name_label.visible = true
|
||||
emit_signal("hovered")
|
||||
queue_redraw()
|
||||
NOTIFICATION_MOUSE_EXIT:
|
||||
is_hovered = false
|
||||
|
|
@ -255,7 +745,10 @@ class ListEntry extends VBoxContainer:
|
|||
MOUSE_BUTTON_LEFT:
|
||||
# If `Add new` is clicked
|
||||
if !resource:
|
||||
set_edited_resource(Terrain3DTexture.new(), false)
|
||||
if type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
set_edited_resource(Terrain3DTextureAsset.new(), false)
|
||||
else:
|
||||
set_edited_resource(Terrain3DMeshAsset.new(), false)
|
||||
edit()
|
||||
else:
|
||||
emit_signal("selected")
|
||||
|
|
@ -279,19 +772,38 @@ class ListEntry extends VBoxContainer:
|
|||
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])
|
||||
if res is Terrain3DTexture:
|
||||
if res is Texture2D and type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
var ta := Terrain3DTextureAsset.new()
|
||||
if resource is Terrain3DTextureAsset:
|
||||
ta.id = resource.id
|
||||
ta.set_albedo_texture(res)
|
||||
set_edited_resource(ta, false)
|
||||
resource = ta
|
||||
elif res is Terrain3DTextureAsset and type == Terrain3DAssets.TYPE_TEXTURE:
|
||||
if resource is Terrain3DTextureAsset:
|
||||
res.id = resource.id
|
||||
set_edited_resource(res, false)
|
||||
if res is Texture2D:
|
||||
var surf: Terrain3DTexture = Terrain3DTexture.new()
|
||||
surf.set_albedo_texture(res)
|
||||
set_edited_resource(surf, false)
|
||||
elif res is PackedScene and type == Terrain3DAssets.TYPE_MESH:
|
||||
var ma := Terrain3DMeshAsset.new()
|
||||
if resource is Terrain3DMeshAsset:
|
||||
ma.id = resource.id
|
||||
ma.set_scene_file(res)
|
||||
set_edited_resource(ma, false)
|
||||
resource = ma
|
||||
elif res is Terrain3DMeshAsset and type == Terrain3DAssets.TYPE_MESH:
|
||||
if resource is Terrain3DMeshAsset:
|
||||
res.id = resource.id
|
||||
set_edited_resource(res, false)
|
||||
emit_signal("selected")
|
||||
emit_signal("inspected", resource)
|
||||
|
||||
|
||||
func set_edited_resource(p_res: Terrain3DTexture, p_no_signal: bool = true) -> void:
|
||||
|
||||
|
||||
func set_edited_resource(p_res: Resource, p_no_signal: bool = true) -> void:
|
||||
resource = p_res
|
||||
if resource:
|
||||
resource.setting_changed.connect(_on_texture_changed)
|
||||
resource.file_changed.connect(_on_texture_changed)
|
||||
resource.setting_changed.connect(_on_resource_changed)
|
||||
resource.file_changed.connect(_on_resource_changed)
|
||||
|
||||
if button_clear:
|
||||
button_clear.set_visible(resource != null)
|
||||
|
|
@ -301,7 +813,7 @@ class ListEntry extends VBoxContainer:
|
|||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
func _on_texture_changed() -> void:
|
||||
func _on_resource_changed() -> void:
|
||||
emit_signal("changed", resource)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,26 +3,45 @@
|
|||
[ext_resource type="Script" path="res://addons/terrain_3d/src/asset_dock.gd" id="1_e23pg"]
|
||||
|
||||
[node name="Terrain3D" type="PanelContainer"]
|
||||
custom_minimum_size = Vector2(256, 136)
|
||||
offset_right = 256.0
|
||||
offset_bottom = 128.0
|
||||
custom_minimum_size = Vector2(256, 95)
|
||||
offset_right = 766.0
|
||||
offset_bottom = 100.0
|
||||
script = ExtResource("1_e23pg")
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="."]
|
||||
[node name="Box" type="BoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
vertical = true
|
||||
|
||||
[node name="Buttons" type="BoxContainer" parent="Box"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="PlacementHBox" type="HBoxContainer" parent="VBox"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBox/PlacementHBox"]
|
||||
layout_mode = 2
|
||||
text = "Dock Position: "
|
||||
|
||||
[node name="Options" type="OptionButton" parent="VBox/PlacementHBox"]
|
||||
[node name="TexturesBtn" type="Button" parent="Box/Buttons"]
|
||||
custom_minimum_size = Vector2(80, 30)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
theme_override_font_sizes/font_size = 16
|
||||
toggle_mode = true
|
||||
button_pressed = true
|
||||
text = "Textures"
|
||||
|
||||
[node name="MeshesBtn" type="Button" parent="Box/Buttons"]
|
||||
custom_minimum_size = Vector2(80, 30)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
theme_override_font_sizes/font_size = 16
|
||||
toggle_mode = true
|
||||
text = "Meshes"
|
||||
|
||||
[node name="PlacementOpt" type="OptionButton" parent="Box/Buttons"]
|
||||
custom_minimum_size = Vector2(80, 30)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
item_count = 9
|
||||
selected = 5
|
||||
selected = 7
|
||||
popup/item_0/text = "Left_UL"
|
||||
popup/item_0/id = 0
|
||||
popup/item_1/text = "Left_BL"
|
||||
|
|
@ -42,28 +61,33 @@ popup/item_7/id = 7
|
|||
popup/item_8/text = "Bottom"
|
||||
popup/item_8/id = 8
|
||||
|
||||
[node name="Pinned" type="Button" parent="VBox/PlacementHBox"]
|
||||
[node name="SizeSlider" type="HSlider" parent="Box/Buttons"]
|
||||
custom_minimum_size = Vector2(80, 10)
|
||||
layout_mode = 2
|
||||
tooltip_text = "Keep panel visible even if Terrain3D is not selected. Useful for keeping dock floating."
|
||||
size_flags_horizontal = 3
|
||||
min_value = 56.0
|
||||
max_value = 230.0
|
||||
value = 83.0
|
||||
|
||||
[node name="Floating" type="Button" parent="Box/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
tooltip_text = "Pop this dock out to a floating window."
|
||||
toggle_mode = true
|
||||
text = "F"
|
||||
flat = true
|
||||
|
||||
[node name="Pinned" type="Button" parent="Box/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
tooltip_text = "Make this window \"Always on top\"."
|
||||
toggle_mode = true
|
||||
text = "P"
|
||||
flat = true
|
||||
|
||||
[node name="Label" type="Label" parent="VBox"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 16
|
||||
text = "Textures"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="SizeSlider" type="HSlider" parent="VBox"]
|
||||
custom_minimum_size = Vector2(100, 10)
|
||||
layout_mode = 2
|
||||
min_value = 56.0
|
||||
max_value = 256.0
|
||||
value = 83.0
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="VBox"]
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="Box"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ func _bake_nav_region_nav_mesh(p_nav_region: NavigationRegion3D) -> void:
|
|||
aabb = p_nav_region.global_transform * aabb
|
||||
var faces: PackedVector3Array = terrain.generate_nav_mesh_source_geometry(aabb)
|
||||
if not faces.is_empty():
|
||||
source_geometry_data.add_faces(faces, p_nav_region.global_transform.inverse())
|
||||
source_geometry_data.add_faces(faces, Transform3D.IDENTITY)
|
||||
|
||||
NavigationMeshGenerator.bake_from_source_geometry_data(nav_mesh, source_geometry_data)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ signal pressed
|
|||
signal value_changed
|
||||
|
||||
|
||||
const ICON_PICKER: String = "res://addons/terrain_3d/icons/icon_picker.svg"
|
||||
const ICON_PICKER_CHECKED: String = "res://addons/terrain_3d/icons/icon_picker_checked.svg"
|
||||
const ICON_PICKER: String = "res://addons/terrain_3d/icons/picker.svg"
|
||||
const ICON_PICKER_CHECKED: String = "res://addons/terrain_3d/icons/picker_checked.svg"
|
||||
const MAX_POINTS: int = 2
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ func _enter_tree() -> void:
|
|||
add_child(menu_button)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
# TODO: If packer isn't freed, Godot complains about ObjectDB instances leaked and
|
||||
# resources still in use at exit. Figure out why.
|
||||
packer.free()
|
||||
|
||||
|
||||
func _on_menu_pressed(p_id: int) -> void:
|
||||
match p_id:
|
||||
MENU_BAKE_ARRAY_MESH:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ enum SettingType {
|
|||
const MultiPicker: Script = preload("res://addons/terrain_3d/src/multi_picker.gd")
|
||||
const DEFAULT_BRUSH: String = "circle0.exr"
|
||||
const BRUSH_PATH: String = "res://addons/terrain_3d/brushes"
|
||||
const PICKER_ICON: String = "res://addons/terrain_3d/icons/icon_picker.svg"
|
||||
const PICKER_ICON: String = "res://addons/terrain_3d/icons/picker.svg"
|
||||
|
||||
# Add settings flags
|
||||
const NONE: int = 0x0
|
||||
|
|
@ -103,6 +103,41 @@ func _ready() -> void:
|
|||
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 })
|
||||
|
||||
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 })
|
||||
|
||||
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_angle", "label":"Fixed Angle (From Y)", "type":SettingType.SLIDER, "list":rotation_list,
|
||||
"default":0, "unit":"°", "range":Vector3(-85, 85, 1), "flags":ALLOW_OUT_OF_BOUNDS })
|
||||
add_setting({ "name":"random_angle", "label":"Random Angle ±", "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) })
|
||||
|
||||
var spacer: Control = Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
|
|
@ -135,10 +170,10 @@ func create_submenu(p_parent: Control, p_button_name: String, p_layout: Layout)
|
|||
var panel_style: StyleBox = get_theme_stylebox("panel", "PopupMenu").duplicate()
|
||||
panel_style.set_content_margin_all(10)
|
||||
submenu.set("theme_override_styles/panel", panel_style)
|
||||
submenu.add_to_group("terrain3d_submenus")
|
||||
|
||||
# Pop up menu on hover, hide on exit
|
||||
menu_button.mouse_entered.connect(_on_show_submenu.bind(true, menu_button))
|
||||
menu_button.mouse_exited.connect(_on_show_submenu.bind(false, menu_button))
|
||||
submenu.mouse_exited.connect(_on_show_submenu.bind(false, menu_button))
|
||||
|
||||
var sublist: Container
|
||||
|
|
@ -171,6 +206,8 @@ func _on_show_submenu(p_toggled: bool, p_button: Button) -> void:
|
|||
if not p_toggled and ( in_button or in_panel ):
|
||||
return
|
||||
|
||||
# Hide all submenus before possibly enabling the current one
|
||||
get_tree().call_group("terrain3d_submenus", "set_visible", false)
|
||||
var popup: PopupPanel = p_button.get_child(0)
|
||||
var popup_pos: Vector2 = p_button.get_screen_transform().origin
|
||||
popup.set_visible(p_toggled)
|
||||
|
|
@ -326,6 +363,7 @@ func add_setting(p_args: Dictionary) -> void:
|
|||
|
||||
SettingType.PICKER:
|
||||
var button := Button.new()
|
||||
button.set_v_size_flags(SIZE_SHRINK_CENTER)
|
||||
button.icon = load(PICKER_ICON)
|
||||
button.tooltip_text = "Pick value from the Terrain"
|
||||
button.pressed.connect(_on_pick.bind(p_default))
|
||||
|
|
@ -361,7 +399,6 @@ func add_setting(p_args: Dictionary) -> void:
|
|||
spin_slider.set_step(p_step)
|
||||
spin_slider.set_value(p_default)
|
||||
spin_slider.set_suffix(p_suffix)
|
||||
spin_slider.set_h_size_flags(SIZE_SHRINK_CENTER)
|
||||
spin_slider.set_v_size_flags(SIZE_SHRINK_CENTER)
|
||||
spin_slider.set_custom_minimum_size(Vector2(75, 0))
|
||||
|
||||
|
|
@ -378,8 +415,6 @@ func add_setting(p_args: Dictionary) -> void:
|
|||
|
||||
else: # DOUBLE_SLIDER
|
||||
var label := Label.new()
|
||||
label.set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER)
|
||||
label.set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER)
|
||||
label.set_custom_minimum_size(Vector2(75, 0))
|
||||
slider = DoubleSlider.new()
|
||||
slider.label = label
|
||||
|
|
@ -394,7 +429,6 @@ func add_setting(p_args: Dictionary) -> void:
|
|||
slider.set_step(p_step)
|
||||
slider.set_value(p_default)
|
||||
slider.set_v_size_flags(SIZE_SHRINK_CENTER)
|
||||
slider.set_h_size_flags(SIZE_SHRINK_END | SIZE_EXPAND)
|
||||
slider.set_custom_minimum_size(Vector2(60, 10))
|
||||
|
||||
control.name = p_name.to_pascal_case()
|
||||
|
|
|
|||
|
|
@ -3,22 +3,23 @@ extends VBoxContainer
|
|||
|
||||
signal tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation)
|
||||
|
||||
const ICON_REGION_ADD: String = "res://addons/terrain_3d/icons/icon_map_add.svg"
|
||||
const ICON_REGION_REMOVE: String = "res://addons/terrain_3d/icons/icon_map_remove.svg"
|
||||
const ICON_HEIGHT_ADD: String = "res://addons/terrain_3d/icons/icon_height_add.svg"
|
||||
const ICON_HEIGHT_SUB: String = "res://addons/terrain_3d/icons/icon_height_sub.svg"
|
||||
const ICON_HEIGHT_MUL: String = "res://addons/terrain_3d/icons/icon_height_mul.svg"
|
||||
const ICON_HEIGHT_DIV: String = "res://addons/terrain_3d/icons/icon_height_div.svg"
|
||||
const ICON_HEIGHT_FLAT: String = "res://addons/terrain_3d/icons/icon_height_flat.svg"
|
||||
const ICON_HEIGHT_SLOPE: String = "res://addons/terrain_3d/icons/icon_height_slope.svg"
|
||||
const ICON_HEIGHT_SMOOTH: String = "res://addons/terrain_3d/icons/icon_height_smooth.svg"
|
||||
const ICON_PAINT_TEXTURE: String = "res://addons/terrain_3d/icons/icon_brush.svg"
|
||||
const ICON_SPRAY_TEXTURE: String = "res://addons/terrain_3d/icons/icon_spray.svg"
|
||||
const ICON_COLOR: String = "res://addons/terrain_3d/icons/icon_color.svg"
|
||||
const ICON_WETNESS: String = "res://addons/terrain_3d/icons/icon_wetness.svg"
|
||||
const ICON_AUTOSHADER: String = "res://addons/terrain_3d/icons/icon_terrain_material.svg"
|
||||
const ICON_HOLES: String = "res://addons/terrain_3d/icons/icon_holes.svg"
|
||||
const ICON_NAVIGATION: String = "res://addons/terrain_3d/icons/icon_navigation.svg"
|
||||
const ICON_REGION_ADD: String = "res://addons/terrain_3d/icons/region_add.svg"
|
||||
const ICON_REGION_REMOVE: String = "res://addons/terrain_3d/icons/region_remove.svg"
|
||||
const ICON_HEIGHT_ADD: String = "res://addons/terrain_3d/icons/height_add.svg"
|
||||
const ICON_HEIGHT_SUB: String = "res://addons/terrain_3d/icons/height_sub.svg"
|
||||
const ICON_HEIGHT_MUL: String = "res://addons/terrain_3d/icons/height_mul.svg"
|
||||
const ICON_HEIGHT_DIV: String = "res://addons/terrain_3d/icons/height_div.svg"
|
||||
const ICON_HEIGHT_FLAT: String = "res://addons/terrain_3d/icons/height_flat.svg"
|
||||
const ICON_HEIGHT_SLOPE: String = "res://addons/terrain_3d/icons/height_slope.svg"
|
||||
const ICON_HEIGHT_SMOOTH: String = "res://addons/terrain_3d/icons/height_smooth.svg"
|
||||
const ICON_PAINT_TEXTURE: String = "res://addons/terrain_3d/icons/texture_paint.svg"
|
||||
const ICON_SPRAY_TEXTURE: String = "res://addons/terrain_3d/icons/texture_spray.svg"
|
||||
const ICON_COLOR: String = "res://addons/terrain_3d/icons/color_paint.svg"
|
||||
const ICON_WETNESS: String = "res://addons/terrain_3d/icons/wetness.svg"
|
||||
const ICON_AUTOSHADER: String = "res://addons/terrain_3d/icons/autoshader.svg"
|
||||
const ICON_HOLES: String = "res://addons/terrain_3d/icons/holes.svg"
|
||||
const ICON_NAVIGATION: String = "res://addons/terrain_3d/icons/navigation.svg"
|
||||
const ICON_INSTANCER: String = "res://addons/terrain_3d/icons/multimesh.svg"
|
||||
|
||||
var tool_group: ButtonGroup = ButtonGroup.new()
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ func _ready() -> void:
|
|||
tool_group.connect("pressed", _on_tool_selected)
|
||||
|
||||
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.ADD, "Add Region", load(ICON_REGION_ADD), tool_group)
|
||||
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.SUBTRACT, "Delete Region", load(ICON_REGION_REMOVE), tool_group)
|
||||
add_tool_button(Terrain3DEditor.REGION, Terrain3DEditor.SUBTRACT, "Remove Region", load(ICON_REGION_REMOVE), tool_group)
|
||||
add_child(HSeparator.new())
|
||||
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.ADD, "Raise", load(ICON_HEIGHT_ADD), tool_group)
|
||||
add_tool_button(Terrain3DEditor.HEIGHT, Terrain3DEditor.SUBTRACT, "Lower", load(ICON_HEIGHT_SUB), tool_group)
|
||||
|
|
@ -50,6 +51,7 @@ func _ready() -> void:
|
|||
add_child(HSeparator.new())
|
||||
add_tool_button(Terrain3DEditor.HOLES, Terrain3DEditor.REPLACE, "Create Holes", load(ICON_HOLES), tool_group)
|
||||
add_tool_button(Terrain3DEditor.NAVIGATION, Terrain3DEditor.REPLACE, "Paint Navigable Area", load(ICON_NAVIGATION), tool_group)
|
||||
add_tool_button(Terrain3DEditor.INSTANCER, Terrain3DEditor.ADD, "Instance Meshes", load(ICON_INSTANCER), tool_group)
|
||||
|
||||
var buttons: Array[BaseButton] = tool_group.get_buttons()
|
||||
buttons[0].set_pressed(true)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ const COLOR_ROUGHNESS := Color.ROYAL_BLUE
|
|||
const COLOR_AUTOSHADER := Color.DODGER_BLUE
|
||||
const COLOR_HOLES := Color.BLACK
|
||||
const COLOR_NAVIGATION := Color.REBECCA_PURPLE
|
||||
const COLOR_INSTANCER := Color.CRIMSON
|
||||
const COLOR_PICK_COLOR := Color.WHITE
|
||||
const COLOR_PICK_HEIGHT := Color.DARK_RED
|
||||
const COLOR_PICK_ROUGH := Color.ROYAL_BLUE
|
||||
|
|
@ -95,8 +96,18 @@ func set_visible(p_visible: bool) -> void:
|
|||
update_decal()
|
||||
|
||||
|
||||
func set_menu_visibility(p_list: Control, p_visible: bool) -> void:
|
||||
if p_list:
|
||||
p_list.get_parent().get_parent().visible = p_visible
|
||||
|
||||
|
||||
func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor.Operation) -> void:
|
||||
clear_picking()
|
||||
set_menu_visibility(toolbar_settings.advanced_list, true)
|
||||
set_menu_visibility(toolbar_settings.scale_list, false)
|
||||
set_menu_visibility(toolbar_settings.rotation_list, false)
|
||||
set_menu_visibility(toolbar_settings.height_list, false)
|
||||
set_menu_visibility(toolbar_settings.color_list, false)
|
||||
|
||||
# Select which settings to show. Options in tool_settings.gd:_ready
|
||||
var to_show: PackedStringArray = []
|
||||
|
|
@ -146,6 +157,27 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
|
|||
to_show.push_back("size")
|
||||
to_show.push_back("enable")
|
||||
|
||||
Terrain3DEditor.INSTANCER:
|
||||
to_show.push_back("size")
|
||||
to_show.push_back("strength")
|
||||
to_show.push_back("enable")
|
||||
set_menu_visibility(toolbar_settings.height_list, true)
|
||||
to_show.push_back("height_offset")
|
||||
to_show.push_back("random_height")
|
||||
set_menu_visibility(toolbar_settings.scale_list, true)
|
||||
to_show.push_back("fixed_scale")
|
||||
to_show.push_back("random_scale")
|
||||
set_menu_visibility(toolbar_settings.rotation_list, true)
|
||||
to_show.push_back("fixed_spin")
|
||||
to_show.push_back("random_spin")
|
||||
to_show.push_back("fixed_angle")
|
||||
to_show.push_back("random_angle")
|
||||
to_show.push_back("align_to_normal")
|
||||
set_menu_visibility(toolbar_settings.color_list, true)
|
||||
to_show.push_back("vertex_color")
|
||||
to_show.push_back("random_darken")
|
||||
to_show.push_back("random_hue")
|
||||
|
||||
_:
|
||||
pass
|
||||
|
||||
|
|
@ -174,8 +206,7 @@ func _on_setting_changed() -> void:
|
|||
if not plugin.asset_dock:
|
||||
return
|
||||
brush_data = toolbar_settings.get_settings()
|
||||
brush_data["strength"] /= 100.0
|
||||
brush_data["texture_index"] = plugin.asset_dock.get_selected_index()
|
||||
brush_data["asset_id"] = plugin.asset_dock.get_current_list().get_selected_id()
|
||||
update_decal()
|
||||
plugin.editor.set_brush_data(brush_data)
|
||||
|
||||
|
|
@ -239,7 +270,7 @@ func update_decal() -> void:
|
|||
decal.modulate = COLOR_SLOPE
|
||||
_:
|
||||
decal.modulate = Color.WHITE
|
||||
decal.modulate.a = max(.3, brush_data["strength"])
|
||||
decal.modulate.a = max(.3, brush_data["strength"] * .01)
|
||||
Terrain3DEditor.TEXTURE:
|
||||
match plugin.editor.get_operation():
|
||||
Terrain3DEditor.REPLACE:
|
||||
|
|
@ -247,15 +278,15 @@ func update_decal() -> void:
|
|||
decal.modulate.a = 1.0
|
||||
Terrain3DEditor.ADD:
|
||||
decal.modulate = COLOR_SPRAY
|
||||
decal.modulate.a = max(.3, brush_data["strength"])
|
||||
decal.modulate.a = max(.3, brush_data["strength"] * .01)
|
||||
_:
|
||||
decal.modulate = Color.WHITE
|
||||
Terrain3DEditor.COLOR:
|
||||
decal.modulate = brush_data["color"].srgb_to_linear()*.5
|
||||
decal.modulate.a = max(.3, brush_data["strength"])
|
||||
decal.modulate.a = max(.3, brush_data["strength"] * .01)
|
||||
Terrain3DEditor.ROUGHNESS:
|
||||
decal.modulate = COLOR_ROUGHNESS
|
||||
decal.modulate.a = max(.3, brush_data["strength"])
|
||||
decal.modulate.a = max(.3, brush_data["strength"] * .01)
|
||||
Terrain3DEditor.AUTOSHADER:
|
||||
decal.modulate = COLOR_AUTOSHADER
|
||||
decal.modulate.a = 1.0
|
||||
|
|
@ -265,9 +296,13 @@ func update_decal() -> void:
|
|||
Terrain3DEditor.NAVIGATION:
|
||||
decal.modulate = COLOR_NAVIGATION
|
||||
decal.modulate.a = 1.0
|
||||
Terrain3DEditor.INSTANCER:
|
||||
decal.texture_albedo = ring_texture
|
||||
decal.modulate = COLOR_INSTANCER
|
||||
decal.modulate.a = 1.0
|
||||
_:
|
||||
decal.modulate = Color.WHITE
|
||||
decal.modulate.a = max(.3, brush_data["strength"])
|
||||
decal.modulate.a = max(.3, brush_data["strength"] * .01)
|
||||
decal.size.y = max(1000, decal.size.y)
|
||||
decal.albedo_mix = 1.0
|
||||
decal.cull_mask = 1 << ( plugin.terrain.get_mouse_layer() - 1 )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue