Adding status tag component

This commit is contained in:
emb 2015-01-18 20:09:14 -06:00
parent efe651ea4e
commit 86f80f06cb
9 changed files with 67 additions and 18 deletions

View File

@ -391,3 +391,13 @@ void Configuration::SetVerbose(bool verbose)
{ {
this->Verbose = verbose; this->Verbose = verbose;
} }
void Configuration::SetStatus(std::string status)
{
Status = status;
}
std::string Configuration::GetStatus()
{
return Status;
}

View File

@ -16,7 +16,8 @@ public:
static void SetAbsolutePath(std::string absolutePath); static void SetAbsolutePath(std::string absolutePath);
static std::string GetAbsolutePath(); static std::string GetAbsolutePath();
static std::string ConvertToAbsolutePath(std::string prefix, std::string path); static std::string ConvertToAbsolutePath(std::string prefix, std::string path);
void SetStatus(std::string status);
std::string GetStatus();
// gets the global configuration // gets the global configuration
bool Import(std::string keyPrefix, std::string file); bool Import(std::string keyPrefix, std::string file);
void SetCurrentCollection(std::string collection); void SetCurrentCollection(std::string collection);
@ -45,5 +46,6 @@ private:
static std::string AbsolutePath; static std::string AbsolutePath;
std::string CurrentCollection; std::string CurrentCollection;
PropertiesType Properties; PropertiesType Properties;
std::string Status;
}; };

View File

@ -35,7 +35,6 @@ Text::~Text()
FreeGraphicsMemory(); FreeGraphicsMemory();
} }
void Text::FreeGraphicsMemory() void Text::FreeGraphicsMemory()
{ {
Component::FreeGraphicsMemory(); Component::FreeGraphicsMemory();
@ -47,6 +46,11 @@ void Text::AllocateGraphicsMemory()
Component::AllocateGraphicsMemory(); Component::AllocateGraphicsMemory();
} }
void Text::SetText(std::string text)
{
TextData = text;
}
void Text::Draw() void Text::Draw()
{ {
Component::Draw(); Component::Draw();

View File

@ -15,6 +15,7 @@ class Text : public Component
public: public:
//todo: should have a Font flass that references fontcache, pass that in as an argument //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); Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
void SetText(std::string text);
virtual ~Text(); virtual ~Text();
void AllocateGraphicsMemory(); void AllocateGraphicsMemory();
void FreeGraphicsMemory(); void FreeGraphicsMemory();

View File

@ -56,7 +56,9 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color)
if (!font) 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; return false;
} }

View File

@ -17,18 +17,21 @@
#include "Page.h" #include "Page.h"
#include "ComponentItemBinding.h" #include "ComponentItemBinding.h"
#include "Component/Component.h" #include "Component/Component.h"
#include "Component/Text.h"
#include "../Utility/Log.h" #include "../Utility/Log.h"
#include "Component/ScrollingList.h" #include "Component/ScrollingList.h"
#include "../Sound/Sound.h" #include "../Sound/Sound.h"
#include "ComponentItemBindingBuilder.h" #include "ComponentItemBindingBuilder.h"
#include <sstream> #include <sstream>
Page::Page(std::string collectionName) Page::Page(std::string collectionName, Configuration &config)
: CollectionName(collectionName) : CollectionName(collectionName)
, Config(config)
, Menu(NULL) , Menu(NULL)
, Items(NULL) , Items(NULL)
, ScrollActive(false) , ScrollActive(false)
, SelectedItem(NULL) , SelectedItem(NULL)
, TextStatusComponent(NULL)
, SelectedItemChanged(false) , SelectedItemChanged(false)
, LoadSoundChunk(NULL) , LoadSoundChunk(NULL)
, UnloadSoundChunk(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 Page::AddComponent(Component *c)
{ {
bool retVal = false; bool retVal = false;
@ -324,6 +333,11 @@ void Page::Update(float dt)
HasSoundedWhenActive = false; HasSoundedWhenActive = false;
} }
if(TextStatusComponent)
{
TextStatusComponent->SetText(Config.GetStatus());
}
for(unsigned int i = 0; i < NUM_LAYERS; ++i) for(unsigned int i = 0; i < NUM_LAYERS; ++i)
{ {
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)

View File

@ -9,7 +9,9 @@
#include <string> #include <string>
class Component; class Component;
class Configuration;
class ScrollingList; class ScrollingList;
class Text;
class Item; class Item;
class Sound; class Sound;
@ -24,7 +26,7 @@ public:
}; };
Page(std::string collectionName); Page(std::string collectionName, Configuration &c);
virtual ~Page(); virtual ~Page();
virtual void OnNewItemSelected(Item *); virtual void OnNewItemSelected(Item *);
void SetItems(std::vector<Item *> *items); void SetItems(std::vector<Item *> *items);
@ -55,6 +57,7 @@ public:
void RemoveSelectedItem(); void RemoveSelectedItem();
bool IsIdle(); bool IsIdle();
bool IsHidden(); bool IsHidden();
void SetStatusTextComponent(Text *t);
void Update(float dt); void Update(float dt);
void Draw(); void Draw();
void FreeGraphicsMemory(); void FreeGraphicsMemory();
@ -66,12 +69,14 @@ public:
private: private:
void Highlight(); void Highlight();
std::string CollectionName; std::string CollectionName;
Configuration &Config;
ScrollingList *Menu; ScrollingList *Menu;
static const unsigned int NUM_LAYERS = 8; static const unsigned int NUM_LAYERS = 8;
std::vector<Component *> LayerComponents[NUM_LAYERS]; std::vector<Component *> LayerComponents[NUM_LAYERS];
std::vector<Item *> *Items; std::vector<Item *> *Items;
bool ScrollActive; bool ScrollActive;
Item *SelectedItem; Item *SelectedItem;
Text *TextStatusComponent;
bool SelectedItemChanged; bool SelectedItemChanged;
Sound *LoadSoundChunk; Sound *LoadSoundChunk;
Sound *UnloadSoundChunk; Sound *UnloadSoundChunk;

View File

@ -168,7 +168,7 @@ Page *PageBuilder::BuildPage()
ss << layoutWidth << "x" << layoutHeight << " (scale " << ScaleX << "x" << ScaleY << ")"; ss << layoutWidth << "x" << layoutHeight << " (scale " << ScaleX << "x" << ScaleY << ")";
Logger::Write(Logger::ZONE_DEBUG, "Layout", "Layout resolution " + ss.str()); Logger::Write(Logger::ZONE_DEBUG, "Layout", "Layout resolution " + ss.str());
page = new Page(Collection); page = new Page(Collection, Config);
// load sounds // load sounds
for(xml_node<> *sound = root->first_node("sound"); sound; sound = sound->next_sibling("sound")) 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, "reloadableImage", page);
LoadReloadableImages(layout, "reloadableVideo", page); LoadReloadableImages(layout, "reloadableVideo", page);
LoadReloadableImages(layout, "reloadableText", page); LoadReloadableImages(layout, "reloadableText", page);

View File

@ -57,6 +57,7 @@ CollectionDatabase *RetroFE::InitializeCollectionDatabase(DB &db, Configuration
{ {
CollectionDatabase *cdb = NULL; CollectionDatabase *cdb = NULL;
config.SetStatus("Initializing database");
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db"); std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
std::ifstream infile(dbFile.c_str()); std::ifstream infile(dbFile.c_str());
@ -124,9 +125,6 @@ int RetroFE::Initialize(void *context)
return -1; return -1;
} }
instance->FC.Initialize();
instance->Config.GetProperty("videoEnable", videoEnable); instance->Config.GetProperty("videoEnable", videoEnable);
instance->Config.GetProperty("videoLoop", videoLoop); instance->Config.GetProperty("videoLoop", videoLoop);
@ -220,6 +218,8 @@ void RetroFE::Run()
{ {
if(!SDL::Initialize(Config)) return; if(!SDL::Initialize(Config)) return;
FC.Initialize();
InitializeThread = SDL_CreateThread(Initialize, "RetroFEInit", (void *)this); InitializeThread = SDL_CreateThread(Initialize, "RetroFEInit", (void *)this);
if(!InitializeThread) if(!InitializeThread)
@ -464,7 +464,6 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
return state; return state;
} }
void RetroFE::WaitToInitialize() void RetroFE::WaitToInitialize()
{ {
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Loading splash screen"); Logger::Write(Logger::ZONE_INFO, "RetroFE", "Loading splash screen");
@ -474,14 +473,11 @@ void RetroFE::WaitToInitialize()
while(!Initialized) while(!Initialized)
{ {
SDL_SetRenderDrawColor(SDL::GetRenderer(), 0x0, 0x0, 0x00, 0xFF); SDL_SetRenderDrawColor(SDL::GetRenderer(), 0x0, 0x0, 0x00, 0xFF);
SDL_RenderClear(SDL::GetRenderer()); SDL_RenderClear(SDL::GetRenderer());
// image->Draw();
//todo: decouple page from a collection
page->Draw();
SDL_RenderPresent(SDL::GetRenderer());
SDL_Delay(2000); page->Draw();
SDL_RenderPresent(SDL::GetRenderer());
} }
int status = 0; int status = 0;
@ -528,6 +524,7 @@ Page *RetroFE::LoadSplashPage()
PageBuilder pb("Splash", "", Config, &FC); PageBuilder pb("Splash", "", Config, &FC);
std::vector<Item *> *coll = new std::vector<Item *>(); std::vector<Item *> *coll = new std::vector<Item *>();
Page * page = pb.BuildPage(); Page * page = pb.BuildPage();
// page->SetStatusText("foobar");
Config.SetCurrentCollection(""); Config.SetCurrentCollection("");
page->SetItems(coll); page->SetItems(coll);
page->Start(); page->Start();