aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authornokoe <nokoe@mailbox.org>2025-10-10 11:52:03 +0200
committernokoe <nokoe@mailbox.org>2025-10-10 11:52:03 +0200
commit9adcb0056b59746fb9fdd23ba920aa6823e9f96d (patch)
tree44dfa0819044e75167b65816980ff2087d710efe /client
parent1700aba6fece444c9eb8bb7e7f67ad2a68eb81d4 (diff)
downloadhurrycurry-9adcb0056b59746fb9fdd23ba920aa6823e9f96d.tar
hurrycurry-9adcb0056b59746fb9fdd23ba920aa6823e9f96d.tar.bz2
hurrycurry-9adcb0056b59746fb9fdd23ba920aa6823e9f96d.tar.zst
scale book diagram
Diffstat (limited to 'client')
-rw-r--r--client/gui/menus/book/book.gd4
-rw-r--r--client/gui/menus/book/diagram.gd19
2 files changed, 22 insertions, 1 deletions
diff --git a/client/gui/menus/book/book.gd b/client/gui/menus/book/book.gd
index 7b0bcec5..6c887d0f 100644
--- a/client/gui/menus/book/book.gd
+++ b/client/gui/menus/book/book.gd
@@ -49,7 +49,9 @@ func build_book(d: Dictionary) -> void:
var title = Label.new()
title.text = title_string
page.left.add_child(title)
- page.right.add_child(Diagram.new(p["diagram"], book_data.game))
+ var dia := Diagram.new(p["diagram"], book_data.game)
+ dia.scale(Rect2(Vector2(64., 64.), Vector2(PAGE_WIDTH - 128., PAGE_WIDTH * ASPECT_RATIO - 128.)))
+ page.right.add_child(dia)
_: push_error("%s not known" % p.page_type)
$ScrollContainer/VBoxContainer.add_child(page)
return Control.new()
diff --git a/client/gui/menus/book/diagram.gd b/client/gui/menus/book/diagram.gd
index 4a8c4dc4..7d85459d 100644
--- a/client/gui/menus/book/diagram.gd
+++ b/client/gui/menus/book/diagram.gd
@@ -59,6 +59,25 @@ func _ready() -> void:
MessageParser.Kind.TILE: r.mode = Renderer.Mode.TILES
r.setup_object(n.label.result)
+func scale(bounds: Rect2):
+ var current := Rect2(Vector2(INF, INF), Vector2(-INF, -INF))
+ for n: DiagramNode in nodes:
+ if n.position.x < current.position.x:
+ current.position.x = n.position.x
+ if n.position.y < current.position.y:
+ current.position.y = n.position.y
+ if n.position.x > current.end.x:
+ current.end.x = n.position.x
+ if n.position.y > current.end.y:
+ current.end.y = n.position.y
+
+ var s := bounds.size / current.size
+ for n: DiagramNode in nodes:
+ var p := n.position
+ p -= current.position
+ p *= s
+ n.position = p + bounds.position
+
func _draw() -> void:
for n: DiagramNode in nodes:
match n.style: