diff options
-rw-r--r-- | SConstruct | 2 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 37 | ||||
-rw-r--r-- | core/os/input_event.cpp | 3 | ||||
-rw-r--r-- | core/translation.cpp | 18 | ||||
-rwxr-xr-x | methods.py | 5 | ||||
-rw-r--r-- | modules/openssl/SCsub | 2 | ||||
-rw-r--r-- | platform/windows/detect.py | 26 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 34 | ||||
-rw-r--r-- | tools/editor/editor_file_dialog.cpp | 47 | ||||
-rw-r--r-- | tools/editor/scene_tree_dock.cpp | 64 | ||||
-rw-r--r-- | tools/editor/scene_tree_dock.h | 6 |
11 files changed, 146 insertions, 98 deletions
diff --git a/SConstruct b/SConstruct index 72de2e2004..365463ebad 100644 --- a/SConstruct +++ b/SConstruct @@ -61,7 +61,7 @@ platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False)) if (os.name=="posix"): pass elif (os.name=="nt"): - if (not methods.msvc_is_detected() or platform_arg=="android"): + if ( os.getenv("VCINSTALLDIR")==None or platform_arg=="android"): custom_tools=['mingw'] env_base=Environment(tools=custom_tools); diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 64615fe6b4..46c0218707 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -41,37 +41,16 @@ static uint32_t Q[4096]; #endif uint32_t Math::rand_from_seed(uint32_t *seed) { - -#if 1 - uint32_t k; - uint32_t s = (*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; -// if (s < 0) -// s += 2147483647; - (*seed) = s; - return (s & Math::RANDOM_MAX); -#else - *seed = *seed * 1103515245 + 12345; - return (*seed % ((unsigned int)RANDOM_MAX + 1)); -#endif + // Xorshift31 PRNG + if ( *seed == 0 ) *seed = Math::RANDOM_MAX; + (*seed) ^= (*seed) << 13; + (*seed) ^= (*seed) >> 17; + (*seed) ^= (*seed) << 5; + return (*seed) & Math::RANDOM_MAX; } void Math::seed(uint32_t x) { -#if 0 - int i; - - Q[0] = x; - Q[1] = x + PHI; - Q[2] = x + PHI + PHI; - - for (i = 3; i < 4096; i++) - Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; -#else default_seed=x; -#endif } void Math::randomize() { @@ -82,12 +61,12 @@ void Math::randomize() { uint32_t Math::rand() { - return rand_from_seed(&default_seed)&0x7FFFFFFF; + return rand_from_seed(&default_seed); } double Math::randf() { - return (double)rand() / (double)RANDOM_MAX; + return (double)rand() / (double)Math::RANDOM_MAX; } double Math::sin(double p_x) { diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 9982767be1..7350be824a 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -50,7 +50,8 @@ bool InputEvent::operator==(const InputEvent &p_event) const { case MOUSE_MOTION: return mouse_motion.x == p_event.mouse_motion.x && mouse_motion.y == p_event.mouse_motion.y - && mouse_motion.relative_x == p_event.mouse_motion.relative_y + && mouse_motion.relative_x == p_event.mouse_motion.relative_x + && mouse_motion.relative_y == p_event.mouse_motion.relative_y && mouse_motion.button_mask == p_event.mouse_motion.button_mask && key.mod == p_event.key.mod; case MOUSE_BUTTON: diff --git a/core/translation.cpp b/core/translation.cpp index 0137db3b42..4d81073fe6 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -844,8 +844,11 @@ void Translation::_set_messages(const DVector<String>& p_messages){ void Translation::set_locale(const String& p_locale) { - if(!is_valid_locale(p_locale)) { - String trimmed_locale = get_trimmed_locale(p_locale); + // replaces '-' with '_' for macOS Sierra-style locales + String univ_locale = p_locale.replace("-", "_"); + + if(!is_valid_locale(univ_locale)) { + String trimmed_locale = get_trimmed_locale(univ_locale); ERR_EXPLAIN("Invalid Locale: "+trimmed_locale); ERR_FAIL_COND(!is_valid_locale(trimmed_locale)); @@ -853,7 +856,7 @@ void Translation::set_locale(const String& p_locale) { locale=trimmed_locale; } else { - locale=p_locale; + locale=univ_locale; } } @@ -919,8 +922,11 @@ Translation::Translation() { void TranslationServer::set_locale(const String& p_locale) { - if(!is_valid_locale(p_locale)) { - String trimmed_locale = get_trimmed_locale(p_locale); + // replaces '-' with '_' for macOS Sierra-style locales + String univ_locale = p_locale.replace("-", "_"); + + if(!is_valid_locale(univ_locale)) { + String trimmed_locale = get_trimmed_locale(univ_locale); ERR_EXPLAIN("Invalid Locale: "+trimmed_locale); ERR_FAIL_COND(!is_valid_locale(trimmed_locale)); @@ -928,7 +934,7 @@ void TranslationServer::set_locale(const String& p_locale) { locale=trimmed_locale; } else { - locale=p_locale; + locale=univ_locale; } } diff --git a/methods.py b/methods.py index 477fe4f12f..bd5409e3d4 100755 --- a/methods.py +++ b/methods.py @@ -1516,11 +1516,6 @@ def detect_visual_c_compiler_version(tools_env): return vc_chosen_compiler_str -def msvc_is_detected() : - # looks for VisualStudio env variable - # or for Visual C++ Build Tools (which is a standalone MSVC) - return os.getenv("VSINSTALLDIR") or os.getenv("VS100COMNTOOLS") or os.getenv("VS110COMNTOOLS") or os.getenv("VS120COMNTOOLS") or os.getenv("VS140COMNTOOLS"); - def precious_program(env, program, sources, **args): program = env.ProgramOriginal(program, sources, **args) diff --git a/modules/openssl/SCsub b/modules/openssl/SCsub index 3cc6f21bd2..2327cf483c 100644 --- a/modules/openssl/SCsub +++ b/modules/openssl/SCsub @@ -671,7 +671,7 @@ if (env["openssl"] != "system"): # builtin # Workaround for compilation error with GCC/Clang when -Werror is too greedy (GH-4517) import os import methods - if not (os.name=="nt" and methods.msvc_is_detected()): # not Windows and not MSVC + if not (os.name=="nt" and os.getenv("VCINSTALLDIR")): # not Windows and not MSVC env_openssl.Append(CFLAGS = ["-Wno-error=implicit-function-declaration"]) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index a5b26930be..7ae0100762 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -1,16 +1,11 @@ # -# tested on | Windows native | Linux cross-compilation -# ----------------------------+-------------------+--------------------------- -# MSVS C++ 2010 Express | WORKS | n/a +# tested on | Windows native | Linux cross-compilation +# ----------------------------+-------------------+--------------------------- # Visual C++ Build Tools 2015 | WORKS | n/a -# Mingw-w64 | WORKS | WORKS -# Mingw-w32 | WORKS | WORKS -# MinGW | WORKS | untested -# -##### -# Notes about MSVS C++ : -# -# - MSVC2010-Express compiles to 32bits only. +# MSVS C++ 2010 Express | WORKS | n/a +# Mingw-w64 | WORKS | WORKS +# Mingw-w32 | WORKS | WORKS +# MinGW | WORKS | untested # ##### # Note about Visual C++ Build Tools : @@ -19,6 +14,11 @@ # http://landinghub.visualstudio.com/visual-cpp-build-tools # ##### +# Notes about MSVS C++ : +# +# - MSVC2010-Express compiles to 32bits only. +# +##### # Notes about Mingw-w64 and Mingw-w32 under Windows : # # - both can be installed using the official installer : @@ -109,7 +109,7 @@ def can_build(): if (os.name=="nt"): #building natively on windows! - if ( methods.msvc_is_detected() ): + if ( os.getenv("VCINSTALLDIR") ): return True else: print("\nMSVC not detected, attempting Mingw.") @@ -204,7 +204,7 @@ def configure(env): env.Append(CPPPATH=['#platform/windows']) env['is_mingw']=False - if (os.name=="nt" and methods.msvc_is_detected() ): + if (os.name=="nt" and os.getenv("VCINSTALLDIR") ): #build using visual studio env['ENV']['TMP'] = os.environ['TMP'] env.Append(CPPPATH=['#platform/windows/include']) diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 6b43425edc..f942f15ed0 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -186,15 +186,17 @@ void FileDialog::_action_pressed() { hide(); }else if (mode==MODE_OPEN_ANY || mode==MODE_OPEN_DIR) { - String path=dir_access->get_current_dir(); - /*if (tree->get_selected()) { - Dictionary d = tree->get_selected()->get_metadata(0); + + path=path.replace("\\","/"); + + if (TreeItem* item = tree->get_selected()) { + Dictionary d = item->get_metadata(0); if (d["dir"]) { - path=path+"/"+String(d["name"]); + path=path.plus_file(d["name"]); } - }*/ - path=path.replace("\\","/"); + } + emit_signal("dir_selected",path); hide(); } @@ -348,18 +350,18 @@ void FileDialog::update_file_list() { files.sort_custom<NoCaseComparator>(); while(!dirs.empty()) { + String& dir_name = dirs.front()->get(); + TreeItem *ti=tree->create_item(root); + ti->set_text(0,dir_name+"/"); + ti->set_icon(0,folder); - if (dirs.front()->get()!=".") { - TreeItem *ti=tree->create_item(root); - ti->set_text(0,dirs.front()->get()+"/"); - ti->set_icon(0,folder); - Dictionary d; - d["name"]=dirs.front()->get(); - d["dir"]=true; - ti->set_metadata(0,d); - } - dirs.pop_front(); + Dictionary d; + d["name"]=dir_name; + d["dir"]=true; + + ti->set_metadata(0,d); + dirs.pop_front(); } dirs.clear(); diff --git a/tools/editor/editor_file_dialog.cpp b/tools/editor/editor_file_dialog.cpp index b8abd1d32c..90289a275e 100644 --- a/tools/editor/editor_file_dialog.cpp +++ b/tools/editor/editor_file_dialog.cpp @@ -336,15 +336,21 @@ void EditorFileDialog::_action_pressed() { hide(); }else if (mode==MODE_OPEN_ANY || mode==MODE_OPEN_DIR) { - String path=dir_access->get_current_dir(); - /*if (tree->get_selected()) { - Dictionary d = tree->get_selected()->get_metadata(0); - if (d["dir"]) { - path=path+"/"+String(d["name"]); - } - }*/ + path=path.replace("\\","/"); + + for(int i=0;i<item_list->get_item_count();i++) { + if (item_list->is_selected(i)) { + Dictionary d=item_list->get_item_metadata(i); + if (d["dir"]) { + path=path.plus_file(d["name"]); + + break; + } + } + } + _save_to_recent(); emit_signal("dir_selected",path); hide(); @@ -571,25 +577,26 @@ void EditorFileDialog::update_file_list() { files.sort_custom<NoCaseComparator>(); while(!dirs.empty()) { + const String& dir_name=dirs.front()->get(); - if (dirs.front()->get()!=".") { - item_list->add_item(dirs.front()->get()+"/"); - if (display_mode==DISPLAY_THUMBNAILS) { + item_list->add_item(dir_name+"/"); - item_list->set_item_icon(item_list->get_item_count()-1,folder_thumbnail); - } else { + if (display_mode==DISPLAY_THUMBNAILS) { - item_list->set_item_icon(item_list->get_item_count()-1,folder); - } + item_list->set_item_icon(item_list->get_item_count()-1,folder_thumbnail); + } else { - Dictionary d; - d["name"]=dirs.front()->get(); - d["path"]=String(); - d["dir"]=true; - item_list->set_item_metadata( item_list->get_item_count() -1, d); + item_list->set_item_icon(item_list->get_item_count()-1,folder); } - dirs.pop_front(); + Dictionary d; + d["name"]=dir_name; + d["path"]=String(); + d["dir"]=true; + + item_list->set_item_metadata( item_list->get_item_count() -1, d); + + dirs.pop_front(); } dirs.clear(); diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 56f10ff7f8..7ff2728310 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -81,7 +81,10 @@ void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { _tool_selected(TOOL_DUPLICATE); } else if (ED_IS_SHORTCUT("scene_tree/add_script", p_event)) { - _tool_selected(TOOL_SCRIPT); + _tool_selected(TOOL_CREATE_SCRIPT); + } + else if (ED_IS_SHORTCUT("scene_tree/load_script", p_event)) { + _tool_selected(TOOL_LOAD_SCRIPT); } else if (ED_IS_SHORTCUT("scene_tree/move_up", p_event)) { _tool_selected(TOOL_MOVE_UP); @@ -266,6 +269,24 @@ void SceneTreeDock::_replace_with_branch_scene(const String& p_file,Node* base) scene_tree->set_selected(instanced_scene); } + +void SceneTreeDock::_file_selected(String p_file) { + RES p_script = ResourceLoader::load(p_file, "Script"); + if (p_script.is_null()) { + accept->get_ok()->set_text(TTR("Ugh")); + accept->set_text(vformat(TTR("Error loading script from %s"), p_file)); + accept->popup_centered_minsize(); + return; + } + + Node *selected = scene_tree->get_selected(); + if (!selected) + return; + selected->set_script(p_script.get_ref_ptr()); + editor->push_item(p_script.operator->()); + file_dialog->hide(); +} + bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) { int childCount = p_desired_node->get_child_count(); @@ -358,7 +379,22 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { //groups_editor->set_current(current); //groups_editor->popup_centered_ratio(); } break; - case TOOL_SCRIPT: { + case TOOL_LOAD_SCRIPT: { + Node *selected = scene_tree->get_selected(); + if (!selected) + break; + + file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + + List<String> extensions; + ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); + file_dialog->clear_filters(); + for (List<String>::Element *E = extensions.front(); E; E = E->next()) + file_dialog->add_filter("*." + E->get() + " ; " + E->get().to_upper()); + + file_dialog->popup_centered_ratio(); + } break; + case TOOL_CREATE_SCRIPT: { Node *selected = scene_tree->get_selected(); if (!selected) @@ -672,6 +708,7 @@ void SceneTreeDock::_notification(int p_what) { button_add->set_icon(get_icon("Add","EditorIcons")); button_instance->set_icon(get_icon("Instance","EditorIcons")); button_create_script->set_icon(get_icon("Script","EditorIcons")); + button_load_script->set_icon(get_icon("Script", "EditorIcons")); filter_icon->set_texture(get_icon("Zoom","EditorIcons")); @@ -1303,8 +1340,10 @@ void SceneTreeDock::_selection_changed() { if (selection_size==1 && EditorNode::get_singleton()->get_editor_selection()->get_selection().front()->key()->get_script().is_null()) { button_create_script->show(); + button_load_script->show(); } else { button_create_script->hide(); + button_load_script->hide(); } //tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2); @@ -1775,7 +1814,8 @@ void SceneTreeDock::_tree_rmb(const Vector2& p_menu_pos) { //menu->add_icon_item(get_icon("Groups","EditorIcons"),TTR("Edit Groups"),TOOL_GROUP); //menu->add_icon_item(get_icon("Connect","EditorIcons"),TTR("Edit Connections"),TOOL_CONNECT); menu->add_separator(); - menu->add_icon_shortcut(get_icon("Script","EditorIcons"),ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_SCRIPT); + menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_CREATE_SCRIPT); + menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/load_script"), TOOL_LOAD_SCRIPT); menu->add_separator(); } @@ -1834,7 +1874,7 @@ void SceneTreeDock::_focus_node() { void SceneTreeDock::open_script_dialog(Node* p_for_node) { scene_tree->set_selected(p_for_node,false); - _tool_selected(TOOL_SCRIPT); + _tool_selected(TOOL_CREATE_SCRIPT); } void SceneTreeDock::_bind_methods() { @@ -1862,6 +1902,7 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tree_rmb"),&SceneTreeDock::_tree_rmb); ObjectTypeDB::bind_method(_MD("_filter_changed"),&SceneTreeDock::_filter_changed); ObjectTypeDB::bind_method(_MD("_focus_node"),&SceneTreeDock::_focus_node); + ObjectTypeDB::bind_method(_MD("_file_selected"), &SceneTreeDock::_file_selected); ObjectTypeDB::bind_method(_MD("instance"),&SceneTreeDock::instance); @@ -1886,6 +1927,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec ED_SHORTCUT("scene_tree/instance_scene",TTR("Instance Child Scene")); ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); ED_SHORTCUT("scene_tree/add_script", TTR("Add Script")); + ED_SHORTCUT("scene_tree/load_script", TTR("Load Script")); ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KEY_MASK_CMD | KEY_UP); ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KEY_MASK_CMD | KEY_DOWN); ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"),KEY_MASK_CMD | KEY_D); @@ -1922,12 +1964,19 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec tb = memnew( ToolButton ); - tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_SCRIPT, false)); + tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_CREATE_SCRIPT, false)); tb->set_tooltip(TTR("Create a new script for the selected node.")); tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/add_script")); filter_hbc->add_child(tb); button_create_script=tb; + tb = memnew(ToolButton); + tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_LOAD_SCRIPT, false)); + tb->set_tooltip(TTR("Load a script for the selected node.")); + tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/load_script")); + filter_hbc->add_child(tb); + button_load_script = tb; + scene_tree = memnew( SceneTreeEditor(false,true,true )); vbc->add_child(scene_tree); @@ -1955,6 +2004,11 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec add_child(create_dialog); create_dialog->connect("create",this,"_create"); + file_dialog = memnew(EditorFileDialog); + add_child(file_dialog); + file_dialog->hide(); + file_dialog->connect("file_selected", this, "_file_selected"); + //groups_editor = memnew( GroupsEditor ); //add_child(groups_editor); //groups_editor->set_undo_redo(&editor_data->get_undo_redo()); diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index 8933a03883..ddd28cfd2d 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -58,7 +58,8 @@ class SceneTreeDock : public VBoxContainer { TOOL_REPLACE, TOOL_CONNECT, TOOL_GROUP, - TOOL_SCRIPT, + TOOL_CREATE_SCRIPT, + TOOL_LOAD_SCRIPT, TOOL_MOVE_UP, TOOL_MOVE_DOWN, TOOL_DUPLICATE, @@ -75,10 +76,12 @@ class SceneTreeDock : public VBoxContainer { int current_option; CreateDialog *create_dialog; + EditorFileDialog *file_dialog; ToolButton *button_add; ToolButton *button_instance; ToolButton *button_create_script; + ToolButton *button_load_script; SceneTreeEditor *scene_tree; @@ -155,6 +158,7 @@ class SceneTreeDock : public VBoxContainer { void _perform_instance_scenes(const Vector<String>& p_files,Node* parent,int p_pos); void _replace_with_branch_scene(const String& p_file,Node* base); + void _file_selected(String p_file); protected: void _notification(int p_what); |