Browse Source

Removing android settings from editor preferences and instead using ToolCore preferences for them

Josh Engebretson 10 years ago
parent
commit
466882aa7e

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

@@ -62,11 +62,12 @@ class Preferences {
         }
         }
         //Read file
         //Read file
         jsonFile = new Atomic.File(filePath, Atomic.FILE_READ);
         jsonFile = new Atomic.File(filePath, Atomic.FILE_READ);
-        var prefs = <PreferencesFormat> JSON.parse(jsonFile.readText());
+        var prefs = <PreferencesFormat>JSON.parse(jsonFile.readText());
         if (prefs) {
         if (prefs) {
-            if(!prefs.recentProjects) prefs.recentProjects = [""];
+            if (!prefs.recentProjects) prefs.recentProjects = [""];
             this._prefs = prefs;
             this._prefs = prefs;
         }
         }
+
     }
     }
 
 
     write(): void {
     write(): void {
@@ -88,33 +89,6 @@ class Preferences {
         return this._prefs.recentProjects;
         return this._prefs.recentProjects;
     }
     }
 
 
-    get androidSDKPath(): string {
-        return Atomic.addTrailingSlash(this._prefs.androidSDKPath);
-    }
-
-    set androidSDKPath(path: string) {
-        this._prefs.androidSDKPath = path;
-        this.write()
-    }
-
-    get jdkRootPath(): string {
-        return Atomic.addTrailingSlash(this._prefs.jdkRootPath);
-    }
-
-    set jdkRootPath(path: string) {
-        this._prefs.jdkRootPath = path;
-        this.write();
-    }
-
-    get antPath(): string {
-        return Atomic.addTrailingSlash(this._prefs.antPath);
-    }
-
-    set antPath(path: string) {
-        this._prefs.antPath = path;
-        this.write();
-    }
-
     static getInstance(): Preferences {
     static getInstance(): Preferences {
         return Preferences.instance;
         return Preferences.instance;
     }
     }
@@ -122,9 +96,6 @@ class Preferences {
 
 
 class PreferencesFormat {
 class PreferencesFormat {
     recentProjects: [string];
     recentProjects: [string];
-    androidSDKPath: string;
-    jdkRootPath: string;
-    antPath: string;
     window: { x: number, y: number, width: number, height: number };
     window: { x: number, y: number, width: number, height: number };
 }
 }
 
 

+ 61 - 4
Script/AtomicEditor/ui/modal/build/platforms/AndroidSettingsWidget.ts

@@ -1,16 +1,73 @@
 
 
-
 class AndroidSettingsWidget extends Atomic.UIWidget {
 class AndroidSettingsWidget extends Atomic.UIWidget {
 
 
-  constructor() {
+    constructor() {
+
+        super();
 
 
-      super();
+        this.load("AtomicEditor/editor/ui/buildsettings_android.tb.txt");
 
 
-      this.load("AtomicEditor/editor/ui/buildsettings_android.tb.txt");
+        this.refreshWidgets();
+
+        this.subscribeToEvent(this, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            if (ev.target.id == "choose_sdk_path") {
+
+                var fileUtils = new Editor.FileUtils();
+
+                var path = fileUtils.getAndroidSDKPath("");
+
+                if (path.length) {
+
+                    var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
+                    if (toolPrefs.androidSDKPath != path) {
+                        toolPrefs.androidSDKPath = path;
+                        toolPrefs.save();
+                    }
+
+                    this.refreshWidgets();
+
+                }
+
+                return true;
+
+            }
+
+        }
+
+        return false;
+    }
+
+    refreshWidgets() {
+
+        var sdkPathEdit = <Atomic.UIEditField>this.getWidget("sdk_path");
+        var antPathEdit = <Atomic.UIEditField>this.getWidget("ant_path");
+        var jdkRootEdit = <Atomic.UIEditField>this.getWidget("jdk_root");
+
+        var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
+
+        sdkPathEdit.text = toolPrefs.androidSDKPath;
+        antPathEdit.text = toolPrefs.antPath;
+        jdkRootEdit.text = toolPrefs.jDKRootPath;
+
+        /*
+        appNameEdit_->SetText(settings.appName.CString());
+        appPackageEdit_->SetText(settings.package.CString());
+        productNameEdit_->SetText(settings.productName.CString());
+        companyNameEdit_->SetText(settings.companyName.CString());
+        sdkTargetSelect_->SetText(settings.targetSDKVersion.CString());
+        */
 
 
     }
     }
 
 
     storeValues() {
     storeValues() {
+
     }
     }
 
 
 }
 }

+ 2 - 2
Script/AtomicEditor/ui/modal/build/platforms/MacSettingsWidget.ts

@@ -15,11 +15,11 @@ class MacSettingsWidget extends Atomic.UIWidget {
         this.productNameEdit = <Atomic.UIEditField>this.getWidget("product_name");
         this.productNameEdit = <Atomic.UIEditField>this.getWidget("product_name");
         this.companyNameEdit = <Atomic.UIEditField>this.getWidget("company_name");
         this.companyNameEdit = <Atomic.UIEditField>this.getWidget("company_name");
 
 
-        this.refreshWidgetsFromSettings();
+        this.refreshWidgets();
 
 
     }
     }
 
 
-    refreshWidgetsFromSettings() {
+    refreshWidgets() {
 
 
         this.appNameEdit.text = this.settings.appName;
         this.appNameEdit.text = this.settings.appName;
         this.packageNameEdit.text = this.settings.packageName;
         this.packageNameEdit.text = this.settings.packageName;

+ 1 - 1
Script/Packages/ToolCore/ToolCore.json

@@ -2,7 +2,7 @@
 	"name" : "ToolCore",
 	"name" : "ToolCore",
 	"sources" : ["Source/ToolCore", "Source/ToolCore/Project", "Source/ToolCore/Platform", "Source/ToolCore/Command",
 	"sources" : ["Source/ToolCore", "Source/ToolCore/Project", "Source/ToolCore/Platform", "Source/ToolCore/Command",
 							 "Source/ToolCore/Import", "Source/ToolCore/Assets", "Source/ToolCore/License", "Source/ToolCore/Build"],
 							 "Source/ToolCore/Import", "Source/ToolCore/Assets", "Source/ToolCore/License", "Source/ToolCore/Build"],
-	"classes" : ["ToolEnvironment", "ToolSystem", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
+	"classes" : ["ToolEnvironment", "ToolSystem", "ToolPrefs", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
 							 "PlatformWindows", "PlatformAndroid", "PlatformIOS", "Command", "PlayCmd", "OpenAssetImporter",
 							 "PlatformWindows", "PlatformAndroid", "PlatformIOS", "Command", "PlayCmd", "OpenAssetImporter",
 							 "Asset", "AssetDatabase", "AssetImporter", "AudioImporter", "ModelImporter", "MaterialImporter", "AnimationImportInfo",
 							 "Asset", "AssetDatabase", "AssetImporter", "AudioImporter", "ModelImporter", "MaterialImporter", "AnimationImportInfo",
 							 "PrefabImporter", "JavascriptImporter", "TextureImporter", "SpriterImporter", "PEXImporter", "LicenseSystem",
 							 "PrefabImporter", "JavascriptImporter", "TextureImporter", "SpriterImporter", "PEXImporter", "LicenseSystem",

+ 25 - 0
Source/AtomicEditor/Utils/FileUtils.cpp

@@ -106,6 +106,31 @@ String FileUtils::GetBuildPath(const String& defaultPath)
 
 
 }
 }
 
 
+String FileUtils::GetAndroidSDKPath(const String& defaultPath)
+{
+    String sdkPath;
+
+    nfdchar_t *outPath = NULL;
+
+    nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your Android SDK",
+                                defaultPath.Length() ? defaultPath.CString() : NULL,
+                                &outPath);
+
+    if (outPath && result == NFD_OKAY)
+    {
+        sdkPath = outPath;
+    }
+
+    if (outPath)
+        free(outPath);
+
+    GetSubsystem<Graphics>()->RaiseWindow();
+
+    return GetInternalPath(sdkPath);
+
+}
+
+
 
 
 void FileUtils::RevealInFinder(const String& fullpath)
 void FileUtils::RevealInFinder(const String& fullpath)
 {
 {

+ 1 - 0
Source/AtomicEditor/Utils/FileUtils.h

@@ -21,6 +21,7 @@ public:
 
 
     bool CreateDirs(const String& folder);
     bool CreateDirs(const String& folder);
 
 
+    String GetAndroidSDKPath(const String& defaultPath);
     String OpenProjectFileDialog();
     String OpenProjectFileDialog();
     String NewProjectFileDialog();
     String NewProjectFileDialog();
     String GetBuildPath(const String& defaultPath);
     String GetBuildPath(const String& defaultPath);

+ 34 - 1
Source/ToolCore/Platform/PlatformAndroid.cpp

@@ -1,6 +1,7 @@
 
 
+#include <Atomic/IO/FileSystem.h>
 
 
-#include "../Build/BuildWeb.h"
+#include "../ToolEnvironment.h"
 #include "PlatformAndroid.h"
 #include "PlatformAndroid.h"
 
 
 namespace ToolCore
 namespace ToolCore
@@ -21,5 +22,37 @@ BuildBase* PlatformAndroid::NewBuild(Project *project)
     return 0;
     return 0;
 }
 }
 
 
+void PlatformAndroid::PrependAndroidCommandArgs(Vector<String> args)
+{
+    // android is a batch file on windows, so have to run with cmd /c
+    args.Push("/c");
+    args.Push("\"" + GetAndroidCommand() + "\"");
+
+}
+
+String PlatformAndroid::GetAndroidCommand() const
+{
+    ToolPrefs* prefs = GetSubsystem<ToolEnvironment>()->GetToolPrefs();
+
+    String androidCommand = GetNativePath(prefs->GetAndroidSDKPath());
+
+    if (!androidCommand.Length())
+        return String::EMPTY;
+
+#ifdef ATOMIC_PLATFORM_OSX
+    //Vector<String> args = String("list targets").Split(' ');
+    androidCommand += "tools/android";
+#else
+
+    // android is a batch file on windows, so have to run with cmd /c
+    androidCommand += "\\tools\\android.bat";
+
+    //androidCommand = "cmd";
+#endif
+
+    return androidCommand;
+
+}
+
 
 
 }
 }

+ 6 - 0
Source/ToolCore/Platform/PlatformAndroid.h

@@ -18,8 +18,14 @@ public:
     String GetName() { return "ANDROID"; }
     String GetName() { return "ANDROID"; }
     PlatformID GetPlatformID() { return PLATFORMID_ANDROID; }
     PlatformID GetPlatformID() { return PLATFORMID_ANDROID; }
 
 
+    String GetAndroidCommand() const;
+
     BuildBase* NewBuild(Project* project);
     BuildBase* NewBuild(Project* project);
 
 
+private:
+
+    void PrependAndroidCommandArgs(Vector<String> args);
+
 };
 };
 
 
 }
 }

+ 5 - 1
Source/ToolCore/ToolEnvironment.cpp

@@ -16,7 +16,8 @@ using namespace rapidjson;
 namespace ToolCore
 namespace ToolCore
 {
 {
 
 
-ToolEnvironment::ToolEnvironment(Context* context) : Object(context)
+ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
+    toolPrefs_(new ToolPrefs(context))
 {
 {
 
 
 }
 }
@@ -28,6 +29,7 @@ ToolEnvironment::~ToolEnvironment()
 
 
 bool ToolEnvironment::InitFromPackage()
 bool ToolEnvironment::InitFromPackage()
 {
 {
+    toolPrefs_->Load();
 
 
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
 
@@ -47,6 +49,8 @@ bool ToolEnvironment::InitFromPackage()
 bool ToolEnvironment::InitFromJSON(bool atomicTool)
 bool ToolEnvironment::InitFromJSON(bool atomicTool)
 {
 {
 
 
+    toolPrefs_->Load();
+
     // make sure config path is initialized
     // make sure config path is initialized
     GetDevConfigFilename();
     GetDevConfigFilename();
 
 

+ 8 - 0
Source/ToolCore/ToolEnvironment.h

@@ -3,6 +3,8 @@
 
 
 #include <Atomic/Core/Object.h>
 #include <Atomic/Core/Object.h>
 
 
+#include "ToolPrefs.h"
+
 using namespace Atomic;
 using namespace Atomic;
 
 
 namespace ToolCore
 namespace ToolCore
@@ -32,6 +34,10 @@ public:
     void SetRootSourceDir(const String& sourceDir);
     void SetRootSourceDir(const String& sourceDir);
     void SetRootBuildDir(const String& buildDir, bool setBinaryPaths = false);
     void SetRootBuildDir(const String& buildDir, bool setBinaryPaths = false);
 
 
+    ToolPrefs* GetToolPrefs() { return toolPrefs_; }
+    void SaveToolPrefs() { toolPrefs_->Save(); }
+    void LoadToolPrefs() { toolPrefs_->Load(); }
+
     const String& GetRootSourceDir() { return rootSourceDir_; }
     const String& GetRootSourceDir() { return rootSourceDir_; }
     const String& GetRootBuildDir() { return rootBuildDir_; }
     const String& GetRootBuildDir() { return rootBuildDir_; }
 
 
@@ -101,6 +107,8 @@ private:
     String webBuildDir_;
     String webBuildDir_;
 
 
     String devConfigFilename_;
     String devConfigFilename_;
+
+    SharedPtr<ToolPrefs> toolPrefs_;
 };
 };
 
 
 }
 }

+ 85 - 0
Source/ToolCore/ToolPrefs.cpp

@@ -0,0 +1,85 @@
+
+#include <Atomic/IO/Log.h>
+#include <Atomic/IO/File.h>
+#include <Atomic/IO/FileSystem.h>
+
+#include <Atomic/Resource/JSONFile.h>
+
+#include "ToolPrefs.h"
+
+namespace ToolCore
+{
+
+ToolPrefs::ToolPrefs(Context* context) : Object(context)
+{
+
+}
+
+ToolPrefs::~ToolPrefs()
+{
+
+}
+
+String ToolPrefs::GetPrefsPath()
+{
+    FileSystem* fs = GetSubsystem<FileSystem>();
+    String path = fs->GetAppPreferencesDir("AtomicGameEngine", "ToolCore");
+    path += "ToolPrefs.json";
+    return path;
+
+}
+
+void ToolPrefs::Load()
+{
+    String path = GetPrefsPath();
+
+    SharedPtr<File> file(new File(context_, path));
+
+    if (!file->IsOpen())
+        return;
+
+    SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
+    bool result = jsonFile->Load(*file);
+    file->Close();
+
+    if (!result)
+        return;
+
+    JSONValue root = jsonFile->GetRoot();
+    if (root == JSONValue::EMPTY)
+        return;
+
+    JSONValue androidRoot = root.GetChild("android");
+
+    if (androidRoot.IsObject()) {
+
+        androidSDKPath_ = androidRoot.GetString("androidSDKPath");
+        jdkRootPath_ = androidRoot.GetString("jdkRootPath");
+        antPath_ = androidRoot.GetString("antPath");
+    }
+
+}
+
+void ToolPrefs::Save()
+{
+    String path = GetPrefsPath();
+
+    SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
+
+    JSONValue root = jsonFile->CreateRoot();
+
+    SharedPtr<File> file(new File(context_, path, FILE_WRITE));
+
+    JSONValue androidRoot = root.CreateChild("android");
+    androidRoot.SetString("androidSDKPath", androidSDKPath_);
+    androidRoot.SetString("jdkRootPath", jdkRootPath_);
+    androidRoot.SetString("antPath", antPath_);
+
+    jsonFile->Save(*file, String("   "));
+
+    file->Close();
+
+}
+
+
+}

+ 39 - 0
Source/ToolCore/ToolPrefs.h

@@ -0,0 +1,39 @@
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+using namespace Atomic;
+
+namespace ToolCore
+{
+
+class ToolPrefs : public Object
+{
+    OBJECT(ToolPrefs)
+
+public:
+
+    ToolPrefs(Context* context);
+    virtual ~ToolPrefs();
+
+    const String& GetAndroidSDKPath() { return androidSDKPath_; }
+    const String& GetJDKRootPath() { return jdkRootPath_; }
+    const String& GetAntPath() { return antPath_; }
+
+    void SetAndroidSDKPath(const String& path) { androidSDKPath_ = path; }
+    void SetJDKRootPath(const String& path) { jdkRootPath_ = path; }
+    void SetAntPath(const String& path) { antPath_ = path; }
+
+    String GetPrefsPath();
+    void Load();
+    void Save();
+
+private:
+
+    String androidSDKPath_;
+    String jdkRootPath_;
+    String antPath_;
+
+};
+
+}