Refactor Godot architecture into AppShell, modular menus and game domains
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
extends CanvasLayer
|
||||
## Configurazione in-game; la definizione delle righe è in OptionsSchema.
|
||||
|
||||
var rows: Dictionary = {}
|
||||
var mode_option: OptionButton
|
||||
var gentle_button: CheckButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
visible = false
|
||||
_build()
|
||||
|
||||
|
||||
func _build() -> void:
|
||||
var dim := ColorRect.new()
|
||||
dim.color = Color(0, 0, 0, 0.65)
|
||||
dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
dim.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
add_child(dim)
|
||||
var center := CenterContainer.new()
|
||||
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
add_child(center)
|
||||
var panel := PanelContainer.new()
|
||||
center.add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
margin.add_theme_constant_override("margin_left", 24)
|
||||
margin.add_theme_constant_override("margin_right", 24)
|
||||
margin.add_theme_constant_override("margin_top", 16)
|
||||
margin.add_theme_constant_override("margin_bottom", 16)
|
||||
panel.add_child(margin)
|
||||
var content := VBoxContainer.new()
|
||||
content.add_theme_constant_override("separation", 8)
|
||||
margin.add_child(content)
|
||||
_add_title(content)
|
||||
_add_settings_rows(content)
|
||||
_add_mode_controls(content)
|
||||
_add_actions(content)
|
||||
|
||||
|
||||
func _add_title(parent: VBoxContainer) -> void:
|
||||
var title := Label.new()
|
||||
title.text = "CONFIGURAZIONE"
|
||||
title.add_theme_font_size_override("font_size", 30)
|
||||
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
parent.add_child(title)
|
||||
|
||||
|
||||
func _add_settings_rows(parent: VBoxContainer) -> void:
|
||||
for entry in JuggleBoardOptionsSchema.ENTRIES:
|
||||
var row := OptionSliderRow.new()
|
||||
row.setup(entry[0], entry[1], entry[2], entry[3], entry[4], Settings.get(entry[0]))
|
||||
row.setting_changed.connect(func(key: String, value: float): Settings.set(key, value))
|
||||
parent.add_child(row)
|
||||
rows[entry[0]] = row
|
||||
|
||||
|
||||
func _add_mode_controls(parent: VBoxContainer) -> void:
|
||||
parent.add_child(HSeparator.new())
|
||||
var row := HBoxContainer.new()
|
||||
row.custom_minimum_size.y = 44
|
||||
row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
parent.add_child(row)
|
||||
var label := Label.new()
|
||||
label.text = "Modalità di gioco:"
|
||||
label.custom_minimum_size.x = 230
|
||||
label.add_theme_font_size_override("font_size", 18)
|
||||
row.add_child(label)
|
||||
mode_option = OptionButton.new()
|
||||
mode_option.custom_minimum_size = Vector2(300, 40)
|
||||
mode_option.add_theme_font_size_override("font_size", 17)
|
||||
mode_option.add_item("Classica (a punteggio)")
|
||||
mode_option.add_item("Zen (senza tempo)")
|
||||
mode_option.add_item("Survival (a vite)")
|
||||
mode_option.item_selected.connect(func(index: int): Settings.game_mode = index)
|
||||
row.add_child(mode_option)
|
||||
gentle_button = CheckButton.new()
|
||||
gentle_button.text = "Errori gentili (combo -1)"
|
||||
gentle_button.toggled.connect(func(enabled: bool): Settings.gentle_errors = enabled)
|
||||
parent.add_child(gentle_button)
|
||||
|
||||
|
||||
func _add_actions(parent: VBoxContainer) -> void:
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
parent.add_child(row)
|
||||
for spec in [["Salva e riavvia", _on_save], ["Ripristina default", _on_reset], ["Annulla", hide_menu]]:
|
||||
var button := Button.new()
|
||||
button.text = spec[0]
|
||||
button.pressed.connect(spec[1])
|
||||
row.add_child(button)
|
||||
|
||||
|
||||
func show_menu() -> void:
|
||||
_refresh_values()
|
||||
visible = true
|
||||
get_tree().paused = true
|
||||
|
||||
|
||||
func hide_menu() -> void:
|
||||
visible = false
|
||||
get_tree().paused = false
|
||||
|
||||
|
||||
func _refresh_values() -> void:
|
||||
for key in rows:
|
||||
rows[key].set_value(Settings.get(key))
|
||||
mode_option.select(Settings.game_mode)
|
||||
gentle_button.button_pressed = Settings.gentle_errors
|
||||
|
||||
|
||||
func _on_save() -> void:
|
||||
Settings.save_settings()
|
||||
hide_menu()
|
||||
get_tree().call_deferred("reload_current_scene")
|
||||
|
||||
|
||||
func _on_reset() -> void:
|
||||
Settings.reset_defaults()
|
||||
_refresh_values()
|
||||
Reference in New Issue
Block a user