Implement pascal case auto naming for tasks without _generate_name()
This commit is contained in:
parent
2215999689
commit
d5088a9f20
|
@ -24,7 +24,7 @@ String BTTask::_generate_name() const {
|
||||||
String name = get_script_instance()->get_script()->get_path();
|
String name = get_script_instance()->get_script()->get_path();
|
||||||
if (!name.is_empty()) {
|
if (!name.is_empty()) {
|
||||||
// Generate name based on script file
|
// Generate name based on script file
|
||||||
name = name.get_basename().get_file().trim_prefix("BT");
|
name = name.get_basename().get_file().trim_prefix("BT").to_pascal_case();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,52 +397,54 @@ void TaskPanel::refresh() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, List<String>> categories;
|
HashMap<String, List<String>> categorized_tasks;
|
||||||
|
|
||||||
categories["Composites"] = List<String>();
|
categorized_tasks["Composites"] = List<String>();
|
||||||
_populate_core_tasks_from_class("BTComposite", &categories["Composites"]);
|
_populate_core_tasks_from_class("BTComposite", &categorized_tasks["Composites"]);
|
||||||
|
|
||||||
categories["Actions"] = List<String>();
|
categorized_tasks["Actions"] = List<String>();
|
||||||
_populate_core_tasks_from_class("BTAction", &categories["Actions"]);
|
_populate_core_tasks_from_class("BTAction", &categorized_tasks["Actions"]);
|
||||||
|
|
||||||
categories["Decorators"] = List<String>();
|
categorized_tasks["Decorators"] = List<String>();
|
||||||
_populate_core_tasks_from_class("BTDecorator", &categories["Decorators"]);
|
_populate_core_tasks_from_class("BTDecorator", &categorized_tasks["Decorators"]);
|
||||||
|
|
||||||
categories["Conditions"] = List<String>();
|
categorized_tasks["Conditions"] = List<String>();
|
||||||
_populate_core_tasks_from_class("BTCondition", &categories["Conditions"]);
|
_populate_core_tasks_from_class("BTCondition", &categorized_tasks["Conditions"]);
|
||||||
|
|
||||||
categories["User"] = List<String>();
|
categorized_tasks["User"] = List<String>();
|
||||||
|
|
||||||
String dir1 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1");
|
String dir1 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1");
|
||||||
_populate_from_user_dir(dir1, &categories);
|
_populate_from_user_dir(dir1, &categorized_tasks);
|
||||||
|
|
||||||
String dir2 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_2");
|
String dir2 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_2");
|
||||||
_populate_from_user_dir(dir2, &categories);
|
_populate_from_user_dir(dir2, &categorized_tasks);
|
||||||
|
|
||||||
String dir3 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_3");
|
String dir3 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_3");
|
||||||
_populate_from_user_dir(dir3, &categories);
|
_populate_from_user_dir(dir3, &categorized_tasks);
|
||||||
|
|
||||||
List<String> keys;
|
List<String> categories;
|
||||||
for (const KeyValue<String, List<String>> &K : categories) {
|
for (const KeyValue<String, List<String>> &K : categorized_tasks) {
|
||||||
keys.push_back(K.key);
|
categories.push_back(K.key);
|
||||||
}
|
}
|
||||||
keys.sort();
|
categories.sort();
|
||||||
for (List<String>::Element *E = keys.front(); E; E = E->next()) {
|
for (String cat : categories) {
|
||||||
String cat = E->get();
|
List<String> tasks = categorized_tasks.get(cat);
|
||||||
List<String> task_list = categories.get(cat);
|
|
||||||
|
|
||||||
if (task_list.size() == 0) {
|
if (tasks.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskSection *sec = memnew(TaskSection(cat));
|
TaskSection *sec = memnew(TaskSection(cat));
|
||||||
for (List<String>::Element *E = task_list.front(); E; E = E->next()) {
|
for (String task_meta : tasks) {
|
||||||
String meta = E->get();
|
|
||||||
String tname;
|
String tname;
|
||||||
Ref<Texture> icon;
|
Ref<Texture> icon;
|
||||||
icon = LimboAIEditor::get_task_icon(meta);
|
icon = LimboAIEditor::get_task_icon(task_meta);
|
||||||
tname = meta.begins_with("res:") ? meta.get_file().get_basename().trim_prefix("BT") : meta.trim_prefix("BT");
|
if (task_meta.begins_with("res:")) {
|
||||||
sec->add_task_button(tname, icon, meta);
|
tname = task_meta.get_file().get_basename().trim_prefix("BT").to_pascal_case();
|
||||||
|
} else {
|
||||||
|
tname = task_meta.trim_prefix("BT");
|
||||||
|
}
|
||||||
|
sec->add_task_button(tname, icon, task_meta);
|
||||||
}
|
}
|
||||||
sec->set_filter("");
|
sec->set_filter("");
|
||||||
sec->connect("task_button_pressed", callable_mp(this, &TaskPanel::_on_task_button_pressed));
|
sec->connect("task_button_pressed", callable_mp(this, &TaskPanel::_on_task_button_pressed));
|
||||||
|
@ -455,8 +457,8 @@ void TaskPanel::_populate_core_tasks_from_class(const StringName &p_base_class,
|
||||||
List<StringName> inheriters;
|
List<StringName> inheriters;
|
||||||
ClassDB::get_inheriters_from_class(p_base_class, &inheriters);
|
ClassDB::get_inheriters_from_class(p_base_class, &inheriters);
|
||||||
|
|
||||||
for (List<StringName>::Element *E = inheriters.front(); E; E = E->next()) {
|
for (StringName cl : inheriters) {
|
||||||
p_task_classes->push_back(E->get());
|
p_task_classes->push_back(cl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue