summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/animation/animation_blend_tree.cpp24
-rw-r--r--scene/animation/animation_blend_tree.h1
-rw-r--r--scene/animation/animation_tree.cpp7
-rw-r--r--scene/gui/box_container.cpp4
-rw-r--r--scene/gui/graph_node.cpp159
-rw-r--r--scene/gui/grid_container.cpp4
-rw-r--r--scene/gui/margin_container.cpp38
-rw-r--r--scene/gui/split_container.cpp4
-rw-r--r--scene/gui/tab_container.cpp1
-rw-r--r--scene/resources/surface_tool.cpp2
-rw-r--r--scene/resources/surface_tool.h2
-rw-r--r--scene/resources/texture.cpp20
-rw-r--r--scene/resources/texture.h5
-rw-r--r--scene/resources/theme.cpp29
-rw-r--r--scene/resources/theme.h1
15 files changed, 191 insertions, 110 deletions
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index a343a4f0ed..0daa574f72 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -141,10 +141,14 @@ void AnimationNodeOneShot::get_parameter_list(List<PropertyInfo> *r_list) const
r_list->push_back(PropertyInfo(Variant::BOOL, prev_active, PROPERTY_HINT_NONE, "", 0));
r_list->push_back(PropertyInfo(Variant::REAL, time, PROPERTY_HINT_NONE, "", 0));
r_list->push_back(PropertyInfo(Variant::REAL, remaining, PROPERTY_HINT_NONE, "", 0));
+ r_list->push_back(PropertyInfo(Variant::REAL, time_to_restart, PROPERTY_HINT_NONE, "", 0));
}
+
Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const {
if (p_parameter == active || p_parameter == prev_active) {
return false;
+ } else if (p_parameter == time_to_restart) {
+ return -1;
} else {
return 0.0;
}
@@ -218,13 +222,26 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
bool prev_active = get_parameter(this->prev_active);
float time = get_parameter(this->time);
float remaining = get_parameter(this->remaining);
+ float time_to_restart = get_parameter(this->time_to_restart);
if (!active) {
//make it as if this node doesn't exist, pass input 0 by.
if (prev_active) {
set_parameter(this->prev_active, false);
}
- return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
+ if (time_to_restart >= 0.0 && !p_seek) {
+ time_to_restart -= p_time;
+ if (time_to_restart < 0) {
+ //restart
+ set_parameter(this->active, true);
+ active = true;
+ }
+ set_parameter(this->time_to_restart, time_to_restart);
+ }
+
+ if (!active) {
+ return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
+ }
}
bool os_seek = p_seek;
@@ -276,6 +293,10 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
if (remaining <= 0) {
set_parameter(this->active, false);
set_parameter(this->prev_active, false);
+ if (autorestart) {
+ float restart_sec = autorestart_delay + Math::randf() * autorestart_random_delay;
+ set_parameter(this->time_to_restart, restart_sec);
+ }
}
}
@@ -350,6 +371,7 @@ AnimationNodeOneShot::AnimationNodeOneShot() {
prev_active = "prev_active";
time = "time";
remaining = "remaining";
+ time_to_restart = "time_to_restart";
}
////////////////////////////////////////////////
diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h
index e207713134..c16dcb1b8c 100644
--- a/scene/animation/animation_blend_tree.h
+++ b/scene/animation/animation_blend_tree.h
@@ -91,6 +91,7 @@ private:
StringName prev_active;
StringName time;
StringName remaining;
+ StringName time_to_restart;
protected:
static void _bind_methods();
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 706717a8e3..dc022bcd70 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -685,6 +685,10 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
track = track_animation;
} break;
+ default: {
+ ERR_PRINT("Animation corrupted (invalid track type");
+ continue;
+ }
}
track_cache[path] = track;
@@ -853,6 +857,9 @@ void AnimationTree::_process_graph(float p_delta) {
for (int i = 0; i < a->get_track_count(); i++) {
NodePath path = a->track_get_path(i);
+
+ ERR_CONTINUE(!track_cache.has(path));
+
TrackCache *track = track_cache[path];
if (track->type != a->track_get_type(i)) {
continue; //may happen should not
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 35e8e984cd..cc37d4cf7d 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -255,6 +255,10 @@ void BoxContainer::_notification(int p_what) {
_resort();
} break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ minimum_size_changed();
+ } break;
}
}
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 7c879d239c..8c588109d6 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -192,97 +192,104 @@ bool GraphNode::has_point(const Point2 &p_point) const {
void GraphNode::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
- Ref<StyleBox> sb;
+ Ref<StyleBox> sb;
- if (comment) {
- sb = get_stylebox(selected ? "commentfocus" : "comment");
+ if (comment) {
+ sb = get_stylebox(selected ? "commentfocus" : "comment");
- } else {
+ } else {
- sb = get_stylebox(selected ? "selectedframe" : "frame");
- }
+ sb = get_stylebox(selected ? "selectedframe" : "frame");
+ }
- //sb=sb->duplicate();
- //sb->call("set_modulate",modulate);
- Ref<Texture> port = get_icon("port");
- Ref<Texture> close = get_icon("close");
- Ref<Texture> resizer = get_icon("resizer");
- int close_offset = get_constant("close_offset");
- int close_h_offset = get_constant("close_h_offset");
- Color close_color = get_color("close_color");
- Ref<Font> title_font = get_font("title_font");
- int title_offset = get_constant("title_offset");
- int title_h_offset = get_constant("title_h_offset");
- Color title_color = get_color("title_color");
- Point2i icofs = -port->get_size() * 0.5;
- int edgeofs = get_constant("port_offset");
- icofs.y += sb->get_margin(MARGIN_TOP);
-
- draw_style_box(sb, Rect2(Point2(), get_size()));
-
- switch (overlay) {
- case OVERLAY_DISABLED: {
-
- } break;
- case OVERLAY_BREAKPOINT: {
-
- draw_style_box(get_stylebox("breakpoint"), Rect2(Point2(), get_size()));
- } break;
- case OVERLAY_POSITION: {
- draw_style_box(get_stylebox("position"), Rect2(Point2(), get_size()));
-
- } break;
- }
+ //sb=sb->duplicate();
+ //sb->call("set_modulate",modulate);
+ Ref<Texture> port = get_icon("port");
+ Ref<Texture> close = get_icon("close");
+ Ref<Texture> resizer = get_icon("resizer");
+ int close_offset = get_constant("close_offset");
+ int close_h_offset = get_constant("close_h_offset");
+ Color close_color = get_color("close_color");
+ Ref<Font> title_font = get_font("title_font");
+ int title_offset = get_constant("title_offset");
+ int title_h_offset = get_constant("title_h_offset");
+ Color title_color = get_color("title_color");
+ Point2i icofs = -port->get_size() * 0.5;
+ int edgeofs = get_constant("port_offset");
+ icofs.y += sb->get_margin(MARGIN_TOP);
+
+ draw_style_box(sb, Rect2(Point2(), get_size()));
+
+ switch (overlay) {
+ case OVERLAY_DISABLED: {
+
+ } break;
+ case OVERLAY_BREAKPOINT: {
+
+ draw_style_box(get_stylebox("breakpoint"), Rect2(Point2(), get_size()));
+ } break;
+ case OVERLAY_POSITION: {
+ draw_style_box(get_stylebox("position"), Rect2(Point2(), get_size()));
+
+ } break;
+ }
- int w = get_size().width - sb->get_minimum_size().x;
+ int w = get_size().width - sb->get_minimum_size().x;
- if (show_close)
- w -= close->get_width();
+ if (show_close)
+ w -= close->get_width();
- draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
- if (show_close) {
- Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT) + close_h_offset, -close->get_height() + close_offset);
- draw_texture(close, cpos, close_color);
- close_rect.position = cpos;
- close_rect.size = close->get_size();
- } else {
- close_rect = Rect2();
- }
+ draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
+ if (show_close) {
+ Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT) + close_h_offset, -close->get_height() + close_offset);
+ draw_texture(close, cpos, close_color);
+ close_rect.position = cpos;
+ close_rect.size = close->get_size();
+ } else {
+ close_rect = Rect2();
+ }
- for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
-
- if (E->key() < 0 || E->key() >= cache_y.size())
- continue;
- if (!slot_info.has(E->key()))
- continue;
- const Slot &s = slot_info[E->key()];
- //left
- if (s.enable_left) {
- Ref<Texture> p = port;
- if (s.custom_slot_left.is_valid()) {
- p = s.custom_slot_left;
+ for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
+
+ if (E->key() < 0 || E->key() >= cache_y.size())
+ continue;
+ if (!slot_info.has(E->key()))
+ continue;
+ const Slot &s = slot_info[E->key()];
+ //left
+ if (s.enable_left) {
+ Ref<Texture> p = port;
+ if (s.custom_slot_left.is_valid()) {
+ p = s.custom_slot_left;
+ }
+ p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
}
- p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left);
- }
- if (s.enable_right) {
- Ref<Texture> p = port;
- if (s.custom_slot_right.is_valid()) {
- p = s.custom_slot_right;
+ if (s.enable_right) {
+ Ref<Texture> p = port;
+ if (s.custom_slot_right.is_valid()) {
+ p = s.custom_slot_right;
+ }
+ p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
}
- p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E->key()]), s.color_right);
}
- }
- if (resizable) {
- draw_texture(resizer, get_size() - resizer->get_size());
- }
- }
+ if (resizable) {
+ draw_texture(resizer, get_size() - resizer->get_size());
+ }
+ } break;
+
+ case NOTIFICATION_SORT_CHILDREN: {
+
+ _resort();
+ } break;
- if (p_what == NOTIFICATION_SORT_CHILDREN) {
+ case NOTIFICATION_THEME_CHANGED: {
- _resort();
+ minimum_size_changed();
+ } break;
}
}
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index b37d08de71..d0e2edc7b5 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -164,6 +164,10 @@ void GridContainer::_notification(int p_what) {
}
} break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ minimum_size_changed();
+ } break;
}
}
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index a087b68d25..62ba45c484 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -64,27 +64,33 @@ Size2 MarginContainer::get_minimum_size() const {
void MarginContainer::_notification(int p_what) {
- if (p_what == NOTIFICATION_SORT_CHILDREN) {
+ switch (p_what) {
+ case NOTIFICATION_SORT_CHILDREN: {
- int margin_left = get_constant("margin_left");
- int margin_top = get_constant("margin_top");
- int margin_right = get_constant("margin_right");
- int margin_bottom = get_constant("margin_bottom");
+ int margin_left = get_constant("margin_left");
+ int margin_top = get_constant("margin_top");
+ int margin_right = get_constant("margin_right");
+ int margin_bottom = get_constant("margin_bottom");
- Size2 s = get_size();
+ Size2 s = get_size();
- for (int i = 0; i < get_child_count(); i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
- continue;
- if (c->is_set_as_toplevel())
- continue;
+ Control *c = Object::cast_to<Control>(get_child(i));
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
- int w = s.width - margin_left - margin_right;
- int h = s.height - margin_top - margin_bottom;
- fit_child_in_rect(c, Rect2(margin_left, margin_top, w, h));
- }
+ int w = s.width - margin_left - margin_right;
+ int h = s.height - margin_top - margin_bottom;
+ fit_child_in_rect(c, Rect2(margin_left, margin_top, w, h));
+ }
+ } break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ minimum_size_changed();
+ } break;
}
}
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index e4cb2a06fc..d6a93238b2 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -193,6 +193,10 @@ void SplitContainer::_notification(int p_what) {
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
}
} break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ minimum_size_changed();
+ } break;
}
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index b4fe6b0255..212efa4976 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -338,6 +338,7 @@ void TabContainer::_notification(int p_what) {
}
} break;
case NOTIFICATION_THEME_CHANGED: {
+ minimum_size_changed();
call_deferred("_on_theme_changed"); //wait until all changed theme
} break;
}
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 1684cbf15f..2116dd0b1e 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -1021,8 +1021,6 @@ void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_normals", "flip"), &SurfaceTool::generate_normals, DEFVAL(false));
ClassDB::bind_method(D_METHOD("generate_tangents"), &SurfaceTool::generate_tangents);
- ClassDB::bind_method(D_METHOD("add_to_format", "flags"), &SurfaceTool::add_to_format);
-
ClassDB::bind_method(D_METHOD("set_material", "material"), &SurfaceTool::set_material);
ClassDB::bind_method(D_METHOD("clear"), &SurfaceTool::clear);
diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h
index 754254150d..ef13238c13 100644
--- a/scene/resources/surface_tool.h
+++ b/scene/resources/surface_tool.h
@@ -118,8 +118,6 @@ public:
void generate_normals(bool p_flip = false);
void generate_tangents();
- void add_to_format(int p_flags) { format |= p_flags; }
-
void set_material(const Ref<Material> &p_material);
void clear();
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 3870916779..26036c08a9 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -178,6 +178,12 @@ void ImageTexture::_reload_hook(const RID &p_hook) {
_change_notify();
}
+bool ImageTexture::keep_images_cached = false;
+
+void ImageTexture::set_keep_images_cached(bool p_enable) {
+ keep_images_cached = p_enable;
+}
+
void ImageTexture::create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags) {
flags = p_flags;
@@ -198,6 +204,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image, uint32_t p_flags
VisualServer::get_singleton()->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_flags);
VisualServer::get_singleton()->texture_set_data(texture, p_image);
_change_notify();
+
+ if (keep_images_cached) {
+ image_cache = p_image;
+ }
}
void ImageTexture::set_flags(uint32_t p_flags) {
@@ -245,6 +255,10 @@ void ImageTexture::set_data(const Ref<Image> &p_image) {
_change_notify();
alpha_cache.unref();
+
+ if (keep_images_cached) {
+ image_cache = p_image;
+ }
}
void ImageTexture::_resource_path_changed() {
@@ -254,7 +268,11 @@ void ImageTexture::_resource_path_changed() {
Ref<Image> ImageTexture::get_data() const {
- return VisualServer::get_singleton()->texture_get_data(texture);
+ if (image_cache.is_valid()) {
+ return image_cache;
+ } else {
+ return VisualServer::get_singleton()->texture_get_data(texture);
+ }
}
int ImageTexture::get_width() const {
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index 2b67ebec62..4b5b504510 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -111,6 +111,7 @@ private:
Size2 size_override;
float lossy_storage_quality;
mutable Ref<BitMap> alpha_cache;
+ Ref<Image> image_cache;
protected:
virtual void reload_from_file();
@@ -125,7 +126,11 @@ protected:
void _set_data(Dictionary p_data);
+ static bool keep_images_cached;
+
public:
+ static void set_keep_images_cached(bool p_enable);
+
void create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags = FLAGS_DEFAULT);
void create_from_image(const Ref<Image> &p_image, uint32_t p_flags = FLAGS_DEFAULT);
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 786a136040..87b40d5447 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -622,43 +622,47 @@ void Theme::clear() {
void Theme::copy_default_theme() {
Ref<Theme> default_theme = get_default();
+ copy_theme(default_theme);
+}
+
+void Theme::copy_theme(const Ref<Theme> &p_other) {
//these need reconnecting, so add normally
{
const StringName *K = NULL;
- while ((K = default_theme->icon_map.next(K))) {
+ while ((K = p_other->icon_map.next(K))) {
const StringName *L = NULL;
- while ((L = default_theme->icon_map[*K].next(L))) {
- set_icon(*K, *L, default_theme->icon_map[*K][*L]);
+ while ((L = p_other->icon_map[*K].next(L))) {
+ set_icon(*L, *K, p_other->icon_map[*K][*L]);
}
}
}
{
const StringName *K = NULL;
- while ((K = default_theme->style_map.next(K))) {
+ while ((K = p_other->style_map.next(K))) {
const StringName *L = NULL;
- while ((L = default_theme->style_map[*K].next(L))) {
- set_stylebox(*K, *L, default_theme->style_map[*K][*L]);
+ while ((L = p_other->style_map[*K].next(L))) {
+ set_stylebox(*L, *K, p_other->style_map[*K][*L]);
}
}
}
{
const StringName *K = NULL;
- while ((K = default_theme->font_map.next(K))) {
+ while ((K = p_other->font_map.next(K))) {
const StringName *L = NULL;
- while ((L = default_theme->font_map[*K].next(L))) {
- set_font(*K, *L, default_theme->font_map[*K][*L]);
+ while ((L = p_other->font_map[*K].next(L))) {
+ set_font(*L, *K, p_other->font_map[*K][*L]);
}
}
}
//these are ok to just copy
- color_map = default_theme->color_map;
- constant_map = default_theme->constant_map;
- shader_map = default_theme->shader_map;
+ color_map = p_other->color_map;
+ constant_map = p_other->constant_map;
+ shader_map = p_other->shader_map;
_change_notify();
emit_changed();
@@ -752,6 +756,7 @@ void Theme::_bind_methods() {
ClassDB::bind_method(D_METHOD("_emit_theme_changed"), &Theme::_emit_theme_changed);
ClassDB::bind_method("copy_default_theme", &Theme::copy_default_theme);
+ ClassDB::bind_method("copy_theme", &Theme::copy_theme);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "default_font", PROPERTY_HINT_RESOURCE_TYPE, "Font"), "set_default_font", "get_default_font");
}
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index 021a2936bd..fb59073cbe 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -184,6 +184,7 @@ public:
void get_type_list(List<StringName> *p_list) const;
void copy_default_theme();
+ void copy_theme(const Ref<Theme> &p_other);
void clear();
Theme();