Assign "bold" font to tasks with custom name set in BT debugger
Also, fixes resources used without Ref in debugger view.
This commit is contained in:
parent
feab3c1ba9
commit
4ff1b874f3
|
@ -40,6 +40,7 @@ BehaviorTreeData::BehaviorTreeData(const Ref<BTTask> &p_instance, const NodePath
|
||||||
tasks.push_back(TaskData(
|
tasks.push_back(TaskData(
|
||||||
id,
|
id,
|
||||||
task->get_task_name(),
|
task->get_task_name(),
|
||||||
|
!task->get_custom_name().is_empty(),
|
||||||
num_children,
|
num_children,
|
||||||
task->get_status(),
|
task->get_status(),
|
||||||
task->get_elapsed_time(),
|
task->get_elapsed_time(),
|
||||||
|
@ -54,6 +55,7 @@ void BehaviorTreeData::serialize(Array &p_arr) {
|
||||||
for (const TaskData &td : tasks) {
|
for (const TaskData &td : tasks) {
|
||||||
p_arr.push_back(td.id);
|
p_arr.push_back(td.id);
|
||||||
p_arr.push_back(td.name);
|
p_arr.push_back(td.name);
|
||||||
|
p_arr.push_back(td.is_custom_name);
|
||||||
p_arr.push_back(td.num_children);
|
p_arr.push_back(td.num_children);
|
||||||
p_arr.push_back(td.status);
|
p_arr.push_back(td.status);
|
||||||
p_arr.push_back(td.elapsed_time);
|
p_arr.push_back(td.elapsed_time);
|
||||||
|
@ -74,12 +76,13 @@ void BehaviorTreeData::deserialize(const Array &p_arr) {
|
||||||
ERR_FAIL_COND(p_arr.size() < idx + 7);
|
ERR_FAIL_COND(p_arr.size() < idx + 7);
|
||||||
ERR_FAIL_COND(p_arr[idx].get_type() != Variant::INT);
|
ERR_FAIL_COND(p_arr[idx].get_type() != Variant::INT);
|
||||||
ERR_FAIL_COND(p_arr[idx + 1].get_type() != Variant::STRING);
|
ERR_FAIL_COND(p_arr[idx + 1].get_type() != Variant::STRING);
|
||||||
ERR_FAIL_COND(p_arr[idx + 2].get_type() != Variant::INT);
|
ERR_FAIL_COND(p_arr[idx + 2].get_type() != Variant::BOOL);
|
||||||
ERR_FAIL_COND(p_arr[idx + 3].get_type() != Variant::INT);
|
ERR_FAIL_COND(p_arr[idx + 3].get_type() != Variant::INT);
|
||||||
ERR_FAIL_COND(p_arr[idx + 4].get_type() != Variant::FLOAT);
|
ERR_FAIL_COND(p_arr[idx + 4].get_type() != Variant::INT);
|
||||||
ERR_FAIL_COND(p_arr[idx + 5].get_type() != Variant::STRING);
|
ERR_FAIL_COND(p_arr[idx + 5].get_type() != Variant::FLOAT);
|
||||||
ERR_FAIL_COND(p_arr[idx + 6].get_type() != Variant::STRING);
|
ERR_FAIL_COND(p_arr[idx + 6].get_type() != Variant::STRING);
|
||||||
tasks.push_back(TaskData(p_arr[idx], p_arr[idx + 1], p_arr[idx + 2], p_arr[idx + 3], p_arr[idx + 4], p_arr[idx + 5], p_arr[idx + 6]));
|
ERR_FAIL_COND(p_arr[idx + 7].get_type() != Variant::STRING);
|
||||||
idx += 7;
|
tasks.push_back(TaskData(p_arr[idx], p_arr[idx + 1], p_arr[idx + 2], p_arr[idx + 3], p_arr[idx + 4], p_arr[idx + 5], p_arr[idx + 6], p_arr[idx + 7]));
|
||||||
|
idx += 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,17 @@ public:
|
||||||
struct TaskData {
|
struct TaskData {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
String name;
|
String name;
|
||||||
|
bool is_custom_name = false;
|
||||||
int num_children = 0;
|
int num_children = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
double elapsed_time = 0.0;
|
double elapsed_time = 0.0;
|
||||||
String type_name;
|
String type_name;
|
||||||
String script_path;
|
String script_path;
|
||||||
|
|
||||||
TaskData(int p_id, const String &p_name, int p_num_children, int p_status, double p_elapsed_time, const String &p_type_name, const String &p_script_path) {
|
TaskData(int p_id, const String &p_name, bool p_is_custom_name, int p_num_children, int p_status, double p_elapsed_time, const String &p_type_name, const String &p_script_path) {
|
||||||
id = p_id;
|
id = p_id;
|
||||||
name = p_name;
|
name = p_name;
|
||||||
|
is_custom_name = p_is_custom_name;
|
||||||
num_children = p_num_children;
|
num_children = p_num_children;
|
||||||
status = p_status;
|
status = p_status;
|
||||||
elapsed_time = p_elapsed_time;
|
elapsed_time = p_elapsed_time;
|
||||||
|
|
|
@ -26,17 +26,17 @@
|
||||||
|
|
||||||
void BehaviorTreeView::_draw_running_status(Object *p_obj, Rect2 p_rect) {
|
void BehaviorTreeView::_draw_running_status(Object *p_obj, Rect2 p_rect) {
|
||||||
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
||||||
sbf_running.draw(tree->get_canvas_item(), p_rect);
|
theme_cache.sbf_running->draw(tree->get_canvas_item(), p_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTreeView::_draw_success_status(Object *p_obj, Rect2 p_rect) {
|
void BehaviorTreeView::_draw_success_status(Object *p_obj, Rect2 p_rect) {
|
||||||
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
||||||
sbf_success.draw(tree->get_canvas_item(), p_rect);
|
theme_cache.sbf_success->draw(tree->get_canvas_item(), p_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTreeView::_draw_failure_status(Object *p_obj, Rect2 p_rect) {
|
void BehaviorTreeView::_draw_failure_status(Object *p_obj, Rect2 p_rect) {
|
||||||
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x);
|
||||||
sbf_failure.draw(tree->get_canvas_item(), p_rect);
|
theme_cache.sbf_failure->draw(tree->get_canvas_item(), p_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTreeView::_item_collapsed(Object *p_obj) {
|
void BehaviorTreeView::_item_collapsed(Object *p_obj) {
|
||||||
|
@ -81,7 +81,12 @@ void BehaviorTreeView::update_tree(const BehaviorTreeData &p_data) {
|
||||||
item->set_cell_mode(1, TreeItem::CELL_MODE_ICON);
|
item->set_cell_mode(1, TreeItem::CELL_MODE_ICON);
|
||||||
|
|
||||||
item->set_metadata(0, task_data.id);
|
item->set_metadata(0, task_data.id);
|
||||||
|
|
||||||
item->set_text(0, task_data.name);
|
item->set_text(0, task_data.name);
|
||||||
|
if (task_data.is_custom_name) {
|
||||||
|
item->set_custom_font(0, theme_cache.font_custom_name);
|
||||||
|
}
|
||||||
|
|
||||||
item->set_text(2, rtos(Math::snapped(task_data.elapsed_time, 0.01)).pad_decimals(2));
|
item->set_text(2, rtos(Math::snapped(task_data.elapsed_time, 0.01)).pad_decimals(2));
|
||||||
|
|
||||||
String cors = (task_data.script_path.is_empty()) ? task_data.type_name : task_data.script_path;
|
String cors = (task_data.script_path.is_empty()) ? task_data.type_name : task_data.script_path;
|
||||||
|
@ -90,13 +95,13 @@ void BehaviorTreeView::update_tree(const BehaviorTreeData &p_data) {
|
||||||
|
|
||||||
if (task_data.status == BTTask::SUCCESS) {
|
if (task_data.status == BTTask::SUCCESS) {
|
||||||
item->set_custom_draw(0, this, SNAME("_draw_success_status"));
|
item->set_custom_draw(0, this, SNAME("_draw_success_status"));
|
||||||
item->set_icon(1, icon_success);
|
item->set_icon(1, theme_cache.icon_success);
|
||||||
} else if (task_data.status == BTTask::FAILURE) {
|
} else if (task_data.status == BTTask::FAILURE) {
|
||||||
item->set_custom_draw(0, this, SNAME("_draw_failure_status"));
|
item->set_custom_draw(0, this, SNAME("_draw_failure_status"));
|
||||||
item->set_icon(1, icon_failure);
|
item->set_icon(1, theme_cache.icon_failure);
|
||||||
} else if (task_data.status == BTTask::RUNNING) {
|
} else if (task_data.status == BTTask::RUNNING) {
|
||||||
item->set_custom_draw(0, this, SNAME("_draw_running_status"));
|
item->set_custom_draw(0, this, SNAME("_draw_running_status"));
|
||||||
item->set_icon(1, icon_running);
|
item->set_icon(1, theme_cache.icon_running);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task_data.id == selected_id) {
|
if (task_data.id == selected_id) {
|
||||||
|
@ -119,34 +124,39 @@ void BehaviorTreeView::clear() {
|
||||||
collapsed_ids.clear();
|
collapsed_ids.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTreeView::_notification(int p_notification) {
|
void BehaviorTreeView::_update_theme_item_cache() {
|
||||||
if (p_notification == NOTIFICATION_THEME_CHANGED) {
|
Control::_update_theme_item_cache();
|
||||||
icon_running = get_theme_icon(SNAME("LimboExtraClock"), SNAME("EditorIcons"));
|
|
||||||
icon_success = get_theme_icon(SNAME("BTAlwaysSucceed"), SNAME("EditorIcons"));
|
|
||||||
icon_failure = get_theme_icon(SNAME("BTAlwaysFail"), SNAME("EditorIcons"));
|
|
||||||
|
|
||||||
Color running_border = Color::html("#fea900");
|
theme_cache.icon_running = get_theme_icon(SNAME("LimboExtraClock"), SNAME("EditorIcons"));
|
||||||
Color running_fill = Color(running_border, 0.1);
|
theme_cache.icon_success = get_theme_icon(SNAME("BTAlwaysSucceed"), SNAME("EditorIcons"));
|
||||||
Color success_border = Color::html("#2fa139");
|
theme_cache.icon_failure = get_theme_icon(SNAME("BTAlwaysFail"), SNAME("EditorIcons"));
|
||||||
Color success_fill = Color(success_border, 0.1);
|
|
||||||
Color failure_border = Color::html("#cd3838");
|
|
||||||
Color failure_fill = Color(failure_border, 0.1);
|
|
||||||
|
|
||||||
sbf_running.set_border_color(running_border);
|
theme_cache.font_custom_name = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
|
||||||
sbf_running.set_bg_color(running_fill);
|
|
||||||
sbf_running.set_border_width(SIDE_LEFT, 4.0);
|
|
||||||
sbf_running.set_border_width(SIDE_RIGHT, 4.0);
|
|
||||||
|
|
||||||
sbf_success.set_border_color(success_border);
|
Color running_border = Color::html("#fea900");
|
||||||
sbf_success.set_bg_color(success_fill);
|
Color running_fill = Color(running_border, 0.1);
|
||||||
sbf_success.set_border_width(SIDE_LEFT, 4.0);
|
Color success_border = Color::html("#2fa139");
|
||||||
sbf_success.set_border_width(SIDE_RIGHT, 4.0);
|
Color success_fill = Color(success_border, 0.1);
|
||||||
|
Color failure_border = Color::html("#cd3838");
|
||||||
|
Color failure_fill = Color(failure_border, 0.1);
|
||||||
|
|
||||||
sbf_failure.set_border_color(failure_border);
|
theme_cache.sbf_running.instantiate();
|
||||||
sbf_failure.set_bg_color(failure_fill);
|
theme_cache.sbf_running->set_border_color(running_border);
|
||||||
sbf_failure.set_border_width(SIDE_LEFT, 4.0);
|
theme_cache.sbf_running->set_bg_color(running_fill);
|
||||||
sbf_failure.set_border_width(SIDE_RIGHT, 4.0);
|
theme_cache.sbf_running->set_border_width(SIDE_LEFT, 4.0);
|
||||||
}
|
theme_cache.sbf_running->set_border_width(SIDE_RIGHT, 4.0);
|
||||||
|
|
||||||
|
theme_cache.sbf_success.instantiate();
|
||||||
|
theme_cache.sbf_success->set_border_color(success_border);
|
||||||
|
theme_cache.sbf_success->set_bg_color(success_fill);
|
||||||
|
theme_cache.sbf_success->set_border_width(SIDE_LEFT, 4.0);
|
||||||
|
theme_cache.sbf_success->set_border_width(SIDE_RIGHT, 4.0);
|
||||||
|
|
||||||
|
theme_cache.sbf_failure.instantiate();
|
||||||
|
theme_cache.sbf_failure->set_border_color(failure_border);
|
||||||
|
theme_cache.sbf_failure->set_bg_color(failure_fill);
|
||||||
|
theme_cache.sbf_failure->set_border_width(SIDE_LEFT, 4.0);
|
||||||
|
theme_cache.sbf_failure->set_border_width(SIDE_RIGHT, 4.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTreeView::_bind_methods() {
|
void BehaviorTreeView::_bind_methods() {
|
||||||
|
@ -171,4 +181,4 @@ BehaviorTreeView::BehaviorTreeView() {
|
||||||
tree->connect(SNAME("item_collapsed"), callable_mp(this, &BehaviorTreeView::_item_collapsed));
|
tree->connect(SNAME("item_collapsed"), callable_mp(this, &BehaviorTreeView::_item_collapsed));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TOOLS_ENABLED
|
#endif // TOOLS_ENABLED
|
||||||
|
|
|
@ -28,14 +28,20 @@ class BehaviorTreeView : public Control {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Tree *tree;
|
Tree *tree;
|
||||||
StyleBoxFlat sbf_running;
|
|
||||||
StyleBoxFlat sbf_success;
|
|
||||||
StyleBoxFlat sbf_failure;
|
|
||||||
Vector<int> collapsed_ids;
|
|
||||||
|
|
||||||
Ref<Texture2D> icon_running;
|
struct ThemeCache {
|
||||||
Ref<Texture2D> icon_success;
|
Ref<StyleBoxFlat> sbf_running;
|
||||||
Ref<Texture2D> icon_failure;
|
Ref<StyleBoxFlat> sbf_success;
|
||||||
|
Ref<StyleBoxFlat> sbf_failure;
|
||||||
|
|
||||||
|
Ref<Texture2D> icon_running;
|
||||||
|
Ref<Texture2D> icon_success;
|
||||||
|
Ref<Texture2D> icon_failure;
|
||||||
|
|
||||||
|
Ref<Font> font_custom_name;
|
||||||
|
} theme_cache;
|
||||||
|
|
||||||
|
Vector<int> collapsed_ids;
|
||||||
|
|
||||||
void _draw_success_status(Object *p_obj, Rect2 p_rect);
|
void _draw_success_status(Object *p_obj, Rect2 p_rect);
|
||||||
void _draw_running_status(Object *p_obj, Rect2 p_rect);
|
void _draw_running_status(Object *p_obj, Rect2 p_rect);
|
||||||
|
@ -43,9 +49,9 @@ private:
|
||||||
void _item_collapsed(Object *p_obj);
|
void _item_collapsed(Object *p_obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
virtual void _update_theme_item_cache() override;
|
||||||
|
|
||||||
void _notification(int p_notification);
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update_tree(const BehaviorTreeData &p_data);
|
void update_tree(const BehaviorTreeData &p_data);
|
||||||
|
|
Loading…
Reference in New Issue