|  |  |  | extends Control | 
					
						
							|  |  |  | class_name Headbar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @onready var hit_text_scene: PackedScene = preload("res://scene/ui/item/hit_text.tscn") | 
					
						
							|  |  |  | @onready var battle_info: Control = (%BattleInfo as Control) | 
					
						
							|  |  |  | @onready var hp_bar: TextureProgressBar = (%HpBar as TextureProgressBar) | 
					
						
							|  |  |  | @onready var shield_bar: TextureProgressBar = (%ShieldBar as TextureProgressBar) | 
					
						
							|  |  |  | @onready var break_level: Sprite2D = (%BreakLevel as Sprite2D) | 
					
						
							|  |  |  | @onready var alert_bar: TextureProgressBar = (%AlertBar as TextureProgressBar) | 
					
						
							|  |  |  | #debug info | 
					
						
							|  |  |  | @onready var stun_bar: TextureProgressBar = (%StunBar as TextureProgressBar) | 
					
						
							|  |  |  | @onready var mp_bar: TextureProgressBar = (%MpBar as TextureProgressBar) | 
					
						
							|  |  |  | @onready var mp_sub_bar: TextureProgressBar = (%MpSubBar as TextureProgressBar) | 
					
						
							|  |  |  | @onready var pos_lable: Label = (%PosLabel as Label) | 
					
						
							|  |  |  | @onready var role_lable: Label = (%RoleLabel as Label) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func set_debug_info_show(is_show: bool) -> void: | 
					
						
							|  |  |  | 	var debug_info: Control = (%DebugInfo as Control) | 
					
						
							|  |  |  | 	debug_info.visible = is_show | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func set_length(hp: float) -> void: | 
					
						
							|  |  |  | 	if hp > 100: | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	var length_px: int = max(32 * hp / 100, 10) | 
					
						
							|  |  |  | 	if (length_px % 2) == 1: | 
					
						
							|  |  |  | 		length_px += 1 | 
					
						
							|  |  |  | 	hp_bar.size.x = length_px | 
					
						
							|  |  |  | 	hp_bar.position.x = -length_px / 2 | 
					
						
							|  |  |  | 	shield_bar.size.x = length_px | 
					
						
							|  |  |  | 	shield_bar.position.x = -length_px / 2 | 
					
						
							|  |  |  | 	break_level.position.x = -length_px / 2 - 5 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var hit_text_damage_cache: HitText | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_hp_changed(value): hp_bar.value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_hp_max_changed(value): | 
					
						
							|  |  |  | 	hp_bar.max_value = value | 
					
						
							|  |  |  | 	set_length(value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_shield_changed(value): | 
					
						
							|  |  |  | 	shield_bar.value = value | 
					
						
							|  |  |  | 	shield_bar.visible = value > 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_shield_max_changed(value): shield_bar.max_value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_break_level_def_changed(value): | 
					
						
							|  |  |  | 	break_level.frame = clamp(value + 4, 0, 8) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_ai_is_alert_changed(value): | 
					
						
							|  |  |  | 	alert_bar.visible = not value | 
					
						
							|  |  |  | 	battle_info.visible = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_ai_alert_max_changed(value): | 
					
						
							|  |  |  | 	alert_bar.max_value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_ai_alert_changed(value): | 
					
						
							|  |  |  | 	alert_bar.value = value | 
					
						
							|  |  |  | 	alert_bar.visible = value > 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_stun_changed(value): stun_bar.value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_stun_max_changed(value): stun_bar.max_value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_mp_changed(value): mp_bar.value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_mp_max_changed(value): mp_bar.max_value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_mp_sub_changed(value): mp_sub_bar.value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_mp_sub_max_changed(value): mp_sub_bar.max_value = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_pos2d_changed(value): pos_lable.text = "(%.2f,%.2f)"%[value.x, value.y] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_ai_role_changed(value): role_lable.text = str(value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_hit_text(value: String): | 
					
						
							|  |  |  | 	var hit_text: HitText = get_hit_text_object() | 
					
						
							|  |  |  | 	hit_text.show_hit_text(value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func on_hit_damage(value: float): | 
					
						
							|  |  |  | 	var hit_text: HitText = hit_text_damage_cache | 
					
						
							|  |  |  | 	if not hit_text or hit_text.is_close: | 
					
						
							|  |  |  | 		hit_text_damage_cache = get_hit_text_object() | 
					
						
							|  |  |  | 		hit_text = hit_text_damage_cache | 
					
						
							|  |  |  | 	hit_text.show_hit_damage(value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func get_hit_text_object()->HitText: | 
					
						
							|  |  |  | 	var hit_text: HitText = hit_text_scene.instantiate() as HitText | 
					
						
							|  |  |  | 	add_child(hit_text) | 
					
						
							|  |  |  | 	return hit_text |