2023-08-22 10:20:09 +00:00
|
|
|
/**
|
|
|
|
* action_banner.cpp
|
|
|
|
* =============================================================================
|
2024-03-21 20:38:57 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2023-08-22 10:20:09 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2024-01-11 10:22:02 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2023-08-22 10:20:09 +00:00
|
|
|
#include "action_banner.h"
|
|
|
|
|
2024-01-10 21:45:42 +00:00
|
|
|
#include "../util/limbo_compat.h"
|
|
|
|
#include "../util/limbo_string_names.h"
|
|
|
|
|
2024-01-07 12:36:59 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2024-01-17 14:51:24 +00:00
|
|
|
#include "editor/editor_scale.h"
|
2023-08-22 10:20:09 +00:00
|
|
|
#include "scene/gui/button.h"
|
2024-01-07 12:36:59 +00:00
|
|
|
#endif // LIMBOAI_MODULE
|
|
|
|
|
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
#include <godot_cpp/classes/button.hpp>
|
2024-01-17 14:51:24 +00:00
|
|
|
#include <godot_cpp/classes/editor_interface.hpp>
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
2023-08-22 10:20:09 +00:00
|
|
|
|
|
|
|
void ActionBanner::set_text(const String &p_text) {
|
|
|
|
message->set_text(p_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
String ActionBanner::get_text() const {
|
|
|
|
return message->get_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionBanner::close() {
|
|
|
|
queue_free();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2024-01-09 12:42:54 +00:00
|
|
|
action_btn->connect(LW_NAME(pressed), callable_mp(this, &ActionBanner::_execute_action).bind(p_action, p_auto_close));
|
2023-08-22 10:20:09 +00:00
|
|
|
hbox->add_child(action_btn);
|
|
|
|
}
|
|
|
|
|
2024-01-17 14:51:24 +00:00
|
|
|
void ActionBanner::add_spacer() {
|
|
|
|
Control *spacer = memnew(Control);
|
|
|
|
spacer->set_custom_minimum_size(Vector2(8.0 * EDSCALE, 0.0));
|
|
|
|
hbox->add_child(spacer);
|
|
|
|
}
|
|
|
|
|
2023-08-22 10:20:09 +00:00
|
|
|
void ActionBanner::_execute_action(const Callable &p_action, bool p_auto_close) {
|
2024-01-07 12:36:59 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2023-08-22 10:20:09 +00:00
|
|
|
Callable::CallError ce;
|
|
|
|
Variant ret;
|
|
|
|
p_action.callp(nullptr, 0, ret, ce);
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-01-07 12:36:59 +00:00
|
|
|
p_action.call();
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif
|
2023-08-22 10:20:09 +00:00
|
|
|
|
|
|
|
if (p_auto_close) {
|
|
|
|
queue_free();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionBanner::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2024-01-09 12:42:54 +00:00
|
|
|
icon->set_texture(get_theme_icon(LW_NAME(StatusWarning), LW_NAME(EditorIcons)));
|
2023-08-22 10:20:09 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionBanner::_bind_methods() {
|
2024-03-04 20:36:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_execute_action", "action", "auto_close"), &ActionBanner::_execute_action);
|
2023-08-22 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionBanner::ActionBanner() {
|
|
|
|
add_theme_constant_override("margin_bottom", 4);
|
|
|
|
add_theme_constant_override("margin_top", 4);
|
|
|
|
add_theme_constant_override("margin_left", 10);
|
|
|
|
add_theme_constant_override("margin_right", 10);
|
|
|
|
|
|
|
|
hbox = memnew(HBoxContainer);
|
|
|
|
hbox->add_theme_constant_override("hseparation", 8);
|
|
|
|
add_child(hbox);
|
|
|
|
|
|
|
|
icon = memnew(TextureRect);
|
|
|
|
icon->set_expand_mode(TextureRect::ExpandMode::EXPAND_KEEP_SIZE);
|
|
|
|
icon->set_stretch_mode(TextureRect::StretchMode::STRETCH_KEEP_CENTERED);
|
|
|
|
hbox->add_child(icon);
|
|
|
|
|
|
|
|
message = memnew(Label);
|
|
|
|
message->set_text(vformat(TTR("User task folder doesn't exist")));
|
|
|
|
message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
|
|
|
hbox->add_child(message);
|
|
|
|
|
|
|
|
Control *spacer = memnew(Control);
|
|
|
|
spacer->set_custom_minimum_size(Size2(0, 16));
|
|
|
|
hbox->add_child(spacer);
|
|
|
|
}
|
2024-01-11 10:22:02 +00:00
|
|
|
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // TOOLS_ENABLED
|