Initial Commit
This commit is contained in:
commit
48a5e71e00
1136 changed files with 64347 additions and 0 deletions
205
addons/script_splitter/core/base/container.gd
Normal file
205
addons/script_splitter/core/base/container.gd
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
@tool
|
||||
extends RefCounted
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# Script Splitter
|
||||
# https://github.com/CodeNameTwister/Script-Splitter
|
||||
#
|
||||
# Script Splitter addon for godot 4
|
||||
# author: "Twister"
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
const SplitterContainer = preload("./../../../script_splitter/core/ui/splitter/splitter_container.gd")
|
||||
const NControl = preload("./../../core/util/control.gd")
|
||||
|
||||
const IoBar = preload("./../../core/ui/splitter/io/io_bar.gd")
|
||||
|
||||
signal update()
|
||||
signal focus_by_tab(root : TabContainer, index : int)
|
||||
signal remove_by_tab(root : TabContainer, index : int)
|
||||
signal change_container(container : TabContainer)
|
||||
signal exiting()
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal rmb_click(index : int, TabContainer)
|
||||
|
||||
@warning_ignore("unused_signal")
|
||||
signal swap_tab(from : Container, index : int, to : Container)
|
||||
@warning_ignore("unused_signal")
|
||||
signal same_swap_tab(from : Container, index : int, type : StringName)
|
||||
|
||||
var _editor_container : TabContainer = null
|
||||
var _editor_splitter_container : SplitterContainer = null
|
||||
|
||||
var _current_container : TabContainer = null:
|
||||
set(e):
|
||||
if _current_container != e:
|
||||
change_container.emit(e)
|
||||
_current_container = e
|
||||
|
||||
var _frm : int = 0
|
||||
|
||||
var _io_bar : Node = null
|
||||
|
||||
func on_focus(root : TabContainer, index : int) -> void:
|
||||
focus_by_tab.emit(root, index)
|
||||
|
||||
func on_remove(root : TabContainer, index : int) -> void:
|
||||
remove_by_tab.emit(root, index)
|
||||
|
||||
func get_io_bar() -> IoBar:
|
||||
if !is_instance_valid(_io_bar):
|
||||
_io_bar = IoBar.new()
|
||||
return _io_bar
|
||||
|
||||
func get_container(control : Control) -> Container:
|
||||
if control is SplitterContainer.SplitterEditorContainer.Editor:
|
||||
return _editor_splitter_container.get_base_container(control)
|
||||
return null
|
||||
|
||||
func get_container_item(control : Control) -> Control:
|
||||
if control is SplitterContainer.SplitterEditorContainer.Editor:
|
||||
return _editor_splitter_container.get_base_container_item(control)
|
||||
return null
|
||||
|
||||
func _init(container : TabContainer) -> void:
|
||||
_editor_container = container
|
||||
_editor_splitter_container = SplitterContainer.new()
|
||||
_editor_splitter_container.initialize(_editor_container, self)
|
||||
_editor_splitter_container.visible = false
|
||||
|
||||
_editor_container.child_entered_tree.connect(_on_update)
|
||||
_editor_container.child_exiting_tree.connect(_on_update)
|
||||
|
||||
_editor_container.tree_exiting.connect(_on_exiting)
|
||||
|
||||
|
||||
func is_active() -> bool:
|
||||
if _frm > 0:
|
||||
_frm -= 1
|
||||
return false
|
||||
return is_instance_valid(_editor_container) and _editor_container.is_inside_tree()
|
||||
|
||||
func _on_exiting() -> void:
|
||||
_frm = 3
|
||||
exiting.emit()
|
||||
|
||||
func initialize_editor_container() -> void:
|
||||
_editor_splitter_container.initialize_editor_contianer()
|
||||
|
||||
func _on_update(__ : Node) -> void:
|
||||
update.emit()
|
||||
|
||||
func set_current_container(container : TabContainer) -> void:
|
||||
if _editor_splitter_container.set_current_editor(container):
|
||||
_current_container = container
|
||||
|
||||
func get_editor_container() -> TabContainer:
|
||||
return _editor_container
|
||||
|
||||
func get_root_container() -> SplitterContainer.SplitterRoot:
|
||||
return _editor_splitter_container.get_root()
|
||||
|
||||
func get_editor_root_container(node : Node) -> SplitterContainer.BaseContainerItem:
|
||||
if node is SplitterContainer.SplitterRoot:
|
||||
node = node.get_parent()
|
||||
return node
|
||||
return null
|
||||
|
||||
func get_editors() -> Array[Node]:
|
||||
return _editor_container.get_children()
|
||||
|
||||
func get_current_editor() -> Control:
|
||||
return _editor_splitter_container.get_current_editor()
|
||||
|
||||
func tool_created() -> void:
|
||||
_editor_container.visible = false
|
||||
_editor_splitter_container.visible = true
|
||||
|
||||
func new_column() -> Control:
|
||||
_current_container = _editor_splitter_container.create_new_column()
|
||||
return _current_container
|
||||
|
||||
func new_row() -> Control:
|
||||
_current_container = _editor_splitter_container.create_new_row()
|
||||
return _current_container
|
||||
|
||||
func update_split_container() -> void:
|
||||
for x : Node in Engine.get_main_loop().get_nodes_in_group(&"__ST_CS__"):
|
||||
if x.has_method(&"update"):
|
||||
x.call(&"update")
|
||||
|
||||
func get_all_containers() -> Array[Node]:
|
||||
if !_editor_splitter_container:
|
||||
return []
|
||||
return _editor_splitter_container.get_tree().get_nodes_in_group(&"__SP_BR__")
|
||||
|
||||
func get_current_containers() -> Array[Node]:
|
||||
if !is_instance_valid(_current_container):
|
||||
return []
|
||||
var c : Control = _editor_splitter_container.get_base_container(_current_container)
|
||||
if is_instance_valid(c):
|
||||
return c.get_children()
|
||||
return []
|
||||
|
||||
func get_all_splitters() -> Array[Node]:
|
||||
if !_editor_splitter_container:
|
||||
return []
|
||||
return _editor_splitter_container.get_tree().get_nodes_in_group(&"__SC_SPLITTER__")
|
||||
|
||||
func get_current_splitters() -> Array[Node]:
|
||||
if !is_instance_valid(_current_container):
|
||||
return []
|
||||
var c : Control = _editor_splitter_container.get_base_container_item(_current_container)
|
||||
if is_instance_valid(c):
|
||||
c = c.get_parent()
|
||||
if c:
|
||||
return c.get_children()
|
||||
return []
|
||||
|
||||
func garbage() -> void:
|
||||
var control : Node = get_current_editor()
|
||||
|
||||
var nodes : Array[Node] = get_all_splitters()
|
||||
var total : int = nodes.size()
|
||||
if total > 2:
|
||||
total = 0
|
||||
for x : Node in nodes:
|
||||
if !x.is_queued_for_deletion():
|
||||
total += 1
|
||||
|
||||
if total > 1:
|
||||
for x : Node in nodes:
|
||||
if total < 2:
|
||||
break
|
||||
if x.get_child_count() == 0:
|
||||
if control == x:
|
||||
control = null
|
||||
if !x.is_queued_for_deletion():
|
||||
x.queue_free()
|
||||
total -= 1
|
||||
|
||||
if control == null:
|
||||
for x : Node in _editor_splitter_container.get_tree().get_nodes_in_group(&"__SC_SPLITTER__"):
|
||||
if x is Control and !x.is_queued_for_deletion():
|
||||
control = x
|
||||
break
|
||||
|
||||
func reset() -> void:
|
||||
_editor_container.visible = true
|
||||
|
||||
if _editor_container.child_entered_tree.is_connected(_on_update):
|
||||
_editor_container.child_entered_tree.disconnect(_on_update)
|
||||
if _editor_container.child_exiting_tree.is_connected(_on_update):
|
||||
_editor_container.child_exiting_tree.disconnect(_on_update)
|
||||
|
||||
_editor_splitter_container.reset()
|
||||
_editor_splitter_container.queue_free()
|
||||
|
||||
func get_current_container() -> TabContainer:
|
||||
return _current_container
|
||||
|
||||
func move_container(from : int, to : int) -> bool:
|
||||
if _editor_container.get_child_count() > from and from > -1:
|
||||
_editor_container.move_child(_editor_container.get_child(from), to)
|
||||
return true
|
||||
return false
|
||||
1
addons/script_splitter/core/base/container.gd.uid
Normal file
1
addons/script_splitter/core/base/container.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://iyslc58y0lp1
|
||||
311
addons/script_splitter/core/base/list.gd
Normal file
311
addons/script_splitter/core/base/list.gd
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
@tool
|
||||
extends RefCounted
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# Script Splitter
|
||||
# https://github.com/CodeNameTwister/Script-Splitter
|
||||
#
|
||||
# Script Splitter addon for godot 4
|
||||
# author: "Twister"
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
const SplitterList = preload("./../../core/ui/splitter/splitter_list.gd")
|
||||
|
||||
signal item_selected(item : int)
|
||||
signal move_item(from : int, to : int)
|
||||
signal updated()
|
||||
|
||||
var _editor_list : ItemList = null
|
||||
var _script_list : ItemList = null
|
||||
var _script_filesearch : LineEdit = null
|
||||
var _editor_filesearch : LineEdit = null
|
||||
var _update_list_queue : bool = false
|
||||
var _array_list : Array = []
|
||||
var _selet_queue : int = -1
|
||||
var _selecting : bool = false
|
||||
|
||||
var update_selections_callback : Callable
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
if is_instance_valid(_editor_list):
|
||||
_editor_list.visible = true
|
||||
if _editor_list.item_selected.is_connected(_item_selected):
|
||||
_editor_list.item_selected.disconnect(_item_selected)
|
||||
if _editor_list.property_list_changed.is_connected(_on_property):
|
||||
_editor_list.property_list_changed.disconnect(_on_property)
|
||||
if is_instance_valid(_editor_filesearch):
|
||||
_editor_filesearch.visible = true
|
||||
|
||||
if is_instance_valid(_script_filesearch):
|
||||
_script_filesearch.queue_free()
|
||||
|
||||
if is_instance_valid(_script_list):
|
||||
_script_list.queue_free()
|
||||
|
||||
func _on_sc_item_selected(index : int) -> void:
|
||||
if _script_list.item_count > index and index > -1:
|
||||
index = _get_script_selected(index)
|
||||
if index == -1:
|
||||
return
|
||||
select(index)
|
||||
|
||||
func _on_sc_item_activate(index : int) -> void:
|
||||
if _script_list.item_count > index:
|
||||
index = _get_script_selected(index)
|
||||
if index > -1 and index < _editor_list.item_count:
|
||||
_editor_list.item_activated.emit(index)
|
||||
|
||||
func _on_property() -> void:
|
||||
_script_list.update()
|
||||
|
||||
func _on_sc_item_clicked(index: int, at_position: Vector2, mouse_button_index: int) -> void:
|
||||
if _script_list.item_count > index:
|
||||
index = _get_script_selected(index)
|
||||
if index == -1:
|
||||
return
|
||||
_editor_list.item_clicked.emit(index, at_position, mouse_button_index)
|
||||
_script_list.update()
|
||||
|
||||
func _get_script_selected(index : int) -> int:
|
||||
if _editor_list.item_count == _script_list.item_count:
|
||||
return index
|
||||
|
||||
var tp : String = _script_list.get_item_tooltip(index)
|
||||
var cindx : int = -1
|
||||
if !tp.is_empty():
|
||||
for x : int in _editor_list.item_count:
|
||||
if tp == _editor_list.get_item_tooltip(x):
|
||||
cindx = x
|
||||
break
|
||||
else:
|
||||
tp = _script_list.get_item_text(index)
|
||||
for x : int in _editor_list.item_count:
|
||||
if tp == _editor_list.get_item_text(x):
|
||||
cindx = x
|
||||
break
|
||||
|
||||
return cindx
|
||||
|
||||
#func set_handler(manager : Object) -> void:
|
||||
#_script_list.set_handler(manager)
|
||||
#
|
||||
func _init(list : ItemList) -> void:
|
||||
_editor_list = list
|
||||
_editor_list.item_selected.connect(_item_selected)
|
||||
_editor_list.property_list_changed.connect(_on_property)
|
||||
|
||||
var parent: Node = _editor_list.get_parent()
|
||||
_script_list = list.duplicate()
|
||||
_script_list.set_script(SplitterList)
|
||||
_script_list.set_reference(_update_list)
|
||||
_script_list.set_list(_editor_list)
|
||||
_script_list.item_selected.connect(_on_sc_item_selected)
|
||||
_script_list.item_activated.connect(_on_sc_item_activate)
|
||||
_script_list.item_clicked.connect(_on_sc_item_clicked)
|
||||
|
||||
if _script_list.has_signal(&"move_item_by_index"):
|
||||
_script_list.connect(&"move_item_by_index", _on_move_item_by_index)
|
||||
#_editor_list.draw.connect(_on_update_list)
|
||||
|
||||
_script_list.add_to_group(&"__SP_LT__")
|
||||
_array_list = [_editor_list, _script_list]
|
||||
|
||||
list.visible = false
|
||||
|
||||
var filesearch : Object = parent.get_child(0)
|
||||
if filesearch is LineEdit:
|
||||
_editor_filesearch = filesearch
|
||||
var txt : String = filesearch.text
|
||||
if !txt.is_empty():
|
||||
filesearch.set(&"text", "")
|
||||
|
||||
_script_filesearch = filesearch.duplicate()
|
||||
_script_filesearch.text_changed.connect(_on_update_list_search)
|
||||
|
||||
filesearch.visible = false
|
||||
|
||||
parent.add_child(_script_list)
|
||||
parent.move_child(_script_list, 0)
|
||||
parent.add_child(_script_filesearch)
|
||||
parent.move_child(_script_filesearch, 0)
|
||||
|
||||
_script_list.update()
|
||||
|
||||
func _on_update_list() -> void:
|
||||
if _update_list_queue:
|
||||
return
|
||||
|
||||
if !is_instance_valid(_script_list) or !is_instance_valid(_editor_list):
|
||||
return
|
||||
|
||||
_update_list_queue = true
|
||||
|
||||
var filtered : bool = false
|
||||
|
||||
if is_instance_valid(_script_filesearch):
|
||||
filtered = !_script_filesearch.text.is_empty()
|
||||
|
||||
|
||||
var item_list : ItemList = _editor_list
|
||||
|
||||
_script_list.clear()
|
||||
|
||||
if filtered:
|
||||
_on_update_list_search(_script_filesearch.text)
|
||||
else:
|
||||
for x : int in item_list.item_count:
|
||||
var indx : int = _script_list.item_count
|
||||
_script_list.add_item(item_list.get_item_text(x), item_list.get_item_icon(x), true)
|
||||
_script_list.set_item_metadata(indx, item_list.get_item_metadata(x))
|
||||
_script_list.set_item_tooltip(indx, item_list.get_item_tooltip(x))
|
||||
_script_list.set_item_icon_modulate(indx, item_list.get_item_icon_modulate(x))
|
||||
_script_list.set_item_custom_fg_color(indx, item_list.get_item_custom_fg_color(x))
|
||||
|
||||
update_list_selection()
|
||||
|
||||
set_deferred(&"_update_list_queue", false)
|
||||
|
||||
func _on_update_list_search(txt : String) -> void:
|
||||
if txt.is_empty():
|
||||
_on_update_list()
|
||||
return
|
||||
|
||||
if !is_instance_valid(_script_list):
|
||||
return
|
||||
|
||||
_script_list.clear()
|
||||
|
||||
var rgx : RegEx = RegEx.create_from_string("(?i).*{0}.*".format([txt]))
|
||||
|
||||
if !is_instance_valid(rgx) or !rgx.is_valid():
|
||||
return
|
||||
|
||||
var item_list : ItemList = _editor_list
|
||||
for x : int in item_list.item_count:
|
||||
var _txt : String = item_list.get_item_text(x)
|
||||
if rgx.search(_txt) != null:
|
||||
var indx : int = _script_list.add_item(item_list.get_item_text(x), item_list.get_item_icon(x), true)
|
||||
_script_list.set_item_metadata(indx, item_list.get_item_metadata(x))
|
||||
_script_list.set_item_tooltip(indx, item_list.get_item_tooltip(x))
|
||||
_script_list.set_item_icon_modulate(indx, item_list.get_item_icon_modulate(x))
|
||||
_script_list.set_item_custom_fg_color(indx, item_list.get_item_custom_fg_color(x))
|
||||
|
||||
update_list_selection()
|
||||
|
||||
func update_list_selection() -> void:
|
||||
if update_selections_callback.is_valid():
|
||||
update_selections_callback.call(_array_list)
|
||||
|
||||
func _item_selected(i : int) -> void:
|
||||
item_selected.emit(i)
|
||||
|
||||
func _update_list() -> void:
|
||||
updated.emit()
|
||||
_on_update_list()
|
||||
|
||||
func get_editor_list() -> ItemList:
|
||||
return _editor_list
|
||||
|
||||
func get_selected_id() -> int:
|
||||
for x : int in range(_editor_list.item_count):
|
||||
if _editor_list.is_selected(x):
|
||||
return x
|
||||
return -1
|
||||
|
||||
func remove(index : int) -> void:
|
||||
if _editor_list.item_count > index and index > -1:
|
||||
_editor_list.item_clicked.emit(index, _editor_list.get_local_mouse_position(), MOUSE_BUTTON_MIDDLE)
|
||||
|
||||
func item_count() -> int:
|
||||
return _editor_list.item_count
|
||||
|
||||
func _select() -> void:
|
||||
if _selet_queue > -1 and _editor_list.item_count > _selet_queue:
|
||||
_editor_list.select(_selet_queue, true)
|
||||
_editor_list.item_selected.emit(_selet_queue)
|
||||
_update_list.call_deferred()
|
||||
_selecting = false
|
||||
|
||||
func update_list() -> void:
|
||||
_on_update_list()
|
||||
|
||||
func select(i : int) -> void:
|
||||
if i > -1 and _editor_list.item_count > i:
|
||||
_selet_queue = i
|
||||
if _selecting:
|
||||
return
|
||||
_selecting = true
|
||||
_select.call_deferred()
|
||||
|
||||
func is_selected(i : int) -> bool:
|
||||
if _editor_list.item_count > i and i > -1:
|
||||
return _editor_list.is_selected(i)
|
||||
return false
|
||||
|
||||
func get_item_tooltip(item : int) -> String:
|
||||
if _editor_list.item_count > item and item > -1:
|
||||
return _editor_list.get_item_tooltip(item)
|
||||
return ""
|
||||
|
||||
func get_item_icon(item : int) -> Texture2D:
|
||||
if _editor_list.item_count > item and item > -1:
|
||||
return _editor_list.get_item_icon(item)
|
||||
return null
|
||||
|
||||
func get_item_icon_modulate(item : int) -> Color:
|
||||
if _editor_list.item_count > item and item > -1:
|
||||
return _editor_list.get_item_icon_modulate(item)
|
||||
return Color.WHITE
|
||||
|
||||
func get_item_text(item : int) -> String:
|
||||
if _editor_list.item_count > item and item > -1:
|
||||
return _editor_list.get_item_text(item)
|
||||
return ""
|
||||
|
||||
func reset() -> void:
|
||||
if is_instance_valid(_editor_list):
|
||||
_editor_list.visible = true
|
||||
if _editor_list.draw.is_connected(_on_update_list):
|
||||
_editor_list.draw.disconnect(_on_update_list)
|
||||
if _editor_list.item_selected.is_connected(_item_selected):
|
||||
_editor_list.item_selected.disconnect(_item_selected)
|
||||
if _editor_list.property_list_changed.is_connected(_on_property):
|
||||
_editor_list.property_list_changed.disconnect(_on_property)
|
||||
|
||||
if is_instance_valid(_editor_filesearch):
|
||||
_editor_filesearch.visible = true
|
||||
|
||||
if is_instance_valid(_script_filesearch):
|
||||
_script_filesearch.queue_free()
|
||||
|
||||
if is_instance_valid(_script_list):
|
||||
_script_list.queue_free()
|
||||
|
||||
func _on_move_item_by_index(from : int, to : int) -> void:
|
||||
if from == to:
|
||||
return
|
||||
|
||||
for x : ItemList in [_script_list, _editor_list]:
|
||||
if !is_instance_valid(x):
|
||||
return
|
||||
for y : int in [from, to]:
|
||||
if x.item_count <= y or y < 0:
|
||||
return
|
||||
|
||||
var values : Array[int] = [from, to]
|
||||
|
||||
for v : int in range(0, values.size(), 1):
|
||||
if _script_list.get_item_tooltip(v) != _editor_list.get_item_tooltip(v):
|
||||
var value = -1
|
||||
var st : String = _script_list.get_item_tooltip(from)
|
||||
|
||||
for x : int in _editor_list.item_count:
|
||||
if st == _editor_list.get_item_tooltip(x):
|
||||
value = x
|
||||
break
|
||||
|
||||
if value == -1:
|
||||
return
|
||||
|
||||
values[v] = value
|
||||
|
||||
move_item.emit(values[0], values[1])
|
||||
1
addons/script_splitter/core/base/list.gd.uid
Normal file
1
addons/script_splitter/core/base/list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ors5ojuayup4
|
||||
Loading…
Add table
Add a link
Reference in a new issue