Initial commit
This commit is contained in:
8
scripts/types/misc/action_reference.gd
Normal file
8
scripts/types/misc/action_reference.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
extends Node
|
||||
|
||||
class_name UIB_ActionReference
|
||||
|
||||
export(NodePath) var action
|
||||
|
||||
func get_action() -> UIB_Action:
|
||||
return get_node_or_null(action) as UIB_Action
|
||||
25
scripts/types/misc/constraints/dynamic_grid_constraints.gd
Normal file
25
scripts/types/misc/constraints/dynamic_grid_constraints.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
tool
|
||||
extends Node
|
||||
|
||||
class_name UIB_DynamicGridConstraints
|
||||
|
||||
export(int, 1, 100) var colspan := 1 setget _set_colspan
|
||||
export(int, 1, 100) var rowspan := 1 setget _set_rowspan
|
||||
|
||||
func _ready():
|
||||
__trigger_update()
|
||||
|
||||
func __trigger_update():
|
||||
var container := get_node_or_null("../..") as Container # cyclic inclusion, cannot use UIB_DynamicGridContainer
|
||||
if container != null:
|
||||
container.notification(Container.NOTIFICATION_SORT_CHILDREN)
|
||||
|
||||
func _set_colspan(value : int):
|
||||
if value != colspan:
|
||||
colspan = value
|
||||
__trigger_update()
|
||||
|
||||
func _set_rowspan(value : int):
|
||||
if value != rowspan:
|
||||
rowspan = value
|
||||
__trigger_update()
|
||||
50
scripts/types/misc/file_adapter.gd
Normal file
50
scripts/types/misc/file_adapter.gd
Normal file
@@ -0,0 +1,50 @@
|
||||
extends Reference
|
||||
|
||||
class_name UIB_FileAdapter
|
||||
|
||||
class FileEntry:
|
||||
func _is_folder() -> bool:
|
||||
return false
|
||||
|
||||
func _is_link() -> bool:
|
||||
return false
|
||||
|
||||
func _list_files() -> Array:
|
||||
return []
|
||||
|
||||
func _get_name() -> String:
|
||||
return ""
|
||||
|
||||
func _get_size() -> int:
|
||||
return 0
|
||||
|
||||
func _get_modified_time() -> int:
|
||||
return 0
|
||||
|
||||
func _get_parent() -> FileEntry:
|
||||
return null
|
||||
|
||||
func _get_path() -> String:
|
||||
var parent := _get_parent()
|
||||
if parent:
|
||||
return parent._get_path().plus_file(_get_name())
|
||||
var name := _get_name()
|
||||
if name == "":
|
||||
return "/"
|
||||
return name
|
||||
|
||||
func _get_root() -> FileEntry:
|
||||
return null
|
||||
|
||||
func _get_file(path : String) -> FileEntry:
|
||||
return null
|
||||
|
||||
func _get_icon(entry) -> Texture:
|
||||
if entry._is_folder():
|
||||
return preload("res://addons/de.mewin.gduibasics/images/folder.svg")
|
||||
else:
|
||||
|
||||
return preload("res://addons/de.mewin.gduibasics/images/file.svg")
|
||||
|
||||
func _get_drives() -> Array:
|
||||
return [""]
|
||||
20
scripts/types/misc/file_extension_filter.gd
Normal file
20
scripts/types/misc/file_extension_filter.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends UIB_FileFilter
|
||||
|
||||
class_name UIB_FileExtensionFilter
|
||||
|
||||
var __extensions : PoolStringArray
|
||||
|
||||
func _init(extensions_ : Array):
|
||||
for ext in extensions_:
|
||||
if !ext.begins_with("."):
|
||||
ext = "." + ext
|
||||
__extensions.append(ext)
|
||||
|
||||
func _accepts(entry) -> bool:
|
||||
for ext in __extensions:
|
||||
if entry._get_name().ends_with(ext):
|
||||
return true
|
||||
return false
|
||||
|
||||
func _get_default_name() -> String:
|
||||
return tr("%s-Files") % __extensions.join(", ")
|
||||
16
scripts/types/misc/file_filter.gd
Normal file
16
scripts/types/misc/file_filter.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
extends Reference
|
||||
|
||||
class_name UIB_FileFilter
|
||||
|
||||
var name := ""
|
||||
|
||||
func _accepts(entry) -> bool:
|
||||
return true
|
||||
|
||||
func _get_name() -> String:
|
||||
if name:
|
||||
return name
|
||||
return _get_default_name()
|
||||
|
||||
func _get_default_name() -> String:
|
||||
return ""
|
||||
110
scripts/types/misc/local_file_adapter.gd
Normal file
110
scripts/types/misc/local_file_adapter.gd
Normal file
@@ -0,0 +1,110 @@
|
||||
extends UIB_FileAdapter
|
||||
|
||||
class_name UIB_LocalFileAdapter
|
||||
|
||||
var __dir = Directory.new()
|
||||
|
||||
class LocalFileEntry:
|
||||
extends UIB_FileAdapter.FileEntry
|
||||
|
||||
var path : String
|
||||
var is_link : bool
|
||||
var is_folder : bool
|
||||
var size := -1
|
||||
var modified_time := -1
|
||||
|
||||
func _init(path_ : String, is_link_ : bool, is_folder_ : bool):
|
||||
path = path_
|
||||
is_link = is_link_
|
||||
is_folder = is_folder_
|
||||
if path.ends_with("/") && path != "/":
|
||||
path = path.left(path.length() - 1)
|
||||
|
||||
func _is_folder() -> bool:
|
||||
return is_folder
|
||||
|
||||
func _is_link() -> bool:
|
||||
return is_link
|
||||
|
||||
func _list_files() -> Array:
|
||||
if !is_folder:
|
||||
return []
|
||||
var dir := Directory.new()
|
||||
if dir.open(path + "/") != OK:
|
||||
return []
|
||||
if dir.list_dir_begin(true) != OK:
|
||||
return []
|
||||
var fname := dir.get_next()
|
||||
var files := []
|
||||
while fname:
|
||||
var fpath := path.plus_file(fname)
|
||||
var ffolder := dir.current_is_dir()
|
||||
var flink := false
|
||||
|
||||
files.append(LocalFileEntry.new(fpath, flink, ffolder))
|
||||
|
||||
fname = dir.get_next()
|
||||
return files
|
||||
|
||||
func _get_name() -> String:
|
||||
return path.get_file()
|
||||
|
||||
func _get_size() -> int:
|
||||
if size == -1:
|
||||
size = __calc_size()
|
||||
return size
|
||||
|
||||
func _get_modified_time() -> int:
|
||||
if modified_time == -1:
|
||||
modified_time = __calc_modified_time()
|
||||
return modified_time
|
||||
|
||||
func _get_parent() -> UIB_FileAdapter.FileEntry:
|
||||
var parent_path := path.get_base_dir()
|
||||
if parent_path && parent_path != path:
|
||||
return LocalFileEntry.new(parent_path, false, true)
|
||||
return null
|
||||
|
||||
func __calc_size() -> int:
|
||||
if is_folder:
|
||||
return 0
|
||||
var file := File.new()
|
||||
if file.open(path, File.READ) != OK:
|
||||
return 0
|
||||
return file.get_len()
|
||||
|
||||
func __calc_modified_time() -> int:
|
||||
if is_folder:
|
||||
return 0
|
||||
var file := File.new()
|
||||
return file.get_modified_time(path)
|
||||
|
||||
func _get_file(path : String) -> FileEntry:
|
||||
if OS.has_feature("Windows"): # has "feature"
|
||||
path = path.replace("\\", "/")
|
||||
if path.length() < 2 || path[1] != ":":
|
||||
path = "c:/" + path.lstrip("/")
|
||||
if path.length() == 2: #
|
||||
path += "/"
|
||||
elif !path.begins_with("/"):
|
||||
path = "/" + path # only drive letter, dir_exists() wouldnt work
|
||||
|
||||
var dir := Directory.new()
|
||||
if dir.dir_exists(path):
|
||||
return LocalFileEntry.new(path, false, true)
|
||||
elif dir.file_exists(path):
|
||||
return LocalFileEntry.new(path, false, false)
|
||||
else:
|
||||
return null
|
||||
|
||||
func _get_root() -> UIB_FileAdapter.FileEntry:
|
||||
return _get_file("/")
|
||||
|
||||
func _get_drives() -> Array:
|
||||
var dir := Directory.new()
|
||||
var drives := []
|
||||
|
||||
for i in range(dir.get_drive_count()):
|
||||
drives.append(dir.get_drive(i))
|
||||
|
||||
return drives
|
||||
5
scripts/types/misc/seperator.gd
Normal file
5
scripts/types/misc/seperator.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Node
|
||||
|
||||
class_name UIB_Seperator
|
||||
|
||||
export(String) var text := ""
|
||||
102
scripts/types/misc/simple_action.gd
Normal file
102
scripts/types/misc/simple_action.gd
Normal file
@@ -0,0 +1,102 @@
|
||||
extends UIB_Action
|
||||
|
||||
class_name UIB_SimpleAction
|
||||
|
||||
export var text := "" setget _set_text
|
||||
export(Texture) var icon setget _set_icon
|
||||
export(Texture) var untoggled_icon setget _set_untoggled_icon
|
||||
export(String) var shortcut_action setget _set_shortcut_action
|
||||
export var disabled := false setget _set_disabled
|
||||
export var toggleable := false setget _set_toggleable
|
||||
export var toggled := false setget _set_toggled
|
||||
|
||||
#############
|
||||
# overrides #
|
||||
#############
|
||||
func _get_text() -> String:
|
||||
return text
|
||||
|
||||
func _get_icon() -> Texture:
|
||||
if untoggled_icon && !toggled:
|
||||
return untoggled_icon
|
||||
return icon
|
||||
|
||||
func _get_shortcut() -> ShortCut:
|
||||
if shortcut_action:
|
||||
var action_list = InputMap.get_action_list(shortcut_action)
|
||||
if !action_list:
|
||||
return null
|
||||
var shortcut := ShortCut.new()
|
||||
shortcut.shortcut = action_list[0]
|
||||
return shortcut
|
||||
return null
|
||||
|
||||
func _is_disabled() -> bool:
|
||||
return disabled
|
||||
|
||||
func _is_toggleable() -> bool:
|
||||
return toggleable
|
||||
|
||||
func _is_toggled() -> bool:
|
||||
return toggled
|
||||
|
||||
func _toggle(value : bool):
|
||||
if toggleable:
|
||||
_set_toggled(value)
|
||||
|
||||
func _apply():
|
||||
emit_signal("applied")
|
||||
|
||||
func _update():
|
||||
emit_signal("update", self)
|
||||
|
||||
###########
|
||||
# setters #
|
||||
###########
|
||||
func _set_text(value : String):
|
||||
if value != text:
|
||||
text = value
|
||||
emit_signal("text_changed")
|
||||
|
||||
func _set_icon(value : Texture):
|
||||
if value != icon:
|
||||
icon = value
|
||||
emit_signal("icon_changed")
|
||||
|
||||
func _set_untoggled_icon(value : Texture):
|
||||
if value != untoggled_icon:
|
||||
untoggled_icon = value
|
||||
emit_signal("icon_changed")
|
||||
|
||||
func _set_shortcut_action(value : String):
|
||||
if value != shortcut_action:
|
||||
shortcut_action = value
|
||||
emit_signal("shortcut_changed")
|
||||
|
||||
func _set_disabled(value : bool):
|
||||
if value != disabled:
|
||||
disabled = value
|
||||
emit_signal("disabled_changed")
|
||||
|
||||
func _set_toggled(value : bool):
|
||||
if value != toggled:
|
||||
toggled = value
|
||||
emit_signal("toggled_changed")
|
||||
if toggled:
|
||||
_set_toggleable(true)
|
||||
if untoggled_icon:
|
||||
emit_signal("icon_changed")
|
||||
|
||||
func _set_toggleable(value : bool):
|
||||
if value != toggleable:
|
||||
toggleable = value
|
||||
emit_signal("toggleable_changed")
|
||||
if !toggleable:
|
||||
_set_toggled(false)
|
||||
|
||||
###########
|
||||
# signals #
|
||||
###########
|
||||
signal applied()
|
||||
signal update(action)
|
||||
signal toggleable_changed()
|
||||
71
scripts/types/misc/ui_action.gd
Normal file
71
scripts/types/misc/ui_action.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
extends Node
|
||||
|
||||
class_name UIB_Action, "res://addons/de.mewin.gduibasics/images/action.svg"
|
||||
|
||||
export var continuous_update = false setget _set_continuous_update
|
||||
|
||||
#############
|
||||
# overrides #
|
||||
#############
|
||||
func _ready():
|
||||
set_process(continuous_update)
|
||||
|
||||
func _process(delta):
|
||||
_update()
|
||||
|
||||
func _unhandled_input(event : InputEvent):
|
||||
if self._is_disabled() || !event.is_pressed():
|
||||
return
|
||||
|
||||
var shortcut := self._get_shortcut()
|
||||
if !shortcut || !shortcut.is_shortcut(event):
|
||||
return
|
||||
|
||||
self._apply()
|
||||
|
||||
################
|
||||
# overridables #
|
||||
################
|
||||
func _get_text() -> String:
|
||||
return ""
|
||||
|
||||
func _get_icon() -> Texture:
|
||||
return null
|
||||
|
||||
func _get_shortcut() -> ShortCut:
|
||||
return null
|
||||
|
||||
func _is_disabled() -> bool:
|
||||
return false
|
||||
|
||||
func _is_toggleable() -> bool:
|
||||
return false
|
||||
|
||||
func _is_toggled() -> bool:
|
||||
return false
|
||||
|
||||
func _toggle(value : bool):
|
||||
pass
|
||||
|
||||
func _apply():
|
||||
_toggle(!_is_toggled())
|
||||
|
||||
func _update():
|
||||
pass
|
||||
|
||||
###########
|
||||
# setters #
|
||||
###########
|
||||
func _set_continuous_update(value):
|
||||
if value != continuous_update:
|
||||
continuous_update = value
|
||||
set_process(continuous_update)
|
||||
|
||||
###########
|
||||
# signals #
|
||||
###########
|
||||
signal text_changed()
|
||||
signal icon_changed()
|
||||
signal shortcut_changed()
|
||||
signal disabled_changed()
|
||||
signal toggled_changed()
|
||||
Reference in New Issue
Block a user