diff options
| author | Juan Linietsky | 2015-05-21 15:02:49 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2015-05-21 15:02:49 -0300 |
| commit | bb5d46bb113bca3204db7678eb69900f159e8087 (patch) | |
| tree | cd34e10d67a196d217559ab8d4973b8f5bc4ccde /scene | |
| parent | 4b8745ad63409cf14b02735981ee35d2f794421c (diff) | |
| parent | 6049479a99f66b620d59498a76ed9f2c3891f4c8 (diff) | |
| download | godot-bb5d46bb113bca3204db7678eb69900f159e8087.tar.gz godot-bb5d46bb113bca3204db7678eb69900f159e8087.tar.zst godot-bb5d46bb113bca3204db7678eb69900f159e8087.zip | |
Merge branch 'master' of https://github.com/okamstudio/godot
Diffstat (limited to 'scene')
| -rw-r--r-- | scene/2d/canvas_item.cpp | 2 | ||||
| -rw-r--r-- | scene/2d/node_2d.cpp | 14 | ||||
| -rw-r--r-- | scene/2d/node_2d.h | 3 | ||||
| -rw-r--r-- | scene/animation/animation_player.cpp | 2 | ||||
| -rw-r--r-- | scene/gui/file_dialog.cpp | 10 | ||||
| -rw-r--r-- | scene/gui/label.cpp | 10 | ||||
| -rw-r--r-- | scene/gui/rich_text_label.cpp | 2 | ||||
| -rw-r--r-- | scene/gui/text_edit.cpp | 9 | ||||
| -rw-r--r-- | scene/io/resource_format_wav.cpp | 12 | ||||
| -rw-r--r-- | scene/main/scene_main_loop.cpp | 76 | ||||
| -rw-r--r-- | scene/main/scene_main_loop.h | 15 | ||||
| -rw-r--r-- | scene/main/viewport.cpp | 6 | ||||
| -rw-r--r-- | scene/main/viewport.h | 1 | ||||
| -rw-r--r-- | scene/resources/shader_graph.cpp | 2 |
14 files changed, 145 insertions, 19 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 9b2cdf4ea..6a1ea0728 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -288,6 +288,7 @@ void CanvasItem::show() { if (is_visible()) { _propagate_visibility_changed(true); } + _change_notify("visibility/visible"); } @@ -305,6 +306,7 @@ void CanvasItem::hide() { if (propagate) _propagate_visibility_changed(false); + _change_notify("visibility/visible"); } diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index fc5be255c..99c33c787 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -346,6 +346,17 @@ Matrix32 Node2D::get_relative_transform(const Node *p_parent) const { return parent_2d->get_relative_transform(p_parent) * get_transform(); } + +void Node2D::look_at(const Vector2& p_pos) { + + rotate(get_angle_to(p_pos)); +} + +float Node2D::get_angle_to(const Vector2& p_pos) const { + + return (get_global_transform().affine_inverse().xform(p_pos)).atan2(); +} + void Node2D::_bind_methods() { @@ -374,6 +385,9 @@ void Node2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform); ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform); + ObjectTypeDB::bind_method(_MD("look_at","point"),&Node2D::look_at); + ObjectTypeDB::bind_method(_MD("get_angle_to","point"),&Node2D::get_angle_to); + ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z); ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z); diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 74612b3c6..8efce33cd 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -93,6 +93,9 @@ public: void set_z(int p_z); int get_z() const; + void look_at(const Vector2& p_pos); + float get_angle_to(const Vector2& p_pos) const; + void set_z_as_relative(bool p_enabled); bool is_z_relative() const; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 51afe6b3f..4949b33c4 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -295,7 +295,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { p_anim->node_cache[i]->bone_idx=p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx<0) { - // broken track (unexisting bone) + // broken track (nonexistent bone) p_anim->node_cache[i]->skeleton=NULL; p_anim->node_cache[i]->spatial=NULL; printf("bone is %ls\n", String(bone_name).c_str()); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 13cf87ac2..c53de6568 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -608,18 +608,12 @@ void FileDialog::_update_drives() { drives->clear(); drives->show(); - int current=-1; - String abspath = dir_access->get_current_dir(); - for(int i=0;i<dir_access->get_drive_count();i++) { - String d = dir_access->get_drive(i); - if (abspath.begins_with(d)) - current=i; + String d = dir_access->get_drive(i); drives->add_item(dir_access->get_drive(i)); } - if (current!=-1) - drives->select(current); + drives->select(dir_access->get_current_drive()); } } diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index dac21275d..27d0f568a 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -378,7 +378,11 @@ void Label::regenerate_word_cache() { if (uppercase) current=String::char_uppercase(current); - bool not_latin = current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); + // ranges taken from http://www.unicodemap.org/ + // if your language is not well supported, consider helping improve + // the unicode support in Godot. + bool separatable = (current>=0x2E08 && current<=0xFAFF) || (current>=0xFE30 && current<=0xFE4F); + //current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); bool insert_newline=false; int char_width; @@ -433,8 +437,8 @@ void Label::regenerate_word_cache() { } - if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || not_latin)) || insert_newline) { - if (not_latin) { + if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) { + if (separatable) { if (current_word_size>0) { WordCache *wc = memnew( WordCache ); if (word_cache) { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 6b2e5aea7..987a2ed80 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1673,6 +1673,8 @@ void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_scroll_follow","follow"),&RichTextLabel::set_scroll_follow); ObjectTypeDB::bind_method(_MD("is_scroll_following"),&RichTextLabel::is_scroll_following); + ObjectTypeDB::bind_method(_MD("get_v_scroll"),&RichTextLabel::get_v_scroll); + ObjectTypeDB::bind_method(_MD("set_tab_size","spaces"),&RichTextLabel::set_tab_size); ObjectTypeDB::bind_method(_MD("get_tab_size"),&RichTextLabel::get_tab_size); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index db8fbf7a6..0c15f9950 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1893,7 +1893,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { selection.from_line=0; selection.from_column=0; selection.to_line=text.size()-1; - selection.to_column=text[selection.to_line].size(); + selection.to_column=text[selection.to_line].length(); selection.selecting_mode=Selection::MODE_NONE; update(); @@ -2778,6 +2778,11 @@ void TextEdit::copy() { if (!selection.active) return; + print_line("from line: "+itos(selection.from_line)); + print_line("from column: "+itos(selection.from_column)); + print_line("to line: "+itos(selection.to_line)); + print_line("to column: "+itos(selection.to_column)); + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); @@ -2809,7 +2814,7 @@ void TextEdit::select_all() { selection.from_line=0; selection.from_column=0; selection.to_line=text.size()-1; - selection.to_column=text[selection.to_line].size(); + selection.to_column=text[selection.to_line].length(); selection.selecting_mode=Selection::MODE_NONE; update(); diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index a37d3b063..b246eb66f 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -146,9 +146,13 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_ } int frames=chunksize; + frames/=format_channels; frames/=(format_bits>>3); + print_line("chunksize: "+itos(chunksize)); + print_line("channels: "+itos(format_channels)); + print_line("bits: "+itos(format_bits)); sample->create( (format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16, @@ -156,8 +160,14 @@ RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_ frames ); sample->set_mix_rate( format_freq ); + int len=frames; + if (format_channels==2) + len*=2; + if (format_bits>8) + len*=2; + DVector<uint8_t> data; - data.resize(chunksize); + data.resize(len); DVector<uint8_t>::Write dataw = data.write(); void * data_ptr = dataw.ptr(); diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 9f2fadcb4..584b40337 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -41,7 +41,7 @@ #include "scene/scene_string_names.h" #include "io/resource_loader.h" #include "viewport.h" - +#include "scene/resources/packed_scene.h" void SceneTree::tree_changed() { @@ -51,6 +51,9 @@ void SceneTree::tree_changed() { void SceneTree::node_removed(Node *p_node) { + if (current_scene==p_node) { + current_scene=NULL; + } emit_signal(node_removed_name,p_node); if (call_lock>0) call_skip.insert(p_node); @@ -984,6 +987,63 @@ Node *SceneTree::get_edited_scene_root() const { } #endif +void SceneTree::set_current_scene(Node* p_scene) { + + ERR_FAIL_COND(p_scene && p_scene->get_parent()!=root); + current_scene=p_scene; +} + +Node* SceneTree::get_current_scene() const{ + + return current_scene; +} + +void SceneTree::_change_scene(Node* p_to) { + + if (current_scene) { + memdelete( current_scene ); + current_scene=NULL; + } + + if (p_to) { + current_scene=p_to; + root->add_child(p_to); + } +} + +Error SceneTree::change_scene(const String& p_path){ + + Ref<PackedScene> new_scene = ResourceLoader::load(p_path); + if (new_scene.is_null()) + return ERR_CANT_OPEN; + + return change_scene_to(new_scene); + +} +Error SceneTree::change_scene_to(const Ref<PackedScene>& p_scene){ + + Node *new_scene=NULL; + if (p_scene.is_valid()) { + new_scene = p_scene->instance(); + ERR_FAIL_COND_V(!new_scene,ERR_CANT_CREATE); + } + + call_deferred("_change_scene",new_scene); + return OK; + +} +Error SceneTree::reload_current_scene() { + + ERR_FAIL_COND_V(!current_scene,ERR_UNCONFIGURED); + String fname = current_scene->get_filename(); + return change_scene(fname); +} + +void SceneTree::add_current_scene(Node * p_current) { + + current_scene=p_current; + root->add_child(p_current); +} void SceneTree::_bind_methods() { @@ -1016,10 +1076,11 @@ void SceneTree::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_screen_stretch","mode","aspect","minsize"),&SceneTree::set_screen_stretch); - ObjectTypeDB::bind_method(_MD("queue_delete","obj"),&SceneTree::queue_delete); + + MethodInfo mi; mi.name="call_group"; mi.arguments.push_back( PropertyInfo( Variant::INT, "flags")); @@ -1033,6 +1094,16 @@ void SceneTree::_bind_methods() { ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi,defargs); + ObjectTypeDB::bind_method(_MD("set_current_scene","child_node:Node"),&SceneTree::set_current_scene); + ObjectTypeDB::bind_method(_MD("get_current_scene:Node"),&SceneTree::get_current_scene); + + ObjectTypeDB::bind_method(_MD("change_scene","path"),&SceneTree::change_scene); + ObjectTypeDB::bind_method(_MD("change_scene_to","packed_scene:PackedScene"),&SceneTree::change_scene_to); + + ObjectTypeDB::bind_method(_MD("reload_current_scene"),&SceneTree::reload_current_scene); + + ObjectTypeDB::bind_method(_MD("_change_scene"),&SceneTree::_change_scene); + ADD_SIGNAL( MethodInfo("tree_changed") ); ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) ); ADD_SIGNAL( MethodInfo("screen_resized") ); @@ -1077,6 +1148,7 @@ SceneTree::SceneTree() { //root->set_world_2d( Ref<World2D>( memnew( World2D ))); root->set_as_audio_listener(true); root->set_as_audio_listener_2d(true); + current_scene=NULL; stretch_mode=STRETCH_MODE_DISABLED; stretch_aspect=STRETCH_ASPECT_IGNORE; diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index fec4dd390..e49c150fb 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -42,7 +42,7 @@ class SceneTree; - +class PackedScene; class Node; class Viewport; @@ -136,7 +136,9 @@ private: Array _get_nodes_in_group(const StringName& p_group); + Node *current_scene; + void _change_scene(Node* p_to); //void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2); friend class Node; @@ -234,6 +236,17 @@ public: Node *get_edited_scene_root() const; #endif + void set_current_scene(Node* p_scene); + Node* get_current_scene() const; + Error change_scene(const String& p_path); + Error change_scene_to(const Ref<PackedScene>& p_scene); + Error reload_current_scene(); + + //used by Main::start, don't use otherwise + void add_current_scene(Node * p_current); + + + SceneTree(); ~SceneTree(); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 4d9feb3af..3bb64e54c 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1177,6 +1177,11 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { } +Vector2 Viewport::get_mouse_pos() const { + + return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos()); +} + void Viewport::warp_mouse(const Vector2& p_pos) { Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); @@ -1377,6 +1382,7 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d); ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect"), &Viewport::set_render_target_to_screen_rect); + ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos); ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse); ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") ); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index fba672561..c3c339ac5 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -252,6 +252,7 @@ public: void set_render_target_to_screen_rect(const Rect2& p_rect); Rect2 get_render_target_to_screen_rect() const; + Vector2 get_mouse_pos() const; void warp_mouse(const Vector2& p_pos); void set_physics_object_picking(bool p_enable); diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 24d597885..a0766ff31 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1301,7 +1301,7 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT","",SLOT_TYPE_VEC,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPECULAR","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION","",SLOT_TYPE_VEC,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW","",SLOT_TYPE_SCALAR,SLOT_OUT}, {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_OUT}, |
