From 86f80f06cb97a2b282f84c978fed3dbd28bbf507 Mon Sep 17 00:00:00 2001 From: emb <> Date: Sun, 18 Jan 2015 20:09:14 -0600 Subject: [PATCH] Adding status tag component --- RetroFE/Source/Database/Configuration.cpp | 12 +++++++++++- RetroFE/Source/Database/Configuration.h | 4 +++- RetroFE/Source/Graphics/Component/Text.cpp | 6 +++++- RetroFE/Source/Graphics/Component/Text.h | 1 + RetroFE/Source/Graphics/Font.cpp | 4 +++- RetroFE/Source/Graphics/Page.cpp | 16 +++++++++++++++- RetroFE/Source/Graphics/Page.h | 7 ++++++- RetroFE/Source/Graphics/PageBuilder.cpp | 16 +++++++++++++++- RetroFE/Source/RetroFE.cpp | 19 ++++++++----------- 9 files changed, 67 insertions(+), 18 deletions(-) diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index dce3acf..3d3a4be 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -390,4 +390,14 @@ bool Configuration::IsVerbose() const void Configuration::SetVerbose(bool verbose) { this->Verbose = verbose; -} \ No newline at end of file +} + +void Configuration::SetStatus(std::string status) +{ + Status = status; +} + +std::string Configuration::GetStatus() +{ + return Status; +} diff --git a/RetroFE/Source/Database/Configuration.h b/RetroFE/Source/Database/Configuration.h index c486259..198f8bc 100644 --- a/RetroFE/Source/Database/Configuration.h +++ b/RetroFE/Source/Database/Configuration.h @@ -16,7 +16,8 @@ public: static void SetAbsolutePath(std::string absolutePath); static std::string GetAbsolutePath(); static std::string ConvertToAbsolutePath(std::string prefix, std::string path); - + void SetStatus(std::string status); + std::string GetStatus(); // gets the global configuration bool Import(std::string keyPrefix, std::string file); void SetCurrentCollection(std::string collection); @@ -45,5 +46,6 @@ private: static std::string AbsolutePath; std::string CurrentCollection; PropertiesType Properties; + std::string Status; }; diff --git a/RetroFE/Source/Graphics/Component/Text.cpp b/RetroFE/Source/Graphics/Component/Text.cpp index 4328e42..7fc9d9a 100644 --- a/RetroFE/Source/Graphics/Component/Text.cpp +++ b/RetroFE/Source/Graphics/Component/Text.cpp @@ -35,7 +35,6 @@ Text::~Text() FreeGraphicsMemory(); } - void Text::FreeGraphicsMemory() { Component::FreeGraphicsMemory(); @@ -47,6 +46,11 @@ void Text::AllocateGraphicsMemory() Component::AllocateGraphicsMemory(); } +void Text::SetText(std::string text) +{ + TextData = text; +} + void Text::Draw() { Component::Draw(); diff --git a/RetroFE/Source/Graphics/Component/Text.h b/RetroFE/Source/Graphics/Component/Text.h index 9c63c09..8733a69 100644 --- a/RetroFE/Source/Graphics/Component/Text.h +++ b/RetroFE/Source/Graphics/Component/Text.h @@ -15,6 +15,7 @@ class Text : public Component public: //todo: should have a Font flass that references fontcache, pass that in as an argument Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY); + void SetText(std::string text); virtual ~Text(); void AllocateGraphicsMemory(); void FreeGraphicsMemory(); diff --git a/RetroFE/Source/Graphics/Font.cpp b/RetroFE/Source/Graphics/Font.cpp index 935eb5b..b3a0718 100644 --- a/RetroFE/Source/Graphics/Font.cpp +++ b/RetroFE/Source/Graphics/Font.cpp @@ -56,7 +56,9 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color) if (!font) { - Logger::Write(Logger::ZONE_ERROR, "FontCache", "TTF_OpenFont failed"); + std::stringstream ss; + ss << "Could not open font: " << TTF_GetError(); + Logger::Write(Logger::ZONE_ERROR, "FontCache", ss.str()); return false; } diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index e079a9a..42115ec 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -17,18 +17,21 @@ #include "Page.h" #include "ComponentItemBinding.h" #include "Component/Component.h" +#include "Component/Text.h" #include "../Utility/Log.h" #include "Component/ScrollingList.h" #include "../Sound/Sound.h" #include "ComponentItemBindingBuilder.h" #include -Page::Page(std::string collectionName) +Page::Page(std::string collectionName, Configuration &config) : CollectionName(collectionName) + , Config(config) , Menu(NULL) , Items(NULL) , ScrollActive(false) , SelectedItem(NULL) + , TextStatusComponent(NULL) , SelectedItemChanged(false) , LoadSoundChunk(NULL) , UnloadSoundChunk(NULL) @@ -104,6 +107,12 @@ void Page::SetMenu(ScrollingList *s) } } + +void Page::SetStatusTextComponent(Text *t) +{ + TextStatusComponent = t; +} + bool Page::AddComponent(Component *c) { bool retVal = false; @@ -324,6 +333,11 @@ void Page::Update(float dt) HasSoundedWhenActive = false; } + if(TextStatusComponent) + { + TextStatusComponent->SetText(Config.GetStatus()); + } + for(unsigned int i = 0; i < NUM_LAYERS; ++i) { for(std::vector::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it) diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index e9dc2af..e5a1fa9 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -9,7 +9,9 @@ #include class Component; +class Configuration; class ScrollingList; +class Text; class Item; class Sound; @@ -24,7 +26,7 @@ public: }; - Page(std::string collectionName); + Page(std::string collectionName, Configuration &c); virtual ~Page(); virtual void OnNewItemSelected(Item *); void SetItems(std::vector *items); @@ -55,6 +57,7 @@ public: void RemoveSelectedItem(); bool IsIdle(); bool IsHidden(); + void SetStatusTextComponent(Text *t); void Update(float dt); void Draw(); void FreeGraphicsMemory(); @@ -66,12 +69,14 @@ public: private: void Highlight(); std::string CollectionName; + Configuration &Config; ScrollingList *Menu; static const unsigned int NUM_LAYERS = 8; std::vector LayerComponents[NUM_LAYERS]; std::vector *Items; bool ScrollActive; Item *SelectedItem; + Text *TextStatusComponent; bool SelectedItemChanged; Sound *LoadSoundChunk; Sound *UnloadSoundChunk; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 22e5e3a..22b4805 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -168,7 +168,7 @@ Page *PageBuilder::BuildPage() ss << layoutWidth << "x" << layoutHeight << " (scale " << ScaleX << "x" << ScaleY << ")"; Logger::Write(Logger::ZONE_DEBUG, "Layout", "Layout resolution " + ss.str()); - page = new Page(Collection); + page = new Page(Collection, Config); // load sounds for(xml_node<> *sound = root->first_node("sound"); sound; sound = sound->next_sibling("sound")) @@ -381,6 +381,20 @@ bool PageBuilder::BuildComponents(xml_node<> *layout, Page *page) } } + for(xml_node<> *componentXml = layout->first_node("statusText"); componentXml; componentXml = componentXml->next_sibling("statusText")) + { + FC->LoadFont(Font, FontSize, FontColor); + Text *c = new Text("", FC->GetFont(Font), FontColor, ScaleX, ScaleY); + ViewInfo *v = c->GetBaseViewInfo(); + + BuildViewInfo(componentXml, v); + + LoadTweens(c, componentXml); + page->AddComponent(c); + page->SetStatusTextComponent(c); + } + + LoadReloadableImages(layout, "reloadableImage", page); LoadReloadableImages(layout, "reloadableVideo", page); LoadReloadableImages(layout, "reloadableText", page); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index bbed359..6d4d3bd 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -57,6 +57,7 @@ CollectionDatabase *RetroFE::InitializeCollectionDatabase(DB &db, Configuration { CollectionDatabase *cdb = NULL; + config.SetStatus("Initializing database"); std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db"); std::ifstream infile(dbFile.c_str()); @@ -124,9 +125,6 @@ int RetroFE::Initialize(void *context) return -1; } - - instance->FC.Initialize(); - instance->Config.GetProperty("videoEnable", videoEnable); instance->Config.GetProperty("videoLoop", videoLoop); @@ -220,6 +218,8 @@ void RetroFE::Run() { if(!SDL::Initialize(Config)) return; + FC.Initialize(); + InitializeThread = SDL_CreateThread(Initialize, "RetroFEInit", (void *)this); if(!InitializeThread) @@ -464,7 +464,6 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page) return state; } - void RetroFE::WaitToInitialize() { Logger::Write(Logger::ZONE_INFO, "RetroFE", "Loading splash screen"); @@ -474,14 +473,11 @@ void RetroFE::WaitToInitialize() while(!Initialized) { - SDL_SetRenderDrawColor(SDL::GetRenderer(), 0x0, 0x0, 0x00, 0xFF); - SDL_RenderClear(SDL::GetRenderer()); -// image->Draw(); - //todo: decouple page from a collection - page->Draw(); - SDL_RenderPresent(SDL::GetRenderer()); + SDL_SetRenderDrawColor(SDL::GetRenderer(), 0x0, 0x0, 0x00, 0xFF); + SDL_RenderClear(SDL::GetRenderer()); - SDL_Delay(2000); + page->Draw(); + SDL_RenderPresent(SDL::GetRenderer()); } int status = 0; @@ -528,6 +524,7 @@ Page *RetroFE::LoadSplashPage() PageBuilder pb("Splash", "", Config, &FC); std::vector *coll = new std::vector(); Page * page = pb.BuildPage(); +// page->SetStatusText("foobar"); Config.SetCurrentCollection(""); page->SetItems(coll); page->Start();