aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-14 22:10:39 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-14 22:10:42 +0200
commit65a492c588ee073fdcfbbb149897604aea46a24f (patch)
tree4cab8c29b7cfc98685eaba21c39fefc468812fe2 /client
parent954d7d7dbda5f8a3ac5862198d0ade93017d259e (diff)
downloadhurrycurry-65a492c588ee073fdcfbbb149897604aea46a24f.tar
hurrycurry-65a492c588ee073fdcfbbb149897604aea46a24f.tar.bz2
hurrycurry-65a492c588ee073fdcfbbb149897604aea46a24f.tar.zst
Improve diagram downscaling
Diffstat (limited to 'client')
-rw-r--r--client/gui/menus/book/diagram.gd29
1 files changed, 15 insertions, 14 deletions
diff --git a/client/gui/menus/book/diagram.gd b/client/gui/menus/book/diagram.gd
index 2fa657f1..2a6727d7 100644
--- a/client/gui/menus/book/diagram.gd
+++ b/client/gui/menus/book/diagram.gd
@@ -17,8 +17,8 @@ class_name Diagram
extends Control
const RENDERER := preload("res://gui/components/message/renderer.tscn")
-const SIZE: float = 64.;
-const HSIZE: float = SIZE / 2.;
+var BASE_SIZE: float = 64.;
+var hsize: float = 32.;
var raw: Dictionary
var nodes: Array#[DiagramNode]
@@ -54,8 +54,7 @@ func _init(raw_: Dictionary, game: Game) -> void:
func _ready() -> void:
redraw_images()
item_rect_changed.connect(func():
- if size != Vector2(64, 64):
- scale(Rect2(Vector2(HSIZE, HSIZE), Vector2(size.x - SIZE, size.y - SIZE)))
+ if size != Vector2(64, 64): scale()
)
func redraw_images() -> void:
@@ -64,21 +63,23 @@ func redraw_images() -> void:
renderers.clear()
for n: DiagramNode in draw_nodes:
var r: Renderer = RENDERER.instantiate()
- r.get_node("SubViewport").size = Vector2i(SIZE, SIZE)
+ r.get_node("SubViewport").size = Vector2.ONE * hsize * 2.
add_child(r)
- r.position = n.position - Vector2(HSIZE, HSIZE)
+ r.position = n.position - Vector2(hsize, hsize)
match n.label.kind:
MessageParser.Kind.ITEM: r.mode = Renderer.Mode.ITEMS
MessageParser.Kind.TILE: r.mode = Renderer.Mode.TILES
r.setup_object(n.label.result)
renderers.push_back(r)
-func scale(bounds: Rect2) -> void:
+func scale() -> void:
+ var bounds = Rect2(Vector2.ONE * BASE_SIZE * 0.5, Vector2(size.x - BASE_SIZE, size.y - BASE_SIZE))
var current := Rect2(Vector2(INF, INF), Vector2(-INF, -INF))
for n: DiagramNode in nodes:
current.position = current.position.min(n.position)
current.end = current.end.max(n.position)
var s = Vector2.ONE.min(bounds.size / current.size)
+ hsize = BASE_SIZE * 0.5 * min(s.x, s.y)
for i in nodes.size():
var dn: DiagramNode = draw_nodes[i]
var n: DiagramNode = nodes[i]
@@ -91,15 +92,15 @@ func _draw() -> void:
for n: DiagramNode in draw_nodes:
match n.style:
"intermediate_product":
- draw_circle(n.position, HSIZE, Color("#555"), true, -1., true)
+ draw_circle(n.position, hsize, Color("#555"), true, -1., true)
"final_product":
- draw_circle(n.position, HSIZE, Color("#333"), true, -1., true)
+ draw_circle(n.position, hsize, Color("#333"), true, -1., true)
"process_active":
- draw_rect(Rect2(n.position - Vector2(HSIZE, HSIZE), Vector2(SIZE, SIZE)), Color("#47c42b"))
+ draw_rect(Rect2(n.position - Vector2(hsize, hsize), Vector2(hsize, hsize) * 2.), Color("#47c42b"))
"process_passive":
- draw_rect(Rect2(n.position - Vector2(HSIZE, HSIZE), Vector2(SIZE, SIZE)), Color("#c4a32b"))
+ draw_rect(Rect2(n.position - Vector2(hsize, hsize), Vector2(hsize, hsize) * 2.), Color("#c4a32b"))
"process_instant":
- draw_rect(Rect2(n.position - Vector2(HSIZE, HSIZE), Vector2(SIZE, SIZE)), Color("#5452d8"))
+ draw_rect(Rect2(n.position - Vector2(hsize, hsize), Vector2(hsize, hsize) * 2.), Color("#5452d8"))
for e: DiagramEdge in edges:
var src_node: DiagramNode = draw_nodes[e.src]
@@ -119,6 +120,6 @@ func _draw() -> void:
func node_edge_connect_pos(src: DiagramNode, dst: DiagramNode) -> Vector2:
var dir = (dst.position - src.position).normalized()
if src.style == "intermediate_product" or src.style == "final_product":
- return src.position + dir * HSIZE
+ return src.position + dir * hsize
else:
- return src.position + dir / max(abs(dir.y), abs(dir.x)) * HSIZE
+ return src.position + dir / max(abs(dir.y), abs(dir.x)) * hsize