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 "ImageBuilder.h"
#include "VideoBuilder.h"
#include "ReloadableText.h"
#include "../ViewInfo.h"
#include "../../Video/VideoFactory.h"
#include "../../Database/Configuration.h"
@ -27,13 +28,16 @@
#include <vector>
#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)
, LoadedComponent(NULL)
, ReloadRequested(false)
, FirstLoad(true)
, Type(type)
, IsVideo(isVideo)
, FontInst(font)
, FontColor(fontColor)
, TextFallback(false)
, ScaleX(scaleX)
, ScaleY(scaleY)
{
@ -48,6 +52,11 @@ ReloadableMedia::~ReloadableMedia()
}
}
void ReloadableMedia::EnableTextFallback(bool value)
{
TextFallback = value;
}
void ReloadableMedia::Update(float dt)
{
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)
{
std::string imagePath;
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, imagePath);
ImageBuilder imageBuild;
std::string imageBasename = selectedItem->GetFullTitle();
if(Utils::ToLower(Type) == "manufacturer")
{
imageBasename = selectedItem->GetManufacturer();
}
LoadedComponent = imageBuild.CreateImage(imagePath, imageBasename, ScaleX, ScaleY);
@ -184,6 +212,13 @@ void ReloadableMedia::ReloadTexture()
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
#include "Component.h"
#include "ReloadableText.h"
#include "../../Video/IVideo.h"
#include "../../Collection/Item.h"
#include <SDL2/SDL.h>
@ -26,7 +27,7 @@ class Image;
class ReloadableMedia : public Component
{
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();
void Update(float dt);
void Draw();
@ -34,6 +35,7 @@ public:
void AllocateGraphicsMemory();
void LaunchEnter();
void LaunchExit();
void EnableTextFallback(bool value);
private:
void ReloadTexture();
@ -42,8 +44,10 @@ private:
bool ReloadRequested;
bool FirstLoad;
IVideo *VideoInst;
bool IsVideo;
Font *FontInst;
SDL_Color FontColor;
bool TextFallback;
std::string Type;
float ScaleX;
float ScaleY;

View File

@ -436,7 +436,18 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName,
}
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)