Skip to content

Commit ac88236

Browse files
authored
Merge pull request #395 from aaronfranke/gui
Improve GUI demos
2 parents 6899d44 + 84c8d6e commit ac88236

File tree

12 files changed

+116
-192
lines changed

12 files changed

+116
-192
lines changed

gui/drag_and_drop/drag_and_drop.tscn

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ext_resource path="res://drag_drop_script.gd" type="Script" id=1]
44

5-
[node name="Control" type="Control"]
5+
[node name="DragAndDrop" type="Control"]
66
anchor_left = 0.5
77
anchor_top = 0.5
88
anchor_right = 0.5
@@ -18,6 +18,15 @@ __meta__ = {
1818
"_edit_use_anchors_": false
1919
}
2020

21+
[node name="Information" type="Label" parent="."]
22+
margin_left = 250.0
23+
margin_top = 140.0
24+
margin_right = 761.0
25+
margin_bottom = 154.0
26+
size_flags_horizontal = 2
27+
size_flags_vertical = 0
28+
text = "Drag colors from button to button, or change button colors and drag them again."
29+
2130
[node name="ColorPickerButton0" type="ColorPickerButton" parent="."]
2231
margin_left = 304.0
2332
margin_top = 193.0
@@ -107,12 +116,3 @@ size_flags_horizontal = 2
107116
size_flags_vertical = 2
108117
color = Color( 0, 0, 0.178211, 1 )
109118
script = ExtResource( 1 )
110-
111-
[node name="Label" type="Label" parent="."]
112-
margin_left = 250.0
113-
margin_top = 140.0
114-
margin_right = 761.0
115-
margin_bottom = 154.0
116-
size_flags_horizontal = 2
117-
size_flags_vertical = 0
118-
text = "Drag colors from button to button, or change button colors and drag them again."

gui/drag_and_drop/drag_drop_script.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
21
extends ColorPickerButton
32

4-
53
func get_drag_data(_pos):
64
# Use another colorpicker as drag preview
75
var cpb = ColorPickerButton.new()

gui/input_mapping/controls.gd

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,62 @@ extends Control
1111
# action and the node, e.g.:
1212
# button.connect("pressed", self, "wait_for_input", [ button, action ])
1313

14-
# Constants
1514
const INPUT_ACTIONS = [ "move_up", "move_down", "move_left", "move_right", "jump" ]
1615
const CONFIG_FILE = "user://input.cfg"
1716

18-
# Member variables
1917
var action # To register the action the UI is currently handling
2018
var button # Button node corresponding to the above action
2119

20+
onready var bindings = $Bindings
21+
onready var contextual_help = $ContextualHelp
22+
23+
func _ready():
24+
# Load config if existing, if not it will be generated with default values
25+
load_config()
26+
# Initialise each button with the default key binding from InputMap
27+
for action in INPUT_ACTIONS:
28+
# We assume that the key binding that we want is the first one (0), if there are several
29+
var input_event = InputMap.get_action_list(action)[0]
30+
# See note at the beginning of the script
31+
var button = bindings.get_node(action).get_node("Button")
32+
button.text = OS.get_scancode_string(input_event.scancode)
33+
button.connect("pressed", self, "wait_for_input", [action])
34+
35+
# Do not start processing input until a button is pressed
36+
set_process_input(false)
37+
38+
39+
# Input management
40+
func _input(event):
41+
# Handle the first pressed key
42+
if event is InputEventKey:
43+
# Register the event as handled and stop polling
44+
get_tree().set_input_as_handled()
45+
set_process_input(false)
46+
# Reinitialise the contextual help label
47+
contextual_help.text = "Click a key binding to reassign it, or press the Cancel action."
48+
if not event.is_action("ui_cancel"):
49+
# Display the string corresponding to the pressed key
50+
var scancode = OS.get_scancode_string(event.scancode)
51+
button.text = scancode
52+
# Start by removing previously key binding(s)
53+
for old_event in InputMap.get_action_list(action):
54+
InputMap.action_erase_event(action, old_event)
55+
# Add the new key binding
56+
InputMap.action_add_event(action, event)
57+
save_to_config("input", action, scancode)
58+
59+
60+
func wait_for_input(action_bind):
61+
action = action_bind
62+
# See note at the beginning of the script
63+
button = bindings.get_node(action).get_node("Button")
64+
contextual_help.text = "Press a key to assign to the '" + action + "' action."
65+
set_process_input(true)
66+
2267

2368
# Load/save input mapping to a config file
2469
# Changes done while testing the demo will be persistent, saved to CONFIG_FILE
25-
2670
func load_config():
2771
var config = ConfigFile.new()
2872
var err = config.load(CONFIG_FILE)
@@ -48,57 +92,11 @@ func load_config():
4892

4993

5094
func save_to_config(section, key, value):
51-
"""Helper function to redefine a parameter in the settings file"""
95+
# Helper function to redefine a parameter in the settings file.
5296
var config = ConfigFile.new()
5397
var err = config.load(CONFIG_FILE)
5498
if err:
5599
print("Error code when loading config file: ", err)
56100
else:
57101
config.set_value(section, key, value)
58102
config.save(CONFIG_FILE)
59-
60-
61-
# Input management
62-
63-
func wait_for_input(action_bind):
64-
action = action_bind
65-
# See note at the beginning of the script
66-
button = get_node("bindings").get_node(action).get_node("Button")
67-
get_node("contextual_help").text = "Press a key to assign to the '" + action + "' action."
68-
set_process_input(true)
69-
70-
71-
func _input(event):
72-
# Handle the first pressed key
73-
if event is InputEventKey:
74-
# Register the event as handled and stop polling
75-
get_tree().set_input_as_handled()
76-
set_process_input(false)
77-
# Reinitialise the contextual help label
78-
get_node("contextual_help").text = "Click a key binding to reassign it, or press the Cancel action."
79-
if not event.is_action("ui_cancel"):
80-
# Display the string corresponding to the pressed key
81-
var scancode = OS.get_scancode_string(event.scancode)
82-
button.text = scancode
83-
# Start by removing previously key binding(s)
84-
for old_event in InputMap.get_action_list(action):
85-
InputMap.action_erase_event(action, old_event)
86-
# Add the new key binding
87-
InputMap.action_add_event(action, event)
88-
save_to_config("input", action, scancode)
89-
90-
91-
func _ready():
92-
# Load config if existing, if not it will be generated with default values
93-
load_config()
94-
# Initialise each button with the default key binding from InputMap
95-
for action in INPUT_ACTIONS:
96-
# We assume that the key binding that we want is the first one (0), if there are several
97-
var input_event = InputMap.get_action_list(action)[0]
98-
# See note at the beginning of the script
99-
var button = get_node("bindings").get_node(action).get_node("Button")
100-
button.text = OS.get_scancode_string(input_event.scancode)
101-
button.connect("pressed", self, "wait_for_input", [action])
102-
103-
# Do not start processing input until a button is pressed
104-
set_process_input(false)

gui/input_mapping/controls.tscn

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ext_resource path="res://controls.gd" type="Script" id=1]
44

5-
[node name="controls_ui" type="Control"]
5+
[node name="Controls" type="Control"]
66
anchor_left = 0.5
77
anchor_top = 0.5
88
anchor_right = 0.5
@@ -19,7 +19,7 @@ __meta__ = {
1919
"_edit_use_anchors_": false
2020
}
2121

22-
[node name="contextual_help" type="Label" parent="."]
22+
[node name="ContextualHelp" type="Label" parent="."]
2323
margin_left = 130.0
2424
margin_top = 100.0
2525
margin_right = 533.0
@@ -31,26 +31,19 @@ __meta__ = {
3131
"_edit_use_anchors_": false
3232
}
3333

34-
[node name="bindings" type="Control" parent="."]
35-
margin_left = 80.0
36-
margin_top = 100.0
37-
margin_right = 120.0
38-
margin_bottom = 140.0
34+
[node name="Bindings" type="VBoxContainer" parent="."]
35+
margin_left = 150.0
36+
margin_top = 150.0
37+
margin_right = 350.0
38+
margin_bottom = 450.0
3939
size_flags_horizontal = 2
4040
size_flags_vertical = 2
41-
__meta__ = {
42-
"_edit_use_anchors_": false
43-
}
4441

45-
[node name="move_up" type="Control" parent="bindings"]
46-
margin_left = 50.0
47-
margin_top = 50.0
48-
margin_right = 90.0
49-
margin_bottom = 90.0
42+
[node name="move_up" type="Control" parent="Bindings"]
5043
size_flags_horizontal = 2
5144
size_flags_vertical = 2
5245

53-
[node name="Label" type="Label" parent="bindings/move_up"]
46+
[node name="Label" type="Label" parent="Bindings/move_up"]
5447
margin_left = 5.0
5548
margin_top = 8.0
5649
margin_right = 45.0
@@ -59,23 +52,21 @@ size_flags_horizontal = 2
5952
size_flags_vertical = 0
6053
text = "Up"
6154

62-
[node name="Button" type="Button" parent="bindings/move_up"]
55+
[node name="Button" type="Button" parent="Bindings/move_up"]
6356
margin_left = 84.0
6457
margin_top = -1.0
6558
margin_right = 144.0
6659
margin_bottom = 29.0
6760
size_flags_horizontal = 2
6861
size_flags_vertical = 2
6962

70-
[node name="move_down" type="Control" parent="bindings"]
71-
margin_left = 50.0
72-
margin_top = 100.0
73-
margin_right = 90.0
74-
margin_bottom = 140.0
63+
[node name="move_down" type="Control" parent="Bindings"]
64+
margin_top = 60.0
65+
margin_bottom = 60.0
7566
size_flags_horizontal = 2
7667
size_flags_vertical = 2
7768

78-
[node name="Label" type="Label" parent="bindings/move_down"]
69+
[node name="Label" type="Label" parent="Bindings/move_down"]
7970
margin_left = 5.0
8071
margin_top = 8.0
8172
margin_right = 45.0
@@ -84,23 +75,21 @@ size_flags_horizontal = 2
8475
size_flags_vertical = 0
8576
text = "Down"
8677

87-
[node name="Button" type="Button" parent="bindings/move_down"]
78+
[node name="Button" type="Button" parent="Bindings/move_down"]
8879
margin_left = 84.0
8980
margin_top = -1.0
9081
margin_right = 144.0
9182
margin_bottom = 29.0
9283
size_flags_horizontal = 2
9384
size_flags_vertical = 2
9485

95-
[node name="move_left" type="Control" parent="bindings"]
96-
margin_left = 50.0
97-
margin_top = 150.0
98-
margin_right = 90.0
99-
margin_bottom = 190.0
86+
[node name="move_left" type="Control" parent="Bindings"]
87+
margin_top = 120.0
88+
margin_bottom = 120.0
10089
size_flags_horizontal = 2
10190
size_flags_vertical = 2
10291

103-
[node name="Label" type="Label" parent="bindings/move_left"]
92+
[node name="Label" type="Label" parent="Bindings/move_left"]
10493
margin_left = 5.0
10594
margin_top = 8.0
10695
margin_right = 45.0
@@ -109,23 +98,21 @@ size_flags_horizontal = 2
10998
size_flags_vertical = 0
11099
text = "Left"
111100

112-
[node name="Button" type="Button" parent="bindings/move_left"]
101+
[node name="Button" type="Button" parent="Bindings/move_left"]
113102
margin_left = 84.0
114103
margin_top = -1.0
115104
margin_right = 144.0
116105
margin_bottom = 29.0
117106
size_flags_horizontal = 2
118107
size_flags_vertical = 2
119108

120-
[node name="move_right" type="Control" parent="bindings"]
121-
margin_left = 50.0
122-
margin_top = 200.0
123-
margin_right = 90.0
124-
margin_bottom = 240.0
109+
[node name="move_right" type="Control" parent="Bindings"]
110+
margin_top = 180.0
111+
margin_bottom = 180.0
125112
size_flags_horizontal = 2
126113
size_flags_vertical = 2
127114

128-
[node name="Label" type="Label" parent="bindings/move_right"]
115+
[node name="Label" type="Label" parent="Bindings/move_right"]
129116
margin_left = 5.0
130117
margin_top = 8.0
131118
margin_right = 45.0
@@ -134,23 +121,21 @@ size_flags_horizontal = 2
134121
size_flags_vertical = 0
135122
text = "Right"
136123

137-
[node name="Button" type="Button" parent="bindings/move_right"]
124+
[node name="Button" type="Button" parent="Bindings/move_right"]
138125
margin_left = 84.0
139126
margin_top = -1.0
140127
margin_right = 144.0
141128
margin_bottom = 29.0
142129
size_flags_horizontal = 2
143130
size_flags_vertical = 2
144131

145-
[node name="jump" type="Control" parent="bindings"]
146-
margin_left = 50.0
147-
margin_top = 250.0
148-
margin_right = 90.0
149-
margin_bottom = 290.0
132+
[node name="jump" type="Control" parent="Bindings"]
133+
margin_top = 240.0
134+
margin_bottom = 240.0
150135
size_flags_horizontal = 2
151136
size_flags_vertical = 2
152137

153-
[node name="Label" type="Label" parent="bindings/jump"]
138+
[node name="Label" type="Label" parent="Bindings/jump"]
154139
margin_left = 5.0
155140
margin_top = 8.0
156141
margin_right = 45.0
@@ -159,7 +144,7 @@ size_flags_horizontal = 2
159144
size_flags_vertical = 0
160145
text = "Jump"
161146

162-
[node name="Button" type="Button" parent="bindings/jump"]
147+
[node name="Button" type="Button" parent="Bindings/jump"]
163148
margin_left = 84.0
164149
margin_top = -1.0
165150
margin_right = 144.0

gui/rich_text_bbcode/rich_text_bbcode.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
21
extends Panel
32

4-
53
func _on_RichTextLabel_meta_clicked(meta):
64
var err = OS.shell_open(meta)
75
if (err == OK):

gui/rich_text_bbcode/rich_text_bbcode.tscn

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ font_data = ExtResource( 4 )
2222
size = 20
2323
font_data = ExtResource( 5 )
2424

25-
[node name="Panel" type="Panel"]
25+
[node name="RichTextBBCode" type="Panel"]
2626
anchor_left = 0.5
2727
anchor_top = 0.5
2828
anchor_right = 0.5
@@ -55,20 +55,24 @@ custom_fonts/normal_font = SubResource( 4 )
5555
bbcode_enabled = true
5656
bbcode_text = "[b][u]Rich Text Test[/u][/b]
5757
58-
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.
58+
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].
59+
[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].
5960
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].
6061
6162
Left alignment is default,[center]but center alignment is supported,[/center][right]as well as right alignment.[/right]
63+
6264
[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]
6365
6466
For full reference, [color=aqua][url=https://docs.godotengine.org/en/latest/tutorials/gui/bbcode_in_richtextlabel.html]check the documentation.[/url][/color]
6567
"
6668
text = "Rich Text Test
6769
68-
RichTextLabel is a flexible way of adding text to your game, with support for italics, bold and both. Underline works too.
70+
RichTextLabel is a flexible way of adding text to your game, with support for italics, bold and both.
71+
Underline works too, including with italics, bold and both.
6972
It is also possible to include custom images, as well as custom URLs.
7073
7174
Left alignment is default,but center alignment is supported,as well as right alignment.
75+
7276
Fill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy.
7377
7478
For full reference, check the documentation.

0 commit comments

Comments
 (0)