#112: every skill node carries an icon
A node that unlocks a structure borrows that structure's own menu icon, so the tree and the build menu cannot disagree about what a shipyard looks like. Doctrines and permanent bonuses, which have no building to point at, carry an explicit one. Drawn as child IconButtons with their frame turned off rather than reimplemented in the tree's _draw: the glyphs already exist there and are not trivial, and a dozen of them copied here would be two places to change every time one is redrawn. They are inert - MOUSE_FILTER_IGNORE means the tree's raw-input handling still sees every press, exactly as it did when there was nothing on top of the nodes - and hidden rather than clipped when scrolled off the panel. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c5c41b85e7
commit
551360f2e9
2 changed files with 90 additions and 2 deletions
|
|
@ -69,8 +69,48 @@ func _max_scroll() -> float:
|
|||
return maxf(0.0, _content_height() - size.y)
|
||||
|
||||
|
||||
# #112: one glyph per node, as a child IconButton with its frame turned off.
|
||||
# Drawn as nodes rather than into _draw() because the glyphs already exist
|
||||
# there and are non-trivial - reimplementing a dozen of them here would be
|
||||
# two places to change every time one is redrawn. They are inert:
|
||||
# MOUSE_FILTER_IGNORE means the tree's own raw-input handling still sees
|
||||
# every press, exactly as it did when there was nothing on top of the nodes.
|
||||
var _glyphs: Dictionary = {}
|
||||
|
||||
|
||||
func _build_glyphs() -> void:
|
||||
for node in GameState.SKILL_TREE:
|
||||
var icon: int = GameState.skill_node_icon(node)
|
||||
if icon < 0:
|
||||
continue
|
||||
var glyph := IconButton.new()
|
||||
glyph.icon = icon
|
||||
glyph.show_frame = false
|
||||
glyph.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(glyph)
|
||||
_glyphs[String(node.id)] = glyph
|
||||
|
||||
|
||||
func _layout_glyphs() -> void:
|
||||
var span: float = node_radius * 1.5
|
||||
for node in GameState.SKILL_TREE:
|
||||
var glyph: Control = _glyphs.get(String(node.id))
|
||||
if glyph == null:
|
||||
continue
|
||||
var centre: Vector2 = node_screen_pos(node)
|
||||
glyph.position = centre - Vector2(span, span) * 0.5
|
||||
glyph.size = Vector2(span, span)
|
||||
# Off the top or bottom of the panel entirely: hidden rather than
|
||||
# clipped, so a glyph never bleeds past the canvas the tree scrolls
|
||||
# inside.
|
||||
glyph.visible = centre.y > -span and centre.y < size.y + span
|
||||
glyph.glow_color = _state_color(node)
|
||||
glyph.queue_redraw()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_build_glyphs()
|
||||
call_deferred("reset_scroll")
|
||||
|
||||
|
||||
|
|
@ -164,6 +204,7 @@ func handle_pan(relative: Vector2) -> bool:
|
|||
|
||||
|
||||
func _draw() -> void:
|
||||
_layout_glyphs()
|
||||
# Links first, so nodes sit on top of them.
|
||||
for node in GameState.SKILL_TREE:
|
||||
if node.requires == "":
|
||||
|
|
|
|||
Loading…
Reference in a new issue