Browse Source

Close Player Output window when player quits #215

JimMarlowe 9 years ago
parent
commit
25a1a8881b

+ 8 - 3
Resources/EditorData/AtomicEditor/editor/ui/playeroutput.tb.txt

@@ -1,7 +1,12 @@
 TBLayout: axis: y, distribution: gravity, position: left
-	TBTextField: text: "Player Output:", id: project_name
+	TBTextField: text: "Player Output: (This log is also available in the Tools menu)", id: project_name
 	TBEditField: multiline: 1, styling: 1, gravity: all, id: output, readonly: 1, adapt-to-content: 0
 		lp: min-width: 640, min-height: 480
 	TBSeparator: gravity: left right, skin: AESeparator
-	TBLayout: 
-		TBButton: text: Close, id: closebutton
+	TBLayout:
+		TBClickLabel: text: Close on Player Stop    
+			font: size: 14
+			TBCheckBox: id: closeonstop, value: 1
+		TBButton: text: "  Close  ", id: closebutton
+			font: size: 16
+

+ 17 - 0
Script/AtomicEditor/editor/Preferences.ts

@@ -185,6 +185,10 @@ class Preferences {
         return this._prefs.editorBuildData;
     }
 
+    get editorFeatures(): EditorFeatures {
+        return this._prefs.editorFeatures;
+    }
+
     static getInstance(): Preferences {
         return Preferences.instance;
     }
@@ -335,6 +339,9 @@ interface EditorBuildData {
     lastEditorBuildSHA: string;
 }
 
+interface EditorFeatures {
+    closePlayerLog: boolean;
+}
 
 class PreferencesFormat {
 
@@ -388,6 +395,10 @@ class PreferencesFormat {
             lastEditorBuildSHA: "Unversioned Build"
         };
 
+        this.editorFeatures = {
+            closePlayerLog: true
+        };
+
     }
 
     /**
@@ -433,6 +444,11 @@ class PreferencesFormat {
             updatedMissingDefaults = true;
         }
 
+        if (!prefs.editorFeatures) {
+            prefs.editorFeatures = this.editorFeatures;
+            updatedMissingDefaults = true;
+        }
+
         return updatedMissingDefaults;
     }
 
@@ -443,6 +459,7 @@ class PreferencesFormat {
     uiData: UserInterfaceData;
     editorBuildData: EditorBuildData;
     colorHistory: string[];
+    editorFeatures: EditorFeatures;
 }
 
 export = Preferences;

+ 18 - 2
Script/AtomicEditor/ui/playmode/PlayMode.ts

@@ -22,17 +22,20 @@
 
 import EditorEvents = require("../../editor/EditorEvents");
 import PlayerOutput = require("./PlayerOutput");
+import Preferences = require("../../editor/Preferences");
 
 class PlayMode extends Atomic.ScriptObject {
 
     inErrorState: boolean;
+    myPlayer: PlayerOutput;
 
     constructor() {
 
         super();
-
+        this.myPlayer = null;
         this.subscribeToEvent("IPCJSError", (ev: Atomic.IPCJSErrorEvent) => this.handleIPCJSError(ev));
         this.subscribeToEvent(EditorEvents.PlayerStarted, (ev) => this.handlePlayerStarted(ev));
+        this.subscribeToEvent(EditorEvents.PlayerStopped, (ev) => this.handlePlayerStopped(ev));
 
     }
 
@@ -40,9 +43,22 @@ class PlayMode extends Atomic.ScriptObject {
 
         this.inErrorState = false;
 
-        new PlayerOutput();
+        if ( this.myPlayer != null ) {
+             this.myPlayer.remove();
+        }
+
+        this.myPlayer = new PlayerOutput();
     }
 
+    handlePlayerStopped(ev) {
+
+        if ( Preferences.getInstance().editorFeatures.closePlayerLog ) {
+             this.myPlayer.remove();
+        }
+
+    }
+
+
     handleIPCJSError(ev: Atomic.IPCJSErrorEvent) {
 
         if (this.inErrorState)

+ 14 - 1
Script/AtomicEditor/ui/playmode/PlayerOutput.ts

@@ -22,10 +22,12 @@
 
 import EditorEvents = require("../../editor/EditorEvents");
 import EditorUI = require("../EditorUI");
+import Preferences = require("../../editor/Preferences");
 
 class PlayerOutput extends Atomic.UIWindow {
 
     output: Atomic.UIEditField;
+    closeOnStop: Atomic.UICheckBox;
 
     constructor() {
 
@@ -39,6 +41,9 @@ class PlayerOutput extends Atomic.UIWindow {
         this.load("AtomicEditor/editor/ui/playeroutput.tb.txt");
 
         this.output = <Atomic.UIEditField> this.getWidget("output");
+        this.closeOnStop = <Atomic.UICheckBox> this.getWidget("closeonstop");
+        
+        this.closeOnStop.value = Preferences.getInstance().editorFeatures.closePlayerLog ? 1 : 0;
 
         (<Atomic.UIButton>this.getWidget("closebutton")).onClick = () => {
 
@@ -68,7 +73,15 @@ class PlayerOutput extends Atomic.UIWindow {
 
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
-
+    
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+            var id = ev.target.id;
+            if (id == "closeonstop") {
+                Preferences.getInstance().editorFeatures.closePlayerLog = this.closeOnStop.value > 0 ? true : false;
+                Preferences.getInstance().write();
+                return true;
+            }
+        }
     }
 
 }