Text now is a fallback option if reloadable media cannot load image.

This commit is contained in:
emb 2015-02-10 13:00:20 -06:00
parent a4c29eeb7b
commit 9f7290bb12
3 changed files with 60 additions and 10 deletions

View File

@ -17,6 +17,7 @@
#include "ReloadableMedia.h" #include "ReloadableMedia.h"
#include "ImageBuilder.h" #include "ImageBuilder.h"
#include "VideoBuilder.h" #include "VideoBuilder.h"
#include "ReloadableText.h"
#include "../ViewInfo.h" #include "../ViewInfo.h"
#include "../../Video/VideoFactory.h" #include "../../Video/VideoFactory.h"
#include "../../Database/Configuration.h" #include "../../Database/Configuration.h"
@ -27,13 +28,16 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
ReloadableMedia::ReloadableMedia(Configuration &config, std::string type, bool isVideo, float scaleX, float scaleY) ReloadableMedia::ReloadableMedia(Configuration &config, std::string type, bool isVideo, Font *font, SDL_Color fontColor, float scaleX, float scaleY)
: Config(config) : Config(config)
, LoadedComponent(NULL) , LoadedComponent(NULL)
, ReloadRequested(false) , ReloadRequested(false)
, FirstLoad(true) , FirstLoad(true)
, Type(type) , Type(type)
, IsVideo(isVideo) , IsVideo(isVideo)
, FontInst(font)
, FontColor(fontColor)
, TextFallback(false)
, ScaleX(scaleX) , ScaleX(scaleX)
, ScaleY(scaleY) , ScaleY(scaleY)
{ {
@ -48,6 +52,11 @@ ReloadableMedia::~ReloadableMedia()
} }
} }
void ReloadableMedia::EnableTextFallback(bool value)
{
TextFallback = value;
}
void ReloadableMedia::Update(float dt) void ReloadableMedia::Update(float dt)
{ {
if(NewItemSelected) if(NewItemSelected)
@ -162,18 +171,37 @@ void ReloadableMedia::ReloadTexture()
} }
} }
std::string imageBasename = selectedItem->GetFullTitle();
std::string typeLC = Utils::ToLower(Type);
if(typeLC == "numberButtons")
{
imageBasename = selectedItem->GetNumberButtons();
}
else if(typeLC == "numberPlayers")
{
imageBasename = selectedItem->GetNumberPlayers();
}
else if(typeLC == "year")
{
imageBasename = selectedItem->GetYear();
}
else if(typeLC == "title")
{
imageBasename = selectedItem->GetTitle();
}
else if(typeLC == "manufacturer")
{
imageBasename = selectedItem->GetManufacturer();
}
if(!LoadedComponent) if(!LoadedComponent)
{ {
std::string imagePath; std::string imagePath;
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, imagePath); Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, imagePath);
ImageBuilder imageBuild; ImageBuilder imageBuild;
std::string imageBasename = selectedItem->GetFullTitle();
if(Utils::ToLower(Type) == "manufacturer")
{
imageBasename = selectedItem->GetManufacturer();
}
LoadedComponent = imageBuild.CreateImage(imagePath, imageBasename, ScaleX, ScaleY); LoadedComponent = imageBuild.CreateImage(imagePath, imageBasename, ScaleX, ScaleY);
@ -184,6 +212,13 @@ void ReloadableMedia::ReloadTexture()
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight()); GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
} }
} }
if(!LoadedComponent && TextFallback)
{
LoadedComponent = new Text(imageBasename, FontInst, FontColor, ScaleX, ScaleY);
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
}
} }
} }

View File

@ -15,6 +15,7 @@
*/ */
#pragma once #pragma once
#include "Component.h" #include "Component.h"
#include "ReloadableText.h"
#include "../../Video/IVideo.h" #include "../../Video/IVideo.h"
#include "../../Collection/Item.h" #include "../../Collection/Item.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@ -26,7 +27,7 @@ class Image;
class ReloadableMedia : public Component class ReloadableMedia : public Component
{ {
public: public:
ReloadableMedia(Configuration &config, std::string type, bool isVideo, float scaleX, float scaleY); ReloadableMedia(Configuration &config, std::string type, bool isVideo, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
virtual ~ReloadableMedia(); virtual ~ReloadableMedia();
void Update(float dt); void Update(float dt);
void Draw(); void Draw();
@ -34,6 +35,7 @@ public:
void AllocateGraphicsMemory(); void AllocateGraphicsMemory();
void LaunchEnter(); void LaunchEnter();
void LaunchExit(); void LaunchExit();
void EnableTextFallback(bool value);
private: private:
void ReloadTexture(); void ReloadTexture();
@ -42,8 +44,10 @@ private:
bool ReloadRequested; bool ReloadRequested;
bool FirstLoad; bool FirstLoad;
IVideo *VideoInst; IVideo *VideoInst;
bool IsVideo; bool IsVideo;
Font *FontInst;
SDL_Color FontColor;
bool TextFallback;
std::string Type; std::string Type;
float ScaleX; float ScaleX;
float ScaleY; float ScaleY;

View File

@ -436,7 +436,18 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName,
} }
else else
{ {
c = new ReloadableMedia(Config, type->value(), (tagName == "reloadableVideo"), ScaleX, ScaleY); FC->LoadFont(Font, FontSize, FontColor);
c = new ReloadableMedia(Config, type->value(), (tagName == "reloadableVideo"), FC->GetFont(Font), FontColor, ScaleX, ScaleY);
xml_attribute<> *textFallback = componentXml->first_attribute("textFallback");
if(textFallback && Utils::ToLower(textFallback->value()) == "true")
{
static_cast<ReloadableMedia *>(c)->EnableTextFallback(true);
}
else
{
static_cast<ReloadableMedia *>(c)->EnableTextFallback(false);
}
} }
if(c) if(c)