From bc156183342059a4ba25d5342268d8c28825ae8a Mon Sep 17 00:00:00 2001 From: Niraculix <75939533+Niraculix@users.noreply.github.com> Date: Sat, 29 Jun 2024 14:38:00 +0200 Subject: [PATCH 1/3] Main Menu Overhaul --- scenes/Objects/copy_category.tscn | 24 ++++ scenes/menu.tscn | 210 +++++++++++++++++++++++------- scripts/menu.gd | 30 +++-- 3 files changed, 208 insertions(+), 56 deletions(-) create mode 100644 scenes/Objects/copy_category.tscn diff --git a/scenes/Objects/copy_category.tscn b/scenes/Objects/copy_category.tscn new file mode 100644 index 0000000..fdbcbd0 --- /dev/null +++ b/scenes/Objects/copy_category.tscn @@ -0,0 +1,24 @@ +[gd_scene format=3 uid="uid://cchd6j6lk7w13"] + +[node name="CopyCategory" type="HBoxContainer"] +layout_direction = 3 +anchors_preset = 6 +anchor_left = 1.0 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = -160.0 +offset_top = -33.0 +offset_bottom = 34.0 +grow_horizontal = 0 +grow_vertical = 2 + +[node name="Amount" type="SpinBox" parent="."] +layout_mode = 2 + +[node name="Name" type="Label" parent="."] +layout_direction = 2 +layout_mode = 2 +theme_override_font_sizes/font_size = 30 +text = "Test" +max_lines_visible = 1 diff --git a/scenes/menu.tscn b/scenes/menu.tscn index a9e5d10..a84e20b 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,76 +1,192 @@ -[gd_scene load_steps=3 format=3 uid="uid://yyc1l3e78qgl"] +[gd_scene load_steps=7 format=3 uid="uid://yyc1l3e78qgl"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_f4qtc"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_r2tkh"] +bg_color = Color(0.239216, 0.239216, 0.239216, 1) +border_width_left = 8 +border_width_top = 8 +border_width_right = 8 +border_width_bottom = 8 +border_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_e6ve8"] +bg_color = Color(0.239216, 0.239216, 0.239216, 1) +border_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sdl70"] +bg_color = Color(0.239216, 0.239216, 0.239216, 1) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yhbp7"] +bg_color = Color(0.192157, 0.192157, 0.192157, 1) +border_width_left = 8 +border_width_top = 8 +border_width_right = 8 +border_width_bottom = 8 +border_color = Color(0, 0, 0, 1) + [sub_resource type="Theme" id="Theme_31w7n"] default_font_size = 70 [node name="Menu" type="CanvasLayer"] script = ExtResource("1_f4qtc") -[node name="Start" type="Button" parent="."] -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -360.0 -offset_top = -140.0 -offset_right = -60.0 -offset_bottom = -60.0 -grow_horizontal = 0 -grow_vertical = 0 -theme_override_font_sizes/font_size = 40 -text = "Spiel starten" +[node name="BG" type="Sprite2D" parent="."] -[node name="ModeSelect" type="OptionButton" parent="."] -offset_left = 56.0 -offset_top = 56.0 -offset_right = 101.0 -offset_bottom = 76.0 -theme_override_font_sizes/font_size = 40 -metadata/_edit_use_anchors_ = true +[node name="Play" type="Button" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -228.0 +offset_top = -214.0 +offset_right = 231.0 +offset_bottom = -86.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 60 +theme_override_styles/normal = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/hover = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/pressed = SubResource("StyleBoxFlat_e6ve8") +text = "Play" -[node name="CopyCategory" type="HBoxContainer" parent="."] -visible = false -layout_direction = 3 -offset_right = 100.0 -offset_bottom = 31.0 +[node name="Options" type="Button" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -229.0 +offset_top = -64.0 +offset_right = 230.0 +offset_bottom = 64.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 60 +theme_override_styles/normal = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/hover = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/pressed = SubResource("StyleBoxFlat_e6ve8") +text = "Options" -[node name="Amount" type="SpinBox" parent="CopyCategory"] -layout_mode = 2 +[node name="Quit" type="Button" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -227.0 +offset_top = 82.0 +offset_right = 232.0 +offset_bottom = 210.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 60 +theme_override_styles/normal = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/hover = SubResource("StyleBoxFlat_r2tkh") +theme_override_styles/pressed = SubResource("StyleBoxFlat_e6ve8") +theme_override_styles/focus = SubResource("StyleBoxFlat_sdl70") +text = "Quit Game" -[node name="Name" type="Label" parent="CopyCategory"] -layout_direction = 2 -layout_mode = 2 -max_lines_visible = 1 +[node name="RoundCreation" type="CanvasLayer" parent="."] -[node name="CategoryBox" type="ScrollContainer" parent="."] -layout_direction = 2 -anchors_preset = 1 +[node name="ColorRect" type="ColorRect" parent="RoundCreation"] +offset_left = -360.0 +offset_top = -210.0 +offset_right = 2263.0 +offset_bottom = 1201.0 +color = Color(0.137255, 0.137255, 0.137255, 0.431373) + +[node name="CreationMenu" type="Panel" parent="RoundCreation"] +anchors_preset = 6 anchor_left = 1.0 +anchor_top = 0.5 anchor_right = 1.0 -offset_left = -154.0 -offset_top = 48.0 -offset_right = -48.0 -offset_bottom = 362.0 +anchor_bottom = 0.5 +offset_left = -602.0 +offset_top = -436.0 +offset_right = -86.0 +offset_bottom = 473.0 grow_horizontal = 0 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_yhbp7") + +[node name="Start" type="Button" parent="RoundCreation/CreationMenu"] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = 1.0 +offset_top = -85.0 +offset_right = 217.0 +offset_bottom = -10.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_font_sizes/font_size = 30 +text = "Start Game" + +[node name="Cancel" type="Button" parent="RoundCreation/CreationMenu"] +layout_mode = 0 +offset_left = 45.0 +offset_top = 825.0 +offset_right = 233.0 +offset_bottom = 900.0 +theme_override_font_sizes/font_size = 30 +text = "Cancel" + +[node name="ModeSelect" type="OptionButton" parent="RoundCreation/CreationMenu"] +layout_mode = 1 +offset_left = 43.0 +offset_top = 44.0 +offset_right = 299.0 +offset_bottom = 114.0 +theme_override_font_sizes/font_size = 40 + +[node name="CategoryBox" type="ScrollContainer" parent="RoundCreation/CreationMenu"] +layout_direction = 2 +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 47.0 +offset_top = -186.5 +offset_right = 331.0 +offset_bottom = 306.499 +grow_vertical = 2 horizontal_scroll_mode = 0 -[node name="Categories" type="VBoxContainer" parent="CategoryBox"] +[node name="Categories" type="VBoxContainer" parent="RoundCreation/CreationMenu/CategoryBox"] layout_direction = 3 layout_mode = 2 alignment = 2 -[node name="RoundDuration" type="SpinBox" parent="."] -offset_left = 54.0 -offset_top = 190.0 -offset_right = 326.225 -offset_bottom = 278.0 +[node name="RoundDuration" type="SpinBox" parent="RoundCreation/CreationMenu"] +layout_mode = 1 +anchors_preset = 6 +anchor_left = 1.0 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = -472.0 +offset_top = -304.5 +offset_right = -199.775 +offset_bottom = -216.5 +grow_horizontal = 0 +grow_vertical = 2 theme = SubResource("Theme_31w7n") min_value = 5.0 max_value = 90.0 value = 30.0 suffix = "s" -[connection signal="pressed" from="Start" to="." method="on_btn_start_pressed"] +[connection signal="pressed" from="Play" to="." method="on_play_pressed"] +[connection signal="pressed" from="Quit" to="." method="on_quit_pressed"] +[connection signal="pressed" from="RoundCreation/CreationMenu/Start" to="." method="on_btn_start_pressed"] +[connection signal="pressed" from="RoundCreation/CreationMenu/Cancel" to="." method="on_cancel_pressed"] diff --git a/scripts/menu.gd b/scripts/menu.gd index 717684f..5a36b88 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -5,10 +5,10 @@ var round_duration: int ## ready is called when the node enters the scene tree for the first time. func _ready(): - $ModeSelect.add_item("Streamer VS Chat", 0) + $RoundCreation/CreationMenu/ModeSelect.add_item("Streamer VS Chat", 0) if (scene_manager.round_duration > 0): round_duration = scene_manager.round_duration - $RoundDuration.value = round_duration + $RoundCreation/CreationMenu/RoundDuration.value = round_duration api.category(on_category_response) ## on_category_response is called as when the categories api call completed. @@ -20,33 +20,45 @@ func on_category_response(success: bool, categories: Dictionary={}): ## update_category_list updates the category selection list with the given dictionary (mapping String to int). func update_category_list(categories: Dictionary): + const copy_category = preload("res://scenes/Objects/copy_category.tscn") for category in categories: - var c: HBoxContainer = $CopyCategory.duplicate() # # TODO: create new categories via code instread of copying a template from the tree + var c = copy_category.instantiate() c.get_child(0).max_value = categories[category] c.get_child(1).text = category c.show() - $CategoryBox/Categories.add_child(c) + $RoundCreation/CreationMenu/CategoryBox/Categories.add_child(c) ## on_btn_start_pressed is called when pressed the start game button. ## It collects all the selected categories and creates a new game on the server. func on_btn_start_pressed(): - $Start.disabled = true - round_duration = $RoundDuration.value + $RoundCreation/CreationMenu/Start.disabled = true + round_duration = $RoundCreation/CreationMenu/RoundDuration.value var categories: Dictionary = {} - for category: HBoxContainer in $CategoryBox/Categories.get_children(): + for category: HBoxContainer in $RoundCreation/CreationMenu/CategoryBox/Categories.get_children(): var amount: int = category.get_child(0).value if amount == 0: continue categories[category.get_child(1).text] = amount - + var game_data: Dictionary = {} game_data["categories"] = categories game_data["round_duration"] = round_duration api.game_start(JSON.stringify(game_data), on_game_start_response) + +func on_cancel_pressed(): + $RoundCreation.hide() func on_game_start_response(success: bool): if !success: print("failed to create new game!") - $Start.disabled = false + $RoundCreation/CreationMenu/Start.disabled = false return scene_manager.change_scene(self, "question") + + +func on_play_pressed(): + $RoundCreation.show() + + +func on_quit_pressed(): + get_tree().quit() From f16ae41c652ec13c60f94eb262c85160ae3af958 Mon Sep 17 00:00:00 2001 From: Niraculix <75939533+Niraculix@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:30:17 +0200 Subject: [PATCH 2/3] game creation & login polish --- scenes/Objects/copy_category.tscn | 24 ----- scenes/components/copy_category.tscn | 21 +++++ scenes/login.tscn | 28 +++++- scenes/menu.tscn | 134 +++++++++++++++++---------- scripts/login.gd | 7 ++ scripts/menu.gd | 12 +-- 6 files changed, 143 insertions(+), 83 deletions(-) delete mode 100644 scenes/Objects/copy_category.tscn create mode 100644 scenes/components/copy_category.tscn diff --git a/scenes/Objects/copy_category.tscn b/scenes/Objects/copy_category.tscn deleted file mode 100644 index fdbcbd0..0000000 --- a/scenes/Objects/copy_category.tscn +++ /dev/null @@ -1,24 +0,0 @@ -[gd_scene format=3 uid="uid://cchd6j6lk7w13"] - -[node name="CopyCategory" type="HBoxContainer"] -layout_direction = 3 -anchors_preset = 6 -anchor_left = 1.0 -anchor_top = 0.5 -anchor_right = 1.0 -anchor_bottom = 0.5 -offset_left = -160.0 -offset_top = -33.0 -offset_bottom = 34.0 -grow_horizontal = 0 -grow_vertical = 2 - -[node name="Amount" type="SpinBox" parent="."] -layout_mode = 2 - -[node name="Name" type="Label" parent="."] -layout_direction = 2 -layout_mode = 2 -theme_override_font_sizes/font_size = 30 -text = "Test" -max_lines_visible = 1 diff --git a/scenes/components/copy_category.tscn b/scenes/components/copy_category.tscn new file mode 100644 index 0000000..1d9a997 --- /dev/null +++ b/scenes/components/copy_category.tscn @@ -0,0 +1,21 @@ +[gd_scene format=3 uid="uid://cxdrsvvm35br2"] + +[node name="CopyCategory" type="HBoxContainer"] +layout_direction = 3 +offset_left = 20.0 +offset_right = 197.0 +offset_bottom = 49.0 +theme_override_constants/separation = 5 + +[node name="MarginContainer" type="MarginContainer" parent="."] +custom_minimum_size = Vector2(10, 0) +layout_mode = 2 + +[node name="Amount" type="SpinBox" parent="."] +layout_mode = 2 + +[node name="Name" type="Label" parent="."] +layout_direction = 2 +layout_mode = 2 +text = "adwawdawd" +max_lines_visible = 1 diff --git a/scenes/login.tscn b/scenes/login.tscn index 2428a4d..fcd24b8 100644 --- a/scenes/login.tscn +++ b/scenes/login.tscn @@ -1,8 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://2ysj36v7ruon"] +[gd_scene load_steps=4 format=3 uid="uid://2ysj36v7ruon"] [ext_resource type="Script" path="res://scripts/login.gd" id="1_4rhoe"] [ext_resource type="LabelSettings" uid="uid://jfhijl2ucmeq" path="res://assets/label_settings.tres" id="2_hmd01"] +[sub_resource type="LabelSettings" id="LabelSettings_cvayw"] +font_size = 20 +font_color = Color(0.984314, 0.443137, 0.345098, 1) + [node name="Login" type="CanvasLayer"] script = ExtResource("1_4rhoe") scene_after_login = "menu" @@ -47,7 +51,7 @@ grow_horizontal = 2 grow_vertical = 2 focus_next = NodePath("../Password") theme_override_font_sizes/font_size = 30 -placeholder_text = "EMail oder Benutzername" +placeholder_text = "E-Mail oder Benutzername" alignment = 1 expand_to_text_length = true context_menu_enabled = false @@ -93,7 +97,25 @@ grow_vertical = 0 focus_previous = NodePath("../Password") theme_override_font_sizes/font_size = 40 disabled = true -text = "Anmelden ->" +text = "Login" + +[node name="Error" type="Label" parent="LoginBox"] +visible = false +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -170.0 +offset_top = -108.0 +offset_right = 170.0 +offset_bottom = -85.0 +grow_horizontal = 2 +grow_vertical = 0 +text = "E-Mail/Benutzername oder Passwort sind falsch!" +label_settings = SubResource("LabelSettings_cvayw") +horizontal_alignment = 1 [connection signal="text_changed" from="LoginBox/EMail" to="." method="on_email_text_changed"] [connection signal="text_changed" from="LoginBox/Password" to="." method="on_password_text_changed"] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index a84e20b..f0b8d96 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://yyc1l3e78qgl"] +[gd_scene load_steps=10 format=3 uid="uid://yyc1l3e78qgl"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_f4qtc"] @@ -30,6 +30,25 @@ border_width_right = 8 border_width_bottom = 8 border_color = Color(0, 0, 0, 1) +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_r78im"] +bg_color = Color(0.0980392, 0.0980392, 0.0980392, 1) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_v1l70"] +bg_color = Color(0.137255, 0.137255, 0.137255, 1) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_eb82c"] +bg_color = Color(0.137255, 0.137255, 0.137255, 1) + [sub_resource type="Theme" id="Theme_31w7n"] default_font_size = 70 @@ -38,15 +57,26 @@ script = ExtResource("1_f4qtc") [node name="BG" type="Sprite2D" parent="."] -[node name="Play" type="Button" parent="."] +[node name="Buttons" type="Control" parent="."] +layout_mode = 3 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -228.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Play" type="Button" parent="Buttons"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -229.5 offset_top = -214.0 -offset_right = 231.0 +offset_right = 229.5 offset_bottom = -86.0 grow_horizontal = 2 grow_vertical = 2 @@ -56,15 +86,16 @@ theme_override_styles/hover = SubResource("StyleBoxFlat_r2tkh") theme_override_styles/pressed = SubResource("StyleBoxFlat_e6ve8") text = "Play" -[node name="Options" type="Button" parent="."] +[node name="Options" type="Button" parent="Buttons"] +layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -229.0 +offset_left = -229.5 offset_top = -64.0 -offset_right = 230.0 +offset_right = 229.5 offset_bottom = 64.0 grow_horizontal = 2 grow_vertical = 2 @@ -74,16 +105,17 @@ theme_override_styles/hover = SubResource("StyleBoxFlat_r2tkh") theme_override_styles/pressed = SubResource("StyleBoxFlat_e6ve8") text = "Options" -[node name="Quit" type="Button" parent="."] +[node name="Quit" type="Button" parent="Buttons"] +layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -227.0 -offset_top = 82.0 -offset_right = 232.0 -offset_bottom = 210.0 +offset_left = -229.5 +offset_top = 86.0 +offset_right = 229.5 +offset_bottom = 214.0 grow_horizontal = 2 grow_vertical = 2 theme_override_font_sizes/font_size = 60 @@ -94,53 +126,54 @@ theme_override_styles/focus = SubResource("StyleBoxFlat_sdl70") text = "Quit Game" [node name="RoundCreation" type="CanvasLayer" parent="."] +visible = false [node name="ColorRect" type="ColorRect" parent="RoundCreation"] -offset_left = -360.0 -offset_top = -210.0 -offset_right = 2263.0 -offset_bottom = 1201.0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 color = Color(0.137255, 0.137255, 0.137255, 0.431373) [node name="CreationMenu" type="Panel" parent="RoundCreation"] -anchors_preset = 6 -anchor_left = 1.0 +anchors_preset = 8 +anchor_left = 0.5 anchor_top = 0.5 -anchor_right = 1.0 +anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -602.0 -offset_top = -436.0 -offset_right = -86.0 -offset_bottom = 473.0 -grow_horizontal = 0 +offset_left = -258.0 +offset_top = -454.5 +offset_right = 258.0 +offset_bottom = 454.5 +grow_horizontal = 2 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_yhbp7") -[node name="Start" type="Button" parent="RoundCreation/CreationMenu"] -layout_mode = 1 -anchors_preset = 7 -anchor_left = 0.5 -anchor_top = 1.0 -anchor_right = 0.5 -anchor_bottom = 1.0 -offset_left = 1.0 -offset_top = -85.0 -offset_right = 217.0 -offset_bottom = -10.0 -grow_horizontal = 2 -grow_vertical = 0 -theme_override_font_sizes/font_size = 30 -text = "Start Game" - [node name="Cancel" type="Button" parent="RoundCreation/CreationMenu"] layout_mode = 0 offset_left = 45.0 -offset_top = 825.0 +offset_top = 821.0 offset_right = 233.0 -offset_bottom = 900.0 +offset_bottom = 896.0 theme_override_font_sizes/font_size = 30 +theme_override_styles/normal = SubResource("StyleBoxFlat_r78im") +theme_override_styles/hover = SubResource("StyleBoxFlat_v1l70") +theme_override_styles/pressed = SubResource("StyleBoxFlat_eb82c") text = "Cancel" +[node name="Start" type="Button" parent="RoundCreation/CreationMenu"] +layout_mode = 0 +offset_left = 286.0 +offset_top = 821.0 +offset_right = 474.0 +offset_bottom = 896.0 +theme_override_font_sizes/font_size = 30 +theme_override_styles/normal = SubResource("StyleBoxFlat_r78im") +theme_override_styles/hover = SubResource("StyleBoxFlat_v1l70") +theme_override_styles/pressed = SubResource("StyleBoxFlat_eb82c") +text = "Start Game" + [node name="ModeSelect" type="OptionButton" parent="RoundCreation/CreationMenu"] layout_mode = 1 offset_left = 43.0 @@ -155,17 +188,18 @@ layout_mode = 1 anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 -offset_left = 47.0 -offset_top = -186.5 -offset_right = 331.0 -offset_bottom = 306.499 +offset_left = 126.0 +offset_top = -182.5 +offset_right = 269.0 +offset_bottom = 310.5 grow_vertical = 2 +follow_focus = true horizontal_scroll_mode = 0 [node name="Categories" type="VBoxContainer" parent="RoundCreation/CreationMenu/CategoryBox"] layout_direction = 3 layout_mode = 2 -alignment = 2 +theme_override_constants/separation = 3 [node name="RoundDuration" type="SpinBox" parent="RoundCreation/CreationMenu"] layout_mode = 1 @@ -186,7 +220,7 @@ max_value = 90.0 value = 30.0 suffix = "s" -[connection signal="pressed" from="Play" to="." method="on_play_pressed"] -[connection signal="pressed" from="Quit" to="." method="on_quit_pressed"] -[connection signal="pressed" from="RoundCreation/CreationMenu/Start" to="." method="on_btn_start_pressed"] +[connection signal="pressed" from="Buttons/Play" to="." method="on_play_pressed"] +[connection signal="pressed" from="Buttons/Quit" to="." method="on_quit_pressed"] [connection signal="pressed" from="RoundCreation/CreationMenu/Cancel" to="." method="on_cancel_pressed"] +[connection signal="pressed" from="RoundCreation/CreationMenu/Start" to="." method="on_btn_start_pressed"] diff --git a/scripts/login.gd b/scripts/login.gd index 5cc7a3c..bac57cd 100644 --- a/scripts/login.gd +++ b/scripts/login.gd @@ -4,6 +4,10 @@ extends CanvasLayer ## on_email_text_changed is called when the user changed the text in the email input field. It is ## used to toggle the 'disabled' property of the Login button. +func _process(delta): + if Input.is_action_just_pressed("ui_accept") && !$LoginBox/Login.disabled: + on_login_button_pressed() + func on_email_text_changed(email_text: String): if email_text == ""||$LoginBox/Password.text == "": $LoginBox/Login.disabled = true @@ -23,11 +27,14 @@ func on_login_button_pressed(): $LoginBox/Login.disabled = true var auth: String = Marshalls.utf8_to_base64("%s:%s" % [$LoginBox/EMail.text, $LoginBox/Password.text]) api.login(auth, on_login_reponse) + DisplayServer.cursor_set_shape(DisplayServer.CURSOR_BUSY) ## on_login_reponse is called as when the login api call completed. func on_login_reponse(success: bool, _username: String=""): + DisplayServer.cursor_set_shape(DisplayServer.CURSOR_ARROW) if !success: print("login failed!") + $LoginBox/Error.show() $LoginBox/Login.disabled = false return diff --git a/scripts/menu.gd b/scripts/menu.gd index 5a36b88..db5869a 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -2,6 +2,7 @@ class_name Menu extends CanvasLayer ## Time for each round in seconds var round_duration: int +const CATEGORY = preload("res://scenes/components/copy_category.tscn") ## ready is called when the node enters the scene tree for the first time. func _ready(): @@ -20,11 +21,10 @@ func on_category_response(success: bool, categories: Dictionary={}): ## update_category_list updates the category selection list with the given dictionary (mapping String to int). func update_category_list(categories: Dictionary): - const copy_category = preload("res://scenes/Objects/copy_category.tscn") for category in categories: - var c = copy_category.instantiate() - c.get_child(0).max_value = categories[category] - c.get_child(1).text = category + var c = CATEGORY.instantiate() + c.get_child(1).max_value = categories[category] + c.get_child(2).text = category c.show() $RoundCreation/CreationMenu/CategoryBox/Categories.add_child(c) @@ -35,10 +35,10 @@ func on_btn_start_pressed(): round_duration = $RoundCreation/CreationMenu/RoundDuration.value var categories: Dictionary = {} for category: HBoxContainer in $RoundCreation/CreationMenu/CategoryBox/Categories.get_children(): - var amount: int = category.get_child(0).value + var amount: int = category.get_child(1).value if amount == 0: continue - categories[category.get_child(1).text] = amount + categories[category.get_child(2).text] = amount var game_data: Dictionary = {} game_data["categories"] = categories From be12be24d1482484b3e7e3f01e8c67e26b580ffb Mon Sep 17 00:00:00 2001 From: Niraculix <75939533+Niraculix@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:37:53 +0200 Subject: [PATCH 3/3] formatting --- scripts/menu.gd | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/menu.gd b/scripts/menu.gd index db5869a..f842317 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -39,12 +39,12 @@ func on_btn_start_pressed(): if amount == 0: continue categories[category.get_child(2).text] = amount - + var game_data: Dictionary = {} game_data["categories"] = categories game_data["round_duration"] = round_duration api.game_start(JSON.stringify(game_data), on_game_start_response) - + func on_cancel_pressed(): $RoundCreation.hide() @@ -55,10 +55,8 @@ func on_game_start_response(success: bool): return scene_manager.change_scene(self, "question") - func on_play_pressed(): $RoundCreation.show() - func on_quit_pressed(): get_tree().quit()