Add low HP unit warnings
This commit is contained in:
@@ -35,6 +35,7 @@ const FLOATING_TEXT_LIFETIME := 1.0
|
||||
const FLOATING_TEXT_RISE := 42.0
|
||||
const UNIT_MOVE_ANIMATION_DURATION := 0.18
|
||||
const TARGET_PREVIEW_BADGE_SIZE := Vector2(92, 22)
|
||||
const LOW_HP_WARNING_RATIO := 0.35
|
||||
|
||||
var state: BattleState = BattleStateScript.new()
|
||||
var campaign_state: CampaignState = CampaignStateScript.new()
|
||||
@@ -845,16 +846,30 @@ func _draw_units() -> void:
|
||||
var label := _short_name(String(unit["name"]))
|
||||
draw_string(font, rect.position + Vector2(2, 25), label, HORIZONTAL_ALIGNMENT_CENTER, TILE_SIZE - 4, 13, Color.WHITE)
|
||||
|
||||
var hp_ratio := float(unit["hp"]) / float(unit["max_hp"])
|
||||
var hp_ratio := float(unit["hp"]) / float(max(1, int(unit["max_hp"])))
|
||||
var hp_back := Rect2(rect.position + Vector2(8, TILE_SIZE - 12), Vector2(TILE_SIZE - 16, 6))
|
||||
var hp_front := Rect2(hp_back.position, Vector2(hp_back.size.x * hp_ratio, hp_back.size.y))
|
||||
draw_rect(hp_back, Color(0.08, 0.08, 0.09))
|
||||
draw_rect(hp_front, Color(0.28, 0.82, 0.36))
|
||||
draw_rect(hp_front, _unit_hp_color(hp_ratio))
|
||||
_draw_unit_status_markers(center, hp_ratio)
|
||||
|
||||
if unit.get("id", "") == state.selected_unit_id:
|
||||
draw_arc(center, 29, 0.0, TAU, 48, Color(1.0, 0.92, 0.25), 3.0)
|
||||
|
||||
|
||||
func _unit_hp_color(hp_ratio: float) -> Color:
|
||||
if hp_ratio <= LOW_HP_WARNING_RATIO:
|
||||
return Color(1.0, 0.24, 0.18)
|
||||
if hp_ratio <= 0.55:
|
||||
return Color(1.0, 0.72, 0.24)
|
||||
return Color(0.28, 0.82, 0.36)
|
||||
|
||||
|
||||
func _draw_unit_status_markers(center: Vector2, hp_ratio: float) -> void:
|
||||
if hp_ratio <= LOW_HP_WARNING_RATIO:
|
||||
draw_arc(center, 27, 0.0, TAU, 48, Color(1.0, 0.28, 0.14), 3.0)
|
||||
|
||||
|
||||
func _visual_rect_for_unit(unit: Dictionary) -> Rect2:
|
||||
var cell: Vector2i = unit.get("pos", Vector2i(-1, -1))
|
||||
var rect := _rect_for_cell(cell)
|
||||
|
||||
Reference in New Issue
Block a user