2018-05-28 16:48:02 +00:00
|
|
|
extends Object
|
|
|
|
|
|
|
|
var node
|
|
|
|
|
2018-07-19 20:12:01 +00:00
|
|
|
var position_in_children = 0
|
|
|
|
|
2018-06-10 21:14:43 +00:00
|
|
|
func item_or_items(count):
|
|
|
|
if count == 1:
|
|
|
|
return "item"
|
|
|
|
else:
|
|
|
|
return "items"
|
|
|
|
|
2018-07-03 17:01:00 +00:00
|
|
|
func focus_button():
|
2018-06-10 20:32:27 +00:00
|
|
|
var text = "Unlabelled"
|
|
|
|
if node.text:
|
|
|
|
text = node.text
|
2018-07-19 15:15:49 +00:00
|
|
|
if text:
|
|
|
|
print("%s: button" % text)
|
|
|
|
else:
|
|
|
|
print("button")
|
2018-06-10 20:32:27 +00:00
|
|
|
|
2018-07-03 17:01:00 +00:00
|
|
|
func focus_item_list():
|
|
|
|
var count = node.get_item_count()
|
|
|
|
var selected = node.get_selected_items()
|
|
|
|
print("list, %s %s" % [count, item_or_items(count)])
|
|
|
|
print(selected)
|
|
|
|
|
|
|
|
|
|
|
|
func handle_item_list_item_selected(index):
|
|
|
|
print("Selected")
|
|
|
|
|
|
|
|
func handle_item_list_multi_selected(index, selected):
|
|
|
|
print("Multiselect")
|
|
|
|
|
|
|
|
func handle_item_list_nothing_selected():
|
|
|
|
print("Nothing selected")
|
|
|
|
|
2018-07-03 16:39:43 +00:00
|
|
|
func input_item_list(event):
|
2018-07-19 20:12:01 +00:00
|
|
|
var old_pos = position_in_children
|
2018-07-03 16:39:43 +00:00
|
|
|
if event.echo or not event.pressed:
|
|
|
|
return
|
|
|
|
if event.scancode == KEY_UP:
|
2018-07-19 15:24:42 +00:00
|
|
|
node.get_tree().set_input_as_handled()
|
2018-07-19 20:12:01 +00:00
|
|
|
if position_in_children == 0:
|
2018-07-03 16:39:43 +00:00
|
|
|
return
|
2018-07-19 20:12:01 +00:00
|
|
|
position_in_children -= 1
|
2018-07-03 16:39:43 +00:00
|
|
|
elif event.scancode == KEY_DOWN:
|
2018-07-19 15:24:42 +00:00
|
|
|
node.get_tree().set_input_as_handled()
|
2018-07-19 20:12:01 +00:00
|
|
|
if position_in_children >= node.get_item_count()-1:
|
2018-07-03 16:39:43 +00:00
|
|
|
return
|
2018-07-19 20:12:01 +00:00
|
|
|
position_in_children += 1
|
2018-07-03 16:39:43 +00:00
|
|
|
elif event.scancode == KEY_HOME:
|
2018-07-19 20:12:01 +00:00
|
|
|
position_in_children = 0
|
2018-07-03 16:39:43 +00:00
|
|
|
elif event.scancode == KEY_END:
|
2018-07-19 20:12:01 +00:00
|
|
|
position_in_children = node.get_item_count()-1
|
|
|
|
if old_pos != position_in_children:
|
|
|
|
var text = node.get_item_text(position_in_children)
|
|
|
|
print("%s: %s of %s" % [text, position_in_children+1, node.get_item_count()])
|
2018-06-10 21:14:43 +00:00
|
|
|
|
2018-07-19 20:20:48 +00:00
|
|
|
func focus_label():
|
|
|
|
print(node.text)
|
|
|
|
|
2018-07-03 17:01:00 +00:00
|
|
|
func focus_line_edit():
|
2018-06-10 20:32:27 +00:00
|
|
|
var text = "blank"
|
|
|
|
if node.secret:
|
|
|
|
text = "password"
|
|
|
|
elif node.text != "":
|
|
|
|
text = node.text
|
|
|
|
elif node.placeholder_text != "":
|
|
|
|
text = node.placeholder_text
|
|
|
|
var type = "editable text"
|
|
|
|
if not node.editable:
|
|
|
|
type = "text"
|
|
|
|
print("%s: %s" % [text, type])
|
|
|
|
|
2018-07-03 15:45:31 +00:00
|
|
|
func text_deleted(text):
|
|
|
|
print("%s deleted" % text)
|
|
|
|
|
|
|
|
func text_inserted(text):
|
|
|
|
print(text)
|
|
|
|
|
2018-06-18 20:33:03 +00:00
|
|
|
var old_pos
|
|
|
|
|
|
|
|
func check_caret_moved():
|
2018-06-12 12:32:09 +00:00
|
|
|
var pos = node.caret_position
|
2018-06-18 20:33:03 +00:00
|
|
|
if old_pos != pos:
|
|
|
|
var text = node.text
|
|
|
|
if pos > len(text)-1:
|
|
|
|
print("blank")
|
|
|
|
else:
|
|
|
|
print(text[pos])
|
|
|
|
old_pos = pos
|
2018-06-12 12:32:09 +00:00
|
|
|
|
2018-07-19 20:12:01 +00:00
|
|
|
func focus_menu_button():
|
|
|
|
print(node.text, ": menu")
|
|
|
|
|
|
|
|
func render_popup_menu_item(id):
|
|
|
|
var item = node.get_item_text(id)
|
|
|
|
var submenu = node.get_item_submenu(position_in_children)
|
|
|
|
var tooltip = node.get_item_tooltip(position_in_children)
|
|
|
|
if submenu:
|
|
|
|
item = submenu
|
|
|
|
if item and tooltip:
|
|
|
|
item += ": "
|
|
|
|
item += tooltip
|
|
|
|
elif tooltip:
|
|
|
|
item = tooltip
|
|
|
|
var shortcut = node.get_item_shortcut(position_in_children)
|
|
|
|
if shortcut:
|
|
|
|
item += ": "+shortcut.get_as_text()
|
|
|
|
return item
|
|
|
|
|
|
|
|
func focus_popup_menu():
|
|
|
|
print("menu")
|
|
|
|
|
|
|
|
func focus_popup_menu_item(id):
|
|
|
|
print(render_popup_menu_item(id))
|
|
|
|
|
|
|
|
func render_tree_item():
|
2018-07-19 17:02:40 +00:00
|
|
|
var item = node.get_selected()
|
|
|
|
var result = item.get_text(0)
|
|
|
|
return result
|
|
|
|
|
2018-07-03 17:01:00 +00:00
|
|
|
func focus_tree():
|
2018-07-19 20:20:48 +00:00
|
|
|
if node.get_selected():
|
|
|
|
print(render_tree_item(), ": tree item")
|
|
|
|
else:
|
|
|
|
print("tree")
|
2018-07-19 17:02:40 +00:00
|
|
|
|
|
|
|
func select_tree():
|
|
|
|
if node.has_focus():
|
2018-07-19 20:12:01 +00:00
|
|
|
print(render_tree_item())
|
2018-06-10 21:02:45 +00:00
|
|
|
|
2018-05-28 21:45:13 +00:00
|
|
|
func focused():
|
2018-07-19 20:12:01 +00:00
|
|
|
# print(node)
|
|
|
|
if node is MenuButton:
|
|
|
|
focus_menu_button()
|
|
|
|
elif node is Button:
|
2018-07-03 17:01:00 +00:00
|
|
|
focus_button()
|
2018-06-10 21:14:43 +00:00
|
|
|
elif node is ItemList:
|
2018-07-03 17:01:00 +00:00
|
|
|
focus_item_list()
|
2018-07-19 20:20:48 +00:00
|
|
|
elif node is Label:
|
|
|
|
focus_label()
|
2018-06-10 20:32:27 +00:00
|
|
|
elif node is LineEdit:
|
2018-07-03 17:01:00 +00:00
|
|
|
focus_line_edit()
|
2018-07-19 20:12:01 +00:00
|
|
|
elif node is PopupMenu:
|
|
|
|
focus_popup_menu()
|
2018-06-10 21:02:45 +00:00
|
|
|
elif node is Tree:
|
2018-07-03 17:01:00 +00:00
|
|
|
focus_tree()
|
2018-06-10 20:18:00 +00:00
|
|
|
else:
|
2018-07-03 16:42:00 +00:00
|
|
|
print("Focus entered.", node)
|
2018-07-19 15:15:49 +00:00
|
|
|
if node.hint_tooltip:
|
|
|
|
print(node.hint_tooltip)
|
2018-05-28 16:48:02 +00:00
|
|
|
|
2018-05-28 21:45:13 +00:00
|
|
|
func unfocused():
|
2018-07-19 20:12:01 +00:00
|
|
|
position_in_children = 0
|
2018-05-28 21:09:29 +00:00
|
|
|
|
2018-06-10 19:42:58 +00:00
|
|
|
func gui_input(event):
|
2018-07-03 16:39:43 +00:00
|
|
|
if node is ItemList:
|
|
|
|
return input_item_list(event)
|
2018-07-19 20:12:01 +00:00
|
|
|
elif node is LineEdit:
|
2018-07-03 16:39:43 +00:00
|
|
|
return check_caret_moved()
|
2018-05-28 16:48:02 +00:00
|
|
|
|
|
|
|
func _init(node):
|
2018-06-07 21:18:36 +00:00
|
|
|
if node.is_in_group("accessible"):
|
|
|
|
return
|
|
|
|
node.add_to_group("accessible")
|
2018-05-28 16:48:02 +00:00
|
|
|
self.node = node
|
2018-07-19 18:30:38 +00:00
|
|
|
if not node is Container and not node is Panel and not node is Separator:
|
|
|
|
node.set_focus_mode(Control.FOCUS_ALL)
|
2018-07-03 16:42:00 +00:00
|
|
|
node.connect("focus_entered", self, "focused")
|
|
|
|
node.connect("mouse_entered", self, "focused")
|
|
|
|
node.connect("focus_exited", self, "unfocused")
|
|
|
|
node.connect("mouse_exited", self, "unfocused")
|
|
|
|
node.connect("gui_input", self, "gui_input")
|
2018-07-03 16:39:43 +00:00
|
|
|
if node is ItemList:
|
|
|
|
node.connect("item_selected", self, "handle_item_list_item_selected")
|
|
|
|
node.connect("multi_selected", self, "handle_item_list_multi_selected")
|
|
|
|
node.connect("nothing_selected", self, "handle_item_list_nothing_selected")
|
|
|
|
|
2018-07-03 16:42:00 +00:00
|
|
|
elif node is LineEdit:
|
|
|
|
node.connect("text_deleted", self, "text_deleted")
|
|
|
|
node.connect("text_inserted", self, "text_inserted")
|
2018-07-19 20:12:01 +00:00
|
|
|
elif node is PopupMenu:
|
|
|
|
node.connect("id_focused", self, "focus_popup_menu_item")
|
2018-07-19 17:02:40 +00:00
|
|
|
elif node is Tree:
|
|
|
|
node.connect("item_selected", self, "select_tree")
|
2018-07-03 16:42:00 +00:00
|
|
|
node.connect("tree_exiting", self, "free")
|