diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/animated_sprite.cpp | 2 | ||||
-rw-r--r-- | scene/2d/camera_2d.cpp | 37 | ||||
-rw-r--r-- | scene/2d/camera_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/canvas_item.cpp | 77 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 1 | ||||
-rw-r--r-- | scene/2d/navigation2d.cpp | 7 | ||||
-rw-r--r-- | scene/2d/parallax_background.cpp | 15 | ||||
-rw-r--r-- | scene/2d/parallax_background.h | 7 | ||||
-rw-r--r-- | scene/2d/parallax_layer.cpp | 36 | ||||
-rw-r--r-- | scene/2d/parallax_layer.h | 4 | ||||
-rw-r--r-- | scene/2d/sprite.cpp | 13 | ||||
-rw-r--r-- | scene/2d/sprite.h | 2 | ||||
-rw-r--r-- | scene/2d/visibility_notifier_2d.cpp | 12 |
13 files changed, 127 insertions, 88 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index c062a6d1fc..73774e12d9 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -318,7 +318,7 @@ void AnimatedSprite::_validate_property(PropertyInfo& property) const { if (property.name=="frame") { - property.hint=PROPERTY_HINT_RANGE; + property.hint=PROPERTY_HINT_SPRITE_FRAME; if (frames->has_animation(animation)) { property.hint_string="0,"+itos(frames->get_frame_count(animation)-1)+",1"; diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index fd8a0ed0f3..f98a50e3e0 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -44,7 +44,6 @@ void Camera2D::_update_scroll() { if (current) { Matrix32 xform = get_camera_transform(); - RID vp = viewport->get_viewport(); if (viewport) { viewport->set_canvas_transform( xform ); } @@ -281,11 +280,10 @@ void Camera2D::_notification(int p_what) { inv_camera_transform.xform(Vector2(0, screen_size.height)) }; - Matrix32 inv_transform = get_transform().affine_inverse(); // undo global space - draw_set_transform(inv_transform.get_origin(), inv_transform.get_rotation(), inv_transform.get_scale()); + Matrix32 inv_transform = get_global_transform().affine_inverse(); // undo global space for(int i=0;i<4;i++) { - draw_line(screen_endpoints[i], screen_endpoints[(i+1)%4], area_axis_color, area_axis_width); + draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i+1)%4]), area_axis_color, area_axis_width); } } break; @@ -410,6 +408,35 @@ void Camera2D::force_update_scroll() { _update_scroll(); } +void Camera2D::reset_smoothing() { + + smoothed_camera_pos = camera_pos; + _update_scroll(); +} + +void Camera2D::align() { + + Size2 screen_size = get_viewport_rect().size; + screen_size=get_viewport_rect().size; + Point2 current_camera_pos = get_global_transform().get_origin(); + if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) { + if (h_ofs<0) { + camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; + } else { + camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; + } + if (v_ofs<0) { + camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; + } else { + camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; + } + } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){ + + camera_pos=current_camera_pos; + } + + _update_scroll(); +} void Camera2D::set_follow_smoothing(float p_speed) { @@ -545,6 +572,8 @@ void Camera2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_follow_smoothing_enabled"),&Camera2D::is_follow_smoothing_enabled); ObjectTypeDB::bind_method(_MD("force_update_scroll"),&Camera2D::force_update_scroll); + ObjectTypeDB::bind_method(_MD("reset_smoothing"),&Camera2D::reset_smoothing); + ObjectTypeDB::bind_method(_MD("align"),&Camera2D::align); ObjectTypeDB::bind_method(_MD("_set_old_smoothing","follow_smoothing"),&Camera2D::_set_old_smoothing); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 22e5bc382a..b3f55d798d 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -128,6 +128,8 @@ public: Vector2 get_camera_pos() const; void force_update_scroll(); + void reset_smoothing(); + void align(); Camera2D(); }; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index fa9b040d92..bc5bff3b8e 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -756,6 +756,17 @@ void CanvasItem::draw_set_transform(const Point2& p_offset, float p_rot, const S VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,xform); } +void CanvasItem::draw_set_transform_matrix(const Matrix32& p_matrix) { + + if (!drawing) { + ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); + ERR_FAIL(); + } + + VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,p_matrix); + +} + void CanvasItem::draw_polygon(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture) { if (!drawing) { @@ -942,72 +953,21 @@ InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const { ERR_FAIL_COND_V(!is_inside_tree(),p_event); - InputEvent ev = p_event; - - Matrix32 local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse(); - - switch(ev.type) { - - case InputEvent::MOUSE_BUTTON: { + return p_event.xform_by( (get_canvas_transform() * get_global_transform()).affine_inverse() ); - Vector2 g = local_matrix.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); - Vector2 l = local_matrix.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)); - ev.mouse_button.x=l.x; - ev.mouse_button.y=l.y; - ev.mouse_button.global_x=g.x; - ev.mouse_button.global_y=g.y; - - } break; - case InputEvent::MOUSE_MOTION: { - - Vector2 g = local_matrix.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); - Vector2 l = local_matrix.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); - Vector2 r = local_matrix.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); - Vector2 s = local_matrix.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); - ev.mouse_motion.x=l.x; - ev.mouse_motion.y=l.y; - ev.mouse_motion.global_x=g.x; - ev.mouse_motion.global_y=g.y; - ev.mouse_motion.relative_x=r.x; - ev.mouse_motion.relative_y=r.y; - ev.mouse_motion.speed_x=s.x; - ev.mouse_motion.speed_y=s.y; - - } break; - case InputEvent::SCREEN_TOUCH: { - - - Vector2 t = local_matrix.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)); - ev.screen_touch.x=t.x; - ev.screen_touch.y=t.y; - - } break; - case InputEvent::SCREEN_DRAG: { - - - Vector2 t = local_matrix.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); - Vector2 r = local_matrix.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); - Vector2 s = local_matrix.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); - ev.screen_drag.x=t.x; - ev.screen_drag.y=t.y; - ev.screen_drag.relative_x=r.x; - ev.screen_drag.relative_y=r.y; - ev.screen_drag.speed_x=s.x; - ev.screen_drag.speed_y=s.y; - } break; - } - - return ev; } Vector2 CanvasItem::get_global_mouse_pos() const { - return get_viewport_transform().affine_inverse().xform(Input::get_singleton()->get_mouse_pos()); + ERR_FAIL_COND_V(!get_viewport(),Vector2()); + return get_canvas_transform().affine_inverse().xform( get_viewport()->get_mouse_pos() ); } Vector2 CanvasItem::get_local_mouse_pos() const{ - return (get_viewport_transform() * get_global_transform()).affine_inverse().xform(Input::get_singleton()->get_mouse_pos()); + ERR_FAIL_COND_V(!get_viewport(),Vector2()); + + return get_global_transform().affine_inverse().xform( get_global_mouse_pos() ); } @@ -1020,7 +980,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("_is_visible_"),&CanvasItem::_is_visible_); ObjectTypeDB::bind_method(_MD("edit_set_state","state"),&CanvasItem::edit_set_state); - ObjectTypeDB::bind_method(_MD("edit_get"),&CanvasItem::edit_get_state); + ObjectTypeDB::bind_method(_MD("edit_get_state:Variant"),&CanvasItem::edit_get_state); ObjectTypeDB::bind_method(_MD("edit_set_rect","rect"),&CanvasItem::edit_set_rect); ObjectTypeDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate); @@ -1073,6 +1033,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("draw_char","font:Font","pos","char","next","modulate"),&CanvasItem::draw_char,DEFVAL(Color(1,1,1))); ObjectTypeDB::bind_method(_MD("draw_set_transform","pos","rot","scale"),&CanvasItem::draw_set_transform); + ObjectTypeDB::bind_method(_MD("draw_set_transform_matrix","xform"),&CanvasItem::draw_set_transform_matrix); ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasItem::get_transform); ObjectTypeDB::bind_method(_MD("get_global_transform"),&CanvasItem::get_global_transform); ObjectTypeDB::bind_method(_MD("get_global_transform_with_canvas"),&CanvasItem::get_global_transform_with_canvas); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 8b44e09857..8a61b449fd 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -222,6 +222,7 @@ public: float draw_char(const Ref<Font>& p_font,const Point2& p_pos, const String& p_char,const String& p_next="",const Color& p_modulate=Color(1,1,1)); void draw_set_transform(const Point2& p_offset, float p_rot, const Size2& p_scale); + void draw_set_transform_matrix(const Matrix32& p_matrix); /* RECT / TRANSFORM */ diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index b4332cc75d..82c1327a8f 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -552,7 +552,6 @@ debug path if (p_optimize) { //string pulling - Polygon *apex_poly=end_poly; Vector2 apex_point=end_point; Vector2 portal_left=apex_point; Vector2 portal_right=apex_point; @@ -613,12 +612,9 @@ debug path //print_line("***ADVANCE LEFT"); } else { - //_clip_path(path,apex_poly,portal_right,right_poly); - apex_point=portal_right; p=right_poly; left_poly=p; - apex_poly=p; portal_left=apex_point; portal_right=apex_point; if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) @@ -637,12 +633,9 @@ debug path //print_line("***ADVANCE RIGHT"); } else { - //_clip_path(path,apex_poly,portal_left,left_poly); - apex_point=portal_left; p=left_poly; right_poly=p; - apex_poly=p; portal_right=apex_point; portal_left=apex_point; if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 7f2e9efd96..1b6ab66fcc 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -104,16 +104,18 @@ void ParallaxBackground::_update_scroll() { } ofs = -ofs; + final_offset=ofs; + for(int i=0;i<get_child_count();i++) { ParallaxLayer *l=get_child(i)->cast_to<ParallaxLayer>(); if (!l) continue; - if (ignore_camera_zoom) - l->set_base_offset_and_scale(ofs, 1.0); - else - l->set_base_offset_and_scale(ofs, scale); + if (ignore_camera_zoom) + l->set_base_offset_and_scale(ofs, 1.0); + else + l->set_base_offset_and_scale(ofs, scale); } } @@ -180,6 +182,11 @@ bool ParallaxBackground::is_ignore_camera_zoom(){ } +Vector2 ParallaxBackground::get_final_offset() const { + + return final_offset; +} + void ParallaxBackground::_bind_methods() { ObjectTypeDB::bind_method(_MD("_camera_moved"),&ParallaxBackground::_camera_moved); diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h index bdaf7d241f..c00cd52f26 100644 --- a/scene/2d/parallax_background.h +++ b/scene/2d/parallax_background.h @@ -44,6 +44,7 @@ class ParallaxBackground : public CanvasLayer { String group_name; Point2 limit_begin; Point2 limit_end; + Point2 final_offset; bool ignore_camera_zoom; void _update_scroll(); @@ -73,8 +74,10 @@ public: void set_limit_end(const Point2& p_ofs); Point2 get_limit_end() const; - void set_ignore_camera_zoom(bool ignore); - bool is_ignore_camera_zoom(); + void set_ignore_camera_zoom(bool ignore); + bool is_ignore_camera_zoom(); + + Vector2 get_final_offset() const; ParallaxBackground(); }; diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index bf559deb09..e9378b1d02 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -32,6 +32,15 @@ void ParallaxLayer::set_motion_scale(const Size2& p_scale) { motion_scale=p_scale; + + + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + if (is_inside_tree() && pb) { + Vector2 ofs = pb->get_final_offset(); + float scale = pb->get_scroll_scale(); + set_base_offset_and_scale(ofs,scale); + } + } Size2 ParallaxLayer::get_motion_scale() const { @@ -40,6 +49,23 @@ Size2 ParallaxLayer::get_motion_scale() const { } +void ParallaxLayer::set_motion_offset(const Size2& p_offset) { + + motion_offset=p_offset; + + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + if (is_inside_tree() && pb) { + Vector2 ofs = pb->get_final_offset(); + float scale = pb->get_scroll_scale(); + set_base_offset_and_scale(ofs,scale); + } +} + +Size2 ParallaxLayer::get_motion_offset() const { + + return motion_offset; + +} void ParallaxLayer::_update_mirroring() { @@ -59,6 +85,11 @@ void ParallaxLayer::_update_mirroring() { void ParallaxLayer::set_mirroring(const Size2& p_mirroring) { mirroring=p_mirroring; + if (mirroring.x<0) + mirroring.x=0; + if (mirroring.y<0) + mirroring.y=0; + _update_mirroring(); } @@ -89,7 +120,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2& p_offset,float p_sca return; if (get_tree()->is_editor_hint()) return; - Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale; + Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale+motion_offset; if (mirroring.x) { @@ -132,10 +163,13 @@ void ParallaxLayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_motion_scale","scale"),&ParallaxLayer::set_motion_scale); ObjectTypeDB::bind_method(_MD("get_motion_scale"),&ParallaxLayer::get_motion_scale); + ObjectTypeDB::bind_method(_MD("set_motion_offset","offset"),&ParallaxLayer::set_motion_offset); + ObjectTypeDB::bind_method(_MD("get_motion_offset"),&ParallaxLayer::get_motion_offset); ObjectTypeDB::bind_method(_MD("set_mirroring","mirror"),&ParallaxLayer::set_mirroring); ObjectTypeDB::bind_method(_MD("get_mirroring"),&ParallaxLayer::get_mirroring); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/scale"),_SCS("set_motion_scale"),_SCS("get_motion_scale")); + ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/offset"),_SCS("set_motion_offset"),_SCS("get_motion_offset")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/mirroring"),_SCS("set_mirroring"),_SCS("get_mirroring")); } diff --git a/scene/2d/parallax_layer.h b/scene/2d/parallax_layer.h index c2d345da47..6b1d73ea66 100644 --- a/scene/2d/parallax_layer.h +++ b/scene/2d/parallax_layer.h @@ -38,6 +38,7 @@ class ParallaxLayer : public Node2D { Point2 orig_offset; Point2 orig_scale; Size2 motion_scale; + Vector2 motion_offset; Vector2 mirroring; void _update_mirroring(); @@ -48,6 +49,9 @@ protected: public: + void set_motion_offset(const Size2& p_scale); + Size2 get_motion_offset() const; + void set_motion_scale(const Size2& p_scale); Size2 get_motion_scale() const; diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 3e6384ea2c..c5b338bf59 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -120,6 +120,7 @@ void Sprite::set_texture(const Ref<Texture>& p_texture) { } #endif update(); + emit_signal("texture_changed"); item_rect_changed(); } @@ -287,6 +288,17 @@ Rect2 Sprite::get_item_rect() const { } + +void Sprite::_validate_property(PropertyInfo& property) const { + + if (property.name=="frame") { + + property.hint=PROPERTY_HINT_SPRITE_FRAME; + + property.hint_string="0,"+itos(vframes*hframes-1)+",1"; + } +} + void Sprite::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_texture","texture:Texture"),&Sprite::set_texture); @@ -323,6 +335,7 @@ void Sprite::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_modulate"),&Sprite::get_modulate); ADD_SIGNAL(MethodInfo("frame_changed")); + ADD_SIGNAL(MethodInfo("texture_changed")); ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered")); diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h index f789538b1d..32d3f476d1 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite.h @@ -61,6 +61,8 @@ protected: static void _bind_methods();; + virtual void _validate_property(PropertyInfo& property) const; + public: virtual void edit_set_pivot(const Point2& p_pivot); diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 12524a2192..5411950976 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -270,9 +270,6 @@ void VisibilityEnabler2D::_notification(int p_what){ return; - Node *from = this; - //find where current scene starts - for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { if (!visible) @@ -293,14 +290,7 @@ void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) { RigidBody2D *rb = p_node->cast_to<RigidBody2D>(); if (rb) { - if (p_enabled) { - RigidBody2D::Mode mode = RigidBody2D::Mode(nodes[p_node].operator int()); - //rb->set_mode(mode); - rb->set_sleeping(false); - } else { - //rb->set_mode(RigidBody2D::MODE_STATIC); - rb->set_sleeping(true); - } + rb->set_sleeping(!p_enabled); } } |