Skip to content

Commit

Permalink
New menu pog
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZajicek committed Mar 3, 2023
1 parent 326405a commit 58dea3d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 67 deletions.
18 changes: 9 additions & 9 deletions src/InfiniteModeMain.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ extends Node2D
@onready var grid: Grid = $Grid
@export var polyomino: PackedScene = preload("res://Polyomino.tscn")

var dragging: Polyomino
var offset: Vector2
var dragging: Polyomino
var score: int = 0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
randomize()
if Globals.top_score.top_scores.has(Globals.poly_size):
$UserInterface/TopScore.text = "Top Score for size " + str(Globals.poly_size) + ": \n" + str(Globals.top_score.top_scores[Globals.poly_size])
$CanvasLayer/UserInterface/HBoxContainer/TopScore.text = "Top Score for size " + str(Globals.poly_size) + ": \n" + str(Globals.top_score.top_scores[Globals.poly_size])
else:
$UserInterface/TopScore.text = "Top Score for size " + str(Globals.poly_size) + ": \n0"
$UserInterface/QuitButton.pressed.connect(save_and_quit.bind())
$UserInterface/RestartButton.pressed.connect(save_and_reload.bind())
$CanvasLayer/UserInterface/HBoxContainer/TopScore.text = "Top Score for size " + str(Globals.poly_size) + ": \n0"
$CanvasLayer/UserInterface/HBoxContainer/QuitButton.pressed.connect(save_and_quit.bind())
$CanvasLayer/UserInterface/HBoxContainer/RestartButton.pressed.connect(save_and_reload.bind())

func _process(_delta: float) -> void:
if not get_tree().get_nodes_in_group("polyominoes").size():
Expand Down Expand Up @@ -83,7 +83,7 @@ func bind_polyominoes():

func _on_Poly_destroyed(_score: int):
score += _score
$UserInterface/ScoreLabel.text = "Current Score: \n" + str(score)
$CanvasLayer/UserInterface/HBoxContainer/ScoreLabel.text = "Current Score: \n" + str(score)

func test_if_legal(_polyomino: Polyomino, _position: Vector2):
for poly in _polyomino.get_children():
Expand All @@ -104,10 +104,10 @@ func test_for_any_legal_moves():
var _position: Vector2 = Vector2(x, y) * Globals.tile_size
if test_if_legal(_polyomino, _position):
legal_moves += 1
$UserInterface/PossibleMoves.text = "Possible Moves: \n" + str(legal_moves)
$CanvasLayer/UserInterface/HBoxContainer/PossibleMoves.text = "Possible Moves: \n" + str(legal_moves)
if legal_moves == 0:
save()
$UserInterface/PossibleMoves.text = "No more moves,\nrestart? -->"
$CanvasLayer/UserInterface/HBoxContainer/PossibleMoves.text = "No more moves,\nrestart? -->"


func save():
Expand All @@ -127,7 +127,7 @@ func save_and_reload():

func save_and_quit():
save()
get_tree().change_scene_to_file("res://MainMenu.tscn")
get_tree().change_scene_to_file("res://InfiniteModeMainMenu.tscn")



91 changes: 41 additions & 50 deletions src/InfiniteModeMain.tscn
Original file line number Diff line number Diff line change
@@ -1,78 +1,69 @@
[gd_scene load_steps=3 format=3 uid="uid://dxcwofo851bx3"]
[gd_scene load_steps=4 format=3 uid="uid://dxcwofo851bx3"]

[ext_resource type="Script" path="res://InfiniteModeMain.gd" id="1_l1gu7"]
[ext_resource type="PackedScene" uid="uid://t6a4vln63jxa" path="res://Grid.tscn" id="2_1uqbt"]
[ext_resource type="Theme" uid="uid://b2mieut3kuy46" path="res://MainMenuTheme.tres" id="3_g6g1x"]

[node name="InfiniteModeMain" type="Node2D"]
script = ExtResource("1_l1gu7")

[node name="Grid" parent="." instance=ExtResource("2_1uqbt")]
position = Vector2(64, 128)
position = Vector2(256, 256)
grid_size = Vector2(10, 10)

[node name="UserInterface" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="SpawnPoints" type="Node2D" parent="."]

[node name="Marker2D" type="Marker2D" parent="SpawnPoints"]
position = Vector2(64, 970)

[node name="Marker2D2" type="Marker2D" parent="SpawnPoints"]
position = Vector2(896, 970)

[node name="Marker2D3" type="Marker2D" parent="SpawnPoints"]
position = Vector2(512, 970)

[node name="CanvasLayer" type="CanvasLayer" parent="."]

[node name="UserInterface" type="MarginContainer" parent="CanvasLayer"]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 46.0
grow_horizontal = 2
theme = ExtResource("3_g6g1x")

[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/UserInterface"]
layout_mode = 2
theme_override_constants/separation = 15
alignment = 1

[node name="QuitButton" type="Button" parent="CanvasLayer/UserInterface/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Quit"

[node name="ScoreLabel" type="RichTextLabel" parent="UserInterface"]
layout_mode = 0
offset_left = 128.0
offset_top = 32.0
offset_right = 168.0
offset_bottom = 58.0
[node name="ScoreLabel" type="RichTextLabel" parent="CanvasLayer/UserInterface/HBoxContainer"]
layout_mode = 2
text = "Current Score:
0"
fit_content = true
scroll_active = false
autowrap_mode = 0

[node name="TopScore" type="RichTextLabel" parent="UserInterface"]
layout_mode = 0
offset_left = 320.0
offset_top = 32.0
offset_right = 400.0
offset_bottom = 84.0
[node name="TopScore" type="RichTextLabel" parent="CanvasLayer/UserInterface/HBoxContainer"]
layout_mode = 2
text = "Top Score:
0"
fit_content = true
autowrap_mode = 0

[node name="PossibleMoves" type="RichTextLabel" parent="UserInterface"]
layout_mode = 0
offset_left = 512.0
offset_top = 32.0
offset_right = 635.0
offset_bottom = 84.0
[node name="PossibleMoves" type="RichTextLabel" parent="CanvasLayer/UserInterface/HBoxContainer"]
layout_mode = 2
text = "Possible Moves:
0"
fit_content = true
autowrap_mode = 0

[node name="QuitButton" type="Button" parent="UserInterface"]
layout_mode = 0
offset_left = 40.0
offset_top = 32.0
offset_right = 105.0
offset_bottom = 63.0
text = "Quit"

[node name="RestartButton" type="Button" parent="UserInterface"]
layout_mode = 0
offset_left = 640.0
offset_top = 32.0
offset_right = 705.0
offset_bottom = 63.0
[node name="RestartButton" type="Button" parent="CanvasLayer/UserInterface/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Restart"

[node name="SpawnPoints" type="Node2D" parent="."]

[node name="Marker2D" type="Marker2D" parent="SpawnPoints"]
position = Vector2(64, 832)

[node name="Marker2D2" type="Marker2D" parent="SpawnPoints"]
position = Vector2(256, 1088)

[node name="Marker2D3" type="Marker2D" parent="SpawnPoints"]
position = Vector2(512, 832)
2 changes: 1 addition & 1 deletion src/InfiniteModeMainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extends Control
func _ready() -> void:
top_score_label.text = "Top Score: \n" + str(Globals.top_score.top_score)
start_button.pressed.connect(start_game.bind())
quit_button.pressed.connect(get_tree().quit)
quit_button.pressed.connect(func(): get_tree().change_scene_to_file("res://MainMenu.tscn"))
difficulty_slider.value_changed.connect(update_difficulty_label)
difficulty_slider.value = Globals.poly_size as int
color_picker_button.color_changed.connect(change_background.bind())
Expand Down
12 changes: 8 additions & 4 deletions src/InfiniteModeMainMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ theme_override_constants/separation = 16
alignment = 1

[node name="Title" type="RichTextLabel" parent="VBoxContainer"]
visible = false
layout_mode = 2
size_flags_vertical = 3
theme_override_font_sizes/normal_font_size = 50
Expand All @@ -72,10 +73,6 @@ horizontal_alignment = 1
layout_mode = 2
text = "Start Game"

[node name="QuitButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
text = "Quit"

[node name="DifficultyLabel" type="Label" parent="VBoxContainer"]
layout_mode = 2
text = "Max Block Size:
Expand All @@ -98,16 +95,23 @@ text = "Top Score for size 6:
horizontal_alignment = 1

[node name="ColourLabel" type="Label" parent="VBoxContainer"]
visible = false
layout_mode = 2
text = "Background Colour Picker:"
horizontal_alignment = 1

[node name="ColorPickerButton" type="ColorPickerButton" parent="VBoxContainer"]
visible = false
layout_mode = 2
text = "Background Colour"
color = Color(0.301961, 0.301961, 0.301961, 1)

[node name="GridTileColorPicker" type="ColorPickerButton" parent="VBoxContainer"]
visible = false
layout_mode = 2
text = "Background Colour"
color = Color(0, 0, 1, 0.490196)

[node name="QuitButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
text = "Back"
8 changes: 8 additions & 0 deletions src/MainMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ layout_mode = 2
text = "Infinite Mode"

[node name="PuzzleMode" type="Button" parent="MainMenu/MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2
text = "Puzzle Mode"

Expand All @@ -65,10 +66,17 @@ layout_mode = 2
text = "Settings Menu"

[node name="TopScores" type="Button" parent="MainMenu/MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2
text = "Top Scores"

[node name="ExitGame" type="Button" parent="MainMenu/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 10
text = "Exit Game"

[node name="Label" type="Label" parent="MainMenu/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "v0.2.0"
horizontal_alignment = 2
vertical_alignment = 2
4 changes: 4 additions & 0 deletions src/Poly.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ extends Area2D
var score: int = 1
@onready var label: Label = $Label
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var sprite_2d: Sprite2D = $Sprite2D


signal destroy_poly

func _ready() -> void:
sprite_2d.texture = Globals.user_settings.block_texture
#func _physics_process(_delta: float) -> void:
# drop_shadow.position = snapped(position, Globals.tile_size)

Expand Down
6 changes: 5 additions & 1 deletion src/Polyomino.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func _ready() -> void:
generate_shape()
connect_with_poly_children()

scale = Vector2(0.5, 0.5)

func generate_shape() -> void:
var size_poly = polyforms_resource.polyominoes[size]
Expand Down Expand Up @@ -58,9 +59,10 @@ func _on_ClickableChild_event(_viewport: Node, event: InputEvent, _shape_idx: in
get_tree().get_root().set_input_as_handled()
original_position = position
offset = position - event.position
offset.y -= Globals.tile_size.y
offset.y -= Globals.user_settings.pickup_offset
dragging = self
emit_signal("picked_up", self, offset)
scale = Vector2(1, 1)
dragging.drop_shadow.visible = true
z_index = 1

Expand All @@ -75,6 +77,8 @@ func _unhandled_input(event: InputEvent) -> void:
if child.has_overlapping_areas():
position = original_position
emit_signal("put_down", self, position, original_position)

scale = Vector2(0.5, 0.5)
dragging.drop_shadow.visible = false
dragging = null
z_index = 0
2 changes: 1 addition & 1 deletion src/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extends CanvasLayer
@onready var exit_game: Button = $MainMenu/MarginContainer/VBoxContainer/ExitGame


@onready var infinite_mode_scene: PackedScene = load("res://InfiniteModeMain.tscn")
@onready var infinite_mode_scene: PackedScene = load("res://InfiniteModeMainMenu.tscn")

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand Down
5 changes: 5 additions & 0 deletions src/settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ const BASE_BLOCK_SIZE_LABEL: String = "[center]Max Block Size: "

@onready var difficulty_label: RichTextLabel = $MarginContainer/VBoxContainer/GridContainer/DifficultyLabel
@onready var difficulty_slider: HSlider = $MarginContainer/VBoxContainer/GridContainer/DifficultySlider
@onready var offset_slider: HSlider = $MarginContainer/VBoxContainer/GridContainer/OffsetSlider

@onready var change_block_texture_button: TextureButton = $MarginContainer/VBoxContainer/GridContainer/ChangeBlockTextureButton
@onready var back_button: Button = $MarginContainer/VBoxContainer/NavigationButtons/BackButton

@onready var theme_menu: = preload("res://theme_menu.tscn")

func _ready() -> void:

change_block_texture_button.texture_normal = Globals.user_settings.block_texture
change_block_texture_button.pressed.connect(func(): get_tree().change_scene_to_packed(theme_menu))
difficulty_slider.value_changed.connect(func(value): difficulty_label.text = BASE_BLOCK_SIZE_LABEL + str(value) )
back_button.pressed.connect(func(): get_tree().change_scene_to_file("res://MainMenu.tscn"))
offset_slider.value = Globals.user_settings.pickup_offset
offset_slider.value_changed.connect(func(value): Globals.user_settings.pickup_offset = value)
36 changes: 35 additions & 1 deletion src/settings_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://ooqp1e2ogghe"]
[gd_scene load_steps=7 format=3 uid="uid://ooqp1e2ogghe"]

[ext_resource type="Script" path="res://settings_menu.gd" id="1_5seey"]
[ext_resource type="Theme" uid="uid://b2mieut3kuy46" path="res://MainMenuTheme.tres" id="1_a2qbf"]
Expand All @@ -22,6 +22,22 @@ expand_margin_top = 10.0
expand_margin_right = 10.0
expand_margin_bottom = 10.0

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fncdd"]
border_width_left = 20
border_width_top = 20
border_width_right = 20
border_width_bottom = 20
border_color = Color(0.196078, 0.196078, 0.196078, 1)
border_blend = true
corner_radius_top_left = 3
corner_radius_top_right = 3
corner_radius_bottom_right = 3
corner_radius_bottom_left = 3
expand_margin_left = 10.0
expand_margin_top = 10.0
expand_margin_right = 10.0
expand_margin_bottom = 10.0

[node name="SettingsMenu" type="CanvasLayer"]
script = ExtResource("1_5seey")

Expand Down Expand Up @@ -51,13 +67,15 @@ size_flags_vertical = 4
columns = 2

[node name="DifficultyLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/GridContainer"]
visible = false
layout_mode = 2
bbcode_enabled = true
text = "[center]Max Block Size: 6"
fit_content = true
scroll_active = false

[node name="DifficultySlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
visible = false
layout_mode = 2
theme_override_styles/slider = SubResource("StyleBoxFlat_bir1q")
min_value = 4.0
Expand All @@ -66,6 +84,22 @@ value = 6.0
tick_count = 7
ticks_on_borders = true

[node name="OffsetLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/GridContainer"]
layout_mode = 2
bbcode_enabled = true
text = "[center]Offset On Pickup:"
fit_content = true
scroll_active = false

[node name="OffsetSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
layout_mode = 2
theme_override_styles/slider = SubResource("StyleBoxFlat_fncdd")
max_value = 128.0
step = 32.0
value = 64.0
tick_count = 5
ticks_on_borders = true

[node name="BackgroundColourLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer/GridContainer"]
layout_mode = 2
bbcode_enabled = true
Expand Down
Loading

0 comments on commit 58dea3d

Please sign in to comment.