From 3369c37a0020e6507b4d42841a4809224d6e013f Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 8 Jun 2020 18:39:16 +0200 Subject: [PATCH] fix popup shifting --- src/Main.gd | 12 +++++++++++- src/NewGamePanel.gd | 8 +------- src/NewGamePanel.tscn | 27 +++++++++++---------------- src/Taquin.gd | 2 -- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/Main.gd b/src/Main.gd index 03bbbe6..9820c6c 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -3,6 +3,8 @@ extends Control onready var container = $GridContainer onready var taquin = $GridContainer/Taquin +var _first_popup_call := true + func _ready(): taquin.rect_min_size = get_viewport().get_visible_rect().size * (2.0 / 3.0) layout_reflow() @@ -84,7 +86,15 @@ func _on_Taquin_state_changed(previous, new): pass func _on_New_game_pressed(): - $NewGamePanel.popup_centered_ratio($NewGamePanel.window_scale_factor) + $NewGamePanel.rect_position = Vector2.ZERO + if _first_popup_call: + # We only call popup_centered() once, otherwise the popup shifts to the + # bottom right after each call. + $NewGamePanel.popup_centered_ratio($NewGamePanel.window_scale_factor) + _first_popup_call = false + else: + # After the 1st call, the position should be settled. + $NewGamePanel.popup() func _on_NewGamePanel_about_to_show(): taquin.set_process_input(false) diff --git a/src/NewGamePanel.gd b/src/NewGamePanel.gd index 9717d7d..c7b992f 100644 --- a/src/NewGamePanel.gd +++ b/src/NewGamePanel.gd @@ -33,7 +33,6 @@ onready var easy_button = $Panel/VBoxContainer/Difficulty/Easy onready var normal_button = $Panel/VBoxContainer/Difficulty/Normal onready var hard_button = $Panel/VBoxContainer/Difficulty/Hard onready var custom_button = $Panel/VBoxContainer/HBoxContainer/Custom -onready var edit_button = $Panel/Edit onready var columns_spinbox = $EditPanel/VBoxContainer/Columns/SpinBox onready var rows_spinbox = $EditPanel/VBoxContainer/Rows/SpinBox @@ -59,7 +58,7 @@ func _ready(): edit_panel.set("custom_styles/panel", modified_panel_style) panel.show() edit_panel.hide() - edit_button.hide() + edit_panel.hide() var button_max_width: int = $EditPanel/VBoxContainer.rect_size.x / 3.5 var button_width := min(200, button_max_width) @@ -70,14 +69,12 @@ func _ready(): custom_button.rect_min_size.x = button_width 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.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) @@ -193,9 +190,6 @@ func _on_NewGamePanel_about_to_show(): 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() diff --git a/src/NewGamePanel.tscn b/src/NewGamePanel.tscn index 43ed7b7..712000e 100644 --- a/src/NewGamePanel.tscn +++ b/src/NewGamePanel.tscn @@ -7,7 +7,7 @@ [ext_resource path="res://assets/fonts/OpenSans-SemiBold-24.tres" type="DynamicFont" id=5] [ext_resource path="res://assets/fonts/OpenSans-ExtraBold-28.tres" type="DynamicFont" id=6] -[sub_resource type="StyleBoxFlat" id=4] +[sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 1, 0.831373, 0.639216, 1 ) corner_radius_top_left = 20 corner_radius_top_right = 20 @@ -21,6 +21,8 @@ corner_radius_bottom_left = 20 [node name="NewGamePanel" type="PopupPanel"] anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 rect_pivot_offset = Vector2( 512, 300 ) theme = ExtResource( 1 ) popup_exclusive = true @@ -37,7 +39,7 @@ margin_top = 4.0 margin_right = -4.0 margin_bottom = -4.0 rect_clip_content = true -custom_styles/panel = SubResource( 4 ) +custom_styles/panel = SubResource( 1 ) __meta__ = { "_edit_use_anchors_": false } @@ -48,14 +50,16 @@ anchor_bottom = 1.0 margin_left = 15.0 margin_top = 15.0 margin_right = -15.0 -margin_bottom = -15.0 +margin_bottom = -110.0 +alignment = 1 __meta__ = { "_edit_use_anchors_": false } [node name="Difficulty" type="HBoxContainer" parent="Panel/VBoxContainer"] +margin_top = 159.0 margin_right = 986.0 -margin_bottom = 70.0 +margin_bottom = 229.0 rect_min_size = Vector2( 0, 70 ) rect_clip_content = true size_flags_horizontal = 3 @@ -101,9 +105,9 @@ toggle_mode = true group = ExtResource( 2 ) [node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"] -margin_top = 78.0 +margin_top = 237.0 margin_right = 986.0 -margin_bottom = 148.0 +margin_bottom = 307.0 [node name="Description" type="RichTextLabel" parent="Panel/VBoxContainer/HBoxContainer"] modulate = Color( 0.733333, 0.34902, 0.0666667, 1 ) @@ -171,14 +175,6 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Edit" parent="Panel" instance=ExtResource( 4 )] -visible = false -margin_left = 651.0 -margin_top = 126.0 -margin_right = -148.0 -margin_bottom = -350.0 -text = "Edit" - [node name="EditPanel" type="Panel" parent="."] visible = false anchor_right = 1.0 @@ -188,7 +184,7 @@ margin_top = 4.0 margin_right = -4.0 margin_bottom = -4.0 rect_clip_content = true -custom_styles/panel = SubResource( 4 ) +custom_styles/panel = SubResource( 1 ) __meta__ = { "_edit_use_anchors_": false } @@ -325,6 +321,5 @@ text = "Save" [connection signal="pressed" from="Panel/VBoxContainer/HBoxContainer/Custom" to="." method="_on_Custom_pressed"] [connection signal="pressed" from="Panel/Start" to="." method="_on_Start_pressed"] [connection signal="pressed" from="Panel/Cancel" to="." method="_on_Cancel_pressed"] -[connection signal="pressed" from="Panel/Edit" to="." method="_on_Edit_pressed"] [connection signal="pressed" from="EditPanel/Cancel" to="." method="_on_Edit_Cancel_pressed"] [connection signal="pressed" from="EditPanel/Save" to="." method="_on_Edit_Save_pressed"] diff --git a/src/Taquin.gd b/src/Taquin.gd index ed24c1d..31559af 100644 --- a/src/Taquin.gd +++ b/src/Taquin.gd @@ -67,7 +67,6 @@ func compute_padding(piece_size: int) -> Vector2: return p func _ready() -> void: - print_debug("") $AnimationPlayer/MockPiece.visible = false $Particles2D.emitting = false @@ -368,7 +367,6 @@ func load(saved_state) -> void: init(saved_state["pieces"], saved_state["hidden_piece"]) func init(pieces_order: Array, hidden_piece: int) -> void: - print_debug("") var piece_size: int = compute_piece_size() padding = compute_padding(piece_size) print("piece size: ", piece_size)