Add mostly minimal changes in order to compile and run with godot 4

This commit is contained in:
Serhii Snitsaruk 2022-12-15 08:26:52 +01:00
parent 71201a7389
commit dbc9a7ad31
135 changed files with 702 additions and 633 deletions

24
SCsub
View File

@ -1,12 +1,16 @@
# SCsub
#!/usr/bin/env python
Import('env')
Import("env")
Import("env_modules")
env.add_source_files(env.modules_sources, "*.cpp")
env.add_source_files(env.modules_sources, "bt/*.cpp")
env.add_source_files(env.modules_sources, "bt/composites/*.cpp")
env.add_source_files(env.modules_sources, "bt/actions/*.cpp")
env.add_source_files(env.modules_sources, "bt/decorators/*.cpp")
env.add_source_files(env.modules_sources, "bt/conditions/*.cpp")
env.add_source_files(env.modules_sources, "editor/*.cpp")
env.add_source_files(env.modules_sources, "bb_param/*.cpp")
module_env = env.Clone()
module_env.add_source_files(env.modules_sources, "*.cpp")
module_env.add_source_files(env.modules_sources, "bt/*.cpp")
module_env.add_source_files(env.modules_sources, "bt/composites/*.cpp")
module_env.add_source_files(env.modules_sources, "bt/actions/*.cpp")
module_env.add_source_files(env.modules_sources, "bt/decorators/*.cpp")
module_env.add_source_files(env.modules_sources, "bt/conditions/*.cpp")
module_env.add_source_files(env.modules_sources, "bb_param/*.cpp")
if env.editor_build:
module_env.add_source_files(env.modules_sources, "editor/*.cpp")

View File

@ -4,13 +4,13 @@
#define BB_AABB_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBAabb : public BBParam {
GDCLASS(BBAabb, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::AABB; }
virtual Variant::Type get_type() const override { return Variant::AABB; }
};
#endif // BB_AABB_H

View File

@ -4,13 +4,13 @@
#define BB_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBArray : public BBParam {
GDCLASS(BBArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::ARRAY; }
virtual Variant::Type get_type() const override { return Variant::ARRAY; }
};
#endif // BB_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_BASIS_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBBasis : public BBParam {
GDCLASS(BBBasis, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::BASIS; }
virtual Variant::Type get_type() const override { return Variant::BASIS; }
};
#endif // BB_BASIS_H

View File

@ -4,13 +4,13 @@
#define BB_BOOL_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBBool : public BBParam {
GDCLASS(BBBool, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::BOOL; }
virtual Variant::Type get_type() const override { return Variant::BOOL; }
};
#endif // BB_BOOL_H

View File

@ -4,13 +4,13 @@
#define BB_BYTE_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBByteArray : public BBParam {
GDCLASS(BBByteArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_BYTE_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_BYTE_ARRAY; }
};
#endif // BB_BYTE_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_COLOR_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBColor : public BBParam {
GDCLASS(BBColor, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::COLOR; }
virtual Variant::Type get_type() const override { return Variant::COLOR; }
};
#endif // BB_COLOR_H

View File

@ -4,13 +4,13 @@
#define BB_COLOR_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBColorArray : public BBParam {
GDCLASS(BBColorArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_COLOR_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_COLOR_ARRAY; }
};
#endif // BB_COLOR_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_DICTIONARY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBDictionary : public BBParam {
GDCLASS(BBDictionary, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::DICTIONARY; }
virtual Variant::Type get_type() const override { return Variant::DICTIONARY; }
};
#endif // BB_DICTIONARY_H

View File

@ -4,13 +4,13 @@
#define BB_FLOAT_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBFloat : public BBParam {
GDCLASS(BBFloat, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::REAL; }
virtual Variant::Type get_type() const override { return Variant::FLOAT; }
};
#endif // BB_FLOAT_H

View File

@ -4,13 +4,13 @@
#define BB_INT_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBInt : public BBParam {
GDCLASS(BBInt, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::INT; }
virtual Variant::Type get_type() const override { return Variant::INT; }
};
#endif // BB_INT_H

View File

@ -4,13 +4,13 @@
#define BB_INT_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBIntArray : public BBParam {
GDCLASS(BBIntArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_INT_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_INT64_ARRAY; }
};
#endif // BB_INT_ARRAY_H

View File

@ -1,8 +1,8 @@
/* bb_node.cpp */
#include "bb_node.h"
#include "core/error_macros.h"
#include "core/variant.h"
#include "core/error/error_macros.h"
#include "core/variant/variant.h"
#include "scene/main/node.h"
Variant BBNode::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default) {
@ -21,7 +21,7 @@ Variant BBNode::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard,
ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node.");
return agent->get_node(val);
} else {
Node *node = val;
Node *node = Object::cast_to<Node>(val);
if (unlikely(node == nullptr && val.get_type() != Variant::NIL)) {
WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable.");
return p_default;

View File

@ -4,16 +4,16 @@
#define BB_NODE_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBNode : public BBParam {
GDCLASS(BBNode, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::NODE_PATH; }
virtual Variant::Type get_type() const override { return Variant::NODE_PATH; }
public:
virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());
virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override;
};
#endif // BB_NODE_H

View File

@ -1,25 +1,26 @@
/* bb_param.cpp */
#include "bb_param.h"
#include "core/class_db.h"
#include "core/error_macros.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/core_bind.h"
#include "core/error/error_macros.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
#include "modules/limboai/limbo_utility.h"
VARIANT_ENUM_CAST(BBParam::ValueSource);
void BBParam::set_value_source(ValueSource p_value) {
value_source = p_value;
property_list_changed_notify();
notify_property_list_changed();
_update_name();
emit_changed();
}
Variant BBParam::get_saved_value() {
if (saved_value.get_type() != get_type()) {
Variant::CallError err;
saved_value = Variant::construct(get_type(), nullptr, 0, err);
Callable::CallError err;
Variant::construct(get_type(), saved_value, nullptr, 0, err);
}
return saved_value;
}

View File

@ -3,10 +3,10 @@
#ifndef BB_PARAM_H
#define BB_PARAM_H
#include "core/object.h"
#include "core/resource.h"
#include "core/io/resource.h"
#include "core/object/object.h"
#include "core/typedefs.h"
#include "core/variant.h"
#include "core/variant/variant.h"
#include "modules/limboai/blackboard.h"
#include "modules/limboai/limbo_utility.h"
@ -45,7 +45,7 @@ public:
void set_variable(const String &p_value);
String get_variable() const { return variable; }
virtual String to_string();
virtual String to_string() override;
virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());

View File

@ -4,13 +4,13 @@
#define BB_PLANE_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBPlane : public BBParam {
GDCLASS(BBPlane, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::PLANE; }
virtual Variant::Type get_type() const override { return Variant::PLANE; }
};
#endif // BB_PLANE_H

View File

@ -4,13 +4,13 @@
#define BB_QUAT_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBQuat : public BBParam {
GDCLASS(BBQuat, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::QUAT; }
virtual Variant::Type get_type() const override { return Variant::QUATERNION; }
};
#endif // BB_QUAT_H

View File

@ -4,13 +4,13 @@
#define BB_REAL_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBRealArray : public BBParam {
GDCLASS(BBRealArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_REAL_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_FLOAT64_ARRAY; }
};
#endif // BB_REAL_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_RECT2_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBRect2 : public BBParam {
GDCLASS(BBRect2, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::RECT2; }
virtual Variant::Type get_type() const override { return Variant::RECT2; }
};
#endif // BB_RECT2_H

View File

@ -4,13 +4,13 @@
#define BB_STRING_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBString : public BBParam {
GDCLASS(BBString, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::STRING; }
virtual Variant::Type get_type() const override { return Variant::STRING; }
};
#endif // BB_STRING_H

View File

@ -4,13 +4,13 @@
#define BB_STRING_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBStringArray : public BBParam {
GDCLASS(BBStringArray, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_STRING_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_STRING_ARRAY; }
};
#endif // BB_STRING_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_TRANSFORM_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBTransform : public BBParam {
GDCLASS(BBTransform, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::TRANSFORM; }
virtual Variant::Type get_type() const override { return Variant::TRANSFORM3D; }
};
#endif // BB_TRANSFORM_H

View File

@ -4,13 +4,13 @@
#define BB_TRANSFORM2D_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBTransform2D : public BBParam {
GDCLASS(BBTransform2D, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::TRANSFORM2D; }
virtual Variant::Type get_type() const override { return Variant::TRANSFORM2D; }
};
#endif // BB_TRANSFORM2D_H

View File

@ -1,12 +1,12 @@
/* bb_variant.cpp */
#include "bb_variant.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
void BBVariant::set_type(Variant::Type p_type) {
type = p_type;
property_list_changed_notify();
notify_property_list_changed();
emit_changed();
}

View File

@ -4,8 +4,8 @@
#define BB_VARIANT_H
#include "bb_param.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
class BBVariant : public BBParam {
GDCLASS(BBVariant, BBParam);
@ -16,7 +16,7 @@ private:
protected:
static void _bind_methods();
virtual Variant::Type get_type() const { return type; }
virtual Variant::Type get_type() const override { return type; }
void set_type(Variant::Type p_type);
public:

View File

@ -4,13 +4,13 @@
#define BB_VECTOR2_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBVector2 : public BBParam {
GDCLASS(BBVector2, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::VECTOR2; }
virtual Variant::Type get_type() const override { return Variant::VECTOR2; }
};
#endif // BB_VECTOR2_H

View File

@ -4,13 +4,13 @@
#define BB_VECTOR2_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBVector2Array : public BBParam {
GDCLASS(BBVector2Array, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_VECTOR2_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_VECTOR2_ARRAY; }
};
#endif // BB_VECTOR2_ARRAY_H

View File

@ -4,13 +4,13 @@
#define BB_VECTOR3_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBVector3 : public BBParam {
GDCLASS(BBVector3, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::VECTOR3; }
virtual Variant::Type get_type() const override { return Variant::VECTOR3; }
};
#endif // BB_VECTOR3_H

View File

@ -4,13 +4,13 @@
#define BB_VECTOR3_ARRAY_H
#include "bb_param.h"
#include "core/object.h"
#include "core/object/object.h"
class BBVector3Array : public BBParam {
GDCLASS(BBVector3Array, BBParam);
protected:
virtual Variant::Type get_type() const { return Variant::POOL_VECTOR3_ARRAY; }
virtual Variant::Type get_type() const override { return Variant::PACKED_VECTOR3_ARRAY; }
};
#endif // BB_VECTOR3_ARRAY_H

View File

@ -1,10 +1,9 @@
/* blackboard.cpp */
#include "blackboard.h"
#include "core/error_macros.h"
#include "core/variant.h"
#include "core/error/error_macros.h"
#include "core/variant/variant.h"
#include "scene/main/node.h"
#include <cstddef>
Ref<Blackboard> Blackboard::top() const {
Ref<Blackboard> bb(this);

View File

@ -3,13 +3,14 @@
#ifndef BLACKBOARD_H
#define BLACKBOARD_H
#include "core/dictionary.h"
#include "core/object.h"
#include "core/reference.h"
#include "core/variant.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/variant/dictionary.h"
#include "core/variant/variant.h"
#include "scene/main/node.h"
class Blackboard : public Reference {
GDCLASS(Blackboard, Reference);
class Blackboard : public RefCounted {
GDCLASS(Blackboard, RefCounted);
private:
Dictionary data;

View File

@ -4,7 +4,7 @@
String BTAction::get_configuration_warning() const {
String warning = BTTask::get_configuration_warning();
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (get_child_count() != 0) {

View File

@ -4,13 +4,13 @@
#define BT_ACTION_H
#include "../bt_task.h"
#include "core/object.h"
#include "core/object/object.h"
class BTAction : public BTTask {
GDCLASS(BTAction, BTTask);
public:
virtual String get_configuration_warning() const;
virtual String get_configuration_warning() const override;
};
#endif // BT_ACTION_H

View File

@ -1,8 +1,8 @@
/* bt_console_print.cpp */
#include "bt_console_print.h"
#include "core/object.h"
#include "core/print_string.h"
#include "core/object/object.h"
#include "core/string/print_string.h"
#include "modules/limboai/bt/actions/bt_action.h"
String BTConsolePrint::_generate_name() const {
@ -54,7 +54,7 @@ int BTConsolePrint::_tick(float p_delta) {
String BTConsolePrint::get_configuration_warning() const {
String warning = BTAction::get_configuration_warning();
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (format_var_args.size() > 5) {
@ -70,5 +70,5 @@ void BTConsolePrint::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_format_var_args"), &BTConsolePrint::get_format_var_args);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "format_var_args"), "set_format_var_args", "get_format_var_args");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "format_var_args"), "set_format_var_args", "get_format_var_args");
}

View File

@ -4,21 +4,21 @@
#define BT_CONSOLE_PRINT_H
#include "bt_action.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
class BTConsolePrint : public BTAction {
GDCLASS(BTConsolePrint, BTAction);
private:
String text;
PoolStringArray format_var_args;
PackedStringArray format_var_args;
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual int _tick(float p_delta) override;
public:
void set_text(String p_value) {
@ -27,13 +27,13 @@ public:
}
String get_text() const { return text; }
void set_format_var_args(const PoolStringArray &p_value) {
void set_format_var_args(const PackedStringArray &p_value) {
format_var_args = p_value;
emit_changed();
}
PoolStringArray get_format_var_args() const { return format_var_args; }
PackedStringArray get_format_var_args() const { return format_var_args; }
virtual String get_configuration_warning() const;
virtual String get_configuration_warning() const override;
};
#endif // BT_CONSOLE_PRINT_H

View File

@ -4,13 +4,13 @@
#define BT_FAIL_H
#include "bt_action.h"
#include "core/object.h"
#include "core/object/object.h"
class BTFail : public BTAction {
GDCLASS(BTFail, BTAction);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_FAIL_H

View File

@ -4,7 +4,7 @@
#define BT_RANDOM_WAIT_H
#include "bt_action.h"
#include "core/object.h"
#include "core/object/object.h"
class BTRandomWait : public BTAction {
GDCLASS(BTRandomWait, BTAction);
@ -18,9 +18,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_duration_min_max(Vector2 p_value) {

View File

@ -1,9 +1,9 @@
/* bt_wait.cpp */
#include "bt_wait.h"
#include "core/class_db.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
String BTWait::_generate_name() const {
return vformat("Wait %ss", duration);
@ -26,5 +26,5 @@ void BTWait::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_duration", "p_value"), &BTWait::set_duration);
ClassDB::bind_method(D_METHOD("get_duration"), &BTWait::get_duration);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "duration"), "set_duration", "get_duration");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "duration"), "set_duration", "get_duration");
}

View File

@ -4,7 +4,7 @@
#define BT_WAIT_H
#include "bt_action.h"
#include "core/object.h"
#include "core/object/object.h"
class BTWait : public BTAction {
GDCLASS(BTWait, BTAction);
@ -17,9 +17,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_duration(float p_value) {

View File

@ -1,9 +1,9 @@
/* bt_wait_ticks.cpp */
#include "bt_wait_ticks.h"
#include "core/class_db.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
String BTWaitTicks::_generate_name() const {
return vformat("WaitTicks x%d", num_ticks);

View File

@ -4,7 +4,7 @@
#define BT_WAIT_TICKS_H
#include "bt_action.h"
#include "core/object.h"
#include "core/object/object.h"
class BTWaitTicks : public BTAction {
GDCLASS(BTWaitTicks, BTAction);
@ -17,9 +17,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_num_ticks(int p_value) {

View File

@ -1,12 +1,11 @@
/* behavior_tree.cpp */
#include "behavior_tree.h"
#include "core/class_db.h"
#include "core/error_macros.h"
#include "core/list.h"
#include "core/object.h"
#include "core/variant.h"
#include <cstddef>
#include "core/error/error_macros.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/templates/list.h"
#include "core/variant/variant.h"
void BehaviorTree::init() {
List<BTTask *> stack;
@ -17,7 +16,7 @@ void BehaviorTree::init() {
stack.push_back(task->get_child(i).ptr());
}
task = nullptr;
if (!stack.empty()) {
if (!stack.is_empty()) {
task = stack.front()->get();
stack.pop_front();
}

View File

@ -4,8 +4,8 @@
#define BEHAVIOR_TREE_H
#include "bt_task.h"
#include "core/object.h"
#include "core/resource.h"
#include "core/io/resource.h"
#include "core/object/object.h"
#include "modules/limboai/blackboard.h"
class BehaviorTree : public Resource {

View File

@ -4,14 +4,13 @@
#include "../limbo_string_names.h"
#include "bt_task.h"
#include "core/class_db.h"
#include "core/engine.h"
#include "core/config/engine.h"
#include "core/io/resource_loader.h"
#include "core/object.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/os/memory.h"
#include "core/variant.h"
#include "core/variant/variant.h"
#include "modules/limboai/blackboard.h"
#include <cstddef>
VARIANT_ENUM_CAST(BTPlayer::UpdateMode);

View File

@ -5,7 +5,7 @@
#include "behavior_tree.h"
#include "bt_task.h"
#include "core/object.h"
#include "core/object/object.h"
#include "modules/limboai/blackboard.h"
#include "scene/main/node.h"

View File

@ -1,8 +1,8 @@
/* bt_state.cpp */
#include "bt_state.h"
#include "core/class_db.h"
#include "core/variant.h"
#include "core/object/class_db.h"
#include "core/variant/variant.h"
#include "modules/limboai/bt/bt_task.h"
#include "modules/limboai/limbo_state.h"

View File

@ -3,7 +3,7 @@
#ifndef BT_STATE_H
#define BT_STATE_H
#include "core/object.h"
#include "core/object/object.h"
#include "modules/limboai/bt/behavior_tree.h"
#include "modules/limboai/bt/bt_task.h"
#include "modules/limboai/limbo_state.h"
@ -20,10 +20,10 @@ private:
protected:
static void _bind_methods();
virtual void _setup();
virtual void _enter() {}
virtual void _exit();
virtual void _update(float p_delta);
virtual void _setup() override;
virtual void _enter() override {}
virtual void _exit() override;
virtual void _update(float p_delta) override;
public:
void set_behavior_tree(const Ref<BehaviorTree> &p_value) { behavior_tree = p_value; }

View File

@ -2,16 +2,18 @@
#include "bt_task.h"
#include "core/class_db.h"
#include "core/error_macros.h"
#include "core/object.h"
#include "core/script_language.h"
#include "core/variant.h"
#include "editor/editor_node.h"
#include "core/error/error_macros.h"
#include "core/io/resource.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/object/script_language.h"
#include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/variant/variant.h"
#include "modules/limboai/blackboard.h"
#include "modules/limboai/limbo_string_names.h"
#include "modules/limboai/limbo_utility.h"
#include <cstddef>
String BTTask::_generate_name() const {
if (get_script_instance()) {
@ -20,7 +22,7 @@ String BTTask::_generate_name() const {
return get_script_instance()->call(LimboStringNames::get_singleton()->_generate_name);
}
String name = get_script_instance()->get_script()->get_path();
if (!name.empty()) {
if (!name.is_empty()) {
// Generate name based on script file
name = name.get_basename().get_file().trim_prefix("BT");
return name;
@ -53,7 +55,7 @@ void BTTask::_set_children(Array p_children) {
}
String BTTask::get_task_name() const {
if (custom_name.empty()) {
if (custom_name.is_empty()) {
return _generate_name();
}
return custom_name;
@ -82,12 +84,16 @@ void BTTask::initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) {
for (int i = 0; i < children.size(); i++) {
get_child(i)->initialize(p_agent, p_blackboard);
}
if (get_script_instance() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_setup)) {
get_script_instance()->call(LimboStringNames::get_singleton()->_setup);
} else {
if (!GDVIRTUAL_CALL(_setup)) {
_setup();
}
// if (get_script_instance() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_setup)) {
// get_script_instance()->call(LimboStringNames::get_singleton()->_setup);
// } else {
// _setup();
// }
}
Ref<BTTask> BTTask::clone() const {
@ -104,7 +110,7 @@ Ref<BTTask> BTTask::clone() const {
// Make BBParam properties unique.
List<PropertyInfo> props;
inst->get_property_list(&props);
Map<RES, RES> duplicates;
HashMap<Ref<Resource>, Ref<Resource>> duplicates;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
@ -112,10 +118,10 @@ Ref<BTTask> BTTask::clone() const {
Variant v = inst->get(E->get().name);
if (v.is_ref()) {
REF ref = v;
if (v.is_ref_counted()) {
Ref<RefCounted> ref = v;
if (ref.is_valid()) {
RES res = ref;
Ref<Resource> res = ref;
if (res.is_valid() && res->is_class("BBParam")) {
if (!duplicates.has(res)) {
duplicates[res] = res->duplicate();
@ -132,31 +138,40 @@ Ref<BTTask> BTTask::clone() const {
int BTTask::execute(float p_delta) {
if (status != RUNNING) {
if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_enter)) {
get_script_instance()->call(LimboStringNames::get_singleton()->_enter);
} else {
if (!GDVIRTUAL_CALL(_enter)) {
_enter();
}
// if (get_script_instance() &&
// // get_script_instance()->get_script()->is_valid() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_enter)) {
// get_script_instance()->call(LimboStringNames::get_singleton()->_enter);
// } else {
// _enter();
// }
}
if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_tick)) {
status = get_script_instance()->call(LimboStringNames::get_singleton()->_tick, Variant(p_delta));
} else {
if (!GDVIRTUAL_CALL(_tick, p_delta, status)) {
status = _tick(p_delta);
}
// if (get_script_instance() &&
// // get_script_instance()->get_script()->is_valid() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_tick)) {
// status = get_script_instance()->call(LimboStringNames::get_singleton()->_tick, Variant(p_delta));
// } else {
// status = _tick(p_delta);
// }
if (status != RUNNING) {
if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
get_script_instance()->call(LimboStringNames::get_singleton()->_exit);
} else {
if (!GDVIRTUAL_CALL(_exit)) {
_exit();
}
// if (get_script_instance() &&
// // get_script_instance()->get_script()->is_valid() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
// get_script_instance()->call(LimboStringNames::get_singleton()->_exit);
// } else {
// _exit();
// }
}
return status;
}
@ -166,13 +181,16 @@ void BTTask::cancel() {
get_child(i)->cancel();
}
if (status == RUNNING) {
if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
get_script_instance()->call(LimboStringNames::get_singleton()->_exit);
} else {
if (!GDVIRTUAL_CALL(_exit)) {
_exit();
}
// if (get_script_instance() &&
// // get_script_instance()->get_script()->is_valid() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
// get_script_instance()->call(LimboStringNames::get_singleton()->_exit);
// } else {
// _exit();
// }
}
status = FRESH;
}
@ -208,7 +226,7 @@ void BTTask::remove_child(Ref<BTTask> p_child) {
if (idx == -1) {
ERR_FAIL_MSG("p_child not found!");
} else {
children.remove(idx);
children.remove_at(idx);
p_child->parent = nullptr;
emit_changed();
}
@ -216,7 +234,7 @@ void BTTask::remove_child(Ref<BTTask> p_child) {
void BTTask::remove_child_at_index(int p_idx) {
ERR_FAIL_INDEX(p_idx, get_child_count());
children.remove(p_idx);
children.remove_at(p_idx);
}
bool BTTask::has_child(const Ref<BTTask> &p_child) const {
@ -250,10 +268,13 @@ Ref<BTTask> BTTask::next_sibling() const {
String BTTask::get_configuration_warning() const {
String warning = "";
if (get_script_instance() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_get_configuration_warning)) {
warning = get_script_instance()->call(LimboStringNames::get_singleton()->_get_configuration_warning);
}
GDVIRTUAL_CALL(_get_configuration_warning, warning);
// if (get_script_instance() &&
// get_script_instance()->has_method(LimboStringNames::get_singleton()->_get_configuration_warning)) {
// warning = get_script_instance()->call(LimboStringNames::get_singleton()->_get_configuration_warning);
// }
return warning;
}
@ -287,22 +308,24 @@ void BTTask::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "agent", PROPERTY_HINT_RESOURCE_TYPE, "Object", 0), "set_agent", "get_agent");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_RESOURCE_TYPE, "Blackboard", 0), "", "get_blackboard");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "parent", PROPERTY_HINT_RESOURCE_TYPE, "BTTask", 0), "", "get_parent");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "children", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_children", "_get_children");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "children", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_children", "_get_children");
ADD_PROPERTY(PropertyInfo(Variant::INT, "status", PROPERTY_HINT_NONE, "", 0), "", "get_status");
// Virtual methods.
// TODO: Remove if unneeded.
ClassDB::bind_method(D_METHOD("_setup"), &BTTask::_setup);
BIND_VMETHOD(MethodInfo("_setup"));
ClassDB::bind_method(D_METHOD("_enter"), &BTTask::_enter);
BIND_VMETHOD(MethodInfo("_enter"))
ClassDB::bind_method(D_METHOD("_exit"), &BTTask::_exit);
BIND_VMETHOD(MethodInfo("_exit"));
ClassDB::bind_method(D_METHOD("_tick", "p_delta"), &BTTask::_tick);
BIND_VMETHOD(MethodInfo(Variant::INT, "_tick", PropertyInfo(Variant::REAL, "p_delta")));
ClassDB::bind_method(D_METHOD("_generate_name"), &BTTask::_generate_name);
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::STRING, ""), "_generate_name"));
ClassDB::bind_method(D_METHOD("_get_configuration_warning"), &BTTask::get_configuration_warning);
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::STRING, ""), "_get_configuration_warning"));
GDVIRTUAL_BIND(_setup);
GDVIRTUAL_BIND(_enter);
GDVIRTUAL_BIND(_exit);
GDVIRTUAL_BIND(_tick, "p_delta");
GDVIRTUAL_BIND(_generate_name);
GDVIRTUAL_BIND(_get_configuration_warning);
// Public Methods.
ClassDB::bind_method(D_METHOD("is_root"), &BTTask::is_root);

View File

@ -3,13 +3,13 @@
#ifndef BTTASK_H
#define BTTASK_H
#include "core/array.h"
#include "core/dictionary.h"
#include "core/object.h"
#include "core/reference.h"
#include "core/resource.h"
#include "core/ustring.h"
#include "core/vector.h"
#include "core/io/resource.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/string/ustring.h"
#include "core/templates/vector.h"
#include "core/variant/array.h"
#include "core/variant/dictionary.h"
#include "modules/limboai/blackboard.h"
#include "scene/resources/texture.h"
@ -46,6 +46,13 @@ protected:
virtual void _exit() {}
virtual int _tick(float p_delta) { return FAILURE; }
GDVIRTUAL0RC(String, _generate_name);
GDVIRTUAL0(_setup);
GDVIRTUAL0(_enter);
GDVIRTUAL0(_exit);
GDVIRTUAL1R(int, _tick, float);
GDVIRTUAL0RC(String, _get_configuration_warning);
public:
Object *get_agent() const { return agent; }
void set_agent(Object *p_agent) { agent = p_agent; }
@ -60,6 +67,7 @@ public:
virtual Ref<BTTask> clone() const;
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
int execute(float p_delta);
void cancel();
Ref<BTTask> get_child(int p_idx) const;

View File

@ -4,7 +4,7 @@
String BTComposite::get_configuration_warning() const {
String warning = BTTask::get_configuration_warning();
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (get_child_count() < 1) {

View File

@ -4,13 +4,13 @@
#define BT_COMPOSITE_H
#include "../bt_task.h"
#include "core/object.h"
#include "core/object/object.h"
class BTComposite : public BTTask {
GDCLASS(BTComposite, BTTask);
public:
virtual String get_configuration_warning() const;
virtual String get_configuration_warning() const override;
};
#endif // BT_COMPOSITE_H

View File

@ -4,7 +4,7 @@
#define BT_DYNAMIC_SELECTOR_H
#include "bt_composite.h"
#include "core/object.h"
#include "core/object/object.h"
class BTDynamicSelector : public BTComposite {
GDCLASS(BTDynamicSelector, BTComposite);
@ -13,8 +13,8 @@ private:
int last_running_idx = 0;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_DYNAMIC_SELECTOR_H

View File

@ -4,7 +4,7 @@
#define BT_DYNAMIC_SEQUENCE_H
#include "bt_composite.h"
#include "core/object.h"
#include "core/object/object.h"
class BTDynamicSequence : public BTComposite {
GDCLASS(BTDynamicSequence, BTComposite);
@ -13,8 +13,8 @@ private:
int last_running_idx = 0;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_DYNAMIC_SEQUENCE_H

View File

@ -1,7 +1,7 @@
/* bt_parallel.cpp */
#include "bt_parallel.h"
#include "core/class_db.h"
#include "core/object/class_db.h"
void BTParallel::_enter() {
for (int i = 0; i < get_child_count(); i++) {

View File

@ -4,7 +4,7 @@
#define BT_PARALLEL_H
#include "bt_composite.h"
#include "core/object.h"
#include "core/object/object.h"
class BTParallel : public BTComposite {
GDCLASS(BTParallel, BTComposite);
@ -17,8 +17,8 @@ private:
protected:
static void _bind_methods();
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
int get_num_successes_required() const { return num_successes_required; }

View File

@ -4,7 +4,7 @@
#define BT_RANDOM_SELECTOR_H
#include "bt_composite.h"
#include "core/vector.h"
#include "core/templates/vector.h"
class BTRandomSelector : public BTComposite {
GDCLASS(BTRandomSelector, BTComposite);
@ -14,7 +14,7 @@ private:
Array _indicies;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_RANDOM_SELECTOR_H

View File

@ -4,7 +4,7 @@
#define BT_RANDOM_SEQUENCE_H
#include "bt_composite.h"
#include "core/vector.h"
#include "core/templates/vector.h"
class BTRandomSequence : public BTComposite {
GDCLASS(BTRandomSequence, BTComposite);
@ -14,7 +14,7 @@ private:
Array _indicies;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_RANDOM_SEQUENCE_H

View File

@ -12,7 +12,7 @@ private:
int last_running_idx = 0;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_SELECTOR_H

View File

@ -4,7 +4,7 @@
#define BT_SEQUENCE_H
#include "bt_composite.h"
#include "core/object.h"
#include "core/object/object.h"
class BTSequence : public BTComposite {
GDCLASS(BTSequence, BTComposite);
@ -13,8 +13,8 @@ private:
int last_running_idx = 0;
protected:
virtual void _enter();
virtual int _tick(float p_delta);
virtual void _enter() override;
virtual int _tick(float p_delta) override;
};
#endif // BT_SEQUENCE_H

View File

@ -4,7 +4,7 @@
String BTCondition::get_configuration_warning() const {
String warning = BTTask::get_configuration_warning();
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (get_child_count() != 0) {

View File

@ -4,13 +4,13 @@
#define BT_CONDITION_H
#include "../bt_task.h"
#include "core/object.h"
#include "core/object/object.h"
class BTCondition : public BTTask {
GDCLASS(BTCondition, BTTask);
public:
virtual String get_configuration_warning() const;
virtual String get_configuration_warning() const override;
};
#endif // BT_CONDITION_H

View File

@ -4,13 +4,13 @@
#define BT_ALWAYS_FAIL_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTAlwaysFail : public BTDecorator {
GDCLASS(BTAlwaysFail, BTDecorator);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_ALWAYS_FAIL_H

View File

@ -4,13 +4,13 @@
#define BT_ALWAYS_SUCCEED_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTAlwaysSucceed : public BTDecorator {
GDCLASS(BTAlwaysSucceed, BTDecorator);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_ALWAYS_SUCCEED_H

View File

@ -1,8 +1,8 @@
/* bt_cooldown.cpp */
#include "bt_cooldown.h"
#include "core/array.h"
#include "core/class_db.h"
#include "core/object/class_db.h"
#include "core/variant/array.h"
#include "scene/main/scene_tree.h"
String BTCooldown::_generate_name() const {
@ -10,7 +10,7 @@ String BTCooldown::_generate_name() const {
}
void BTCooldown::_setup() {
if (cooldown_state_var.empty()) {
if (cooldown_state_var.is_empty()) {
cooldown_state_var = vformat("cooldown_%d", rand());
}
get_blackboard()->set_var(cooldown_state_var, false);
@ -37,7 +37,7 @@ void BTCooldown::_chill() {
_timer->set_time_left(duration);
} else {
_timer = SceneTree::get_singleton()->create_timer(duration, process_pause);
_timer->connect("timeout", this, "_on_timeout", Vector<Variant>(), CONNECT_ONESHOT);
_timer->connect("timeout", callable_mp(this, &BTCooldown::_on_timeout), CONNECT_ONE_SHOT);
}
}
@ -59,7 +59,7 @@ void BTCooldown::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_cooldown_state_var"), &BTCooldown::get_cooldown_state_var);
ClassDB::bind_method(D_METHOD("_on_timeout"), &BTCooldown::_on_timeout);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "duration"), "set_duration", "get_duration");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "duration"), "set_duration", "get_duration");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "process_pause"), "set_process_pause", "get_process_pause");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "start_cooled"), "set_start_cooled", "get_start_cooled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trigger_on_failure"), "set_trigger_on_failure", "get_trigger_on_failure");

View File

@ -4,7 +4,7 @@
#define BT_COOLDOWN_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
#include "scene/main/scene_tree.h"
class BTCooldown : public BTDecorator {
@ -25,9 +25,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _setup();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _setup() override;
virtual int _tick(float p_delta) override;
public:
void set_duration(float p_value) {

View File

@ -4,7 +4,7 @@
String BTDecorator::get_configuration_warning() const {
String warning = BTTask::get_configuration_warning();
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (get_child_count() != 1) {

View File

@ -4,13 +4,13 @@
#define BT_DECORATOR_H
#include "../bt_task.h"
#include "core/object.h"
#include "core/object/object.h"
class BTDecorator : public BTTask {
GDCLASS(BTDecorator, BTTask)
public:
virtual String get_configuration_warning() const;
virtual String get_configuration_warning() const override;
};
#endif // BT_DECORATOR_H

View File

@ -1,11 +1,11 @@
/* bt_delay.cpp */
#include "bt_delay.h"
#include "core/array.h"
#include "core/class_db.h"
#include "core/error_macros.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/error/error_macros.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/array.h"
#include "core/variant/variant.h"
String BTDelay::_generate_name() const {
return vformat("Delay %ss", seconds);
@ -27,5 +27,5 @@ int BTDelay::_tick(float p_delta) {
void BTDelay::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seconds", "p_value"), &BTDelay::set_seconds);
ClassDB::bind_method(D_METHOD("get_seconds"), &BTDelay::get_seconds);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "seconds"), "set_seconds", "get_seconds");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "seconds"), "set_seconds", "get_seconds");
}

View File

@ -4,7 +4,7 @@
#define BT_DELAY_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTDelay : public BTDecorator {
GDCLASS(BTDelay, BTDecorator);
@ -16,9 +16,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_seconds(float p_value) {

View File

@ -1,9 +1,9 @@
/* bt_for_each.cpp */
#include "bt_for_each.h"
#include "core/error_list.h"
#include "core/error_macros.h"
#include "core/variant.h"
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#include "core/variant/variant.h"
#include "modules/limboai/blackboard.h"
#include "modules/limboai/limbo_utility.h"
@ -19,8 +19,8 @@ void BTForEach::_enter() {
int BTForEach::_tick(float p_delta) {
ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "ForEach decorator has no child.");
ERR_FAIL_COND_V_MSG(save_var.empty(), FAILURE, "ForEach save variable is not set.");
ERR_FAIL_COND_V_MSG(array_var.empty(), FAILURE, "ForEach array variable is not set.");
ERR_FAIL_COND_V_MSG(save_var.is_empty(), FAILURE, "ForEach save variable is not set.");
ERR_FAIL_COND_V_MSG(array_var.is_empty(), FAILURE, "ForEach array variable is not set.");
Array arr = get_blackboard()->get_var(array_var, Variant());
if (arr.size() == 0) {

View File

@ -4,7 +4,7 @@
#define BT_FOR_EACH_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTForEach : public BTDecorator {
GDCLASS(BTForEach, BTDecorator);
@ -18,9 +18,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_array_var(String p_value) {

View File

@ -4,13 +4,13 @@
#define BT_INVERT_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTInvert : public BTDecorator {
GDCLASS(BTInvert, BTDecorator);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_INVERT_H

View File

@ -1,9 +1,9 @@
/* bt_new_scope.cpp */
#include "bt_new_scope.h"
#include "core/error_macros.h"
#include "core/error/error_macros.h"
#include "core/os/memory.h"
#include "core/ustring.h"
#include "core/string/ustring.h"
#include "modules/limboai/blackboard.h"
void BTNewScope::initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) {

View File

@ -4,7 +4,7 @@
#define BT_NEW_SCOPE_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
#include "bt_decorator.h"
class BTNewScope : public BTDecorator {
@ -19,10 +19,10 @@ protected:
void _set_blackboard_data(const Dictionary &p_value) { blackboard_data = p_value; }
Dictionary _get_blackboard_data() const { return blackboard_data; }
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
public:
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) override;
};
#endif // BT_NEW_SCOPE_H

View File

@ -1,7 +1,7 @@
/* bt_probability.cpp */
#include "bt_probability.h"
#include "core/object.h"
#include "core/object/object.h"
String BTProbability::_generate_name() const {
return vformat("Probability %.1f%%", run_chance);
@ -18,5 +18,5 @@ int BTProbability::_tick(float p_delta) {
void BTProbability::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_run_chance", "p_value"), &BTProbability::set_run_chance);
ClassDB::bind_method(D_METHOD("get_run_chance"), &BTProbability::get_run_chance);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "run_chance", PROPERTY_HINT_RANGE, "0.0,1.0"), "set_run_chance", "get_run_chance");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "run_chance", PROPERTY_HINT_RANGE, "0.0,1.0"), "set_run_chance", "get_run_chance");
}

View File

@ -4,7 +4,7 @@
#define BT_PROBABILITY_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTProbability : public BTDecorator {
GDCLASS(BTProbability, BTDecorator);
@ -15,8 +15,8 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual int _tick(float p_delta) override;
public:
void set_run_chance(float p_value) {

View File

@ -1,8 +1,8 @@
/* bt_repeat.cpp */
#include "bt_repeat.h"
#include "core/object.h"
#include "core/variant.h"
#include "core/object/object.h"
#include "core/variant/variant.h"
String BTRepeat::_generate_name() const {
return vformat("Repeat x%s", times);

View File

@ -4,7 +4,7 @@
#define BT_REPEAT_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTRepeat : public BTDecorator {
GDCLASS(BTRepeat, BTDecorator);
@ -17,9 +17,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_times(int p_value) {

View File

@ -4,13 +4,13 @@
#define BT_REPEAT_UNTIL_FAILURE_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTRepeatUntilFailure : public BTDecorator {
GDCLASS(BTRepeatUntilFailure, BTDecorator);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_REPEAT_UNTIL_FAILURE_H

View File

@ -4,13 +4,13 @@
#define BT_REPEAT_UNTIL_SUCCESS_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTRepeatUntilSuccess : public BTDecorator {
GDCLASS(BTRepeatUntilSuccess, BTDecorator);
protected:
virtual int _tick(float p_delta);
virtual int _tick(float p_delta) override;
};
#endif // BT_REPEAT_UNTIL_SUCCESS_H

View File

@ -4,7 +4,7 @@
#define BT_RUN_LIMIT_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTRunLimit : public BTDecorator {
GDCLASS(BTRunLimit, BTDecorator);
@ -16,8 +16,8 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual int _tick(float p_delta) override;
public:
void set_run_limit(int p_value) {

View File

@ -1,11 +1,11 @@
/* bt_subtree.cpp */
#include "bt_subtree.h"
#include "core/engine.h"
#include "core/error_macros.h"
#include "core/object.h"
#include "core/config/engine.h"
#include "core/error/error_macros.h"
#include "core/object/object.h"
#include "core/typedefs.h"
#include "core/variant.h"
#include "core/variant/variant.h"
#include "modules/limboai/blackboard.h"
#include "modules/limboai/bt/actions/bt_action.h"
#include "modules/limboai/bt/actions/bt_fail.h"
@ -17,7 +17,7 @@ String BTSubtree::_generate_name() const {
String s;
if (subtree.is_null()) {
s = "(unassigned)";
} else if (subtree->get_path().empty()) {
} else if (subtree->get_path().is_empty()) {
s = "(unsaved)";
} else {
s = vformat("\"%s\"", subtree->get_path());
@ -46,7 +46,7 @@ int BTSubtree::_tick(float p_delta) {
String BTSubtree::get_configuration_warning() const {
String warning = BTTask::get_configuration_warning(); // BTDecorator skipped intentionally
if (!warning.empty()) {
if (!warning.is_empty()) {
warning += "\n";
}
if (subtree.is_null()) {

View File

@ -4,7 +4,7 @@
#define BT_SUBTREE_H
#include "bt_new_scope.h"
#include "core/object.h"
#include "core/object/object.h"
#include "modules/limboai/bt/behavior_tree.h"
class BTSubtree : public BTNewScope {
@ -16,8 +16,8 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual int _tick(float p_delta) override;
public:
void set_subtree(const Ref<BehaviorTree> &p_value) {
@ -26,8 +26,8 @@ public:
}
Ref<BehaviorTree> get_subtree() const { return subtree; }
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
virtual String get_configuration_warning() const;
virtual void initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) override;
virtual String get_configuration_warning() const override;
};
#endif // BT_SUBTREE_H

View File

@ -24,5 +24,5 @@ int BTTimeLimit::_tick(float p_delta) {
void BTTimeLimit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_time_limit", "p_value"), &BTTimeLimit::set_time_limit);
ClassDB::bind_method(D_METHOD("get_time_limit"), &BTTimeLimit::get_time_limit);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_limit"), "set_time_limit", "get_time_limit");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_limit"), "set_time_limit", "get_time_limit");
}

View File

@ -4,7 +4,7 @@
#define BT_TIME_LIMIT_H
#include "bt_decorator.h"
#include "core/object.h"
#include "core/object/object.h"
class BTTimeLimit : public BTDecorator {
GDCLASS(BTTimeLimit, BTDecorator);
@ -16,9 +16,9 @@ private:
protected:
static void _bind_methods();
virtual String _generate_name() const;
virtual void _enter();
virtual int _tick(float p_delta);
virtual String _generate_name() const override;
virtual void _enter() override;
virtual int _tick(float p_delta) override;
public:
void set_time_limit(float p_value) {

View File

@ -13,6 +13,10 @@ def get_doc_path():
return "doc_classes"
# def get_icons_path():
# return "icons"
def get_doc_classes():
return [
"BBAabb",

View File

@ -4,35 +4,40 @@
#include "limbo_ai_editor_plugin.h"
#include "core/array.h"
#include "core/class_db.h"
#include "core/dictionary.h"
#include "core/error_list.h"
#include "core/error_macros.h"
#include "core/config/project_settings.h"
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/image_loader.h"
#include "core/io/resource.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/list.h"
#include "core/math/math_defs.h"
#include "core/math/vector2.h"
#include "core/object.h"
#include "core/os/dir_access.h"
#include "core/object/callable_method_pointer.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/object/script_language.h"
#include "core/os/memory.h"
#include "core/print_string.h"
#include "core/project_settings.h"
#include "core/resource.h"
#include "core/script_language.h"
#include "core/string_name.h"
#include "core/string/print_string.h"
#include "core/string/string_name.h"
#include "core/string/ustring.h"
#include "core/templates/list.h"
#include "core/templates/vector.h"
#include "core/typedefs.h"
#include "core/ustring.h"
#include "core/variant.h"
#include "core/vector.h"
#include "core/variant/array.h"
#include "core/variant/dictionary.h"
#include "core/variant/variant.h"
#include "editor/editor_file_system.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_paths.h"
#include "editor/editor_plugin.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/inspector_dock.h"
#include "editor/plugins/script_editor_plugin.h"
#include "modules/limboai/bt/actions/bt_action.h"
#include "modules/limboai/bt/behavior_tree.h"
#include "modules/limboai/bt/bt_task.h"
@ -51,7 +56,7 @@
#include "scene/gui/separator.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"
#include <cstddef>
#include "servers/display_server.h"
////////////////////////////// TaskTree //////////////////////////////////////
@ -72,7 +77,7 @@ void TaskTree::_update_item(TreeItem *p_item) {
Ref<BTTask> task = p_item->get_metadata(0);
ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata.");
p_item->set_text(0, task->get_task_name());
if (task->get_script_instance() && !task->get_script_instance()->get_script()->get_path().empty()) {
if (task->get_script_instance() && !task->get_script_instance()->get_script()->get_path().is_empty()) {
p_item->set_icon(0, LimboAIEditor::get_task_icon(task->get_script_instance()->get_script()->get_path()));
} else {
p_item->set_icon(0, LimboAIEditor::get_task_icon(task->get_class()));
@ -83,8 +88,8 @@ void TaskTree::_update_item(TreeItem *p_item) {
p_item->erase_button(0, i);
}
String warning = task->get_configuration_warning();
if (!warning.empty()) {
p_item->add_button(0, get_icon("NodeWarning", "EditorIcons"), 0, false, warning);
if (!warning.is_empty()) {
p_item->add_button(0, get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")), 0, false, warning);
}
// TODO: Update probabilities.
@ -114,11 +119,11 @@ TreeItem *TaskTree::_find_item(const Ref<BTTask> &p_task) const {
TreeItem *item = tree->get_root();
List<TreeItem *> stack;
while (item && item->get_metadata(0) != p_task) {
if (item->get_children()) {
stack.push_back(item->get_children());
if (item->get_child_count() > 0) {
stack.push_back(item->get_first_child());
}
item = item->get_next();
if (item == nullptr && !stack.empty()) {
if (item == nullptr && !stack.is_empty()) {
item = stack.front()->get();
stack.pop_front();
}
@ -126,19 +131,21 @@ TreeItem *TaskTree::_find_item(const Ref<BTTask> &p_task) const {
return item;
}
void TaskTree::_on_item_rmb_selected(const Vector2 &p_pos) {
emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
void TaskTree::_on_item_mouse_selected(const Vector2 &p_pos, int p_button_index) {
if (p_button_index == 2) {
emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
}
}
void TaskTree::_on_item_selected() {
if (last_selected.is_valid()) {
update_task(last_selected);
if (last_selected->is_connected("changed", this, "_on_task_changed")) {
last_selected->disconnect("changed", this, "_on_task_changed");
if (last_selected->is_connected("changed", callable_mp(this, &TaskTree::_on_task_changed))) {
last_selected->disconnect("changed", callable_mp(this, &TaskTree::_on_task_changed));
}
}
last_selected = get_selected();
last_selected->connect("changed", this, "_on_task_changed");
last_selected->connect("changed", callable_mp(this, &TaskTree::_on_task_changed));
emit_signal("task_selected", last_selected);
}
@ -153,8 +160,8 @@ void TaskTree::_on_task_changed() {
void TaskTree::load_bt(const Ref<BehaviorTree> &p_behavior_tree) {
ERR_FAIL_COND_MSG(p_behavior_tree.is_null(), "Tried to load a null tree.");
if (last_selected.is_valid() and last_selected->is_connected("changed", this, "_on_task_changed")) {
last_selected->disconnect("changed", this, "_on_task_changed");
if (last_selected.is_valid() and last_selected->is_connected("changed", callable_mp(this, &TaskTree::_on_task_changed))) {
last_selected->disconnect("changed", callable_mp(this, &TaskTree::_on_task_changed));
}
bt = p_behavior_tree;
@ -186,7 +193,7 @@ void TaskTree::deselect() {
}
}
Variant TaskTree::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
Variant TaskTree::_get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (editable && tree->get_item_at_position(p_point)) {
Dictionary drag_data;
drag_data["type"] = "task";
@ -197,7 +204,7 @@ Variant TaskTree::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
return Variant();
}
bool TaskTree::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
bool TaskTree::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (!editable) {
return false;
}
@ -224,7 +231,7 @@ bool TaskTree::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
return false;
}
void TaskTree::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
void TaskTree::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
Dictionary d = p_data;
TreeItem *item = tree->get_item_at_position(p_point);
if (item && d.has("task")) {
@ -234,7 +241,7 @@ void TaskTree::drop_data_fw(const Point2 &p_point, const Variant &p_data, Contro
}
void TaskTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_item_rmb_selected"), &TaskTree::_on_item_rmb_selected);
ClassDB::bind_method(D_METHOD("_on_item_mouse_selected"), &TaskTree::_on_item_mouse_selected);
ClassDB::bind_method(D_METHOD("_on_item_selected"), &TaskTree::_on_item_selected);
ClassDB::bind_method(D_METHOD("_on_item_double_clicked"), &TaskTree::_on_item_double_clicked);
ClassDB::bind_method(D_METHOD("_on_task_changed"), &TaskTree::_on_task_changed);
@ -245,9 +252,9 @@ void TaskTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_selected"), &TaskTree::get_selected);
ClassDB::bind_method(D_METHOD("deselect"), &TaskTree::deselect);
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &TaskTree::get_drag_data_fw);
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &TaskTree::can_drop_data_fw);
ClassDB::bind_method(D_METHOD("drop_data_fw"), &TaskTree::drop_data_fw);
ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &TaskTree::_get_drag_data_fw);
ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &TaskTree::_can_drop_data_fw);
ClassDB::bind_method(D_METHOD("_drop_data_fw"), &TaskTree::_drop_data_fw);
ADD_SIGNAL(MethodInfo("rmb_pressed"));
ADD_SIGNAL(MethodInfo("task_selected"));
@ -266,19 +273,20 @@ TaskTree::TaskTree() {
tree->set_columns(2);
tree->set_column_expand(0, true);
tree->set_column_expand(1, false);
tree->set_column_min_width(1, 64);
tree->set_anchor(MARGIN_RIGHT, ANCHOR_END);
tree->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
tree->set_column_custom_minimum_width(1, 64);
tree->set_anchor(SIDE_RIGHT, ANCHOR_END);
tree->set_anchor(SIDE_BOTTOM, ANCHOR_END);
tree->set_allow_rmb_select(true);
tree->connect("item_rmb_selected", this, "_on_item_rmb_selected");
tree->connect("item_selected", this, "_on_item_selected");
tree->connect("item_activated", this, "_on_item_double_clicked");
tree->connect("item_mouse_selected", callable_mp(this, &TaskTree::_on_item_mouse_selected));
tree->connect("item_selected", callable_mp(this, &TaskTree::_on_item_selected));
tree->connect("item_activated", callable_mp(this, &TaskTree::_on_item_double_clicked));
tree->set_drag_forwarding(this);
}
TaskTree::~TaskTree() {
if (last_selected.is_valid() and last_selected->is_connected("changed", this, "_on_task_changed")) {
last_selected->disconnect("changed", this, "_on_task_changed");
if (last_selected.is_valid() and last_selected->is_connected("changed", callable_mp(this, &TaskTree::_on_task_changed))) {
last_selected->disconnect("changed", callable_mp(this, &TaskTree::_on_task_changed));
}
}
@ -292,12 +300,12 @@ void TaskSection::_on_task_button_pressed(const StringName &p_task) {
void TaskSection::_on_header_pressed() {
tasks_container->set_visible(!tasks_container->is_visible());
section_header->set_icon(tasks_container->is_visible() ? get_icon("GuiTreeArrowDown", "EditorIcons") : get_icon("GuiTreeArrowRight", "EditorIcons"));
section_header->set_icon(tasks_container->is_visible() ? get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")) : get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")));
}
void TaskSection::set_filter(String p_filter_text) {
int num_hidden = 0;
if (p_filter_text.empty()) {
if (p_filter_text.is_empty()) {
for (int i = 0; i < tasks_container->get_child_count(); i++) {
Object::cast_to<Button>(tasks_container->get_child(i))->show();
}
@ -316,13 +324,13 @@ void TaskSection::add_task_button(String p_name, const Ref<Texture> &icon, Varia
Button *btn = memnew(Button);
btn->set_text(p_name);
btn->set_icon(icon);
btn->connect("pressed", this, "_on_task_button_pressed", varray(p_meta));
btn->connect("pressed", callable_mp(this, &TaskSection::_on_task_button_pressed).bind(p_meta));
tasks_container->add_child(btn);
}
void TaskSection::set_collapsed(bool p_collapsed) {
tasks_container->set_visible(!p_collapsed);
section_header->set_icon(p_collapsed ? get_icon("GuiTreeArrowRight", "EditorIcons") : get_icon("GuiTreeArrowDown", "EditorIcons"));
section_header->set_icon(p_collapsed ? get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")) : get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")));
}
bool TaskSection::is_collapsed() const {
@ -336,13 +344,13 @@ void TaskSection::_bind_methods() {
ADD_SIGNAL(MethodInfo("task_button_pressed"));
}
TaskSection::TaskSection(String p_category_name, EditorNode *p_editor) {
TaskSection::TaskSection(String p_category_name) {
section_header = memnew(Button);
add_child(section_header);
section_header->set_text(p_category_name);
section_header->set_icon(p_editor->get_gui_base()->get_icon("GuiTreeArrowDown", "EditorIcons"));
section_header->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")));
section_header->set_focus_mode(FOCUS_NONE);
section_header->connect("pressed", this, "_on_header_pressed");
section_header->connect("pressed", callable_mp(this, &TaskSection::_on_header_pressed));
tasks_container = memnew(HFlowContainer);
add_child(tasks_container);
@ -367,13 +375,13 @@ void TaskPanel::_on_filter_text_changed(String p_text) {
}
void TaskPanel::refresh() {
filter_edit->set_right_icon(get_icon("Search", "EditorIcons"));
filter_edit->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
Set<String> collapsed_sections;
HashSet<String> collapsed_sections;
if (sections->get_child_count() == 0) {
// Restore collapsed state from config.
ConfigFile conf;
String conf_path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("limbo_ai.cfg");
String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg");
if (conf.load(conf_path) == OK) {
Variant value = conf.get_value("bt_editor", "collapsed_sections", Array());
if (value.is_array()) {
@ -391,7 +399,7 @@ void TaskPanel::refresh() {
if (sec->is_collapsed()) {
collapsed_sections.insert(sec->get_category_name());
}
sections->get_child(i)->queue_delete();
sections->get_child(i)->queue_free();
}
}
@ -421,7 +429,9 @@ void TaskPanel::refresh() {
_populate_from_user_dir(dir3, &categories);
List<String> keys;
categories.get_key_list(&keys);
for (const KeyValue<String, List<String>> &K : categories) {
keys.push_back(K.key);
}
keys.sort();
for (List<String>::Element *E = keys.front(); E; E = E->next()) {
String cat = E->get();
@ -431,7 +441,7 @@ void TaskPanel::refresh() {
continue;
}
TaskSection *sec = memnew(TaskSection(cat, editor));
TaskSection *sec = memnew(TaskSection(cat));
for (List<String>::Element *E = task_list.front(); E; E = E->next()) {
String meta = E->get();
String tname;
@ -441,7 +451,7 @@ void TaskPanel::refresh() {
sec->add_task_button(tname, icon, meta);
}
sec->set_filter("");
sec->connect("task_button_pressed", this, "_on_task_button_pressed");
sec->connect("task_button_pressed", callable_mp(this, &TaskPanel::_on_task_button_pressed));
sections->add_child(sec);
sec->set_collapsed(collapsed_sections.has(cat));
}
@ -457,14 +467,14 @@ void TaskPanel::_populate_core_tasks_from_class(const StringName &p_base_class,
}
void TaskPanel::_populate_from_user_dir(String p_path, HashMap<String, List<String>> *p_categories) {
if (p_path.empty()) {
if (p_path.is_empty()) {
return;
}
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (dir->change_dir(p_path) == OK) {
dir->list_dir_begin();
String fn = dir->get_next();
while (!fn.empty()) {
while (!fn.is_empty()) {
if (dir->current_is_dir() && fn != "..") {
String full_path;
String category;
@ -472,12 +482,12 @@ void TaskPanel::_populate_from_user_dir(String p_path, HashMap<String, List<Stri
full_path = p_path;
category = "User";
} else {
full_path = p_path.plus_file(fn);
full_path = p_path.path_join(fn);
category = fn.capitalize();
}
if (!p_categories->has(category)) {
p_categories->set(category, List<String>());
p_categories->insert(category, List<String>());
}
_populate_scripted_tasks_from_dir(full_path, &p_categories->get(category));
@ -488,20 +498,19 @@ void TaskPanel::_populate_from_user_dir(String p_path, HashMap<String, List<Stri
} else {
ERR_FAIL_MSG(vformat("Failed to list \"%s\" directory.", p_path));
}
memdelete(dir);
}
void TaskPanel::_populate_scripted_tasks_from_dir(String p_path, List<String> *p_task_classes) {
if (p_path.empty()) {
if (p_path.is_empty()) {
return;
}
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (dir->change_dir(p_path) == OK) {
dir->list_dir_begin();
String fn = dir->get_next();
while (!fn.empty()) {
while (!fn.is_empty()) {
if (fn.ends_with(".gd")) {
String full_path = p_path.plus_file(fn);
String full_path = p_path.path_join(fn);
p_task_classes->push_back(full_path);
}
fn = dir->get_next();
@ -510,7 +519,6 @@ void TaskPanel::_populate_scripted_tasks_from_dir(String p_path, List<String> *p
} else {
ERR_FAIL_MSG(vformat("Failed to list \"%s\" directory.", p_path));
}
memdelete(dir);
}
void TaskPanel::_notification(int p_what) {
@ -526,7 +534,7 @@ void TaskPanel::_notification(int p_what) {
}
}
ConfigFile conf;
String conf_path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("limbo_ai.cfg");
String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg");
conf.load(conf_path);
conf.set_value("bt_editor", "collapsed_sections", collapsed_sections);
conf.save(conf_path);
@ -541,16 +549,14 @@ void TaskPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("task_selected"));
}
TaskPanel::TaskPanel(EditorNode *p_editor) {
editor = p_editor;
TaskPanel::TaskPanel() {
VBoxContainer *vb = memnew(VBoxContainer);
add_child(vb);
filter_edit = memnew(LineEdit);
vb->add_child(filter_edit);
filter_edit->set_clear_button_enabled(true);
filter_edit->connect("text_changed", this, "_on_filter_text_changed");
filter_edit->connect("text_changed", callable_mp(this, &TaskPanel::_on_filter_text_changed));
ScrollContainer *sc = memnew(ScrollContainer);
vb->add_child(sc);
@ -588,14 +594,14 @@ void LimboAIEditor::_add_task(const Ref<BTTask> &p_task) {
void LimboAIEditor::_update_header() const {
String text = task_tree->get_bt()->get_path();
if (text.empty()) {
if (text.is_empty()) {
text = TTR("New Behavior Tree");
} else if (dirty.has(task_tree->get_bt())) {
text += "(*)";
}
header->set_text(text);
header->set_icon(editor->get_object_icon(task_tree->get_bt().ptr(), "BehaviorTree"));
header->set_icon(EditorNode::get_singleton()->get_object_icon(task_tree->get_bt().ptr(), "BehaviorTree"));
}
void LimboAIEditor::_update_history_buttons() {
@ -606,20 +612,20 @@ void LimboAIEditor::_update_history_buttons() {
void LimboAIEditor::_new_bt() {
BehaviorTree *bt = memnew(BehaviorTree);
bt->set_root_task(memnew(BTSelector));
editor->edit_resource(bt);
EditorNode::get_singleton()->edit_resource(bt);
}
void LimboAIEditor::_save_bt(String p_path) {
ERR_FAIL_COND_MSG(p_path.empty(), "Empty p_path");
ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path");
ERR_FAIL_COND_MSG(task_tree->get_bt().is_null(), "Behavior Tree is null.");
task_tree->get_bt()->set_path(p_path, true);
ResourceSaver::save(p_path, task_tree->get_bt(), ResourceSaver::FLAG_CHANGE_PATH);
ResourceSaver::save(task_tree->get_bt(), p_path, ResourceSaver::FLAG_CHANGE_PATH);
_update_header();
_mark_as_dirty(false);
}
void LimboAIEditor::_load_bt(String p_path) {
ERR_FAIL_COND_MSG(p_path.empty(), "Empty p_path");
ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path");
Ref<BehaviorTree> bt = ResourceLoader::load(p_path, "BehaviorTree");
if (history.find(bt) != -1) {
@ -627,7 +633,7 @@ void LimboAIEditor::_load_bt(String p_path) {
history.push_back(bt);
}
editor->edit_resource(bt);
EditorNode::get_singleton()->edit_resource(bt);
}
void LimboAIEditor::edit_bt(Ref<BehaviorTree> p_behavior_tree, bool p_force_refresh) {
@ -671,12 +677,12 @@ void LimboAIEditor::_on_tree_rmb(const Vector2 &p_menu_pos) {
menu->set_position(p_menu_pos);
menu->clear();
menu->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Remove"), ACTION_REMOVE);
menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Remove"), ACTION_REMOVE);
menu->add_separator();
menu->add_icon_item(get_icon("MoveUp", "EditorIcons"), TTR("Move Up"), ACTION_MOVE_UP);
menu->add_icon_item(get_icon("MoveDown", "EditorIcons"), TTR("Move Down"), ACTION_MOVE_DOWN);
menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Duplicate"), ACTION_DUPLICATE);
menu->add_icon_item(get_icon("NewRoot", "EditorIcons"), TTR("Make Root"), ACTION_MAKE_ROOT);
menu->add_icon_item(get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons")), TTR("Move Up"), ACTION_MOVE_UP);
menu->add_icon_item(get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons")), TTR("Move Down"), ACTION_MOVE_DOWN);
menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Duplicate"), ACTION_DUPLICATE);
menu->add_icon_item(get_theme_icon(SNAME("NewRoot"), SNAME("EditorIcons")), TTR("Make Root"), ACTION_MAKE_ROOT);
menu->popup();
}
@ -692,7 +698,7 @@ void LimboAIEditor::_on_action_selected(int p_id) {
sel->get_parent()->remove_child(sel);
}
task_tree->update_tree();
editor->edit_node(nullptr);
EditorNode::get_singleton()->edit_node(nullptr);
_mark_as_dirty(true);
}
} break;
@ -750,8 +756,8 @@ void LimboAIEditor::_on_action_selected(int p_id) {
}
}
void LimboAIEditor::_on_tree_task_selected(const Ref<BTTask> &p_task) const {
editor->edit_resource(p_task);
void LimboAIEditor::_on_tree_task_selected(const Ref<BTTask> &p_task) {
EditorNode::get_singleton()->edit_resource(p_task);
}
void LimboAIEditor::_on_tree_task_double_clicked() {
@ -769,11 +775,11 @@ void LimboAIEditor::_on_panel_task_selected(String p_task) {
if (p_task.begins_with("res:")) {
Ref<Script> script = ResourceLoader::load(p_task, "Script");
ERR_FAIL_COND_MSG(script.is_null() || !script->is_valid(), vformat("LimboAI: Failed to instance task. Bad script: %s", p_task));
Variant inst = ClassDB::instance(script->get_instance_base_type());
Variant inst = ClassDB::instantiate(script->get_instance_base_type());
ERR_FAIL_COND_MSG(inst.is_zero(), vformat("LimboAI: Failed to instance base type \"%s\".", script->get_instance_base_type()));
if (unlikely(!((Object *)inst)->is_class("BTTask"))) {
if (!inst.is_ref()) {
if (!inst.is_ref_counted()) {
memdelete((Object *)inst);
}
ERR_PRINT(vformat("LimboAI: Failed to instance task. Script is not a BTTask: %s", p_task));
@ -781,31 +787,31 @@ void LimboAIEditor::_on_panel_task_selected(String p_task) {
}
if (inst && script.is_valid()) {
((Object *)inst)->set_script(script.get_ref_ptr());
((Object *)inst)->set_script(script);
_add_task(Variant(inst));
}
} else {
_add_task(Ref<BTTask>(ClassDB::instance(p_task)));
_add_task(Ref<BTTask>(ClassDB::instantiate(p_task)));
}
}
void LimboAIEditor::_on_visibility_changed() const {
if (is_visible()) {
void LimboAIEditor::_on_visibility_changed() {
if (task_tree->is_visible()) {
Ref<BTTask> sel = task_tree->get_selected();
if (sel.is_valid()) {
editor->edit_resource(sel);
} else if (task_tree->get_bt().is_valid() && editor->get_inspector()->get_edited_object() != task_tree->get_bt().ptr()) {
editor->edit_resource(task_tree->get_bt());
EditorNode::get_singleton()->edit_resource(sel);
} else if (task_tree->get_bt().is_valid() && InspectorDock::get_inspector_singleton()->get_edited_object() != task_tree->get_bt().ptr()) {
EditorNode::get_singleton()->edit_resource(task_tree->get_bt());
}
task_panel->refresh();
}
}
void LimboAIEditor::_on_header_pressed() const {
void LimboAIEditor::_on_header_pressed() {
_update_header();
task_tree->deselect();
editor->edit_resource(task_tree->get_bt());
EditorNode::get_singleton()->edit_resource(task_tree->get_bt());
}
void LimboAIEditor::_on_save_pressed() {
@ -813,7 +819,7 @@ void LimboAIEditor::_on_save_pressed() {
return;
}
String path = task_tree->get_bt()->get_path();
if (path.empty()) {
if (path.is_empty()) {
save_dialog->popup_centered_ratio();
} else {
_save_bt(path);
@ -822,12 +828,12 @@ void LimboAIEditor::_on_save_pressed() {
void LimboAIEditor::_on_history_back() {
idx_history = MAX(idx_history - 1, 0);
editor->edit_resource(history[idx_history]);
EditorNode::get_singleton()->edit_resource(history[idx_history]);
}
void LimboAIEditor::_on_history_forward() {
idx_history = MIN(idx_history + 1, history.size() - 1);
editor->edit_resource(history[idx_history]);
EditorNode::get_singleton()->edit_resource(history[idx_history]);
}
void LimboAIEditor::_on_task_dragged(Ref<BTTask> p_task, Ref<BTTask> p_to_task, int p_type) {
@ -872,10 +878,9 @@ void LimboAIEditor::_on_resources_reload(const Vector<String> &p_resources) {
disk_changed_list->clear();
disk_changed_list->set_hide_root(true);
disk_changed_list->create_item();
for (Set<String>::Element *E = disk_changed_files.front(); E; E = E->next()) {
// for (int i = 0; i < disk_changed_files.size(); i++) {
for (const String &fn : disk_changed_files) {
TreeItem *ti = disk_changed_list->create_item();
ti->set_text(0, E->get());
ti->set_text(0, fn);
}
if (!is_visible()) {
@ -886,9 +891,9 @@ void LimboAIEditor::_on_resources_reload(const Vector<String> &p_resources) {
}
void LimboAIEditor::_reload_modified() {
for (Set<String>::Element *E = disk_changed_files.front(); E; E = E->next()) {
for (const String &fn : disk_changed_files) {
for (int j = 0; j < history.size(); j++) {
if (history.get(j)->get_path() == E->get()) {
if (history.get(j)->get_path() == fn) {
dirty.erase(history.get(j));
history.get(j)->get_root_task()->clear_internal_resource_paths();
history.get(j)->reload_from_file();
@ -902,10 +907,10 @@ void LimboAIEditor::_reload_modified() {
}
void LimboAIEditor::_resave_modified(String _str) {
for (Set<String>::Element *E = disk_changed_files.front(); E; E = E->next()) {
for (const String &fn : disk_changed_files) {
for (int j = 0; j < history.size(); j++) {
if (history.get(j)->get_path() == E->get()) {
ResourceSaver::save(history.get(j)->get_path(), history.get(j));
if (history.get(j)->get_path() == fn) {
ResourceSaver::save(history.get(j), history.get(j)->get_path());
}
}
}
@ -917,7 +922,7 @@ void LimboAIEditor::_rename_task(String _str) {
ERR_FAIL_COND(!task_tree->get_selected().is_valid());
task_tree->get_selected()->set_custom_name(rename_edit->get_text());
rename_dialog->hide();
editor->edit_resource(task_tree->get_selected());
EditorNode::get_singleton()->edit_resource(task_tree->get_selected());
}
void LimboAIEditor::apply_changes() {
@ -925,7 +930,7 @@ void LimboAIEditor::apply_changes() {
Ref<BehaviorTree> bt = history.get(i);
String path = bt->get_path();
if (ResourceLoader::exists(path)) {
ResourceSaver::save(path, bt);
ResourceSaver::save(bt, path);
}
dirty.clear();
_update_header();
@ -941,7 +946,7 @@ Ref<Texture> LimboAIEditor::get_task_icon(String p_script_path_or_class) {
while (base_script.is_valid()) {
StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path());
String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
if (!icon_path.empty()) {
if (!icon_path.is_empty()) {
Ref<Image> img = memnew(Image);
Error err = ImageLoader::load_image(icon_path, img);
if (err == OK) {
@ -964,14 +969,14 @@ void LimboAIEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
ConfigFile conf;
String conf_path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("limbo_ai.cfg");
String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg");
if (conf.load(conf_path) == OK) {
hsc->set_split_offset(conf.get_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()));
}
} break;
case NOTIFICATION_EXIT_TREE: {
ConfigFile conf;
String conf_path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("limbo_ai.cfg");
String conf_path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("limbo_ai.cfg");
conf.load(conf_path);
conf.set_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset());
conf.save(conf_path);
@ -1003,28 +1008,28 @@ void LimboAIEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_rename_task"), &LimboAIEditor::_rename_task, String());
}
LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
editor = p_editor;
LimboAIEditor::LimboAIEditor() {
idx_history = 0;
save_dialog = memnew(FileDialog);
add_child(save_dialog);
save_dialog->set_mode(FileDialog::MODE_SAVE_FILE);
save_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
save_dialog->set_title("Save Behavior Tree");
save_dialog->add_filter("*.tres");
save_dialog->connect("file_selected", this, "_save_bt");
save_dialog->connect("file_selected", callable_mp(this, &LimboAIEditor::_save_bt));
save_dialog->hide();
load_dialog = memnew(FileDialog);
add_child(load_dialog);
load_dialog->set_mode(FileDialog::MODE_OPEN_FILE);
load_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
load_dialog->set_title("Load Behavior Tree");
load_dialog->add_filter("*.tres");
load_dialog->connect("file_selected", this, "_load_bt");
load_dialog->connect("file_selected", callable_mp(this, &LimboAIEditor::_load_bt));
load_dialog->hide();
VBoxContainer *vb = memnew(VBoxContainer);
vb->set_anchor(MARGIN_RIGHT, ANCHOR_END);
vb->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
vb->set_anchor(SIDE_RIGHT, ANCHOR_END);
vb->set_anchor(SIDE_BOTTOM, ANCHOR_END);
add_child(vb);
HBoxContainer *panel = memnew(HBoxContainer);
@ -1032,29 +1037,29 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
Button *selector_btn = memnew(Button);
selector_btn->set_text(TTR("Selector"));
selector_btn->set_tooltip(TTR("Add Selector task."));
selector_btn->set_icon(editor->get_class_icon("BTSelector"));
selector_btn->set_tooltip_text(TTR("Add Selector task."));
selector_btn->set_icon(EditorNode::get_singleton()->get_class_icon("BTSelector"));
selector_btn->set_flat(true);
selector_btn->set_focus_mode(Control::FOCUS_NONE);
selector_btn->connect("pressed", this, "_add_task_with_prototype", varray(Ref<BTTask>(memnew(BTSelector))));
selector_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_add_task_with_prototype).bind(Ref<BTTask>(memnew(BTSelector))));
panel->add_child(selector_btn);
Button *sequence_btn = memnew(Button);
sequence_btn->set_text(TTR("Sequence"));
sequence_btn->set_tooltip(TTR("Add Sequence task."));
sequence_btn->set_icon(editor->get_class_icon("BTSequence"));
sequence_btn->set_tooltip_text(TTR("Add Sequence task."));
sequence_btn->set_icon(EditorNode::get_singleton()->get_class_icon("BTSequence"));
sequence_btn->set_flat(true);
sequence_btn->set_focus_mode(Control::FOCUS_NONE);
sequence_btn->connect("pressed", this, "_add_task_with_prototype", varray(Ref<BTTask>(memnew(BTSequence))));
sequence_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_add_task_with_prototype).bind(Ref<BTTask>(memnew(BTSequence))));
panel->add_child(sequence_btn);
Button *parallel_btn = memnew(Button);
parallel_btn->set_text(TTR("Parallel"));
parallel_btn->set_tooltip(TTR("Add Parallel task."));
parallel_btn->set_icon(editor->get_class_icon("BTParallel"));
parallel_btn->set_tooltip_text(TTR("Add Parallel task."));
parallel_btn->set_icon(EditorNode::get_singleton()->get_class_icon("BTParallel"));
parallel_btn->set_flat(true);
parallel_btn->set_focus_mode(Control::FOCUS_NONE);
parallel_btn->connect("pressed", this, "_add_task_with_prototype", varray(Ref<BTTask>(memnew(BTParallel))));
parallel_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_add_task_with_prototype).bind(Ref<BTTask>(memnew(BTParallel))));
panel->add_child(parallel_btn);
panel->add_child(memnew(VSeparator));
@ -1062,37 +1067,37 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
Button *new_btn = memnew(Button);
panel->add_child(new_btn);
new_btn->set_text(TTR("New"));
new_btn->set_tooltip(TTR("Create new behavior tree."));
new_btn->set_icon(editor->get_gui_base()->get_icon("New", "EditorIcons"));
new_btn->set_tooltip_text(TTR("Create new behavior tree."));
new_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("New"), SNAME("EditorIcons")));
new_btn->set_flat(true);
new_btn->set_focus_mode(Control::FOCUS_NONE);
new_btn->connect("pressed", this, "_new_bt");
new_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_new_bt));
Button *load_btn = memnew(Button);
panel->add_child(load_btn);
load_btn->set_text(TTR("Load"));
load_btn->set_tooltip(TTR("Load behavior tree."));
load_btn->set_icon(editor->get_gui_base()->get_icon("Load", "EditorIcons"));
load_btn->set_tooltip_text(TTR("Load behavior tree."));
load_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Load"), SNAME("EditorIcons")));
load_btn->set_flat(true);
load_btn->set_focus_mode(Control::FOCUS_NONE);
load_btn->connect("pressed", load_dialog, "popup_centered_ratio");
load_btn->connect("pressed", callable_mp(load_dialog, &FileDialog::popup_file_dialog));
Button *save_btn = memnew(Button);
panel->add_child(save_btn);
save_btn->set_text(TTR("Save"));
save_btn->set_tooltip(TTR("Save current behavior tree."));
save_btn->set_icon(editor->get_gui_base()->get_icon("Save", "EditorIcons"));
save_btn->set_tooltip_text(TTR("Save current behavior tree."));
save_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Save"), SNAME("EditorIcons")));
save_btn->set_flat(true);
save_btn->set_focus_mode(Control::FOCUS_NONE);
save_btn->connect("pressed", this, "_on_save_pressed");
save_btn->connect("pressed", callable_mp(this, &LimboAIEditor::_on_save_pressed));
panel->add_child(memnew(VSeparator));
Button *new_script_btn = memnew(Button);
panel->add_child(new_script_btn);
new_script_btn->set_text(TTR("New Task"));
new_script_btn->set_tooltip(TTR("Create new task script and edit it."));
new_script_btn->set_icon(editor->get_gui_base()->get_icon("ScriptCreate", "EditorIcons"));
new_script_btn->set_tooltip_text(TTR("Create new task script and edit it."));
new_script_btn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
new_script_btn->set_flat(true);
new_script_btn->set_focus_mode(Control::FOCUS_NONE);
@ -1101,24 +1106,24 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
nav->set_h_size_flags(SIZE_EXPAND | SIZE_SHRINK_END);
history_back = memnew(Button);
history_back->set_icon(editor->get_gui_base()->get_icon("Back", "EditorIcons"));
history_back->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Back"), SNAME("EditorIcons")));
history_back->set_flat(true);
history_back->set_focus_mode(FOCUS_NONE);
history_back->connect("pressed", this, "_on_history_back");
history_back->connect("pressed", callable_mp(this, &LimboAIEditor::_on_history_back));
nav->add_child(history_back);
history_forward = memnew(Button);
history_forward->set_icon(editor->get_gui_base()->get_icon("Forward", "EditorIcons"));
history_forward->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Forward"), SNAME("EditorIcons")));
history_forward->set_flat(true);
history_forward->set_focus_mode(FOCUS_NONE);
history_forward->connect("pressed", this, "_on_history_forward");
history_forward->connect("pressed", callable_mp(this, &LimboAIEditor::_on_history_forward));
nav->add_child(history_forward);
header = memnew(Button);
vb->add_child(header);
header->set_text_align(Button::ALIGN_LEFT);
header->add_constant_override("hseparation", 8);
header->connect("pressed", this, "_on_header_pressed");
header->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
header->add_theme_constant_override("hseparation", 8);
header->connect("pressed", callable_mp(this, &LimboAIEditor::_on_header_pressed));
hsc = memnew(HSplitContainer);
vb->add_child(hsc);
@ -1129,11 +1134,11 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
hsc->add_child(task_tree);
task_tree->set_v_size_flags(SIZE_EXPAND_FILL);
task_tree->set_h_size_flags(SIZE_EXPAND_FILL);
task_tree->connect("rmb_pressed", this, "_on_tree_rmb");
task_tree->connect("task_selected", this, "_on_tree_task_selected");
task_tree->connect("visibility_changed", this, "_on_visibility_changed");
task_tree->connect("task_dragged", this, "_on_task_dragged");
task_tree->connect("task_double_clicked", this, "_on_tree_task_double_clicked");
task_tree->connect("rmb_pressed", callable_mp(this, &LimboAIEditor::_on_tree_rmb));
task_tree->connect("task_selected", callable_mp(this, &LimboAIEditor::_on_tree_task_selected));
task_tree->connect("visibility_changed", callable_mp(this, &LimboAIEditor::_on_visibility_changed));
task_tree->connect("task_dragged", callable_mp(this, &LimboAIEditor::_on_task_dragged));
task_tree->connect("task_double_clicked", callable_mp(this, &LimboAIEditor::_on_tree_task_double_clicked));
task_tree->hide();
usage_hint = memnew(Panel);
@ -1141,23 +1146,23 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
usage_hint->set_h_size_flags(SIZE_EXPAND_FILL);
hsc->add_child(usage_hint);
Label *usage_label = memnew(Label);
usage_label->set_anchor(MARGIN_RIGHT, 1);
usage_label->set_anchor(MARGIN_BOTTOM, 1);
usage_label->set_align(Label::ALIGN_CENTER);
usage_label->set_valign(Label::VALIGN_CENTER);
usage_label->set_anchor(SIDE_RIGHT, 1);
usage_label->set_anchor(SIDE_BOTTOM, 1);
usage_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
usage_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
usage_label->set_text(TTR("Create a new or load an existing behavior tree."));
usage_hint->add_child(usage_label);
task_panel = memnew(TaskPanel(p_editor));
task_panel = memnew(TaskPanel());
hsc->add_child(task_panel);
hsc->set_split_offset(-300);
task_panel->connect("task_selected", this, "_on_panel_task_selected");
task_panel->connect("task_selected", callable_mp(this, &LimboAIEditor::_on_panel_task_selected));
task_panel->hide();
menu = memnew(PopupMenu);
add_child(menu);
menu->connect("id_pressed", this, "_on_action_selected");
menu->set_hide_on_window_lose_focus(true);
menu->connect("id_pressed", callable_mp(this, &LimboAIEditor::_on_action_selected));
// menu->set_hide_on_window_lose_focus(true);
rename_dialog = memnew(ConfirmationDialog);
{
@ -1171,10 +1176,10 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
rename_edit->set_placeholder("Custom Name");
rename_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
rename_edit->set_custom_minimum_size(Size2(350.0, 0.0));
rename_edit->connect("text_entered", this, "_rename_task");
rename_edit->connect("text_changed", callable_mp(this, &LimboAIEditor::_rename_task));
rename_dialog->get_ok()->set_text(TTR("Rename"));
rename_dialog->connect("confirmed", this, "_rename_task");
rename_dialog->get_ok_button()->set_text(TTR("Rename"));
rename_dialog->connect("confirmed", callable_mp(this, &LimboAIEditor::_rename_task));
}
add_child(rename_dialog);
@ -1191,13 +1196,13 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
vbc->add_child(disk_changed_list);
disk_changed_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
disk_changed->get_ok()->set_text(TTR("Reload"));
disk_changed->connect("confirmed", this, "_reload_modified");
disk_changed->get_ok_button()->set_text(TTR("Reload"));
disk_changed->connect("confirmed", callable_mp(this, &LimboAIEditor::_reload_modified));
disk_changed->add_button(TTR("Resave"), !OS::get_singleton()->get_swap_ok_cancel(), "resave");
disk_changed->connect("custom_action", this, "_resave_modified");
disk_changed->add_button(TTR("Resave"), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "resave");
disk_changed->connect("custom_action", callable_mp(this, &LimboAIEditor::_resave_modified));
}
editor->get_gui_base()->add_child(disk_changed);
EditorNode::get_singleton()->get_gui_base()->add_child(disk_changed);
GLOBAL_DEF("limbo_ai/behavior_tree/behavior_tree_default_dir", "res://ai/trees");
ProjectSettings::get_singleton()->set_custom_property_info("limbo_ai/behavior_tree/behavior_tree_default_dir",
@ -1214,10 +1219,9 @@ LimboAIEditor::LimboAIEditor(EditorNode *p_editor) {
save_dialog->set_current_dir(GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir"));
load_dialog->set_current_dir(GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir"));
new_script_btn->connect("pressed", ScriptEditor::get_singleton(), "open_script_create_dialog",
varray("BTAction", String(GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1")).plus_file("new_task")));
new_script_btn->connect("pressed", callable_mp(ScriptEditor::get_singleton(), &ScriptEditor::open_script_create_dialog).bind("BTAction", String(GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1")).path_join("new_task")));
EditorFileSystem::get_singleton()->connect("resources_reload", this, "_on_resources_reload");
EditorFileSystem::get_singleton()->connect("resources_reload", callable_mp(this, &LimboAIEditor::_on_resources_reload));
}
LimboAIEditor::~LimboAIEditor() {
@ -1227,8 +1231,8 @@ LimboAIEditor::~LimboAIEditor() {
///////////////////////// LimboAIEditorPlugin ////////////////////////////////
const Ref<Texture> LimboAIEditorPlugin::get_icon() const {
return editor->get_gui_base()->get_icon("LimboAIEditor", "EditorIcons");
const Ref<Texture2D> LimboAIEditorPlugin::get_icon() const {
return EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("LimboAIEditor"), SNAME("EditorIcons"));
}
void LimboAIEditorPlugin::apply_changes() {
@ -1253,11 +1257,10 @@ bool LimboAIEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("BehaviorTree");
}
LimboAIEditorPlugin::LimboAIEditorPlugin(EditorNode *p_editor) {
editor = p_editor;
limbo_ai_editor = memnew(LimboAIEditor(p_editor));
LimboAIEditorPlugin::LimboAIEditorPlugin() {
limbo_ai_editor = memnew(LimboAIEditor());
limbo_ai_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
editor->get_viewport()->add_child(limbo_ai_editor);
EditorNode::get_singleton()->get_main_screen_control()->add_child(limbo_ai_editor);
limbo_ai_editor->hide();
}

View File

@ -4,15 +4,19 @@
#ifndef LIMBO_AI_EDITOR_PLUGIN_H
#define LIMBO_AI_EDITOR_PLUGIN_H
#include "core/object.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/templates/hash_set.h"
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "modules/limboai/bt/behavior_tree.h"
#include "modules/limboai/bt/bt_task.h"
#include "scene/gui/box_container.h"
#include "scene/gui/control.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/flow_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"
@ -34,12 +38,12 @@ private:
void _on_item_selected();
void _on_item_double_clicked();
void _on_item_rmb_selected(const Vector2 &p_pos);
void _on_item_mouse_selected(const Vector2 &p_pos, int p_button_index);
void _on_task_changed();
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
Variant _get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
protected:
static void _bind_methods();
@ -80,7 +84,7 @@ public:
String get_category_name() const { return section_header->get_text(); }
TaskSection(String p_category_name, EditorNode *p_editor);
TaskSection(String p_category_name);
~TaskSection();
};
@ -88,7 +92,6 @@ class TaskPanel : public PanelContainer {
GDCLASS(TaskPanel, PanelContainer)
private:
EditorNode *editor;
LineEdit *filter_edit;
VBoxContainer *sections;
@ -106,7 +109,7 @@ protected:
public:
void refresh();
TaskPanel(EditorNode *p_editor);
TaskPanel();
~TaskPanel();
};
@ -122,10 +125,9 @@ private:
ACTION_MAKE_ROOT,
};
EditorNode *editor;
Vector<Ref<BehaviorTree>> history;
int idx_history;
Set<Ref<BehaviorTree>> dirty;
HashSet<Ref<BehaviorTree>> dirty;
Button *header;
HSplitContainer *hsc;
@ -143,7 +145,7 @@ private:
ConfirmationDialog *disk_changed;
Tree *disk_changed_list;
Set<String> disk_changed_files;
HashSet<String> disk_changed_files;
void _add_task(const Ref<BTTask> &p_task);
_FORCE_INLINE_ void _add_task_with_prototype(const Ref<BTTask> &p_prototype) { _add_task(p_prototype->clone()); }
@ -161,10 +163,10 @@ private:
void _on_tree_rmb(const Vector2 &p_menu_pos);
void _on_action_selected(int p_id);
void _on_tree_task_selected(const Ref<BTTask> &p_task) const;
void _on_tree_task_selected(const Ref<BTTask> &p_task);
void _on_tree_task_double_clicked();
void _on_visibility_changed() const;
void _on_header_pressed() const;
void _on_visibility_changed();
void _on_header_pressed();
void _on_save_pressed();
void _on_panel_task_selected(String p_task);
void _on_history_back();
@ -184,7 +186,7 @@ public:
void apply_changes();
LimboAIEditor(EditorNode *p_editor);
LimboAIEditor();
~LimboAIEditor();
};
@ -192,22 +194,21 @@ class LimboAIEditorPlugin : public EditorPlugin {
GDCLASS(LimboAIEditorPlugin, EditorPlugin);
private:
EditorNode *editor;
LimboAIEditor *limbo_ai_editor;
protected:
void _notification(int p_notification);
public:
virtual String get_name() const { return "LimboAI"; }
virtual const Ref<Texture> get_icon() const;
bool has_main_screen() const { return true; }
virtual void make_visible(bool p_visible);
virtual void apply_changes();
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
virtual String get_name() const override { return "LimboAI"; }
virtual const Ref<Texture2D> get_icon() const override;
bool has_main_screen() const override { return true; }
virtual void make_visible(bool p_visible) override;
virtual void apply_changes() override;
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
LimboAIEditorPlugin(EditorNode *p_editor);
LimboAIEditorPlugin();
~LimboAIEditorPlugin();
};

View File

Before

Width:  |  Height:  |  Size: 281 B

After

Width:  |  Height:  |  Size: 281 B

View File

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 600 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 268 B

After

Width:  |  Height:  |  Size: 268 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 661 B

After

Width:  |  Height:  |  Size: 661 B

View File

Before

Width:  |  Height:  |  Size: 296 B

After

Width:  |  Height:  |  Size: 296 B

View File

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

Some files were not shown because too many files have changed in this diff Show More