taqin/src/NewGamePanel.gd

75 lines
2.6 KiB
GDScript
Raw Normal View History

2020-04-13 17:54:11 +02:00
tool
class_name NewGamePanel
extends PopupPanel
signal start_triggered(config)
2020-05-22 15:34:52 +02:00
const pref_path = "user://preferences.cfg"
2020-05-23 19:02:18 +02:00
export var window_scale_factor = 0.9 # how big the popup will be compared to screen
2020-05-22 15:34:52 +02:00
var preferences = ConfigFile.new()
2020-05-23 18:27:02 +02:00
var fade_duration = 0.2
2020-05-23 19:02:18 +02:00
var fade_scale_factor = 0.9
2020-05-23 18:27:02 +02:00
onready var tween = $Tween
2020-05-22 15:34:52 +02:00
2020-04-13 17:54:11 +02:00
func _init():
2020-05-22 15:34:52 +02:00
var err = preferences.load(pref_path)
2020-04-13 17:54:11 +02:00
func _ready():
pass
2020-05-23 18:27:02 +02:00
func fade_out():
tween.remove_all()
2020-05-23 19:02:18 +02:00
tween.interpolate_property(self, "rect_scale", Vector2(1.0, 1.0), Vector2(fade_scale_factor, fade_scale_factor), fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
var scaled_center_position: Vector2 = (OS.window_size - (rect_size * fade_scale_factor)) / 2
tween.interpolate_property(self, "rect_position", rect_position, scaled_center_position, fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
2020-05-23 18:27:02 +02:00
tween.interpolate_property(self, "modulate:a", 1.0, 0.0, fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.interpolate_callback(self, fade_duration, "hide")
tween.start()
2020-04-13 17:54:11 +02:00
func _on_Cancel_pressed():
2020-05-23 18:27:02 +02:00
fade_out()
2020-04-13 17:54:11 +02:00
func _on_Start_pressed():
2020-05-22 15:34:52 +02:00
if $Panel/HBoxContainer/Easy.pressed:
preferences.set_value("game", "difficulty", "easy")
if $Panel/HBoxContainer/Normal.pressed:
preferences.set_value("game", "difficulty", "normal")
if $Panel/HBoxContainer/Hard.pressed:
preferences.set_value("game", "difficulty", "hard")
preferences.save(pref_path)
emit_signal("start_triggered", preferences)
2020-05-23 18:27:02 +02:00
fade_out()
2020-05-22 15:34:52 +02:00
func _on_NewGamePanel_about_to_show():
$Panel/HBoxContainer/Easy.pressed = false
$Panel/HBoxContainer/Normal.pressed = false
$Panel/HBoxContainer/Hard.pressed = false
var difficulty = preferences.get_value("game", "difficulty", "normal")
match difficulty:
"easy":
$Panel/HBoxContainer/Easy.pressed = true
"normal":
$Panel/HBoxContainer/Normal.pressed = true
"hard":
$Panel/HBoxContainer/Hard.pressed = true
_:
assert("Invalid value")
2020-05-22 15:34:52 +02:00
$Panel/HBoxContainer/Normal.pressed = true
$Panel/Start.grab_focus()
2020-05-23 18:27:02 +02:00
2020-05-23 19:02:18 +02:00
var size = OS.window_size * window_scale_factor
tween.interpolate_property(self, "rect_scale", Vector2(fade_scale_factor, fade_scale_factor), Vector2(1.0, 1.0), fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
var original_position: Vector2 = (OS.window_size - size) / 2
var scaled_center_position: Vector2 = (OS.window_size - (size * fade_scale_factor)) / 2
tween.interpolate_property(self, "rect_position", scaled_center_position, original_position, fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.interpolate_property(self, "modulate:a", 0.0, 1.0, fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
2020-05-23 18:27:02 +02:00
tween.start()