1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**************************************************************************/
/*  item_list_editor_plugin.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.                 */
/**************************************************************************/

#ifndef ITEM_LIST_EDITOR_PLUGIN_H
#define ITEM_LIST_EDITOR_PLUGIN_H

#include "canvas_item_editor_plugin.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
#include "scene/gui/popup_menu.h"

class ItemListPlugin : public Object {
	GDCLASS(ItemListPlugin, Object);

protected:
	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;

public:
	enum Flags {

		FLAG_ICON = 1,
		FLAG_CHECKABLE = 2,
		FLAG_ID = 4,
		FLAG_ENABLE = 8,
		FLAG_SEPARATOR = 16
	};

	virtual void set_object(Object *p_object) = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual bool handles(Object *p_object) const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	virtual int get_flags() const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	virtual void set_item_text(int p_idx, const String &p_text) {}<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual String get_item_text(int p_idx) const { return ""; };<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) {}<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); };<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	virtual void set_item_checkable(int p_idx, bool p_check) {}<--- Virtual function in base class
	virtual void set_item_radio_checkable(int p_idx, bool p_check) {}<--- Virtual function in base class
	virtual bool is_item_checkable(int p_idx) const { return false; };<--- Virtual function in base class
	virtual bool is_item_radio_checkable(int p_idx) const { return false; };<--- Virtual function in base class

	virtual void set_item_checked(int p_idx, bool p_checked) {}<--- Virtual function in base class
	virtual bool is_item_checked(int p_idx) const { return false; };<--- Virtual function in base class

	virtual void set_item_enabled(int p_idx, int p_enabled) {}<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual bool is_item_enabled(int p_idx) const { return false; };<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	virtual void set_item_id(int p_idx, int p_id) {}<--- Virtual function in base class<--- Virtual function in base class
	virtual int get_item_id(int p_idx) const { return -1; };<--- Virtual function in base class<--- Virtual function in base class

	virtual void set_item_separator(int p_idx, bool p_separator) {}<--- Virtual function in base class
	virtual bool is_item_separator(int p_idx) const { return false; };<--- Virtual function in base class

	virtual void add_item() = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual int get_item_count() const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
	virtual void erase(int p_idx) = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

	ItemListPlugin() {}
};

///////////////////////////////////////////////////////////////

class ItemListOptionButtonPlugin : public ItemListPlugin {
	GDCLASS(ItemListOptionButtonPlugin, ItemListPlugin);

	OptionButton *ob;

public:
	virtual void set_object(Object *p_object);<--- Function in derived class
	virtual bool handles(Object *p_object) const;<--- Function in derived class
	virtual int get_flags() const;<--- Function in derived class

	virtual void set_item_text(int p_idx, const String &p_text) { ob->set_item_text(p_idx, p_text); }<--- Function in derived class
	virtual String get_item_text(int p_idx) const { return ob->get_item_text(p_idx); }<--- Function in derived class

	virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { ob->set_item_icon(p_idx, p_tex); }<--- Function in derived class
	virtual Ref<Texture> get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); }<--- Function in derived class

	virtual void set_item_enabled(int p_idx, int p_enabled) { ob->set_item_disabled(p_idx, !p_enabled); }<--- Function in derived class
	virtual bool is_item_enabled(int p_idx) const { return !ob->is_item_disabled(p_idx); }<--- Function in derived class

	virtual void set_item_id(int p_idx, int p_id) { ob->set_item_id(p_idx, p_id); }<--- Function in derived class
	virtual int get_item_id(int p_idx) const { return ob->get_item_id(p_idx); }<--- Function in derived class

	virtual void add_item();<--- Function in derived class
	virtual int get_item_count() const;<--- Function in derived class
	virtual void erase(int p_idx);<--- Function in derived class

	ItemListOptionButtonPlugin();
};

class ItemListPopupMenuPlugin : public ItemListPlugin {
	GDCLASS(ItemListPopupMenuPlugin, ItemListPlugin);

	PopupMenu *pp;

public:
	virtual void set_object(Object *p_object);<--- Function in derived class
	virtual bool handles(Object *p_object) const;<--- Function in derived class
	virtual int get_flags() const;<--- Function in derived class

	virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); }<--- Function in derived class
	virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); }<--- Function in derived class

	virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); }<--- Function in derived class
	virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }<--- Function in derived class

	virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); }<--- Function in derived class
	virtual void set_item_radio_checkable(int p_idx, bool p_check) { pp->set_item_as_radio_checkable(p_idx, p_check); }<--- Function in derived class
	virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); }<--- Function in derived class
	virtual bool is_item_radio_checkable(int p_idx) const { return pp->is_item_radio_checkable(p_idx); }<--- Function in derived class

	virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx, p_checked); }<--- Function in derived class
	virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); }<--- Function in derived class

	virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); }<--- Function in derived class
	virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); }<--- Function in derived class

	virtual void set_item_id(int p_idx, int p_id) { pp->set_item_id(p_idx, p_id); }<--- Function in derived class
	virtual int get_item_id(int p_idx) const { return pp->get_item_id(p_idx); }<--- Function in derived class

	virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx, p_separator); }<--- Function in derived class
	virtual bool is_item_separator(int p_idx) const { return pp->is_item_separator(p_idx); }<--- Function in derived class

	virtual void add_item();<--- Function in derived class
	virtual int get_item_count() const;<--- Function in derived class
	virtual void erase(int p_idx);<--- Function in derived class

	ItemListPopupMenuPlugin();
};

///////////////////////////////////////////////////////////////

class ItemListItemListPlugin : public ItemListPlugin {
	GDCLASS(ItemListItemListPlugin, ItemListPlugin);

	ItemList *pp;

public:
	virtual void set_object(Object *p_object);<--- Function in derived class
	virtual bool handles(Object *p_object) const;<--- Function in derived class
	virtual int get_flags() const;<--- Function in derived class

	virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); }<--- Function in derived class
	virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); }<--- Function in derived class

	virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); }<--- Function in derived class
	virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }<--- Function in derived class

	virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); }<--- Function in derived class
	virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); }<--- Function in derived class

	virtual void add_item();<--- Function in derived class
	virtual int get_item_count() const;<--- Function in derived class
	virtual void erase(int p_idx);<--- Function in derived class

	ItemListItemListPlugin();
};

///////////////////////////////////////////////////////////////

class ItemListEditor : public HBoxContainer {
	GDCLASS(ItemListEditor, HBoxContainer);

	Node *item_list;

	ToolButton *toolbar_button;

	AcceptDialog *dialog;
	EditorInspector *property_editor;
	Tree *tree;
	Button *add_button;
	Button *del_button;

	int selected_idx;

	Vector<ItemListPlugin *> item_plugins;

	void _edit_items();

	void _add_pressed();
	void _delete_pressed();

	void _node_removed(Node *p_node);

protected:
	void _notification(int p_notification);
	static void _bind_methods();

public:
	void edit(Node *p_item_list);
	bool handles(Object *p_object) const;
	void add_plugin(ItemListPlugin *p_plugin) { item_plugins.push_back(p_plugin); }
	ItemListEditor();
	~ItemListEditor();
};

class ItemListEditorPlugin : public EditorPlugin {
	GDCLASS(ItemListEditorPlugin, EditorPlugin);

	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_object);
	virtual bool handles(Object *p_object) const;
	virtual void make_visible(bool p_visible);

	ItemListEditorPlugin(EditorNode *p_node);
	~ItemListEditorPlugin();
};

#endif // ITEM_LIST_EDITOR_PLUGIN_H