gui: support string resources
storing strings in a map (for fast lookup) in resource manager To define a string resource in <resources>: <string name="foo">Hello</string> To use a string, e.g.: <text>%@foo%</text> 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
This commit is contained in:
+16
-9
@@ -4,22 +4,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#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<std::string, std::string>::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());
|
||||
|
||||
Reference in New Issue
Block a user