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

@ -390,4 +390,14 @@ bool Configuration::IsVerbose() const
void Configuration::SetVerbose(bool 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 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;
};

View File

@ -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();

View File

@ -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();

View File

@ -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;
}

View File

@ -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 <sstream>
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<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)

View File

@ -9,7 +9,9 @@
#include <string>
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<Item *> *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<Component *> LayerComponents[NUM_LAYERS];
std::vector<Item *> *Items;
bool ScrollActive;
Item *SelectedItem;
Text *TextStatusComponent;
bool SelectedItemChanged;
Sound *LoadSoundChunk;
Sound *UnloadSoundChunk;

View File

@ -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);

View File

@ -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<Item *> *coll = new std::vector<Item *>();
Page * page = pb.BuildPage();
// page->SetStatusText("foobar");
Config.SetCurrentCollection("");
page->SetItems(coll);
page->Start();