Store resources in generic inventories
This commit is contained in:
parent
02643c76c4
commit
1721edd123
24 changed files with 385 additions and 172 deletions
|
|
@ -1,6 +1,8 @@
|
|||
class_name ResourceGlyph
|
||||
extends Control
|
||||
|
||||
const RESOURCE_DEFINITIONS = preload("res://ResourceDefinitions.gd")
|
||||
|
||||
# A small, non-interactive resource mark shared by tables and transfer rows.
|
||||
# Resource buttons used to borrow IconButton, which made decorative icons
|
||||
# look tappable and encouraged each screen to invent its own version.
|
||||
|
|
@ -12,43 +14,21 @@ func set_resource_type(value: String) -> void:
|
|||
if resource_type == value:
|
||||
return
|
||||
resource_type = value
|
||||
queue_redraw()
|
||||
if is_node_ready():
|
||||
_rebuild_visual()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
queue_redraw()
|
||||
_rebuild_visual()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
var colour: Color = GameState.resource_color(resource_type)
|
||||
var centre: Vector2 = size * 0.5
|
||||
var radius: float = minf(size.x, size.y) * 0.34
|
||||
match resource_type:
|
||||
GameState.RESOURCE_GAS:
|
||||
_draw_gas(centre, radius, colour)
|
||||
_:
|
||||
_draw_ore(centre, radius, colour)
|
||||
|
||||
|
||||
func _draw_ore(centre: Vector2, radius: float, colour: Color) -> void:
|
||||
var points := PackedVector2Array()
|
||||
for i in range(6):
|
||||
var angle: float = TAU * float(i) / 6.0 - PI * 0.5
|
||||
points.append(centre + Vector2(cos(angle), sin(angle)) * radius)
|
||||
NeonDraw.draw_glowing_polygon(self, points, colour, 1.0, colour.darkened(0.78), maxf(0.5, radius * 0.035))
|
||||
NeonDraw.draw_glowing_line(self, points[5], points[2], colour, 0.55, maxf(0.4, radius * 0.025), colour.darkened(0.78))
|
||||
|
||||
|
||||
func _draw_gas(centre: Vector2, radius: float, colour: Color) -> void:
|
||||
var bubbles: Array = [
|
||||
[centre + Vector2(-radius * 0.38, radius * 0.12), radius * 0.46],
|
||||
[centre + Vector2(radius * 0.34, radius * 0.26), radius * 0.58],
|
||||
[centre + Vector2(radius * 0.38, -radius * 0.48), radius * 0.32],
|
||||
]
|
||||
for bubble in bubbles:
|
||||
var ring := PackedVector2Array()
|
||||
for i in range(12):
|
||||
var angle: float = TAU * float(i) / 12.0
|
||||
ring.append(bubble[0] + Vector2(cos(angle), sin(angle)) * float(bubble[1]))
|
||||
NeonDraw.draw_glowing_polygon(self, ring, colour, 1.0, colour.darkened(0.78), maxf(0.5, radius * 0.035))
|
||||
func _rebuild_visual() -> void:
|
||||
for child in get_children():
|
||||
child.queue_free()
|
||||
var definition: Resource = RESOURCE_DEFINITIONS.get_definition(resource_type)
|
||||
if definition == null or definition.glyph_scene == null:
|
||||
return
|
||||
var visual: Control = definition.glyph_scene.instantiate()
|
||||
visual.colour = definition.color
|
||||
add_child(visual)
|
||||
|
|
|
|||
Loading…
Reference in a new issue