54 lines
1.9 KiB
GDScript3
54 lines
1.9 KiB
GDScript3
|
|
class_name ResourceGlyph
|
||
|
|
extends Control
|
||
|
|
|
||
|
|
# 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.
|
||
|
|
|
||
|
|
@export var resource_type: String = GameState.RESOURCE_ORE: set = set_resource_type
|
||
|
|
|
||
|
|
|
||
|
|
func set_resource_type(value: String) -> void:
|
||
|
|
if resource_type == value:
|
||
|
|
return
|
||
|
|
resource_type = value
|
||
|
|
queue_redraw()
|
||
|
|
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
|
|
queue_redraw()
|
||
|
|
|
||
|
|
|
||
|
|
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))
|