fix popup shifting
This commit is contained in:
parent
c8bd0412f3
commit
3369c37a00
10
src/Main.gd
10
src/Main.gd
|
@ -3,6 +3,8 @@ extends Control
|
||||||
onready var container = $GridContainer
|
onready var container = $GridContainer
|
||||||
onready var taquin = $GridContainer/Taquin
|
onready var taquin = $GridContainer/Taquin
|
||||||
|
|
||||||
|
var _first_popup_call := true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
taquin.rect_min_size = get_viewport().get_visible_rect().size * (2.0 / 3.0)
|
taquin.rect_min_size = get_viewport().get_visible_rect().size * (2.0 / 3.0)
|
||||||
layout_reflow()
|
layout_reflow()
|
||||||
|
@ -84,7 +86,15 @@ func _on_Taquin_state_changed(previous, new):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _on_New_game_pressed():
|
func _on_New_game_pressed():
|
||||||
|
$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)
|
$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():
|
func _on_NewGamePanel_about_to_show():
|
||||||
taquin.set_process_input(false)
|
taquin.set_process_input(false)
|
||||||
|
|
|
@ -33,7 +33,6 @@ onready var easy_button = $Panel/VBoxContainer/Difficulty/Easy
|
||||||
onready var normal_button = $Panel/VBoxContainer/Difficulty/Normal
|
onready var normal_button = $Panel/VBoxContainer/Difficulty/Normal
|
||||||
onready var hard_button = $Panel/VBoxContainer/Difficulty/Hard
|
onready var hard_button = $Panel/VBoxContainer/Difficulty/Hard
|
||||||
onready var custom_button = $Panel/VBoxContainer/HBoxContainer/Custom
|
onready var custom_button = $Panel/VBoxContainer/HBoxContainer/Custom
|
||||||
onready var edit_button = $Panel/Edit
|
|
||||||
|
|
||||||
onready var columns_spinbox = $EditPanel/VBoxContainer/Columns/SpinBox
|
onready var columns_spinbox = $EditPanel/VBoxContainer/Columns/SpinBox
|
||||||
onready var rows_spinbox = $EditPanel/VBoxContainer/Rows/SpinBox
|
onready var rows_spinbox = $EditPanel/VBoxContainer/Rows/SpinBox
|
||||||
|
@ -59,7 +58,7 @@ func _ready():
|
||||||
edit_panel.set("custom_styles/panel", modified_panel_style)
|
edit_panel.set("custom_styles/panel", modified_panel_style)
|
||||||
panel.show()
|
panel.show()
|
||||||
edit_panel.hide()
|
edit_panel.hide()
|
||||||
edit_button.hide()
|
edit_panel.hide()
|
||||||
|
|
||||||
var button_max_width: int = $EditPanel/VBoxContainer.rect_size.x / 3.5
|
var button_max_width: int = $EditPanel/VBoxContainer.rect_size.x / 3.5
|
||||||
var button_width := min(200, button_max_width)
|
var button_width := min(200, button_max_width)
|
||||||
|
@ -70,14 +69,12 @@ func _ready():
|
||||||
custom_button.rect_min_size.x = button_width
|
custom_button.rect_min_size.x = button_width
|
||||||
|
|
||||||
func fade_in():
|
func fade_in():
|
||||||
rect_pivot_offset = rect_size / 2
|
|
||||||
tween.remove_all()
|
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, "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.interpolate_property(self, "modulate:a", 0.0, 1.0, fade_duration, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||||
tween.start()
|
tween.start()
|
||||||
|
|
||||||
func fade_out():
|
func fade_out():
|
||||||
rect_pivot_offset = rect_size / 2
|
|
||||||
tween.remove_all()
|
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, "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_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)
|
rows_spinbox.value = preferences.get_value("game", "custom_rows", normal_rows)
|
||||||
iterations_spinbox.value = preferences.get_value("game", "custom_shuffle_iterations", normal_iterations)
|
iterations_spinbox.value = preferences.get_value("game", "custom_shuffle_iterations", normal_iterations)
|
||||||
|
|
||||||
if custom_button.pressed:
|
|
||||||
edit_button.show()
|
|
||||||
|
|
||||||
_update_description()
|
_update_description()
|
||||||
|
|
||||||
# $Panel/Start.grab_focus()
|
# $Panel/Start.grab_focus()
|
||||||
|
|
|
@ -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-SemiBold-24.tres" type="DynamicFont" id=5]
|
||||||
[ext_resource path="res://assets/fonts/OpenSans-ExtraBold-28.tres" type="DynamicFont" id=6]
|
[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 )
|
bg_color = Color( 1, 0.831373, 0.639216, 1 )
|
||||||
corner_radius_top_left = 20
|
corner_radius_top_left = 20
|
||||||
corner_radius_top_right = 20
|
corner_radius_top_right = 20
|
||||||
|
@ -21,6 +21,8 @@ corner_radius_bottom_left = 20
|
||||||
[node name="NewGamePanel" type="PopupPanel"]
|
[node name="NewGamePanel" type="PopupPanel"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
rect_pivot_offset = Vector2( 512, 300 )
|
rect_pivot_offset = Vector2( 512, 300 )
|
||||||
theme = ExtResource( 1 )
|
theme = ExtResource( 1 )
|
||||||
popup_exclusive = true
|
popup_exclusive = true
|
||||||
|
@ -37,7 +39,7 @@ margin_top = 4.0
|
||||||
margin_right = -4.0
|
margin_right = -4.0
|
||||||
margin_bottom = -4.0
|
margin_bottom = -4.0
|
||||||
rect_clip_content = true
|
rect_clip_content = true
|
||||||
custom_styles/panel = SubResource( 4 )
|
custom_styles/panel = SubResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
@ -48,14 +50,16 @@ anchor_bottom = 1.0
|
||||||
margin_left = 15.0
|
margin_left = 15.0
|
||||||
margin_top = 15.0
|
margin_top = 15.0
|
||||||
margin_right = -15.0
|
margin_right = -15.0
|
||||||
margin_bottom = -15.0
|
margin_bottom = -110.0
|
||||||
|
alignment = 1
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Difficulty" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
[node name="Difficulty" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||||
|
margin_top = 159.0
|
||||||
margin_right = 986.0
|
margin_right = 986.0
|
||||||
margin_bottom = 70.0
|
margin_bottom = 229.0
|
||||||
rect_min_size = Vector2( 0, 70 )
|
rect_min_size = Vector2( 0, 70 )
|
||||||
rect_clip_content = true
|
rect_clip_content = true
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
@ -101,9 +105,9 @@ toggle_mode = true
|
||||||
group = ExtResource( 2 )
|
group = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||||
margin_top = 78.0
|
margin_top = 237.0
|
||||||
margin_right = 986.0
|
margin_right = 986.0
|
||||||
margin_bottom = 148.0
|
margin_bottom = 307.0
|
||||||
|
|
||||||
[node name="Description" type="RichTextLabel" parent="Panel/VBoxContainer/HBoxContainer"]
|
[node name="Description" type="RichTextLabel" parent="Panel/VBoxContainer/HBoxContainer"]
|
||||||
modulate = Color( 0.733333, 0.34902, 0.0666667, 1 )
|
modulate = Color( 0.733333, 0.34902, 0.0666667, 1 )
|
||||||
|
@ -171,14 +175,6 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_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="."]
|
[node name="EditPanel" type="Panel" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
@ -188,7 +184,7 @@ margin_top = 4.0
|
||||||
margin_right = -4.0
|
margin_right = -4.0
|
||||||
margin_bottom = -4.0
|
margin_bottom = -4.0
|
||||||
rect_clip_content = true
|
rect_clip_content = true
|
||||||
custom_styles/panel = SubResource( 4 )
|
custom_styles/panel = SubResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_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/VBoxContainer/HBoxContainer/Custom" to="." method="_on_Custom_pressed"]
|
||||||
[connection signal="pressed" from="Panel/Start" to="." method="_on_Start_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/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/Cancel" to="." method="_on_Edit_Cancel_pressed"]
|
||||||
[connection signal="pressed" from="EditPanel/Save" to="." method="_on_Edit_Save_pressed"]
|
[connection signal="pressed" from="EditPanel/Save" to="." method="_on_Edit_Save_pressed"]
|
||||||
|
|
|
@ -67,7 +67,6 @@ func compute_padding(piece_size: int) -> Vector2:
|
||||||
return p
|
return p
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
print_debug("")
|
|
||||||
$AnimationPlayer/MockPiece.visible = false
|
$AnimationPlayer/MockPiece.visible = false
|
||||||
$Particles2D.emitting = false
|
$Particles2D.emitting = false
|
||||||
|
|
||||||
|
@ -368,7 +367,6 @@ func load(saved_state) -> void:
|
||||||
init(saved_state["pieces"], saved_state["hidden_piece"])
|
init(saved_state["pieces"], saved_state["hidden_piece"])
|
||||||
|
|
||||||
func init(pieces_order: Array, hidden_piece: int) -> void:
|
func init(pieces_order: Array, hidden_piece: int) -> void:
|
||||||
print_debug("")
|
|
||||||
var piece_size: int = compute_piece_size()
|
var piece_size: int = compute_piece_size()
|
||||||
padding = compute_padding(piece_size)
|
padding = compute_padding(piece_size)
|
||||||
print("piece size: ", piece_size)
|
print("piece size: ", piece_size)
|
||||||
|
|
Loading…
Reference in a new issue