Support to display a reloadable image for the currently selected collection.

This commit is contained in:
emb 2015-02-27 22:23:26 -06:00
parent 86e37ab230
commit c7dccd7109
3 changed files with 47 additions and 10 deletions

View File

@ -28,8 +28,9 @@
#include <vector>
#include <iostream>
ReloadableMedia::ReloadableMedia(Configuration &config, std::string type, bool isVideo, Font *font, float scaleX, float scaleY)
ReloadableMedia::ReloadableMedia(Configuration &config, bool systemMode, std::string type, bool isVideo, Font *font, float scaleX, float scaleY)
: Config(config)
, SystemMode(systemMode)
, LoadedComponent(NULL)
, ReloadRequested(false)
, FirstLoad(true)
@ -61,7 +62,10 @@ void ReloadableMedia::Update(float dt)
{
if(NewItemSelected)
{
ReloadRequested = true;
if(!SystemMode || (SystemMode && CurrentCollection != Config.GetCurrentCollection()))
{
ReloadRequested = true;
}
}
// wait for the right moment to reload the image
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
@ -140,6 +144,8 @@ void ReloadableMedia::ReloadTexture()
Item *selectedItem = GetSelectedItem();
CurrentCollection = Config.GetCurrentCollection();
if (selectedItem != NULL)
{
if(IsVideo)
@ -157,11 +163,19 @@ void ReloadableMedia::ReloadTexture()
{
VideoBuilder videoBuild;
std::string videoPath;
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), "video", false, videoPath);
LoadedComponent = videoBuild.CreateVideo(videoPath, names[n], ScaleX, ScaleY);
if(SystemMode)
{
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), "video", true, videoPath);
LoadedComponent = videoBuild.CreateVideo(videoPath, "video", ScaleX, ScaleY);
}
else
{
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), "video", false, videoPath);
LoadedComponent = videoBuild.CreateVideo(videoPath, names[n], ScaleX, ScaleY);
}
if(!LoadedComponent)
if(!LoadedComponent && !SystemMode)
{
Config.GetMediaPropertyAbsolutePath(names[n], Type, true, videoPath);
LoadedComponent = videoBuild.CreateVideo(videoPath, "video", ScaleX, ScaleY);
@ -205,13 +219,21 @@ void ReloadableMedia::ReloadTexture()
if(!LoadedComponent)
{
std::string imagePath;
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, false, imagePath);
ImageBuilder imageBuild;
LoadedComponent = imageBuild.CreateImage(imagePath, imageBasename, ScaleX, ScaleY);
if(SystemMode)
{
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, true, imagePath);
LoadedComponent = imageBuild.CreateImage(imagePath, Type, ScaleX, ScaleY);
}
else
{
Config.GetMediaPropertyAbsolutePath(GetCollectionName(), Type, false, imagePath);
LoadedComponent = imageBuild.CreateImage(imagePath, imageBasename, ScaleX, ScaleY);
}
if(!LoadedComponent)
if(!LoadedComponent && !SystemMode)
{
Config.GetMediaPropertyAbsolutePath(imageBasename, Type, true, imagePath);
LoadedComponent = imageBuild.CreateImage(imagePath, Type, ScaleX, ScaleY);

View File

@ -27,7 +27,7 @@ class Image;
class ReloadableMedia : public Component
{
public:
ReloadableMedia(Configuration &config, std::string type, bool isVideo, Font *font, float scaleX, float scaleY);
ReloadableMedia(Configuration &config, bool systemMode, std::string type, bool isVideo, Font *font, float scaleX, float scaleY);
virtual ~ReloadableMedia();
void Update(float dt);
void Draw();
@ -40,6 +40,7 @@ public:
private:
void ReloadTexture();
Configuration &Config;
bool SystemMode;
Component *LoadedComponent;
bool ReloadRequested;
bool FirstLoad;
@ -50,4 +51,5 @@ private:
std::string Type;
float ScaleX;
float ScaleY;
std::string CurrentCollection;
};

View File

@ -400,17 +400,21 @@ bool PageBuilder::BuildComponents(xml_node<> *layout, Page *page)
void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName, Page *page)
{
for(xml_node<> *componentXml = layout->first_node(tagName.c_str()); componentXml; componentXml = componentXml->next_sibling(tagName.c_str()))
{
std::string reloadableImagePath;
std::string reloadableVideoPath;
xml_attribute<> *type = componentXml->first_attribute("type");
xml_attribute<> *mode = componentXml->first_attribute("mode");
bool systemMode = false;
if(tagName == "reloadableVideo")
{
type = componentXml->first_attribute("imageType");
}
if(!type && tagName == "reloadableVideo")
{
Logger::Write(Logger::ZONE_WARNING, "Layout", "<reloadableImage> component in layout does not specify an imageType for when the video does not exist");
@ -421,6 +425,15 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName,
}
if(mode)
{
std::string sysMode = mode->value();
if(sysMode == "system")
{
systemMode = true;
}
}
Component *c = NULL;
@ -435,7 +448,7 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName,
else
{
Font *font = AddFont(componentXml, NULL);
c = new ReloadableMedia(Config, type->value(), (tagName == "reloadableVideo"), font, ScaleX, ScaleY);
c = new ReloadableMedia(Config, systemMode, type->value(), (tagName == "reloadableVideo"), font, ScaleX, ScaleY);
xml_attribute<> *textFallback = componentXml->first_attribute("textFallback");
if(textFallback && Utils::ToLower(textFallback->value()) == "true")