summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornokoe <nokoe@mailbox.org>2024-10-15 00:04:10 +0200
committernokoe <nokoe@mailbox.org>2024-10-15 00:04:10 +0200
commit5e87146c1f6a1fc59ba7dd41753d9ebfe0b262de (patch)
treea9337a73aed994cba852ba65874df03a6b13637e
parent55851861d13df210d4c51c932e055e9248b5336c (diff)
downloadhurrycurry-5e87146c1f6a1fc59ba7dd41753d9ebfe0b262de.tar
hurrycurry-5e87146c1f6a1fc59ba7dd41753d9ebfe0b262de.tar.bz2
hurrycurry-5e87146c1f6a1fc59ba7dd41753d9ebfe0b262de.tar.zst
replace old book textures with ui book
-rw-r--r--client/game.gd8
-rw-r--r--client/global.gd5
-rw-r--r--client/menu/book/book.gd29
-rw-r--r--client/menu/communicate/item/item_render.gd5
-rw-r--r--client/menu/communicate/item/item_render.tscn2
-rw-r--r--client/menu/document/document.gd115
-rw-r--r--client/menu/document/document.tscn (renamed from client/menu/book/book.tscn)4
-rw-r--r--client/multiplayer.gd2
8 files changed, 130 insertions, 40 deletions
diff --git a/client/game.gd b/client/game.gd
index da09ae9a..3a037be9 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -306,8 +306,8 @@ func handle_packet(p):
tutorial_queue.clear()
"menu":
match p.menu:
- "book":
- menu.submenu("res://menu/book/book.tscn")
+ "document":
+ menu.submenu("res://menu/document/document.tscn", p["data"])
"score":
menu.submenu("res://menu/rating/rating.tscn", [p.data.stars, p.data.points])
"server_message":
@@ -367,11 +367,9 @@ func _process(delta):
mp.send_replay_tick(delta)
func get_message_str(m: Dictionary) -> String:
- if "text" in m: return m.text
- if "translation" in m: return tr(m.translation.id).format(m.translation.params.map(get_message_str))
if "tile" in m: return tile_names[m.tile]
if "item" in m: return item_names[m.item]
- return "[unknown message type]"
+ return Global.get_message_str(m)
func get_tile_collision(pos: Vector2i) -> bool:
var t = map.get_tile_name(pos)
diff --git a/client/global.gd b/client/global.gd
index b6fb8b8a..f16aa52e 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -217,6 +217,11 @@ func find_menu(node: Node) -> Menu:
if node is Menu: return node
else: return find_menu(node.get_parent())
+func get_message_str(m: Dictionary) -> String:
+ if "text" in m: return m.text
+ if "translation" in m: return tr(m.translation.id).format(m.translation.params.map(get_message_str))
+ return "[unsupported message type]"
+
func language_list():
var a = TranslationServer.get_loaded_locales()
a.sort()
diff --git a/client/menu/book/book.gd b/client/menu/book/book.gd
deleted file mode 100644
index 512ddfd4..00000000
--- a/client/menu/book/book.gd
+++ /dev/null
@@ -1,29 +0,0 @@
-# Hurry Curry! - a game about cooking
-# Copyright 2024 metamuffin
-#
-# 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
-
-func _ready():
- super()
- for d in ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"]:
- var texture := TextureRect.new()
- texture.texture = load("res://menu/book/book_%s.webp" % d)
- texture.expand_mode = TextureRect.EXPAND_FIT_WIDTH
- texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
- texture.custom_minimum_size = get_viewport_rect().size
- $ScrollContainer/VBoxContainer.add_child(texture)
-
-func _menu_open(): pass
-func _menu_exit(): pass
diff --git a/client/menu/communicate/item/item_render.gd b/client/menu/communicate/item/item_render.gd
index 5c3aa0c4..875c5a74 100644
--- a/client/menu/communicate/item/item_render.gd
+++ b/client/menu/communicate/item/item_render.gd
@@ -19,7 +19,10 @@ class_name ItemRender
var item: Item
var do_rotate: bool
-@onready var base = $ItemBase
+var base := Node3D.new()
+
+func _ready() -> void:
+ add_child(base)
func set_item(item_name: String, enable_rotation := true):
if item != null:
diff --git a/client/menu/communicate/item/item_render.tscn b/client/menu/communicate/item/item_render.tscn
index 1309509e..27f5f303 100644
--- a/client/menu/communicate/item/item_render.tscn
+++ b/client/menu/communicate/item/item_render.tscn
@@ -15,8 +15,6 @@ transform = Transform3D(1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, 0,
projection = 1
size = 0.6
-[node name="ItemBase" type="Node3D" parent="."]
-
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.173648, 0.984808, 0, -0.984808, 0.173648, 0, 0, 0)
light_energy = 0.5
diff --git a/client/menu/document/document.gd b/client/menu/document/document.gd
new file mode 100644
index 00000000..68787bdc
--- /dev/null
+++ b/client/menu/document/document.gd
@@ -0,0 +1,115 @@
+# 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":
+ push_warning("Table not yet implemented")
+ "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 = "•"
+ bullet_label.add_theme_font_size_override("font_size", element["size"])
+ 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["size"]:
+ node.add_theme_font_size_override("font_size", element["size"])
+ if element["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
diff --git a/client/menu/book/book.tscn b/client/menu/document/document.tscn
index 366959a4..69290d4b 100644
--- a/client/menu/book/book.tscn
+++ b/client/menu/document/document.tscn
@@ -1,9 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://bdggwo8un3mys"]
-[ext_resource type="Script" path="res://menu/book/book.gd" id="1_gyisx"]
+[ext_resource type="Script" path="res://menu/document/document.gd" id="1_gyisx"]
[ext_resource type="Script" path="res://menu/auto_setup/scroll_container_custom.gd" id="2_0d0p0"]
-[node name="Book" type="Control"]
+[node name="Document" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
diff --git a/client/multiplayer.gd b/client/multiplayer.gd
index 20c50efd..72a44507 100644
--- a/client/multiplayer.gd
+++ b/client/multiplayer.gd
@@ -22,7 +22,7 @@ signal packet(packet: Dictionary)
signal connection_closed()
static var VERSION_MAJOR: int = 7
-static var VERSION_MINOR: int = 3
+static var VERSION_MINOR: int = 4
var connected := false
var socket := WebSocketPeer.new()