summaryrefslogtreecommitdiff
path: root/demos/gui
diff options
context:
space:
mode:
Diffstat (limited to 'demos/gui')
-rw-r--r--demos/gui/input_mapping/controls.gd49
-rw-r--r--demos/gui/input_mapping/controls.scnbin0 -> 2686 bytes
-rw-r--r--demos/gui/input_mapping/engine.cfg18
-rw-r--r--demos/gui/translation/controls.gd20
-rw-r--r--demos/gui/translation/controls.scnbin0 -> 2349 bytes
-rw-r--r--demos/gui/translation/engine.cfg9
-rw-r--r--demos/gui/translation/flag_japan.pngbin0 -> 1473 bytes
-rw-r--r--demos/gui/translation/flag_spain.pngbin0 -> 3048 bytes
-rw-r--r--demos/gui/translation/flag_uk.pngbin0 -> 6544 bytes
-rw-r--r--demos/gui/translation/main.gd42
-rw-r--r--demos/gui/translation/main.scnbin0 -> 2671 bytes
-rw-r--r--demos/gui/translation/noto.fntbin0 -> 9171 bytes
-rw-r--r--demos/gui/translation/notosans.otfbin0 -> 16426032 bytes
-rw-r--r--demos/gui/translation/text.csv3
-rw-r--r--demos/gui/translation/translations/text.en.xlbin0 -> 575 bytes
-rw-r--r--demos/gui/translation/translations/text.es.xlbin0 -> 579 bytes
-rw-r--r--demos/gui/translation/translations/text.ja.xlbin0 -> 595 bytes
17 files changed, 141 insertions, 0 deletions
diff --git a/demos/gui/input_mapping/controls.gd b/demos/gui/input_mapping/controls.gd
new file mode 100644
index 0000000000..6ca059c812
--- /dev/null
+++ b/demos/gui/input_mapping/controls.gd
@@ -0,0 +1,49 @@
+# Note for the reader:
+#
+# This demo conveniently uses the same names for actions and for the container nodes
+# that hold each remapping button. This allow to get back to the button based simply
+# on the name of the corresponding action, but it might not be so simple in your project.
+#
+# A better approach for large-scale input remapping might be to do the connections between
+# buttons and wait_for_input through the code, passing as arguments both the name of the
+# action and the node, e.g.:
+# button.connect("pressed", self, "wait_for_input", [ button, action ])
+
+extends Control
+
+var player_actions = [ "move_up", "move_down", "move_left", "move_right", "jump" ]
+var action # To register the action the UI is currently handling
+var button # Button node corresponding to the above action
+
+func wait_for_input(action_bind):
+ action = action_bind
+ # See note at the beginning of the script
+ button = get_node("bindings").get_node(action).get_node("Button")
+ get_node("contextual_help").set_text("Press a key to assign to the '" + action + "' action.")
+ set_process_input(true)
+
+func _input(event):
+ # Handle the first pressed key
+ if (event.type == InputEvent.KEY):
+ # Register the event as handled and stop polling
+ get_tree().set_input_as_handled()
+ set_process_input(false)
+ # Reinitialise the contextual help label
+ get_node("contextual_help").set_text("Click a key binding to reassign it, or press the Cancel action.")
+ if (not event.is_action("ui_cancel")):
+ # Display the string corresponding to the pressed key
+ button.set_text(OS.get_scancode_string(event.scancode))
+ # Start by removing previously key binding(s)
+ for old_event in InputMap.get_action_list(action):
+ InputMap.action_erase_event(action, old_event)
+ # Add the new key binding
+ InputMap.action_add_event(action, event)
+
+func _ready():
+ # Initialise each button with the default key binding from InputMap
+ var input_event
+ for action in player_actions:
+ # We assume that the key binding that we want is the first one (0), if there are several
+ input_event = InputMap.get_action_list(action)[0]
+ # See note at the beginning of the script
+ get_node("bindings").get_node(action).get_node("Button").set_text(OS.get_scancode_string(input_event.scancode))
diff --git a/demos/gui/input_mapping/controls.scn b/demos/gui/input_mapping/controls.scn
new file mode 100644
index 0000000000..276712ba22
--- /dev/null
+++ b/demos/gui/input_mapping/controls.scn
Binary files differ
diff --git a/demos/gui/input_mapping/engine.cfg b/demos/gui/input_mapping/engine.cfg
new file mode 100644
index 0000000000..959c0ac7d5
--- /dev/null
+++ b/demos/gui/input_mapping/engine.cfg
@@ -0,0 +1,18 @@
+[application]
+
+name="Input Mapping GUI"
+main_scene="res://controls.scn"
+icon="icon.png"
+
+[display]
+
+width=640
+height=480
+
+[input]
+
+move_up=[key(Up)]
+move_down=[key(Down)]
+move_left=[key(Left)]
+move_right=[key(Right)]
+jump=[key(Space)]
diff --git a/demos/gui/translation/controls.gd b/demos/gui/translation/controls.gd
new file mode 100644
index 0000000000..f8403f49a7
--- /dev/null
+++ b/demos/gui/translation/controls.gd
@@ -0,0 +1,20 @@
+
+extends Panel
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+func _ready():
+ # Initialization here
+ pass
+
+
+
+
+func _on_back_pressed():
+ var s = load("res://main.scn")
+ var si = s.instance()
+ get_parent().add_child(si)
+ queue_free()
+ pass # replace with function body
diff --git a/demos/gui/translation/controls.scn b/demos/gui/translation/controls.scn
new file mode 100644
index 0000000000..66e6d47702
--- /dev/null
+++ b/demos/gui/translation/controls.scn
Binary files differ
diff --git a/demos/gui/translation/engine.cfg b/demos/gui/translation/engine.cfg
new file mode 100644
index 0000000000..169b65e154
--- /dev/null
+++ b/demos/gui/translation/engine.cfg
@@ -0,0 +1,9 @@
+[application]
+
+name="Translation Demo"
+main_scene="res://main.scn"
+
+[locale]
+
+translations=["res://translations/text.en.xl", "res://translations/text.es.xl", "res://translations/text.ja.xl"]
+translation_remaps={"res://flag_uk.png":["res://flag_spain.png:es", "res://flag_japan.png:ja"]}
diff --git a/demos/gui/translation/flag_japan.png b/demos/gui/translation/flag_japan.png
new file mode 100644
index 0000000000..4cc8267a5c
--- /dev/null
+++ b/demos/gui/translation/flag_japan.png
Binary files differ
diff --git a/demos/gui/translation/flag_spain.png b/demos/gui/translation/flag_spain.png
new file mode 100644
index 0000000000..4d00f93593
--- /dev/null
+++ b/demos/gui/translation/flag_spain.png
Binary files differ
diff --git a/demos/gui/translation/flag_uk.png b/demos/gui/translation/flag_uk.png
new file mode 100644
index 0000000000..53fbef3d67
--- /dev/null
+++ b/demos/gui/translation/flag_uk.png
Binary files differ
diff --git a/demos/gui/translation/main.gd b/demos/gui/translation/main.gd
new file mode 100644
index 0000000000..bf3c0c0840
--- /dev/null
+++ b/demos/gui/translation/main.gd
@@ -0,0 +1,42 @@
+
+extends Panel
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+func _ready():
+ # Initialization here
+ pass
+
+
+
+func _goto_scene():
+ var s = load("res://controls.scn")
+ var si = s.instance()
+ get_parent().add_child(si)
+ queue_free()
+ pass
+
+
+func _on_system_pressed():
+ #will autodetect based on system, then fall back
+ #to english if not found
+ _goto_scene()
+
+#NOTE: Changling locale will not change the text in the controls,
+# The scene must be reloaded for changes to take effect.
+
+func _on_english_pressed():
+ TranslationServer.set_locale("en")
+ _goto_scene()
+
+
+func _on_spanish_pressed():
+ TranslationServer.set_locale("es")
+ _goto_scene()
+
+
+func _on_japanese_pressed():
+ TranslationServer.set_locale("ja")
+ _goto_scene()
diff --git a/demos/gui/translation/main.scn b/demos/gui/translation/main.scn
new file mode 100644
index 0000000000..76c9ba7b45
--- /dev/null
+++ b/demos/gui/translation/main.scn
Binary files differ
diff --git a/demos/gui/translation/noto.fnt b/demos/gui/translation/noto.fnt
new file mode 100644
index 0000000000..e019615f41
--- /dev/null
+++ b/demos/gui/translation/noto.fnt
Binary files differ
diff --git a/demos/gui/translation/notosans.otf b/demos/gui/translation/notosans.otf
new file mode 100644
index 0000000000..6443f9023e
--- /dev/null
+++ b/demos/gui/translation/notosans.otf
Binary files differ
diff --git a/demos/gui/translation/text.csv b/demos/gui/translation/text.csv
new file mode 100644
index 0000000000..0f4c148b95
--- /dev/null
+++ b/demos/gui/translation/text.csv
@@ -0,0 +1,3 @@
+,en,es,ja
+KEY_HELLO,Hello!,Hola!,こんにちは
+KEY_PUSH,Push Me!,Aprétame!,私をプッシュ \ No newline at end of file
diff --git a/demos/gui/translation/translations/text.en.xl b/demos/gui/translation/translations/text.en.xl
new file mode 100644
index 0000000000..7bcba63e71
--- /dev/null
+++ b/demos/gui/translation/translations/text.en.xl
Binary files differ
diff --git a/demos/gui/translation/translations/text.es.xl b/demos/gui/translation/translations/text.es.xl
new file mode 100644
index 0000000000..4474d955d5
--- /dev/null
+++ b/demos/gui/translation/translations/text.es.xl
Binary files differ
diff --git a/demos/gui/translation/translations/text.ja.xl b/demos/gui/translation/translations/text.ja.xl
new file mode 100644
index 0000000000..b3d1f0bf60
--- /dev/null
+++ b/demos/gui/translation/translations/text.ja.xl
Binary files differ