Add BTComment task
This commit is contained in:
parent
107b94fad6
commit
a717a3ed8f
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* bt_comment.cpp
|
||||||
|
* =============================================================================
|
||||||
|
* Copyright 2021-2023 Serhii Snitsaruk
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
* =============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bt_comment.h"
|
||||||
|
|
||||||
|
Ref<BTTask> BTComment::clone() const {
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
return BTTask::clone();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* bt_comment.h
|
||||||
|
* =============================================================================
|
||||||
|
* Copyright 2021-2023 Serhii Snitsaruk
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
* =============================================================================
|
||||||
|
*/
|
||||||
|
/* bt_comment.h */
|
||||||
|
|
||||||
|
#ifndef BT_COMMENT_H
|
||||||
|
#define BT_COMMENT_H
|
||||||
|
|
||||||
|
#include "bt_task.h"
|
||||||
|
|
||||||
|
class BTComment : public BTTask {
|
||||||
|
GDCLASS(BTComment, BTTask);
|
||||||
|
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
virtual Ref<BTTask> clone() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BT_COMMENT
|
|
@ -104,10 +104,19 @@ Ref<BTTask> BTTask::clone() const {
|
||||||
inst->data.parent = nullptr;
|
inst->data.parent = nullptr;
|
||||||
inst->data.agent = nullptr;
|
inst->data.agent = nullptr;
|
||||||
inst->data.blackboard.unref();
|
inst->data.blackboard.unref();
|
||||||
|
int num_null = 0;
|
||||||
for (int i = 0; i < data.children.size(); i++) {
|
for (int i = 0; i < data.children.size(); i++) {
|
||||||
Ref<BTTask> c = get_child(i)->clone();
|
Ref<BTTask> c = get_child(i)->clone();
|
||||||
|
if (c.is_valid()) {
|
||||||
c->data.parent = inst.ptr();
|
c->data.parent = inst.ptr();
|
||||||
inst->data.children.set(i, c);
|
inst->data.children.set(i - num_null, c);
|
||||||
|
} else {
|
||||||
|
num_null += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (num_null > 0) {
|
||||||
|
// * BTComment tasks return nullptr at runtime - we remove those.
|
||||||
|
inst->data.children.resize(data.children.size() - num_null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make BBParam properties unique.
|
// Make BBParam properties unique.
|
||||||
|
|
|
@ -65,6 +65,7 @@ def get_doc_classes():
|
||||||
"BTCheckAgentProperty",
|
"BTCheckAgentProperty",
|
||||||
"BTCheckTrigger",
|
"BTCheckTrigger",
|
||||||
"BTCheckVar",
|
"BTCheckVar",
|
||||||
|
"BTComment",
|
||||||
"BTComposite",
|
"BTComposite",
|
||||||
"BTCondition",
|
"BTCondition",
|
||||||
"BTConsolePrint",
|
"BTConsolePrint",
|
||||||
|
|
|
@ -94,9 +94,12 @@ void TaskTree::_update_item(TreeItem *p_item) {
|
||||||
Ref<BTTask> task = p_item->get_metadata(0);
|
Ref<BTTask> task = p_item->get_metadata(0);
|
||||||
ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata.");
|
ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata.");
|
||||||
p_item->set_text(0, task->get_task_name());
|
p_item->set_text(0, task->get_task_name());
|
||||||
if (task->get_custom_name().is_empty()) {
|
if (task->is_class("BTComment")) {
|
||||||
|
p_item->set_custom_font(0, (get_theme_font(SNAME("doc_italic"), SNAME("EditorFonts"))));
|
||||||
|
p_item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
|
||||||
|
} else if (task->get_custom_name().is_empty()) {
|
||||||
p_item->set_custom_font(0, nullptr);
|
p_item->set_custom_font(0, nullptr);
|
||||||
// p_item->clear_custom_color(0);
|
p_item->clear_custom_color(0);
|
||||||
} else {
|
} else {
|
||||||
p_item->set_custom_font(0, (get_theme_font(SNAME("bold"), SNAME("EditorFonts"))));
|
p_item->set_custom_font(0, (get_theme_font(SNAME("bold"), SNAME("EditorFonts"))));
|
||||||
// p_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor")));
|
// p_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor")));
|
||||||
|
@ -1333,6 +1336,15 @@ LimboAIEditor::LimboAIEditor() {
|
||||||
fav_tasks_hbox = memnew(HBoxContainer);
|
fav_tasks_hbox = memnew(HBoxContainer);
|
||||||
toolbar->add_child(fav_tasks_hbox);
|
toolbar->add_child(fav_tasks_hbox);
|
||||||
|
|
||||||
|
comment_btn = memnew(Button);
|
||||||
|
comment_btn->set_text(TTR("Comment"));
|
||||||
|
comment_btn->set_icon(LimboUtility::get_singleton()->get_task_icon("BTComment"));
|
||||||
|
comment_btn->set_tooltip_text(TTR("Add a BTComment task."));
|
||||||
|
comment_btn->set_flat(true);
|
||||||
|
comment_btn->set_focus_mode(Control::FOCUS_NONE);
|
||||||
|
comment_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_add_task_by_class_or_path).bind("BTComment"));
|
||||||
|
toolbar->add_child(comment_btn);
|
||||||
|
|
||||||
toolbar->add_child(memnew(VSeparator));
|
toolbar->add_child(memnew(VSeparator));
|
||||||
|
|
||||||
new_btn = memnew(Button);
|
new_btn = memnew(Button);
|
||||||
|
|
|
@ -171,6 +171,7 @@ private:
|
||||||
TaskPanel *task_panel;
|
TaskPanel *task_panel;
|
||||||
HBoxContainer *fav_tasks_hbox;
|
HBoxContainer *fav_tasks_hbox;
|
||||||
|
|
||||||
|
Button *comment_btn;
|
||||||
Button *new_btn;
|
Button *new_btn;
|
||||||
Button *load_btn;
|
Button *load_btn;
|
||||||
Button *save_btn;
|
Button *save_btn;
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#include "bt/tasks/actions/bt_wait.h"
|
#include "bt/tasks/actions/bt_wait.h"
|
||||||
#include "bt/tasks/actions/bt_wait_ticks.h"
|
#include "bt/tasks/actions/bt_wait_ticks.h"
|
||||||
#include "bt/tasks/bt_action.h"
|
#include "bt/tasks/bt_action.h"
|
||||||
|
#include "bt/tasks/bt_comment.h"
|
||||||
#include "bt/tasks/bt_composite.h"
|
#include "bt/tasks/bt_composite.h"
|
||||||
#include "bt/tasks/bt_condition.h"
|
#include "bt/tasks/bt_condition.h"
|
||||||
#include "bt/tasks/bt_decorator.h"
|
#include "bt/tasks/bt_decorator.h"
|
||||||
|
@ -120,6 +121,8 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) {
|
||||||
GDREGISTER_CLASS(BTPlayer);
|
GDREGISTER_CLASS(BTPlayer);
|
||||||
GDREGISTER_CLASS(BTState);
|
GDREGISTER_CLASS(BTState);
|
||||||
|
|
||||||
|
GDREGISTER_CLASS(BTComment);
|
||||||
|
|
||||||
GDREGISTER_CLASS(BTComposite);
|
GDREGISTER_CLASS(BTComposite);
|
||||||
GDREGISTER_CLASS(BTSequence);
|
GDREGISTER_CLASS(BTSequence);
|
||||||
GDREGISTER_CLASS(BTSelector);
|
GDREGISTER_CLASS(BTSelector);
|
||||||
|
|
Loading…
Reference in New Issue