Prechádzať zdrojové kódy

Merge pull request #395 from aaronfranke/gui

Improve GUI demos
Aaron Franke 5 rokov pred
rodič
commit
ac882369bc

+ 10 - 10
gui/drag_and_drop/drag_and_drop.tscn

@@ -2,7 +2,7 @@
 
 [ext_resource path="res://drag_drop_script.gd" type="Script" id=1]
 
-[node name="Control" type="Control"]
+[node name="DragAndDrop" type="Control"]
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
@@ -18,6 +18,15 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
+[node name="Information" type="Label" parent="."]
+margin_left = 250.0
+margin_top = 140.0
+margin_right = 761.0
+margin_bottom = 154.0
+size_flags_horizontal = 2
+size_flags_vertical = 0
+text = "Drag colors from button to button, or change button colors and drag them again."
+
 [node name="ColorPickerButton0" type="ColorPickerButton" parent="."]
 margin_left = 304.0
 margin_top = 193.0
@@ -107,12 +116,3 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 color = Color( 0, 0, 0.178211, 1 )
 script = ExtResource( 1 )
-
-[node name="Label" type="Label" parent="."]
-margin_left = 250.0
-margin_top = 140.0
-margin_right = 761.0
-margin_bottom = 154.0
-size_flags_horizontal = 2
-size_flags_vertical = 0
-text = "Drag colors from button to button, or change button colors and drag them again."

+ 0 - 2
gui/drag_and_drop/drag_drop_script.gd

@@ -1,7 +1,5 @@
-
 extends ColorPickerButton
 
-
 func get_drag_data(_pos):
 	# Use another colorpicker as drag preview
 	var cpb = ColorPickerButton.new()

+ 48 - 50
gui/input_mapping/controls.gd

@@ -11,18 +11,62 @@ extends Control
 # action and the node, e.g.:
 # button.connect("pressed", self, "wait_for_input", [ button, action ])
 
-# Constants
 const INPUT_ACTIONS = [ "move_up", "move_down", "move_left", "move_right", "jump" ]
 const CONFIG_FILE = "user://input.cfg"
 
-# Member variables
 var action # To register the action the UI is currently handling
 var button # Button node corresponding to the above action
 
+onready var bindings = $Bindings
+onready var contextual_help = $ContextualHelp
+
+func _ready():
+	# Load config if existing, if not it will be generated with default values
+	load_config()
+	# Initialise each button with the default key binding from InputMap
+	for action in INPUT_ACTIONS:
+		# We assume that the key binding that we want is the first one (0), if there are several
+		var input_event = InputMap.get_action_list(action)[0]
+		# See note at the beginning of the script
+		var button = bindings.get_node(action).get_node("Button")
+		button.text = OS.get_scancode_string(input_event.scancode)
+		button.connect("pressed", self, "wait_for_input", [action])
+
+	# Do not start processing input until a button is pressed
+	set_process_input(false)
+
+
+# Input management
+func _input(event):
+	# Handle the first pressed key
+	if event is InputEventKey:
+		# Register the event as handled and stop polling
+		get_tree().set_input_as_handled()
+		set_process_input(false)
+		# Reinitialise the contextual help label
+		contextual_help.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
+			var scancode = OS.get_scancode_string(event.scancode)
+			button.text = 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)
+			save_to_config("input", action, scancode)
+
+
+func wait_for_input(action_bind):
+	action = action_bind
+	# See note at the beginning of the script
+	button = bindings.get_node(action).get_node("Button")
+	contextual_help.text = "Press a key to assign to the '" + action + "' action."
+	set_process_input(true)
+
 
 # Load/save input mapping to a config file
 # Changes done while testing the demo will be persistent, saved to CONFIG_FILE
-
 func load_config():
 	var config = ConfigFile.new()
 	var err = config.load(CONFIG_FILE)
@@ -48,7 +92,7 @@ func load_config():
 
 
 func save_to_config(section, key, value):
-	"""Helper function to redefine a parameter in the settings file"""
+	# Helper function to redefine a parameter in the settings file.
 	var config = ConfigFile.new()
 	var err = config.load(CONFIG_FILE)
 	if err:
@@ -56,49 +100,3 @@ func save_to_config(section, key, value):
 	else:
 		config.set_value(section, key, value)
 		config.save(CONFIG_FILE)
-
-
-# Input management
-
-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").text = "Press a key to assign to the '" + action + "' action."
-	set_process_input(true)
-
-
-func _input(event):
-	# Handle the first pressed key
-	if event is InputEventKey:
-		# 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").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
-			var scancode = OS.get_scancode_string(event.scancode)
-			button.text = 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)
-			save_to_config("input", action, scancode)
-
-
-func _ready():
-	# Load config if existing, if not it will be generated with default values
-	load_config()
-	# Initialise each button with the default key binding from InputMap
-	for action in INPUT_ACTIONS:
-		# We assume that the key binding that we want is the first one (0), if there are several
-		var input_event = InputMap.get_action_list(action)[0]
-		# See note at the beginning of the script
-		var button = get_node("bindings").get_node(action).get_node("Button")
-		button.text = OS.get_scancode_string(input_event.scancode)
-		button.connect("pressed", self, "wait_for_input", [action])
-
-	# Do not start processing input until a button is pressed
-	set_process_input(false)

+ 30 - 45
gui/input_mapping/controls.tscn

@@ -2,7 +2,7 @@
 
 [ext_resource path="res://controls.gd" type="Script" id=1]
 
-[node name="controls_ui" type="Control"]
+[node name="Controls" type="Control"]
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
@@ -19,7 +19,7 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
-[node name="contextual_help" type="Label" parent="."]
+[node name="ContextualHelp" type="Label" parent="."]
 margin_left = 130.0
 margin_top = 100.0
 margin_right = 533.0
@@ -31,26 +31,19 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
-[node name="bindings" type="Control" parent="."]
-margin_left = 80.0
-margin_top = 100.0
-margin_right = 120.0
-margin_bottom = 140.0
+[node name="Bindings" type="VBoxContainer" parent="."]
+margin_left = 150.0
+margin_top = 150.0
+margin_right = 350.0
+margin_bottom = 450.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
-__meta__ = {
-"_edit_use_anchors_": false
-}
 
-[node name="move_up" type="Control" parent="bindings"]
-margin_left = 50.0
-margin_top = 50.0
-margin_right = 90.0
-margin_bottom = 90.0
+[node name="move_up" type="Control" parent="Bindings"]
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="Label" type="Label" parent="bindings/move_up"]
+[node name="Label" type="Label" parent="Bindings/move_up"]
 margin_left = 5.0
 margin_top = 8.0
 margin_right = 45.0
@@ -59,7 +52,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 0
 text = "Up"
 
-[node name="Button" type="Button" parent="bindings/move_up"]
+[node name="Button" type="Button" parent="Bindings/move_up"]
 margin_left = 84.0
 margin_top = -1.0
 margin_right = 144.0
@@ -67,15 +60,13 @@ margin_bottom = 29.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="move_down" type="Control" parent="bindings"]
-margin_left = 50.0
-margin_top = 100.0
-margin_right = 90.0
-margin_bottom = 140.0
+[node name="move_down" type="Control" parent="Bindings"]
+margin_top = 60.0
+margin_bottom = 60.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="Label" type="Label" parent="bindings/move_down"]
+[node name="Label" type="Label" parent="Bindings/move_down"]
 margin_left = 5.0
 margin_top = 8.0
 margin_right = 45.0
@@ -84,7 +75,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 0
 text = "Down"
 
-[node name="Button" type="Button" parent="bindings/move_down"]
+[node name="Button" type="Button" parent="Bindings/move_down"]
 margin_left = 84.0
 margin_top = -1.0
 margin_right = 144.0
@@ -92,15 +83,13 @@ margin_bottom = 29.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="move_left" type="Control" parent="bindings"]
-margin_left = 50.0
-margin_top = 150.0
-margin_right = 90.0
-margin_bottom = 190.0
+[node name="move_left" type="Control" parent="Bindings"]
+margin_top = 120.0
+margin_bottom = 120.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="Label" type="Label" parent="bindings/move_left"]
+[node name="Label" type="Label" parent="Bindings/move_left"]
 margin_left = 5.0
 margin_top = 8.0
 margin_right = 45.0
@@ -109,7 +98,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 0
 text = "Left"
 
-[node name="Button" type="Button" parent="bindings/move_left"]
+[node name="Button" type="Button" parent="Bindings/move_left"]
 margin_left = 84.0
 margin_top = -1.0
 margin_right = 144.0
@@ -117,15 +106,13 @@ margin_bottom = 29.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="move_right" type="Control" parent="bindings"]
-margin_left = 50.0
-margin_top = 200.0
-margin_right = 90.0
-margin_bottom = 240.0
+[node name="move_right" type="Control" parent="Bindings"]
+margin_top = 180.0
+margin_bottom = 180.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="Label" type="Label" parent="bindings/move_right"]
+[node name="Label" type="Label" parent="Bindings/move_right"]
 margin_left = 5.0
 margin_top = 8.0
 margin_right = 45.0
@@ -134,7 +121,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 0
 text = "Right"
 
-[node name="Button" type="Button" parent="bindings/move_right"]
+[node name="Button" type="Button" parent="Bindings/move_right"]
 margin_left = 84.0
 margin_top = -1.0
 margin_right = 144.0
@@ -142,15 +129,13 @@ margin_bottom = 29.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="jump" type="Control" parent="bindings"]
-margin_left = 50.0
-margin_top = 250.0
-margin_right = 90.0
-margin_bottom = 290.0
+[node name="jump" type="Control" parent="Bindings"]
+margin_top = 240.0
+margin_bottom = 240.0
 size_flags_horizontal = 2
 size_flags_vertical = 2
 
-[node name="Label" type="Label" parent="bindings/jump"]
+[node name="Label" type="Label" parent="Bindings/jump"]
 margin_left = 5.0
 margin_top = 8.0
 margin_right = 45.0
@@ -159,7 +144,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 0
 text = "Jump"
 
-[node name="Button" type="Button" parent="bindings/jump"]
+[node name="Button" type="Button" parent="Bindings/jump"]
 margin_left = 84.0
 margin_top = -1.0
 margin_right = 144.0

+ 0 - 2
gui/rich_text_bbcode/rich_text_bbcode.gd

@@ -1,7 +1,5 @@
-
 extends Panel
 
-
 func _on_RichTextLabel_meta_clicked(meta):
 	var err = OS.shell_open(meta)
 	if (err == OK):

+ 7 - 3
gui/rich_text_bbcode/rich_text_bbcode.tscn

@@ -22,7 +22,7 @@ font_data = ExtResource( 4 )
 size = 20
 font_data = ExtResource( 5 )
 
-[node name="Panel" type="Panel"]
+[node name="RichTextBBCode" type="Panel"]
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
@@ -55,20 +55,24 @@ custom_fonts/normal_font = SubResource( 4 )
 bbcode_enabled = true
 bbcode_text = "[b][u]Rich Text Test[/u][/b]
 
-RichTextLabel is a flexible way of adding text to your game, with support for [i]italics[/i], [b]bold[/b] and [i][b]both[/b][/i]. [u]Underline[/u] works too.
+RichTextLabel is a flexible way of adding text to your game, with support for [i]italics[/i], [b]bold[/b] and [i][b]both[/b][/i].
+ [u]Underline[/u] works too, including with [u][i]italics[/i][/u], [u][b]bold[/b][/u] and [u][i][b]both[/b][/i][/u].
 It is also possible to include [img]res://unicorn_icon.png[/img] custom images, as well as [color=aqua][url=https://godotengine.org]custom URLs[/url][/color].
 
 Left alignment is default,[center]but center alignment is supported,[/center][right]as well as right alignment.[/right]
+
 [fill]Fill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy.[/fill]
 
 For full reference, [color=aqua][url=https://docs.godotengine.org/en/latest/tutorials/gui/bbcode_in_richtextlabel.html]check the documentation.[/url][/color]
 "
 text = "Rich Text Test
 
-RichTextLabel is a flexible way of adding text to your game, with support for italics, bold and both. Underline works too.
+RichTextLabel is a flexible way of adding text to your game, with support for italics, bold and both.
+ Underline works too, including with italics, bold and both.
 It is also possible to include  custom images, as well as custom URLs.
 
 Left alignment is default,but center alignment is supported,as well as right alignment.
+
 Fill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy.
 
 For full reference, check the documentation.

+ 0 - 8
gui/translation/controls.gd

@@ -1,8 +0,0 @@
-
-extends Panel
-
-func _on_back_pressed():
-	var scene = load("res://main.tscn")
-	var si = scene.instance()
-	get_parent().add_child(si)
-	queue_free()

+ 0 - 53
gui/translation/controls.tscn

@@ -1,53 +0,0 @@
-[gd_scene load_steps=3 format=2]
-
-[ext_resource path="res://controls.gd" type="Script" id=1]
-[ext_resource path="res://flag_uk.png" type="Texture" id=2]
-
-[node name="Panel" type="Panel"]
-anchor_right = 1.0
-anchor_bottom = 1.0
-size_flags_horizontal = 2
-size_flags_vertical = 2
-script = ExtResource( 1 )
-__meta__ = {
-"__editor_plugin_screen__": "2D"
-}
-
-[node name="Label" type="Label" parent="."]
-margin_left = 175.0
-margin_top = 118.0
-margin_right = 328.0
-margin_bottom = 132.0
-size_flags_horizontal = 2
-size_flags_vertical = 0
-text = "KEY_HELLO"
-align = 1
-
-[node name="Button" type="Button" parent="."]
-margin_left = 166.0
-margin_top = 178.0
-margin_right = 335.0
-margin_bottom = 199.0
-size_flags_horizontal = 2
-size_flags_vertical = 2
-text = "KEY_PUSH"
-
-[node name="TextureFrame" type="TextureRect" parent="."]
-margin_left = 377.0
-margin_top = 118.0
-margin_right = 505.0
-margin_bottom = 203.0
-size_flags_horizontal = 2
-size_flags_vertical = 2
-texture = ExtResource( 2 )
-
-[node name="back" type="Button" parent="."]
-margin_left = 26.0
-margin_top = 20.0
-margin_right = 150.0
-margin_bottom = 44.0
-size_flags_horizontal = 2
-size_flags_vertical = 2
-text = "<- back"
-
-[connection signal="pressed" from="back" to="." method="_on_back_pressed"]

BIN
gui/translation/noto.fnt


+ 1 - 1
gui/translation/project.godot

@@ -16,7 +16,7 @@ _global_script_class_icons={
 [application]
 
 config/name="Translation Demo"
-run/main_scene="res://main.tscn"
+run/main_scene="res://translation_demo.tscn"
 config/icon="res://icon.png"
 
 [display]

+ 4 - 2
gui/translation/main.gd → gui/translation/translation_demo.gd

@@ -1,14 +1,16 @@
-
 extends Panel
 
 func _on_english_pressed():
 	TranslationServer.set_locale("en")
 
+
 func _on_spanish_pressed():
 	TranslationServer.set_locale("es")
 
+
 func _on_japanese_pressed():
 	TranslationServer.set_locale("ja")
 
+
 func _on_play_pressed():
-	get_node("audio").play()
+	$Audio.play()

+ 16 - 16
gui/translation/main.tscn → gui/translation/translation_demo.tscn

@@ -1,12 +1,12 @@
 [gd_scene load_steps=6 format=2]
 
-[ext_resource path="res://main.gd" type="Script" id=1]
+[ext_resource path="res://translation_demo.gd" type="Script" id=1]
 [ext_resource path="res://font/droid_sans.tres" type="DynamicFont" id=2]
 [ext_resource path="res://speaker.png" type="Texture" id=3]
 [ext_resource path="res://flag_uk.png" type="Texture" id=4]
 [ext_resource path="res://hello_en.wav" type="AudioStream" id=5]
 
-[node name="Panel" type="Panel"]
+[node name="TranslationDemo" type="Panel"]
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
@@ -23,7 +23,7 @@ __meta__ = {
 "_edit_use_anchors_": false
 }
 
-[node name="english" type="Button" parent="."]
+[node name="English" type="Button" parent="."]
 margin_left = 32.0
 margin_top = 64.0
 margin_right = 192.0
@@ -32,7 +32,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 text = "Use English"
 
-[node name="spanish" type="Button" parent="."]
+[node name="Spanish" type="Button" parent="."]
 margin_left = 32.0
 margin_top = 112.0
 margin_right = 192.0
@@ -41,7 +41,7 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 text = "Use Spanish"
 
-[node name="japanese" type="Button" parent="."]
+[node name="Japanese" type="Button" parent="."]
 margin_left = 32.0
 margin_top = 160.0
 margin_right = 192.0
@@ -50,10 +50,10 @@ size_flags_horizontal = 2
 size_flags_vertical = 2
 text = "Use Japanese"
 
-[node name="description" type="Label" parent="."]
+[node name="Description" type="Label" parent="."]
 margin_left = 243.0
 margin_top = 42.0
-margin_right = 808.0
+margin_right = 804.0
 margin_bottom = 312.0
 size_flags_horizontal = 2
 size_flags_vertical = 0
@@ -62,7 +62,7 @@ text = "This is a demo of how a game can be internationalized.
 Translations are created in a CSV file and then imported into Godot.
 
 Using a TTF/OTF font with CJK is required for this demo to run. One is provided
-in the font/ folder for your games.
+in the font/ folder that you can use for your games.
 
 Godot allows internationalized text to change automatically when the locale is
 modified. Resources can also be set internationalized alternatives and replaced
@@ -74,7 +74,7 @@ margin_top = 330.0
 margin_right = 1001.0
 margin_bottom = 370.0
 
-[node name="label" type="Label" parent="."]
+[node name="HelloText" type="Label" parent="."]
 margin_left = 246.0
 margin_top = 381.0
 margin_right = 324.0
@@ -83,7 +83,7 @@ size_flags_vertical = 0
 custom_fonts/font = ExtResource( 2 )
 text = "KEY_HELLO"
 
-[node name="play" type="Button" parent="."]
+[node name="PlayAudio" type="Button" parent="."]
 margin_left = 243.0
 margin_top = 442.0
 margin_right = 475.0
@@ -92,16 +92,16 @@ custom_fonts/font = ExtResource( 2 )
 text = "KEY_PUSH"
 icon = ExtResource( 3 )
 
-[node name="TextureRect" type="TextureRect" parent="."]
+[node name="Flag" type="TextureRect" parent="."]
 margin_left = 85.0
 margin_top = 382.0
 margin_right = 213.0
 margin_bottom = 467.0
 texture = ExtResource( 4 )
 
-[node name="audio" type="AudioStreamPlayer" parent="."]
+[node name="Audio" type="AudioStreamPlayer" parent="."]
 stream = ExtResource( 5 )
-[connection signal="pressed" from="english" to="." method="_on_english_pressed"]
-[connection signal="pressed" from="spanish" to="." method="_on_spanish_pressed"]
-[connection signal="pressed" from="japanese" to="." method="_on_japanese_pressed"]
-[connection signal="pressed" from="play" to="." method="_on_play_pressed"]
+[connection signal="pressed" from="English" to="." method="_on_english_pressed"]
+[connection signal="pressed" from="Spanish" to="." method="_on_spanish_pressed"]
+[connection signal="pressed" from="Japanese" to="." method="_on_japanese_pressed"]
+[connection signal="pressed" from="PlayAudio" to="." method="_on_play_pressed"]