summaryrefslogtreecommitdiff
path: root/demos/misc
diff options
context:
space:
mode:
Diffstat (limited to 'demos/misc')
-rw-r--r--demos/misc/autoload/global.gd38
-rw-r--r--demos/misc/regex/engine.cfg4
-rw-r--r--demos/misc/regex/regex.gd22
-rw-r--r--demos/misc/regex/regex.scnbin0 -> 1772 bytes
-rw-r--r--demos/misc/scene_changer/engine.cfg4
-rw-r--r--demos/misc/scene_changer/scene_a.gd17
-rw-r--r--demos/misc/scene_changer/scene_a.scnbin0 -> 1459 bytes
-rw-r--r--demos/misc/scene_changer/scene_b.gd17
-rw-r--r--demos/misc/scene_changer/scene_b.scnbin0 -> 1448 bytes
-rw-r--r--demos/misc/window_management/control.gd10
-rw-r--r--demos/misc/window_management/engine.cfg2
-rw-r--r--demos/misc/window_management/window_management.scnbin5129 -> 5132 bytes
12 files changed, 103 insertions, 11 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd
index a0415c6ee0..d1bd45461f 100644
--- a/demos/misc/autoload/global.gd
+++ b/demos/misc/autoload/global.gd
@@ -4,20 +4,40 @@ extends Node
var current_scene = null
-func goto_scene(scene):
- #load new scene
- var s = ResourceLoader.load(scene)
- #queue erasing old (don't use free because that scene is calling this method)
- current_scene.queue_free()
- #instance the new scene
+func goto_scene(path):
+
+ # This function will usually be called from a signal callback,
+ # or some other function from the running scene.
+ # Deleting the current scene at this point might be
+ # a bad idea, because it may be inside of a callback or function of it.
+ # The worst case will be a crash or unexpected behavior.
+
+ # The way around this is deferring the load to a later time, when
+ # it is ensured that no code from the current scene is running:
+
+ call_deferred("_deferred_goto_scene",path)
+
+
+func _deferred_goto_scene(path):
+
+ # Immediately free the current scene,
+ # there is no risk here.
+ current_scene.free()
+
+ # Load new scene
+ var s = ResourceLoader.load(path)
+
+ # Instance the new scene
current_scene = s.instance()
- #add it to the active scene, as child of root
+
+ # Add it to the active scene, as child of root
get_tree().get_root().add_child(current_scene)
func _ready():
- # get the current scene
+ # Get the current scene, the first time.
# it is always the last child of root,
- # after the autoloaded nodes
+ # after the autoloaded nodes.
+
var root = get_tree().get_root()
current_scene = root.get_child( root.get_child_count() -1 )
diff --git a/demos/misc/regex/engine.cfg b/demos/misc/regex/engine.cfg
new file mode 100644
index 0000000000..0a6f4f869c
--- /dev/null
+++ b/demos/misc/regex/engine.cfg
@@ -0,0 +1,4 @@
+[application]
+
+name="RegEx"
+main_scene="res://regex.scn"
diff --git a/demos/misc/regex/regex.gd b/demos/misc/regex/regex.gd
new file mode 100644
index 0000000000..e648c18093
--- /dev/null
+++ b/demos/misc/regex/regex.gd
@@ -0,0 +1,22 @@
+extends VBoxContainer
+
+var regex = RegEx.new()
+
+func update_expression():
+ regex.compile(get_node("Expression").get_text())
+ update_text()
+
+func update_text():
+ var text = get_node("Text").get_text()
+ regex.find(text)
+ var list = get_node("List")
+ for child in list.get_children():
+ child.queue_free()
+ for res in regex.get_captures():
+ var label = Label.new()
+ label.set_text(res)
+ list.add_child(label)
+
+func _ready():
+ get_node("Text").set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
+ update_expression()
diff --git a/demos/misc/regex/regex.scn b/demos/misc/regex/regex.scn
new file mode 100644
index 0000000000..2b62d6b82a
--- /dev/null
+++ b/demos/misc/regex/regex.scn
Binary files differ
diff --git a/demos/misc/scene_changer/engine.cfg b/demos/misc/scene_changer/engine.cfg
new file mode 100644
index 0000000000..1ba1a41167
--- /dev/null
+++ b/demos/misc/scene_changer/engine.cfg
@@ -0,0 +1,4 @@
+[application]
+
+name="Scene Changer"
+main_scene="res://scene_a.scn"
diff --git a/demos/misc/scene_changer/scene_a.gd b/demos/misc/scene_changer/scene_a.gd
new file mode 100644
index 0000000000..956878b0f7
--- /dev/null
+++ b/demos/misc/scene_changer/scene_a.gd
@@ -0,0 +1,17 @@
+
+extends Panel
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+func _ready():
+ # Initalization here
+ pass
+
+
+
+
+func _on_goto_scene_pressed():
+ get_tree().change_scene("res://scene_b.scn")
+ pass # replace with function body
diff --git a/demos/misc/scene_changer/scene_a.scn b/demos/misc/scene_changer/scene_a.scn
new file mode 100644
index 0000000000..61727a57ba
--- /dev/null
+++ b/demos/misc/scene_changer/scene_a.scn
Binary files differ
diff --git a/demos/misc/scene_changer/scene_b.gd b/demos/misc/scene_changer/scene_b.gd
new file mode 100644
index 0000000000..4f94d6bb8f
--- /dev/null
+++ b/demos/misc/scene_changer/scene_b.gd
@@ -0,0 +1,17 @@
+
+extends Panel
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+func _ready():
+ # Initalization here
+ pass
+
+
+
+
+func _on_goto_scene_pressed():
+ get_tree().change_scene("res://scene_a.scn")
+ pass # replace with function body
diff --git a/demos/misc/scene_changer/scene_b.scn b/demos/misc/scene_changer/scene_b.scn
new file mode 100644
index 0000000000..ae09eeff88
--- /dev/null
+++ b/demos/misc/scene_changer/scene_b.scn
Binary files differ
diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd
index 5eb5817619..1609dda699 100644
--- a/demos/misc/window_management/control.gd
+++ b/demos/misc/window_management/control.gd
@@ -1,6 +1,8 @@
extends Control
+var mousepos
+
func _fixed_process(delta):
var modetext = "Mode:\n"
@@ -31,7 +33,7 @@ func _fixed_process(delta):
get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) )
- get_node("Label_MousePosition").set_text(str("Mouse Position:\n", Input.get_mouse_pos() ) )
+ get_node("Label_MousePosition").set_text(str("Mouse Position:\n", mousepos ) )
get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) )
@@ -126,6 +128,12 @@ func check_wm_api():
func _ready():
if( check_wm_api() ):
set_fixed_process(true)
+ set_process_input(true)
+
+
+func _input(ev):
+ if (ev.type==InputEvent.MOUSE_MOTION):
+ mousepos = ev.pos
func _on_Button_MoveTo_pressed():
diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg
index c53bd45fb7..0a34231673 100644
--- a/demos/misc/window_management/engine.cfg
+++ b/demos/misc/window_management/engine.cfg
@@ -1,6 +1,6 @@
[application]
-name="window_management"
+name="Window Management"
main_scene="res://window_management.scn"
icon="icon.png"
diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn
index c7d6260df6..8db43b6638 100644
--- a/demos/misc/window_management/window_management.scn
+++ b/demos/misc/window_management/window_management.scn
Binary files differ