summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/color_ramp.cpp34
-rw-r--r--scene/resources/color_ramp.h3
-rw-r--r--scene/resources/font.cpp43
-rw-r--r--scene/resources/font.h12
-rw-r--r--scene/resources/material.cpp2
-rw-r--r--scene/resources/packed_scene.cpp13
-rw-r--r--scene/resources/scene_format_text.cpp4
-rw-r--r--scene/resources/shader.cpp20
8 files changed, 92 insertions, 39 deletions
diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp
index 97d3fafd58..bf1f298e7a 100644
--- a/scene/resources/color_ramp.cpp
+++ b/scene/resources/color_ramp.cpp
@@ -26,6 +26,23 @@ ColorRamp::~ColorRamp() {
void ColorRamp::_bind_methods() {
+
+
+
+
+ ObjectTypeDB::bind_method(_MD("add_point","offset","color"),&ColorRamp::add_point);
+ ObjectTypeDB::bind_method(_MD("remove_point","offset","color"),&ColorRamp::remove_point);
+
+ ObjectTypeDB::bind_method(_MD("set_offset","point","offset"),&ColorRamp::set_offset);
+ ObjectTypeDB::bind_method(_MD("get_offset","point"),&ColorRamp::get_offset);
+
+ ObjectTypeDB::bind_method(_MD("set_color","point","color"),&ColorRamp::set_color);
+ ObjectTypeDB::bind_method(_MD("get_color","point"),&ColorRamp::get_color);
+
+ ObjectTypeDB::bind_method(_MD("interpolate","offset"),&ColorRamp::get_color_at_offset);
+
+ ObjectTypeDB::bind_method(_MD("get_point_count"),&ColorRamp::get_points_count);
+
ObjectTypeDB::bind_method(_MD(COLOR_RAMP_SET_OFFSETS,"offsets"),&ColorRamp::set_offsets);
ObjectTypeDB::bind_method(_MD(COLOR_RAMP_GET_OFFSETS),&ColorRamp::get_offsets);
@@ -79,6 +96,23 @@ Vector<ColorRamp::Point>& ColorRamp::get_points() {
return points;
}
+void ColorRamp::add_point(float p_offset, const Color& p_color) {
+
+ Point p;
+ p.offset=p_offset;
+ p.color=p_color;
+ is_sorted=false;
+ points.push_back(p);
+
+}
+
+void ColorRamp::remove_point(int p_index) {
+
+ ERR_FAIL_INDEX(p_index,points.size());
+ ERR_FAIL_COND(points.size()<=2);
+ points.remove(p_index);
+}
+
void ColorRamp::set_points(Vector<ColorRamp::Point>& p_points) {
points = p_points;
is_sorted = false;
diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h
index 8f6ba2c3e5..aab5698c2b 100644
--- a/scene/resources/color_ramp.h
+++ b/scene/resources/color_ramp.h
@@ -32,6 +32,9 @@ public:
ColorRamp();
virtual ~ColorRamp();
+ void add_point(float p_offset, const Color& p_color);
+ void remove_point(int p_index);
+
void set_points(Vector<Point>& points);
Vector<Point>& get_points();
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 2d93113b40..aad5e7cfdd 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -462,31 +462,16 @@ void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,fl
void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const {
- Point2 pos=p_pos;
- float ofs=0;
- VisualServer *vs = VisualServer::get_singleton();
+ Vector2 ofs;
for (int i=0;i<p_text.length();i++) {
- const Character * c = char_map.getptr(p_text[i]);
+ int width = get_char_size(p_text[i]).width;
- if (!c)
- continue;
-
-// if (p_clip_w>=0 && (ofs+c->rect.size.width)>(p_clip_w))
-// break; //width exceeded
-
- if (p_clip_w>=0 && (ofs+c->rect.size.width)>p_clip_w)
+ if (p_clip_w>=0 && (ofs.x+width)>p_clip_w)
break; //clip
- Point2 cpos=pos;
- cpos.x+=ofs+c->h_align;
- cpos.y-=ascent;
- cpos.y+=c->v_align;
- ERR_CONTINUE( c->texture_idx<-1 || c->texture_idx>=textures.size());
- if (c->texture_idx!=-1)
- textures[c->texture_idx]->draw_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), c->rect, p_modulate );
-
- ofs+=get_char_size(p_text[i],p_text[i+1]).width;
+
+ ofs.x+=draw_char(p_canvas_item,p_pos+ofs,p_text[i],p_text[i+1],p_modulate);
}
}
@@ -494,8 +479,11 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_
const Character * c = char_map.getptr(p_char);
- if (!c)
+ if (!c) {
+ if (fallback.is_valid())
+ return fallback->draw_char(p_canvas_item,p_pos,p_char,p_next,p_modulate);
return 0;
+ }
Point2 cpos=p_pos;
cpos.x+=c->h_align;
@@ -508,6 +496,16 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_
return get_char_size(p_char,p_next).width;
}
+void Font::set_fallback(const Ref<Font> &p_fallback) {
+
+ fallback=p_fallback;
+}
+
+Ref<Font> Font::get_fallback() const{
+
+ return fallback;
+}
+
void Font::_bind_methods() {
ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt);
@@ -548,6 +546,8 @@ void Font::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_set_textures"),&Font::_set_textures);
ObjectTypeDB::bind_method(_MD("_get_textures"),&Font::_get_textures);
+ ObjectTypeDB::bind_method(_MD("set_fallback","fallback"),&Font::set_fallback);
+ ObjectTypeDB::bind_method(_MD("get_fallback"),&Font::get_fallback);
ADD_PROPERTY( PropertyInfo( Variant::ARRAY, "textures", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_textures"), _SCS("_get_textures") );
ADD_PROPERTY( PropertyInfo( Variant::INT_ARRAY, "chars", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_chars"), _SCS("_get_chars") );
@@ -556,6 +556,7 @@ void Font::_bind_methods() {
ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_height"), _SCS("get_height") );
ADD_PROPERTY( PropertyInfo( Variant::REAL, "ascent", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_ascent"), _SCS("get_ascent") );
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "distance_field" ), _SCS("set_distance_field_hint"), _SCS("is_distance_field_hint") );
+ ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "fallback", PROPERTY_HINT_RESOURCE_TYPE,"Font" ), _SCS("set_fallback"), _SCS("get_fallback") );
}
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 6728b59f8e..27e3045eaa 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -84,6 +84,7 @@ private:
void _set_textures(const Vector<Variant> & p_textures);
Vector<Variant> _get_textures() const;
+ Ref<Font> fallback;
protected:
static void _bind_methods();
@@ -113,9 +114,13 @@ public:
int get_kerning_pair(CharType p_A,CharType p_B) const;
Vector<KerningPairKey> get_kerning_pair_keys() const;
- _FORCE_INLINE_ Size2 get_char_size(CharType p_char,CharType p_next=0) const;
+ inline Size2 get_char_size(CharType p_char,CharType p_next=0) const;
Size2 get_string_size(const String& p_string) const;
+
+ void set_fallback(const Ref<Font> &p_fallback);
+ Ref<Font> get_fallback() const;
+
void clear();
void set_distance_field_hint(bool p_distance_field);
@@ -134,8 +139,11 @@ Size2 Font::get_char_size(CharType p_char,CharType p_next) const {
const Character * c = char_map.getptr(p_char);
- if (!c)
+ if (!c) {
+ if (fallback.is_valid())
+ return fallback->get_char_size(p_char,p_next);
return Size2();
+ }
Size2 ret(c->advance,c->rect.size.y);
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 55bb4e9073..b4ea60cb8d 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -535,6 +535,8 @@ void ShaderMaterial::_shader_changed() {
void ShaderMaterial::set_shader(const Ref<Shader>& p_shader) {
+ ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_MATERIAL);
+
if (shader.is_valid())
shader->disconnect(SceneStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->_shader_changed);
shader=p_shader;
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 863f2be699..f8283bb5ca 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -509,6 +509,19 @@ Error SceneState::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<S
}
}
+ if (exists && p_node->get_script_instance()) {
+ //if this is an overriden value by another script, save it anyway
+ //as the script change will erase it
+ //https://github.com/godotengine/godot/issues/2958
+
+ bool valid=false;
+ p_node->get_script_instance()->get_property_type(name,&valid);
+ if (valid) {
+ exists=false;
+ isdefault=false;
+ }
+ }
+
if (exists && bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) {
//exists and did not change
diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp
index 5f41dc2ce8..851083aecf 100644
--- a/scene/resources/scene_format_text.cpp
+++ b/scene/resources/scene_format_text.cpp
@@ -932,6 +932,10 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderText::load_interactive(const
void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const {
+ if (p_type=="") {
+ get_recognized_extensions(p_extensions);
+ return;
+ }
if (p_type=="PackedScene")
p_extensions->push_back("tscn");
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index a9376faf62..f0a2721016 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -448,31 +448,19 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String& p_origi
void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const {
- p_extensions->push_back("shader");
+ ObjectTypeDB::get_extensions_for_type("Shader", p_extensions);
}
+
bool ResourceFormatLoaderShader::handles_type(const String& p_type) const {
- return p_type=="Shader";
+ return ObjectTypeDB::is_type(p_type, "Shader");
}
String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
- if (p_path.extension().to_lower()=="shader")
+ if (p_path.extension().to_lower()=="shd")
return "Shader";
return "";
}
-
-
-
-
-
-
-
-
-
-
-
-
-