extends RefCounted
## Painted Attack button (Boss pick 2026-10-18, option B "royal blue + gems"; source art/ui_attack on the laptop
## project). The normal / pressed / disabled art goes on the Button itself as StyleBoxTexture, so the click / touch
## area (the Button rect) is unchanged and the game keeps drawing the "Attack" / "โจมตี" label.
## Used by ui/skill_pad.gd (PC HUD, 112 px x view scale) and ui/touch_controls.gd (touch layer, 74 px).

const DIR := "res://assets/ui/v4/"
const FILES := {"normal": "attack_normal.png", "hover": "attack_normal.png", "pressed": "attack_pressed.png",
	"disabled": "attack_disabled.png"}


static func ok() -> bool:
	return ResourceLoader.exists(DIR + "attack_normal.png")


## Puts the painted states on b. text_d > 0: the button's own text is pushed down onto the bottom rim
## (a button text_d px tall, the touch layer); 0 = the caller draws the label itself (skill pad).
static func apply(b: Button, text_d := 0.0) -> bool:
	if b == null or not ok():
		return false
	for st in FILES:
		var sb := StyleBoxTexture.new()
		sb.texture = load(DIR + str(FILES[st]))
		if st == "hover":
			sb.modulate_color = Color(1.08, 1.08, 1.08)
		if text_d > 0.0:
			sb.content_margin_top = text_d * 0.58
			sb.content_margin_bottom = 0.0
		b.add_theme_stylebox_override(st, sb)
	b.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
	b.set_meta("painted_attack", true)
	return true


static func on(b: Control) -> bool:
	return b != null and b.has_meta("painted_attack")
