Browse Source

WIP new ui support in editor player mode

Josh Engebretson 10 years ago
parent
commit
5d7098a483

+ 28 - 24
Source/Atomic/UI/UI.cpp

@@ -72,7 +72,7 @@ void UI::Shutdown()
     SetInputDisabled(true);
     SetInputDisabled(true);
 }
 }
 
 
-void UI::Initialize()
+void UI::Initialize(const String& languageFile)
 {
 {
     Graphics* graphics = GetSubsystem<Graphics>();
     Graphics* graphics = GetSubsystem<Graphics>();
     assert(graphics);
     assert(graphics);
@@ -87,39 +87,17 @@ void UI::Initialize()
     TBWidgetsAnimationManager::Init();
     TBWidgetsAnimationManager::Init();
 
 
     renderer_ = new UIRenderer(graphics_->GetContext());
     renderer_ = new UIRenderer(graphics_->GetContext());
-    tb_core_init(renderer_, "AtomicEditor/resources/language/lng_en.tb.txt");
-
-    // Load the default skin, and override skin that contains the graphics specific to the demo.
-    tb::g_tb_skin->Load("AtomicEditor/resources/default_skin/skin.tb.txt", "AtomicEditor/editor/skin/skin.tb.txt");
+    tb_core_init(renderer_, languageFile.CString());
 
 
     //register_tbbf_font_renderer();
     //register_tbbf_font_renderer();
     //register_stb_font_renderer();
     //register_stb_font_renderer();
     register_freetype_font_renderer();
     register_freetype_font_renderer();
 
 
-    tb::g_font_manager->AddFontInfo("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
-    tb::g_font_manager->AddFontInfo("AtomicEditor/resources/vera.ttf", "Vera");
-
-    tb::TBFontDescription fd;
-    fd.SetID(tb::TBIDC("Vera"));
-    fd.SetSize(tb::g_tb_skin->GetDimensionConverter()->DpToPx(12));
-    tb::g_font_manager->SetDefaultFontDescription(fd);
-
-    // Create the font now.
-    tb::TBFontFace *font = tb::g_font_manager->CreateFontFace(tb::g_font_manager->GetDefaultFontDescription());
-
-    // Render some glyphs in one go now since we know we are going to use them. It would work fine
-    // without this since glyphs are rendered when needed, but with some extra updating of the glyph bitmap.
-    if (font)
-        font->RenderGlyphs(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~•·åäöÅÄÖ");
-
     rootWidget_ = new TBWidget();
     rootWidget_ = new TBWidget();
-    //rootWidget_->SetSkinBg(tb::TBIDC("background"));
 
 
     int width = graphics_->GetWidth();
     int width = graphics_->GetWidth();
     int height = graphics_->GetHeight();
     int height = graphics_->GetHeight();
     rootWidget_->SetSize(width, height);
     rootWidget_->SetSize(width, height);
-    //SetSize(width, height);
-
     rootWidget_->SetVisibilility(tb::WIDGET_VISIBILITY_VISIBLE);
     rootWidget_->SetVisibilility(tb::WIDGET_VISIBILITY_VISIBLE);
 
 
     SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown));
     SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown));
@@ -138,6 +116,32 @@ void UI::Initialize()
     //TB_DEBUG_SETTING(LAYOUT_BOUNDS) = 1;
     //TB_DEBUG_SETTING(LAYOUT_BOUNDS) = 1;
 }
 }
 
 
+void UI::LoadSkin(const String& skin, const String& overrideSkin)
+{
+    // Load the default skin, and override skin
+    tb::g_tb_skin->Load(skin.CString(), overrideSkin.CString());
+}
+
+void UI::SetDefaultFont(const String& name, int size)
+{
+    tb::TBFontDescription fd;
+    fd.SetID(tb::TBIDC(name.CString()));
+    fd.SetSize(tb::g_tb_skin->GetDimensionConverter()->DpToPx(12));
+    tb::g_font_manager->SetDefaultFontDescription(fd);
+
+    // Create the font now.
+    tb::TBFontFace *font = tb::g_font_manager->CreateFontFace(tb::g_font_manager->GetDefaultFontDescription());
+
+    // Render some glyphs in one go now since we know we are going to use them. It would work fine
+    // without this since glyphs are rendered when needed, but with some extra updating of the glyph bitmap.
+    if (font)
+        font->RenderGlyphs(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~•·åäöÅÄÖ");
+}
+
+void UI::AddFont(const String& fontFile, const String& name)
+{
+    tb::g_font_manager->AddFontInfo(fontFile.CString(), name.CString());
+}
 
 
 void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigned batchStart, unsigned batchEnd)
 void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigned batchStart, unsigned batchEnd)
 {
 {

+ 6 - 1
Source/Atomic/UI/UI.h

@@ -36,9 +36,14 @@ public:
     void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
     void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
     void SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData);
     void SubmitBatchVertexData(Texture* texture, const PODVector<float>& vertexData);
 
 
-    void Initialize();
+    void Initialize(const String& languageFile);
+
     void Shutdown();
     void Shutdown();
 
 
+    void LoadSkin(const String& skin, const String& overrideSkin);
+    void AddFont(const String& fontFile, const String &name);
+    void SetDefaultFont(const String& name, int size);
+
 private:
 private:
 
 
     static WeakPtr<Context> readerContext_;
     static WeakPtr<Context> readerContext_;

+ 6 - 1
Source/AtomicEditor/Source/AEApplication.cpp

@@ -96,7 +96,12 @@ void AEApplication::Start()
 
 
     // initialize after EditorResources set
     // initialize after EditorResources set
     UI* tbui = GetSubsystem<UI>();
     UI* tbui = GetSubsystem<UI>();
-    tbui->Initialize();
+
+    tbui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
+    tbui->LoadSkin("AtomicEditor/resources/default_skin/skin.tb.txt", "AtomicEditor/editor/skin/skin.tb.txt");
+    tbui->AddFont("AtomicEditor/resources/vera.ttf", "Vera");
+    tbui->AddFont("AtomicEditor/resources/MesloLGS-Regular.ttf", "Monaco");
+    tbui->SetDefaultFont("Vera", 12);
 
 
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();
     input->SetMouseVisible(true);
     input->SetMouseVisible(true);

+ 6 - 1
Source/AtomicEditor/Source/Player/AEPlayer.cpp

@@ -78,7 +78,8 @@ bool AEPlayer::Play(AEPlayerMode mode, const IntRect &rect)
 
 
     Vector<String> paths;
     Vector<String> paths;
     paths.Push(env->GetCoreDataDir());
     paths.Push(env->GetCoreDataDir());
-    paths.Push("/Users/josh/Dev/atomic/AtomicExamples/Basic2D/Resources");
+    paths.Push(env->GetPlayerDataDir());
+    paths.Push("/Users/josh/Dev/atomic/AtomicExamples/UIExample/Resources");
 
 
     String resourcePaths;
     String resourcePaths;
     resourcePaths.Join(paths, "!");
     resourcePaths.Join(paths, "!");
@@ -90,6 +91,10 @@ bool AEPlayer::Play(AEPlayerMode mode, const IntRect &rect)
     vargs = args.Split(' ');
     vargs = args.Split(' ');
     vargs.Insert(0, "--player");
     vargs.Insert(0, "--player");
 
 
+    String dump;
+    dump.Join(vargs, " ");
+    LOGINFOF("Launching Broker %s", dump.CString());
+
     IPC* ipc = GetSubsystem<IPC>();
     IPC* ipc = GetSubsystem<IPC>();
     broker_ = ipc->SpawnWorker(editorBinary, vargs);
     broker_ = ipc->SpawnWorker(editorBinary, vargs);
 
 

+ 13 - 3
Source/AtomicEditor/Source/Player/AEPlayerApplication.cpp

@@ -152,9 +152,19 @@ void AEPlayerApplication::Start()
 
 
     SubscribeToEvent(E_IPCHELLOFROMBROKER, HANDLER(AEPlayerApplication, HandleHelloFromBroker));
     SubscribeToEvent(E_IPCHELLOFROMBROKER, HANDLER(AEPlayerApplication, HandleHelloFromBroker));
 
 
-    IPC* ipc = new IPC(context_);
-    context_->RegisterSubsystem(ipc);
-    ipc->InitWorker(fd_[0], fd_[1]);
+    if (fd_[0] != -1 && fd_[1] != -1)
+    {
+        IPC* ipc = new IPC(context_);
+        context_->RegisterSubsystem(ipc);
+        ipc->InitWorker(fd_[0], fd_[1]);
+    }
+
+    UI* tbui = GetSubsystem<UI>();
+
+    tbui->Initialize("UI/language/lng_en.tb.txt");
+    tbui->LoadSkin("UI/default_skin/skin.tb.txt", "");
+    tbui->AddFont("UI/fonts/vera.ttf", "Vera");
+    tbui->SetDefaultFont("Vera", 12);
 
 
     // Instantiate and register the Javascript subsystem
     // Instantiate and register the Javascript subsystem
     javascript = new Javascript(context_);
     javascript = new Javascript(context_);

+ 1 - 1
Source/ThirdParty/TurboBadger/tb_skin.cpp

@@ -128,7 +128,7 @@ bool TBSkin::Load(const char *skin_file, const char *override_skin_file)
 {
 {
 	if (!LoadInternal(skin_file))
 	if (!LoadInternal(skin_file))
 		return false;
 		return false;
-	if (override_skin_file && !LoadInternal(override_skin_file))
+    if (override_skin_file && strlen(override_skin_file) && !LoadInternal(override_skin_file))
 		return false;
 		return false;
 	return ReloadBitmaps();
 	return ReloadBitmaps();
 }
 }

+ 1 - 0
Source/ToolCore/ToolEnvironment.cpp

@@ -94,6 +94,7 @@ void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
 {
 {
     rootSourceDir_ = AddTrailingSlash(sourceDir);
     rootSourceDir_ = AddTrailingSlash(sourceDir);
     resourceCoreDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/CoreData";
     resourceCoreDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/CoreData";
+    resourcePlayerDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/PlayerData";
     resourceEditorDataDir_ = rootSourceDir_ + "Data/AtomicEditor/Resources/EditorData";
     resourceEditorDataDir_ = rootSourceDir_ + "Data/AtomicEditor/Resources/EditorData";
 }
 }
 
 

+ 2 - 0
Source/ToolCore/ToolEnvironment.h

@@ -34,6 +34,7 @@ public:
     const String& GetToolBinary() { return toolBinary_; }
     const String& GetToolBinary() { return toolBinary_; }
 
 
     const String& GetCoreDataDir() { return resourceCoreDataDir_; }
     const String& GetCoreDataDir() { return resourceCoreDataDir_; }
+    const String& GetPlayerDataDir() { return resourcePlayerDataDir_; }
     const String& GetEditorDataDir() { return resourceEditorDataDir_; }
     const String& GetEditorDataDir() { return resourceEditorDataDir_; }
 
 
     const String& GetDeploymentDataDir() { return toolBinary_; }
     const String& GetDeploymentDataDir() { return toolBinary_; }
@@ -66,6 +67,7 @@ private:
 
 
     // resources
     // resources
     String resourceCoreDataDir_;
     String resourceCoreDataDir_;
+    String resourcePlayerDataDir_;
     String resourceEditorDataDir_;
     String resourceEditorDataDir_;
 
 
     // deployment
     // deployment