From b2e8f672f310276e7009895c0ac4e58fcfeb35ac Mon Sep 17 00:00:00 2001 From: that Date: Thu, 5 Mar 2015 20:25:39 +0100 Subject: gui: support string resources storing strings in a map (for fast lookup) in resource manager To define a string resource in : Hello To use a string, e.g.: %@foo% Not yet done: language-specific resources (should be solved not only for strings, but for all kinds of resources - e.g. for localized images) Change-Id: I3ba5cf5298c09e0d28a83973e9662f179271b33f --- gui/resources.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'gui/resources.cpp') diff --git a/gui/resources.cpp b/gui/resources.cpp index 563dcc45c..dcd4ca8b0 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -4,22 +4,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include #include #include #include +#include "../minzip/Zip.h" extern "C" { #include "../twcommon.h" #include "../minuitwrp/minui.h" @@ -282,6 +274,14 @@ AnimationResource* ResourceManager::FindAnimation(const std::string& name) const return NULL; } +std::string ResourceManager::FindString(const std::string& name) const +{ + std::map::const_iterator it = mStrings.find(name); + if (it != mStrings.end()) + return it->second; + return "[" + name + ("]"); +} + ResourceManager::ResourceManager() { } @@ -339,6 +339,13 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) delete res; } } + else if (type == "string") + { + if (xml_attribute<>* attr = child->first_attribute("name")) + mStrings[attr->value()] = child->value(); + else + error = true; + } else { LOGERR("Resource type (%s) not supported.\n", type.c_str()); -- cgit v1.2.3