You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Add custom icons to script classes.
This commit is contained in:
@@ -1811,7 +1811,7 @@ bool GDScriptLanguage::handles_global_class_type(const String &p_type) const {
|
||||
return p_type == "GDScript";
|
||||
}
|
||||
|
||||
String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type) const {
|
||||
String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
|
||||
|
||||
PoolVector<uint8_t> sourcef;
|
||||
Error err;
|
||||
@@ -1876,6 +1876,12 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r_icon_path) {
|
||||
if (c->icon_path.is_abs_path())
|
||||
*r_icon_path = c->icon_path;
|
||||
else if (c->icon_path.is_rel_path())
|
||||
*r_icon_path = p_path.get_base_dir().plus_file(c->icon_path).simplify_path();
|
||||
}
|
||||
return c->name;
|
||||
}
|
||||
|
||||
|
||||
@@ -492,7 +492,7 @@ public:
|
||||
/* GLOBAL CLASSES */
|
||||
|
||||
virtual bool handles_global_class_type(const String &p_type) const;
|
||||
virtual String get_global_class_name(const String &p_path, String *r_base_type = NULL) const;
|
||||
virtual String get_global_class_name(const String &p_path, String *r_base_type = NULL, String *r_icon_path = NULL) const;
|
||||
|
||||
GDScriptLanguage();
|
||||
~GDScriptLanguage();
|
||||
|
||||
@@ -3429,6 +3429,32 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
||||
|
||||
tokenizer->advance(2);
|
||||
|
||||
if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
|
||||
tokenizer->advance();
|
||||
|
||||
if ((tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING)) {
|
||||
Variant constant = tokenizer->get_token_constant();
|
||||
String icon_path = constant.operator String();
|
||||
|
||||
String abs_icon_path = icon_path.is_rel_path() ? self_path.get_base_dir().plus_file(icon_path).simplify_path() : icon_path;
|
||||
if (!FileAccess::exists(abs_icon_path)) {
|
||||
_set_error("No class icon found at: " + abs_icon_path);
|
||||
return;
|
||||
}
|
||||
|
||||
p_class->icon_path = icon_path;
|
||||
|
||||
tokenizer->advance();
|
||||
} else {
|
||||
_set_error("Optional parameter after 'class_name' must be a string constant file path to an icon.");
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) {
|
||||
_set_error("Class icon must be separated by a comma.");
|
||||
return;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GDScriptTokenizer::TK_PR_TOOL: {
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ public:
|
||||
StringName extends_file;
|
||||
Vector<StringName> extends_class;
|
||||
DataType base_type;
|
||||
String icon_path;
|
||||
|
||||
struct Member {
|
||||
PropertyInfo _export;
|
||||
|
||||
Reference in New Issue
Block a user