diff options
84 files changed, 2886 insertions, 1990 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index f951237971..94d9e22a1e 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -708,6 +708,15 @@ _OS::ScreenOrientation _OS::get_screen_orientation() const { return ScreenOrientation(OS::get_singleton()->get_screen_orientation()); } +void _OS::set_keep_screen_on(bool p_enabled) { + + OS::get_singleton()->set_keep_screen_on(p_enabled); +} + +bool _OS::is_keep_screen_on() const { + + return OS::get_singleton()->is_keep_screen_on(); +} String _OS::get_system_dir(SystemDir p_dir) const { @@ -775,6 +784,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation); ObjectTypeDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation); + ObjectTypeDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on); + ObjectTypeDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on); ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 62572d7761..e03657f3a0 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -262,6 +262,9 @@ public: void set_screen_orientation(ScreenOrientation p_orientation); ScreenOrientation get_screen_orientation() const; + void set_keep_screen_on(bool p_enabled); + bool is_keep_screen_on() const; + void set_time_scale(float p_scale); float get_time_scale(); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 796dcde3d0..c008c3f9a4 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -725,7 +725,8 @@ Error ResourceInteractiveLoaderBinary::poll(){ } } else { - path=res_path; + if (!ResourceCache::has(res_path)) + path=res_path; } uint64_t offset = internal_resources[s].offset; diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp index 74813d24fa..8c8d79948a 100644 --- a/core/io/resource_format_xml.cpp +++ b/core/io/resource_format_xml.cpp @@ -1570,7 +1570,9 @@ Error ResourceInteractiveLoaderXML::poll() { if (main) { f->close(); resource=res; - resource->set_path(res_path); + if (!ResourceCache::has(res_path)) { + resource->set_path(res_path); + } error=ERR_FILE_EOF; return error; diff --git a/core/os/os.cpp b/core/os/os.cpp index be447d511e..e93038f854 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -112,6 +112,14 @@ float OS::get_target_fps() const { return _target_fps; } +void OS::set_keep_screen_on(bool p_enabled) { + _keep_screen_on=p_enabled; +} + +bool OS::is_keep_screen_on() const { + return _keep_screen_on; +} + void OS::set_low_processor_usage_mode(bool p_enabled) { low_processor_usage_mode=p_enabled; @@ -520,6 +528,7 @@ OS::OS() { frames_drawn=0; singleton=this; ips=60; + _keep_screen_on=true; // set default value to true, because this had been true before godot 2.0. low_processor_usage_mode=false; _verbose_stdout=false; _frame_delay=0; diff --git a/core/os/os.h b/core/os/os.h index 83ea2c2101..bc3fad302a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -46,6 +46,7 @@ class OS { String _custom_level; List<String> _cmdline; int ips; + bool _keep_screen_on; bool low_processor_usage_mode; bool _verbose_stdout; String _local_clipboard; @@ -180,7 +181,8 @@ public: virtual float get_frames_per_second() const { return _fps; }; - + virtual void set_keep_screen_on(bool p_enabled); + virtual bool is_keep_screen_on() const; virtual void set_low_processor_usage_mode(bool p_enabled); virtual bool is_in_low_processor_usage_mode() const; diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 4a1e437694..4c8e57eca7 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -19503,6 +19503,19 @@ returns:= "username=user&password=pass" <description> </description> </method> + <method name="set_keep_screen_on"> + <argument index="0" name="enabled" type="bool"> + </argument> + <description> + Set keep screen on if true, or goes to sleep by device setting if false. (for Android/iOS) + </description> + </method> + <method name="is_keep_screen_on" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> <method name="set_iterations_per_second"> <argument index="0" name="iterations_per_second" type="int"> </argument> diff --git a/main/main.cpp b/main/main.cpp index 8319c415fc..19fe037613 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -707,6 +707,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas GLOBAL_DEF("display/test_width",0); GLOBAL_DEF("display/test_height",0); OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false); + OS::get_singleton()->_keep_screen_on=GLOBAL_DEF("display/keep_screen_on",true); if (rtm==-1) { rtm=GLOBAL_DEF("render/thread_model",OS::RENDER_THREAD_SAFE); if (rtm>=1) //hack for now diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index cbcb08334a..71c56aba01 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -852,7 +852,6 @@ void GDTokenizerText::_advance() { {TK_OP_AND,"and"}, //func {TK_PR_FUNCTION,"func"}, - {TK_PR_FUNCTION,"function"}, {TK_PR_CLASS,"class"}, {TK_PR_EXTENDS,"extends"}, {TK_PR_ONREADY,"onready"}, diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index c6bc6a6943..1f208f8fb6 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -113,6 +113,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC private boolean use_immersive=false; private boolean mStatePaused; private int mState; + private boolean keep_screen_on=true; private void setState(int newState) { if (mState != newState) { @@ -259,7 +260,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC mView = new GodotView(getApplication(),io,use_gl2,use_32_bits, this); layout.addView(mView,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); - mView.setKeepScreenOn(true); + setKeepScreenOn(GodotLib.getGlobal("display/keep_screen_on").equals("True")); edittext.setView(mView); io.setEdit(edittext); @@ -270,7 +271,19 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC layout.addView(adLayout); } - + + public void setKeepScreenOn(final boolean p_enabled) { + keep_screen_on = p_enabled; + if (mView != null){ + runOnUiThread(new Runnable() { + @Override + public void run() { + mView.setKeepScreenOn(p_enabled); + } + }); + } + } + private static Godot _self; public static Godot getInstance(){ @@ -385,8 +398,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC super.onCreate(icicle); _self = this; Window window = getWindow(); - window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON - | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + //window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //check for apk expansion API diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index 459cf4c994..75c1d78151 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -671,7 +671,7 @@ static jmethodID _playVideo=0; static jmethodID _isVideoPlaying=0; static jmethodID _pauseVideo=0; static jmethodID _stopVideo=0; - +static jmethodID _setKeepScreenOn=0; static void _gfx_init_func(void* ud, bool gl2) { @@ -765,6 +765,11 @@ static void _stop_video() { env->CallVoidMethod(godot_io, _stopVideo); } +static void _set_keep_screen_on(bool p_enabled) { + JNIEnv* env = ThreadAndroid::get_env(); + env->CallVoidMethod(_godot_instance, _setKeepScreenOn, p_enabled); +} + JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv * env, jobject obj, jobject activity,jboolean p_need_reload_hook, jobjectArray p_cmdline,jobject p_asset_manager) { __android_log_print(ANDROID_LOG_INFO,"godot","**INIT EVENT! - %p\n",env); @@ -801,6 +806,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv * e godot_io=gob; _on_video_init = env->GetMethodID(cls, "onVideoInit", "(Z)V"); + _setKeepScreenOn = env->GetMethodID(cls,"setKeepScreenOn","(Z)V"); jclass clsio = env->FindClass("org/godotengine/godot/Godot"); if (cls) { @@ -863,7 +869,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv * e __android_log_print(ANDROID_LOG_INFO,"godot","CMDLINE LEN %i - APK EXPANSION %I\n",cmdlen,int(use_apk_expansion)); - os_android = new OS_Android(_gfx_init_func,env,_open_uri,_get_data_dir,_get_locale, _get_model,_show_vk, _hide_vk,_set_screen_orient,_get_unique_id, _get_system_dir, _play_video,_is_video_playing, _pause_video, _stop_video,use_apk_expansion); + os_android = new OS_Android(_gfx_init_func,env,_open_uri,_get_data_dir,_get_locale, _get_model,_show_vk, _hide_vk,_set_screen_orient,_get_unique_id, _get_system_dir, _play_video,_is_video_playing, _pause_video, _stop_video, _set_keep_screen_on, use_apk_expansion); os_android->set_need_reload_hooks(p_need_reload_hook); char wd[500]; diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 207e4499bc..03177317af 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -302,6 +302,14 @@ void OS_Android::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) p_list->push_back(default_videomode); } +void OS_Android::set_keep_screen_on(bool p_enabled) { + OS::set_keep_screen_on(p_enabled); + + if (set_keep_screen_on_func) { + set_keep_screen_on_func(p_enabled); + } +} + Size2 OS_Android::get_window_size() const { return Vector2(default_videomode.width,default_videomode.height); @@ -734,7 +742,7 @@ void OS_Android::set_context_is_16_bits(bool p_is_16) { rasterizer->set_force_16_bits_fbo(p_is_16); } -OS_Android::OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id,GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func,bool p_use_apk_expansion) { +OS_Android::OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id,GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, bool p_use_apk_expansion) { use_apk_expansion=p_use_apk_expansion; @@ -767,6 +775,7 @@ OS_Android::OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFu hide_virtual_keyboard_func = p_hide_vk; set_screen_orientation_func=p_screen_orient; + set_keep_screen_on_func = p_set_keep_screen_on_func; use_reload_hooks=false; } diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 3e42db8fb1..1ae42e9cc7 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -73,6 +73,7 @@ typedef void (*VideoPlayFunc)(const String&); typedef bool (*VideoIsPlayingFunc)(); typedef void (*VideoPauseFunc)(); typedef void (*VideoStopFunc)(); +typedef void (*SetKeepScreenOnFunc)(bool p_enabled); class OS_Android : public OS_Unix { public: @@ -132,6 +133,7 @@ private: VideoIsPlayingFunc video_is_playing_func; VideoPauseFunc video_pause_func; VideoStopFunc video_stop_func; + SetKeepScreenOnFunc set_keep_screen_on_func; public: @@ -175,7 +177,9 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; - + + virtual void set_keep_screen_on(bool p_enabled); + virtual Size2 get_window_size() const; virtual String get_name(); @@ -228,7 +232,7 @@ public: virtual void native_video_pause(); virtual void native_video_stop(); - OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id,GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func,bool p_use_apk_expansion); + OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id,GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, bool p_use_apk_expansion); ~OS_Android(); }; diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index 8a3dfe0623..e90a16a684 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -57,6 +57,7 @@ #endif Error _shell_open(String); +void _set_keep_screen_on(bool p_enabled); Error _shell_open(String p_uri) { NSString* url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()]; @@ -70,6 +71,10 @@ Error _shell_open(String p_uri) { return OK; }; +void _set_keep_screen_on(bool p_enabled) { + [[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)p_enabled]; +}; + @implementation AppDelegate @synthesize window; @@ -212,8 +217,8 @@ static int frame_count = 0; [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; // disable idle timer - application.idleTimerDisabled = YES; - + //application.idleTimerDisabled = YES; + //Create a full-screen window window = [[UIWindow alloc] initWithFrame:rect]; //window.autoresizesSubviews = YES; @@ -238,6 +243,7 @@ static int frame_count = 0; view_controller.view = glView; window.rootViewController = view_controller; + _set_keep_screen_on(bool(GLOBAL_DEF("display/set_keep_screen_on",true)) ? YES : NO); glView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink",true)) ? YES : NO; printf("cadisaplylink: %d", glView.useCADisplayLink); glView.animationInterval = 1.0 / kRenderingFrequency; diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index b60da43374..ec62cb5c26 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -454,6 +454,7 @@ bool OSIPhone::has_virtual_keyboard() const { extern void _show_keyboard(String p_existing); extern void _hide_keyboard(); extern Error _shell_open(String p_uri); +extern void _set_keep_screen_on(bool p_enabled); void OSIPhone::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) { _show_keyboard(p_existing_text); @@ -467,6 +468,10 @@ Error OSIPhone::shell_open(String p_uri) { return _shell_open(p_uri); }; +void OSIPhone::set_keep_screen_on(bool p_enabled) { + OS::set_keep_screen_on(p_enabled); + _set_keep_screen_on(p_enabled); +}; void OSIPhone::set_cursor_shape(CursorShape p_shape) { diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 631c9d6452..abe797fed1 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -166,6 +166,8 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; + + virtual void set_keep_screen_on(bool p_enabled); virtual bool can_draw() const; diff --git a/platform/windows/detect.py b/platform/windows/detect.py index c00d94a4fb..81247db388 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -339,7 +339,13 @@ def configure(env): if (env["target"]=="release"): - env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2']) + env.Append(CCFLAGS=['-ffast-math','-fomit-frame-pointer','-msse2']) + + if (env["bits"]=="64"): + env.Append(CCFLAGS=['-O3']) + else: + env.Append(CCFLAGS=['-O2']) + env.Append(LINKFLAGS=['-Wl,--subsystem,windows']) elif (env["target"]=="release_debug"): @@ -382,7 +388,7 @@ def configure(env): #'d3dx9d' env.Append(CPPFLAGS=['-DMINGW_ENABLED']) - env.Append(LINKFLAGS=['-g']) + #env.Append(LINKFLAGS=['-g']) # resrc env['is_mingw']=True diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 7ae87b881c..179d1f451a 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -223,6 +223,14 @@ void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vect Size2 s=p_sc; Vector2 offset = p_offset; + if (s.y > s.x) { + if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose)) + offset.y += s.y - s.x; + } else if (s.y < s.x) { + if ((p_cell.flip_v && (p_cell.flip_h || p_cell.transpose)) || (p_cell.flip_h && !p_cell.transpose)) + offset.x += s.x - s.y; + } + if (p_cell.transpose) { SWAP(xform.elements[0].x, xform.elements[0].y); SWAP(xform.elements[1].x, xform.elements[1].y); @@ -376,13 +384,28 @@ void TileMap::_update_dirty_quadrants() { rect.pos=offset.floor(); rect.size=s; + if (rect.size.y > rect.size.x) { + if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) + tile_ofs.y += rect.size.y - rect.size.x; + } else if (rect.size.y < rect.size.x) { + if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) + tile_ofs.x += rect.size.x - rect.size.y; + } + /* rect.size.x+=fp_adjust; rect.size.y+=fp_adjust;*/ - if (c.flip_h) + if (c.transpose) + SWAP(tile_ofs.x, tile_ofs.y); + + if (c.flip_h) { rect.size.x=-rect.size.x; - if (c.flip_v) + tile_ofs.x=-tile_ofs.x; + } + if (c.flip_v) { rect.size.y=-rect.size.y; + tile_ofs.y=-tile_ofs.y; + } Vector2 center_ofs; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 7d6c986d96..8685ec1c99 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -28,25 +28,43 @@ /*************************************************************************/ #include "color_picker.h" +#include "scene/gui/separator.h" +#include "scene/main/viewport.h" +#include "os/os.h" +#include "os/input.h" +#include "os/keyboard.h" + +void update_material(Ref<CanvasItemMaterial>mat,const Color& p_color) { + if (!mat.is_valid()) + return; + Ref<Shader> sdr = mat->get_shader(); + if (!sdr.is_valid()) + return; - + mat->set_shader_param("R",p_color.r); + mat->set_shader_param("G",p_color.g); + mat->set_shader_param("B",p_color.b); + mat->set_shader_param("H",p_color.get_h()); + mat->set_shader_param("S",p_color.get_s()); + mat->set_shader_param("V",p_color.get_v()); + mat->set_shader_param("A",p_color.a); +} void ColorPicker::_notification(int p_what) { switch(p_what) { case NOTIFICATION_THEME_CHANGED: { - + uv_material->set_shader(get_shader("uv_editor")); + w_material->set_shader(get_shader("w_editor")); + update_material(uv_material,color); + update_material(w_material,color); _update_controls(); } break; -/* case NOTIFICATION_DRAW: { - - int w = get_constant("color_width"); - int h = ms.height; - VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(0,0,w,h),color); - - } break;*/ + case NOTIFICATION_ENTER_TREE: { + btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); + } } } @@ -64,10 +82,16 @@ void ColorPicker::_update_controls() { } - void ColorPicker::set_color(const Color& p_color) { color=p_color; + h=color.get_h(); + s=color.get_s(); + v=color.get_v(); + update_material(uv_material, color); + update_material(w_material, color); + uv_edit->get_child(0)->cast_to<Control>()->update(); + w_edit->get_child(0)->cast_to<Control>()->update(); _update_color(); } @@ -77,7 +101,7 @@ void ColorPicker::set_edit_alpha(bool p_show) { edit_alpha=p_show; _update_controls(); _update_color(); - color_box->update(); + sample->update(); } bool ColorPicker::is_editing_alpha() const { @@ -90,35 +114,17 @@ void ColorPicker::_value_changed(double) { if (updating) return; - switch(mode) { - - case MODE_RGB: { - - for(int i=0;i<4;i++) { - color.components[i] = scroll[i]->get_val() / 255.0; - } - - } break; - case MODE_HSV: { - - color.set_hsv( CLAMP(scroll[0]->get_val()/359,0,0.9972), scroll[1]->get_val()/100, scroll[2]->get_val()/100 ); - color.a=scroll[3]->get_val()/100.0; - - } break; - case MODE_RAW: { - - for(int i=0;i<4;i++) { - color.components[i] = scroll[i]->get_val(); - } - - } break; - + for(int i=0;i<3;i++) { + color.components[i] = scroll[i]->get_val()/(raw_mode_enabled?1.0:255.0); } + color.components[3] = scroll[3]->get_val()/255.0; + update_material(uv_material,color); + update_material(w_material,color); html->set_text(color.to_html(edit_alpha && color.a<1)); - color_box->update(); + sample->update(); emit_signal("color_changed",color); @@ -138,144 +144,325 @@ void ColorPicker::_update_color() { updating=true; - switch(mode) { - - case MODE_RAW: { - - static const char*_lt[4]={"R","G","B","A"}; - - for(int i=0;i<4;i++) { - scroll[i]->set_max(255); - scroll[i]->set_step(0.01); - scroll[i]->set_val(color.components[i]); - labels[i]->set_text(_lt[i]); - } - } break; - case MODE_RGB: { - - static const char*_lt[4]={"R","G","B","A"}; - - for(int i=0;i<4;i++) { - scroll[i]->set_max(255); - scroll[i]->set_step(1); - scroll[i]->set_val(color.components[i]*255); - labels[i]->set_text(_lt[i]); - } - - } break; - case MODE_HSV: { - - static const char*_lt[4]={"H","S","V","A"}; + for(int i=0;i<4;i++) { + scroll[i]->set_max(255); + scroll[i]->set_step(0.01); + if (raw_mode_enabled && i != 3) + scroll[i]->set_val(color.components[i]); + else + scroll[i]->set_val(color.components[i]*255); + } - for(int i=0;i<4;i++) { - labels[i]->set_text(_lt[i]); - } + html->set_text(color.to_html(edit_alpha && color.a<1)); - scroll[0]->set_max(359); - scroll[0]->set_step(0.01); - scroll[0]->set_val( color.get_h()*359 ); + sample->update(); + updating=false; +} - scroll[1]->set_max(100); - scroll[1]->set_step(0.01); - scroll[1]->set_val( color.get_s()*100 ); +void ColorPicker::_update_presets() +{ + Size2 size=bt_add_preset->get_size(); + preset->set_custom_minimum_size(Size2(size.width*presets.size(),size.height)); + Image i(size.x*presets.size(),size.y, false, Image::FORMAT_RGB); + for (int y=0;y<size.y;y++) + for (int x=0;x<size.x*presets.size();x++) + i.put_pixel(x,y,presets[(int)x/size.x]); + Ref<ImageTexture> t; + t.instance(); + t->create_from_image(i); + preset->set_texture(t); +} - scroll[2]->set_max(100); - scroll[2]->set_step(0.01); - scroll[2]->set_val( color.get_v()*100 ); +Color ColorPicker::get_color() const { - scroll[3]->set_max(100); - scroll[3]->set_step(0.01); - scroll[3]->set_val( color.a*100); + return color; +} - } break; +void ColorPicker::add_preset(const Color &p_color) +{ + if (presets.find(p_color)) { + presets.move_to_back(presets.find(p_color)); + } else { + presets.push_back(p_color); } + _update_presets(); + if (presets.size()==10) + bt_add_preset->hide(); +} - html->set_text(color.to_html(edit_alpha && color.a<1)); +void ColorPicker::set_raw_mode(bool p_enabled) { - color_box->update(); - updating=false; + if (raw_mode_enabled==p_enabled) + return; + raw_mode_enabled=p_enabled; + if (btn_mode->is_pressed()!=p_enabled) + btn_mode->set_pressed(p_enabled); + + _update_controls(); + _update_color(); } -Color ColorPicker::get_color() const { +bool ColorPicker::is_raw_mode() const { - return color; + return raw_mode_enabled; } +void ColorPicker::_sample_draw() { + sample->draw_rect(Rect2(Point2(),Size2(256,20)),color); +} -void ColorPicker::set_mode(Mode p_mode) { +void ColorPicker::_hsv_draw(int p_wich,Control* c) +{ + if (!c) + return; + if (p_wich==0) { + int x=c->get_size().x*color.get_s(); + int y=c->get_size().y-c->get_size().y*color.get_v(); + c->draw_line(Point2(x,0),Point2(x,c->get_size().y),color.inverted()); + c->draw_line(Point2(0,y),Point2(c->get_size().x,y),color.inverted()); + c->draw_line(Point2(x,y),Point2(x,y),Color(1,1,1),2); + } else if (p_wich==1) { + int y=c->get_size().y-c->get_size().y*color.get_h(); + Color col=Color(); + col.set_hsv(color.get_h(),1,1); + c->draw_line(Point2(0,y),Point2(c->get_size().x,y),col.inverted()); + } +} - ERR_FAIL_INDEX(p_mode,3); - mode=p_mode; - if (mode_box->get_selected()!=p_mode) - mode_box->select(p_mode); +void ColorPicker::_uv_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed) { + changing_color = true; + float x = CLAMP((float)bev.x,0,256); + float y = CLAMP((float)bev.y,0,256); + s=x/256; + v=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } else { + changing_color = false; + } + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &bev = ev.mouse_motion; + if (!changing_color) + return; + float x = CLAMP((float)bev.x,0,256); + float y = CLAMP((float)bev.y,0,256); + s=x/256; + v=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } +} - _update_controls(); - _update_color(); +void ColorPicker::_w_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed) { + changing_color = true; + h=1-((float)bev.y)/256.0; + + } else { + changing_color = false; + } + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &bev = ev.mouse_motion; + if (!changing_color) + return; + float y = CLAMP((float)bev.y,0,256); + h=1.0-y/256.0; + color.set_hsv(h,s,v,color.a); + set_color(color); + _update_color(); + emit_signal("color_changed", color); + } } -ColorPicker::Mode ColorPicker::get_mode() const { +void ColorPicker::_preset_input(const InputEvent &ev) { + if (ev.type == InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.pressed && bev.button_index==BUTTON_LEFT) { + int index = bev.x/(preset->get_size().x/presets.size()); + set_color(presets[index]); + } else if (bev.pressed && bev.button_index==BUTTON_RIGHT) { + int index = bev.x/(preset->get_size().x/presets.size()); + presets.erase(presets[index]); + _update_presets(); + bt_add_preset->show(); + } + _update_color(); + emit_signal("color_changed", color); + } else if (ev.type == InputEvent::MOUSE_MOTION) { + const InputEventMouse &mev = ev.mouse_motion; + int index = mev.x/(preset->get_size().x/presets.size()); + if (index<0 || index >= presets.size()) + return; + preset->set_tooltip("Color: #"+presets[index].to_html(presets[index].a<1)+"\n" + "LMB: Set color\n" + "RMB: Remove preset"); + } +} - return mode; +void ColorPicker::_screen_input(const InputEvent &ev) +{ + if (ev.type==InputEvent::MOUSE_BUTTON) { + const InputEventMouseButton &bev = ev.mouse_button; + if (bev.button_index==BUTTON_LEFT&&!bev.pressed) { + emit_signal("color_changed", color); + screen->hide(); + } + } else if (ev.type==InputEvent::MOUSE_MOTION) { + const InputEventMouse &mev = ev.mouse_motion; + Viewport *r=get_tree()->get_root(); + if (!r->get_rect().has_point(Point2(mev.global_x,mev.global_y))) + return; + Image img =r->get_screen_capture(); + if (!img.empty()) + last_capture=img; + r->queue_screen_capture(); + if (!last_capture.empty()) + set_color(last_capture.get_pixel(mev.global_x,mev.global_y)); + } } -void ColorPicker::_color_box_draw() { +void ColorPicker::_add_preset_pressed() { + add_preset(color); +} - color_box->draw_rect( Rect2( Point2(), color_box->get_size()), color); +void ColorPicker::_screen_pick_pressed() +{ + Viewport *r=get_tree()->get_root(); + if (!screen) { + screen=memnew( Control ); + r->add_child(screen); + screen->set_area_as_parent_rect(); + screen->connect("input_event",this,"_screen_input"); + } + screen->raise(); + screen->show(); + r->queue_screen_capture(); } void ColorPicker::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_color","color"),&ColorPicker::set_color); ObjectTypeDB::bind_method(_MD("get_color"),&ColorPicker::get_color); - ObjectTypeDB::bind_method(_MD("set_mode","mode"),&ColorPicker::set_mode); - ObjectTypeDB::bind_method(_MD("get_mode"),&ColorPicker::get_mode); + ObjectTypeDB::bind_method(_MD("set_raw_mode","mode"),&ColorPicker::set_raw_mode); + ObjectTypeDB::bind_method(_MD("is_raw_mode"),&ColorPicker::is_raw_mode); ObjectTypeDB::bind_method(_MD("set_edit_alpha","show"),&ColorPicker::set_edit_alpha); ObjectTypeDB::bind_method(_MD("is_editing_alpha"),&ColorPicker::is_editing_alpha); + ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset); ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed); ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered); - ObjectTypeDB::bind_method(_MD("_color_box_draw"),&ColorPicker::_color_box_draw); + ObjectTypeDB::bind_method(_MD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); + ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); + ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw); + ObjectTypeDB::bind_method(_MD("_hsv_draw"),&ColorPicker::_hsv_draw); + ObjectTypeDB::bind_method(_MD("_uv_input"),&ColorPicker::_uv_input); + ObjectTypeDB::bind_method(_MD("_w_input"),&ColorPicker::_w_input); + ObjectTypeDB::bind_method(_MD("_preset_input"),&ColorPicker::_preset_input); + ObjectTypeDB::bind_method(_MD("_screen_input"),&ColorPicker::_screen_input); ADD_SIGNAL( MethodInfo("color_changed",PropertyInfo(Variant::COLOR,"color"))); } +ColorPicker::ColorPicker() : + BoxContainer(true) { - - -ColorPicker::ColorPicker() { - - - //edit_alpha=false; updating=true; edit_alpha=true; + raw_mode_enabled=false; + changing_color=false; + screen=NULL; + + HBoxContainer *hb_smpl = memnew( HBoxContainer ); + btn_pick = memnew( ToolButton ); + btn_pick->connect("pressed",this,"_screen_pick_pressed"); + + sample = memnew( TextureFrame ); + sample->set_h_size_flags(SIZE_EXPAND_FILL); + sample->connect("draw",this,"_sample_draw"); + + hb_smpl->add_child(sample); + hb_smpl->add_child(btn_pick); + add_child(hb_smpl); + + HBoxContainer *hb_edit = memnew( HBoxContainer ); + + uv_edit= memnew ( TextureFrame ); + Image i(256, 256, false, Image::FORMAT_RGB); + for (int y=0;y<256;y++) + for (int x=0;x<256;x++) + i.put_pixel(x,y,Color()); + Ref<ImageTexture> t; + t.instance(); + t->create_from_image(i); + uv_edit->set_texture(t); + uv_edit->set_ignore_mouse(false); + uv_edit->set_custom_minimum_size(Size2(256,256)); + uv_edit->connect("input_event", this, "_uv_input"); + Control *c= memnew( Control ); + uv_edit->add_child(c); + c->set_area_as_parent_rect(); + c->set_stop_mouse(false); + c->set_material(memnew ( CanvasItemMaterial )); + Vector<Variant> args=Vector<Variant>(); + args.push_back(0); + args.push_back(c); + c->connect("draw",this,"_hsv_draw",args); + + add_child(hb_edit); + w_edit= memnew( TextureFrame ); + i = Image(15, 256, false, Image::FORMAT_RGB); + for (int y=0;y<256;y++) + for (int x=0;x<15;x++) + i.put_pixel(x,y,Color()); + Ref<ImageTexture> tw; + tw.instance(); + tw->create_from_image(i); + w_edit->set_texture(tw); + w_edit->set_ignore_mouse(false); + w_edit->set_custom_minimum_size(Size2(15,256)); + w_edit->connect("input_event", this, "_w_input"); + c= memnew( Control ); + w_edit->add_child(c); + c->set_area_as_parent_rect(); + c->set_stop_mouse(false); + c->set_material(memnew ( CanvasItemMaterial )); + args.clear(); + args.push_back(1); + args.push_back(c); + c->connect("draw",this,"_hsv_draw",args); + + hb_edit->add_child(uv_edit); + hb_edit->add_child(memnew( VSeparator )); + hb_edit->add_child(w_edit); VBoxContainer *vbl = memnew( VBoxContainer ); add_child(vbl); - mode_box = memnew( OptionButton ); - mode_box->add_item("RGB"); - mode_box->add_item("HSV"); - mode_box->add_item("RAW"); - mode_box->connect("item_selected",this,"set_mode"); - - color_box=memnew( Control ); - color_box->set_v_size_flags(SIZE_EXPAND_FILL); - vbl->add_child(color_box); - color_box->connect("draw",this,"_color_box_draw"); - - vbl->add_child(mode_box); - + add_child(memnew( HSeparator )); VBoxContainer *vbr = memnew( VBoxContainer ); add_child(vbr); vbr->set_h_size_flags(SIZE_EXPAND_FILL); - + const char* lt[4] = {"R","G","B","A"}; for(int i=0;i<4;i++) { HBoxContainer *hbc = memnew( HBoxContainer ); - labels[i]=memnew( Label ); + labels[i]=memnew( Label(lt[i]) ); hbc->add_child(labels[i]); scroll[i]=memnew( HSlider ); @@ -294,10 +481,14 @@ ColorPicker::ColorPicker() { vbr->add_child(hbc); - } HBoxContainer *hhb = memnew( HBoxContainer ); + + btn_mode = memnew( CheckButton ); + btn_mode->set_text("RAW Mode"); + btn_mode->connect("toggled", this, "set_raw_mode"); + hhb->add_child(btn_mode); vbr->add_child(hhb); html_num = memnew( Label ); hhb->add_child(html_num); @@ -309,11 +500,49 @@ ColorPicker::ColorPicker() { html->set_h_size_flags(SIZE_EXPAND_FILL); - mode=MODE_RGB; _update_controls(); _update_color(); updating=false; + uv_material.instance(); + Ref<Shader> s_uv = get_shader("uv_editor"); + uv_material->set_shader(s_uv); + + w_material.instance(); + + Ref<Shader> s_w = get_shader("w_editor"); + w_material->set_shader(s_w); + + uv_edit->set_material(uv_material); + w_edit->set_material(w_material); + + set_color(Color(1,1,1)); + + i.create(256,20,false,Image::FORMAT_RGB); + for (int y=0;y<20;y++) + for(int x=0;x<256;x++) + if ((x/4+y/4)%2) + i.put_pixel(x,y,Color(1,1,1)); + else + i.put_pixel(x,y,Color(0.6,0.6,0.6)); + Ref<ImageTexture> t_smpl; + t_smpl.instance(); + t_smpl->create_from_image(i); + sample->set_texture(t_smpl); + + HBoxContainer *bbc = memnew( HBoxContainer ); + add_child(bbc); + + preset = memnew( TextureFrame ); + bbc->add_child(preset); + preset->set_ignore_mouse(false); + preset->connect("input_event", this, "_preset_input"); + + bt_add_preset = memnew ( Button ); + bt_add_preset->set_icon(get_icon("add_preset")); + bt_add_preset->set_tooltip("Add current color as a preset"); + bt_add_preset->connect("pressed", this, "_add_preset_pressed"); + bbc->add_child(bt_add_preset); } @@ -331,7 +560,7 @@ void ColorPickerButton::_color_changed(const Color& p_color) { void ColorPickerButton::pressed() { - Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + Size2 ms = Size2(300, picker->get_combined_minimum_size().height+10); popup->set_pos(get_global_pos()-Size2(0,ms.height)); popup->set_size(ms); popup->popup(); @@ -347,7 +576,6 @@ void ColorPickerButton::_notification(int p_what) { } } - void ColorPickerButton::set_color(const Color& p_color){ diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 95c26a9c6f..c6c7fe537d 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -36,25 +36,29 @@ #include "scene/gui/button.h" #include "scene/gui/popup.h" #include "scene/gui/box_container.h" -#include "scene/gui/option_button.h" +#include "scene/gui/texture_frame.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/check_button.h" +#include "scene/resources/material.h" -class ColorPicker : public HBoxContainer { +class ColorPicker : public BoxContainer { - OBJ_TYPE(ColorPicker,HBoxContainer); -public: + OBJ_TYPE(ColorPicker,BoxContainer); - enum Mode { - MODE_RGB, - MODE_HSV, - MODE_RAW - }; private: - Mode mode; - - OptionButton *mode_box; - - Control *color_box; + Control *screen; + Image last_capture; + TextureFrame *uv_edit; + TextureFrame *w_edit; + TextureFrame *sample; + TextureFrame *preset; + Button *bt_add_preset; + List<Color> presets; + ToolButton *btn_pick; + CheckButton *btn_mode; + Ref<CanvasItemMaterial> uv_material; + Ref<CanvasItemMaterial> w_material; HSlider *scroll[4]; SpinBox *values[4]; Label *labels[4]; @@ -64,13 +68,25 @@ private: Size2i ms; Color color; + bool raw_mode_enabled; bool updating; + bool changing_color; + float h,s,v; void _html_entered(const String& p_html); void _value_changed(double); void _update_controls(); void _update_color(); - void _color_box_draw(); + void _update_presets(); + void _sample_draw(); + void _hsv_draw(int p_wich,Control *c); + + void _uv_input(const InputEvent& p_input); + void _w_input(const InputEvent& p_input); + void _preset_input(const InputEvent& p_input); + void _screen_input(const InputEvent& p_input); + void _add_preset_pressed(); + void _screen_pick_pressed(); protected: void _notification(int); @@ -83,15 +99,14 @@ public: void set_color(const Color& p_color); Color get_color() const; - void set_mode(Mode p_mode); - Mode get_mode() const; + void add_preset(const Color& p_color); + void set_raw_mode(bool p_enabled); + bool is_raw_mode() const; ColorPicker(); }; -VARIANT_ENUM_CAST( ColorPicker::Mode ); - class ColorPickerButton : public Button { OBJ_TYPE(ColorPickerButton,Button); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 5a8ecfeffe..90c72989bd 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -42,37 +42,6 @@ #include <stdio.h> -class TooltipPanel : public Panel { - - OBJ_TYPE(TooltipPanel,Panel) -public: - TooltipPanel() {}; - -}; - -class TooltipLabel : public Label { - - OBJ_TYPE(TooltipLabel,Label) -public: - TooltipLabel() {}; - -}; - -Control::Window::Window() { - - - mouse_focus=NULL; - mouse_focus_button=-1; - key_focus=NULL; - mouse_over=NULL; - disable_input=false; - - cancelled_input_ID=0; - tooltip=NULL; - tooltip_popup=NULL; - tooltip_label=NULL; - subwindow_order_dirty=false; -} Variant Control::edit_get_state() const { @@ -140,6 +109,11 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { data.icon_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); update(); + } else if (name.begins_with("custom_shaders/")) { + String dname = name.get_slicec('/',1); + data.shader_override.erase(dname); + notification(NOTIFICATION_THEME_CHANGED); + update(); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/',1); data.style_override.erase(dname); @@ -168,6 +142,10 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { String dname = name.get_slicec('/',1); notification(NOTIFICATION_THEME_CHANGED); add_icon_override(dname,p_value); + } else if (name.begins_with("custom_shaders/")) { + String dname = name.get_slicec('/',1); + add_shader_override(dname,p_value); + notification(NOTIFICATION_THEME_CHANGED); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/',1); add_style_override(dname,p_value); @@ -220,6 +198,10 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { String name = sname.get_slicec('/',1); r_ret= data.icon_override.has(name)?Variant(data.icon_override[name]):Variant(); + } else if (sname.begins_with("custom_shaders/")) { + String name = sname.get_slicec('/',1); + + r_ret= data.shader_override.has(name)?Variant(data.shader_override[name]):Variant(); } else if (sname.begins_with("custom_styles/")) { String name = sname.get_slicec('/',1); @@ -269,6 +251,18 @@ void Control::_get_property_list( List<PropertyInfo> *p_list) const { } { List<StringName> names; + theme->get_shader_list(get_type_name(),&names); + for(List<StringName>::Element *E=names.front();E;E=E->next()) { + + uint32_t hint= PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_CHECKABLE; + if (data.shader_override.has(E->get())) + hint|=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_CHECKED; + + p_list->push_back( PropertyInfo(Variant::OBJECT,"custom_shaders/"+E->get(),PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph",hint) ); + } + } + { + List<StringName> names; theme->get_stylebox_list(get_type_name(),&names); for(List<StringName>::Element *E=names.front();E;E=E->next()) { @@ -325,19 +319,6 @@ Control *Control::get_parent_control() const { return data.parent; } -void Control::_input_text(const String& p_text) { - - if (!window) - return; - if (window->key_focus) - window->key_focus->call("set_text",p_text); - -} - -void Control::_gui_input(const InputEvent& p_event) { - - _window_input_event(p_event); -} void Control::_resize(const Size2& p_size) { @@ -353,79 +334,12 @@ void Control::_notification(int p_notification) { case NOTIFICATION_ENTER_TREE: { - if (data.window==this) { - - window = memnew( Window ); - add_to_group("_vp_gui_input"+itos(get_viewport()->get_instance_ID())); - add_to_group("windows"); - - window->tooltip_timer = memnew( Timer ); - add_child(window->tooltip_timer); - window->tooltip_timer->force_parent_owned(); - window->tooltip_timer->set_wait_time( GLOBAL_DEF("display/tooltip_delay",0.7)); - window->tooltip_timer->connect("timeout",this,"_window_show_tooltip"); - window->tooltip=NULL; - window->tooltip_popup = memnew( TooltipPanel ); - add_child(window->tooltip_popup); - window->tooltip_popup->force_parent_owned(); - window->tooltip_label = memnew( TooltipLabel ); - window->tooltip_popup->add_child(window->tooltip_label); - window->tooltip_popup->set_as_toplevel(true); - window->tooltip_popup->hide(); - window->drag_attempted=false; - window->drag_preview=NULL; - - if (get_tree()->is_editor_hint()) { - - Node *n = this; - while(n) { - - if (n->has_meta("_editor_disable_input")) { - window->disable_input=true; - break; - } - n=n->get_parent(); - } - } - - } else { - window=NULL; - } - _size_changed(); } break; case NOTIFICATION_EXIT_TREE: { - if (data.window) { - - if (data.window->window->mouse_focus == this) - data.window->window->mouse_focus=NULL; - if (data.window->window->key_focus == this) - data.window->window->key_focus=NULL; - if (data.window->window->mouse_over == this) - data.window->window->mouse_over=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; - } - - if (window) { - - remove_from_group("_vp_gui_input"+itos(get_viewport()->get_instance_ID())); - remove_from_group("windows"); - if (window->tooltip_timer) - memdelete(window->tooltip_timer); - window->tooltip_timer=NULL; - window->tooltip=NULL; - if (window->tooltip_popup) - memdelete(window->tooltip_popup); - window->tooltip_popup=NULL; - - memdelete(window); - window=NULL; - - } - + get_viewport()->_gui_remove_control(this); } break; @@ -433,112 +347,94 @@ void Control::_notification(int p_notification) { case NOTIFICATION_ENTER_CANVAS: { - data.window=NULL; - data.viewport=NULL; - data.parent=NULL; - - Control *_window=this; - bool gap=false; - bool gap_valid=true; - bool window_found=false; + data.parent=get_parent()->cast_to<Control>(); - Node *parent=_window->get_parent(); - if (parent && parent->cast_to<Control>()) { + if (is_set_as_toplevel()) { + data.SI=get_viewport()->_gui_add_subwindow_control(this); + } else { - data.parent=parent->cast_to<Control>(); - } - Viewport *viewport=NULL; + Node *parent=this; //meh + Node *parent_control=NULL; + bool subwindow=false; - parent=this; //meh + while(parent) { - while(parent) { + parent=parent->get_parent(); - Control *c=parent->cast_to<Control>(); + if (!parent) + break; - if (!window_found && c) { - if (!gap && c!=this) { - gap_valid=false; + CanvasItem *ci =parent->cast_to<CanvasItem>(); + if (ci && ci->is_set_as_toplevel()) { + subwindow=true; + break; } - _window = c; - } - - CanvasItem *ci =parent->cast_to<CanvasItem>(); + if (parent->cast_to<Control>()) { + parent_control=parent->cast_to<Control>(); + break; + } else if (ci) { - if ((ci && ci->is_set_as_toplevel()) || !ci) { - gap=true; + } else { + break; + } } - if (parent->cast_to<CanvasLayer>()) { - window_found=true; //don't go beyond canvas layer - } - viewport =parent->cast_to<Viewport>(); - if (viewport) { - break; //no go beyond viewport either + if (parent_control) { + //do nothing, has a parent control + } else if (subwindow) { + //is a subwindow (process input before other controls for that canvas) + data.SI=get_viewport()->_gui_add_subwindow_control(this); + } else { + //is a regular root control + data.RI=get_viewport()->_gui_add_root_control(this); } - parent=parent->get_parent(); - } - - data.window=_window; - data.viewport=viewport; - data.parent_canvas_item=get_parent_item(); - - if (data.parent_canvas_item) { - - data.parent_canvas_item->connect("item_rect_changed",this,"_size_changed"); - } else if (data.viewport) { + data.parent_canvas_item=get_parent_item(); - //connect viewport - data.viewport->connect("size_changed",this,"_size_changed"); - } else { + if (data.parent_canvas_item) { + data.parent_canvas_item->connect("item_rect_changed",this,"_size_changed"); + } else { + //connect viewport + get_viewport()->connect("size_changed",this,"_size_changed"); + } } - if (gap && gap_valid && data.window!=this) { - //is a subwindow, conditions to meet subwindow status are quite complex.. - data.SI = data.window->window->subwindows.push_back(this); - data.window->window->subwindow_order_dirty=true; - - } - } break; case NOTIFICATION_EXIT_CANVAS: { - if (data.parent_canvas_item) { data.parent_canvas_item->disconnect("item_rect_changed",this,"_size_changed"); data.parent_canvas_item=NULL; - } else if (data.viewport) { - + } else if (!is_set_as_toplevel()) { //disconnect viewport - data.viewport->disconnect("size_changed",this,"_size_changed"); - } else { + get_viewport()->disconnect("size_changed",this,"_size_changed"); } if (data.MI) { - - if (data.window && data.window->window) - data.window->window->modal_stack.erase(data.MI); + get_viewport()->_gui_remove_modal_control(data.MI); data.MI=NULL; } if (data.SI) { - //erase from subwindows - if (data.window && data.window->window) - data.window->window->subwindows.erase(data.SI); + get_viewport()->_gui_remove_subwindow_control(data.SI); data.SI=NULL; } - data.viewport=NULL; - data.window=NULL; + if (data.RI) { + get_viewport()->_gui_remove_root_control(data.RI); + data.RI=NULL; + } + data.parent=NULL; + data.parent_canvas_item=NULL; } break; @@ -569,8 +465,11 @@ void Control::_notification(int p_notification) { data.parent->update(); update(); - if (data.SI && data.window) { - data.window->window->subwindow_order_dirty=true; + if (data.SI) { + get_viewport()->_gui_set_subwindow_order_dirty(); + } + if (data.RI) { + get_viewport()->_gui_set_root_order_dirty(); } } break; @@ -614,26 +513,8 @@ void Control::_notification(int p_notification) { if (!is_visible()) { - if (data.window->window->mouse_focus == this) { - data.window->window->mouse_focus=NULL; - } - if (data.window==this) { - window->drag_data=Variant(); - if (window->drag_preview) { - memdelete( window->drag_preview); - window->drag_preview=NULL; - } - } - - if (data.window->window->key_focus == this) - data.window->window->key_focus=NULL; - if (data.window->window->mouse_over == this) - data.window->window->mouse_over=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; - if (data.window->window->tooltip == this) - data.window->window->tooltip=NULL; + get_viewport()->_gui_hid_control(this); _modal_stack_remove(); minimum_size_changed(); @@ -647,10 +528,7 @@ void Control::_notification(int p_notification) { } break; case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: { - if (!window) - return; - if (window->key_focus) - window->key_focus->release_focus(); + get_viewport()->_gui_unfocus_control(this); } break; @@ -726,617 +604,30 @@ void Control::drop_data(const Point2& p_point,const Variant& p_data){ void Control::force_drag(const Variant& p_data,Control *p_control) { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); ERR_FAIL_COND(p_data.get_type()==Variant::NIL); + get_viewport()->_gui_force_drag(p_data,p_control); - - data.window->window->drag_data=p_data; - data.window->window->mouse_focus=NULL; - - if (p_control) { - data.window->set_drag_preview(p_control); - } } void Control::set_drag_preview(Control *p_control) { - ERR_FAIL_NULL(p_control); - ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); - ERR_FAIL_COND(!is_inside_tree() || !data.window); - ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent()!=NULL); - - if (data.window->window->drag_preview) { - memdelete(data.window->window->drag_preview); - } - p_control->set_as_toplevel(true); - p_control->set_pos(data.window->window->last_mouse_pos); - data.window->add_child(p_control); - if (data.window->window->drag_preview) { - memdelete( data.window->window->drag_preview ); - } - - data.window->window->drag_preview=p_control; - -} - - -Control* Control::_find_next_visible_control_at_pos(Node* p_node,const Point2& p_global,Matrix32& r_xform) const { - - return NULL; + ERR_FAIL_COND(!is_inside_tree()); + get_viewport()->_gui_set_drag_preview(p_control); } -Control* Control::_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform) { - - if (p_node->cast_to<Viewport>()) - return NULL; - - Control *c=p_node->cast_to<Control>(); - - if (c) { - // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); - } - - if (c==data.window) { - //try subwindows first!! - - c->_window_sort_subwindows(); // sort them - - for (List<Control*>::Element *E=c->window->subwindows.back();E;E=E->prev()) { - - Control *sw = E->get(); - if (!sw->is_visible()) - continue; - - Matrix32 xform; - CanvasItem *pci = sw->get_parent_item(); - if (pci) - xform=pci->get_global_transform(); - - Control *ret = _find_control_at_pos(sw,p_global,xform,r_inv_xform); - if (ret) - return ret; - - } - } - - if (p_node->is_hidden()) { - //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); - return NULL; //canvas item hidden, discard - } - - Matrix32 matrix = p_xform * p_node->get_transform(); - - if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { - - for(int i=p_node->get_child_count()-1;i>=0;i--) { - - if (p_node==data.window->window->tooltip_popup) - continue; - - CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); - if (!ci || ci->is_set_as_toplevel()) - continue; - - Control *ret=_find_control_at_pos(ci,p_global,matrix,r_inv_xform);; - if (ret) - return ret; - } - } - if (!c) - return NULL; - - matrix.affine_invert(); - - //conditions for considering this as a valid control for return - if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!window->drag_preview || (c!=window->drag_preview && !window->drag_preview->is_a_parent_of(c)))) { - r_inv_xform=matrix; - return c; - } else - return NULL; -} - -void Control::_window_cancel_input_ID(int p_input) { - - window->cancelled_input_ID=(unsigned int)p_input; -} - -void Control::_window_remove_focus() { - - if (window->key_focus) { - Node *f=window->key_focus; - window->key_focus=NULL; - f->notification( NOTIFICATION_FOCUS_EXIT,true ); - - } -} - -bool Control::window_has_modal_stack() const { - if (!data.window) - return false; - return data.window->window->modal_stack.size(); -} - bool Control::is_window_modal_on_top() const { - if (window_has_modal_stack()) - return data.window->window->modal_stack.back()->get()==this; - return false; -} - -void Control::_window_cancel_tooltip() { - - window->tooltip=NULL; - if (window->tooltip_timer) - window->tooltip_timer->stop(); - if (window->tooltip_popup) - window->tooltip_popup->hide(); - -} - -void Control::_window_show_tooltip() { - - if (!window->tooltip) { - return; - } - - String tooltip = window->tooltip->get_tooltip( window->tooltip->get_global_transform().xform_inv(window->tooltip_pos) ); - if (tooltip.length()==0) - return; // bye - - - if (!window->tooltip_label) { - return; - } - Ref<StyleBox> ttp = get_stylebox("panel","TooltipPanel"); - - window->tooltip_label->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); - window->tooltip_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); - window->tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); - window->tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); - window->tooltip_label->set_text(tooltip); - Rect2 r(window->tooltip_pos+Point2(10,10),window->tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); - Rect2 vr = get_viewport_rect(); - if (r.size.x+r.pos.x>vr.size.x) - r.pos.x=vr.size.x-r.size.x; - else if (r.pos.x<0) - r.pos.x=0; - - if (r.size.y+r.pos.y>vr.size.y) - r.pos.y=vr.size.y-r.size.y; - else if (r.pos.y<0) - r.pos.y=0; - - window->tooltip_popup->set_pos(r.pos); - window->tooltip_popup->set_size(r.size); - - window->tooltip_popup->raise(); - - window->tooltip_popup->show(); -} - - -void Control::_window_call_input(Control *p_control,const InputEvent& p_input) { - -// _block(); - - while(p_control) { - - p_control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); - if (window->key_event_accepted) - break; - p_control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); - if (p_control->is_set_as_toplevel()) { - break; - } - if (window->key_event_accepted) - break; - if (p_control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) - break; - p_control=p_control->data.parent; - } - - //_unblock(); - -} - -void Control::_window_input_event(InputEvent p_event) { - - - - if (!window) - return; - - if (window->disable_input) - return; - - if (p_event.ID==window->cancelled_input_ID) { - return; - } - if (!is_visible()) { - return; //simple and plain - } - switch(p_event.type) { - - case InputEvent::MOUSE_BUTTON: { - - - window->key_event_accepted=false; - - Point2 mpos =(get_canvas_transform()).affine_inverse().xform(Point2(p_event.mouse_button.x,p_event.mouse_button.y)); - if (p_event.mouse_button.pressed) { - - - - Size2 pos = mpos; - if (window->mouse_focus && p_event.mouse_button.button_index!=window->mouse_focus_button) { - - //do not steal mouse focus and stuff - - } else { - - - _window_sort_modal_stack(); - while (!window->modal_stack.empty()) { - - Control *top = window->modal_stack.back()->get(); - if (!top->has_point(top->get_global_transform().affine_inverse().xform(pos))) { - - if (top->data.modal_exclusive) { - //cancel event, sorry, modal exclusive EATS UP ALL - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - return; // no one gets the event if exclusive NO ONE - } - - top->notification(NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - } else { - break; - } - } - - - - Matrix32 parent_xform; - - if (data.parent_canvas_item) - parent_xform=data.parent_canvas_item->get_global_transform(); - - - - window->mouse_focus = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform); - //print_line("has mf "+itos(window->mouse_focus!=NULL)); - window->mouse_focus_button=p_event.mouse_button.button_index; - - if (!window->mouse_focus) { - break; - } - - if (p_event.mouse_button.button_index==BUTTON_LEFT) { - window->drag_accum=Vector2(); - window->drag_attempted=false; - window->drag_data=Variant(); - } - - - } - - p_event.mouse_button.global_x = pos.x; - p_event.mouse_button.global_y = pos.y; - - pos = window->focus_inv_xform.xform(pos); - p_event.mouse_button.x = pos.x; - p_event.mouse_button.y = pos.y; - -#ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { - - Array arr; - arr.push_back(window->mouse_focus->get_path()); - arr.push_back(window->mouse_focus->get_type()); - ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); - } - - /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { - - print_line(String(window->mouse_focus->get_path())+" - "+pos); - }*/ -#endif - - if (window->mouse_focus->get_focus_mode()!=FOCUS_NONE && window->mouse_focus!=window->key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { - // also get keyboard focus - window->mouse_focus->grab_focus(); - } - - - if (window->mouse_focus->can_process()) { - _window_call_input(window->mouse_focus,p_event); - } - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - window->tooltip_popup->hide(); - - } else { - - if (window->drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { - memdelete( window->drag_preview ); - window->drag_preview=NULL; - } - - if (!window->mouse_focus) { - - if (window->mouse_over && window->drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { - - Size2 pos = mpos; - pos = window->focus_inv_xform.xform(pos); - - window->mouse_over->drop_data(pos,window->drag_data); - window->drag_data=Variant(); - //change mouse accordingly - } - - break; - } - - Size2 pos = mpos; - p_event.mouse_button.global_x = pos.x; - p_event.mouse_button.global_y = pos.y; - pos = window->focus_inv_xform.xform(pos); - p_event.mouse_button.x = pos.x; - p_event.mouse_button.y = pos.y; - - if (window->mouse_focus->can_process()) { - _window_call_input(window->mouse_focus,p_event); - } - - if (p_event.mouse_button.button_index==window->mouse_focus_button) { - window->mouse_focus=NULL; - window->mouse_focus_button=-1; - } - - if (window->drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { - window->drag_data=Variant(); //always clear - } - - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - } - } break; - case InputEvent::MOUSE_MOTION: { - - window->key_event_accepted=false; - - Matrix32 localizer = (get_canvas_transform()).affine_inverse(); - Size2 pos = localizer.xform(Size2(p_event.mouse_motion.x,p_event.mouse_motion.y)); - Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); - Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); - - window->last_mouse_pos=pos; - - Control *over = NULL; - - Matrix32 parent_xform; - if (data.parent_canvas_item) - parent_xform=data.parent_canvas_item->get_global_transform(); - - // D&D - if (!window->drag_attempted && window->mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - window->drag_accum+=rel; - float len = window->drag_accum.length(); - if (len>10) { - window->drag_data=window->mouse_focus->get_drag_data(window->focus_inv_xform.xform(pos)-window->drag_accum); - if (window->drag_data.get_type()!=Variant::NIL) { - - window->mouse_focus=NULL; - } - window->drag_attempted=true; - } - } - - - if (window->mouse_focus) { - over=window->mouse_focus; - //recompute focus_inv_xform again here - - } else { - - over = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform); - } - - - if (window->drag_data.get_type()==Variant::NIL && over && !window->modal_stack.empty()) { - - Control *top = window->modal_stack.back()->get(); - if (over!=top && !top->is_a_parent_of(over)) { - - break; // don't send motion event to anything below modal stack top - } - } - - if (over!=window->mouse_over) { - - if (window->mouse_over) - window->mouse_over->notification(NOTIFICATION_MOUSE_EXIT); - - if (over) - over->notification(NOTIFICATION_MOUSE_ENTER); - - } - - window->mouse_over=over; - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_tooltip"); - - if (window->drag_preview) { - window->drag_preview->set_pos(pos); - } - - if (!over) { - OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW); - break; - } - - p_event.mouse_motion.global_x = pos.x; - p_event.mouse_motion.global_y = pos.y; - p_event.mouse_motion.speed_x=speed.x; - p_event.mouse_motion.speed_y=speed.y; - p_event.mouse_motion.relative_x=rel.x; - p_event.mouse_motion.relative_y=rel.y; - - if (p_event.mouse_motion.button_mask==0 && window->tooltip_timer) { - //nothing pressed - - bool can_tooltip=true; - - if (!window->modal_stack.empty()) { - if (window->modal_stack.back()->get()!=over && !window->modal_stack.back()->get()->is_a_parent_of(over)) - can_tooltip=false; - - } - - - if (can_tooltip) { - - window->tooltip=over; - window->tooltip_pos=(parent_xform * get_transform()).affine_inverse().xform(pos); - window->tooltip_timer->start(); - } - } - - - pos = window->focus_inv_xform.xform(pos); - - - p_event.mouse_motion.x = pos.x; - p_event.mouse_motion.y = pos.y; - - - CursorShape cursor_shape = over->get_cursor_shape(pos); - OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); - - - if (over->can_process()) { - _window_call_input(over,p_event); - } - - - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - get_tree()->set_input_as_handled(); - - - if (window->drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - /*bool can_drop =*/ over->can_drop_data(pos,window->drag_data); - //change mouse accordingly i guess - } - - } break; - case InputEvent::ACTION: - case InputEvent::JOYSTICK_BUTTON: - case InputEvent::KEY: { - - if (window->key_focus) { - - window->key_event_accepted=false; - if (window->key_focus->can_process()) { - window->key_focus->call_multilevel("_input_event",p_event); - if (window->key_focus) //maybe lost it - window->key_focus->emit_signal(SceneStringNames::get_singleton()->input_event,p_event); - } - - - if (window->key_event_accepted) { - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - break; - } - } - - - if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !window->modal_stack.empty()) { - - _window_sort_modal_stack(); - Control *top = window->modal_stack.back()->get(); - if (!top->data.modal_exclusive) { - - top->notification(NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - } - } - - - Control * from = window->key_focus ? window->key_focus : NULL; //hmm - - //keyboard focus - //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { - - if (from && p_event.is_pressed()) { - Control * next=NULL; - - if (p_event.is_action("ui_focus_next")) { - - next = from->find_next_valid_focus(); - } - - if (p_event.is_action("ui_focus_prev")) { - - next = from->find_prev_valid_focus(); - } - - if (p_event.is_action("ui_up")) { - - next = from->_get_focus_neighbour(MARGIN_TOP); - } - - if (p_event.is_action("ui_left")) { - - next = from->_get_focus_neighbour(MARGIN_LEFT); - } - - if (p_event.is_action("ui_right")) { - - next = from->_get_focus_neighbour(MARGIN_RIGHT); - } - - if (p_event.is_action("ui_down")) { - - next = from->_get_focus_neighbour(MARGIN_BOTTOM); - } - - - if (next) { - next->grab_focus(); - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); - } - } + if (!is_inside_tree()) + return false; - } break; - } + return get_viewport()->_gui_is_modal_on_top(this); } -Control *Control::get_window() const { - - return data.window; -} - -bool Control::is_window() const { - - return (is_inside_tree() && window); -} Size2 Control::get_minimum_size() const { @@ -1384,6 +675,35 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type } +Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_type) const { + if (p_type==StringName()) { + + const Ref<Shader>* sdr = data.shader_override.getptr(p_name); + if (sdr) + return *sdr; + } + + StringName type = p_type?p_type:get_type_name(); + + // try with custom themes + Control *theme_owner = data.theme_owner; + + while(theme_owner) { + + if (theme_owner->data.theme->has_shader(p_name, type)) + return data.theme_owner->data.theme->get_shader(p_name, type ); + Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL; + + if (parent) + theme_owner=parent->data.theme_owner; + else + theme_owner=NULL; + + } + + return Theme::get_default()->get_shader( p_name, type ); +} + Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { if (p_type==StringName()) { @@ -1530,7 +850,37 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } return Theme::get_default()->has_icon( p_name, type ); + +} + +bool Control::has_shader(const StringName &p_name, const StringName &p_type) const +{ + if (p_type==StringName()) { + const Ref<Shader>* sdr = data.shader_override.getptr(p_name); + if (sdr) + return true; + } + + StringName type = p_type?p_type:get_type_name(); + + // try with custom themes + Control *theme_owner = data.theme_owner; + + while(theme_owner) { + + if (theme_owner->data.theme->has_shader(p_name, type)) + return true; + Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL; + if (parent) + theme_owner=parent->data.theme_owner; + else + theme_owner=NULL; + + } + + return Theme::get_default()->has_shader( p_name, type ); + } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { @@ -1662,9 +1012,9 @@ Size2 Control::get_parent_area_size() const { if (data.parent_canvas_item) { parent_size=data.parent_canvas_item->get_item_rect().size; - } else if (data.viewport) { + } else { - parent_size=data.viewport->get_visible_rect().size; + parent_size=get_viewport()->get_visible_rect().size; } return parent_size; @@ -1732,8 +1082,8 @@ float Control::_get_parent_range(int p_idx) const { } if (data.parent_canvas_item) { return data.parent_canvas_item->get_item_rect().size[p_idx&1]; - } else if (data.viewport) { - return data.viewport->get_visible_rect().size[p_idx&1]; + } else { + return get_viewport()->get_visible_rect().size[p_idx&1]; } return 1.0; @@ -1959,10 +1309,9 @@ Rect2 Control::get_global_rect() const { } Rect2 Control::get_window_rect() const { - + ERR_FAIL_COND_V(!is_inside_tree(),Rect2()); Rect2 gr = get_global_rect(); - if (data.viewport) - gr.pos+=data.viewport->get_visible_rect().pos; + gr.pos+=get_viewport()->get_visible_rect().pos; return gr; } @@ -1996,7 +1345,14 @@ void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_ data.icon_override[p_name]=p_icon; notification(NOTIFICATION_THEME_CHANGED); update(); + +} +void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { + ERR_FAIL_COND(p_shader.is_null()); + data.shader_override[p_name]=p_shader; + notification(NOTIFICATION_THEME_CHANGED); + update(); } void Control::add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style) { @@ -2104,7 +1460,17 @@ Control *Control::find_next_valid_focus() const { } if (!next_child) { - next_child=get_window(); + + next_child=const_cast<Control*>(this);; + while(next_child) { + + if (next_child->data.SI || next_child->data.RI) + break; + next_child=next_child->get_parent_control(); + + } + + } } @@ -2222,128 +1588,69 @@ Control::FocusMode Control::get_focus_mode() const { } bool Control::has_focus() const { - return (data.window && data.window->window->key_focus==this); + return is_inside_tree() && get_viewport()->_gui_control_has_focus(this); } void Control::grab_focus() { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); - if (data.focus_mode==FOCUS_NONE) return; - - //no need for change - if (data.window->window->key_focus && data.window->window->key_focus==this) - return; - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); - data.window->window->key_focus=this; - notification(NOTIFICATION_FOCUS_ENTER); -#ifdef DEBUG_ENABLED - if (GLOBAL_DEF("debug/print_clicked_control", false)) { - print_line(String(get_path())+" - focus"); - }; -#endif - update(); + + get_viewport()->_gui_control_grab_focus(this); } void Control::release_focus() { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.window); if (!has_focus()) return; - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_window_remove_focus"); - //data.window->window->key_focus=this; - //notification(NOTIFICATION_FOCUS_ENTER); + get_viewport()->_gui_remove_focus(); update(); } bool Control::is_toplevel_control() const { - return is_inside_tree() && (!data.parent_canvas_item && !window && is_set_as_toplevel()); + return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel()); } void Control::show_modal(bool p_exclusive) { ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.SI && data.window!=this); - ERR_FAIL_COND(!data.window); + ERR_FAIL_COND(!data.SI); if (is_visible()) hide(); - ERR_FAIL_COND( data.MI ); + ERR_FAIL_COND( data.MI!=NULL ); show(); raise(); - - data.window->window->modal_stack.push_back(this); - data.MI = data.window->window->modal_stack.back(); data.modal_exclusive=p_exclusive; - if (data.window->window->key_focus) - data.modal_prev_focus_owner = data.window->window->key_focus->get_instance_ID(); - else - data.modal_prev_focus_owner=0; + data.MI=get_viewport()->_gui_show_modal(this); } -void Control::_window_sort_subwindows() { - - if (!window->subwindow_order_dirty) - return; - - - window->modal_stack.sort_custom<CComparator>(); - window->subwindows.sort_custom<CComparator>(); - - window->subwindow_order_dirty=false; - -} - -void Control::_window_sort_modal_stack() { - - window->modal_stack.sort_custom<CComparator>(); +void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { + data.modal_prev_focus_owner=p_prev; } void Control::_modal_stack_remove() { - List<Control*>::Element *next=NULL; //transfer the focus stack to the next - - - if (data.window && data.MI) { - - next = data.MI->next(); - - - data.window->window->modal_stack.erase(data.MI); - data.MI=NULL; - } - - if (data.modal_prev_focus_owner) { + ERR_FAIL_COND(!is_inside_tree()); - if (!next) { //top of stack + if (!data.MI) + return; - Object *pfo = ObjectDB::get_instance(data.modal_prev_focus_owner); - Control *pfoc = pfo->cast_to<Control>(); - if (!pfoc) - return; + get_viewport()->_gui_remove_from_modal_stack(data.MI,data.modal_prev_focus_owner); - if (!pfoc->is_inside_tree() || !pfoc->is_visible()) - return; - pfoc->grab_focus(); - } else { - - next->get()->data.modal_prev_focus_owner=data.modal_prev_focus_owner; - } + data.MI=NULL; + data.modal_prev_focus_owner=0; - data.modal_prev_focus_owner=0; - } } void Control::_propagate_theme_changed(Control *p_owner) { @@ -2381,17 +1688,11 @@ void Control::set_theme(const Ref<Theme>& p_theme) { } -void Control::_window_accept_event() { +void Control::accept_event() { - window->key_event_accepted=true; if (is_inside_tree()) - get_tree()->set_input_as_handled(); + get_viewport()->_gui_accept_event(); -} -void Control::accept_event() { - - if (is_inside_tree() && get_window()) - get_window()->_window_accept_event(); } @@ -2520,7 +1821,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin,int p_count) { if (c) { if (c->data.SI) break; - if (c==data.window) + if (c->data.RI) break; } base=base->get_parent(); @@ -2639,35 +1940,8 @@ void Control::grab_click_focus() { ERR_FAIL_COND(!is_inside_tree()); - if (data.window && data.window->window->mouse_focus) { - - Window *w=data.window->window; - if (w->mouse_focus==this) - return; - InputEvent ie; - ie.type=InputEvent::MOUSE_BUTTON; - InputEventMouseButton &mb=ie.mouse_button; - - //send unclic - - Point2 click =w->mouse_focus->get_global_transform().affine_inverse().xform(w->last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=w->mouse_focus_button; - mb.pressed=false; - w->mouse_focus->call_deferred("_input_event",ie); - + get_viewport()->_gui_grab_click_focus(this); - w->mouse_focus=this; - w->focus_inv_xform=w->mouse_focus->get_global_transform().affine_inverse(); - click =w->mouse_focus->get_global_transform().affine_inverse().xform(w->last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=w->mouse_focus_button; - mb.pressed=true; - w->mouse_focus->call_deferred("_input_event",ie); - - } } void Control::minimum_size_changed() { @@ -2716,8 +1990,7 @@ bool Control::is_stopping_mouse() const { Control *Control::get_focus_owner() const { ERR_FAIL_COND_V(!is_inside_tree(),NULL); - ERR_FAIL_COND_V(!data.window,NULL); - return data.window->window->key_focus; + return get_viewport()->_gui_get_focus_owner(); } @@ -2776,22 +2049,14 @@ Vector2 Control::get_scale() const{ void Control::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_window_input_event"),&Control::_window_input_event); - ObjectTypeDB::bind_method(_MD("_gui_input"),&Control::_gui_input); - ObjectTypeDB::bind_method(_MD("_input_text"),&Control::_input_text); + // ObjectTypeDB::bind_method(_MD("_window_resize_event"),&Control::_window_resize_event); - ObjectTypeDB::bind_method(_MD("_window_remove_focus"),&Control::_window_remove_focus); - ObjectTypeDB::bind_method(_MD("_cancel_input_ID"),&Control::_window_cancel_input_ID); - ObjectTypeDB::bind_method(_MD("_cancel_tooltip"),&Control::_window_cancel_tooltip); - ObjectTypeDB::bind_method(_MD("_window_show_tooltip"),&Control::_window_show_tooltip); ObjectTypeDB::bind_method(_MD("_size_changed"),&Control::_size_changed); ObjectTypeDB::bind_method(_MD("_update_minimum_size"),&Control::_update_minimum_size); ObjectTypeDB::bind_method(_MD("accept_event"),&Control::accept_event); ObjectTypeDB::bind_method(_MD("get_minimum_size"),&Control::get_minimum_size); ObjectTypeDB::bind_method(_MD("get_combined_minimum_size"),&Control::get_combined_minimum_size); - ObjectTypeDB::bind_method(_MD("is_window"),&Control::is_window); - ObjectTypeDB::bind_method(_MD("get_window"),&Control::get_window); ObjectTypeDB::bind_method(_MD("set_anchor","margin","anchor_mode"),&Control::set_anchor); ObjectTypeDB::bind_method(_MD("get_anchor","margin"),&Control::get_anchor); ObjectTypeDB::bind_method(_MD("set_margin","margin","offset"),&Control::set_margin); @@ -2837,8 +2102,9 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_theme","theme:Theme"),&Control::set_theme); ObjectTypeDB::bind_method(_MD("get_theme:Theme"),&Control::get_theme); - + ObjectTypeDB::bind_method(_MD("add_icon_override","name","texture:Texture"),&Control::add_icon_override); + ObjectTypeDB::bind_method(_MD("add_shader_override","name","shader:Shader"),&Control::add_shader_override); ObjectTypeDB::bind_method(_MD("add_style_override","name","stylebox:StyleBox"),&Control::add_style_override); ObjectTypeDB::bind_method(_MD("add_font_override","name","font:Font"),&Control::add_font_override); ObjectTypeDB::bind_method(_MD("add_color_override","name","color"),&Control::add_color_override); @@ -2965,15 +2231,15 @@ void Control::_bind_methods() { } Control::Control() { - data.parent=NULL; - data.window=NULL; - data.viewport=NULL; + data.parent=NULL; + data.ignore_mouse=false; data.stop_mouse=true; - window=NULL; + data.SI=NULL; data.MI=NULL; + data.RI=NULL; data.modal=false; data.theme_owner=NULL; data.modal_exclusive=false; @@ -2983,6 +2249,7 @@ Control::Control() { data.expand=1; data.pending_min_size_update=false; data.rotation=0; + data.parent_canvas_item=NULL; data.scale=Vector2(1,1); diff --git a/scene/gui/control.h b/scene/gui/control.h index 0ead632aab..ab777a6a6c 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -124,7 +124,6 @@ private: bool stop_mouse; Control *parent; - Control *window; bool modal; bool modal_exclusive; Ref<Theme> theme; @@ -134,81 +133,40 @@ private: List<Control*>::Element *MI; //modal item List<Control*>::Element *SI; + List<Control*>::Element *RI; CanvasItem *parent_canvas_item; - Viewport *viewport; - ObjectID modal_prev_focus_owner; NodePath focus_neighbour[4]; HashMap<StringName, Ref<Texture>, StringNameHasher > icon_override; + HashMap<StringName, Ref<Shader>, StringNameHasher > shader_override; HashMap<StringName, Ref<StyleBox>, StringNameHasher > style_override; HashMap<StringName, Ref<Font>, StringNameHasher > font_override; HashMap<StringName, Color, StringNameHasher > color_override; HashMap<StringName, int, StringNameHasher > constant_override; } data; - - struct Window { - // info used when this is a window - - bool key_event_accepted; - Control *mouse_focus; - int mouse_focus_button; - Control *key_focus; - Control *mouse_over; - Control *tooltip; - Panel *tooltip_popup; - Label *tooltip_label; - Point2 tooltip_pos; - Point2 last_mouse_pos; - Point2 drag_accum; - bool drag_attempted; - Variant drag_data; - Control *drag_preview; - Timer *tooltip_timer; - List<Control*> modal_stack; - unsigned int cancelled_input_ID; - Matrix32 focus_inv_xform; - bool subwindow_order_dirty; - List<Control*> subwindows; - bool disable_input; - - Window(); - }; - - Window *window; - + // used internally - Control* _find_next_visible_control_at_pos(Node* p_node,const Point2& p_global,Matrix32& r_xform) const; Control* _find_control_at_pos(CanvasItem* p_node,const Point2& p_pos,const Matrix32& p_xform,Matrix32& r_inv_xform); - void _window_sort_subwindows(); - void _window_accept_event(); - void _window_remove_focus(); - void _window_cancel_input_ID(int p_input); - void _window_sort_modal_stack(); void _window_find_focus_neighbour(const Vector2& p_dir, Node *p_at, const Point2* p_points ,float p_min,float &r_closest_dist,Control **r_closest); Control *_get_focus_neighbour(Margin p_margin,int p_count=0); - void _window_call_input(Control *p_control,const InputEvent& p_input); + float _get_parent_range(int p_idx) const; float _get_range(int p_idx) const; float _s2a(float p_val, AnchorType p_anchor,float p_range) const; float _a2s(float p_val, AnchorType p_anchor,float p_range) const; - void _modal_stack_remove(); void _propagate_theme_changed(Control *p_owner); void _change_notify_margins(); - void _window_cancel_tooltip(); - void _window_show_tooltip(); void _update_minimum_size(); void _update_scroll(); - void _gui_input(const InputEvent& p_event); //used by scene main loop - void _input_text(const String& p_text); void _resize(const Size2& p_size); void _size_changed(); @@ -217,10 +175,13 @@ private: void _set_rotation_deg(float p_rot); float _get_rotation_deg() const; +friend class Viewport; + void _modal_stack_remove(); + void _modal_set_prev_focus_owner(ObjectID p_prev); + protected: - bool window_has_modal_stack() const; - virtual void _window_input_event(InputEvent p_event); + //virtual void _window_input_event(InputEvent p_event); bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; @@ -272,8 +233,6 @@ public: bool is_window_modal_on_top() const; - bool is_window() const; - Control *get_window() const; Control *get_parent_control() const; @@ -357,18 +316,21 @@ public: /* SKINNING */ void add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon); + void add_shader_override(const StringName& p_name, const Ref<Shader>& p_shader); void add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style); void add_font_override(const StringName& p_name, const Ref<Font>& p_font); void add_color_override(const StringName& p_name, const Color& p_color); void add_constant_override(const StringName& p_name, int p_constant); Ref<Texture> get_icon(const StringName& p_name,const StringName& p_type=StringName()) const; + Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type=StringName()) const; Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const; Ref<Font> get_font(const StringName& p_name,const StringName& p_type=StringName()) const; Color get_color(const StringName& p_name,const StringName& p_type=StringName()) const; int get_constant(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_icon(const StringName& p_name,const StringName& p_type=StringName()) const; + bool has_shader(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_font(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_color(const StringName& p_name,const StringName& p_type=StringName()) const; @@ -400,7 +362,7 @@ public: Control(); ~Control(); - + }; VARIANT_ENUM_CAST(Control::AnchorType); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 03ef50c491..1f04985ec6 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -59,8 +59,6 @@ void Popup::_notification(int p_what) { void Popup::_fix_size() { - Control *window = get_window(); - ERR_FAIL_COND(!window); #if 0 Point2 pos = get_pos(); @@ -182,14 +180,12 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) { void Popup::popup_centered(const Size2& p_size) { - Control *window = get_window(); - ERR_FAIL_COND(!window); - + Point2 window_size = get_viewport_rect().size; emit_signal("about_to_show"); Rect2 rect; rect.size = p_size==Size2()?get_size():p_size; - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); + rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); set_size( rect.size ); @@ -209,13 +205,11 @@ void Popup::popup_centered(const Size2& p_size) { void Popup::popup_centered_ratio(float p_screen_ratio) { - Control *window = get_window(); - ERR_FAIL_COND(!window); emit_signal("about_to_show"); Rect2 rect; - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); + Point2 window_size = get_viewport_rect().size; rect.size = (window_size * p_screen_ratio).floor(); rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index b0d089fcf3..d22f6a0229 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -109,7 +109,7 @@ void SplitContainer::_resort() { int sep=get_constant("separation"); Ref<Texture> g = get_icon("grabber"); - if (collapsed || !dragger_visible) { + if (dragger_visibility==DRAGGER_HIDDEN_COLLAPSED) { sep=0; } else { sep=MAX(sep,vertical?g->get_height():g->get_width()); @@ -221,7 +221,7 @@ Size2 SplitContainer::get_minimum_size() const { Size2i minimum; int sep=get_constant("separation"); Ref<Texture> g = get_icon("grabber"); - sep=dragger_visible?MAX(sep,vertical?g->get_height():g->get_width()):0; + sep=(dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED)?MAX(sep,vertical?g->get_height():g->get_width()):0; for(int i=0;i<2;i++) { @@ -278,19 +278,19 @@ void SplitContainer::_notification(int p_what) { if (collapsed || (!mouse_inside && get_constant("autohide"))) return; - int sep=dragger_visible?get_constant("separation"):0; + int sep=dragger_visibility!=DRAGGER_HIDDEN_COLLAPSED?get_constant("separation"):0; Ref<Texture> tex = get_icon("grabber"); Size2 size=get_size(); if (vertical) { //draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep)); - if (dragger_visible) + if (dragger_visibility==DRAGGER_VISIBLE) draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2)); } else { //draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height)); - if (dragger_visible) + if (dragger_visibility==DRAGGER_VISIBLE) draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2)); } @@ -301,7 +301,7 @@ void SplitContainer::_notification(int p_what) { void SplitContainer::_input_event(const InputEvent& p_event) { - if (collapsed || !_getch(0) || !_getch(1) || !dragger_visible) + if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility!=DRAGGER_VISIBLE) return; if (p_event.type==InputEvent::MOUSE_BUTTON) { @@ -400,19 +400,19 @@ void SplitContainer::set_collapsed(bool p_collapsed) { } -void SplitContainer::set_dragger_visible(bool p_true) { +void SplitContainer::set_dragger_visibility(DraggerVisibility p_visibility) { - dragger_visible=p_true; + dragger_visibility=p_visibility; queue_sort(); update(); } -bool SplitContainer::is_dragger_visible() const{ +SplitContainer::DraggerVisibility SplitContainer::get_dragger_visibility() const { - - return dragger_visible; + return dragger_visibility; } + bool SplitContainer::is_collapsed() const { @@ -429,15 +429,18 @@ void SplitContainer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_collapsed","collapsed"),&SplitContainer::set_collapsed); ObjectTypeDB::bind_method(_MD("is_collapsed"),&SplitContainer::is_collapsed); - ObjectTypeDB::bind_method(_MD("set_dragger_visible","visible"),&SplitContainer::set_dragger_visible); - ObjectTypeDB::bind_method(_MD("is_dragger_visible"),&SplitContainer::is_dragger_visible); + ObjectTypeDB::bind_method(_MD("set_dragger_visibility","mode"),&SplitContainer::set_dragger_visibility); + ObjectTypeDB::bind_method(_MD("get_dragger_visibility"),&SplitContainer::get_dragger_visibility); ADD_SIGNAL( MethodInfo("dragged",PropertyInfo(Variant::INT,"offset"))); ADD_PROPERTY( PropertyInfo(Variant::INT,"split/offset"),_SCS("set_split_offset"),_SCS("get_split_offset")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/collapsed"),_SCS("set_collapsed"),_SCS("is_collapsed")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"split/dragger_visible"),_SCS("set_dragger_visible"),_SCS("is_dragger_visible")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"split/dragger_visibility",PROPERTY_HINT_ENUM,"Visible,Hidden,Hidden & Collapsed"),_SCS("set_dragger_visibility"),_SCS("get_dragger_visibility")); + BIND_CONSTANT( DRAGGER_VISIBLE ); + BIND_CONSTANT( DRAGGER_HIDDEN ); + BIND_CONSTANT( DRAGGER_HIDDEN_COLLAPSED ); } @@ -450,7 +453,7 @@ SplitContainer::SplitContainer(bool p_vertical) { vertical=p_vertical; dragging=false; collapsed=false; - dragger_visible=true; + dragger_visibility=DRAGGER_VISIBLE; } diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index c8cfa3d69b..f721d16310 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -35,7 +35,13 @@ class SplitContainer : public Container { OBJ_TYPE(SplitContainer,Container); - +public: + enum DraggerVisibility { + DRAGGER_VISIBLE, + DRAGGER_HIDDEN, + DRAGGER_HIDDEN_COLLAPSED + }; +private: bool vertical; int expand_ofs; int middle_sep; @@ -43,7 +49,7 @@ class SplitContainer : public Container { int drag_from; int drag_ofs; bool collapsed; - bool dragger_visible; + DraggerVisibility dragger_visibility; bool mouse_inside; @@ -66,8 +72,8 @@ public: void set_collapsed(bool p_collapsed); bool is_collapsed() const; - void set_dragger_visible(bool p_true); - bool is_dragger_visible() const; + void set_dragger_visibility(DraggerVisibility p_visibility); + DraggerVisibility get_dragger_visibility() const; virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()); @@ -76,6 +82,7 @@ public: SplitContainer(bool p_vertical=false); }; +VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility); class HSplitContainer : public SplitContainer { diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index a18eb1249f..8e2d6aa669 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -330,7 +330,8 @@ void SceneTree::input_text( const String& p_text ) { root_lock++; - call_group(GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"input",p_text); + call_group(GROUP_CALL_REALTIME,"_viewports","_vp_input_text",p_text); //special one for GUI, as controls use their own process check + root_lock--; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 330f855006..032fdab6bd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -43,6 +43,13 @@ #include "scene/2d/collision_object_2d.h" +#include "scene/gui/panel.h" +#include "scene/gui/label.h" +#include "scene/main/timer.h" +#include "scene/scene_string_names.h" + +#include "globals.h" + int RenderTargetTexture::get_width() const { ERR_FAIL_COND_V(!vp,0); @@ -92,8 +99,42 @@ RenderTargetTexture::RenderTargetTexture(Viewport *p_vp){ flags=0; } +///////////////////////////////////// + +class TooltipPanel : public Panel { + + OBJ_TYPE(TooltipPanel,Panel) +public: + TooltipPanel() {}; + +}; + +class TooltipLabel : public Label { + + OBJ_TYPE(TooltipLabel,Label) +public: + TooltipLabel() {}; + +}; + + +Viewport::GUI::GUI() { + + + mouse_focus=NULL; + mouse_focus_button=-1; + key_focus=NULL; + mouse_over=NULL; + + cancelled_input_ID=0; + tooltip=NULL; + tooltip_popup=NULL; + tooltip_label=NULL; + subwindow_order_dirty=false; +} +///////////////////////////////////// void Viewport::_update_stretch_transform() { if (size_override_stretch && size_override) { @@ -1223,15 +1264,25 @@ void Viewport::_make_input_local(InputEvent& ev) { } +void Viewport::_vp_input_text(const String& p_text) { + + if (gui.key_focus) { + gui.key_focus->call("set_text",p_text); + } +} void Viewport::_vp_input(const InputEvent& p_ev) { + if (disable_input) + return; + if (render_target && to_screen_rect==Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates //they are converted to viewport coordinates + InputEvent ev = p_ev; _make_input_local(ev); input(ev); @@ -1264,11 +1315,843 @@ void Viewport::warp_mouse(const Vector2& p_pos) { Input::get_singleton()->warp_mouse_pos(gpos); } + + +void Viewport::_gui_sort_subwindows() { + + if (!gui.subwindow_order_dirty) + return; + + + gui.modal_stack.sort_custom<Control::CComparator>(); + gui.subwindows.sort_custom<Control::CComparator>(); + + gui.subwindow_order_dirty=false; +} + +void Viewport::_gui_sort_modal_stack() { + + gui.modal_stack.sort_custom<Control::CComparator>(); +} + + +void Viewport::_gui_sort_roots() { + + if (!gui.roots_order_dirty) + return; + + gui.roots.sort_custom<Control::CComparator>(); + + gui.roots_order_dirty=false; +} + + +void Viewport::_gui_cancel_tooltip() { + + gui.tooltip=NULL; + if (gui.tooltip_timer) + gui.tooltip_timer->stop(); + if (gui.tooltip_popup) + gui.tooltip_popup->hide(); + +} + +void Viewport::_gui_show_tooltip() { + + if (!gui.tooltip) { + return; + } + + String tooltip = gui.tooltip->get_tooltip( gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos) ); + if (tooltip.length()==0) + return; // bye + + + if (!gui.tooltip_label) { + return; + } + Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel","TooltipPanel"); + + gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); + gui.tooltip_label->set_text(tooltip); + Rect2 r(gui.tooltip_pos+Point2(10,10),gui.tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); + Rect2 vr = gui.tooltip_label->get_viewport_rect(); + if (r.size.x+r.pos.x>vr.size.x) + r.pos.x=vr.size.x-r.size.x; + else if (r.pos.x<0) + r.pos.x=0; + + if (r.size.y+r.pos.y>vr.size.y) + r.pos.y=vr.size.y-r.size.y; + else if (r.pos.y<0) + r.pos.y=0; + + gui.tooltip_popup->set_pos(r.pos); + gui.tooltip_popup->set_size(r.size); + + gui.tooltip_popup->raise(); + + gui.tooltip_popup->show(); +} + + +void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { + +// _block(); + + while(p_control) { + + p_control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); + if (gui.key_event_accepted) + break; + if (!p_control->is_inside_tree()) + break; + p_control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); + if (!p_control->is_inside_tree() || p_control->is_set_as_toplevel()) { + break; + } + if (gui.key_event_accepted) + break; + if (p_control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) + break; + p_control=p_control->data.parent; + } + + //_unblock(); + +} + +Control* Viewport::_gui_find_control(const Point2& p_global) { + + _gui_sort_subwindows(); + + for (List<Control*>::Element *E=gui.subwindows.back();E;E=E->prev()) { + + Control *sw = E->get(); + if (!sw->is_visible()) + continue; + + Matrix32 xform; + CanvasItem *pci = sw->get_parent_item(); + if (pci) + xform=pci->get_global_transform(); + + + Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + if (ret) + return ret; + } + + for (List<Control*>::Element *E=gui.roots.back();E;E=E->prev()) { + + Control *sw = E->get(); + if (!sw->is_visible()) + continue; + + Matrix32 xform; + CanvasItem *pci = sw->get_parent_item(); + if (pci) + xform=pci->get_global_transform(); + + + Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + if (ret) + return ret; + } + + return NULL; + +} + + +Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform) { + + if (p_node->cast_to<Viewport>()) + return NULL; + + Control *c=p_node->cast_to<Control>(); + + if (c) { + // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); + } + + //subwindows first!! + + if (p_node->is_hidden()) { + //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); + return NULL; //canvas item hidden, discard + } + + Matrix32 matrix = p_xform * p_node->get_transform(); + + if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { + + for(int i=p_node->get_child_count()-1;i>=0;i--) { + + if (p_node==gui.tooltip_popup) + continue; + + CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); + if (!ci || ci->is_set_as_toplevel()) + continue; + + Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform);; + if (ret) + return ret; + } + } + + if (!c) + return NULL; + + matrix.affine_invert(); + + //conditions for considering this as a valid control for return + if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { + r_inv_xform=matrix; + return c; + } else + return NULL; +} + +void Viewport::_gui_input_event(InputEvent p_event) { + + + + if (p_event.ID==gui.cancelled_input_ID) { + return; + } + //? +// if (!is_visible()) { +// return; //simple and plain +// } + + + switch(p_event.type) { + + case InputEvent::MOUSE_BUTTON: { + + + gui.key_event_accepted=false; + + Point2 mpos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + if (p_event.mouse_button.pressed) { + + + + Size2 pos = mpos; + if (gui.mouse_focus && p_event.mouse_button.button_index!=gui.mouse_focus_button) { + + //do not steal mouse focus and stuff + + } else { + + + _gui_sort_modal_stack(); + while (!gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); + if (!top->has_point(pos)) { + + print_line("NO POINT"); + if (top->data.modal_exclusive) { + //cancel event, sorry, modal exclusive EATS UP ALL + //get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + return; // no one gets the event if exclusive NO ONE + } + + top->notification(Control::NOTIFICATION_MODAL_CLOSE); + top->_modal_stack_remove(); + top->hide(); + } else { + break; + } + } + + + + Matrix32 parent_xform; + + //if (data.parent_canvas_item) + // parent_xform=data.parent_canvas_item->get_global_transform(); + + + + gui.mouse_focus = _gui_find_control(pos); + //print_line("has mf "+itos(gui.mouse_focus!=NULL)); + gui.mouse_focus_button=p_event.mouse_button.button_index; + + if (!gui.mouse_focus) { + break; + } + + if (p_event.mouse_button.button_index==BUTTON_LEFT) { + gui.drag_accum=Vector2(); + gui.drag_attempted=false; + gui.drag_data=Variant(); + } + + + } + + p_event.mouse_button.global_x = pos.x; + p_event.mouse_button.global_y = pos.y; + + pos = gui.focus_inv_xform.xform(pos); + p_event.mouse_button.x = pos.x; + p_event.mouse_button.y = pos.y; + +#ifdef DEBUG_ENABLED + if (ScriptDebugger::get_singleton()) { + + Array arr; + arr.push_back(gui.mouse_focus->get_path()); + arr.push_back(gui.mouse_focus->get_type()); + ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); + } + + /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { + + print_line(String(gui.mouse_focus->get_path())+" - "+pos); + }*/ +#endif + + if (gui.mouse_focus->get_focus_mode()!=Control::FOCUS_NONE && gui.mouse_focus!=gui.key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { + // also get keyboard focus + gui.mouse_focus->grab_focus(); + } + + + if (gui.mouse_focus->can_process()) { + _gui_call_input(gui.mouse_focus,p_event); + } + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + gui.tooltip_popup->hide(); + + } else { + + if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { + memdelete( gui.drag_preview ); + gui.drag_preview=NULL; + } + + if (!gui.mouse_focus) { + + if (gui.mouse_over && gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + + Size2 pos = mpos; + pos = gui.focus_inv_xform.xform(pos); + + gui.mouse_over->drop_data(pos,gui.drag_data); + gui.drag_data=Variant(); + //change mouse accordingly + } + + break; + } + + Size2 pos = mpos; + p_event.mouse_button.global_x = pos.x; + p_event.mouse_button.global_y = pos.y; + pos = gui.focus_inv_xform.xform(pos); + p_event.mouse_button.x = pos.x; + p_event.mouse_button.y = pos.y; + + if (gui.mouse_focus->can_process()) { + _gui_call_input(gui.mouse_focus,p_event); + } + + if (p_event.mouse_button.button_index==gui.mouse_focus_button) { + gui.mouse_focus=NULL; + gui.mouse_focus_button=-1; + } + + if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + gui.drag_data=Variant(); //always clear + } + + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + } + } break; + case InputEvent::MOUSE_MOTION: { + + gui.key_event_accepted=false; + Point2 mpos=Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + + gui.last_mouse_pos=mpos; + + Control *over = NULL; + + + // D&D + if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);; + float len = gui.drag_accum.length(); + if (len>10) { + gui.drag_data=gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos)-gui.drag_accum); + if (gui.drag_data.get_type()!=Variant::NIL) { + + gui.mouse_focus=NULL; + } + gui.drag_attempted=true; + } + } + + + if (gui.mouse_focus) { + over=gui.mouse_focus; + //recompute focus_inv_xform again here + + } else { + + over = _gui_find_control(mpos); + } + + + if (gui.drag_data.get_type()==Variant::NIL && over && !gui.modal_stack.empty()) { + + Control *top = gui.modal_stack.back()->get(); + if (over!=top && !top->is_a_parent_of(over)) { + + break; // don't send motion event to anything below modal stack top + } + } + + if (over!=gui.mouse_over) { + + if (gui.mouse_over) + gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT); + + if (over) + over->notification(Control::NOTIFICATION_MOUSE_ENTER); + + } + + gui.mouse_over=over; + + _gui_cancel_tooltip(); + + if (gui.drag_preview) { + gui.drag_preview->set_pos(mpos); + } + + if (!over) { + OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW); + break; + } + + + Matrix32 localizer = over->get_canvas_transform().affine_inverse(); + Size2 pos = localizer.xform(mpos); + Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); + Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); + + + p_event.mouse_motion.global_x = mpos.x; + p_event.mouse_motion.global_y = mpos.y; + p_event.mouse_motion.speed_x=speed.x; + p_event.mouse_motion.speed_y=speed.y; + p_event.mouse_motion.relative_x=rel.x; + p_event.mouse_motion.relative_y=rel.y; + + if (p_event.mouse_motion.button_mask==0 && gui.tooltip_timer) { + //nothing pressed + + bool can_tooltip=true; + + if (!gui.modal_stack.empty()) { + if (gui.modal_stack.back()->get()!=over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) + can_tooltip=false; + + } + + + if (can_tooltip) { + + gui.tooltip=over; + gui.tooltip_pos=mpos;//(parent_xform * get_transform()).affine_inverse().xform(pos); + gui.tooltip_timer->start(); + } + } + + + pos = gui.focus_inv_xform.xform(pos); + + + p_event.mouse_motion.x = pos.x; + p_event.mouse_motion.y = pos.y; + + + Control::CursorShape cursor_shape = over->get_cursor_shape(pos); + + OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); + + + if (over->can_process()) { + _gui_call_input(over,p_event); + } + + + + //get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->set_input_as_handled(); + + + if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + /*bool can_drop =*/ over->can_drop_data(pos,gui.drag_data); + //change mouse accordingly i guess + } + + } break; + case InputEvent::ACTION: + case InputEvent::JOYSTICK_BUTTON: + case InputEvent::KEY: { + + if (gui.key_focus) { + + gui.key_event_accepted=false; + if (gui.key_focus->can_process()) { + gui.key_focus->call_multilevel("_input_event",p_event); + if (gui.key_focus) //maybe lost it + gui.key_focus->emit_signal(SceneStringNames::get_singleton()->input_event,p_event); + } + + + if (gui.key_event_accepted) { + + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + break; + } + } + + + if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !gui.modal_stack.empty()) { + + _gui_sort_modal_stack(); + Control *top = gui.modal_stack.back()->get(); + if (!top->data.modal_exclusive) { + + top->notification(Control::NOTIFICATION_MODAL_CLOSE); + top->_modal_stack_remove(); + top->hide(); + } + } + + + Control * from = gui.key_focus ? gui.key_focus : NULL; //hmm + + //keyboard focus + //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { + + if (from && p_event.is_pressed()) { + Control * next=NULL; + + if (p_event.is_action("ui_focus_next")) { + + next = from->find_next_valid_focus(); + } + + if (p_event.is_action("ui_focus_prev")) { + + next = from->find_prev_valid_focus(); + } + + if (p_event.is_action("ui_up")) { + + next = from->_get_focus_neighbour(MARGIN_TOP); + } + + if (p_event.is_action("ui_left")) { + + next = from->_get_focus_neighbour(MARGIN_LEFT); + } + + if (p_event.is_action("ui_right")) { + + next = from->_get_focus_neighbour(MARGIN_RIGHT); + } + + if (p_event.is_action("ui_down")) { + + next = from->_get_focus_neighbour(MARGIN_BOTTOM); + } + + + if (next) { + next->grab_focus(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + } + } + + } break; + } +} + + +List<Control*>::Element* Viewport::_gui_add_root_control(Control* p_control) { + + gui.roots_order_dirty=true; + return gui.roots.push_back(p_control); +} + +List<Control*>::Element* Viewport::_gui_add_subwindow_control(Control* p_control) { + + gui.subwindow_order_dirty=true; + return gui.subwindows.push_back(p_control); + +} + +void Viewport::_gui_set_subwindow_order_dirty() { + gui.subwindow_order_dirty=true; +} + +void Viewport::_gui_set_root_order_dirty() { + gui.roots_order_dirty=true; +} + +void Viewport::_gui_remove_modal_control(List<Control*>::Element *MI) { + + gui.modal_stack.erase(MI); +} + +void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner) { + + //transfer the focus stack to the next + + List<Control*>::Element *next = MI->next(); + + gui.modal_stack.erase(MI); + MI=NULL; + + if (p_prev_focus_owner) { + + // for previous window in stack, pass the focus so it feels more + // natural + + if (!next) { //top of stack + + Object *pfo = ObjectDB::get_instance(p_prev_focus_owner); + Control *pfoc = pfo->cast_to<Control>(); + if (!pfoc) + return; + + if (!pfoc->is_inside_tree() || !pfoc->is_visible()) + return; + pfoc->grab_focus(); + } else { + + next->get()->_modal_set_prev_focus_owner(p_prev_focus_owner); + } + } +} + +void Viewport::_gui_force_drag(const Variant& p_data,Control *p_control) { + + gui.drag_data=p_data; + gui.mouse_focus=NULL; + + if (p_control) { + _gui_set_drag_preview(p_control); + } +} + +void Viewport::_gui_set_drag_preview(Control *p_control) { + + ERR_FAIL_NULL(p_control); + ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); + ERR_FAIL_COND(p_control->is_inside_tree()); + ERR_FAIL_COND(p_control->get_parent()!=NULL); + + if (gui.drag_preview) { + memdelete(gui.drag_preview); + } + p_control->set_as_toplevel(true); + p_control->set_pos(gui.last_mouse_pos); + add_child(p_control); //add as child of viewport + p_control->raise(); + if (gui.drag_preview) { + memdelete( gui.drag_preview ); + } + gui.drag_preview=p_control; +} + + +void Viewport::_gui_remove_root_control(List<Control*>::Element *RI) { + + gui.roots.erase(RI); +} + +void Viewport::_gui_remove_subwindow_control(List<Control*>::Element* SI){ + + gui.subwindows.erase(SI); +} + +void Viewport::_gui_unfocus_control(Control *p_control) { + + if (gui.key_focus==p_control) { + gui.key_focus->release_focus(); + } +} + +void Viewport::_gui_hid_control(Control *p_control) { + + if (gui.mouse_focus == p_control) { + gui.mouse_focus=NULL; + } + + /* ??? + if (data.window==p_control) { + window->drag_data=Variant(); + if (window->drag_preview) { + memdelete( window->drag_preview); + window->drag_preview=NULL; + } + } + */ + + if (gui.key_focus == p_control) + gui.key_focus=NULL; + if (gui.mouse_over == p_control) + gui.mouse_over=NULL; + if (gui.tooltip == p_control) + gui.tooltip=NULL; + if (gui.tooltip == p_control) + gui.tooltip=NULL; + +} + +void Viewport::_gui_remove_control(Control *p_control) { + + + if (gui.mouse_focus == p_control) + gui.mouse_focus=NULL; + if (gui.key_focus == p_control) + gui.key_focus=NULL; + if (gui.mouse_over == p_control) + gui.mouse_over=NULL; + if (gui.tooltip == p_control) + gui.tooltip=NULL; + + +} + +void Viewport::_gui_remove_focus() { + + if (gui.key_focus) { + Node *f=gui.key_focus; + gui.key_focus=NULL; + f->notification( Control::NOTIFICATION_FOCUS_EXIT,true ); + + + } +} + +bool Viewport::_gui_is_modal_on_top(const Control* p_control) { + + return (gui.modal_stack.size() && gui.modal_stack.back()->get()==p_control); + +} + +bool Viewport::_gui_control_has_focus(const Control* p_control) { + + return gui.key_focus==p_control; +} + +void Viewport::_gui_control_grab_focus(Control* p_control) { + + + //no need for change + if (gui.key_focus && gui.key_focus==p_control) + return; + + _gui_remove_focus(); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_gui_remove_focus"); + gui.key_focus=p_control; + p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); + p_control->update(); + +} + +void Viewport::_gui_accept_event() { + + gui.key_event_accepted=true; + if (is_inside_tree()) + get_tree()->set_input_as_handled(); +} + + +List<Control*>::Element* Viewport::_gui_show_modal(Control* p_control) { + + gui.modal_stack.push_back(p_control); + if (gui.key_focus) + p_control->_modal_set_prev_focus_owner(gui.key_focus->get_instance_ID()); + else + p_control->_modal_set_prev_focus_owner(0); + + return gui.modal_stack.back(); +} + +Control *Viewport::_gui_get_focus_owner() { + + return gui.key_focus; +} + +void Viewport::_gui_grab_click_focus(Control *p_control) { + + if (gui.mouse_focus) { + + + if (gui.mouse_focus==p_control) + return; + InputEvent ie; + ie.type=InputEvent::MOUSE_BUTTON; + InputEventMouseButton &mb=ie.mouse_button; + + //send unclic + + Point2 click =gui.mouse_focus->get_global_transform().affine_inverse().xform(gui.last_mouse_pos); + mb.x=click.x; + mb.y=click.y; + mb.button_index=gui.mouse_focus_button; + mb.pressed=false; + gui.mouse_focus->call_deferred("_input_event",ie); + + + gui.mouse_focus=p_control; + gui.focus_inv_xform=gui.mouse_focus->get_global_transform().affine_inverse(); + click =gui.mouse_focus->get_global_transform().affine_inverse().xform(gui.last_mouse_pos); + mb.x=click.x; + mb.y=click.y; + mb.button_index=gui.mouse_focus_button; + mb.pressed=true; + gui.mouse_focus->call_deferred("_input_event",ie); + + } +} + + +/////////////////////////////// + + void Viewport::input(const InputEvent& p_event) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(input_group,"_input",p_event); - get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check + get_tree()->_call_input_pause(input_group,"_input",p_event); + _gui_input_event(p_event); + //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } void Viewport::unhandled_input(const InputEvent& p_event) { @@ -1377,6 +2260,19 @@ bool Viewport::get_physics_object_picking() { return physics_object_picking; } +bool Viewport::gui_has_modal_stack() const { + + return gui.modal_stack.size(); +} + +void Viewport::set_disable_input(bool p_disable) { + disable_input=p_disable; +} + +bool Viewport::is_input_disabled() const { + + return disable_input; +} void Viewport::_bind_methods() { @@ -1405,6 +2301,7 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("_parent_resized"), &Viewport::_parent_resized); ObjectTypeDB::bind_method(_MD("_vp_input"), &Viewport::_vp_input); + ObjectTypeDB::bind_method(_MD("_vp_input_text","text"), &Viewport::_vp_input_text); ObjectTypeDB::bind_method(_MD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); ObjectTypeDB::bind_method(_MD("set_size_override","enable","size","margin"), &Viewport::set_size_override,DEFVAL(Size2(-1,-1)),DEFVAL(Size2(0,0))); @@ -1461,6 +2358,13 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos); ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse); + ObjectTypeDB::bind_method(_MD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); + + ObjectTypeDB::bind_method(_MD("set_disable_input","disable"), &Viewport::set_disable_input); + ObjectTypeDB::bind_method(_MD("is_input_disabled"), &Viewport::is_input_disabled); + + ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") ); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") ); @@ -1475,6 +2379,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled") ); ADD_SIGNAL(MethodInfo("size_changed")); @@ -1491,6 +2396,7 @@ void Viewport::_bind_methods() { Viewport::Viewport() { + world_2d = Ref<World2D>( memnew( World2D )); viewport = VisualServer::get_singleton()->viewport_create(); @@ -1524,7 +2430,24 @@ Viewport::Viewport() { unhandled_input_group = "_vp_unhandled_input"+id; unhandled_key_input_group = "_vp_unhandled_key_input"+id; - + disable_input=false; + + //window tooltip + gui.tooltip_timer = memnew( Timer ); + add_child(gui.tooltip_timer); + gui.tooltip_timer->force_parent_owned(); + gui.tooltip_timer->set_wait_time( GLOBAL_DEF("display/tooltip_delay",0.7)); + gui.tooltip_timer->connect("timeout",this,"_gui_show_tooltip"); + gui.tooltip=NULL; + gui.tooltip_popup = memnew( TooltipPanel ); + add_child(gui.tooltip_popup); + gui.tooltip_popup->force_parent_owned(); + gui.tooltip_label = memnew( TooltipLabel ); + gui.tooltip_popup->add_child(gui.tooltip_label); + gui.tooltip_popup->set_as_toplevel(true); + gui.tooltip_popup->hide(); + gui.drag_attempted=false; + gui.drag_preview=NULL; } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 7d86c5f334..97ceb8de4b 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -39,6 +39,11 @@ */ class Camera; +class Control; +class CanvasItem; +class Panel; +class Label; +class Timer; class Viewport; class RenderTargetTexture : public Texture { @@ -162,6 +167,48 @@ friend class RenderTargetTexture; Ref<RenderTargetTexture> render_target_texture; + struct GUI { + // info used when this is a window + + bool key_event_accepted; + Control *mouse_focus; + int mouse_focus_button; + Control *key_focus; + Control *mouse_over; + Control *tooltip; + Panel *tooltip_popup; + Label *tooltip_label; + Point2 tooltip_pos; + Point2 last_mouse_pos; + Point2 drag_accum; + bool drag_attempted; + Variant drag_data; + Control *drag_preview; + Timer *tooltip_timer; + List<Control*> modal_stack; + unsigned int cancelled_input_ID; + Matrix32 focus_inv_xform; + bool subwindow_order_dirty; + List<Control*> subwindows; + bool roots_order_dirty; + List<Control*> roots; + + + GUI(); + } gui; + + bool disable_input; + + void _gui_call_input(Control *p_control,const InputEvent& p_input); + void _gui_sort_subwindows(); + void _gui_sort_roots(); + void _gui_sort_modal_stack(); + Control* _gui_find_control(const Point2& p_global); + Control* _gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform); + + void _gui_input_event(InputEvent p_event); + + void update_worlds(); _FORCE_INLINE_ Matrix32 _get_input_pre_xform() const; @@ -170,9 +217,47 @@ friend class RenderTargetTexture; void _vp_exit_tree(); void _vp_input(const InputEvent& p_ev); + void _vp_input_text(const String& p_text); void _vp_unhandled_input(const InputEvent& p_ev); void _make_input_local(InputEvent& ev); + +friend class Control; + + List<Control*>::Element* _gui_add_root_control(Control* p_control); + List<Control*>::Element* _gui_add_subwindow_control(Control* p_control); + + void _gui_set_subwindow_order_dirty(); + void _gui_set_root_order_dirty(); + + + void _gui_remove_modal_control(List<Control*>::Element *MI); + void _gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner); + void _gui_remove_root_control(List<Control*>::Element *RI); + void _gui_remove_subwindow_control(List<Control*>::Element* SI); + + void _gui_cancel_tooltip(); + void _gui_show_tooltip(); + + + void _gui_remove_control(Control *p_control); + void _gui_hid_control(Control *p_control); + + void _gui_force_drag(const Variant& p_data,Control *p_control); + void _gui_set_drag_preview(Control *p_control); + + bool _gui_is_modal_on_top(const Control* p_control); + List<Control*>::Element* _gui_show_modal(Control* p_control); + + void _gui_remove_focus(); + void _gui_unfocus_control(Control *p_control); + bool _gui_control_has_focus(const Control* p_control); + void _gui_control_grab_focus(Control* p_control); + void _gui_grab_click_focus(Control *p_control); + void _gui_accept_event(); + + Control *_gui_get_focus_owner(); + friend class Camera; void _camera_transform_changed_notify(); void _set_camera(Camera* p_camera); @@ -254,6 +339,9 @@ public: void input(const InputEvent& p_event); void unhandled_input(const InputEvent& p_event); + void set_disable_input(bool p_disable); + bool is_input_disabled() const; + void set_render_target_to_screen_rect(const Rect2& p_rect); Rect2 get_render_target_to_screen_rect() const; @@ -263,6 +351,9 @@ public: void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); + bool gui_has_modal_stack() const; + + Viewport(); ~Viewport(); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index f0b3519b4a..f713b9e979 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -80,6 +80,13 @@ static Ref<Texture> make_icon(T p_src) { return texture; } +static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,const char*lighting_code) { + Ref<Shader> shader = (memnew( Shader(Shader::MODE_CANVAS_ITEM) )); + shader->set_code(vertex_code, fragment_code, lighting_code); + + return shader; +} + static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) { @@ -767,7 +774,11 @@ void make_default_theme() { t->set_constant("label_width","ColorPicker", 20); t->set_constant("hseparator","ColorPicker", 4); - + t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) ); + t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) ); + + t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, "")); + t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, "")); // TooltipPanel diff --git a/scene/resources/default_theme/icon_add.png b/scene/resources/default_theme/icon_add.png Binary files differnew file mode 100644 index 0000000000..26283ca67c --- /dev/null +++ b/scene/resources/default_theme/icon_add.png diff --git a/scene/resources/default_theme/icon_color_pick.png b/scene/resources/default_theme/icon_color_pick.png Binary files differnew file mode 100644 index 0000000000..2896763834 --- /dev/null +++ b/scene/resources/default_theme/icon_color_pick.png diff --git a/scene/resources/default_theme/make_png_header.py b/scene/resources/default_theme/make_header.py index 0f0ce1808f..2d3f989e01 100644 --- a/scene/resources/default_theme/make_png_header.py +++ b/scene/resources/default_theme/make_header.py @@ -3,9 +3,6 @@ import os; import glob; import string; -pixmaps = glob.glob("*.png"); - -pixmaps.sort(); #Generate include files @@ -15,27 +12,61 @@ f.write("// THIS FILE HAS BEEN AUTOGENERATED, DONT EDIT!!\n"); f.write("\n\n"); +#Generate png image block + +pixmaps = glob.glob("*.png"); + +pixmaps.sort(); + f.write("\n\n\n"); - - for x in pixmaps: - + var_str=x[:-4]+"_png"; - + f.write("static const unsigned char "+ var_str +"[]={\n"); - + pngf=open(x,"rb"); - + b=pngf.read(1); while(len(b)==1): f.write(hex(ord(b))) b=pngf.read(1); if (len(b)==1): f.write(",") - + f.write("\n};\n\n\n"); pngf.close(); - -f.close(); +#Generate shaders block + +shaders = glob.glob("*.gsl") + +shaders.sort(); + +f.write("\n\n\n"); + +for x in shaders: + + var_str=x[:-4]+"_shader_code"; + + f.write("static const char *"+ var_str +"=\n"); + + sf=open(x,"rb"); + + + b=sf.readline(); + while(b!=""): + if (b.endswith("\r\n")): + b=b[:-2] + if (b.endswith("\n")): + b=b[:-1] + f.write(" \""+b) + b=sf.readline(); + if (b!=""): + f.write("\"\n") + + f.write("\";\n\n\n"); + sf.close(); + +f.close(); diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index e0b5736d99..4c440ab99a 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -179,11 +179,21 @@ static const unsigned char hsplitter_png[]={ }; +static const unsigned char icon_add_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x12,0x0,0x0,0xb,0x12,0x1,0xd2,0xdd,0x7e,0xfc,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xec,0x49,0x44,0x41,0x54,0x38,0x8d,0xdd,0x92,0x41,0x4a,0xc4,0x30,0x18,0x85,0xbf,0x67,0x93,0xc,0xd9,0x28,0xb9,0x41,0xcf,0x21,0x7a,0x28,0xdd,0xcd,0x5,0x14,0x57,0x73,0x28,0xe7,0x20,0xbd,0x41,0x70,0x5c,0x14,0x93,0xe,0xbf,0xb,0xdb,0x61,0x5a,0x5a,0x70,0xab,0xf,0x2,0x21,0xfc,0xf9,0xf2,0xde,0x23,0xf0,0xe7,0xa5,0xb5,0xc3,0x9c,0xf3,0xae,0x94,0xf2,0xda,0xf7,0xfd,0x13,0x40,0x8c,0xf1,0x10,0x42,0xd8,0xa7,0x94,0xbe,0x96,0xb3,0x6e,0x3,0x6c,0x92,0x4e,0x40,0x1,0x90,0xf4,0x1,0xd8,0xda,0xe0,0xc,0x90,0x73,0xde,0x1,0x66,0x66,0xc1,0xcc,0x9a,0xb,0xcd,0xcc,0x99,0x59,0xc8,0x39,0x3,0xe8,0xda,0xc9,0xc,0x50,0x4a,0x79,0x91,0xf4,0x69,0x66,0xcd,0x30,0xc,0xf,0x40,0x3,0x30,0xee,0x91,0x74,0x36,0xb3,0x5b,0xe0,0x79,0xb5,0x83,0xae,0xeb,0x6c,0xb2,0x3d,0x5e,0x9e,0x5c,0x9c,0xc7,0x5,0x10,0xda,0xb6,0xbd,0xdc,0xbb,0xd9,0xe8,0xe0,0xd7,0x9a,0x45,0x88,0x31,0x1e,0x24,0x9d,0xa6,0x8,0xb5,0xd6,0x47,0x0,0xef,0xfd,0xbb,0x73,0xee,0x78,0x15,0x61,0x1d,0x10,0x42,0xd8,0x33,0x96,0x8,0x50,0x6b,0xbd,0x7,0x70,0xce,0x1d,0xbd,0xf7,0x6f,0x92,0xa,0x8b,0xd8,0x33,0xc0,0xd4,0x6e,0xce,0x19,0x49,0x53,0x66,0x24,0xd,0x92,0x4a,0x4a,0xa9,0xb0,0xd0,0xd6,0x3f,0xd0,0x68,0x35,0xf0,0x63,0xe9,0x6e,0xf9,0xf2,0x3f,0xd2,0x37,0xb9,0xed,0x67,0x29,0x9e,0xb,0x7f,0x1a,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char icon_close_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xd9,0xb,0x17,0x6,0x11,0xd,0x6a,0x1e,0x9a,0x6f,0x0,0x0,0x0,0x5e,0x49,0x44,0x41,0x54,0x38,0xcb,0xd5,0x53,0xcb,0xe,0xc0,0x30,0x8,0x12,0xb2,0xff,0xff,0x65,0x77,0x5a,0xb3,0x36,0xf8,0x48,0xcc,0xe,0xf3,0xd4,0x3,0xa2,0x40,0x85,0x9b,0xdb,0xa4,0x68,0xc3,0x1a,0x13,0x5c,0xcf,0x3,0x86,0xa5,0xc5,0xcd,0xa1,0xc0,0xa,0x43,0xd5,0xf4,0x6,0x56,0x3,0x36,0x9,0x11,0x49,0xb6,0x1d,0x54,0xa,0x6a,0x83,0x48,0x1a,0xbb,0xc0,0xc8,0x97,0x6f,0x62,0xac,0x4c,0x4c,0x9,0x4e,0xc3,0xaa,0x74,0xd8,0x89,0x2a,0x23,0x61,0xf7,0x23,0x85,0x11,0xff,0xff,0x98,0x6e,0x7,0x20,0x33,0x1a,0x5b,0xf5,0xcc,0xfe,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; +static const unsigned char icon_color_pick_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x11,0x0,0x0,0xb,0x11,0x1,0x7f,0x64,0x5f,0x91,0x0,0x0,0x0,0x18,0x74,0x45,0x58,0x74,0x53,0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x0,0x70,0x61,0x69,0x6e,0x74,0x2e,0x6e,0x65,0x74,0x20,0x34,0x2e,0x30,0x2e,0x36,0xfc,0x8c,0x63,0xdf,0x0,0x0,0x1,0xf7,0x49,0x44,0x41,0x54,0x38,0x4f,0x8d,0x90,0xbd,0x6b,0x53,0x51,0x18,0xc6,0xaf,0x26,0xed,0x62,0x70,0x71,0xd0,0xc1,0x2f,0x70,0xa9,0xda,0x4d,0xc7,0x8e,0xd6,0x42,0xc5,0x52,0xa5,0x42,0xa1,0xa4,0xb6,0x20,0x75,0x50,0xf4,0x52,0x41,0x1d,0x6a,0x87,0x96,0xfe,0x1,0x42,0xa1,0x20,0x52,0x71,0x56,0x50,0xf3,0xd5,0x94,0x24,0xed,0x50,0x5d,0xc4,0x41,0xa9,0x70,0xd3,0xc4,0xe7,0x9c,0xa0,0xc5,0xf,0x1c,0x2,0x6,0x29,0x4d,0xe2,0x7d,0x7d,0x4e,0x72,0xc,0xe9,0x7,0xb5,0xf,0xfc,0x48,0xee,0xcd,0xf3,0x7b,0xcf,0x7b,0xe2,0xfc,0x2f,0xc5,0x62,0x31,0x98,0xc8,0xfd,0x8,0x5c,0x8c,0xa1,0xa5,0x3f,0x81,0xe0,0x8d,0x14,0x4e,0xdc,0xcd,0x60,0x6a,0x64,0x1e,0x3,0x3d,0x31,0x84,0x6c,0x6d,0x6b,0x6,0xe6,0x10,0x1c,0x4a,0xe2,0xc0,0xf3,0x8f,0xab,0x7b,0x87,0x53,0x2a,0x40,0xf9,0x24,0xe5,0xa7,0xf7,0x17,0xf0,0xe7,0x5e,0x6,0x55,0x3e,0x7f,0xee,0x8c,0xe0,0xa0,0xad,0x3b,0x8e,0x88,0x34,0x30,0x19,0x4c,0x22,0x70,0x2b,0x85,0xa3,0x7d,0x71,0x1c,0xb9,0x1c,0x47,0x68,0x34,0x8d,0x35,0xca,0xe2,0xa6,0x21,0xe1,0x39,0xf8,0x5d,0x11,0xac,0x9f,0x8b,0xe0,0x71,0xad,0x6c,0xd2,0x2c,0x9b,0xf4,0xc6,0x70,0xfc,0xda,0x3c,0xd6,0x2e,0xc5,0xf0,0x75,0x38,0x89,0x99,0xb1,0x5,0xf8,0x77,0xd2,0xf0,0xaf,0xc4,0x51,0x3d,0x1f,0x41,0x99,0xb2,0x22,0xa7,0x6d,0x7d,0xeb,0x0,0x9e,0x70,0xa6,0x27,0x8a,0x32,0xd7,0x14,0x6e,0x20,0xdc,0xc0,0xe7,0xea,0x3e,0x4f,0x2f,0x71,0xc0,0x7,0xca,0x61,0xd2,0x62,0xeb,0xf5,0x1,0xcd,0x59,0xfe,0xa4,0xdd,0x47,0x6f,0x21,0xdd,0x51,0xf8,0x1c,0xe2,0xf3,0x2a,0xc2,0x3f,0xce,0x6c,0xf0,0x8e,0xc3,0x7,0x29,0xef,0xb3,0xd5,0x7a,0x9a,0x7,0x14,0xa,0x85,0x3e,0x52,0xc9,0x2b,0x5d,0x19,0x5d,0xc4,0x2c,0xcb,0x25,0xb3,0x9,0x87,0xc9,0x85,0x28,0xbe,0xf3,0xfb,0x31,0xbe,0xdb,0x63,0xeb,0xf5,0xfc,0xbb,0x2,0xc5,0xe,0x52,0x22,0x42,0x6e,0xba,0x8b,0xd8,0x3f,0xf5,0x46,0xe5,0x79,0xaa,0x50,0x32,0x54,0x49,0xe7,0xb6,0x3,0x28,0xb4,0x91,0xa2,0x95,0x27,0x49,0x90,0x3c,0xcb,0x42,0xcb,0xf8,0x92,0xfa,0x6d,0x65,0x9f,0xbc,0x22,0xad,0x56,0xad,0x87,0xc5,0x10,0xf1,0x88,0x91,0x9f,0x90,0x9a,0x6c,0x9f,0x7f,0x26,0x96,0xf5,0x59,0x4a,0x2e,0x79,0x49,0x4e,0x91,0x8d,0x1b,0xb0,0xf4,0x42,0xe7,0xb5,0x60,0x36,0xb7,0x8a,0xeb,0x5e,0xb8,0x49,0x36,0xd7,0xe9,0x30,0x1b,0x1a,0x89,0xb4,0x6e,0x27,0xf7,0xea,0xf7,0x4a,0x30,0xb1,0x52,0x46,0xd8,0x2b,0xe3,0x41,0xf6,0xcb,0x66,0x79,0x33,0x1b,0xc2,0x92,0xa7,0x1e,0xe6,0x4,0x57,0xbd,0x75,0xb8,0xd9,0x5f,0x5a,0xeb,0x1d,0x65,0x43,0x23,0x2c,0xb5,0xab,0xc,0x4,0x23,0x9e,0xe0,0xb6,0x57,0xd1,0x2b,0x35,0xf9,0xdb,0x4e,0xb2,0xa1,0x11,0x16,0xf,0x61,0x3a,0x57,0x55,0xaf,0x61,0x44,0x43,0x8a,0x1c,0xb6,0x3f,0xef,0x2e,0x14,0xda,0xc9,0x98,0xf9,0xb4,0xaf,0x76,0x19,0xc7,0xf9,0xb,0x8e,0xb3,0xf3,0x95,0xda,0x15,0xd3,0x79,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char icon_folder_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xde,0x9,0xf,0x14,0x33,0x39,0x1,0xd2,0x43,0x4c,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x36,0x49,0x44,0x41,0x54,0x38,0x8d,0xc5,0x92,0xcd,0x4a,0xc3,0x40,0x14,0x85,0xbf,0x7b,0x67,0x12,0x48,0x3,0x12,0x62,0x45,0xfa,0x30,0x7d,0x5,0x5d,0xfa,0x8,0xbe,0x88,0x3e,0x45,0x5f,0xc1,0x9d,0x4b,0x77,0x3e,0x81,0x2e,0xa4,0x15,0xa5,0x10,0xb2,0xc8,0xa2,0x9b,0x41,0x2c,0x62,0x4c,0x66,0x5c,0x34,0x8a,0x3f,0x95,0x26,0x2b,0xf,0xc,0xcc,0x9d,0x3b,0xe7,0xce,0x39,0x87,0x81,0xff,0x86,0x14,0x45,0x11,0xb6,0x35,0xe2,0x38,0xbe,0x9c,0x4c,0x26,0x47,0xce,0xb9,0x78,0x4b,0x3b,0x64,0x59,0xf6,0x6,0x20,0x65,0x59,0x56,0xde,0xfb,0x43,0x40,0x80,0x0,0x34,0xdd,0xa5,0x28,0x49,0x92,0x73,0x11,0x79,0xf9,0x49,0x16,0x91,0xd5,0x78,0x3c,0x9e,0x1,0x58,0x63,0x4c,0xe9,0xbd,0x3f,0x0,0xc,0x20,0xa3,0xd1,0xe8,0x2c,0x84,0x10,0x1,0x88,0xc8,0x6b,0x37,0xf8,0x9b,0xea,0x10,0xc2,0xa7,0x2a,0xa9,0xaa,0xea,0xa2,0xae,0xeb,0x63,0x40,0xd3,0x34,0x3d,0x5d,0xaf,0xd7,0xb3,0xde,0xfe,0x45,0x9e,0xd4,0x18,0x53,0x0,0x1e,0xd0,0x10,0x42,0xda,0x97,0xc,0x78,0x55,0xad,0x54,0x44,0x96,0x80,0xfd,0xf0,0x37,0x64,0x80,0x31,0x66,0xa1,0xaa,0xfa,0x8,0x68,0x77,0xb8,0x7,0xd4,0x83,0x6,0x88,0xc8,0x3,0x80,0x31,0x66,0xde,0x34,0xcd,0x94,0x4d,0x98,0x7d,0x10,0xab,0xea,0xad,0xe6,0x79,0xbe,0x4,0x88,0xa2,0xe8,0xba,0xae,0xeb,0xe9,0x17,0x35,0x3b,0xa1,0xaa,0x37,0xf6,0x4b,0x71,0x7,0x24,0x7d,0xc9,0x0,0x79,0x9e,0xcf,0x2d,0x80,0x88,0x3c,0xf,0x79,0x99,0x4d,0xd8,0x1e,0xba,0xf4,0x55,0x75,0xd5,0xed,0xdb,0x6e,0xed,0x42,0x63,0xad,0xbd,0x7,0xb0,0xce,0x39,0x6d,0xdb,0xf6,0x44,0x55,0x17,0x49,0x92,0xec,0xff,0xf1,0xfb,0x7e,0x29,0x50,0xd5,0x2b,0xe7,0x9c,0x8,0x80,0x73,0xce,0x74,0x92,0xa2,0x1,0x36,0xda,0x2c,0xcb,0xda,0x77,0xe3,0x5,0x64,0xf1,0xba,0x53,0xe9,0x44,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -519,3 +529,42 @@ static const unsigned char vsplitter_png[]={ }; + + + +static const char *uv_editor_shader_code= + "vec3 nd1sl2=vec3(UV,0);" + "uniform float H=0;" + "float nd4sl0=H;" + "float nd7sl0=nd1sl2.x;" + "float nd7sl1=nd1sl2.y;" + "float nd7sl2=nd1sl2.z;" + "float nd2sl1def=-1;" + "float nd2sl0=nd7sl1*nd2sl1def;" + "float nd6sl1def=1;" + "float nd6sl0=nd2sl0+nd6sl1def;" + "vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);" + "vec3 nd5sl0;" + "{" + " vec3 c = nd3sl0;" + " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);" + " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);" + " nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);" + "}" + "COLOR.rgb=nd5sl0;"; + + +static const char *w_editor_shader_code= + "vec3 nd1sl2=vec3(UV,0);" + "float nd2sl1=1-nd1sl2.y;" + "vec3 nd3sl0=vec3(nd2sl1,1,1);" + "vec3 nd6sl0;" + "{" + " vec3 c = nd3sl0;" + " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);" + " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);" + " nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);" + "}" + "COLOR.rgb=nd6sl0;"; + + diff --git a/scene/resources/default_theme/uv_editor.gsl b/scene/resources/default_theme/uv_editor.gsl new file mode 100644 index 0000000000..8c24e76dd5 --- /dev/null +++ b/scene/resources/default_theme/uv_editor.gsl @@ -0,0 +1,19 @@ +vec3 nd1sl2=vec3(UV,0);
+uniform float H=0;
+float nd4sl0=H;
+float nd7sl0=nd1sl2.x;
+float nd7sl1=nd1sl2.y;
+float nd7sl2=nd1sl2.z;
+float nd2sl1def=-1;
+float nd2sl0=nd7sl1*nd2sl1def;
+float nd6sl1def=1;
+float nd6sl0=nd2sl0+nd6sl1def;
+vec3 nd3sl0=vec3(nd4sl0,nd7sl0,nd6sl0);
+vec3 nd5sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd5sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd5sl0;
\ No newline at end of file diff --git a/scene/resources/default_theme/w_editor.gsl b/scene/resources/default_theme/w_editor.gsl new file mode 100644 index 0000000000..6d2dd9a0bb --- /dev/null +++ b/scene/resources/default_theme/w_editor.gsl @@ -0,0 +1,11 @@ +vec3 nd1sl2=vec3(UV,0);
+float nd2sl1=1-nd1sl2.y;
+vec3 nd3sl0=vec3(nd2sl1,1,1);
+vec3 nd6sl0;
+{
+ vec3 c = nd3sl0;
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
+ vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
+ nd6sl0=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
+}
+COLOR.rgb=nd6sl0;
\ No newline at end of file diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index d2795bddb8..03127620f7 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1597,6 +1597,16 @@ Node *PackedScene::instance(bool p_gen_edit_state) const { return s; } +void PackedScene::replace_state(Ref<SceneState> p_by) { + + state=p_by; + state->set_path(get_path()); +#ifdef TOOLS_ENABLED + state->set_last_modified_time(get_last_modified_time()); +#endif + +} + void PackedScene::recreate_state() { state = Ref<SceneState>( memnew( SceneState )); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index 415357b61f..00a812f16a 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -198,6 +198,7 @@ public: Node *instance(bool p_gen_edit_state=false) const; void recreate_state(); + void replace_state(Ref<SceneState> p_by); virtual void set_path(const String& p_path,bool p_take_over=false); #ifdef TOOLS_ENABLED diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 2552f682fa..5450b9e2ac 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -302,6 +302,10 @@ Error ResourceInteractiveLoaderText::poll() { if (error) { if (error!=ERR_FILE_EOF) { _printerr(); + } else { + if (!ResourceCache::has(res_path)) { + resource->set_path(res_path); + } } return error; } @@ -403,6 +407,9 @@ Error ResourceInteractiveLoaderText::poll() { _printerr(); } else { resource=packed_scene; + if (!ResourceCache::has(res_path)) { + packed_scene->set_path(res_path); + } } return error; } diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index e2413f7d84..685b2e07e1 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -266,7 +266,52 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { p_list->push_back(*key); } + +} + +void Theme::set_shader(const StringName &p_name,const StringName &p_type,const Ref<Shader>& p_shader) { + bool new_value=!shader_map.has(p_type) || !shader_map[p_type].has(p_name); + + shader_map[p_type][p_name]=p_shader; + if (new_value) { + _change_notify(); + emit_changed();; + } +} + +Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_type) const { + if (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()) { + return shader_map[p_type][p_name]; + } else { + return NULL; + } +} + +bool Theme::has_shader(const StringName &p_name, const StringName &p_type) const { + return (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()); +} + +void Theme::clear_shader(const StringName &p_name, const StringName &p_type) { + ERR_FAIL_COND(!shader_map.has(p_type)); + ERR_FAIL_COND(!shader_map[p_type].has(p_name)); + + shader_map[p_type].erase(p_name); + _change_notify(); + emit_changed();; +} + +void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const { + if (!shader_map.has(p_type)) + return; + + const StringName *key=NULL; + + while((key=shader_map[p_type].next(key))) { + + p_list->push_back(*key); + } + } diff --git a/scene/resources/theme.h b/scene/resources/theme.h index f0747fb3c4..180f55381d 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -33,6 +33,7 @@ #include "scene/resources/font.h" #include "scene/resources/style_box.h" #include "scene/resources/texture.h" +#include "scene/resources/shader.h" #include "io/resource_loader.h" /** @@ -48,6 +49,7 @@ class Theme : public Resource { HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map; HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map; HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map; + HashMap<StringName,HashMap<StringName,Ref<Shader>,StringNameHasher >, StringNameHasher > shader_map; HashMap<StringName,HashMap<StringName,Color,StringNameHasher >,StringNameHasher > color_map; HashMap<StringName,HashMap<StringName,int,StringNameHasher>,StringNameHasher > constant_map; protected: @@ -86,7 +88,13 @@ public: bool has_icon(const StringName& p_name,const StringName& p_type) const; void clear_icon(const StringName& p_name,const StringName& p_type); void get_icon_list(StringName p_type, List<StringName> *p_list) const; - + + void set_shader(const StringName& p_name,const StringName& p_type,const Ref<Shader>& p_shader); + Ref<Shader> get_shader(const StringName& p_name,const StringName& p_type) const; + bool has_shader(const StringName& p_name,const StringName& p_type) const; + void clear_shader(const StringName& p_name,const StringName& p_type); + void get_shader_list(const StringName& p_name, List<StringName> *p_list) const; + void set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style); Ref<StyleBox> get_stylebox(const StringName& p_name,const StringName& p_type) const; bool has_stylebox(const StringName& p_name,const StringName& p_type) const; diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index 9a0dde783b..fbe50d6d96 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -1085,6 +1085,7 @@ void AnimationKeyEditor::_track_editor_draw() { move_up_button->set_disabled(true); move_down_button->set_disabled(true); remove_button->set_disabled(true); + return; } @@ -2806,6 +2807,10 @@ void AnimationKeyEditor::_notification(int p_what) { switch(p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: { + + EditorNode::get_singleton()->update_keying(); + } break; case NOTIFICATION_ENTER_TREE: { @@ -2988,6 +2993,8 @@ void AnimationKeyEditor::set_animation(const Ref<Animation>& p_anim) { _update_menu(); selected_track=-1; _edit_if_single_selection(); + + EditorNode::get_singleton()->update_keying(); } void AnimationKeyEditor::set_root(Node *p_root) { @@ -3023,7 +3030,7 @@ void AnimationKeyEditor::set_keying(bool p_enabled) { bool AnimationKeyEditor::has_keying() const { - return keying; + return is_visible() && animation.is_valid(); } void AnimationKeyEditor::_query_insert(const InsertData& p_id) { @@ -3352,6 +3359,7 @@ Ref<Animation> AnimationKeyEditor::get_current_animation() const { void AnimationKeyEditor::_animation_len_changed(float p_len) { + if (updating) return; @@ -3479,8 +3487,10 @@ void AnimationKeyEditor::_insert_delay() { void AnimationKeyEditor::_step_changed(float p_len) { updating=true; - if (!animation.is_null()) + if (!animation.is_null()) { animation->set_step(p_len); + emit_signal("animation_step_changed",animation->get_step()); + } updating=false; } @@ -3691,21 +3701,33 @@ void AnimationKeyEditor::_bind_methods() { ADD_SIGNAL( MethodInfo("keying_changed" ) ); ADD_SIGNAL( MethodInfo("timeline_changed", PropertyInfo(Variant::REAL,"pos") ) ); ADD_SIGNAL( MethodInfo("animation_len_changed", PropertyInfo(Variant::REAL,"len") ) ); + ADD_SIGNAL( MethodInfo("animation_step_changed", PropertyInfo(Variant::REAL,"step") ) ); ADD_SIGNAL( MethodInfo("key_edited", PropertyInfo(Variant::INT,"track"), PropertyInfo(Variant::INT,"key") ) ); } -AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_history,EditorSelection *p_selection) { +AnimationKeyEditor::AnimationKeyEditor() { alc="animation_len_changed"; - editor_selection=p_selection; + editor_selection=EditorNode::get_singleton()->get_editor_selection(); selected_track=-1; updating=false; te_drawing=false; - undo_redo=p_undo_redo; - history=p_history; + undo_redo=EditorNode::get_singleton()->get_undo_redo(); + history=EditorNode::get_singleton()->get_editor_history(); + + ec = memnew (Control); + ec->set_custom_minimum_size(Size2(0,150)); + add_child(ec); + ec->set_v_size_flags(SIZE_EXPAND_FILL); + + h_scroll = memnew( HScrollBar ); + h_scroll->connect("value_changed",this,"_scroll_changed"); + add_child(h_scroll); + h_scroll->set_val(0); + HBoxContainer *hb = memnew( HBoxContainer ); add_child(hb); @@ -3863,10 +3885,6 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h // menu->get_popup()->connect("item_pressed",this,"_menu_callback"); - ec = memnew (Control); - ec->set_custom_minimum_size(Size2(0,150)); - add_child(ec); - ec->set_v_size_flags(SIZE_EXPAND_FILL); hb = memnew( HBoxContainer); hb->set_area_as_parent_rect(); @@ -3943,12 +3961,6 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h curve_edit->set_v_size_flags(SIZE_EXPAND_FILL); key_editor_tab->add_child(curve_vb); - h_scroll = memnew( HScrollBar ); - h_scroll->connect("value_changed",this,"_scroll_changed"); - add_child(h_scroll); - h_scroll->set_val(0); - - track_name = memnew( LineEdit ); track_name->set_as_toplevel(true); track_name->hide(); @@ -4025,6 +4037,7 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h cleanup_dialog->connect("confirmed",this,"_menu_track",varray(TRACK_MENU_CLEAN_UP_CONFIRM)); + add_constant_override("separation",get_constant("separation","VBoxContainer")); } diff --git a/tools/editor/animation_editor.h b/tools/editor/animation_editor.h index 65d0fb70f8..c8a539179e 100644 --- a/tools/editor/animation_editor.h +++ b/tools/editor/animation_editor.h @@ -262,7 +262,7 @@ class AnimationKeyEditor : public VBoxContainer { EditorSelection *editor_selection; - AnimationKeyEditor(); + float _get_zoom_scale() const; @@ -334,7 +334,7 @@ public: void insert_value_key(const String& p_property, const Variant& p_value, bool p_advance); void insert_transform_key(Spatial *p_node,const String& p_sub,const Transform& p_xform); - AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_history, EditorSelection *p_selection); + AnimationKeyEditor(); ~AnimationKeyEditor(); }; diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index d79c1ff466..5e613c658b 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -499,8 +499,8 @@ void EditorData::remove_scene(int p_idx){ bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> &checked_paths) { - if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner())) - return false; +// if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner())) +// return false; Ref<SceneState> ss; diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index fde3d4e278..5203ace125 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -1849,6 +1849,15 @@ void EditorImportExport::load_config() { if (cf->has_section("convert_samples")) { + if (cf->has_section_key("convert_samples","action")) { + String action = cf->get_value("convert_samples","action"); + if (action=="none") { + sample_action=SAMPLE_ACTION_NONE; + } else if (action=="compress_ram") { + sample_action=SAMPLE_ACTION_COMPRESS_RAM; + } + } + if (cf->has_section_key("convert_samples","max_hz")) sample_action_max_hz=cf->get_value("convert_samples","max_hz"); diff --git a/tools/editor/editor_log.cpp b/tools/editor/editor_log.cpp index 601e53eabb..bcdafbb06a 100644 --- a/tools/editor/editor_log.cpp +++ b/tools/editor/editor_log.cpp @@ -79,8 +79,6 @@ void EditorLog::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { log->add_color_override("default_color",get_color("font_color","Tree")); - tb->set_normal_texture( get_icon("Collapse","EditorIcons")); - tb->set_hover_texture( get_icon("CollapseHl","EditorIcons")); //button->set_icon(get_icon("Console","EditorIcons")); } @@ -98,11 +96,6 @@ void EditorLog::_notification(int p_what) { } -void EditorLog::_close_request() { - - _flip_request(); - -} void EditorLog::_clear_request() { @@ -122,17 +115,17 @@ void EditorLog::add_message(const String& p_msg,bool p_error) { if (p_error) { Ref<Texture> icon = get_icon("Error","EditorIcons"); log->add_image( icon ); - button->set_icon(icon); + //button->set_icon(icon); log->push_color(get_color("fg_error","Editor")); } else { - button->set_icon(Ref<Texture>()); + //button->set_icon(Ref<Texture>()); } log->add_newline(); log->add_text(p_msg); - button->set_text(p_msg); +// button->set_text(p_msg); if (p_error) log->pop(); @@ -156,21 +149,7 @@ void EditorLog::_dragged(const Point2& p_ofs) { */ -Button *EditorLog::get_button() { - return button; -} - -void EditorLog::_flip_request() { - - if (is_visible()) { - hide(); - button->show(); - } else { - show(); - button->hide(); - } -} void EditorLog::_undo_redo_cbk(void *p_self,const String& p_name) { @@ -181,21 +160,16 @@ void EditorLog::_undo_redo_cbk(void *p_self,const String& p_name) { void EditorLog::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_close_request"),&EditorLog::_close_request ); - ObjectTypeDB::bind_method(_MD("_flip_request"),&EditorLog::_flip_request ); ObjectTypeDB::bind_method(_MD("_clear_request"),&EditorLog::_clear_request ); //ObjectTypeDB::bind_method(_MD("_dragged"),&EditorLog::_dragged ); - ADD_SIGNAL( MethodInfo("close_request")); - ADD_SIGNAL( MethodInfo("show_request")); ADD_SIGNAL( MethodInfo("clear_request")); } EditorLog::EditorLog() { - VBoxContainer *vb = memnew( VBoxContainer); - add_child(vb); - vb->set_v_size_flags(SIZE_EXPAND_FILL); + VBoxContainer *vb = this; + add_constant_override("separation",get_constant("separation","VBoxContainer")); HBoxContainer *hb = memnew( HBoxContainer ); vb->add_child(hb); @@ -204,14 +178,6 @@ EditorLog::EditorLog() { title->set_h_size_flags(SIZE_EXPAND_FILL); hb->add_child(title); - - button = memnew( Button ); - button->set_text_align(Button::ALIGN_LEFT); - button->connect("pressed",this,"_flip_request"); - button->set_focus_mode(FOCUS_NONE); - button->set_clip_text(true); - button->set_tooltip("Open/Close output panel."); - //pd = memnew( PaneDrag ); //hb->add_child(pd); //pd->connect("dragged",this,"_dragged"); @@ -222,14 +188,9 @@ EditorLog::EditorLog() { clearbutton->set_text("Clear"); clearbutton->connect("pressed", this,"_clear_request"); - tb = memnew( TextureButton ); - hb->add_child(tb); - tb->connect("pressed",this,"_close_request"); - - ec = memnew( Control); vb->add_child(ec); - ec->set_custom_minimum_size(Size2(0,100)); + ec->set_custom_minimum_size(Size2(0,180)); ec->set_v_size_flags(SIZE_EXPAND_FILL); @@ -245,7 +206,6 @@ EditorLog::EditorLog() { pc->add_child(log); add_message(VERSION_FULL_NAME" (c) 2008-2016 Juan Linietsky, Ariel Manzur."); //log->add_text("Initialization Complete.\n"); //because it looks cool. - add_style_override("panel",get_stylebox("panelf","Panel")); eh.errfunc=_error_handler; eh.userdata=this; @@ -255,7 +215,6 @@ EditorLog::EditorLog() { EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk,this); - hide(); } diff --git a/tools/editor/editor_log.h b/tools/editor/editor_log.h index d7d46b70d3..699be710d8 100644 --- a/tools/editor/editor_log.h +++ b/tools/editor/editor_log.h @@ -40,15 +40,13 @@ #include "scene/gui/tool_button.h" #include "pane_drag.h" #include "os/thread.h" -class EditorLog : public PanelContainer { +class EditorLog : public VBoxContainer { - OBJ_TYPE( EditorLog, PanelContainer ); + OBJ_TYPE( EditorLog, VBoxContainer ); - Button *button; Button *clearbutton; Label *title; RichTextLabel *log; - TextureButton *tb; HBoxContainer *title_hb; // PaneDrag *pd; Control *ec; @@ -60,8 +58,6 @@ class EditorLog : public PanelContainer { Thread::ID current; // void _dragged(const Point2& p_ofs); - void _close_request(); - void _flip_request(); void _clear_request(); static void _undo_redo_cbk(void *p_self,const String& p_name); protected: @@ -73,7 +69,7 @@ public: void add_message(const String& p_msg, bool p_error=false); void deinit(); - Button *get_button(); + void clear(); EditorLog(); ~EditorLog(); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 9258637a74..3888ed23a6 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -55,6 +55,7 @@ #include "bind/core_bind.h" #include "io/zip_io.h" #include "io/config_file.h" +#include "animation_editor.h" // plugins #include "plugins/sprite_frames_editor_plugin.h" @@ -1194,75 +1195,6 @@ void EditorNode::_dialog_action(String p_file) { save_translatable_strings(p_file); } break; - case FILE_SAVE_SUBSCENE: { - - List<Node*> selection = editor_selection->get_selected_node_list(); - - if (selection.size()!=1) { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("This operation requieres a single selected node."); - accept->popup_centered_minsize(); - break; - } - - Node *base = selection.front()->get(); - - Map<Node*,Node*> reown; - reown[editor_data.get_edited_scene_root()]=base; - Node *copy = base->duplicate_and_reown(reown); - if (copy) { - - Ref<PackedScene> sdata = memnew( PackedScene ); - Error err = sdata->pack(copy); - memdelete(copy); - - if (err!=OK) { - - - current_option=-1; - //accept->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Couldn't save subscene. Likely dependencies (instances) couldn't be satisfied."); - accept->popup_centered_minsize(); - return; - } - - int flg=0; - if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources")) - flg|=ResourceSaver::FLAG_COMPRESS; - if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative")) - flg|=ResourceSaver::FLAG_RELATIVE_PATHS; - - - err = ResourceSaver::save(p_file,sdata,flg); - if (err!=OK) { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Error saving scene."); - accept->popup_centered_minsize(); - break; - } - //EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type()); - - } else { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Error duplicating scene to save it."); - accept->popup_centered_minsize(); - break; - - } - - - } break; - case FILE_SAVE_SCENE: case FILE_SAVE_AS_SCENE: { @@ -1810,7 +1742,7 @@ void EditorNode::_edit_current() { //p->add_item("All Methods",OBJECT_CALL_METHOD); - _update_keying(); + update_keying(); } void EditorNode::_resource_created() { @@ -2241,70 +2173,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { file->set_title("Save Translatable Strings"); file->popup_centered_ratio(); - - } break; - - case FILE_SAVE_SUBSCENE: { - - Node *scene = editor_data.get_edited_scene_root(); - - if (!scene) { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("This operation can't be done without a scene."); - accept->popup_centered_minsize(); - break; - } - - - List<Node*> selection = editor_selection->get_selected_node_list(); - - if (selection.size()!=1) { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("This operation requieres a single selected node."); - accept->popup_centered_minsize(); - break; - } - - Node *tocopy = selection.front()->get(); - - if (tocopy!=editor_data.get_edited_scene_root() && tocopy->get_filename()!="") { - - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("This operation can't be done on instanced scenes."); - accept->popup_centered_minsize(); - break; - } - - file->set_mode(EditorFileDialog::MODE_SAVE_FILE); - - List<String> extensions; - Ref<PackedScene> sd = memnew( PackedScene ); - ResourceSaver::get_recognized_extensions(sd,&extensions); - file->clear_filters(); - for(int i=0;i<extensions.size();i++) { - - file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); - } - - - String existing; - if (extensions.size()) { - existing="new_scene."+extensions.front()->get().to_lower(); - } - file->set_current_path(existing); - - - file->popup_centered_ratio(); - file->set_title("Save Sub-Scene As.."); } break; case FILE_SAVE_OPTIMIZED: { Node *scene = editor_data.get_edited_scene_root(); @@ -2846,11 +2714,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //optimized_presets->popup_centered_ratio(); } break; - case SETTINGS_SHOW_ANIMATION: { - - animation_panel_make_visible( ! animation_panel->is_visible() ); - - } break; case SETTINGS_LOAD_EXPORT_TEMPLATES: { @@ -3100,7 +2963,7 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (get_editor_data().get_edited_scene_root()) { if (get_editor_data().get_edited_scene_root()->get_parent()==scene_root) scene_root->remove_child(get_editor_data().get_edited_scene_root()); - animation_editor->set_root(NULL); + } get_editor_data().set_edited_scene_root(p_scene); @@ -3113,7 +2976,7 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (p_scene) { if (p_scene->get_parent()!=scene_root) scene_root->add_child(p_scene); - animation_editor->set_root(p_scene); + } } @@ -3465,7 +3328,7 @@ void EditorNode::set_current_scene(int p_idx) { if (get_editor_data().get_edited_scene_root()) { if (get_editor_data().get_edited_scene_root()->get_parent()==scene_root) scene_root->remove_child(get_editor_data().get_edited_scene_root()); - animation_editor->set_root(NULL); + } //print_line("set current 2 "); @@ -3487,7 +3350,7 @@ void EditorNode::set_current_scene(int p_idx) { if (new_scene) { if (new_scene->get_parent()!=scene_root) scene_root->add_child(new_scene); - animation_editor->set_root(new_scene); + } //print_line("set current 4 "); @@ -3623,7 +3486,18 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo add_io_error(txt); } - sdata->set_path(lpath,true); //take over path + if (ResourceCache::has(lpath)) { + //used from somewhere else? no problem! update state and replace sdata + Ref<PackedScene> ps = Ref<PackedScene>( ResourceCache::get(lpath)->cast_to<PackedScene>() ); + if (ps.is_valid()) { + ps->replace_state( sdata->get_state() ); + ps->set_last_modified_time( sdata->get_last_modified_time() ); + sdata=ps; + } + + } else { + sdata->set_path(lpath,true); //take over path + } Node*new_scene=sdata->instance(true); @@ -3742,7 +3616,7 @@ void EditorNode::_instance_request(const String& p_path){ void EditorNode::_property_keyed(const String& p_keyed,const Variant& p_value,bool p_advance) { - animation_editor->insert_value_key(p_keyed,p_value,p_advance); + AnimationPlayerEditor::singleton->get_key_editor()->insert_value_key(p_keyed,p_value,p_advance); } void EditorNode::_transform_keyed(Object *sp,const String& p_sub,const Transform& p_key) { @@ -3750,16 +3624,16 @@ void EditorNode::_transform_keyed(Object *sp,const String& p_sub,const Transform Spatial *s=sp->cast_to<Spatial>(); if (!s) return; - animation_editor->insert_transform_key(s,p_sub,p_key); + AnimationPlayerEditor::singleton->get_key_editor()->insert_transform_key(s,p_sub,p_key); } -void EditorNode::_update_keying() { +void EditorNode::update_keying() { //print_line("KR: "+itos(p_enabled)); bool valid=false; - if (animation_editor->has_keying()) { + if (AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) { if (editor_history.get_path_size()>=1) { @@ -3793,6 +3667,7 @@ void EditorNode::_show_messages() { } +#if 0 void EditorNode::animation_panel_make_visible(bool p_visible) { if (!p_visible) { @@ -3805,6 +3680,7 @@ void EditorNode::animation_panel_make_visible(bool p_visible) { settings_menu->get_popup()->set_item_checked(idx,p_visible); } + void EditorNode::animation_editor_make_visible(bool p_visible) { if (p_visible) { @@ -3828,7 +3704,7 @@ void EditorNode::animation_editor_make_visible(bool p_visible) { animation_editor->set_keying(p_visible); } - +#endif void EditorNode::_add_to_recent_scenes(const String& p_scene) { String base="_"+Globals::get_singleton()->get_resource_path().replace("\\","::").replace("/","::"); @@ -3921,11 +3797,6 @@ void EditorNode::_update_recent_scenes() { } -void EditorNode::hide_animation_player_editors() { - - emit_signal("hide_animation_player_editors"); -} - void EditorNode::_quick_opened() { if (current_option==FILE_QUICK_OPEN_FILE) { @@ -4096,90 +3967,6 @@ void EditorNode::progress_end_task_bg(const String& p_task) { } -void EditorNode::_bind_methods() { - - - ObjectTypeDB::bind_method("_menu_option",&EditorNode::_menu_option); - ObjectTypeDB::bind_method("_menu_confirm_current",&EditorNode::_menu_confirm_current); - ObjectTypeDB::bind_method("_dialog_action",&EditorNode::_dialog_action); - ObjectTypeDB::bind_method("_resource_selected",&EditorNode::_resource_selected,DEFVAL("")); - ObjectTypeDB::bind_method("_property_editor_forward",&EditorNode::_property_editor_forward); - ObjectTypeDB::bind_method("_property_editor_back",&EditorNode::_property_editor_back); - ObjectTypeDB::bind_method("_editor_select",&EditorNode::_editor_select); - ObjectTypeDB::bind_method("_node_renamed",&EditorNode::_node_renamed); - ObjectTypeDB::bind_method("edit_node",&EditorNode::edit_node); - ObjectTypeDB::bind_method("_imported",&EditorNode::_imported); - ObjectTypeDB::bind_method("_unhandled_input",&EditorNode::_unhandled_input); - - ObjectTypeDB::bind_method("_get_scene_metadata",&EditorNode::_get_scene_metadata); - ObjectTypeDB::bind_method("set_edited_scene",&EditorNode::set_edited_scene); - ObjectTypeDB::bind_method("open_request",&EditorNode::open_request); - ObjectTypeDB::bind_method("_instance_request",&EditorNode::_instance_request); - ObjectTypeDB::bind_method("_update_keying",&EditorNode::_update_keying); - ObjectTypeDB::bind_method("_property_keyed",&EditorNode::_property_keyed); - ObjectTypeDB::bind_method("_transform_keyed",&EditorNode::_transform_keyed); - ObjectTypeDB::bind_method("_close_messages",&EditorNode::_close_messages); - ObjectTypeDB::bind_method("_show_messages",&EditorNode::_show_messages); - ObjectTypeDB::bind_method("_vp_resized",&EditorNode::_vp_resized); - ObjectTypeDB::bind_method("_quick_opened",&EditorNode::_quick_opened); - ObjectTypeDB::bind_method("_quick_run",&EditorNode::_quick_run); - - ObjectTypeDB::bind_method("_resource_created",&EditorNode::_resource_created); - - ObjectTypeDB::bind_method("_import_action",&EditorNode::_import_action); - //ObjectTypeDB::bind_method("_import",&EditorNode::_import); -// ObjectTypeDB::bind_method("_import_conflicts_solved",&EditorNode::_import_conflicts_solved); - ObjectTypeDB::bind_method("_open_recent_scene",&EditorNode::_open_recent_scene); -// ObjectTypeDB::bind_method("_open_recent_scene_confirm",&EditorNode::_open_recent_scene_confirm); - - ObjectTypeDB::bind_method("_save_optimized",&EditorNode::_save_optimized); - ObjectTypeDB::bind_method(_MD("animation_panel_make_visible","enable"),&EditorNode::animation_panel_make_visible); - - ObjectTypeDB::bind_method("stop_child_process",&EditorNode::stop_child_process); - - ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed); - ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed); - ObjectTypeDB::bind_method("_dock_select_draw",&EditorNode::_dock_select_draw); - ObjectTypeDB::bind_method("_dock_select_input",&EditorNode::_dock_select_input); - ObjectTypeDB::bind_method("_dock_pre_popup",&EditorNode::_dock_pre_popup); - ObjectTypeDB::bind_method("_dock_split_dragged",&EditorNode::_dock_split_dragged); - ObjectTypeDB::bind_method("_save_docks",&EditorNode::_save_docks); - ObjectTypeDB::bind_method("_dock_popup_exit",&EditorNode::_dock_popup_exit); - ObjectTypeDB::bind_method("_dock_move_left",&EditorNode::_dock_move_left); - ObjectTypeDB::bind_method("_dock_move_right",&EditorNode::_dock_move_right); - - ObjectTypeDB::bind_method("_layout_menu_option",&EditorNode::_layout_menu_option); - - ObjectTypeDB::bind_method("set_current_scene",&EditorNode::set_current_scene); - ObjectTypeDB::bind_method("set_current_version",&EditorNode::set_current_version); - ObjectTypeDB::bind_method("_scene_tab_changed",&EditorNode::_scene_tab_changed); - ObjectTypeDB::bind_method("_scene_tab_closed",&EditorNode::_scene_tab_closed); - ObjectTypeDB::bind_method("_scene_tab_script_edited",&EditorNode::_scene_tab_script_edited); - ObjectTypeDB::bind_method("_set_main_scene_state",&EditorNode::_set_main_scene_state); - ObjectTypeDB::bind_method("_update_scene_tabs",&EditorNode::_update_scene_tabs); - - ObjectTypeDB::bind_method("_prepare_history",&EditorNode::_prepare_history); - ObjectTypeDB::bind_method("_select_history",&EditorNode::_select_history); - - ObjectTypeDB::bind_method("_toggle_search_bar",&EditorNode::_toggle_search_bar); - ObjectTypeDB::bind_method("_clear_search_box",&EditorNode::_clear_search_box); - ObjectTypeDB::bind_method("_clear_undo_history",&EditorNode::_clear_undo_history); - - ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); - ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); - ObjectTypeDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base); - - ADD_SIGNAL( MethodInfo("play_pressed") ); - ADD_SIGNAL( MethodInfo("pause_pressed") ); - ADD_SIGNAL( MethodInfo("stop_pressed") ); - ADD_SIGNAL( MethodInfo("hide_animation_player_editors") ); - ADD_SIGNAL( MethodInfo("request_help") ); - ADD_SIGNAL( MethodInfo("script_add_function_request",PropertyInfo(Variant::OBJECT,"obj"),PropertyInfo(Variant::STRING,"function"),PropertyInfo(Variant::STRING_ARRAY,"args")) ); - ADD_SIGNAL( MethodInfo("resource_saved",PropertyInfo(Variant::OBJECT,"obj")) ); - - - -} Ref<Texture> EditorNode::_file_dialog_get_icon(const String& p_path) { @@ -4770,6 +4557,173 @@ void EditorNode::_clear_search_box() { property_editor->update_tree(); } +ToolButton *EditorNode::add_bottom_panel_item(String p_text,Control *p_item) { + + ToolButton *tb = memnew( ToolButton ); + tb->connect("toggled",this,"_bottom_panel_switch",varray(bottom_panel_items.size())); + tb->set_text(p_text); + tb->set_toggle_mode(true); + tb->set_focus_mode(Control::FOCUS_NONE); + bottom_panel_vb->add_child(p_item); + bottom_panel_hb->raise(); + bottom_panel_hb->add_child(tb); + p_item->set_v_size_flags(Control::SIZE_EXPAND_FILL); + p_item->hide(); + BottomPanelItem bpi; + bpi.button=tb; + bpi.control=p_item; + bpi.name=p_text; + bottom_panel_items.push_back(bpi); + + return tb; + +} + +void EditorNode::hide_bottom_panel() { + + _bottom_panel_switch(false,0); + +} + +void EditorNode::make_bottom_panel_item_visible(Control *p_item) { + + for(int i=0;i<bottom_panel_items.size();i++) { + + if (bottom_panel_items[i].control==p_item) { + _bottom_panel_switch(true,i); + break; + } + } +} + +void EditorNode::raise_bottom_panel_item(Control *p_item) { + + for(int i=0;i<bottom_panel_items.size();i++) { + + if (bottom_panel_items[i].control==p_item) { + bottom_panel_items[i].button->raise(); + SWAP( bottom_panel_items[i], bottom_panel_items[bottom_panel_items.size()-1]); + break; + } + } + + for(int i=0;i<bottom_panel_items.size();i++) { + bottom_panel_items[i].button->disconnect("toggled",this,"_bottom_panel_switch"); + bottom_panel_items[i].button->connect("toggled",this,"_bottom_panel_switch",varray(i)); + } + +} + +void EditorNode::_bottom_panel_switch(bool p_enable,int p_idx) { + + ERR_FAIL_INDEX(p_idx,bottom_panel_items.size()); + + + + if (p_enable) { + for(int i=0;i<bottom_panel_items.size();i++) { + + bottom_panel_items[i].button->set_pressed(i==p_idx); + bottom_panel_items[i].control->set_hidden(i!=p_idx); + } + center_split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE); + center_split->set_collapsed(false); + } else { + for(int i=0;i<bottom_panel_items.size();i++) { + + bottom_panel_items[i].button->set_pressed(false); + bottom_panel_items[i].control->set_hidden(true); + } + center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN); + center_split->set_collapsed(true); + } +} + +void EditorNode::_bind_methods() { + + + ObjectTypeDB::bind_method("_menu_option",&EditorNode::_menu_option); + ObjectTypeDB::bind_method("_menu_confirm_current",&EditorNode::_menu_confirm_current); + ObjectTypeDB::bind_method("_dialog_action",&EditorNode::_dialog_action); + ObjectTypeDB::bind_method("_resource_selected",&EditorNode::_resource_selected,DEFVAL("")); + ObjectTypeDB::bind_method("_property_editor_forward",&EditorNode::_property_editor_forward); + ObjectTypeDB::bind_method("_property_editor_back",&EditorNode::_property_editor_back); + ObjectTypeDB::bind_method("_editor_select",&EditorNode::_editor_select); + ObjectTypeDB::bind_method("_node_renamed",&EditorNode::_node_renamed); + ObjectTypeDB::bind_method("edit_node",&EditorNode::edit_node); + ObjectTypeDB::bind_method("_imported",&EditorNode::_imported); + ObjectTypeDB::bind_method("_unhandled_input",&EditorNode::_unhandled_input); + + ObjectTypeDB::bind_method("_get_scene_metadata",&EditorNode::_get_scene_metadata); + ObjectTypeDB::bind_method("set_edited_scene",&EditorNode::set_edited_scene); + ObjectTypeDB::bind_method("open_request",&EditorNode::open_request); + ObjectTypeDB::bind_method("_instance_request",&EditorNode::_instance_request); + ObjectTypeDB::bind_method("update_keying",&EditorNode::update_keying); + ObjectTypeDB::bind_method("_property_keyed",&EditorNode::_property_keyed); + ObjectTypeDB::bind_method("_transform_keyed",&EditorNode::_transform_keyed); + ObjectTypeDB::bind_method("_close_messages",&EditorNode::_close_messages); + ObjectTypeDB::bind_method("_show_messages",&EditorNode::_show_messages); + ObjectTypeDB::bind_method("_vp_resized",&EditorNode::_vp_resized); + ObjectTypeDB::bind_method("_quick_opened",&EditorNode::_quick_opened); + ObjectTypeDB::bind_method("_quick_run",&EditorNode::_quick_run); + + ObjectTypeDB::bind_method("_resource_created",&EditorNode::_resource_created); + + ObjectTypeDB::bind_method("_import_action",&EditorNode::_import_action); + //ObjectTypeDB::bind_method("_import",&EditorNode::_import); +// ObjectTypeDB::bind_method("_import_conflicts_solved",&EditorNode::_import_conflicts_solved); + ObjectTypeDB::bind_method("_open_recent_scene",&EditorNode::_open_recent_scene); +// ObjectTypeDB::bind_method("_open_recent_scene_confirm",&EditorNode::_open_recent_scene_confirm); + + ObjectTypeDB::bind_method("_save_optimized",&EditorNode::_save_optimized); + + ObjectTypeDB::bind_method("stop_child_process",&EditorNode::stop_child_process); + + ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed); + ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed); + ObjectTypeDB::bind_method("_dock_select_draw",&EditorNode::_dock_select_draw); + ObjectTypeDB::bind_method("_dock_select_input",&EditorNode::_dock_select_input); + ObjectTypeDB::bind_method("_dock_pre_popup",&EditorNode::_dock_pre_popup); + ObjectTypeDB::bind_method("_dock_split_dragged",&EditorNode::_dock_split_dragged); + ObjectTypeDB::bind_method("_save_docks",&EditorNode::_save_docks); + ObjectTypeDB::bind_method("_dock_popup_exit",&EditorNode::_dock_popup_exit); + ObjectTypeDB::bind_method("_dock_move_left",&EditorNode::_dock_move_left); + ObjectTypeDB::bind_method("_dock_move_right",&EditorNode::_dock_move_right); + + ObjectTypeDB::bind_method("_layout_menu_option",&EditorNode::_layout_menu_option); + + ObjectTypeDB::bind_method("set_current_scene",&EditorNode::set_current_scene); + ObjectTypeDB::bind_method("set_current_version",&EditorNode::set_current_version); + ObjectTypeDB::bind_method("_scene_tab_changed",&EditorNode::_scene_tab_changed); + ObjectTypeDB::bind_method("_scene_tab_closed",&EditorNode::_scene_tab_closed); + ObjectTypeDB::bind_method("_scene_tab_script_edited",&EditorNode::_scene_tab_script_edited); + ObjectTypeDB::bind_method("_set_main_scene_state",&EditorNode::_set_main_scene_state); + ObjectTypeDB::bind_method("_update_scene_tabs",&EditorNode::_update_scene_tabs); + + ObjectTypeDB::bind_method("_prepare_history",&EditorNode::_prepare_history); + ObjectTypeDB::bind_method("_select_history",&EditorNode::_select_history); + + ObjectTypeDB::bind_method("_toggle_search_bar",&EditorNode::_toggle_search_bar); + ObjectTypeDB::bind_method("_clear_search_box",&EditorNode::_clear_search_box); + ObjectTypeDB::bind_method("_clear_undo_history",&EditorNode::_clear_undo_history); + + ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); + ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); + ObjectTypeDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base); + ObjectTypeDB::bind_method(_MD("_bottom_panel_switch"), &EditorNode::_bottom_panel_switch); + + + ADD_SIGNAL( MethodInfo("play_pressed") ); + ADD_SIGNAL( MethodInfo("pause_pressed") ); + ADD_SIGNAL( MethodInfo("stop_pressed") ); + ADD_SIGNAL( MethodInfo("request_help") ); + ADD_SIGNAL( MethodInfo("script_add_function_request",PropertyInfo(Variant::OBJECT,"obj"),PropertyInfo(Variant::STRING,"function"),PropertyInfo(Variant::STRING_ARRAY,"args")) ); + ADD_SIGNAL( MethodInfo("resource_saved",PropertyInfo(Variant::OBJECT,"obj")) ); + + + +} + EditorNode::EditorNode() { EditorHelp::generate_doc(); //before any editor classes are crated @@ -5086,8 +5040,9 @@ EditorNode::EditorNode() { //scene_root_base->add_child(scene_root); - scene_root->set_meta("_editor_disable_input",true); + //scene_root->set_meta("_editor_disable_input",true); VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport(),true); + scene_root->set_disable_input(true); scene_root->set_as_audio_listener_2d(true); scene_root->set_size_override(true,Size2(Globals::get_singleton()->get("display/width"),Globals::get_singleton()->get("display/height"))); @@ -5102,44 +5057,6 @@ EditorNode::EditorNode() { scene_root_parent->add_child(viewport); - PanelContainer *pc = memnew( PanelContainer ); - top_split->add_child(pc); - animation_vb = memnew( VBoxContainer ); - animation_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); - pc->add_child(animation_vb); - animation_panel=pc; - animation_panel->hide(); - - - HBoxContainer *animation_hb = memnew( HBoxContainer); - animation_vb->add_child(animation_hb); - - Label *l= memnew( Label ); - l->set_text("Animation:"); - //l->set_h_size_flags(Control::SIZE_); - animation_hb->add_child(l); - - animation_panel_hb = memnew( HBoxContainer ); - animation_hb->add_child(animation_panel_hb); - animation_panel_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - - - /*pd_anim = memnew( PaneDrag ); - animation_hb->add_child(pd_anim); - pd_anim->connect("dragged",this,"_dragged"); - pd_anim->set_default_cursor_shape(Control::CURSOR_MOVE); - pd_anim->hide();*/ - - anim_close = memnew( TextureButton ); - animation_hb->add_child(anim_close); - anim_close->connect("pressed",this,"animation_panel_make_visible",make_binds(false)); - anim_close->set_normal_texture( anim_close->get_icon("Close","EditorIcons")); - anim_close->set_hover_texture( anim_close->get_icon("CloseHover","EditorIcons")); - anim_close->set_pressed_texture( anim_close->get_icon("Close","EditorIcons")); - - - - PanelContainer *top_region = memnew( PanelContainer ); top_region->add_style_override("panel",gui_base->get_stylebox("hover","Button")); HBoxContainer *left_menu_hb = memnew( HBoxContainer ); @@ -5191,7 +5108,6 @@ EditorNode::EditorNode() { pm_export->set_name("Export"); p->add_child(pm_export); p->add_submenu_item("Convert To..","Export"); - pm_export->add_item("Subscene..",FILE_SAVE_SUBSCENE); pm_export->add_item("Translatable Strings..",FILE_DUMP_STRINGS); pm_export->add_separator(); pm_export->add_item("MeshLibrary..",FILE_EXPORT_MESH_LIBRARY); @@ -5459,8 +5375,6 @@ EditorNode::EditorNode() { editor_layouts->connect("item_pressed",this,"_layout_menu_option"); p->add_submenu_item("Editor Layout", "Layouts"); p->add_separator(); - p->add_check_item("Show Animation",SETTINGS_SHOW_ANIMATION,KEY_MASK_CMD+KEY_N); - p->add_separator(); p->add_item("Install Export Templates",SETTINGS_LOAD_EXPORT_TEMPLATES); p->add_separator(); p->add_item("About",SETTINGS_ABOUT); @@ -5624,7 +5538,7 @@ EditorNode::EditorNode() { prop_editor_base->add_child(search_bar); search_bar->hide(); - l = memnew( Label("Search: ") ); + Label *l = memnew( Label("Search: ") ); search_bar->add_child(l); search_box = memnew( LineEdit ); @@ -5672,37 +5586,40 @@ EditorNode::EditorNode() { _update_layouts_menu(); - log = memnew( EditorLog ); - center_split->add_child(log); - log->connect("close_request",this,"_close_messages"); - log->connect("show_request",this,"_show_messages"); - //left_split->set_dragger_visible(false); + bottom_panel = memnew( PanelContainer ); + bottom_panel->add_style_override("panel",gui_base->get_stylebox("panelf","Panel")); + center_split->add_child(bottom_panel); + center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN); + bottom_panel_vb = memnew( VBoxContainer ); + bottom_panel->add_child(bottom_panel_vb); + //bottom_panel_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); - old_split_ofs=0; + bottom_panel_hb = memnew( HBoxContainer ); + bottom_panel_vb->add_child(bottom_panel_hb); - animation_editor = memnew( AnimationKeyEditor(get_undo_redo(),&editor_history,editor_selection) ); - animation_editor->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,0); - animation_editor->set_margin(MARGIN_BOTTOM,200); - animation_editor->connect("keying_changed",this,"_update_keying"); - animation_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); + log = memnew( EditorLog ); + add_bottom_panel_item("Output",log); - animation_vb->add_child(animation_editor); - center_split->connect("resized",this,"_vp_resized"); + //left_split->set_dragger_visible(false); - animation_editor->hide(); + old_split_ofs=0; + + center_split->connect("resized",this,"_vp_resized"); + /*PanelContainer *bottom_pc = memnew( PanelContainer ); srt->add_child(bottom_pc); bottom_hb = memnew( HBoxContainer ); bottom_pc->add_child(bottom_hb);*/ - center_vb->add_child( log->get_button() ); - log->get_button()->set_h_size_flags(Control::SIZE_EXPAND_FILL); + +// center_vb->add_child( log->get_button() ); +// log->get_button()->set_h_size_flags(Control::SIZE_EXPAND_FILL); //progress_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -5902,7 +5819,7 @@ EditorNode::EditorNode() { file_templates->connect("file_selected", this,"_dialog_action"); property_editor->connect("resource_selected", this,"_resource_selected"); property_editor->connect("property_keyed", this,"_property_keyed"); - animation_editor->connect("resource_selected", this,"_resource_selected"); + //plugin stuff file_server = memnew( EditorFileServer ); @@ -5928,10 +5845,15 @@ EditorNode::EditorNode() { editor_import_export->add_export_plugin( Ref<EditorSampleExportPlugin>( memnew(EditorSampleExportPlugin))); editor_import_export->add_export_plugin( Ref<EditorSceneExportPlugin>( memnew(EditorSceneExportPlugin))); + + add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) ); add_editor_plugin( memnew( SpatialEditorPlugin(this) ) ); add_editor_plugin( memnew( ScriptEditorPlugin(this) ) ); - add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); + + //more visually meaningful to have this later + raise_bottom_panel_item(AnimationPlayerEditor::singleton); + add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) ); add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,false) ) ); add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) ); @@ -5964,7 +5886,8 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( Polygon2DEditorPlugin(this) ) ); add_editor_plugin( memnew( LightOccluder2DEditorPlugin(this) ) ); add_editor_plugin( memnew( NavigationPolygonEditorPlugin(this) ) ); - add_editor_plugin( memnew( ColorRampEditorPlugin(this) ) ); + add_editor_plugin( memnew( ColorRampEditorPlugin(this,true) ) ); + add_editor_plugin( memnew( ColorRampEditorPlugin(this,false) ) ); add_editor_plugin( memnew( CollisionShape2DEditorPlugin(this) ) ); for(int i=0;i<EditorPlugins::get_plugin_count();i++) diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index d8d76d47cc..4dc942c023 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -56,7 +56,7 @@ #include "tools/editor/editor_run.h" #include "tools/editor/pane_drag.h" -#include "tools/editor/animation_editor.h" + #include "tools/editor/script_create_dialog.h" #include "tools/editor/run_settings_dialog.h" #include "tools/editor/project_settings.h" @@ -100,13 +100,12 @@ typedef void (*EditorNodeInitCallback)(); class EditorNode : public Node { OBJ_TYPE( EditorNode, Node ); - + enum { - - HISTORY_SIZE=64 + HISTORY_SIZE=64 }; + enum MenuOptions { - FILE_NEW_SCENE, FILE_NEW_INHERITED_SCENE, FILE_OPEN_SCENE, @@ -119,7 +118,6 @@ class EditorNode : public Node { FILE_EXPORT_MESH_LIBRARY, FILE_EXPORT_TILESET, FILE_SAVE_OPTIMIZED, - FILE_SAVE_SUBSCENE, FILE_DUMP_STRINGS, FILE_OPEN_RECENT, FILE_OPEN_OLD_SCENE, @@ -171,7 +169,6 @@ class EditorNode : public Node { SETTINGS_LAYOUT_SAVE, SETTINGS_LAYOUT_DELETE, SETTINGS_LAYOUT_DEFAULT, - SETTINGS_SHOW_ANIMATION, SETTINGS_LOAD_EXPORT_TEMPLATES, SETTINGS_HELP, SETTINGS_ABOUT, @@ -232,7 +229,6 @@ class EditorNode : public Node { Control *vp_base; PaneDrag *pd; //PaneDrag *pd_anim; - TextureButton *anim_close; Panel *menu_panel; @@ -252,7 +248,6 @@ class EditorNode : public Node { ToolButton *pause_button; ToolButton *stop_button; ToolButton *run_settings_button; - ToolButton *animation_menu; ToolButton *play_scene_button; ToolButton *play_custom_scene_button; MenuButton *debug_button; @@ -318,15 +313,12 @@ class EditorNode : public Node { String defer_export_platform; bool defer_export_debug; Node *_last_instanced_scene; - PanelContainer *animation_panel; - HBoxContainer *animation_panel_hb; - VBoxContainer *animation_vb; EditorPath *editor_path; ToolButton *resource_new_button; ToolButton *resource_load_button; MenuButton *resource_save_button; MenuButton *editor_history_menu; - AnimationKeyEditor *animation_editor; + EditorLog *log; CenterContainer *tabs_center; EditorQuickOpen *quick_open; @@ -389,6 +381,21 @@ class EditorNode : public Node { EditorFileServer *file_server; + + struct BottomPanelItem { + String name; + Control *control; + ToolButton *button; + }; + + Vector<BottomPanelItem> bottom_panel_items; + + PanelContainer *bottom_panel; + HBoxContainer *bottom_panel_hb; + VBoxContainer *bottom_panel_vb; + + void _bottom_panel_switch(bool p_enable, int p_idx); + String external_file; List<String> previous_scenes; bool opening_prev; @@ -438,7 +445,6 @@ class EditorNode : public Node { void _property_keyed(const String& p_keyed, const Variant& p_value, bool p_advance); void _transform_keyed(Object *sp,const String& p_sub,const Transform& p_key); - void _update_keying(); void _hide_top_editors(); void _quick_opened(); void _quick_run(const String& p_resource); @@ -588,13 +594,10 @@ public: static EditorLog *get_log() { return singleton->log; } Control* get_viewport(); - AnimationKeyEditor *get_animation_editor() const { return animation_editor; } - Control *get_animation_panel() { return animation_vb; } - HBoxContainer *get_animation_panel_hb() { return animation_panel_hb; } - void animation_editor_make_visible(bool p_visible); - void hide_animation_player_editors(); - void animation_panel_make_visible(bool p_visible); + //void animation_editor_make_visible(bool p_visible); + //void hide_animation_player_editors(); + //void animation_panel_make_visible(bool p_visible); void set_edited_scene(Node *p_scene); @@ -614,6 +617,7 @@ public: void set_current_scene(int p_idx); static EditorData& get_editor_data() { return singleton->editor_data; } + EditorHistory * get_editor_history() { return &editor_history; } static VSplitContainer *get_top_split() { return singleton->top_split; } @@ -662,6 +666,14 @@ public: void save_layout(); + void update_keying(); + + + ToolButton* add_bottom_panel_item(String p_text,Control *p_item); + void make_bottom_panel_item_visible(Control *p_item); + void raise_bottom_panel_item(Control *p_item); + void hide_bottom_panel(); + EditorNode(); ~EditorNode(); void get_singleton(const char* arg1, bool arg2); diff --git a/tools/editor/icons/icon_add_track.png b/tools/editor/icons/icon_add_track.png Binary files differindex 3862597828..6a90950173 100644 --- a/tools/editor/icons/icon_add_track.png +++ b/tools/editor/icons/icon_add_track.png diff --git a/tools/editor/icons/icon_create_new_scene_from.png b/tools/editor/icons/icon_create_new_scene_from.png Binary files differnew file mode 100644 index 0000000000..e747c4f59f --- /dev/null +++ b/tools/editor/icons/icon_create_new_scene_from.png diff --git a/tools/editor/icons/icon_pin.png b/tools/editor/icons/icon_pin.png Binary files differindex 037352137d..4862ee8f71 100644 --- a/tools/editor/icons/icon_pin.png +++ b/tools/editor/icons/icon_pin.png diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp index 12a707b2ca..b56140b32d 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.cpp +++ b/tools/editor/plugins/animation_player_editor_plugin.cpp @@ -32,20 +32,20 @@ #include "io/resource_saver.h" #include "os/keyboard.h" #include "tools/editor/editor_settings.h" +#include "tools/editor/animation_editor.h" void AnimationPlayerEditor::_node_removed(Node *p_node) { if (player && player == p_node) { player=NULL; - hide(); + set_process(false); - if (edit_anim->is_pressed()) { - editor->get_animation_editor()->set_animation(Ref<Animation>()); - editor->get_animation_editor()->set_root(NULL); - editor->animation_editor_make_visible(false); - edit_anim->set_pressed(false); - } + key_editor->set_animation(Ref<Animation>()); + key_editor->set_root(NULL); + _update_player(); + //editor->animation_editor_make_visible(false); + } } @@ -72,19 +72,18 @@ void AnimationPlayerEditor::_notification(int p_what) { Ref<Animation> anim = player->get_animation(animname); if (!anim.is_null()) { - seek->set_max(anim->get_length()); + frame->set_max(anim->get_length()); } } } - seek->set_val(player->get_current_animation_pos()); - if (edit_anim->is_pressed()) - editor->get_animation_editor()->set_anim_pos(player->get_current_animation_pos()); + frame->set_val(player->get_current_animation_pos()); + key_editor->set_anim_pos(player->get_current_animation_pos()); EditorNode::get_singleton()->get_property_editor()->refresh(); } else if (last_active) { //need the last frame after it stopped - seek->set_val(player->get_current_animation_pos()); + frame->set_val(player->get_current_animation_pos()); } last_active=player->is_playing(); @@ -103,7 +102,7 @@ void AnimationPlayerEditor::_notification(int p_what) { save_anim->set_icon(get_icon("Save", "EditorIcons")); save_anim->get_popup()->connect("item_pressed", this, "_animation_save_menu"); remove_anim->set_icon( get_icon("Remove","EditorIcons") ); - edit_anim->set_icon( get_icon("Edit","EditorIcons") ); + blend_anim->set_icon( get_icon("Blend","EditorIcons") ); play->set_icon( get_icon("PlayStart","EditorIcons") ); play_from->set_icon( get_icon("Play","EditorIcons") ); @@ -113,13 +112,14 @@ void AnimationPlayerEditor::_notification(int p_what) { autoplay_icon=get_icon("AutoPlay","EditorIcons"); stop->set_icon( get_icon("Stop","EditorIcons") ); resource_edit_anim->set_icon( get_icon("EditResource","EditorIcons") ); - pin->set_normal_texture(get_icon("Pin","EditorIcons") ); - pin->set_pressed_texture( get_icon("PinPressed","EditorIcons") ); + pin->set_icon(get_icon("Pin","EditorIcons") ); tool_anim->set_icon(get_icon("Tools","EditorIcons")); tool_anim->get_popup()->connect("item_pressed",this,"_animation_tool_menu"); blend_editor.next->connect("text_changed",this,"_blend_editor_next_changed"); + nodename->set_icon(get_icon("AnimationPlayer","EditorIcons")); + /* anim_editor_load->set_normal_texture( get_icon("AnimGet","EditorIcons")); anim_editor_store->set_normal_texture( get_icon("AnimSet","EditorIcons")); @@ -295,22 +295,25 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { player->set_current_animation( current ); Ref<Animation> anim = player->get_animation(current); - if (edit_anim->is_pressed()) { - Ref<Animation> anim = player->get_animation(current); - editor->get_animation_editor()->set_animation(anim); + { + + key_editor->set_animation(anim); Node *root = player->get_node(player->get_root()); if (root) { - editor->get_animation_editor()->set_root(root); + key_editor->set_root(root); } } - seek->set_max(anim->get_length()); + frame->set_max(anim->get_length()); + if (anim->get_step()) + frame->set_step(anim->get_step()); + else + frame->set_step(0.00001); + } else { - if (edit_anim->is_pressed()) { - editor->get_animation_editor()->set_animation(Ref<Animation>()); - editor->get_animation_editor()->set_root(NULL); - } + key_editor->set_animation(Ref<Animation>()); + key_editor->set_root(NULL); } @@ -631,7 +634,7 @@ Dictionary AnimationPlayerEditor::get_state() const { if (is_visible() && player) { d["player"]=EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); d["animation"]=player->get_current_animation(); - d["editing"]=edit_anim->is_pressed(); + } return d; @@ -648,16 +651,12 @@ void AnimationPlayerEditor::set_state(const Dictionary& p_state) { show(); set_process(true); ensure_visibility(); - EditorNode::get_singleton()->animation_panel_make_visible(true); +// EditorNode::get_singleton()->animation_panel_make_visible(true); if (p_state.has("animation")) { String anim = p_state["animation"]; _select_anim_by_name(anim); - if (p_state.has("editing") && p_state["editing"]) { - - edit_anim->set_pressed(true); - _animation_edit(); - } + _animation_edit(); } } @@ -678,36 +677,22 @@ void AnimationPlayerEditor::_animation_resource_edit() { void AnimationPlayerEditor::_animation_edit() { -// if (animation->get_item_count()==0) -// return; - - if (edit_anim->is_pressed()) { - editor->animation_editor_make_visible(true); - - //editor->get_animation_editor()->set_root(player->get_roo); - get root pending - if (animation->get_item_count()) { - String current = animation->get_item_text(animation->get_selected()); - Ref<Animation> anim = player->get_animation(current); - editor->get_animation_editor()->set_animation(anim); - Node *root = player->get_node(player->get_root()); - if (root) { - editor->get_animation_editor()->set_root(root); - } + if (animation->get_item_count()) { + String current = animation->get_item_text(animation->get_selected()); + Ref<Animation> anim = player->get_animation(current); + key_editor->set_animation(anim); + Node *root = player->get_node(player->get_root()); + if (root) { + key_editor->set_root(root); + } - } else { + } else { - editor->get_animation_editor()->set_animation(Ref<Animation>()); - editor->get_animation_editor()->set_root(NULL); + key_editor->set_animation(Ref<Animation>()); + key_editor->set_root(NULL); - } - } else { - editor->animation_editor_make_visible(false); - editor->get_animation_editor()->set_animation(Ref<Animation>()); - editor->get_animation_editor()->set_root(NULL); } - //get_scene()->get_root_node()->call("_resource_selected",anim,""); - } void AnimationPlayerEditor::_dialog_action(String p_file) { @@ -800,16 +785,21 @@ void AnimationPlayerEditor::_update_animation() { void AnimationPlayerEditor::_update_player() { - if (!player) - return; updating=true; List<StringName> animlist; - player->get_animation_list(&animlist); + if (player) + player->get_animation_list(&animlist); animation->clear(); - nodename->set_text(player->get_name()); + if (player) + nodename->set_text(player->get_name()); + else + nodename->set_text("<empty>"); + + add_anim->set_disabled(player==NULL); + load_anim->set_disabled(player==NULL); stop->set_disabled(animlist.size()==0); play->set_disabled(animlist.size()==0); play_bw->set_disabled(animlist.size()==0); @@ -837,6 +827,9 @@ void AnimationPlayerEditor::_update_player() { } + if (!player) + return; + updating=false; if (active_idx!=-1) { animation->select(active_idx); @@ -852,17 +845,14 @@ void AnimationPlayerEditor::_update_player() { //pause->set_pressed(player->is_paused()); - if (edit_anim->is_pressed()) { - - if (animation->get_item_count()) { - String current = animation->get_item_text(animation->get_selected()); - Ref<Animation> anim = player->get_animation(current); - editor->get_animation_editor()->set_animation(anim); - Node *root = player->get_node(player->get_root()); - if (root) { - editor->get_animation_editor()->set_root(root); - } + if (animation->get_item_count()) { + String current = animation->get_item_text(animation->get_selected()); + Ref<Animation> anim = player->get_animation(current); + key_editor->set_animation(anim); + Node *root = player->get_node(player->get_root()); + if (root) { + key_editor->set_root(root); } } @@ -958,7 +948,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value) { Ref<Animation> anim; anim=player->get_animation(current); - float pos = anim->get_length() * (p_value / seek->get_max()); + float pos = anim->get_length() * (p_value / frame->get_max()); if (player->is_valid()) { float cpos = player->get_current_animation_pos(); @@ -968,8 +958,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value) { player->seek(pos,true); } - if (edit_anim->is_pressed()) - editor->get_animation_editor()->set_anim_pos(pos); + key_editor->set_anim_pos(pos); updating=true; }; @@ -999,19 +988,19 @@ void AnimationPlayerEditor::_editor_store() { String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); - if (editor->get_animation_editor()->get_current_animation()==anim) + if (key_editor->get_current_animation()==anim) return; //already there undo_redo->create_action("Store anim in editor"); - undo_redo->add_do_method(editor->get_animation_editor(),"set_animation",anim); - undo_redo->add_undo_method(editor->get_animation_editor(),"remove_animation",anim); + undo_redo->add_do_method(key_editor,"set_animation",anim); + undo_redo->add_undo_method(key_editor,"remove_animation",anim); undo_redo->commit_action(); } void AnimationPlayerEditor::_editor_load(){ - Ref<Animation> anim = editor->get_animation_editor()->get_current_animation(); + Ref<Animation> anim = key_editor->get_current_animation(); if (anim.is_null()) return; @@ -1059,7 +1048,16 @@ void AnimationPlayerEditor::_editor_load(){ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) { - seek->set_max(p_len); + frame->set_max(p_len); + +} + +void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) { + + if (p_len) + frame->set_step(p_len); + else + frame->set_step(0.00001); } @@ -1074,7 +1072,7 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos) { if (player->is_playing() ) return; - seek->set_val(p_pos); + frame->set_val(p_pos); EditorNode::get_singleton()->get_property_editor()->refresh(); @@ -1087,13 +1085,11 @@ void AnimationPlayerEditor::_hide_anim_editors() { player=NULL; hide(); set_process(false); - if (edit_anim->is_pressed()) { - editor->get_animation_editor()->set_animation(Ref<Animation>()); - editor->get_animation_editor()->set_root(NULL); - editor->animation_editor_make_visible(false); - edit_anim->set_pressed(false); - } + key_editor->set_animation(Ref<Animation>()); + key_editor->set_root(NULL); +// editor->animation_editor_make_visible(false); + } @@ -1238,6 +1234,7 @@ void AnimationPlayerEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_list_changed"),&AnimationPlayerEditor::_list_changed); ObjectTypeDB::bind_method(_MD("_animation_key_editor_seek"),&AnimationPlayerEditor::_animation_key_editor_seek); ObjectTypeDB::bind_method(_MD("_animation_key_editor_anim_len_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_len_changed); + ObjectTypeDB::bind_method(_MD("_animation_key_editor_anim_step_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_step_changed); ObjectTypeDB::bind_method(_MD("_hide_anim_editors"),&AnimationPlayerEditor::_hide_anim_editors); ObjectTypeDB::bind_method(_MD("_animation_duplicate"),&AnimationPlayerEditor::_animation_duplicate); ObjectTypeDB::bind_method(_MD("_blend_editor_next_changed"),&AnimationPlayerEditor::_blend_editor_next_changed); @@ -1278,6 +1275,50 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { add_child(hb); + play_bw_from = memnew( ToolButton ); + play_bw_from->set_tooltip("Play backwards selected animation from current pos. (A)"); + hb->add_child(play_bw_from); + + play_bw = memnew( ToolButton ); + play_bw->set_tooltip("Play backwards selected animation from end. (Shift+A)"); + hb->add_child(play_bw); + + stop = memnew( ToolButton ); + stop->set_toggle_mode(true); + hb->add_child(stop); + stop->set_tooltip("Stop animation playback. (S)"); + + play = memnew( ToolButton ); + play->set_tooltip("Play selected animation from start. (Shift+D)"); + hb->add_child(play); + + + play_from = memnew( ToolButton ); + play_from->set_tooltip("Play selected animation from current pos. (D)"); + hb->add_child(play_from); + + + + //pause = memnew( Button ); + //pause->set_toggle_mode(true); + //hb->add_child(pause); + + frame = memnew( SpinBox ); + hb->add_child(frame); + frame->set_custom_minimum_size(Size2(80,0)); + frame->set_stretch_ratio(2); + frame->set_tooltip("Animation position (in seconds)."); + + hb->add_child( memnew( VSeparator)); + + scale = memnew( LineEdit ); + hb->add_child(scale); + scale->set_h_size_flags(SIZE_EXPAND_FILL); + scale->set_stretch_ratio(1); + scale->set_tooltip("Scale animation playback globally for the node."); + scale->hide(); + + add_anim = memnew( ToolButton ); add_anim->set_tooltip("Create new animation in player."); @@ -1337,68 +1378,14 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { //tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM); hb->add_child(tool_anim); - - edit_anim = memnew( ToolButton ); - edit_anim->set_toggle_mode(true); - hb->add_child(edit_anim); - edit_anim->set_tooltip("Open animation editor.\nProperty editor will displays all editable keys too."); - - - hb = memnew (HBoxContainer); - add_child(hb); - - play_bw_from = memnew( ToolButton ); - play_bw_from->set_tooltip("Play backwards selected animation from current pos. (A)"); - hb->add_child(play_bw_from); - - play_bw = memnew( ToolButton ); - play_bw->set_tooltip("Play backwards selected animation from end. (Shift+A)"); - hb->add_child(play_bw); - - stop = memnew( ToolButton ); - stop->set_toggle_mode(true); - hb->add_child(stop); - stop->set_tooltip("Stop animation playback. (S)"); - - play = memnew( ToolButton ); - play->set_tooltip("Play selected animation from start. (Shift+D)"); - hb->add_child(play); - - - play_from = memnew( ToolButton ); - play_from->set_tooltip("Play selected animation from current pos. (D)"); - hb->add_child(play_from); - - - - //pause = memnew( Button ); - //pause->set_toggle_mode(true); - //hb->add_child(pause); - - seek = memnew( HSlider ); - seek->set_val(0); - seek->set_step(0.01); - hb->add_child(seek); - seek->set_h_size_flags(SIZE_EXPAND_FILL); - seek->set_stretch_ratio(8); - seek->set_tooltip("Seek animation (when stopped)."); - - frame = memnew( SpinBox ); - hb->add_child(frame); - frame->set_h_size_flags(SIZE_EXPAND_FILL); - frame->set_stretch_ratio(2); - frame->set_tooltip("Animation position (in seconds)."); - seek->share(frame); + nodename = memnew( Button ); + hb->add_child(nodename); + pin = memnew( ToolButton ); + pin->set_toggle_mode(true); + hb->add_child(pin); - scale = memnew( LineEdit ); - hb->add_child(scale); - scale->set_h_size_flags(SIZE_EXPAND_FILL); - scale->set_stretch_ratio(1); - scale->set_tooltip("Scale animation playback globally for the node."); - scale->hide(); - resource_edit_anim= memnew( Button ); hb->add_child(resource_edit_anim); resource_edit_anim->hide(); @@ -1464,30 +1451,31 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { load_anim->connect("pressed", this,"_animation_load"); duplicate_anim->connect("pressed", this,"_animation_duplicate"); //frame->connect("text_entered", this,"_seek_frame_changed"); - edit_anim->connect("pressed", this,"_animation_edit"); + blend_anim->connect("pressed", this,"_animation_blend"); remove_anim->connect("pressed", this,"_animation_remove"); animation->connect("item_selected", this,"_animation_selected",Vector<Variant>(),true); resource_edit_anim->connect("pressed", this,"_animation_resource_edit"); file->connect("file_selected", this,"_dialog_action"); - seek->connect("value_changed", this, "_seek_value_changed",Vector<Variant>(),true); + frame->connect("value_changed", this, "_seek_value_changed",Vector<Variant>(),true); scale->connect("text_entered", this, "_scale_changed",Vector<Variant>(),true); - editor->get_animation_editor()->connect("timeline_changed",this,"_animation_key_editor_seek"); - editor->get_animation_editor()->connect("animation_len_changed",this,"_animation_key_editor_anim_len_changed"); - - HBoxContainer *ahb = editor->get_animation_panel_hb(); - nodename = memnew( Label ); - ahb->add_child(nodename); - nodename->set_h_size_flags(SIZE_EXPAND_FILL); - nodename->set_opacity(0.5); - pin = memnew( TextureButton ); - pin->set_toggle_mode(true); - ahb->add_child(pin); + + renaming=false; last_active=false; set_process_unhandled_key_input(true); + + key_editor = memnew( AnimationKeyEditor); + add_child(key_editor); + add_constant_override("separation",get_constant("separation","VBoxContainer")); + key_editor->set_v_size_flags(SIZE_EXPAND_FILL); + key_editor->connect("timeline_changed",this,"_animation_key_editor_seek"); + key_editor->connect("animation_len_changed",this,"_animation_key_editor_anim_len_changed"); + key_editor->connect("animation_step_changed",this,"_animation_key_editor_anim_step_changed"); + + _update_player(); } @@ -1510,7 +1498,7 @@ void AnimationPlayerEditorPlugin::make_visible(bool p_visible) { anim_editor->show(); anim_editor->set_process(true); anim_editor->ensure_visibility(); - editor->animation_panel_make_visible(true); +// editor->animation_panel_make_visible(true); } else { // anim_editor->hide(); @@ -1524,7 +1512,8 @@ AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { editor=p_node; anim_editor = memnew( AnimationPlayerEditor(editor) ); anim_editor->set_undo_redo(editor->get_undo_redo()); - editor->get_animation_panel()->add_child(anim_editor); + + editor->add_bottom_panel_item("Animation",anim_editor); /* editor->get_viewport()->add_child(anim_editor); anim_editor->set_area_as_parent_rect(); diff --git a/tools/editor/plugins/animation_player_editor_plugin.h b/tools/editor/plugins/animation_player_editor_plugin.h index 9fbd92e4f0..0ad849c2f9 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.h +++ b/tools/editor/plugins/animation_player_editor_plugin.h @@ -41,7 +41,7 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ - +class AnimationKeyEditor; class AnimationPlayerEditor : public VBoxContainer { OBJ_TYPE(AnimationPlayerEditor, VBoxContainer ); @@ -78,17 +78,16 @@ class AnimationPlayerEditor : public VBoxContainer { Button *autoplay; Button *rename_anim; Button *duplicate_anim; - Button *edit_anim; + Button *resource_edit_anim; Button *load_anim; MenuButton *save_anim; Button *blend_anim; Button *remove_anim; MenuButton *tool_anim; - TextureButton *pin; - Label *nodename; + ToolButton *pin; + Button *nodename; SpinBox *frame; - HSlider *seek; LineEdit *scale; LineEdit *name; Label *name_title; @@ -117,6 +116,9 @@ class AnimationPlayerEditor : public VBoxContainer { bool updating; bool updating_blends; + AnimationKeyEditor *key_editor; + + void _select_anim_by_name(const String& p_anim); void _play_pressed(); void _play_from_pressed(); @@ -158,6 +160,8 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_key_editor_seek(float p_pos); void _animation_key_editor_anim_len_changed(float p_new); + void _animation_key_editor_anim_step_changed(float p_len); + void _unhandled_key_input(const InputEvent& p_ev); void _animation_tool_menu(int p_option); void _animation_save_menu(int p_option); @@ -175,6 +179,7 @@ public: AnimationPlayer *get_player() const; static AnimationPlayerEditor *singleton; + AnimationKeyEditor* get_key_editor() { return key_editor; } Dictionary get_state() const; void set_state(const Dictionary& p_state); diff --git a/tools/editor/plugins/animation_tree_editor_plugin.cpp b/tools/editor/plugins/animation_tree_editor_plugin.cpp index 609b1ccb63..d85553b4db 100644 --- a/tools/editor/plugins/animation_tree_editor_plugin.cpp +++ b/tools/editor/plugins/animation_tree_editor_plugin.cpp @@ -1498,18 +1498,17 @@ bool AnimationTreeEditorPlugin::handles(Object *p_object) const { void AnimationTreeEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - editor->hide_animation_player_editors(); - editor->animation_panel_make_visible(true); - anim_tree_editor->show(); +// editor->hide_animation_player_editors(); +// editor->animation_panel_make_visible(true); + button->show(); + editor->make_bottom_panel_item_visible(anim_tree_editor); anim_tree_editor->set_fixed_process(true); - EditorNode::get_top_split()->set_collapsed(false); - } else { - anim_tree_editor->hide(); + if (anim_tree_editor->is_visible()) + editor->hide_bottom_panel(); + button->hide(); anim_tree_editor->set_fixed_process(false); - editor->animation_panel_make_visible(false); - EditorNode::get_top_split()->set_collapsed(true); } } @@ -1517,12 +1516,10 @@ AnimationTreeEditorPlugin::AnimationTreeEditorPlugin(EditorNode *p_node) { editor=p_node; anim_tree_editor = memnew( AnimationTreeEditor ); - //editor->get_viewport()->add_child(anim_tree_editor); - //anim_tree_editor->set_area_as_parent_rect(); - editor->get_animation_panel()->add_child(anim_tree_editor); - anim_tree_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); - anim_tree_editor->hide(); + anim_tree_editor->set_custom_minimum_size(Size2(0,300)); + button=editor->add_bottom_panel_item("AnimationTree",anim_tree_editor); + button->hide(); diff --git a/tools/editor/plugins/animation_tree_editor_plugin.h b/tools/editor/plugins/animation_tree_editor_plugin.h index fb7eb58f8d..4884a22d90 100644 --- a/tools/editor/plugins/animation_tree_editor_plugin.h +++ b/tools/editor/plugins/animation_tree_editor_plugin.h @@ -176,6 +176,7 @@ class AnimationTreeEditorPlugin : public EditorPlugin { AnimationTreeEditor *anim_tree_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 56ed95fb16..a259fa0fcc 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -37,6 +37,8 @@ #include "os/input.h" #include "tools/editor/editor_settings.h" #include "scene/gui/grid_container.h" +#include "tools/editor/animation_editor.h" +#include "tools/editor/plugins/animation_player_editor_plugin.h" class SnapDialog : public ConfirmationDialog { @@ -194,7 +196,7 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2& mouse_pos) { void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) { - if (!is_visible()) + if (!is_visible() || get_viewport()->gui_has_modal_stack()) return; if (p_ev.key.mod.control) // prevent to change tool mode when control key is pressed @@ -407,7 +409,7 @@ void CanvasItemEditor::_node_removed(Node *p_node) { void CanvasItemEditor::_keying_changed() { - if (editor->get_animation_editor()->has_keying()) + if (AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) animation_hb->show(); else animation_hb->hide(); @@ -2695,11 +2697,11 @@ void CanvasItemEditor::_popup_callback(int p_op) { Node2D *n2d = canvas_item->cast_to<Node2D>(); if (key_pos) - editor->get_animation_editor()->insert_node_value_key(n2d,"transform/pos",n2d->get_pos(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/pos",n2d->get_pos(),existing); if (key_rot) - editor->get_animation_editor()->insert_node_value_key(n2d,"transform/rot",Math::rad2deg(n2d->get_rot()),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/rot",Math::rad2deg(n2d->get_rot()),existing); if (key_scale) - editor->get_animation_editor()->insert_node_value_key(n2d,"transform/scale",n2d->get_scale(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/scale",n2d->get_scale(),existing); if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) { @@ -2727,11 +2729,11 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node2D*>::Element *F=ik_chain.front();F;F=F->next()) { if (key_pos) - editor->get_animation_editor()->insert_node_value_key(F->get(),"transform/pos",F->get()->get_pos(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/pos",F->get()->get_pos(),existing); if (key_rot) - editor->get_animation_editor()->insert_node_value_key(F->get(),"transform/rot",Math::rad2deg(F->get()->get_rot()),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/rot",Math::rad2deg(F->get()->get_rot()),existing); if (key_scale) - editor->get_animation_editor()->insert_node_value_key(F->get(),"transform/scale",F->get()->get_scale(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/scale",F->get()->get_scale(),existing); } @@ -2743,9 +2745,9 @@ void CanvasItemEditor::_popup_callback(int p_op) { Control *ctrl = canvas_item->cast_to<Control>(); if (key_pos) - editor->get_animation_editor()->insert_node_value_key(ctrl,"rect/pos",ctrl->get_pos(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/pos",ctrl->get_pos(),existing); if (key_scale) - editor->get_animation_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size(),existing); } } @@ -2867,7 +2869,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (key_pos) ctrl->set_pos(Point2()); //if (key_scale) - // editor->get_animation_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size()); + // AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size()); } } @@ -3416,7 +3418,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { box_selecting=false; //zoom=0.5; singleton=this; - editor->get_animation_editor()->connect("keying_changed",this,"_keying_changed"); + AnimationPlayerEditor::singleton->get_key_editor()->connect("keying_changed",this,"_keying_changed"); set_process_unhandled_key_input(true); can_move_pivot=false; drag=DRAG_NONE; diff --git a/tools/editor/plugins/color_ramp_editor_plugin.cpp b/tools/editor/plugins/color_ramp_editor_plugin.cpp index df50535402..42ff1b1de9 100644 --- a/tools/editor/plugins/color_ramp_editor_plugin.cpp +++ b/tools/editor/plugins/color_ramp_editor_plugin.cpp @@ -3,14 +3,20 @@ */ #include "color_ramp_editor_plugin.h" +#include "spatial_editor_plugin.h" +#include "canvas_item_editor_plugin.h" -ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { +ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node, bool p_2d) { editor=p_node; ramp_editor = memnew( ColorRampEdit ); - add_custom_control(CONTAINER_CANVAS_EDITOR_BOTTOM,ramp_editor); - //add_custom_control(CONTAINER_SPATIAL_EDITOR_BOTTOM,ramp_editor); + _2d=p_2d; + if (p_2d) + add_custom_control(CONTAINER_CANVAS_EDITOR_BOTTOM,ramp_editor); + else + add_custom_control(CONTAINER_SPATIAL_EDITOR_BOTTOM,ramp_editor); + ramp_editor->set_custom_minimum_size(Size2(100, 48)); ramp_editor->hide(); ramp_editor->connect("ramp_changed", this, "ramp_changed"); @@ -27,7 +33,10 @@ void ColorRampEditorPlugin::edit(Object *p_object) { bool ColorRampEditorPlugin::handles(Object *p_object) const { - return p_object->is_type("ColorRamp"); + if (_2d) + return p_object->is_type("ColorRamp") && CanvasItemEditor::get_singleton()->is_visible() == true; + else + return p_object->is_type("ColorRamp") && SpatialEditor::get_singleton()->is_visible() == true; } void ColorRampEditorPlugin::make_visible(bool p_visible) { diff --git a/tools/editor/plugins/color_ramp_editor_plugin.h b/tools/editor/plugins/color_ramp_editor_plugin.h index e39a5d65fe..f07dbabeb3 100644 --- a/tools/editor/plugins/color_ramp_editor_plugin.h +++ b/tools/editor/plugins/color_ramp_editor_plugin.h @@ -13,6 +13,7 @@ class ColorRampEditorPlugin : public EditorPlugin { OBJ_TYPE( ColorRampEditorPlugin, EditorPlugin ); + bool _2d; Ref<ColorRamp> color_ramp_ref; ColorRampEdit *ramp_editor; EditorNode *editor; @@ -29,7 +30,7 @@ public: virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - ColorRampEditorPlugin(EditorNode *p_node); + ColorRampEditorPlugin(EditorNode *p_node, bool p_2d); ~ColorRampEditorPlugin(); }; diff --git a/tools/editor/plugins/resource_preloader_editor_plugin.cpp b/tools/editor/plugins/resource_preloader_editor_plugin.cpp index 403a919f5d..8490f63ff0 100644 --- a/tools/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/tools/editor/plugins/resource_preloader_editor_plugin.cpp @@ -356,11 +356,16 @@ bool ResourcePreloaderEditorPlugin::handles(Object *p_object) const { void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - preloader_editor->show(); + //preloader_editor->show(); + button->show(); + editor->make_bottom_panel_item_visible(preloader_editor); // preloader_editor->set_process(true); } else { - preloader_editor->hide(); + if (preloader_editor->is_visible()) + editor->hide_bottom_panel(); + button->hide(); + //preloader_editor->hide(); // preloader_editor->set_process(false); } @@ -370,11 +375,14 @@ ResourcePreloaderEditorPlugin::ResourcePreloaderEditorPlugin(EditorNode *p_node) editor=p_node; preloader_editor = memnew( ResourcePreloaderEditor ); - editor->get_viewport()->add_child(preloader_editor); - preloader_editor->set_area_as_parent_rect(); + preloader_editor->set_custom_minimum_size(Size2(0,250)); + + button=editor->add_bottom_panel_item("ResourcePreloader",preloader_editor); + button->hide(); + // preloader_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); // preloader_editor->set_margin( MARGIN_TOP, 120 ); - preloader_editor->hide(); + diff --git a/tools/editor/plugins/resource_preloader_editor_plugin.h b/tools/editor/plugins/resource_preloader_editor_plugin.h index 49ef86b4c2..53436797a9 100644 --- a/tools/editor/plugins/resource_preloader_editor_plugin.h +++ b/tools/editor/plugins/resource_preloader_editor_plugin.h @@ -85,6 +85,7 @@ class ResourcePreloaderEditorPlugin : public EditorPlugin { ResourcePreloaderEditor *preloader_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/sample_library_editor_plugin.cpp b/tools/editor/plugins/sample_library_editor_plugin.cpp index 493ae405ba..a28fbb2ec8 100644 --- a/tools/editor/plugins/sample_library_editor_plugin.cpp +++ b/tools/editor/plugins/sample_library_editor_plugin.cpp @@ -423,11 +423,16 @@ bool SampleLibraryEditorPlugin::handles(Object *p_object) const { void SampleLibraryEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - sample_library_editor->show(); + //sample_library_editor->show(); + button->show(); + editor->make_bottom_panel_item_visible(sample_library_editor); // sample_library_editor->set_process(true); } else { - sample_library_editor->hide(); + if (sample_library_editor->is_visible()) + editor->hide_bottom_panel(); + button->hide(); + // sample_library_editor->set_process(false); } @@ -437,11 +442,16 @@ SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) { editor=p_node; sample_library_editor = memnew( SampleLibraryEditor ); - editor->get_viewport()->add_child(sample_library_editor); - sample_library_editor->set_area_as_parent_rect(); + + //editor->get_viewport()->add_child(sample_library_editor); + sample_library_editor->set_custom_minimum_size(Size2(0,250)); + button=p_node->add_bottom_panel_item("SampleLibrary",sample_library_editor); + button->hide(); + + //sample_library_editor->set_area_as_parent_rect(); // sample_library_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); // sample_library_editor->set_margin( MARGIN_TOP, 120 ); - sample_library_editor->hide(); + //sample_library_editor->hide(); diff --git a/tools/editor/plugins/sample_library_editor_plugin.h b/tools/editor/plugins/sample_library_editor_plugin.h index 6627d8d6de..cbdcf5fc3f 100644 --- a/tools/editor/plugins/sample_library_editor_plugin.h +++ b/tools/editor/plugins/sample_library_editor_plugin.h @@ -90,6 +90,7 @@ class SampleLibraryEditorPlugin : public EditorPlugin { SampleLibraryEditor *sample_library_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index fc0d68b2f8..1e16f32e6e 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -2321,17 +2321,14 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { menu_hb = memnew( HBoxContainer ); add_child(menu_hb); - v_split = memnew( VSplitContainer ); - add_child(v_split); - v_split->set_v_size_flags(SIZE_EXPAND_FILL); script_split = memnew( HSplitContainer ); - v_split->add_child(script_split); + add_child(script_split); script_split->set_v_size_flags(SIZE_EXPAND_FILL); script_list = memnew( ItemList ); script_split->add_child(script_list); - script_list->set_custom_minimum_size(Size2(70,0)); + script_list->set_custom_minimum_size(Size2(0,0)); script_split->set_split_offset(70); tab_container = memnew( TabContainer ); @@ -2416,7 +2413,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { debug_menu->get_popup()->add_item("Break",DEBUG_BREAK); debug_menu->get_popup()->add_item("Continue",DEBUG_CONTINUE); debug_menu->get_popup()->add_separator(); - debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW); + //debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW); debug_menu->get_popup()->add_check_item("Keep Debugger Open",DEBUG_SHOW_KEEP_OPEN); debug_menu->get_popup()->connect("item_pressed", this,"_menu_option"); @@ -2545,7 +2542,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { quick_open->connect("goto_line",this,"_goto_script_line2"); - v_split->add_child(debugger); + + Button *db = EditorNode::get_singleton()->add_bottom_panel_item("Debugger",debugger); + debugger->set_tool_button(db); + + debugger->connect("breaked",this,"_breaked"); autosave_timer = memnew( Timer ); diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index b829d4e0e5..c52da41a43 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -212,8 +212,6 @@ class ScriptEditor : public VBoxContainer { Tree *disk_changed_list; ConfirmationDialog *disk_changed; - VSplitContainer *v_split; - bool restoring_layout; String _get_debug_tooltip(const String&p_text,Node *_ste); diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 29d2a7774c..153d71e9cb 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -39,6 +39,9 @@ #include "scene/resources/surface_tool.h" #include "tools/editor/spatial_editor_gizmos.h" #include "globals.h" +#include "tools/editor/plugins/animation_player_editor_plugin.h" +#include "tools/editor/animation_editor.h" + #define DISTANCE_DEFAULT 4 @@ -1691,7 +1694,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (!get_selected_count() || _edit.mode!=TRANSFORM_NONE) break; - if (!editor->get_animation_editor()->has_keying()) { + if (!AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) { set_message("Keying is disabled (no key inserted)."); break; } @@ -3529,10 +3532,10 @@ void SpatialEditor::_instance_scene() { void SpatialEditor::_unhandled_key_input(InputEvent p_event) { - if (!is_visible()) + if (!is_visible() || get_viewport()->gui_has_modal_stack()) return; - { + { EditorNode *en = editor; EditorPlugin *over_plugin = en->get_editor_plugin_over(); diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.cpp b/tools/editor/plugins/sprite_frames_editor_plugin.cpp index 048df2d682..af73828b61 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/tools/editor/plugins/sprite_frames_editor_plugin.cpp @@ -485,11 +485,15 @@ bool SpriteFramesEditorPlugin::handles(Object *p_object) const { void SpriteFramesEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - frames_editor->show(); + button->show(); + editor->make_bottom_panel_item_visible(frames_editor); // frames_editor->set_process(true); } else { - frames_editor->hide(); + button->hide(); + if (frames_editor->is_visible()) + editor->hide_bottom_panel(); + // frames_editor->set_process(false); } @@ -499,11 +503,9 @@ SpriteFramesEditorPlugin::SpriteFramesEditorPlugin(EditorNode *p_node) { editor=p_node; frames_editor = memnew( SpriteFramesEditor ); - editor->get_viewport()->add_child(frames_editor); - frames_editor->set_area_as_parent_rect(); -// frames_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); -// frames_editor->set_margin( MARGIN_TOP, 120 ); - frames_editor->hide(); + frames_editor->set_custom_minimum_size(Size2(0,300)); + button=editor->add_bottom_panel_item("SpriteFrames",frames_editor); + button->hide(); diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.h b/tools/editor/plugins/sprite_frames_editor_plugin.h index e4088da297..5d0a6cb035 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.h +++ b/tools/editor/plugins/sprite_frames_editor_plugin.h @@ -94,6 +94,7 @@ class SpriteFramesEditorPlugin : public EditorPlugin { SpriteFramesEditor *frames_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/style_box_editor_plugin.cpp b/tools/editor/plugins/style_box_editor_plugin.cpp index 58e9038840..3d7cf4135d 100644 --- a/tools/editor/plugins/style_box_editor_plugin.cpp +++ b/tools/editor/plugins/style_box_editor_plugin.cpp @@ -90,19 +90,24 @@ bool StyleBoxEditorPlugin::handles(Object *p_node) const{ void StyleBoxEditorPlugin::make_visible(bool p_visible){ - if (p_visible) - stylebox_editor->show(); - else - stylebox_editor->hide(); + if (p_visible) { + button->show(); + + } else { + if (stylebox_editor->is_visible()) + EditorNode::get_singleton()->hide_bottom_panel(); + button->hide(); + } } StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) { stylebox_editor = memnew( StyleBoxEditor ); + stylebox_editor->set_custom_minimum_size(Size2(0,250)); - p_node->get_viewport()->add_child(stylebox_editor); - stylebox_editor->set_area_as_parent_rect(); - stylebox_editor->hide(); + //p_node->get_viewport()->add_child(stylebox_editor); + button = p_node->add_bottom_panel_item("StyleBox",stylebox_editor); + button->hide(); } diff --git a/tools/editor/plugins/style_box_editor_plugin.h b/tools/editor/plugins/style_box_editor_plugin.h index 3b3f8d8d0f..737f830bbb 100644 --- a/tools/editor/plugins/style_box_editor_plugin.h +++ b/tools/editor/plugins/style_box_editor_plugin.h @@ -65,6 +65,7 @@ class StyleBoxEditorPlugin : public EditorPlugin { StyleBoxEditor *stylebox_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index f67f049b36..ef7b3b17c3 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -831,21 +831,26 @@ bool ThemeEditorPlugin::handles(Object *p_node) const{ void ThemeEditorPlugin::make_visible(bool p_visible){ if (p_visible) { - theme_editor->show(); theme_editor->set_process(true); + button->show(); } else { - theme_editor->hide(); theme_editor->set_process(false); + if (theme_editor->is_visible()) + EditorNode::get_singleton()->hide_bottom_panel(); + button->hide(); } } ThemeEditorPlugin::ThemeEditorPlugin(EditorNode *p_node) { + editor=p_node; theme_editor = memnew( ThemeEditor ); + theme_editor->set_custom_minimum_size(Size2(0,500)); + +// p_node->get_viewport()->add_child(theme_editor); + button=EditorNode::get_singleton()->add_bottom_panel_item("Theme",theme_editor); + button->hide(); - p_node->get_viewport()->add_child(theme_editor); - theme_editor->set_area_as_parent_rect(); - theme_editor->hide(); } diff --git a/tools/editor/plugins/theme_editor_plugin.h b/tools/editor/plugins/theme_editor_plugin.h index f5e7192a73..52c4aed839 100644 --- a/tools/editor/plugins/theme_editor_plugin.h +++ b/tools/editor/plugins/theme_editor_plugin.h @@ -102,6 +102,7 @@ class ThemeEditorPlugin : public EditorPlugin { ThemeEditor *theme_editor; EditorNode *editor; + Button *button; public: diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index b2562eafe1..29326a2222 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -676,12 +676,9 @@ void TileMapEditor::_canvas_draw() { Ref<Texture> t = ts->tile_get_texture(st); if (t.is_valid()) { Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset(); + Vector2 tile_ofs = ts->tile_get_texture_offset(st); Rect2 r = ts->tile_get_region(st); Size2 sc = xform.get_scale(); - if (mirror_x->is_pressed()) - sc.x*=-1.0; - if (mirror_y->is_pressed()) - sc.y*=-1.0; Rect2 rect; if (r==Rect2()) { @@ -691,23 +688,47 @@ void TileMapEditor::_canvas_draw() { rect=Rect2(from,r.get_size()); } + bool transp = transpose->is_pressed(); + bool flip_h = mirror_x->is_pressed(); + bool flip_v = mirror_y->is_pressed(); + + if (rect.size.y > rect.size.x) { + if ((flip_h && (flip_v || transp)) || (flip_v && !transp)) + tile_ofs.y += rect.size.y - rect.size.x; + } else if (rect.size.y < rect.size.x) { + if ((flip_v && (flip_h || transp)) || (flip_h && !transp)) + tile_ofs.x += rect.size.x - rect.size.y; + } + + if (transp) { + SWAP(tile_ofs.x, tile_ofs.y); + } + + if (flip_h) { + sc.x*=-1.0; + tile_ofs.x*=-1.0; + } + if (flip_v) { + sc.y*=-1.0; + tile_ofs.y*=-1.0; + } if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.pos+=ts->tile_get_texture_offset(st); + rect.pos+=tile_ofs; } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) { rect.pos+=node->get_cell_size()/2; Vector2 s = r.size; - Vector2 center = (s/2) - ts->tile_get_texture_offset(st); + Vector2 center = (s/2) - tile_ofs; - if (mirror_x->is_pressed()) + if (flip_h) rect.pos.x-=s.x-center.x; else rect.pos.x-=center.x; - if (mirror_y->is_pressed()) + if (flip_v) rect.pos.y-=s.y-center.y; else rect.pos.y-=center.y; @@ -718,10 +739,10 @@ void TileMapEditor::_canvas_draw() { if (r==Rect2()) { - canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transpose->is_pressed()); + canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transp); } else { - canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transpose->is_pressed()); + canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transp); } } } diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 6c5e18ec9a..26e8919375 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -60,9 +60,6 @@ void ProjectSettings::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { - search_button->set_icon(get_icon("Zoom","EditorIcons")); - clear_button->set_icon(get_icon("Close","EditorIcons")); - translation_list->connect("button_pressed",this,"_translation_delete"); _update_actions(); popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),"Key",InputEvent::KEY); @@ -93,7 +90,9 @@ void ProjectSettings::_notification(int p_what) { autoload_file_open->add_filter("*."+E->get()); } + } else if (p_what==NOTIFICATION_POST_POPUP) { + globals_editor->clear_search_box(); } } @@ -1339,32 +1338,6 @@ void ProjectSettings::_update_autoload() { } -void ProjectSettings::_toggle_search_bar(bool p_pressed) { - - globals_editor->get_property_editor()->set_use_filter(p_pressed); - - if (p_pressed) { - - search_bar->show(); - add_prop_bar->hide(); - search_box->grab_focus(); - search_box->select_all(); - } else { - - search_bar->hide(); - add_prop_bar->show(); - } -} - -void ProjectSettings::_clear_search_box() { - - if (search_box->get_text()=="") - return; - - search_box->clear(); - globals_editor->get_property_editor()->update_tree(); -} - void ProjectSettings::_bind_methods() { ObjectTypeDB::bind_method(_MD("_item_selected"),&ProjectSettings::_item_selected); @@ -1407,9 +1380,6 @@ void ProjectSettings::_bind_methods() { ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete); ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited); - ObjectTypeDB::bind_method(_MD("_clear_search_box"),&ProjectSettings::_clear_search_box); - ObjectTypeDB::bind_method(_MD("_toggle_search_bar"),&ProjectSettings::_toggle_search_bar); - } ProjectSettings::ProjectSettings(EditorData *p_data) { @@ -1440,77 +1410,50 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); props_base->add_child(hbc); - search_button = memnew( ToolButton ); - search_button->set_toggle_mode(true); - search_button->set_pressed(false); - search_button->set_text("Search"); - hbc->add_child(search_button); - search_button->connect("toggled",this,"_toggle_search_bar"); - - hbc->add_child( memnew( VSeparator ) ); - - add_prop_bar = memnew( HBoxContainer ); - add_prop_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL); - hbc->add_child(add_prop_bar); - Label *l = memnew( Label ); - add_prop_bar->add_child(l); + hbc->add_child(l); l->set_text("Category:"); category = memnew( LineEdit ); category->set_h_size_flags(Control::SIZE_EXPAND_FILL); - add_prop_bar->add_child(category); + hbc->add_child(category); category->connect("text_entered",this,"_item_adds"); l = memnew( Label ); - add_prop_bar->add_child(l); + hbc->add_child(l); l->set_text("Property:"); property = memnew( LineEdit ); property->set_h_size_flags(Control::SIZE_EXPAND_FILL); - add_prop_bar->add_child(property); + hbc->add_child(property); property->connect("text_entered",this,"_item_adds"); l = memnew( Label ); - add_prop_bar->add_child(l); + hbc->add_child(l); l->set_text("Type:"); type = memnew( OptionButton ); type->set_h_size_flags(Control::SIZE_EXPAND_FILL); - add_prop_bar->add_child(type); + hbc->add_child(type); type->add_item("bool"); type->add_item("int"); type->add_item("float"); type->add_item("string"); Button *add = memnew( Button ); - add_prop_bar->add_child(add); + hbc->add_child(add); add->set_text("Add"); add->connect("pressed",this,"_item_add"); Button *del = memnew( Button ); - add_prop_bar->add_child(del); + hbc->add_child(del); del->set_text("Del"); del->connect("pressed",this,"_item_del"); - search_bar = memnew( HBoxContainer ); - search_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL); - hbc->add_child(search_bar); - search_bar->hide(); - - search_box = memnew( LineEdit ); - search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); - search_bar->add_child(search_box); - - clear_button = memnew( ToolButton ); - search_bar->add_child(clear_button); - clear_button->connect("pressed",this,"_clear_search_box"); - globals_editor = memnew( SectionedPropertyEditor ); props_base->add_child(globals_editor); //globals_editor->hide_top_label(); globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); - globals_editor->get_property_editor()->register_text_enter(search_box); globals_editor->get_property_editor()->set_capitalize_paths(false); globals_editor->get_property_editor()->get_scene_tree()->connect("cell_selected",this,"_item_selected"); globals_editor->get_property_editor()->connect("property_toggled",this,"_item_checked",varray(),CONNECT_DEFERRED); diff --git a/tools/editor/project_settings.h b/tools/editor/project_settings.h index b689340fdf..cbf24e7bfd 100644 --- a/tools/editor/project_settings.h +++ b/tools/editor/project_settings.h @@ -48,12 +48,6 @@ class ProjectSettings : public AcceptDialog { UndoRedo *undo_redo; SectionedPropertyEditor *globals_editor; - HBoxContainer *search_bar; - ToolButton *search_button; - LineEdit *search_box; - ToolButton *clear_button; - - HBoxContainer *add_prop_bar; ConfirmationDialog *message; LineEdit *category; LineEdit *property; @@ -142,9 +136,6 @@ class ProjectSettings : public AcceptDialog { void _translation_res_option_changed(); void _translation_res_option_delete(Object *p_item,int p_column, int p_button); - void _toggle_search_bar(bool p_pressed); - void _clear_search_box(); - ProjectSettings(); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 9743dc7202..286a8f25b1 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -595,7 +595,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty color_picker->show(); color_picker->set_edit_alpha(hint!=PROPERTY_HINT_COLOR_NO_ALPHA); color_picker->set_color(v); - set_size( Size2(350, color_picker->get_combined_minimum_size().height+10)); + set_size( Size2(300, color_picker->get_combined_minimum_size().height+10)); /* int ofs=80; int m=10; @@ -3777,6 +3777,10 @@ class SectionedPropertyEditorFilter : public Object { for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { PropertyInfo pi=E->get(); + + if (section=="") + p_list->push_back(pi); + int sp = pi.name.find("/"); if (sp!=-1) { String ss = pi.name.substr(0,sp); @@ -3786,7 +3790,7 @@ class SectionedPropertyEditorFilter : public Object { p_list->push_back(pi); } } else { - if (section=="") + if (section=="global") p_list->push_back(pi); } } @@ -3811,10 +3815,18 @@ public: }; +void SectionedPropertyEditor::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + + clear_button->set_icon(get_icon("Close", "EditorIcons")); + } +} void SectionedPropertyEditor::_bind_methods() { ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected); + ObjectTypeDB::bind_method("_clear_search_box",&SectionedPropertyEditor::clear_search_box); } void SectionedPropertyEditor::_section_selected(int p_which) { @@ -3822,9 +3834,30 @@ void SectionedPropertyEditor::_section_selected(int p_which) { filter->set_section( sections->get_item_metadata(p_which) ); } +void SectionedPropertyEditor::clear_search_box() { + + if (search_box->get_text().strip_edges()=="") + return; + + search_box->clear(); + editor->update_tree(); +} + + String SectionedPropertyEditor::get_current_section() const { - return sections->get_item_metadata( sections->get_current() ); + String section = sections->get_item_metadata( sections->get_current() ); + + if (section=="") { + String name = editor->get_selected_path(); + + int sp = name.find("/"); + if (sp!=-1) + section = name.substr(0, sp); + + } + + return section; } String SectionedPropertyEditor::get_full_item_path(const String& p_item) { @@ -3844,11 +3877,20 @@ void SectionedPropertyEditor::edit(Object* p_object) { sections->clear(); Set<String> existing_sections; + + existing_sections.insert(""); + sections->add_item("All"); + sections->set_item_metadata(0, ""); + for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { PropertyInfo pi=E->get(); + if (pi.usage&PROPERTY_USAGE_CATEGORY) continue; + if ( !(pi.usage&PROPERTY_USAGE_EDITOR) ) + continue; + if (pi.name.find(":")!=-1 || pi.name=="script/script") continue; int sp = pi.name.find("/"); @@ -3861,10 +3903,10 @@ void SectionedPropertyEditor::edit(Object* p_object) { } } else { - if (!existing_sections.has("")) { - existing_sections.insert(""); + if (!existing_sections.has("global")) { + existing_sections.insert("global"); sections->add_item("Global"); - sections->set_item_metadata(sections->get_item_count()-1,""); + sections->set_item_metadata(sections->get_item_count()-1,"global"); } } @@ -3889,6 +3931,8 @@ PropertyEditor *SectionedPropertyEditor::get_property_editor() { SectionedPropertyEditor::SectionedPropertyEditor() { + add_constant_override("separation", 8); + VBoxContainer *left_vb = memnew( VBoxContainer); left_vb->set_custom_minimum_size(Size2(160,0)); add_child(left_vb); @@ -3903,7 +3947,21 @@ SectionedPropertyEditor::SectionedPropertyEditor() { add_child(right_vb); filter = memnew( SectionedPropertyEditorFilter ); + + HBoxContainer *hbc = memnew( HBoxContainer ); + right_vb->add_margin_child("Search:",hbc); + + search_box = memnew( LineEdit ); + search_box->set_h_size_flags(SIZE_EXPAND_FILL); + hbc->add_child(search_box); + + clear_button = memnew( ToolButton ); + hbc->add_child(clear_button); + clear_button->connect("pressed", this, "_clear_search_box"); + editor = memnew( PropertyEditor ); + editor->register_text_enter(search_box); + editor->set_use_filter(true); editor->set_v_size_flags(SIZE_EXPAND_FILL); right_vb->add_margin_child("Properties:",editor,true); diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index 63ad090901..5dc2f6d154 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -259,12 +259,16 @@ class SectionedPropertyEditor : public HBoxContainer { OBJ_TYPE(SectionedPropertyEditor,HBoxContainer); ItemList *sections; SectionedPropertyEditorFilter *filter; + LineEdit *search_box; + ToolButton *clear_button; PropertyEditor *editor; - - static void _bind_methods(); void _section_selected(int p_which); +protected: + + void _notification(int p_what); + static void _bind_methods(); public: PropertyEditor *get_property_editor(); @@ -272,6 +276,8 @@ public: String get_full_item_path(const String& p_item); String get_current_section() const; + void clear_search_box(); + SectionedPropertyEditor(); ~SectionedPropertyEditor(); }; diff --git a/tools/editor/quick_open.cpp b/tools/editor/quick_open.cpp index 22f4a40c83..828275340b 100644 --- a/tools/editor/quick_open.cpp +++ b/tools/editor/quick_open.cpp @@ -78,14 +78,33 @@ void EditorQuickOpen::_text_changed(const String& p_newtext) { void EditorQuickOpen::_sbox_input(const InputEvent& p_ie) { - if (p_ie.type==InputEvent::KEY && ( - p_ie.key.scancode == KEY_UP || - p_ie.key.scancode == KEY_DOWN || - p_ie.key.scancode == KEY_PAGEUP || - p_ie.key.scancode == KEY_PAGEDOWN ) ) { - - search_options->call("_input_event",p_ie); - search_box->accept_event(); + if (p_ie.type==InputEvent::KEY) { + + switch(p_ie.key.scancode) { + case KEY_UP: + case KEY_DOWN: + case KEY_PAGEUP: + case KEY_PAGEDOWN: { + + search_options->call("_input_event", p_ie); + search_box->accept_event(); + + TreeItem *root = search_options->get_root(); + if (!root->get_children()) + break; + + TreeItem *current = search_options->get_selected(); + + TreeItem *item = search_options->get_next_selected(root); + while (item) { + item->deselect(0); + item = search_options->get_next_selected(item); + } + + current->select(0); + + } break; + } } } @@ -125,9 +144,6 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { ti->set_text(0,file); Ref<Texture> icon = get_icon( (has_icon(efsd->get_file_type(i),ei)?efsd->get_file_type(i):ot),ei); ti->set_icon(0,icon); - if (root->get_children()==ti) - ti->select(0); - } } @@ -148,6 +164,13 @@ void EditorQuickOpen::_update_search() { TreeItem *root = search_options->create_item(); _parse_fs(EditorFileSystem::get_singleton()->get_filesystem()); + if (root->get_children()) { + TreeItem *ti = root->get_children(); + + ti->select(0); + ti->set_as_cursor(0); + } + get_ok()->set_disabled(root->get_children()==NULL); } diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 89036d2581..5877ce1a43 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -35,7 +35,10 @@ #include "tools/editor/plugins/canvas_item_editor_plugin.h" #include "script_editor_debugger.h" #include "tools/editor/plugins/script_editor_plugin.h" +#include "core/io/resource_saver.h" #include "multi_node_edit.h" +#include "tools/editor/plugins/animation_player_editor_plugin.h" +#include "animation_editor.h" void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { @@ -291,7 +294,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { for (int i = 0; i < selection.size(); i++) { Node *top_node = selection[i]; Node *bottom_node = selection[selection.size() - 1 - i]; - + ERR_FAIL_COND(!top_node->get_parent()); ERR_FAIL_COND(!bottom_node->get_parent()); @@ -397,7 +400,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner()); } editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup); - editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup); + editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup); editor_data->get_undo_redo().add_do_reference(dup); ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); @@ -485,7 +488,54 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { delete_dialog->popup_centered_minsize(); } + } break; + case TOOL_NEW_SCENE_FROM: { + + Node *scene = editor_data->get_edited_scene_root(); + + if (!scene) { + accept->get_ok()->set_text("I see.."); + accept->set_text("This operation can't be done without a scene."); + accept->popup_centered_minsize(); + break; + } + + List<Node*> selection = editor_selection->get_selected_node_list(); + + if (selection.size()!=1) { + accept->get_ok()->set_text("I see.."); + accept->set_text("This operation requires a single selected node."); + accept->popup_centered_minsize(); + break; + } + + Node *tocopy = selection.front()->get(); + if (tocopy!=editor_data->get_edited_scene_root() && tocopy->get_filename()!="") { + accept->get_ok()->set_text("I see.."); + accept->set_text("This operation can't be done on instanced scenes."); + accept->popup_centered_minsize(); + break; + } + + new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + + List<String> extensions; + Ref<PackedScene> sd = memnew( PackedScene ); + ResourceSaver::get_recognized_extensions(sd,&extensions); + new_scene_from_dialog->clear_filters(); + for(int i=0;i<extensions.size();i++) { + new_scene_from_dialog->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); + } + + String existing; + if (extensions.size()) { + existing="new_scene."+extensions.front()->get().to_lower(); + } + new_scene_from_dialog->set_current_path(existing); + + new_scene_from_dialog->popup_centered_ratio(); + new_scene_from_dialog->set_title("Save New Scene As.."); } break; @@ -520,6 +570,7 @@ void SceneTreeDock::_notification(int p_what) { "MoveDown", "Duplicate", "Reparent", + "CreateNewSceneFrom", "MultiNodeEdit", "Remove", }; @@ -875,7 +926,7 @@ bool SceneTreeDock::_validate_no_foreign() { } - if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E->get()))>=0) { + if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E->get()))>=0) { accept->get_ok()->set_text("Makes Sense!"); accept->set_text("Can't operate on nodes the current scene inherits from!"); @@ -968,8 +1019,8 @@ void SceneTreeDock::_node_reparent(NodePath p_path,bool p_keep_global_xform) { editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners); - if (editor->get_animation_editor()->get_root()==node) - editor_data->get_undo_redo().add_do_method(editor->get_animation_editor(),"set_root",node); + if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==node) + editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",node); editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node); @@ -996,8 +1047,8 @@ void SceneTreeDock::_node_reparent(NodePath p_path,bool p_keep_global_xform) { editor_data->get_undo_redo().add_undo_method(node->get_parent(),"add_child",node); editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,child_pos); editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners); - if (editor->get_animation_editor()->get_root()==node) - editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",node); + if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==node) + editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",node); if (p_keep_global_xform) { if (node->cast_to<Node2D>()) @@ -1103,8 +1154,8 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().add_do_method(n->get_parent(),"remove_child",n); editor_data->get_undo_redo().add_undo_method(n->get_parent(),"add_child",n); editor_data->get_undo_redo().add_undo_method(n->get_parent(),"move_child",n,n->get_index()); - if (editor->get_animation_editor()->get_root()==n) - editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",n); + if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==n) + editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",n); editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners); //editor_data->get_undo_redo().add_undo_method(n,"set_owner",n->get_owner()); editor_data->get_undo_redo().add_undo_reference(n); @@ -1140,6 +1191,7 @@ void SceneTreeDock::_update_tool_buttons() { tool_buttons[TOOL_DUPLICATE]->set_disabled(disable_root); tool_buttons[TOOL_REPARENT]->set_disabled(disable_root); tool_buttons[TOOL_ERASE]->set_disabled(disable); + tool_buttons[TOOL_NEW_SCENE_FROM]->set_disabled(disable_root); tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2); @@ -1279,7 +1331,7 @@ void SceneTreeDock::_create() { editor->push_item(newnode); memdelete(n); - + _update_tool_buttons(); } @@ -1326,6 +1378,59 @@ void SceneTreeDock::_import_subscene() { */ } +void SceneTreeDock::_new_scene_from(String p_file) { + + List<Node*> selection = editor_selection->get_selected_node_list(); + + if (selection.size()!=1) { + accept->get_ok()->set_text("I see.."); + accept->set_text("This operation requires a single selected node."); + accept->popup_centered_minsize(); + return; + } + + Node *base = selection.front()->get(); + + Map<Node*,Node*> reown; + reown[editor_data->get_edited_scene_root()]=base; + Node *copy = base->duplicate_and_reown(reown); + if (copy) { + + Ref<PackedScene> sdata = memnew( PackedScene ); + Error err = sdata->pack(copy); + memdelete(copy); + + if (err!=OK) { + accept->get_ok()->set_text("I see.."); + accept->set_text("Couldn't save new scene. Likely dependencies (instances) couldn't be satisfied."); + accept->popup_centered_minsize(); + return; + } + + int flg=0; + if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources")) + flg|=ResourceSaver::FLAG_COMPRESS; + if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative")) + flg|=ResourceSaver::FLAG_RELATIVE_PATHS; + + + err = ResourceSaver::save(p_file,sdata,flg); + if (err!=OK) { + accept->get_ok()->set_text("I see.."); + accept->set_text("Error saving scene."); + accept->popup_centered_minsize(); + return; + } + + } else { + accept->get_ok()->set_text("I see.."); + accept->set_text("Error duplicating scene to save it."); + accept->popup_centered_minsize(); + return; + } + +} + void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tool_selected"),&SceneTreeDock::_tool_selected); @@ -1343,6 +1448,7 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_node_prerenamed"),&SceneTreeDock::_node_prerenamed); ObjectTypeDB::bind_method(_MD("_import_subscene"),&SceneTreeDock::_import_subscene); ObjectTypeDB::bind_method(_MD("_selection_changed"),&SceneTreeDock::_selection_changed); + ObjectTypeDB::bind_method(_MD("_new_scene_from"),&SceneTreeDock::_new_scene_from); ObjectTypeDB::bind_method(_MD("instance"),&SceneTreeDock::instance); } @@ -1415,9 +1521,10 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec scene_tree->set_undo_redo(&editor_data->get_undo_redo()); scene_tree->set_editor_selection(editor_selection); + HBoxContainer *hbc_bottom = memnew( HBoxContainer ); vbc->add_child(hbc_bottom); - + hbc_bottom->add_constant_override("separation", 0); tb = memnew( ToolButton ); tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_UP, false)); @@ -1446,6 +1553,12 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec hbc_bottom->add_spacer(); tb = memnew( ToolButton ); + tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW_SCENE_FROM, false)); + tb->set_tooltip("Create New Scene From Node(s)"); + hbc_bottom->add_child(tb); + tool_buttons[TOOL_NEW_SCENE_FROM]=tb; + + tb = memnew( ToolButton ); tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MULTI_EDIT, false)); tb->set_tooltip("Multi-Edit Selected Nodes"); hbc_bottom->add_child(tb); @@ -1465,12 +1578,15 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec groups_editor = memnew( GroupsEditor ); add_child(groups_editor); groups_editor->set_undo_redo(&editor_data->get_undo_redo()); + connect_dialog = memnew( ConnectionsDialog(p_editor) ); add_child(connect_dialog); connect_dialog->set_undoredo(&editor_data->get_undo_redo()); + script_create_dialog = memnew( ScriptCreateDialog ); add_child(script_create_dialog); script_create_dialog->connect("script_created",this,"_script_created"); + reparent_dialog = memnew( ReparentDialog ); add_child(reparent_dialog); reparent_dialog->connect("reparent",this,"_node_reparent"); @@ -1486,10 +1602,16 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec delete_dialog = memnew( ConfirmationDialog ); add_child(delete_dialog); delete_dialog->connect("confirmed",this,"_delete_confirm"); + import_subscene_dialog = memnew( EditorSubScene ); add_child(import_subscene_dialog); import_subscene_dialog->connect("subscene_selected",this,"_import_subscene"); + new_scene_from_dialog = memnew( EditorFileDialog ); + new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + add_child(new_scene_from_dialog); + new_scene_from_dialog->connect("file_selected",this,"_new_scene_from"); + first_enter=true; diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index aad12a2340..114e2c5c97 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -62,6 +62,7 @@ class SceneTreeDock : public VBoxContainer { TOOL_MOVE_DOWN, TOOL_DUPLICATE, TOOL_REPARENT, + TOOL_NEW_SCENE_FROM, TOOL_MULTI_EDIT, TOOL_ERASE, TOOL_BUTTON_MAX @@ -90,6 +91,7 @@ class SceneTreeDock : public VBoxContainer { ReparentDialog *reparent_dialog; EditorFileDialog *file; EditorSubScene *import_subscene_dialog; + EditorFileDialog *new_scene_from_dialog; bool first_enter; @@ -119,6 +121,8 @@ class SceneTreeDock : public VBoxContainer { void _import_subscene(); + void _new_scene_from(String p_file); + bool _validate_no_foreign(); void _selection_changed(); diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index 531fe83bc3..ea7d760133 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -39,12 +39,8 @@ Node *SceneTreeEditor::get_scene_node() { ERR_FAIL_COND_V(!is_inside_tree(),NULL); - if (get_tree()->get_root()->get_child_count() && get_tree()->get_root()->get_child(0)->cast_to<EditorNode>()) - return get_tree()->get_root()->get_child(0)->cast_to<EditorNode>()->get_edited_scene(); - else - return get_tree()->get_root(); - return NULL; + return get_tree()->get_edited_scene_root(); } diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp index aad89d1272..297f10a1c8 100644 --- a/tools/editor/script_editor_debugger.cpp +++ b/tools/editor/script_editor_debugger.cpp @@ -210,6 +210,8 @@ void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_dat OS::get_singleton()->move_window_to_foreground(); tabs->set_current_tab(0); + EditorNode::get_singleton()->make_bottom_panel_item_visible(this); + } else if (p_msg=="debug_exit") { breaked=false; @@ -358,7 +360,7 @@ void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_dat if (EditorNode::get_log()->is_hidden()) { log_forced_visible=true; - EditorNode::get_log()->show(); + EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log()); } EditorNode::get_log()->add_message(t); @@ -551,8 +553,14 @@ void ScriptEditorDebugger::_notification(int p_what) { if (error_count==0) { error_split->set_name("Errors"); + debugger_button->set_text("Debugger"); + debugger_button->set_icon(Ref<Texture>()); + tabs->set_tab_icon(error_split->get_index(),Ref<Texture>()); } else { error_split->set_name("Errors ("+itos(error_count)+")"); + debugger_button->set_text("Debugger ("+itos(error_count)+")"); + debugger_button->set_icon(get_icon("Error","EditorIcons")); + tabs->set_tab_icon(error_split->get_index(),get_icon("Error","EditorIcons")); } last_error_count=error_count; } @@ -569,8 +577,8 @@ void ScriptEditorDebugger::_notification(int p_what) { ppeer->set_stream_peer(connection); - show(); - emit_signal("show_debugger",true); + //EditorNode::get_singleton()->make_bottom_panel_item_visible(this); + //emit_signal("show_debugger",true); dobreak->set_disabled(false); tabs->set_current_tab(0); @@ -727,7 +735,9 @@ void ScriptEditorDebugger::stop(){ message.clear(); if (log_forced_visible) { - EditorNode::get_log()->hide(); + //EditorNode::get_singleton()->make_bottom_panel_item_visible(this); + if (EditorNode::get_log()->is_visible()) + EditorNode::get_singleton()->hide_bottom_panel(); log_forced_visible=false; } @@ -738,7 +748,8 @@ void ScriptEditorDebugger::stop(){ if (hide_on_stop) { - hide(); + if (is_visible()) + EditorNode::get_singleton()->hide_bottom_panel(); emit_signal("show_debugger",false); } @@ -770,7 +781,8 @@ void ScriptEditorDebugger::_stack_dump_frame_selected() { void ScriptEditorDebugger::_hide_request() { - hide(); + if (EditorNode::get_log()->is_visible()) + EditorNode::get_singleton()->hide_bottom_panel(); emit_signal("show_debugger",false); } @@ -1227,12 +1239,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor){ vbc->add_child(hbc); - reason = memnew( Label ); + reason = memnew( LineEdit ); reason->set_text(""); + reason->set_editable(false); hbc->add_child(reason); reason->add_color_override("font_color",Color(1,0.4,0.0,0.8)); reason->set_h_size_flags(SIZE_EXPAND_FILL); - reason->set_clip_text(true); + //reason->set_clip_text(true); hbc->add_child( memnew( VSeparator) ); @@ -1459,7 +1472,6 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor){ msgdialog = memnew( AcceptDialog ); add_child(msgdialog); - hide(); log_forced_visible=false; p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds,this); diff --git a/tools/editor/script_editor_debugger.h b/tools/editor/script_editor_debugger.h index 55c79ca3b3..0be311a990 100644 --- a/tools/editor/script_editor_debugger.h +++ b/tools/editor/script_editor_debugger.h @@ -54,6 +54,7 @@ class ScriptEditorDebugger : public Control { AcceptDialog *msgdialog; + Button *debugger_button; LineEdit *clicked_ctrl; LineEdit *clicked_ctrl_type; @@ -80,7 +81,7 @@ class ScriptEditorDebugger : public Control { TabContainer *tabs; - Label *reason; + LineEdit *reason; bool log_forced_visible; ScriptEditorDebuggerVariables *variables; @@ -186,6 +187,8 @@ public: void set_hide_on_stop(bool p_hide); + void set_tool_button(Button *p_tb) { debugger_button=p_tb; } + virtual Size2 get_minimum_size() const; ScriptEditorDebugger(EditorNode *p_editor=NULL); ~ScriptEditorDebugger(); diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp index ebbc488ff2..3d30b3882d 100644 --- a/tools/editor/settings_config_dialog.cpp +++ b/tools/editor/settings_config_dialog.cpp @@ -73,9 +73,6 @@ void EditorSettingsDialog::popup_edit_settings() { property_editor->edit(EditorSettings::get_singleton()); property_editor->get_property_editor()->update_tree(); - search_box->select_all(); - search_box->grab_focus(); - popup_centered_ratio(0.7); } @@ -248,22 +245,15 @@ void EditorSettingsDialog::_update_plugins() { } -void EditorSettingsDialog::_clear_search_box() { - - if (search_box->get_text()=="") - return; - - search_box->clear(); - property_editor->get_property_editor()->update_tree(); -} - void EditorSettingsDialog::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { rescan_plugins->set_icon(get_icon("Reload","EditorIcons")); - clear_button->set_icon(get_icon("Close","EditorIcons")); _update_plugins(); + } else if (p_what==NOTIFICATION_POST_POPUP) { + + property_editor->clear_search_box(); } } @@ -275,7 +265,6 @@ void EditorSettingsDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_plugin_settings"),&EditorSettingsDialog::_plugin_settings); ObjectTypeDB::bind_method(_MD("_plugin_edited"),&EditorSettingsDialog::_plugin_edited); ObjectTypeDB::bind_method(_MD("_plugin_install"),&EditorSettingsDialog::_plugin_install); - ObjectTypeDB::bind_method(_MD("_clear_search_box"),&EditorSettingsDialog::_clear_search_box); } EditorSettingsDialog::EditorSettingsDialog() { @@ -286,38 +275,17 @@ EditorSettingsDialog::EditorSettingsDialog() { add_child(tabs); set_child_rect(tabs); - VBoxContainer *vbc = memnew( VBoxContainer ); - tabs->add_child(vbc); - vbc->set_name("General"); - - HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); - vbc->add_child(hbc); - - Label *l = memnew( Label ); - l->set_text("Search: "); - hbc->add_child(l); - - search_box = memnew( LineEdit ); - search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); - hbc->add_child(search_box); - - clear_button = memnew( ToolButton ); - hbc->add_child(clear_button); - clear_button->connect("pressed",this,"_clear_search_box"); - property_editor = memnew( SectionedPropertyEditor ); //property_editor->hide_top_label(); - property_editor->get_property_editor()->set_use_filter(true); - property_editor->get_property_editor()->register_text_enter(search_box); + property_editor->set_name("General"); property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); - vbc->add_child(property_editor); + tabs->add_child(property_editor); - vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew( VBoxContainer ); tabs->add_child(vbc); vbc->set_name("Plugins"); - hbc = memnew( HBoxContainer ); + HBoxContainer *hbc = memnew( HBoxContainer ); vbc->add_child(hbc); hbc->add_child( memnew( Label("Plugin List: "))); hbc->add_spacer(); diff --git a/tools/editor/settings_config_dialog.h b/tools/editor/settings_config_dialog.h index e1c3238a64..119b4035ca 100644 --- a/tools/editor/settings_config_dialog.h +++ b/tools/editor/settings_config_dialog.h @@ -51,8 +51,6 @@ class EditorSettingsDialog : public AcceptDialog { Button *rescan_plugins; Tree *plugins; - LineEdit *search_box; - ToolButton *clear_button; SectionedPropertyEditor *property_editor; Timer *timer; |