Skip to content

Commit 12f51b7

Browse files
committed
Merge branch 'main' into discord-presence
2 parents f378497 + 1239106 commit 12f51b7

File tree

7 files changed

+161
-84
lines changed

7 files changed

+161
-84
lines changed

assets/theme_small.tres

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[gd_resource type="Theme" format=3 uid="uid://bbjcf4njtb4tm"]
2+
3+
[resource]
4+
default_font_size = 20

scenes/menu.tscn

+95-69
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[gd_scene load_steps=10 format=3 uid="uid://yyc1l3e78qgl"]
22

33
[ext_resource type="Script" path="res://scripts/menu.gd" id="1_f4qtc"]
4+
[ext_resource type="Theme" uid="uid://bbjcf4njtb4tm" path="res://assets/theme_small.tres" id="2_7ph5j"]
45

56
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_r2tkh"]
67
bg_color = Color(0.239216, 0.239216, 0.239216, 1)
@@ -49,9 +50,6 @@ border_color = Color(0, 0, 0, 1)
4950
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_eb82c"]
5051
bg_color = Color(0.137255, 0.137255, 0.137255, 1)
5152

52-
[sub_resource type="Theme" id="Theme_31w7n"]
53-
default_font_size = 70
54-
5553
[node name="Menu" type="CanvasLayer"]
5654
script = ExtResource("1_f4qtc")
5755

@@ -126,7 +124,6 @@ theme_override_styles/focus = SubResource("StyleBoxFlat_sdl70")
126124
text = "Quit Game"
127125

128126
[node name="RoundCreation" type="CanvasLayer" parent="."]
129-
visible = false
130127

131128
[node name="ColorRect" type="ColorRect" parent="RoundCreation"]
132129
anchors_preset = 15
@@ -137,89 +134,118 @@ grow_vertical = 2
137134
color = Color(0.137255, 0.137255, 0.137255, 0.431373)
138135

139136
[node name="CreationMenu" type="Panel" parent="RoundCreation"]
140-
anchors_preset = 8
141-
anchor_left = 0.5
142-
anchor_top = 0.5
143-
anchor_right = 0.5
144-
anchor_bottom = 0.5
145-
offset_left = -258.0
146-
offset_top = -454.5
147-
offset_right = 258.0
148-
offset_bottom = 454.5
137+
anchors_preset = 15
138+
anchor_right = 1.0
139+
anchor_bottom = 1.0
140+
offset_left = 660.0
141+
offset_top = 80.0
142+
offset_right = -660.0
143+
offset_bottom = -80.0
149144
grow_horizontal = 2
150145
grow_vertical = 2
151146
theme_override_styles/panel = SubResource("StyleBoxFlat_yhbp7")
152147

148+
[node name="ModeSelect" type="OptionButton" parent="RoundCreation/CreationMenu"]
149+
layout_mode = 1
150+
offset_left = 40.0
151+
offset_top = 100.0
152+
offset_right = 180.0
153+
offset_bottom = 140.0
154+
theme = ExtResource("2_7ph5j")
155+
theme_override_font_sizes/font_size = 40
156+
157+
[node name="Label" type="Label" parent="RoundCreation/CreationMenu/ModeSelect"]
158+
layout_mode = 1
159+
offset_top = -40.0
160+
offset_right = 120.0
161+
theme = ExtResource("2_7ph5j")
162+
text = "Game Mode"
163+
vertical_alignment = 1
164+
165+
[node name="RoundDuration" type="SpinBox" parent="RoundCreation/CreationMenu"]
166+
layout_mode = 1
167+
offset_left = 40.0
168+
offset_top = 200.0
169+
offset_right = 135.0
170+
offset_bottom = 240.0
171+
theme = ExtResource("2_7ph5j")
172+
min_value = 5.0
173+
max_value = 90.0
174+
value = 30.0
175+
suffix = "s"
176+
custom_arrow_step = 5.0
177+
178+
[node name="Label" type="Label" parent="RoundCreation/CreationMenu/RoundDuration"]
179+
layout_mode = 1
180+
offset_top = -40.0
181+
offset_right = 160.0
182+
theme = ExtResource("2_7ph5j")
183+
text = "Round Duration"
184+
vertical_alignment = 1
185+
186+
[node name="CategoryBox" type="Tree" parent="RoundCreation/CreationMenu"]
187+
layout_mode = 1
188+
anchors_preset = 15
189+
anchor_right = 1.0
190+
anchor_bottom = 1.0
191+
offset_left = 38.0
192+
offset_top = 260.0
193+
offset_right = -38.0
194+
offset_bottom = -114.0
195+
grow_horizontal = 2
196+
grow_vertical = 2
197+
theme_override_colors/font_color = Color(0.6, 0.6, 0.6, 1)
198+
theme_override_colors/relationship_line_color = Color(0.301961, 0.301961, 0.301961, 1)
199+
theme_override_colors/parent_hl_line_color = Color(1, 1, 1, 1)
200+
theme_override_colors/children_hl_line_color = Color(0.6, 0.6, 0.6, 1)
201+
theme_override_constants/inner_item_margin_left = 5
202+
theme_override_constants/draw_relationship_lines = 1
203+
theme_override_constants/relationship_line_width = 2
204+
theme_override_constants/parent_hl_line_width = 3
205+
theme_override_constants/children_hl_line_width = 3
206+
theme_override_constants/draw_guides = 0
207+
columns = 2
208+
column_titles_visible = true
209+
hide_root = true
210+
153211
[node name="Cancel" type="Button" parent="RoundCreation/CreationMenu"]
154-
layout_mode = 0
155-
offset_left = 45.0
156-
offset_top = 821.0
157-
offset_right = 233.0
158-
offset_bottom = 896.0
212+
layout_mode = 1
213+
anchors_preset = 7
214+
anchor_left = 0.5
215+
anchor_top = 1.0
216+
anchor_right = 0.5
217+
anchor_bottom = 1.0
218+
offset_left = -220.0
219+
offset_top = -100.0
220+
offset_right = -32.0
221+
offset_bottom = -25.0
222+
grow_horizontal = 2
223+
grow_vertical = 0
159224
theme_override_font_sizes/font_size = 30
160225
theme_override_styles/normal = SubResource("StyleBoxFlat_r78im")
161226
theme_override_styles/hover = SubResource("StyleBoxFlat_v1l70")
162227
theme_override_styles/pressed = SubResource("StyleBoxFlat_eb82c")
163228
text = "Cancel"
164229

165230
[node name="Start" type="Button" parent="RoundCreation/CreationMenu"]
166-
layout_mode = 0
167-
offset_left = 286.0
168-
offset_top = 821.0
169-
offset_right = 474.0
170-
offset_bottom = 896.0
231+
layout_mode = 1
232+
anchors_preset = 7
233+
anchor_left = 0.5
234+
anchor_top = 1.0
235+
anchor_right = 0.5
236+
anchor_bottom = 1.0
237+
offset_left = 40.0
238+
offset_top = -100.0
239+
offset_right = 228.0
240+
offset_bottom = -25.0
241+
grow_horizontal = 2
242+
grow_vertical = 0
171243
theme_override_font_sizes/font_size = 30
172244
theme_override_styles/normal = SubResource("StyleBoxFlat_r78im")
173245
theme_override_styles/hover = SubResource("StyleBoxFlat_v1l70")
174246
theme_override_styles/pressed = SubResource("StyleBoxFlat_eb82c")
175247
text = "Start Game"
176248

177-
[node name="ModeSelect" type="OptionButton" parent="RoundCreation/CreationMenu"]
178-
layout_mode = 1
179-
offset_left = 43.0
180-
offset_top = 44.0
181-
offset_right = 299.0
182-
offset_bottom = 114.0
183-
theme_override_font_sizes/font_size = 40
184-
185-
[node name="CategoryBox" type="ScrollContainer" parent="RoundCreation/CreationMenu"]
186-
layout_direction = 2
187-
layout_mode = 1
188-
anchors_preset = 4
189-
anchor_top = 0.5
190-
anchor_bottom = 0.5
191-
offset_left = 126.0
192-
offset_top = -182.5
193-
offset_right = 269.0
194-
offset_bottom = 310.5
195-
grow_vertical = 2
196-
follow_focus = true
197-
horizontal_scroll_mode = 0
198-
199-
[node name="Categories" type="VBoxContainer" parent="RoundCreation/CreationMenu/CategoryBox"]
200-
layout_direction = 3
201-
layout_mode = 2
202-
theme_override_constants/separation = 3
203-
204-
[node name="RoundDuration" type="SpinBox" parent="RoundCreation/CreationMenu"]
205-
layout_mode = 1
206-
anchors_preset = 6
207-
anchor_left = 1.0
208-
anchor_top = 0.5
209-
anchor_right = 1.0
210-
anchor_bottom = 0.5
211-
offset_left = -472.0
212-
offset_top = -304.5
213-
offset_right = -199.775
214-
offset_bottom = -216.5
215-
grow_horizontal = 0
216-
grow_vertical = 2
217-
theme = SubResource("Theme_31w7n")
218-
min_value = 5.0
219-
max_value = 90.0
220-
value = 30.0
221-
suffix = "s"
222-
223249
[connection signal="pressed" from="Buttons/Play" to="." method="on_play_pressed"]
224250
[connection signal="pressed" from="Buttons/Quit" to="." method="on_quit_pressed"]
225251
[connection signal="pressed" from="RoundCreation/CreationMenu/Cancel" to="." method="on_cancel_pressed"]

scripts/api.gd

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class_name API extends Node
22

33
var ws: WebSocketPeer = WebSocketPeer.new()
4-
const host: String = "https://api.cake4everyone.de/quiz"
4+
var host: String = "https://api.cake4everyone.de/quiz"
55
var api_token: String = ""
66

77
var category_callback: Callable
@@ -13,6 +13,12 @@ var streamervote_callback: Callable
1313

1414
# Called when the node enters the scene tree for the first time.
1515
func _ready():
16+
var flags: PackedStringArray = OS.get_cmdline_args()
17+
for flag in flags:
18+
if flag.begins_with("--host="):
19+
host = flag.trim_prefix("--host=")
20+
print("[DEBUG] overwrote host with ", host)
21+
1622
$HTTP_Category.request_completed.connect(category_resp)
1723
$HTTP_GameInfo.request_completed.connect(game_info_resp)
1824
$HTTP_GameQuit.request_completed.connect(game_quit_resp)

scripts/game_end.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func _ready():
66
## show_round_data displays the given round_data data on screen.
77
func show_round_data(data: Dictionary):
88
print(data)
9-
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category]
9+
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category.title]
1010

1111
$Quiz/Question/Label.text = data.question
1212
$Quiz/Answers/A/Label.text = data.answers[0]

scripts/menu.gd

+52-11
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,70 @@ func _ready():
1212
$RoundCreation/CreationMenu/RoundDuration.value = round_duration
1313
api.category(on_category_response)
1414

15+
var category_tree: Tree = $RoundCreation/CreationMenu/CategoryBox
16+
category_tree.create_item()
17+
category_tree.set_column_title(0, "Category")
18+
category_tree.set_column_title(1, "Amount")
19+
category_tree.set_column_expand(1, false)
20+
category_tree.set_column_custom_minimum_width(1, 100)
21+
1522
## on_category_response is called as when the categories api call completed.
16-
func on_category_response(success: bool, categories: Dictionary={}):
23+
func on_category_response(success: bool, categories: Dictionary = {}):
1724
if !success:
1825
print("failed to get categories!")
1926
return
2027
update_category_list(categories)
2128

2229
## update_category_list updates the category selection list with the given dictionary (mapping String to int).
23-
func update_category_list(categories: Dictionary):
24-
for category in categories:
25-
var c = CATEGORY.instantiate()
26-
c.get_child(1).max_value = categories[category]
27-
c.get_child(2).text = category
28-
c.show()
29-
$RoundCreation/CreationMenu/CategoryBox/Categories.add_child(c)
30+
func update_category_list(groups: Dictionary):
31+
var category_tree: Tree = $RoundCreation/CreationMenu/CategoryBox
32+
var tree_root: TreeItem = category_tree.get_root()
33+
print(groups)
34+
for group_color in groups:
35+
var group: Dictionary = groups[group_color]
36+
var tree_group: TreeItem = category_tree.create_item(tree_root)
37+
tree_group.set_text(0, group.title)
38+
tree_group.set_custom_bg_color(0, Color(0.23, 0.23, 0.23))
39+
tree_group.set_custom_bg_color(1, Color(0.23, 0.23, 0.23))
40+
var bg_light: bool = false
41+
for cat in group.categories:
42+
var category: TreeItem = category_tree.create_item(tree_group)
43+
category.set_text(0, cat.title)
44+
category.set_cell_mode(1, TreeItem.CELL_MODE_RANGE)
45+
category.set_range_config(1, 0, cat.count, 1)
46+
category.set_editable(1, true)
47+
if bg_light:
48+
category.set_custom_bg_color(0, Color(0.15, 0.15, 0.15))
49+
category.set_custom_bg_color(1, Color(0.15, 0.15, 0.15))
50+
else:
51+
category.set_custom_bg_color(0, Color(0.05, 0.05, 0.05))
52+
category.set_custom_bg_color(1, Color(0.05, 0.05, 0.05))
53+
bg_light = !bg_light
54+
55+
var category_data: CategoryData = CategoryData.new()
56+
category_data.id = cat.id
57+
category_data.group = group.id
58+
category.set_metadata(0, category_data)
3059

3160
## on_btn_start_pressed is called when pressed the start game button.
3261
## It collects all the selected categories and creates a new game on the server.
3362
func on_btn_start_pressed():
3463
$RoundCreation/CreationMenu/Start.disabled = true
3564
round_duration = $RoundCreation/CreationMenu/RoundDuration.value
3665
var categories: Dictionary = {}
37-
for category: HBoxContainer in $RoundCreation/CreationMenu/CategoryBox/Categories.get_children():
38-
var amount: int = category.get_child(1).value
66+
var category: TreeItem = $RoundCreation/CreationMenu/CategoryBox.get_root().get_first_child()
67+
while category != null:
68+
var amount: int = int(category.get_range(1))
3969
if amount == 0:
70+
category = category.get_next_in_tree()
4071
continue
41-
categories[category.get_child(2).text] = amount
72+
var category_data: CategoryData = category.get_metadata(0)
73+
categories[category_data.id] = amount
74+
category = category.get_next_in_tree()
75+
76+
if categories.size() == 0:
77+
print("no categories selected!")
78+
return
4279

4380
var game_data: Dictionary = {}
4481
game_data["categories"] = categories
@@ -60,3 +97,7 @@ func on_play_pressed():
6097

6198
func on_quit_pressed():
6299
get_tree().quit()
100+
101+
class CategoryData:
102+
var id: String
103+
var group: String

scripts/question.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func on_round_next_response(success: bool, data: Dictionary={}):
6565
func show_round_data(data: Dictionary):
6666
print(data)
6767
$Countdown.show()
68-
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category]
68+
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category.title]
6969
$RoundCounter.show()
7070

7171
$Quiz/Question/Label.text = data.question

scripts/question_end.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func _ready():
66
## show_round_data displays the given round_data data on screen.
77
func show_round_data(data: Dictionary):
88
print(data)
9-
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category]
9+
$RoundCounter.text = "Runde %d/%d (%s)" % [data.current_round, data.max_round, data.category.title]
1010

1111
$Quiz/Question/Label.text = data.question
1212
$Quiz/Answers/A/Label.text = data.answers[0]

0 commit comments

Comments
 (0)