1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
extends Menu
const MARGIN: int = 75
var labels := {}
func _ready():
super()
$ScrollContainer/VBoxContainer.add_child(build_document(data))
func build_document(element: Dictionary, bullet: bool = false) -> Control:
var node: Control
match element["t"]:
"document":
node = VBoxContainer.new()
node.name = "Document"
for e in element["es"]:
node.add_child(build_document(e))
"page":
node = PanelContainer.new()
node.name = "Page"
node.add_theme_stylebox_override("panel", preload("res://gui/resources/style/paper_panel_style.tres"))
node.set_custom_minimum_size(Vector2(800, 1131.371))
var margin := MarginContainer.new()
margin.add_theme_constant_override("margin_bottom", MARGIN)
margin.add_theme_constant_override("margin_top", MARGIN)
margin.add_theme_constant_override("margin_left", MARGIN)
margin.add_theme_constant_override("margin_right", MARGIN)
var vbox := VBoxContainer.new()
if element["background"]:
margin.add_child(background(element["background"]))
margin.add_child(vbox)
for e in element["es"]:
vbox.add_child(build_document(e, bullet))
node.add_child(margin)
"label":
var label_id = element["id"]
node = build_document(element["e"], bullet)
labels[label_id] = node
"list":
node = VBoxContainer.new()
node.name = "List"
for e in element["es"]:
node.add_child(build_document(e, true))
"table":
node = VBoxContainer.new()
node.name = "Rows"
node.size_flags_horizontal = Control.SIZE_EXPAND_FILL
for r in range(element["es"].size()):
var row = HBoxContainer.new()
node.add_child(row)
row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
row.name = "Row%d" % r
for c in element["es"][r]:
var e = build_document(c, bullet)
e.size_flags_horizontal = Control.SIZE_EXPAND_FILL
row.add_child(e)
"par":
node = VBoxContainer.new()
node.name = "Paragraph"
for e in element["es"]:
node.add_child(build_document(e, bullet))
"ref":
# TODO: Support clicking
node = build_document(element["e"], bullet)
"conditional":
# Ignore all conditionals for now, since they are only revelant for typst version
node = Control.new()
"text":
node = text_node(element, bullet)
_:
node = Control.new()
push_error("Error building document: Unknown type \"%s\"" % element["t"])
return node
func text_node(element: Dictionary, bullet: bool) -> Control:
var node: Control
var label := Label.new()
# we need a hbox container for rtl
if bullet:
node = HBoxContainer.new()
var bullet_label := Label.new()
bullet_label.text = "•"
if element.get("size"):
bullet_label.add_theme_font_size_override("font_size", element["size"])
# TODO: Ignore font color for now. Will be removed in the future.
# if element.get("color"):
# bullet_label.add_theme_color_override("font_color", Color(element["color"]))
bullet_label.add_theme_color_override("font_color", Color.BLACK)
label.add_theme_color_override("font_color", Color.BLACK)
node.add_child(bullet_label)
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
node.add_child(label)
else:
node = label
label.name = "Text"
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
label.text = Global.get_message_str(element["s"])
if element.get("font"):
match element["font"]:
"Great Vibes":
node.add_theme_font_override("font", preload("res://gui/resources/fonts/font-sansita-swashed.woff2"))
if element.get("size"):
node.add_theme_font_size_override("font_size", element["size"])
# TODO: Ignore font color for now. Will be removed in the future.
# if element.get("color"):
# label.add_theme_color_override("font_color", Color(element["color"]))
label.add_theme_color_override("font_color", Color.BLACK)
return node
func background(background_name: String) -> SubViewportContainer:
var item_name: String
match background_name:
"cover": item_name = "plate:plate,plate,plate,dirt"
"toc": item_name = "tomato"
"tomato_soup": item_name = "plate:tomato-soup"
"burger": item_name = "plate:sliced-bun,sliced-tomato,sliced-lettuce"
"mochi": item_name = "plate:strawberry-mochi"
"curry": item_name = "plate:curry,cooked-rice"
"icecream": item_name = "plate:strawberry-icecream"
"drinks": item_name = "glass:strawberry-shake"
var n: item_name = n
var scene: ItemRender = preload("res://gui/components/message/item/item_render.tscn").instantiate()
scene.set_item(item_name, false)
var vc := SubViewportContainer.new()
var viewport := SubViewport.new()
viewport.add_child(scene)
viewport.own_world_3d = true
viewport.transparent_bg = true
vc.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
vc.size_flags_vertical = Control.SIZE_SHRINK_END
#vc.material = preload("res://menu/theme/materials/printed_material.tres")
vc.add_child(viewport)
return vc
func _menu_open(): pass
func _menu_exit(): pass
|