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