add edit panel
This commit is contained in:
parent
47234f1bc1
commit
89518f6aa5
7 changed files with 328 additions and 90 deletions
|
@ -4,25 +4,44 @@ extends PopupPanel
|
|||
|
||||
signal start_triggered(config)
|
||||
|
||||
const pref_path = "user://preferences.cfg"
|
||||
const pref_path := "user://preferences.cfg"
|
||||
|
||||
const easy_columns := 3
|
||||
const easy_rows := 3
|
||||
const easy_iterations := 4
|
||||
const normal_columns := 4
|
||||
const normal_rows := 4
|
||||
const normal_iterations := 10
|
||||
const hard_columns := 5
|
||||
const hard_rows := 5
|
||||
const hard_iterations := 30
|
||||
|
||||
export var window_scale_factor = 0.9 # how big the popup will be compared to screen
|
||||
|
||||
var preferences = ConfigFile.new()
|
||||
var fade_duration = 0.2
|
||||
var fade_scale_factor = 0.9
|
||||
var flip_duration = 0.4
|
||||
|
||||
onready var popup = $"."
|
||||
onready var panel = $Panel
|
||||
onready var edit_panel = $EditPanel
|
||||
onready var tween = $Tween
|
||||
onready var easy_button = $Panel/Difficulty/Easy
|
||||
onready var normal_button = $Panel/Difficulty/Normal
|
||||
onready var hard_button = $Panel/Difficulty/Hard
|
||||
onready var custom_button = $Panel/Difficulty/Custom
|
||||
onready var edit_button = $Panel/Edit
|
||||
onready var columns_spinbox = $EditPanel/VBoxContainer/Columns/SpinBox
|
||||
onready var rows_spinbox = $EditPanel/VBoxContainer/Rows/SpinBox
|
||||
onready var iterations_spinbox = $EditPanel/VBoxContainer/Iterations/SpinBox
|
||||
|
||||
func _init():
|
||||
var err = preferences.load(pref_path)
|
||||
|
||||
func _ready():
|
||||
rect_pivot_offset = rect_size / 2
|
||||
|
||||
assert(popup.theme != null)
|
||||
var popup_style : = popup.get_stylebox("panel", "PopupPanel") as StyleBoxFlat
|
||||
assert(popup_style != null)
|
||||
|
@ -34,26 +53,94 @@ func _ready():
|
|||
modified_panel_style.corner_radius_top_left = popup_style.corner_radius_top_left
|
||||
modified_panel_style.corner_radius_top_right = popup_style.corner_radius_top_right
|
||||
panel.set("custom_styles/panel", modified_panel_style)
|
||||
edit_panel.set("custom_styles/panel", modified_panel_style)
|
||||
panel.show()
|
||||
edit_panel.hide()
|
||||
edit_button.hide()
|
||||
|
||||
func fade_in():
|
||||
rect_pivot_offset = rect_size / 2
|
||||
tween.remove_all()
|
||||
tween.interpolate_property(self, "rect_scale", Vector2(fade_scale_factor, fade_scale_factor), Vector2.ONE, 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)
|
||||
tween.start()
|
||||
|
||||
func fade_out():
|
||||
rect_pivot_offset = rect_size / 2
|
||||
tween.remove_all()
|
||||
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)
|
||||
tween.interpolate_property(self, "rect_scale", Vector2.ONE, Vector2(fade_scale_factor, fade_scale_factor), fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
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()
|
||||
|
||||
func flip_over():
|
||||
tween.remove_all()
|
||||
var mid_duration = flip_duration / 2.0
|
||||
tween.interpolate_property(self, "rect_scale:x", 1.0, 0.0, mid_duration)
|
||||
tween.interpolate_callback($Panel, mid_duration, "hide")
|
||||
tween.interpolate_callback($EditPanel, mid_duration, "show")
|
||||
tween.interpolate_property(self, "rect_scale:x", 0.0, 1.0, mid_duration, Tween.TRANS_LINEAR, Tween.EASE_IN, mid_duration)
|
||||
tween.start()
|
||||
|
||||
func flip_back():
|
||||
tween.remove_all()
|
||||
var mid_duration = flip_duration / 2.0
|
||||
tween.interpolate_property(self, "rect_scale:x", 1.0, 0.0, mid_duration)
|
||||
tween.interpolate_callback($Panel, mid_duration, "show")
|
||||
tween.interpolate_callback($EditPanel, mid_duration, "hide")
|
||||
tween.interpolate_property(self, "rect_scale:x", 0.0, 1.0, mid_duration, Tween.TRANS_LINEAR, Tween.EASE_IN, mid_duration)
|
||||
tween.start()
|
||||
|
||||
func _update_description():
|
||||
var columns := 0
|
||||
var rows := 0
|
||||
var iterations := 0
|
||||
if easy_button.pressed:
|
||||
columns = easy_columns
|
||||
rows = easy_rows
|
||||
iterations = easy_iterations
|
||||
if normal_button.pressed:
|
||||
columns = normal_columns
|
||||
rows = normal_rows
|
||||
iterations = normal_iterations
|
||||
if hard_button.pressed:
|
||||
columns = hard_columns
|
||||
rows = hard_rows
|
||||
iterations = hard_iterations
|
||||
if custom_button.pressed:
|
||||
columns = columns_spinbox.value as int
|
||||
rows = rows_spinbox.value as int
|
||||
iterations = iterations_spinbox.value as int
|
||||
|
||||
$Panel/Description.text = "Dimension: %d x %d\nIterations: %d" % [columns, rows, iterations]
|
||||
|
||||
#
|
||||
# Signals
|
||||
#
|
||||
func _on_Cancel_pressed():
|
||||
fade_out()
|
||||
|
||||
func _on_Start_pressed():
|
||||
if easy_button.pressed:
|
||||
preferences.set_value("game", "difficulty", "easy")
|
||||
preferences.set_value("game", "columns", easy_columns)
|
||||
preferences.set_value("game", "rows", easy_rows)
|
||||
preferences.set_value("game", "shuffle_iterations", easy_iterations)
|
||||
if normal_button.pressed:
|
||||
preferences.set_value("game", "difficulty", "normal")
|
||||
preferences.set_value("game", "columns", normal_columns)
|
||||
preferences.set_value("game", "rows", normal_rows)
|
||||
preferences.set_value("game", "shuffle_iterations", normal_iterations)
|
||||
if hard_button.pressed:
|
||||
preferences.set_value("game", "difficulty", "hard")
|
||||
preferences.set_value("game", "columns", hard_columns)
|
||||
preferences.set_value("game", "rows", hard_rows)
|
||||
preferences.set_value("game", "shuffle_iterations", hard_iterations)
|
||||
if custom_button.pressed:
|
||||
preferences.set_value("game", "difficulty", "custom")
|
||||
preferences.set_value("game", "columns", columns_spinbox.value)
|
||||
preferences.set_value("game", "rows", rows_spinbox.value)
|
||||
preferences.set_value("game", "shuffle_iterations", iterations_spinbox.value)
|
||||
|
||||
preferences.save(pref_path)
|
||||
|
||||
|
@ -65,13 +152,47 @@ func _on_NewGamePanel_about_to_show():
|
|||
easy_button.pressed = difficulty == "easy"
|
||||
normal_button.pressed = difficulty == "normal"
|
||||
hard_button.pressed = difficulty == "hard"
|
||||
custom_button.pressed = difficulty == "custom"
|
||||
|
||||
columns_spinbox.value = preferences.get_value("game", "custom_columns", normal_columns)
|
||||
rows_spinbox.value = preferences.get_value("game", "custom_rows", normal_rows)
|
||||
iterations_spinbox.value = preferences.get_value("game", "custom_shuffle_iterations", normal_iterations)
|
||||
|
||||
if custom_button.pressed:
|
||||
edit_button.show()
|
||||
|
||||
_update_description()
|
||||
|
||||
$Panel/Start.grab_focus()
|
||||
# $Panel/Start.grab_focus()
|
||||
fade_in()
|
||||
|
||||
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)
|
||||
tween.start()
|
||||
func _on_Edit_pressed():
|
||||
flip_over()
|
||||
|
||||
func _on_Edit_Cancel_pressed():
|
||||
columns_spinbox.value = preferences.get_value("game", "custom_columns", normal_columns)
|
||||
rows_spinbox.value = preferences.get_value("game", "custom_rows", normal_rows)
|
||||
iterations_spinbox.value = preferences.get_value("game", "custom_shuffle_iterations", normal_iterations)
|
||||
flip_back()
|
||||
|
||||
func _on_Edit_Save_pressed():
|
||||
preferences.set_value("game", "custom_columns", columns_spinbox.value) as int
|
||||
preferences.set_value("game", "custom_rows", rows_spinbox.value) as int
|
||||
preferences.set_value("game", "custom_shuffle_iterations", iterations_spinbox.value) as int
|
||||
flip_back()
|
||||
|
||||
func _on_Custom_toggled(value: bool):
|
||||
if value:
|
||||
edit_button.show()
|
||||
_update_description()
|
||||
else:
|
||||
edit_button.hide()
|
||||
|
||||
func _on_Easy_pressed():
|
||||
_update_description()
|
||||
|
||||
func _on_Normal_pressed():
|
||||
_update_description()
|
||||
|
||||
func _on_Hard_pressed():
|
||||
_update_description()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue