summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/bind/core_bind.cpp6
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/io/json.cpp53
-rw-r--r--core/io/json.h4
-rw-r--r--doc/classes/ColorPickerButton.xml7
-rw-r--r--editor/plugins/editor_preview_plugins.cpp39
-rw-r--r--scene/2d/canvas_item.cpp5
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/3d/particles.cpp6
-rw-r--r--scene/3d/particles.h2
-rw-r--r--scene/gui/color_picker.cpp5
-rw-r--r--scene/gui/color_picker.h1
-rw-r--r--scene/resources/material.cpp12
-rw-r--r--scene/resources/material.h6
14 files changed, 114 insertions, 36 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 999befaf67..f6011c3976 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -2694,12 +2694,12 @@ Variant JSONParseResult::get_result() const {
}
void _JSON::_bind_methods() {
- ClassDB::bind_method(D_METHOD("print", "value"), &_JSON::print);
+ ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys"), &_JSON::print, DEFVAL(String()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
}
-String _JSON::print(const Variant &p_value) {
- return JSON::print(p_value);
+String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
+ return JSON::print(p_value, p_indent, p_sort_keys);
}
Ref<JSONParseResult> _JSON::parse(const String &p_json) {
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 8163b08d76..b642a907fb 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -719,7 +719,7 @@ protected:
public:
static _JSON *get_singleton() { return singleton; }
- String print(const Variant &p_value);
+ String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
Ref<JSONParseResult> parse(const String &p_json);
_JSON();
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 2e9170bc34..ddfc792cc7 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -43,7 +43,25 @@ const char *JSON::tk_name[TK_MAX] = {
"EOF",
};
-String JSON::_print_var(const Variant &p_var) {
+static String _make_indent(const String& p_indent, int p_size) {
+
+ String indent_text = "";
+ if (!p_indent.empty()) {
+ for (int i = 0; i < p_size; i++)
+ indent_text += p_indent;
+ }
+ return indent_text;
+}
+
+String JSON::_print_var(const Variant &p_var, const String& p_indent, int p_cur_indent, bool p_sort_keys) {
+
+ String colon = ":";
+ String end_statement = "";
+
+ if (!p_indent.empty()) {
+ colon += " ";
+ end_statement += "\n";
+ }
switch (p_var.get_type()) {
@@ -57,41 +75,50 @@ String JSON::_print_var(const Variant &p_var) {
case Variant::ARRAY: {
String s = "[";
+ s += end_statement;
Array a = p_var;
for (int i = 0; i < a.size(); i++) {
- if (i > 0)
- s += ", ";
- s += _print_var(a[i]);
+ if (i > 0) {
+ s += ",";
+ s += end_statement;
+ }
+ s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys);
}
- s += "]";
+ s += end_statement + _make_indent(p_indent, p_cur_indent) + "]";
return s;
};
case Variant::DICTIONARY: {
String s = "{";
+ s += end_statement;
Dictionary d = p_var;
List<Variant> keys;
d.get_key_list(&keys);
+ if (p_sort_keys)
+ keys.sort();
+
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
- if (E != keys.front())
- s += ", ";
- s += _print_var(String(E->get()));
- s += ":";
- s += _print_var(d[E->get()]);
+ if (E != keys.front()) {
+ s += ",";
+ s += end_statement;
+ }
+ s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys);
+ s += colon;
+ s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys);
}
- s += "}";
+ s += end_statement + _make_indent(p_indent, p_cur_indent) + "}";
return s;
};
default: return "\"" + String(p_var).json_escape() + "\"";
}
}
-String JSON::print(const Variant &p_var) {
+String JSON::print(const Variant &p_var, const String& p_indent, bool p_sort_keys) {
- return _print_var(p_var);
+ return _print_var(p_var, p_indent, 0, p_sort_keys);
}
Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
diff --git a/core/io/json.h b/core/io/json.h
index 893a88e264..5e1a89f069 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -64,7 +64,7 @@ class JSON {
static const char *tk_name[TK_MAX];
- static String _print_var(const Variant &p_var);
+ static String _print_var(const Variant &p_var, const String& p_indent, int p_cur_indent, bool p_sort_keys);
static Error _get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
static Error _parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str);
@@ -72,7 +72,7 @@ class JSON {
static Error _parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str);
public:
- static String print(const Variant &p_var);
+ static String print(const Variant &p_var, const String& p_indent = "", bool p_sort_keys = true);
static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line);
};
diff --git a/doc/classes/ColorPickerButton.xml b/doc/classes/ColorPickerButton.xml
index c8a4b850d0..ee34b2bcd1 100644
--- a/doc/classes/ColorPickerButton.xml
+++ b/doc/classes/ColorPickerButton.xml
@@ -18,6 +18,13 @@
Returns the [code]ColorPicker[/code] that this [code]ColorPickerButton[/code] toggles.
</description>
</method>
+ <method name="get_popup">
+ <return type="PopupPanel">
+ </return>
+ <description>
+ Returns the control's [PopupPanel] which allows you to connect to Popup Signals. This allows you to handle events when the ColorPicker is shown or hidden.
+ </description>
+ </method>
</methods>
<members>
<member name="color" type="Color" setter="set_pick_color" getter="get_pick_color">
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index ed04c90cc5..558f44769d 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -235,29 +235,34 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) {
Ref<Material> material = p_from;
ERR_FAIL_COND_V(material.is_null(), Ref<Texture>());
- VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid());
+ if (material->get_shader_mode() == Shader::MODE_SPATIAL) {
- VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
+ VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid());
- preview_done = false;
- VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
+ VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
- while (!preview_done) {
- OS::get_singleton()->delay_usec(10);
- }
+ preview_done = false;
+ VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
- Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture);
- VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID());
+ while (!preview_done) {
+ OS::get_singleton()->delay_usec(10);
+ }
- ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>());
+ Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture);
+ VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID());
- int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
- thumbnail_size *= EDSCALE;
- img->convert(Image::FORMAT_RGBA8);
- img->resize(thumbnail_size, thumbnail_size);
- Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
- ptex->create_from_image(img, 0);
- return ptex;
+ ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>());
+
+ int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
+ thumbnail_size *= EDSCALE;
+ img->convert(Image::FORMAT_RGBA8);
+ img->resize(thumbnail_size, thumbnail_size);
+ Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture));
+ ptex->create_from_image(img, 0);
+ return ptex;
+ }
+
+ return Ref<Texture>();
}
EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 66abe1baa8..9a3debbe90 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -184,6 +184,11 @@ RID CanvasItemMaterial::get_shader_rid() const {
return shader_map[current_key].shader;
}
+Shader::Mode CanvasItemMaterial::get_shader_mode() const {
+
+ return Shader::MODE_CANVAS_ITEM;
+}
+
void CanvasItemMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index c877a94755..ccbb528d6f 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -123,6 +123,8 @@ public:
RID get_shader_rid() const;
+ virtual Shader::Mode get_shader_mode() const;
+
CanvasItemMaterial();
virtual ~CanvasItemMaterial();
};
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 2a032f5d96..f8685a7b7c 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -869,6 +869,7 @@ void ParticlesMaterial::_update_shader() {
}
//scale by scale
code += " float base_scale = mix(scale*tex_scale,1.0,scale_random*scale_rand);\n";
+ code += " if (base_scale==0.0) base_scale=0.000001;\n";
if (trail_size_modifier.is_valid()) {
code += " if (trail_divisor > 1) { base_scale *= textureLod(trail_size_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0).r; } \n";
}
@@ -1360,6 +1361,11 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
}
}
+Shader::Mode ParticlesMaterial::get_shader_mode() const {
+
+ return Shader::MODE_PARTICLES;
+}
+
void ParticlesMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticlesMaterial::set_spread);
diff --git a/scene/3d/particles.h b/scene/3d/particles.h
index 30080360bb..5b8121e937 100644
--- a/scene/3d/particles.h
+++ b/scene/3d/particles.h
@@ -390,6 +390,8 @@ public:
RID get_shader_rid() const;
+ virtual Shader::Mode get_shader_mode() const;
+
ParticlesMaterial();
~ParticlesMaterial();
};
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index dbd7c1bbc0..7a0593bc87 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -664,11 +664,16 @@ ColorPicker *ColorPickerButton::get_picker() {
return picker;
}
+PopupPanel *ColorPickerButton::get_popup() {
+ return popup;
+}
+
void ColorPickerButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pick_color", "color"), &ColorPickerButton::set_pick_color);
ClassDB::bind_method(D_METHOD("get_pick_color"), &ColorPickerButton::get_pick_color);
ClassDB::bind_method(D_METHOD("get_picker"), &ColorPickerButton::get_picker);
+ ClassDB::bind_method(D_METHOD("get_popup"), &ColorPickerButton::get_popup);
ClassDB::bind_method(D_METHOD("set_edit_alpha", "show"), &ColorPickerButton::set_edit_alpha);
ClassDB::bind_method(D_METHOD("is_editing_alpha"), &ColorPickerButton::is_editing_alpha);
ClassDB::bind_method(D_METHOD("_color_changed"), &ColorPickerButton::_color_changed);
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 7de67a707c..c02cdc8608 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -130,6 +130,7 @@ public:
bool is_editing_alpha() const;
ColorPicker *get_picker();
+ PopupPanel *get_popup();
ColorPickerButton();
};
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 15710f4c14..a6f301af1e 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -215,6 +215,13 @@ bool ShaderMaterial::_can_do_next_pass() const {
return shader.is_valid() && shader->get_mode() == Shader::MODE_SPATIAL;
}
+Shader::Mode ShaderMaterial::get_shader_mode() const {
+ if (shader.is_valid())
+ return shader->get_mode();
+ else
+ return Shader::MODE_SPATIAL;
+}
+
ShaderMaterial::ShaderMaterial() {
}
@@ -1662,6 +1669,11 @@ RID SpatialMaterial::get_shader_rid() const {
return shader_map[current_key].shader;
}
+Shader::Mode SpatialMaterial::get_shader_mode() const {
+
+ return Shader::MODE_SPATIAL;
+}
+
void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo);
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 374ec853dc..7cfa38fce4 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -69,6 +69,8 @@ public:
int get_render_priority() const;
virtual RID get_rid() const;
+
+ virtual Shader::Mode get_shader_mode() const = 0;
Material();
virtual ~Material();
};
@@ -96,6 +98,8 @@ public:
void set_shader_param(const StringName &p_param, const Variant &p_value);
Variant get_shader_param(const StringName &p_param) const;
+ virtual Shader::Mode get_shader_mode() const;
+
ShaderMaterial();
~ShaderMaterial();
};
@@ -600,6 +604,8 @@ public:
RID get_shader_rid() const;
+ virtual Shader::Mode get_shader_mode() const;
+
SpatialMaterial();
virtual ~SpatialMaterial();
};