2023-01-05 20:25:55 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* action_map_editor.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2020-10-01 21:04:57 +08:00
|
|
|
|
|
|
|
#ifndef ACTION_MAP_EDITOR_H
|
|
|
|
#define ACTION_MAP_EDITOR_H
|
|
|
|
|
2022-10-05 20:42:12 +08: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 21:04:57 +08:00
|
|
|
|
|
|
|
class ActionMapEditor : public Control {
|
|
|
|
GDCLASS(ActionMapEditor, Control);
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct ActionInfo {
|
2022-11-15 01:21:06 +08:00
|
|
|
String name;
|
|
|
|
Dictionary action;
|
2023-01-13 19:36:44 +08:00
|
|
|
bool has_initial = false;
|
|
|
|
Dictionary action_initial;
|
2020-10-01 21:04:57 +08:00
|
|
|
|
2024-03-23 17:49:40 +08:00
|
|
|
Ref<Texture2D> icon;
|
2020-10-01 21:04:57 +08:00
|
|
|
bool editable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum ItemButton {
|
|
|
|
BUTTON_ADD_EVENT,
|
|
|
|
BUTTON_EDIT_EVENT,
|
|
|
|
BUTTON_REMOVE_ACTION,
|
|
|
|
BUTTON_REMOVE_EVENT,
|
2023-01-13 19:36:44 +08:00
|
|
|
BUTTON_REVERT_ACTION,
|
2020-10-01 21:04:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<ActionInfo> actions_cache;
|
2022-04-04 21:06:57 +08:00
|
|
|
Tree *action_tree = nullptr;
|
2020-10-01 21:04:57 +08:00
|
|
|
|
|
|
|
// Storing which action/event is currently being edited in the InputEventConfigurationDialog.
|
|
|
|
|
2022-11-15 01:21:06 +08:00
|
|
|
Dictionary current_action;
|
|
|
|
String current_action_name;
|
2020-10-01 21:04:57 +08:00
|
|
|
int current_action_event_index = -1;
|
|
|
|
|
|
|
|
// Popups
|
|
|
|
|
2022-04-04 21:06:57 +08:00
|
|
|
InputEventConfigurationDialog *event_config_dialog = nullptr;
|
|
|
|
AcceptDialog *message = nullptr;
|
2020-10-01 21:04:57 +08:00
|
|
|
|
|
|
|
// Filtering and Adding actions
|
|
|
|
|
2022-02-15 22:56:58 +08:00
|
|
|
bool show_builtin_actions = false;
|
2022-04-04 21:06:57 +08:00
|
|
|
CheckButton *show_builtin_actions_checkbutton = nullptr;
|
|
|
|
LineEdit *action_list_search = nullptr;
|
2022-10-02 22:50:05 +08:00
|
|
|
EventListenerLineEdit *action_list_search_by_event = nullptr;
|
2024-03-23 17:49:40 +08:00
|
|
|
Button *clear_all_search = nullptr;
|
2020-10-01 21:04:57 +08:00
|
|
|
|
2022-04-04 21:06:57 +08:00
|
|
|
HBoxContainer *add_hbox = nullptr;
|
|
|
|
LineEdit *add_edit = nullptr;
|
2022-05-04 07:47:29 +08:00
|
|
|
Button *add_button = nullptr;
|
2020-10-01 21:04:57 +08:00
|
|
|
|
|
|
|
void _event_config_confirmed();
|
|
|
|
|
|
|
|
void _add_action_pressed();
|
2022-05-04 07:47:29 +08:00
|
|
|
void _add_edit_text_changed(const String &p_name);
|
|
|
|
String _check_new_action_name(const String &p_name);
|
2021-12-29 01:08:06 +08:00
|
|
|
bool _has_action(const String &p_name) const;
|
2020-10-01 21:04:57 +08:00
|
|
|
void _add_action(const String &p_name);
|
|
|
|
void _action_edited();
|
|
|
|
|
2021-09-18 15:33:18 +08:00
|
|
|
void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
|
2020-10-01 21:04:57 +08:00
|
|
|
void _tree_item_activated();
|
|
|
|
void _search_term_updated(const String &p_search_term);
|
2022-10-02 22:50:05 +08: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 21:04:57 +08: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 19:48:59 +08:00
|
|
|
void _on_filter_focused();
|
|
|
|
void _on_filter_unfocused();
|
|
|
|
|
2020-10-01 21:04:57 +08:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
LineEdit *get_search_box() const;
|
2023-08-31 02:11:21 +08:00
|
|
|
LineEdit *get_path_box() const;
|
2020-10-01 21:04:57 +08:00
|
|
|
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-06 03:49:35 +08:00
|
|
|
void set_show_builtin_actions(bool p_show);
|
2020-10-01 21:04:57 +08:00
|
|
|
|
|
|
|
void use_external_search_box(LineEdit *p_searchbox);
|
|
|
|
|
|
|
|
ActionMapEditor();
|
|
|
|
};
|
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#endif // ACTION_MAP_EDITOR_H
|