From 75a65fa81c313e8bf506e0bf4b434516563380b9 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 3 Sep 2019 12:54:19 -0500 Subject: [PATCH] Enhance `Tree` presentation and add main script to sample game. --- addons/accessibility/accessible.gd | 27 +++++++++++++++++++++++---- main.gd | 13 +++++++++++++ main.tscn | 9 ++++++--- 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 main.gd diff --git a/addons/accessibility/accessible.gd b/addons/accessibility/accessible.gd index ef2fec6..c729722 100644 --- a/addons/accessibility/accessible.gd +++ b/addons/accessibility/accessible.gd @@ -133,7 +133,16 @@ func focus_popup_menu_item(id): func render_tree_item(): var item = node.get_selected() - var result = item.get_text(0) + var result = "" + for i in range(node.columns): + result += item.get_text(i) + ": " + if item.collapsed: + result += "collapsed " + else: + result += "expanded " + result += "tree item" + if item.is_selected(0): + result += ": selected" return result func focus_tab_container(): @@ -163,7 +172,14 @@ func focus_tree(): else: tts.speak("tree", true) -func select_tree(): +func collapse_tree_item(item): + if node.has_focus(): + tts.speak("collapsed", true) + +func input_tree(event): + pass + +func select_tree_item(): if node.has_focus(): tts.speak(render_tree_item(), true) @@ -200,10 +216,12 @@ func unfocused(): func gui_input(event): if node is TabContainer: return input_tab_container(event) - if node is ItemList: + elif node is ItemList: return input_item_list(event) elif node is LineEdit: return check_caret_moved() + elif node is Tree: + return input_tree(event) func _init(tts, node): if node.is_in_group("accessible"): @@ -230,5 +248,6 @@ func _init(tts, node): elif node is PopupMenu: node.connect("id_focused", self, "focus_popup_menu_item") elif node is Tree: - node.connect("item_selected", self, "select_tree") + node.connect("item_collapsed", self, "collapse_tree_item") + node.connect("item_selected", self, "select_tree_item") node.connect("tree_exiting", self, "free") diff --git a/main.gd b/main.gd new file mode 100644 index 0000000..03b9fc6 --- /dev/null +++ b/main.gd @@ -0,0 +1,13 @@ +extends Node + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/main.tscn b/main.tscn index d2315ed..8fd87ac 100644 --- a/main.tscn +++ b/main.tscn @@ -1,7 +1,10 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://player.tscn" type="PackedScene" id=1] +[ext_resource path="res://main.gd" type="Script" id=1] +[ext_resource path="res://player.tscn" type="PackedScene" id=2] [node name="Main" type="Node"] +editor/display_folded = true +script = ExtResource( 1 ) -[node name="Player" parent="." instance=ExtResource( 1 )] +[node name="Player" parent="." instance=ExtResource( 2 )]