mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
This commit is contained in:
@@ -18,6 +18,10 @@ config/features=PackedStringArray("4.2")
|
||||
run/low_processor_mode=true
|
||||
config/icon="res://icon.webp"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_height=576
|
||||
|
||||
@@ -5,51 +5,51 @@ extends Control
|
||||
# This means that you should use `add_theme_stylebox_override("normal", ...)`
|
||||
# instead of `set("custom_styles/normal", ...)`.
|
||||
|
||||
@onready var label = $Panel/MarginContainer/VBoxContainer/Label
|
||||
@onready var button = $Panel/MarginContainer/VBoxContainer/Button
|
||||
@onready var button2 = $Panel/MarginContainer/VBoxContainer/Button2
|
||||
@onready var reset_all_button = $Panel/MarginContainer/VBoxContainer/ResetAllButton
|
||||
@onready var label: Label = $Panel/MarginContainer/VBoxContainer/Label
|
||||
@onready var button: Button = $Panel/MarginContainer/VBoxContainer/Button
|
||||
@onready var button2: Button = $Panel/MarginContainer/VBoxContainer/Button2
|
||||
@onready var reset_all_button: Button = $Panel/MarginContainer/VBoxContainer/ResetAllButton
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
# Focus the first button automatically for keyboard/controller-friendly navigation.
|
||||
button.grab_focus()
|
||||
|
||||
|
||||
func _on_button_pressed():
|
||||
func _on_button_pressed() -> void:
|
||||
# We have to modify the normal, hover and pressed styleboxes all at once
|
||||
# to get a correct appearance when the button is hovered or pressed.
|
||||
# We can't use a single StyleBox for all of them as these have different
|
||||
# background colors.
|
||||
var new_stylebox_normal = button.get_theme_stylebox("normal").duplicate()
|
||||
var new_stylebox_normal: StyleBoxFlat = button.get_theme_stylebox("normal").duplicate()
|
||||
new_stylebox_normal.border_color = Color(1, 1, 0)
|
||||
var new_stylebox_hover = button.get_theme_stylebox("hover").duplicate()
|
||||
var new_stylebox_hover: StyleBoxFlat = button.get_theme_stylebox("hover").duplicate()
|
||||
new_stylebox_hover.border_color = Color(1, 1, 0)
|
||||
var new_stylebox_pressed = button.get_theme_stylebox("pressed").duplicate()
|
||||
var new_stylebox_pressed: StyleBoxFlat = button.get_theme_stylebox("pressed").duplicate()
|
||||
new_stylebox_pressed.border_color = Color(1, 1, 0)
|
||||
|
||||
button.add_theme_stylebox_override("normal", new_stylebox_normal)
|
||||
button.add_theme_stylebox_override("hover", new_stylebox_hover)
|
||||
button.add_theme_stylebox_override("pressed", new_stylebox_pressed)
|
||||
|
||||
label.add_theme_color_override("font_color", Color(1, 1, 0.5))
|
||||
label.add_theme_color_override("font_color", Color(1, 1, 0.375))
|
||||
|
||||
|
||||
func _on_button2_pressed():
|
||||
var new_stylebox_normal = button2.get_theme_stylebox("normal").duplicate()
|
||||
func _on_button2_pressed() -> void:
|
||||
var new_stylebox_normal: StyleBoxFlat = button2.get_theme_stylebox("normal").duplicate()
|
||||
new_stylebox_normal.border_color = Color(0, 1, 0.5)
|
||||
var new_stylebox_hover = button2.get_theme_stylebox("hover").duplicate()
|
||||
var new_stylebox_hover: StyleBoxFlat = button2.get_theme_stylebox("hover").duplicate()
|
||||
new_stylebox_hover.border_color = Color(0, 1, 0.5)
|
||||
var new_stylebox_pressed = button2.get_theme_stylebox("pressed").duplicate()
|
||||
var new_stylebox_pressed: StyleBoxFlat = button2.get_theme_stylebox("pressed").duplicate()
|
||||
new_stylebox_pressed.border_color = Color(0, 1, 0.5)
|
||||
|
||||
button2.add_theme_stylebox_override("normal", new_stylebox_normal)
|
||||
button2.add_theme_stylebox_override("hover", new_stylebox_hover)
|
||||
button2.add_theme_stylebox_override("pressed", new_stylebox_pressed)
|
||||
|
||||
label.add_theme_color_override("font_color", Color(0.5, 1, 0.75))
|
||||
label.add_theme_color_override("font_color", Color(0.375, 1, 0.75))
|
||||
|
||||
|
||||
func _on_reset_all_button_pressed():
|
||||
func _on_reset_all_button_pressed() -> void:
|
||||
button.remove_theme_stylebox_override("normal")
|
||||
button.remove_theme_stylebox_override("hover")
|
||||
button.remove_theme_stylebox_override("pressed")
|
||||
|
||||
Reference in New Issue
Block a user