Browse Source

Added check if monitor was disabled then restore player position to the available one

rsredsq 10 years ago
parent
commit
41060aba06

+ 1 - 1
Script/AtomicEditor/editor/Editor.ts

@@ -54,7 +54,7 @@ class Editor extends Atomic.ScriptObject {
         });
         });
 
 
         this.subscribeToEvent("IPCPlayerWindowChanged", (data) => {
         this.subscribeToEvent("IPCPlayerWindowChanged", (data) => {
-            Preferences.getInstance().savePlayerWindowData(data.posX, data.posY, data.width, data.height);
+            Preferences.getInstance().savePlayerWindowData(data.posX, data.posY, data.width, data.height, data.monitor);
         });
         });
 
 
         this.subscribeToEvent("ExitRequested", (data) => this.handleExitRequested(data));
         this.subscribeToEvent("ExitRequested", (data) => this.handleExitRequested(data));

+ 4 - 3
Script/AtomicEditor/editor/Preferences.ts

@@ -94,12 +94,12 @@ class Preferences {
             width = graphics.getWidth();
             width = graphics.getWidth();
             height = graphics.getHeight();
             height = graphics.getHeight();
         }
         }
-        this._prefs.editorWindow = { x: pos[0], y: pos[1], width: width, height: height };
+        this._prefs.editorWindow = { x: pos[0], y: pos[1], width: width, height: height, monitor: graphics.getCurrentMonitor() };
         jsonFile.writeString(JSON.stringify(this._prefs, null, 2));
         jsonFile.writeString(JSON.stringify(this._prefs, null, 2));
     }
     }
 
 
-    savePlayerWindowData(x, y, width, height) {
-        this._prefs.playerWindow = { x: x, y: y, width: width, height: height };
+    savePlayerWindowData(x, y, width, height, monitor) {
+        this._prefs.playerWindow = { x: x, y: y, width: width, height: height, monitor: monitor };
     }
     }
 
 
     useDefaultConfig():void {
     useDefaultConfig():void {
@@ -128,6 +128,7 @@ interface WindowData {
     y: number;
     y: number;
     width: number;
     width: number;
     height: number;
     height: number;
+    monitor: number;
 }
 }
 
 
 class PreferencesFormat {
 class PreferencesFormat {

+ 7 - 2
Script/AtomicEditor/ui/Shortcuts.ts

@@ -30,8 +30,13 @@ class Shortcuts extends Atomic.ScriptObject {
         } else {
         } else {
             var playerWindow = Preferences.getInstance().playerWindow;
             var playerWindow = Preferences.getInstance().playerWindow;
             if (playerWindow) {
             if (playerWindow) {
-                var args = "--windowposx " + playerWindow.x + " --windowposy " + playerWindow.y + " --windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable";
-                Atomic.editorMode.playProject(args, debug);
+                if ((playerWindow.monitor + 1) > Atomic.graphics.getMonitorsNumber()) {
+                    var args = "--windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable";
+                    Atomic.editorMode.playProject(args, debug);
+                } else {
+                    var args = "--windowposx " + playerWindow.x + " --windowposy " + playerWindow.y + " --windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable";
+                    Atomic.editorMode.playProject(args, debug);
+                }
             } else {
             } else {
                 Atomic.editorMode.playProject("", debug);
                 Atomic.editorMode.playProject("", debug);
             }
             }

+ 12 - 0
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -2781,4 +2781,16 @@ void RegisterGraphicsLibrary(Context* context)
     Zone::RegisterObject(context);
     Zone::RegisterObject(context);
 }
 }
 
 
+// ATOMIC BEGIN
+int Graphics::GetCurrentMonitor()
+{
+    return SDL_GetWindowDisplayIndex((SDL_Window*) this->GetSDLWindow());
+}
+
+int Graphics::GetMonitorsNumber()
+{
+    return SDL_GetNumVideoDisplays();
+}
+// ATOMIC END
+
 }
 }

+ 7 - 0
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.h

@@ -499,6 +499,13 @@ public:
     /// Return maximum number of supported bones for skinning.
     /// Return maximum number of supported bones for skinning.
     static unsigned GetMaxBones() { return 128; }
     static unsigned GetMaxBones() { return 128; }
 
 
+    // ATOMIC BEGIN
+    /// Return the current monitor number
+    int GetCurrentMonitor();
+    /// Return the available monitors number
+    int GetMonitorsNumber();
+    // ATOMIC END
+
 private:
 private:
     /// Create the application window.
     /// Create the application window.
     bool OpenWindow(int width, int height, bool resizable, bool borderless);
     bool OpenWindow(int width, int height, bool resizable, bool borderless);

+ 12 - 0
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -2761,4 +2761,16 @@ void RegisterGraphicsLibrary(Context* context)
     Zone::RegisterObject(context);
     Zone::RegisterObject(context);
 }
 }
 
 
+// ATOMIC BEGIN
+int Graphics::GetCurrentMonitor()
+{
+    return SDL_GetWindowDisplayIndex((SDL_Window*) this->GetSDLWindow());
+}
+
+int Graphics::GetMonitorsNumber()
+{
+    return SDL_GetNumVideoDisplays();
+}
+// ATOMIC END
+
 }
 }

+ 7 - 0
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.h

@@ -493,6 +493,13 @@ public:
     /// Return maximum number of supported bones for skinning.
     /// Return maximum number of supported bones for skinning.
     static unsigned GetMaxBones() { return 64; }
     static unsigned GetMaxBones() { return 64; }
 
 
+    // ATOMIC BEGIN
+    /// Return the current monitor number
+    int GetCurrentMonitor();
+    /// Return the available monitors number
+    int GetMonitorsNumber();
+    // ATOMIC END
+
 private:
 private:
     /// Set vertex buffer stream frequency.
     /// Set vertex buffer stream frequency.
     void SetStreamFrequency(unsigned index, unsigned frequency);
     void SetStreamFrequency(unsigned index, unsigned frequency);

+ 12 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -3296,4 +3296,16 @@ void RegisterGraphicsLibrary(Context* context)
     Zone::RegisterObject(context);
     Zone::RegisterObject(context);
 }
 }
 
 
+// ATOMIC BEGIN
+int Graphics::GetCurrentMonitor()
+{
+    return SDL_GetWindowDisplayIndex((SDL_Window*) this->GetSDLWindow());
+}
+
+int Graphics::GetMonitorsNumber()
+{
+    return SDL_GetNumVideoDisplays();
+}
+// ATOMIC END
+
 }
 }

+ 7 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.h

@@ -525,6 +525,13 @@ public:
     /// Return whether is using an OpenGL 3 context.
     /// Return whether is using an OpenGL 3 context.
     static bool GetGL3Support() { return gl3Support; }
     static bool GetGL3Support() { return gl3Support; }
 
 
+    // ATOMIC BEGIN
+    /// Return the current monitor number
+    int GetCurrentMonitor();
+    /// Return the available monitors number
+    int GetMonitorsNumber();
+    // ATOMIC END
+
 private:
 private:
     /// Create the application window icon.
     /// Create the application window icon.
     void CreateWindowIcon();
     void CreateWindowIcon();

+ 1 - 0
Source/AtomicEditor/PlayerMode/AEPlayerEvents.h

@@ -25,6 +25,7 @@ EVENT(E_IPCPLAYERWINDOWCHANGED, IPCPlayerWindowChanged)
     PARAM(P_POSY, PosY);
     PARAM(P_POSY, PosY);
     PARAM(P_WIDTH, Width);
     PARAM(P_WIDTH, Width);
     PARAM(P_HEIGHT, Height);
     PARAM(P_HEIGHT, Height);
+    PARAM(P_MONITOR, Monitor);
 }
 }
 
 
 EVENT(E_PLAYERQUIT, PlayerQuit)
 EVENT(E_PLAYERQUIT, PlayerQuit)

+ 1 - 0
Source/AtomicEditor/PlayerMode/AEPlayerMode.cpp

@@ -248,6 +248,7 @@ void PlayerMode::HandleExitRequest(StringHash eventType, VariantMap& eventData)
     data[P_POSY] = graphics->GetWindowPosition().y_;
     data[P_POSY] = graphics->GetWindowPosition().y_;
     data[P_WIDTH] = graphics->GetWidth();
     data[P_WIDTH] = graphics->GetWidth();
     data[P_HEIGHT] = graphics->GetHeight();
     data[P_HEIGHT] = graphics->GetHeight();
+    data[P_MONITOR] = graphics->GetCurrentMonitor();
     ipc_->SendEventToBroker(E_IPCPLAYERWINDOWCHANGED, data);
     ipc_->SendEventToBroker(E_IPCPLAYERWINDOWCHANGED, data);
     SendEvent(E_PLAYERQUIT);
     SendEvent(E_PLAYERQUIT);
 }
 }