2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* item_list_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:11:45 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2018-01-02 11:27:24 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01: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 ITEM_LIST_EDITOR_PLUGIN_H
|
|
|
|
#define ITEM_LIST_EDITOR_PLUGIN_H
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
#include "canvas_item_editor_plugin.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_plugin.h"
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/menu_button.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "scene/gui/option_button.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/popup_menu.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ItemListPlugin : public Object {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(ItemListPlugin, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
2017-03-19 00:36:26 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Flags {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
FLAG_ICON = 1,
|
|
|
|
FLAG_CHECKABLE = 2,
|
|
|
|
FLAG_ID = 4,
|
|
|
|
FLAG_ENABLE = 8,
|
|
|
|
FLAG_SEPARATOR = 16
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_object(Object *p_object) = 0;
|
|
|
|
virtual bool handles(Object *p_object) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual int get_flags() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_text(int p_idx, const String &p_text) {}
|
|
|
|
virtual String get_item_text(int p_idx) const { return ""; };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) {}
|
|
|
|
virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
virtual void set_item_checkable(int p_idx, bool p_check) {}
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual bool is_item_checkable(int p_idx) const { return false; };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
virtual void set_item_checked(int p_idx, bool p_checked) {}
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual bool is_item_checked(int p_idx) const { return false; };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
virtual void set_item_enabled(int p_idx, int p_enabled) {}
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual bool is_item_enabled(int p_idx) const { return false; };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
virtual void set_item_id(int p_idx, int p_id) {}
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual int get_item_id(int p_idx) const { return -1; };
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
virtual void set_item_separator(int p_idx, bool p_separator) {}
|
|
|
|
virtual bool is_item_separator(int p_idx) const { return false; };
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void add_item() = 0;
|
|
|
|
virtual int get_item_count() const = 0;
|
|
|
|
virtual void erase(int p_idx) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ItemListPlugin() {}
|
|
|
|
};
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
class ItemListOptionButtonPlugin : public ItemListPlugin {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(ItemListOptionButtonPlugin, ItemListPlugin);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
OptionButton *ob;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
public:
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual void set_object(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
virtual int get_flags() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_text(int p_idx, const String &p_text) { ob->set_item_text(p_idx, p_text); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual String get_item_text(int p_idx) const { return ob->get_item_text(p_idx); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { ob->set_item_icon(p_idx, p_tex); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual Ref<Texture> get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual void set_item_enabled(int p_idx, int p_enabled) { ob->set_item_disabled(p_idx, !p_enabled); }
|
|
|
|
virtual bool is_item_enabled(int p_idx) const { return !ob->is_item_disabled(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_id(int p_idx, int p_id) { ob->set_item_ID(p_idx, p_id); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual int get_item_id(int p_idx) const { return ob->get_item_ID(p_idx); }
|
|
|
|
|
|
|
|
virtual void add_item();
|
|
|
|
virtual int get_item_count() const;
|
|
|
|
virtual void erase(int p_idx);
|
|
|
|
|
|
|
|
ItemListOptionButtonPlugin();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ItemListPopupMenuPlugin : public ItemListPlugin {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(ItemListPopupMenuPlugin, ItemListPlugin);
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
PopupMenu *pp;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
public:
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual void set_object(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
virtual int get_flags() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx, p_checked); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_id(int p_idx, int p_id) { pp->set_item_ID(p_idx, p_idx); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual int get_item_id(int p_idx) const { return pp->get_item_ID(p_idx); }
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx, p_separator); }
|
2015-12-03 18:59:59 +01:00
|
|
|
virtual bool is_item_separator(int p_idx) const { return pp->is_item_separator(p_idx); }
|
|
|
|
|
|
|
|
virtual void add_item();
|
|
|
|
virtual int get_item_count() const;
|
|
|
|
virtual void erase(int p_idx);
|
|
|
|
|
|
|
|
ItemListPopupMenuPlugin();
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class ItemListEditor : public HBoxContainer {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(ItemListEditor, HBoxContainer);
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
Node *item_list;
|
|
|
|
|
|
|
|
ToolButton *toolbar_button;
|
|
|
|
|
|
|
|
AcceptDialog *dialog;
|
|
|
|
PropertyEditor *property_editor;
|
|
|
|
Tree *tree;
|
2014-02-10 02:10:30 +01:00
|
|
|
Button *add_button;
|
|
|
|
Button *del_button;
|
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
int selected_idx;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Vector<ItemListPlugin *> item_plugins;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-03 18:59:59 +01:00
|
|
|
void _edit_items();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _add_pressed();
|
|
|
|
void _delete_pressed();
|
2015-12-03 18:59:59 +01:00
|
|
|
|
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
void _notification(int p_notification);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
void edit(Node *p_item_list);
|
|
|
|
bool handles(Object *p_object) const;
|
2017-03-19 00:36:26 +01:00
|
|
|
void add_plugin(ItemListPlugin *p_plugin) { item_plugins.push_back(p_plugin); }
|
2014-02-10 02:10:30 +01:00
|
|
|
ItemListEditor();
|
|
|
|
~ItemListEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ItemListEditorPlugin : public EditorPlugin {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(ItemListEditorPlugin, EditorPlugin);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ItemListEditor *item_list_editor;
|
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual String get_name() const { return "ItemList"; }
|
|
|
|
bool has_main_screen() const { return false; }
|
|
|
|
virtual void edit(Object *p_node);
|
|
|
|
virtual bool handles(Object *p_node) const;
|
|
|
|
virtual void make_visible(bool p_visible);
|
|
|
|
|
|
|
|
ItemListEditorPlugin(EditorNode *p_node);
|
|
|
|
~ItemListEditorPlugin();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ITEM_LIST_EDITOR_PLUGIN_H
|