Browse Source

UI Skin preference

JimMarlowe 9 years ago
parent
commit
6624403337
2 changed files with 69 additions and 8 deletions
  1. 12 8
      Script/AtomicEditor/editor/Editor.ts
  2. 57 0
      Script/AtomicEditor/editor/Preferences.ts

+ 12 - 8
Script/AtomicEditor/editor/Editor.ts

@@ -103,14 +103,18 @@ class Editor extends Atomic.ScriptObject {
         this.parseArguments();
     }
 
-    initUI() {
-
-      var ui = Atomic.ui;
-      ui.loadSkin("AtomicEditor/resources/default_skin/skin.tb.txt", "AtomicEditor/editor/skin/skin.tb.txt");
-      ui.addFont("AtomicEditor/resources/vera.ttf", "Vera");
-      ui.addFont("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
-      ui.setDefaultFont("Vera", 12);
-
+    initUI() { 
+        var defSkin = Preferences.getInstance().getApplicationPreference("uiData", "skinPath", "AtomicEditor/editor/skin/");
+        var defDefaultSkin = Preferences.getInstance().getApplicationPreference("uiData", "defaultSkinPath", "AtomicEditor/resources/default_skin/");
+        var defFontFile = Preferences.getInstance().getApplicationPreference("uiData", "fontFile", "AtomicEditor/resources/vera.ttf");
+        var defFontName = Preferences.getInstance().getApplicationPreference("uiData", "fontName", "Vera");
+        var defFontSize = Preferences.getInstance().getApplicationPreference("uiData", "fontSize", 12);
+
+        var ui = Atomic.ui;
+        ui.loadSkin(defDefaultSkin + "/skin.tb.txt", defSkin + "/skin.tb.txt");
+        ui.addFont(defFontFile, defFontName);
+        ui.addFont("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
+        ui.setDefaultFont(defFontName, defFontSize);
     }
 
     saveWindowPreferences(data: Atomic.ScreenModeEvent): boolean {

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

@@ -157,6 +157,40 @@ class Preferences {
         return Preferences.instance;
     }
 
+    /**
+     * Return a preference value or the provided default from the user settings file
+     * @param  {string} settignsGroup name of the group the preference lives under
+     * @param  {string} preferenceName name of the preference to retrieve
+     * @param  {number | boolean | string} defaultValue value to return if pref doesn't exist
+     * @return {number|boolean|string}
+     */
+    getApplicationPreference(settingsGroup: string, preferenceName: string, defaultValue?: number): number;
+    getApplicationPreference(settingsGroup: string, preferenceName: string, defaultValue?: string): string;
+    getApplicationPreference(settingsGroup: string, preferenceName: string, defaultValue?: boolean): boolean;
+    getApplicationPreference(settingsGroup: string, preferenceName: string, defaultValue?: any): any {
+
+        // Cache the settings so we don't keep going out to the file
+        if (this._prefs == null) {
+            const prefsAppFileLoc = this.getPreferencesFullPath();
+            if (Atomic.fileSystem.fileExists(prefsAppFileLoc)) {
+                let prefsAppFile = new Atomic.File(prefsAppFileLoc, Atomic.FILE_READ);
+                try {
+                    let prefs = JSON.parse(prefsAppFile.readText());
+                    this._prefs = prefs;
+                } finally {
+                    prefsAppFile.close();
+                }
+            }
+        }
+
+        if (this._prefs && this._prefs[settingsGroup]) {
+            return this._prefs[settingsGroup][preferenceName] || defaultValue;
+        }
+
+        // if all else fails
+        return defaultValue;
+    }
+    
     /**
      * Return a preference value or the provided default from the user settings file located in the project
      * @param  {string} settingsGroup name of the group these settings should fall under
@@ -284,6 +318,14 @@ interface AceEditorSettings {
     tabSize: number;
 }
 
+interface UserInterfaceData {
+    skinPath : string;
+    defaultSkinPath : string;
+    fontFile : string;
+    fontName : string;
+    fontSize : number;
+}
+
 class PreferencesFormat {
 
     constructor() {
@@ -321,6 +363,15 @@ class PreferencesFormat {
             useSoftTabs: true,
             tabSize: 4
         };
+
+        this.uiData = {
+            skinPath : "AtomicEditor/editor/skin/",
+            defaultSkinPath : "AtomicEditor/resources/default_skin/",
+            fontFile : "AtomicEditor/resources/vera.ttf",
+            fontName : "Vera",
+            fontSize : 12
+        };
+
     }
 
     /**
@@ -351,6 +402,11 @@ class PreferencesFormat {
             updatedMissingDefaults = true;
         }
 
+        if (!prefs.uiData) {
+            prefs.uiData = this.uiData;
+            updatedMissingDefaults = true;
+        }
+
         return updatedMissingDefaults;
     }
 
@@ -358,6 +414,7 @@ class PreferencesFormat {
     editorWindow: WindowData;
     playerWindow: WindowData;
     codeEditorSettings: AceEditorSettings;
+    uiData : UserInterfaceData;
 }
 
 export = Preferences;