diff --git a/assets/taqin_theme.tres b/assets/taqin_theme.tres index 72b5f1f..b590120 100644 --- a/assets/taqin_theme.tres +++ b/assets/taqin_theme.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=6 format=2] +[gd_resource type="Theme" load_steps=7 format=2] [ext_resource path="res://assets/fonts/Montserrat-ExtraBolt-48.tres" type="DynamicFont" id=1] @@ -14,6 +14,18 @@ bg_color = Color( 0.0509804, 0.168627, 0.270588, 1 ) [sub_resource type="StyleBoxFlat" id=4] bg_color = Color( 1, 0.831373, 0.639216, 1 ) +[sub_resource type="StyleBoxFlat" id=5] +bg_color = Color( 1, 0.831373, 0.639216, 1 ) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color( 0.12549, 0.235294, 0.337255, 1 ) +corner_radius_top_left = 4 +corner_radius_top_right = 4 +corner_radius_bottom_right = 4 +corner_radius_bottom_left = 4 + [resource] default_font = ExtResource( 1 ) Button/colors/font_color = Color( 0.815686, 0.505882, 0.34902, 1 ) @@ -28,3 +40,4 @@ Button/styles/hover = SubResource( 1 ) Button/styles/normal = SubResource( 2 ) Button/styles/pressed = SubResource( 3 ) Panel/styles/panel = SubResource( 4 ) +PopupPanel/styles/panel = SubResource( 5 ) diff --git a/project.godot b/project.godot index a43c645..1d576c0 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "PopupPanel", +"class": "NewGamePanel", +"language": "GDScript", +"path": "res://src/NewGamePanel.gd" +}, { "base": "Node2D", "class": "Piece", "language": "GDScript", @@ -20,6 +25,7 @@ _global_script_classes=[ { "path": "res://src/Taquin.gd" } ] _global_script_class_icons={ +"NewGamePanel": "", "Piece": "", "Taquin": "" } diff --git a/src/Main.gd b/src/Main.gd index e6bc50e..c9c9013 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -1,33 +1,23 @@ extends Control -export var blur: int = 3 -export var blur_transition_duration: float = 1 - -var blur_amount: float = 0 -var blur_step: float = 0 - onready var taquin = $HSplitContainer/Taquin func _ready(): - $ColorRect.visible = false - blur_amount = 0 - blur_step = blur / blur_transition_duration print("Starting state: ", taquin.current_state_name()) - taquin.connect("state_changed", self, "_on_Taquin_state_changed") - -func _process(delta): - if blur_amount < blur: - blur_amount += delta * blur_step - print("blur: ", blur_amount) - $ColorRect.material.set_shader_param("blur_amount", blur_amount) func _on_Taquin_state_changed(previous, new): print("Taquin state: ", Taquin.State.keys()[previous], " -> ", Taquin.State.keys()[new]) match new: Taquin.State.WINNING: print("Solved!") - # TODO: wait for the animation to finish before game over - #$GameState.transition_to(GameState.State.GAME_OVER) Taquin.State.GAME_OVER: - $ColorRect.visible = true - $ColorRect.material.set_shader_param("blur_amount", blur_amount) + pass + +func _on_New_game_pressed(): + $NewGamePanel.popup_centered(OS.window_size * 0.9) + +func _on_NewGamePanel_about_to_show(): + $HSplitContainer/Taquin.set_process_input(false) + +func _on_NewGamePanel_popup_hide(): + $HSplitContainer/Taquin.set_process_input(true) diff --git a/src/Main.tscn b/src/Main.tscn index 7d3e127..b1a90bd 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -1,22 +1,10 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://src/Main.gd" type="Script" id=1] [ext_resource path="res://src/Taquin.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/NewGamePanel.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/taqin_theme.tres" type="Theme" id=5] -[sub_resource type="Shader" id=1] -code = "shader_type canvas_item; - -uniform float blur_amount : hint_range(0, 5); - -void fragment() { - COLOR = textureLod(SCREEN_TEXTURE, SCREEN_UV, blur_amount); -}" - -[sub_resource type="ShaderMaterial" id=2] -shader = SubResource( 1 ) -shader_param/blur_amount = null - [node name="Main" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 @@ -70,13 +58,9 @@ margin_right = 436.0 margin_bottom = 327.0 text = "HINTS" -[node name="ColorRect" type="ColorRect" parent="."] -material = SubResource( 2 ) -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_left = 0.510254 -margin_right = 0.510254 -__meta__ = { -"_edit_use_anchors_": false -} +[node name="NewGamePanel" parent="." instance=ExtResource( 3 )] [connection signal="state_changed" from="HSplitContainer/Taquin" to="." method="_on_Taquin_state_changed"] +[connection signal="pressed" from="HSplitContainer/VSplitContainer/New game" to="." method="_on_New_game_pressed"] +[connection signal="about_to_show" from="NewGamePanel" to="." method="_on_NewGamePanel_about_to_show"] +[connection signal="popup_hide" from="NewGamePanel" to="." method="_on_NewGamePanel_popup_hide"] +[connection signal="start_triggered" from="NewGamePanel" to="HSplitContainer/Taquin" method="_on_NewGamePanel_start_triggered"] diff --git a/src/NewGamePanel.gd b/src/NewGamePanel.gd new file mode 100644 index 0000000..883a1a5 --- /dev/null +++ b/src/NewGamePanel.gd @@ -0,0 +1,24 @@ +tool +class_name NewGamePanel +extends PopupPanel + +signal start_triggered(config) + +func _init(): + # TODO: load config with ConfigFile + # https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html + pass + +func _ready(): + # TODO: load previous preferences + $Panel/HBoxContainer/Normal.toggle_mode = true + pass + +func _on_Cancel_pressed(): + self.hide() + +func _on_Start_pressed(): + var config = {} + # TODO: save config + emit_signal("start_triggered", config) + self.hide() diff --git a/src/NewGamePanel.tscn b/src/NewGamePanel.tscn new file mode 100644 index 0000000..dcbea8e --- /dev/null +++ b/src/NewGamePanel.tscn @@ -0,0 +1,88 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/taqin_theme.tres" type="Theme" id=1] +[ext_resource path="res://src/difficulty_buttongroup.tres" type="ButtonGroup" id=2] +[ext_resource path="res://src/NewGamePanel.gd" type="Script" id=3] + +[node name="NewGamePanel" type="PopupPanel"] +anchor_right = 1.0 +anchor_bottom = 1.0 +theme = ExtResource( 1 ) +popup_exclusive = true +script = ExtResource( 3 ) + +[node name="Panel" type="Panel" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 4.0 +margin_right = -4.0 +margin_bottom = -4.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HBoxContainer" type="HBoxContainer" parent="Panel"] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -304.0 +margin_top = 30.0 +margin_right = 304.0 +margin_bottom = 70.0 +rect_min_size = Vector2( 0, 70 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Easy" type="Button" parent="Panel/HBoxContainer"] +margin_right = 200.0 +margin_bottom = 70.0 +rect_min_size = Vector2( 200, 70 ) +group = ExtResource( 2 ) +text = "Easy" + +[node name="Normal" type="Button" parent="Panel/HBoxContainer"] +margin_left = 204.0 +margin_right = 404.0 +margin_bottom = 70.0 +rect_min_size = Vector2( 200, 70 ) +toggle_mode = true +group = ExtResource( 2 ) +text = "Normal" + +[node name="Hard" type="Button" parent="Panel/HBoxContainer"] +margin_left = 408.0 +margin_right = 608.0 +margin_bottom = 70.0 +rect_min_size = Vector2( 200, 70 ) +toggle_mode = true +group = ExtResource( 2 ) +text = "Hard" + +[node name="Start" type="Button" parent="Panel"] +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -220.0 +margin_top = -90.0 +margin_right = -20.0 +margin_bottom = -20.0 +rect_min_size = Vector2( 200, 70 ) +text = "Start" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Cancel" type="Button" parent="Panel"] +anchor_top = 1.0 +anchor_bottom = 1.0 +margin_left = 20.0 +margin_top = -90.0 +margin_right = 220.0 +margin_bottom = -20.0 +rect_min_size = Vector2( 200, 70 ) +text = "Cancel" +flat = true +[connection signal="pressed" from="Panel/Start" to="." method="_on_Start_pressed"] +[connection signal="pressed" from="Panel/Cancel" to="." method="_on_Cancel_pressed"] diff --git a/src/Taquin.gd b/src/Taquin.gd index c7ba8a8..01f835b 100644 --- a/src/Taquin.gd +++ b/src/Taquin.gd @@ -99,9 +99,6 @@ func _ready() -> void: shuffle(difficulty) -func _process(delta): - pass - func _input(event): if $AnimationPlayer.is_playing(): # Disable input during animation @@ -331,3 +328,6 @@ func _on_AnimationPlayer_animation_finished(anim_name): commit_slide() update() check_solved() + +func _on_NewGamePanel_start_triggered(config): + pass # Replace with function body. diff --git a/src/difficulty_buttongroup.tres b/src/difficulty_buttongroup.tres new file mode 100644 index 0000000..0e55d74 --- /dev/null +++ b/src/difficulty_buttongroup.tres @@ -0,0 +1,3 @@ +[gd_resource type="ButtonGroup" format=2] + +[resource]