Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/object/property_info.h
45997 views
1
/**************************************************************************/
2
/* property_info.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/extension/gdextension_interface.gen.h"
34
#include "core/variant/variant.h"
35
36
template <typename T>
37
class TypedArray;
38
39
enum PropertyHint {
40
PROPERTY_HINT_NONE, ///< no hint provided.
41
PROPERTY_HINT_RANGE, ///< hint_text = "min,max[,step][,or_greater][,or_less][,prefer_slider][,hide_control][,radians_as_degrees][,degrees][,exp][,suffix:<keyword>] range.
42
PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"
43
PROPERTY_HINT_ENUM_SUGGESTION, ///< hint_text= "val1,val2,val3,etc"
44
PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "positive_only" to exclude in-out and out-in. (ie: "attenuation,positive_only")
45
PROPERTY_HINT_LINK,
46
PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
47
PROPERTY_HINT_LAYERS_2D_RENDER,
48
PROPERTY_HINT_LAYERS_2D_PHYSICS,
49
PROPERTY_HINT_LAYERS_2D_NAVIGATION,
50
PROPERTY_HINT_LAYERS_3D_RENDER,
51
PROPERTY_HINT_LAYERS_3D_PHYSICS,
52
PROPERTY_HINT_LAYERS_3D_NAVIGATION,
53
PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
54
PROPERTY_HINT_DIR, ///< a directory path must be passed
55
PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
56
PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
57
PROPERTY_HINT_RESOURCE_TYPE, ///< a comma-separated resource object type, e.g. "NoiseTexture,GradientTexture2D". Subclasses can be excluded with a "-" prefix if placed *after* the base class, e.g. "Texture2D,-MeshTexture".
58
PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
59
PROPERTY_HINT_EXPRESSION, ///< used for string properties that can contain multiple lines
60
PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
61
PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
62
PROPERTY_HINT_OBJECT_ID,
63
PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
64
PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, // Deprecated.
65
PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send
66
PROPERTY_HINT_NODE_PATH_VALID_TYPES,
67
PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
68
PROPERTY_HINT_GLOBAL_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
69
PROPERTY_HINT_INT_IS_OBJECTID, // Deprecated.
70
PROPERTY_HINT_INT_IS_POINTER,
71
PROPERTY_HINT_ARRAY_TYPE,
72
PROPERTY_HINT_LOCALE_ID,
73
PROPERTY_HINT_LOCALIZABLE_STRING,
74
PROPERTY_HINT_NODE_TYPE, ///< a node object type
75
PROPERTY_HINT_HIDE_QUATERNION_EDIT, /// Only Node3D::transform should hide the quaternion editor.
76
PROPERTY_HINT_PASSWORD,
77
PROPERTY_HINT_LAYERS_AVOIDANCE,
78
PROPERTY_HINT_DICTIONARY_TYPE,
79
PROPERTY_HINT_TOOL_BUTTON,
80
PROPERTY_HINT_ONESHOT, ///< the property will be changed by self after setting, such as AudioStreamPlayer.playing, Particles.emitting.
81
PROPERTY_HINT_NO_NODEPATH, /// < this property will not contain a NodePath, regardless of type (Array, Dictionary, List, etc.). Needed for SceneTreeDock.
82
PROPERTY_HINT_GROUP_ENABLE, ///< used to make the property's group checkable. Only use for boolean types.
83
PROPERTY_HINT_INPUT_NAME,
84
PROPERTY_HINT_FILE_PATH,
85
PROPERTY_HINT_MAX,
86
};
87
88
enum PropertyUsageFlags {
89
PROPERTY_USAGE_NONE = 0,
90
PROPERTY_USAGE_STORAGE = 1 << 1,
91
PROPERTY_USAGE_EDITOR = 1 << 2,
92
PROPERTY_USAGE_INTERNAL = 1 << 3,
93
PROPERTY_USAGE_CHECKABLE = 1 << 4, // Used for editing global variables.
94
PROPERTY_USAGE_CHECKED = 1 << 5, // Used for editing global variables.
95
PROPERTY_USAGE_GROUP = 1 << 6, // Used for grouping props in the editor.
96
PROPERTY_USAGE_CATEGORY = 1 << 7,
97
PROPERTY_USAGE_SUBGROUP = 1 << 8,
98
PROPERTY_USAGE_CLASS_IS_BITFIELD = 1 << 9,
99
PROPERTY_USAGE_NO_INSTANCE_STATE = 1 << 10,
100
PROPERTY_USAGE_RESTART_IF_CHANGED = 1 << 11,
101
PROPERTY_USAGE_SCRIPT_VARIABLE = 1 << 12,
102
PROPERTY_USAGE_STORE_IF_NULL = 1 << 13,
103
PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 1 << 14,
104
PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 15, // Deprecated.
105
PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 16,
106
PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 17,
107
PROPERTY_USAGE_ARRAY = 1 << 18, // Used in the inspector to group properties as elements of an array.
108
PROPERTY_USAGE_ALWAYS_DUPLICATE = 1 << 19, // When duplicating a resource, always duplicate, even with subresource duplication disabled.
109
PROPERTY_USAGE_NEVER_DUPLICATE = 1 << 20, // When duplicating a resource, never duplicate, even with subresource duplication enabled.
110
PROPERTY_USAGE_HIGH_END_GFX = 1 << 21,
111
PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT = 1 << 22,
112
PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT = 1 << 23,
113
PROPERTY_USAGE_KEYING_INCREMENTS = 1 << 24, // Used in inspector to increment property when keyed in animation player.
114
PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 25, // Deprecated.
115
PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 26, // For Object properties, instantiate them when creating in editor.
116
PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 27, //for project or editor settings, show when basic settings are selected.
117
PROPERTY_USAGE_READ_ONLY = 1 << 28, // Mark a property as read-only in the inspector.
118
PROPERTY_USAGE_SECRET = 1 << 29, // Export preset credentials that should be stored separately from the rest of the export config.
119
120
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR,
121
PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE,
122
};
123
124
struct PropertyInfo {
125
Variant::Type type = Variant::NIL;
126
String name;
127
StringName class_name; // For classes
128
PropertyHint hint = PROPERTY_HINT_NONE;
129
String hint_string;
130
uint32_t usage = PROPERTY_USAGE_DEFAULT;
131
132
// If you are thinking about adding another member to this class, ask the maintainer (Juan) first.
133
134
_FORCE_INLINE_ PropertyInfo added_usage(uint32_t p_fl) const {
135
PropertyInfo pi = *this;
136
pi.usage |= p_fl;
137
return pi;
138
}
139
140
operator Dictionary() const;
141
142
static PropertyInfo from_dict(const Dictionary &p_dict);
143
144
PropertyInfo() {}
145
146
PropertyInfo(const Variant::Type p_type, const String &p_name, const PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", const uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) :
147
type(p_type),
148
name(p_name),
149
hint(p_hint),
150
hint_string(p_hint_string),
151
usage(p_usage) {
152
if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
153
class_name = hint_string;
154
} else {
155
class_name = p_class_name;
156
}
157
}
158
159
PropertyInfo(const StringName &p_class_name) :
160
type(Variant::OBJECT),
161
class_name(p_class_name) {}
162
163
explicit PropertyInfo(const GDExtensionPropertyInfo &pinfo) :
164
type((Variant::Type)pinfo.type),
165
name(*reinterpret_cast<StringName *>(pinfo.name)),
166
class_name(*reinterpret_cast<StringName *>(pinfo.class_name)),
167
hint((PropertyHint)pinfo.hint),
168
hint_string(*reinterpret_cast<String *>(pinfo.hint_string)),
169
usage(pinfo.usage) {}
170
171
bool operator==(const PropertyInfo &p_info) const {
172
return ((type == p_info.type) &&
173
(name == p_info.name) &&
174
(class_name == p_info.class_name) &&
175
(hint == p_info.hint) &&
176
(hint_string == p_info.hint_string) &&
177
(usage == p_info.usage));
178
}
179
180
bool operator<(const PropertyInfo &p_info) const {
181
return name < p_info.name;
182
}
183
};
184
185
TypedArray<Dictionary> convert_property_list(const List<PropertyInfo> *p_list);
186
TypedArray<Dictionary> convert_property_list(const Vector<PropertyInfo> &p_vector);
187
188