GUI: Read icons and metadata from gui-icons.dat
This commit is contained in:
parent
d303d9f042
commit
1661fa1ba6
5 changed files with 40 additions and 17 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "common/rect.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/translation.h"
|
||||
#include "common/unzip.h"
|
||||
#include "gui/EventRecorder.h"
|
||||
|
||||
#include "backends/keymapper/action.h"
|
||||
|
@ -85,6 +86,7 @@ GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _stateIsSaved(false),
|
|||
#endif // USE_TRANSLATION
|
||||
|
||||
initTextToSpeech();
|
||||
initIconsSet();
|
||||
|
||||
ConfMan.registerDefault("gui_theme", "scummremastered");
|
||||
Common::String themefile(ConfMan.get("gui_theme"));
|
||||
|
@ -106,6 +108,26 @@ GuiManager::~GuiManager() {
|
|||
delete _theme;
|
||||
}
|
||||
|
||||
void GuiManager::initIconsSet() {
|
||||
Common::Archive *dat;
|
||||
|
||||
// ConfMan.get("iconspath")
|
||||
|
||||
Common::String path = "gui-icons.dat";
|
||||
|
||||
if (ConfMan.hasKey("themepath"))
|
||||
path = normalizePath(ConfMan.get("themepath") + "/" + path, '/');
|
||||
|
||||
dat = Common::makeZipArchive(Common::FSNode(path));
|
||||
|
||||
if (!dat) {
|
||||
warning("GUI: Could not find '%s'", path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
_iconsSet.add(path, dat);
|
||||
}
|
||||
|
||||
void GuiManager::computeScaleFactor() {
|
||||
uint16 w = g_system->getOverlayWidth();
|
||||
uint16 h = g_system->getOverlayHeight();
|
||||
|
|
|
@ -92,6 +92,8 @@ public:
|
|||
|
||||
ThemeEval *xmlEval() { return _theme->getEvaluator(); }
|
||||
|
||||
Common::SearchSet &getIconsSet() { return _iconsSet; }
|
||||
|
||||
int16 getGUIWidth() const { return _baseWidth; }
|
||||
int16 getGUIHeight() const { return _baseHeight; }
|
||||
float getScaleFactor() const { return _scaleFactor; }
|
||||
|
@ -159,6 +161,8 @@ protected:
|
|||
int _topDialogLeftPadding;
|
||||
int _topDialogRightPadding;
|
||||
|
||||
Common::SearchSet _iconsSet;
|
||||
|
||||
// position and time of last mouse click (used to detect double clicks)
|
||||
struct MousePos {
|
||||
MousePos() : x(-1), y(-1), count(0) { time = 0; }
|
||||
|
@ -189,6 +193,8 @@ protected:
|
|||
void initKeymap();
|
||||
void enableKeymap(bool enabled);
|
||||
|
||||
void initIconsSet();
|
||||
|
||||
void saveState();
|
||||
void restoreState();
|
||||
|
||||
|
|
|
@ -162,9 +162,10 @@ LauncherDialog::LauncherDialog(const Common::String &dialogName)
|
|||
#ifndef DISABLE_LAUNCHERDISPLAY_GRID
|
||||
addLayoutChooserButtons();
|
||||
#endif // !DISABLE_LAUNCHERDISPLAY_GRID
|
||||
Common::FSDirectory *mdDir = new Common::FSDirectory(Common::String("./metadata/"));
|
||||
|
||||
Common::ArchiveMemberList mdFiles;
|
||||
mdDir->listMatchingMembers(mdFiles, "*.xml");
|
||||
|
||||
g_gui.getIconsSet().listMatchingMembers(mdFiles, "*.xml");
|
||||
for (Common::ArchiveMemberList::iterator md = mdFiles.begin(); md != mdFiles.end(); ++md) {
|
||||
if (_metadataParser.loadStream((*md)->createReadStream()) == false) {
|
||||
warning("Failed to load XML file '%s'", (*md)->getDisplayName().encode().c_str());
|
||||
|
|
|
@ -289,14 +289,12 @@ void GridItemTray::handleMouseMoved(int x, int y, int button) {
|
|||
// TODO: Add BMP support, and add scaling of non-vector images.
|
||||
Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name, int renderWidth = 0, int renderHeight = 0) {
|
||||
Graphics::ManagedSurface *surf = nullptr;
|
||||
const Common::String path = Common::String::format("%s/%s", ConfMan.get("iconspath").c_str(), name.c_str());
|
||||
if (name.hasSuffix(".png")) {
|
||||
#ifdef USE_PNG
|
||||
const Graphics::Surface *srcSurface = nullptr;
|
||||
Image::PNGDecoder decoder;
|
||||
Common::FSNode fileNode(path);
|
||||
if (fileNode.exists()) {
|
||||
Common::SeekableReadStream *stream = fileNode.createReadStream();
|
||||
if (g_gui.getIconsSet().hasFile(name)) {
|
||||
Common::SeekableReadStream *stream = g_gui.getIconsSet().createReadStreamForMember(name);
|
||||
if (!decoder.loadStream(*stream)) {
|
||||
warning("Error decoding PNG");
|
||||
return surf;
|
||||
|
@ -310,22 +308,21 @@ Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name, int re
|
|||
surf = new Graphics::ManagedSurface(srcSurface->convertTo(g_system->getOverlayFormat()));
|
||||
}
|
||||
} else {
|
||||
debug(5, "GridWidget: Cannot read file '%s'", path.c_str());
|
||||
debug(5, "GridWidget: Cannot read file '%s'", name.c_str());
|
||||
}
|
||||
#else
|
||||
error("No PNG support compiled");
|
||||
#endif
|
||||
} else if (name.hasSuffix(".svg")) {
|
||||
Common::FSNode fileNode(path);
|
||||
if (fileNode.exists()) {
|
||||
Common::SeekableReadStream *stream = fileNode.createReadStream();
|
||||
if (g_gui.getIconsSet().hasFile(name)) {
|
||||
Common::SeekableReadStream *stream = g_gui.getIconsSet().createReadStreamForMember(name);
|
||||
Graphics::SVGBitmap *image = nullptr;
|
||||
image = new Graphics::SVGBitmap(stream);
|
||||
surf = new Graphics::ManagedSurface(renderWidth, renderHeight, *image->getPixelFormat());
|
||||
image->render(*surf, renderWidth, renderHeight);
|
||||
delete image;
|
||||
} else {
|
||||
debug(5, "GridWidget: Cannot read file '%s'", path.c_str());
|
||||
debug(5, "GridWidget: Cannot read file '%s'", name.c_str());
|
||||
}
|
||||
}
|
||||
return surf;
|
||||
|
@ -335,8 +332,6 @@ Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name, int re
|
|||
|
||||
GridWidget::GridWidget(GuiObject *boss, const Common::String &name)
|
||||
: ContainerWidget(boss, name), CommandSender(boss) {
|
||||
_iconDir = ConfMan.get("iconspath");
|
||||
|
||||
_thumbnailHeight = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Height");
|
||||
_thumbnailWidth = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Width");
|
||||
_flagIconHeight = g_gui.xmlEval()->getVar("Globals.Grid.FlagIcon.Height");
|
||||
|
@ -578,7 +573,7 @@ void GridWidget::reloadThumbnails() {
|
|||
void GridWidget::loadFlagIcons() {
|
||||
const Common::LanguageDescription *l = Common::g_languages;
|
||||
for (; l->code; ++l) {
|
||||
Common::String path = Common::String::format("flags/%s.svg", l->code);
|
||||
Common::String path = Common::String::format("icons/flags/%s.svg", l->code);
|
||||
Graphics::ManagedSurface *gfx = loadSurfaceFromFile(path, _flagIconWidth, _flagIconHeight);
|
||||
if (gfx) {
|
||||
_languageIcons[l->id] = gfx;
|
||||
|
@ -591,7 +586,7 @@ void GridWidget::loadFlagIcons() {
|
|||
void GridWidget::loadPlatformIcons() {
|
||||
const Common::PlatformDescription *l = Common::g_platforms;
|
||||
for (; l->code; ++l) {
|
||||
Common::String path = Common::String::format("platforms/%s.png", l->code);
|
||||
Common::String path = Common::String::format("icons/platforms/%s.png", l->code);
|
||||
Graphics::ManagedSurface *gfx = loadSurfaceFromFile(path);
|
||||
if (gfx) {
|
||||
const Graphics::ManagedSurface *scGfx = scaleGfx(gfx, _platformIconWidth, _platformIconHeight);
|
||||
|
|
|
@ -67,7 +67,7 @@ struct GridItemInfo {
|
|||
GridItemInfo(int id, const Common::String &eid, const Common::String &gid
|
||||
,const Common::String &t, Common::Language l, Common::Platform p)
|
||||
: entryID(id), gameid(gid), engineid(eid), title(t), language(l), platform(p), isHeader(false) {
|
||||
thumbPath = Common::String::format("%s-%s.png", engineid.c_str(), gameid.c_str());
|
||||
thumbPath = Common::String::format("icons/%s-%s.png", engineid.c_str(), gameid.c_str());
|
||||
}
|
||||
|
||||
GridItemInfo(const Common::String &groupHeader, int groupID) : title(groupHeader), isHeader(true), entryID(groupID) {
|
||||
|
@ -141,7 +141,6 @@ protected:
|
|||
int _firstVisibleItem;
|
||||
int _lastVisibleItem;
|
||||
GridItemTray *_tray;
|
||||
Common::String _iconDir;
|
||||
bool _isGridInvalid;
|
||||
|
||||
int _scrollWindowPaddingX;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue