feat: added health percentage to HUD

This commit is contained in:
Sara 2025-08-30 23:08:16 +02:00
parent a2c80df0b8
commit efe5607f60
3 changed files with 53 additions and 1 deletions

View file

@ -4,6 +4,8 @@ HeadsUpDisplay *HeadsUpDisplay::singleton_instance{ nullptr };
void HeadsUpDisplay::_bind_methods() {
ClassDB::bind_static_method("HeadsUpDisplay", D_METHOD("get_singleton"), &self_type::get_singleton);
ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &self_type::set_tooltip);
ClassDB::bind_method(D_METHOD("set_health_percentage", "percentage"), &self_type::set_health_percentage);
}
void HeadsUpDisplay::on_child_entered(Node *child) {
@ -11,6 +13,9 @@ void HeadsUpDisplay::on_child_entered(Node *child) {
if (child->is_unique_name_in_owner() && child->get_name() == "Tooltip") {
this->tooltip = cast_to<Label>(child);
}
if (child->is_unique_name_in_owner() && child->get_name() == "Healthbar") {
this->healthbar = cast_to<ProgressBar>(child);
}
}
void HeadsUpDisplay::enter_tree() {
@ -45,3 +50,7 @@ HeadsUpDisplay *HeadsUpDisplay::get_singleton() {
void HeadsUpDisplay::set_tooltip(String const &tooltip) {
this->tooltip->set_text(tooltip);
}
void HeadsUpDisplay::set_health_percentage(double health_percentage) {
this->healthbar->set_value(health_percentage);
}