summaryrefslogtreecommitdiff
path: root/client/menu/document/document.gd
blob: ba7883dd814bd42325e91dc99b8665e6457f837f (plain)
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
# Hurry Curry! - a game about cooking
# Copyright 2024 nokoe
#
# 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

func _ready():
	super()
	$ScrollContainer/VBoxContainer.add_child(build_document(data))

func build_document(element: Dictionary) -> 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://menu/theme/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))
			node.add_child(margin)
		"list":
			node = VBoxContainer.new()
			node.name = "List"
			for e in element["es"]:
				node.add_child(text_node(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)
					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))
		"text":
			node = text_node(element, false)
	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"])
		if element.get("color"):
			bullet_label.add_theme_color_override("font_color", Color(element["color"]))
		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("size"):
		node.add_theme_font_size_override("font_size", element["size"])
	if element.get("color"):
		label.add_theme_color_override("font_color", Color(element["color"]))
	return node

func background(page_name: String) -> SubViewportContainer:
	var item_name: String
	match page_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://menu/communicate/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