Browse Source

Remove requirement to call UI.__init in app code, load default skin for player

Josh Engebretson 10 years ago
parent
commit
8283a43132

+ 11 - 2
Source/Atomic/UI/UI.cpp

@@ -79,7 +79,8 @@ UI::UI(Context* context) :
     rootWidget_(0),
     inputDisabled_(false),
     keyboardDisabled_(false),
-    initialized_(false)
+    initialized_(false),
+    skinLoaded_(false)
 {
 
 }
@@ -163,8 +164,16 @@ void UI::Initialize(const String& languageFile)
 
 void UI::LoadSkin(const String& skin, const String& overrideSkin)
 {
-    // Load the default skin, and override skin
+    // Load the default skin, and override skin (if any)
     tb::g_tb_skin->Load(skin.CString(), overrideSkin.CString());
+    skinLoaded_ = true;
+}
+
+void UI::LoadDefaultPlayerSkin()
+{
+    LoadSkin("DefaultUI/skin/skin.tb.txt");
+    AddFont("DefaultUI/fonts/vera.ttf", "Vera");
+    SetDefaultFont("Vera", 12);
 }
 
 void UI::SetDefaultFont(const String& name, int size)

+ 5 - 0
Source/Atomic/UI/UI.h

@@ -39,6 +39,10 @@ public:
     void Shutdown();
 
     void LoadSkin(const String& skin, const String& overrideSkin = String::EMPTY);
+    bool GetSkinLoaded() { return skinLoaded_; }
+    void LoadDefaultPlayerSkin();
+
+
     void AddFont(const String& fontFile, const String &name);
     void SetDefaultFont(const String& name, int size);
 
@@ -91,6 +95,7 @@ private:
     bool inputDisabled_;
     bool keyboardDisabled_;
     bool initialized_;
+    bool skinLoaded_;
 
     // Events
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);

+ 5 - 0
Source/AtomicEditor/Application/AEPlayerApp.cpp

@@ -30,6 +30,7 @@
 #include <Atomic/Core/ProcessUtils.h>
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Resource/ResourceEvents.h>
+#include <Atomic/UI/UI.h>
 
 // Move me
 #include <Atomic/Environment/Environment.h>
@@ -150,6 +151,10 @@ void AEPlayerApplication::Start()
 {
     AEEditorCommon::Start();
 
+    UI* ui = GetSubsystem<UI>();
+    ui->Initialize("DefaultUI/language/lng_en.tb.txt");
+    ui->LoadDefaultPlayerSkin();
+
     context_->RegisterSubsystem(new PlayerMode(context_));
     PlayerMode* playerMode = GetSubsystem<PlayerMode>();
     playerMode->ProcessArguments();

+ 0 - 18
Source/AtomicJS/Javascript/JSUIAPI.cpp

@@ -147,21 +147,6 @@ int UI_DebugShowSettingsWindow(duk_context* ctx)
     return 0;
 }
 
-int UI_Init(duk_context* ctx)
-{
-    JSVM* vm = JSVM::GetJSVM(ctx);
-    UI* ui = vm->GetSubsystem<UI>();
-
-    // TODO: take a config object
-    ui->Initialize("DefaultUI/language/lng_en.tb.txt");
-    ui->LoadSkin("DefaultUI/skin/skin.tb.txt", "Skin/skin.ui.txt");
-    ui->AddFont("DefaultUI/fonts/vera.ttf", "Vera");
-
-    ui->SetDefaultFont("Vera", 12);
-
-    return 0;
-}
-
 void jsapi_init_ui(JSVM* vm)
 {
     duk_context* ctx = vm->GetJSContext();
@@ -170,9 +155,6 @@ void jsapi_init_ui(JSVM* vm)
     duk_get_global_string(ctx, "Atomic");
     duk_get_prop_string(ctx, -1, "UI");
 
-    duk_push_c_function(ctx, UI_Init, DUK_VARARGS);
-    duk_put_prop_string(ctx, -2, "__init");
-
     duk_push_c_function(ctx, UI_DebugGetWrappedWidgetCount, 0);
     duk_put_prop_string(ctx, -2, "debugGetWrappedWidgetCount");