2020-10-01 15:04:57 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* action_map_editor.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-10-01 15:04:57 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef ACTION_MAP_EDITOR_H
|
|
|
|
#define ACTION_MAP_EDITOR_H
|
|
|
|
|
2022-10-05 14:42:12 +02:00
|
|
|
#include "scene/gui/control.h"
|
|
|
|
|
|
|
|
class Button;
|
|
|
|
class HBoxContainer;
|
|
|
|
class EventListenerLineEdit;
|
|
|
|
class LineEdit;
|
|
|
|
class CheckButton;
|
|
|
|
class AcceptDialog;
|
|
|
|
class InputEventConfigurationDialog;
|
|
|
|
class Tree;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
class ActionMapEditor : public Control {
|
|
|
|
GDCLASS(ActionMapEditor, Control);
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct ActionInfo {
|
2022-11-14 18:21:06 +01:00
|
|
|
String name;
|
|
|
|
Dictionary action;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
Ref<Texture2D> icon = Ref<Texture2D>();
|
|
|
|
bool editable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum ItemButton {
|
|
|
|
BUTTON_ADD_EVENT,
|
|
|
|
BUTTON_EDIT_EVENT,
|
|
|
|
BUTTON_REMOVE_ACTION,
|
|
|
|
BUTTON_REMOVE_EVENT,
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<ActionInfo> actions_cache;
|
2022-04-04 15:06:57 +02:00
|
|
|
Tree *action_tree = nullptr;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
// Storing which action/event is currently being edited in the InputEventConfigurationDialog.
|
|
|
|
|
2022-11-14 18:21:06 +01:00
|
|
|
Dictionary current_action;
|
|
|
|
String current_action_name;
|
2020-10-01 15:04:57 +02:00
|
|
|
int current_action_event_index = -1;
|
|
|
|
|
|
|
|
// Popups
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
InputEventConfigurationDialog *event_config_dialog = nullptr;
|
|
|
|
AcceptDialog *message = nullptr;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
// Filtering and Adding actions
|
|
|
|
|
2022-02-15 15:56:58 +01:00
|
|
|
bool show_builtin_actions = false;
|
2022-04-04 15:06:57 +02:00
|
|
|
CheckButton *show_builtin_actions_checkbutton = nullptr;
|
|
|
|
LineEdit *action_list_search = nullptr;
|
2022-10-02 16:50:05 +02:00
|
|
|
EventListenerLineEdit *action_list_search_by_event = nullptr;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
HBoxContainer *add_hbox = nullptr;
|
|
|
|
LineEdit *add_edit = nullptr;
|
2022-05-04 01:47:29 +02:00
|
|
|
Button *add_button = nullptr;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
void _event_config_confirmed();
|
|
|
|
|
|
|
|
void _add_action_pressed();
|
2022-05-04 01:47:29 +02:00
|
|
|
void _add_edit_text_changed(const String &p_name);
|
|
|
|
String _check_new_action_name(const String &p_name);
|
2021-12-28 18:08:06 +01:00
|
|
|
bool _has_action(const String &p_name) const;
|
2020-10-01 15:04:57 +02:00
|
|
|
void _add_action(const String &p_name);
|
|
|
|
void _action_edited();
|
|
|
|
|
2021-09-18 09:33:18 +02:00
|
|
|
void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
|
2020-10-01 15:04:57 +02:00
|
|
|
void _tree_item_activated();
|
|
|
|
void _search_term_updated(const String &p_search_term);
|
2022-10-02 16:50:05 +02:00
|
|
|
void _search_by_event(const Ref<InputEvent> &p_event);
|
|
|
|
bool _should_display_action(const String &p_name, const Array &p_events) const;
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-12-21 12:48:59 +01:00
|
|
|
void _on_filter_focused();
|
|
|
|
void _on_filter_unfocused();
|
|
|
|
|
2020-10-01 15:04:57 +02:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
LineEdit *get_search_box() const;
|
|
|
|
InputEventConfigurationDialog *get_configuration_dialog();
|
|
|
|
|
|
|
|
// Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map.
|
|
|
|
void update_action_list(const Vector<ActionInfo> &p_action_infos = Vector<ActionInfo>());
|
|
|
|
void show_message(const String &p_message);
|
|
|
|
|
2021-05-05 21:49:35 +02:00
|
|
|
void set_show_builtin_actions(bool p_show);
|
2020-10-01 15:04:57 +02:00
|
|
|
|
|
|
|
void use_external_search_box(LineEdit *p_searchbox);
|
|
|
|
|
|
|
|
ActionMapEditor();
|
|
|
|
};
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // ACTION_MAP_EDITOR_H
|