Port ActionBanner

This commit is contained in:
Serhii Snitsaruk 2024-01-07 13:36:59 +01:00
parent 3d86a76db9
commit f9ad9cc794
9 changed files with 62 additions and 6 deletions

View File

@ -11,7 +11,17 @@
#include "action_banner.h"
#ifdef LIMBOAI_MODULE
#include "scene/gui/button.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include "../util/limbo_def.h"
#include "../util/limbo_string_names.h"
#include <godot_cpp/classes/button.hpp>
#endif // LIMBOAI_GDEXTENSION
void ActionBanner::set_text(const String &p_text) {
message->set_text(p_text);
@ -28,14 +38,20 @@ void ActionBanner::close() {
void ActionBanner::add_action(const String &p_name, const Callable &p_action, bool p_auto_close) {
Button *action_btn = memnew(Button);
action_btn->set_text(p_name);
action_btn->connect(SNAME("pressed"), callable_mp(this, &ActionBanner::_execute_action).bind(p_action, p_auto_close));
action_btn->connect(LSNAME(pressed), callable_mp(this, &ActionBanner::_execute_action).bind(p_action, p_auto_close));
hbox->add_child(action_btn);
}
void ActionBanner::_execute_action(const Callable &p_action, bool p_auto_close) {
#ifdef LIMBOAI_MODULE
Callable::CallError ce;
Variant ret;
p_action.callp(nullptr, 0, ret, ce);
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
p_action.call();
#endif // LIMBOAI_GDEXTENSION
if (p_auto_close) {
queue_free();
@ -45,7 +61,7 @@ void ActionBanner::_execute_action(const Callable &p_action, bool p_auto_close)
void ActionBanner::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
icon->set_texture(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
icon->set_texture(get_theme_icon(LSNAME(StatusWarning), LSNAME(EditorIcons)));
} break;
}
}

View File

@ -13,11 +13,21 @@
#ifndef ACTION_BANNER_H
#define ACTION_BANNER_H
#include "scene/gui/margin_container.h"
#ifdef LIMBOAI_MODULE
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/texture_rect.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/margin_container.hpp>
#include <godot_cpp/classes/texture_rect.hpp>
using namespace godot;
#endif // LIMBOAI_GDEXTENSION
class ActionBanner : public MarginContainer {
GDCLASS(ActionBanner, MarginContainer);

View File

@ -9,6 +9,8 @@
* =============================================================================
*/
#ifdef LIMBOAI_MODULE
#include "editor_property_bb_param.h"
#include "core/variant/variant.h"
@ -345,3 +347,5 @@ bool EditorInspectorPluginBBParam::parse_property(Object *p_object, const Varian
}
return false;
}
#endif // LIMBOAI_MODULE

View File

@ -12,6 +12,8 @@
#ifndef EDITOR_PROPERTY_BB_PARAM_H
#define EDITOR_PROPERTY_BB_PARAM_H
#ifdef LIMBOAI_MODULE
#include "editor/editor_inspector.h"
#include "modules/limboai/blackboard/bb_param/bb_param.h"
@ -68,4 +70,6 @@ public:
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
};
#endif // LIMBOAI_MODULE
#endif // EDITOR_PROPERTY_BB_PARAM_H

View File

@ -15,6 +15,7 @@
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/editor_settings.hpp>
#include <godot_cpp/classes/translation_server.hpp>
using namespace godot;
@ -24,4 +25,12 @@ Variant _EDITOR_GET(const String &p_setting) {
return es->get(p_setting);
}
#endif
String TTR(const String &p_text, const String &p_context) {
if (TranslationServer::get_singleton()) {
return TranslationServer::get_singleton()->translate(p_text, p_context);
}
return p_text;
}
#endif // LIMBOAI_GDEXTENSION

View File

@ -9,6 +9,9 @@
* =============================================================================
*/
#ifndef LIMBO_DEF_H
#define LIMBO_DEF_H
#ifdef LIMBOAI_MODULE
#include "core/string/print_string.h"
@ -46,4 +49,8 @@ Variant _EDITOR_GET(const String &p_setting);
#define EDSCALE ((int)EDITOR_GET("interface/editor/display_scale"))
#endif // LIMBOAI_GDEXTENSION
String TTR(const String &p_text, const String &p_context = "");
#endif // LIMBOAI_GDEXTENSION
#endif // LIMBO_DEF_H

View File

@ -51,6 +51,8 @@ LimboStringNames::LimboStringNames() {
bold = SN("bold");
EditorFonts = SN("EditorFonts");
item_collapsed = SN("item_collapsed");
pressed = SN("pressed");
StatusWarning = SN("StatusWarning");
EVENT_FINISHED = "finished";
repeat_forever.parse_utf8("Repeat ∞");

View File

@ -70,6 +70,8 @@ public:
StringName bold;
StringName EditorFonts;
StringName item_collapsed;
StringName pressed;
StringName StatusWarning;
String EVENT_FINISHED;
String repeat_forever;

View File

@ -105,6 +105,8 @@ Ref<Texture2D> LimboUtility::get_task_icon(String p_class_or_script_path) const
return theme->get_icon(SNAME("Resource"), SNAME("EditorIcons"));
#endif // TOOLS_ENABLED
// TODO: GDExtension needs the icons too.
// * Class icons are not available at runtime as they are part of the editor theme.
return nullptr;
}