GUI: Switch to GridItemInfo struct from LauncherEntry
This commit is contained in:
parent
f09a05cbb4
commit
4d07dd48e3
3 changed files with 100 additions and 85 deletions
|
@ -302,6 +302,22 @@ void LauncherDialog::close() {
|
|||
Dialog::close();
|
||||
}
|
||||
|
||||
struct LauncherEntry {
|
||||
Common::String key;
|
||||
Common::String description;
|
||||
const Common::ConfigManager::Domain *domain;
|
||||
|
||||
LauncherEntry(Common::String k, Common::String d, const Common::ConfigManager::Domain *v) {
|
||||
key = k; description = d, domain = v;
|
||||
}
|
||||
};
|
||||
|
||||
struct LauncherEntryComparator {
|
||||
bool operator()(const LauncherEntry &x, const LauncherEntry &y) const {
|
||||
return scumm_compareDictionary(x.description.c_str(), y.description.c_str()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
void LauncherDialog::updateListing() {
|
||||
U32StringArray l;
|
||||
ListWidget::ColorList colors;
|
||||
|
@ -347,7 +363,21 @@ void LauncherDialog::updateListing() {
|
|||
// Now sort the list in dictionary order
|
||||
Common::sort(domainList.begin(), domainList.end(), LauncherEntryComparator());
|
||||
|
||||
_grid->setEntryList(&domainList);
|
||||
Common::Array<GridItemInfo> gridList;
|
||||
|
||||
for (Common::Array<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
Common::String gameid = iter->domain->getVal("gameid");
|
||||
Common::String engineid = iter->domain->getVal("engineid");
|
||||
Common::String title = iter->description;
|
||||
Common::String language = "XX";
|
||||
Common::String platform = "UNK";
|
||||
iter->domain->tryGetVal("language",language);
|
||||
iter->domain->tryGetVal("platform", platform);
|
||||
language.toUppercase();
|
||||
gridList.push_back(GridItemInfo(engineid, gameid, title, language, platform));
|
||||
}
|
||||
|
||||
_grid->setEntryList(&gridList);
|
||||
|
||||
// And fill out our structures
|
||||
for (Common::Array<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
|
|
|
@ -1029,18 +1029,24 @@ GridItemWidget::GridItemWidget(GridWidget *boss, GraphicsWidget *th, GraphicsWid
|
|||
}
|
||||
|
||||
void GridItemWidget::attachEntry(Common::String key, Common::String description, Common::ConfigManager::Domain *domain) {
|
||||
_attachedEntries.push_back(LauncherEntry(key, description, domain));
|
||||
Common::String gameid = domain->getVal("gameid");
|
||||
Common::String engineid = domain->getVal("engineid");
|
||||
Common::String language = "XX";
|
||||
Common::String platform = "UNK";
|
||||
domain->tryGetVal("language",language);
|
||||
domain->tryGetVal("platform", platform);
|
||||
_attachedEntries.push_back(GridItemInfo(gameid, engineid, description, language, platform));
|
||||
}
|
||||
|
||||
void GridItemWidget::attachEntry(LauncherEntry &entry) {
|
||||
void GridItemWidget::attachEntry(GridItemInfo &entry) {
|
||||
_attachedEntries.push_back(entry);
|
||||
}
|
||||
|
||||
void GridItemWidget::attachEntries(Common::Array<LauncherEntry> entries) {
|
||||
void GridItemWidget::attachEntries(Common::Array<GridItemInfo> entries) {
|
||||
_attachedEntries.push_back(entries);
|
||||
}
|
||||
|
||||
void GridItemWidget::setActiveEntry(LauncherEntry &entry) {
|
||||
void GridItemWidget::setActiveEntry(GridItemInfo &entry) {
|
||||
_activeEntry = &entry;
|
||||
}
|
||||
|
||||
|
@ -1051,17 +1057,7 @@ void GridItemWidget::update() {
|
|||
|
||||
if (isVisible()) {
|
||||
// warning("%s, %s - Entry", _activeEntry->key.c_str(), _activeEntry->description.c_str());
|
||||
Common::String gameid = _activeEntry->domain->getVal("gameid");
|
||||
Common::String engineid = _activeEntry->domain->getVal("engineid");
|
||||
Common::String language = "XX";
|
||||
Common::String platform = "UNK";
|
||||
_activeEntry->domain->tryGetVal("language",language);
|
||||
_activeEntry->domain->tryGetVal("platform", platform);
|
||||
language.toUppercase();
|
||||
// warning("Fields populated");
|
||||
// warning("%s %s %s %s", gameid.c_str(), engineid.c_str(), language.c_str(), platform.c_str());
|
||||
Common::String thumbPath = Common::String::format("%s-%s.png",engineid.c_str(),gameid.c_str());
|
||||
Graphics::ManagedSurface *gfx = _grid->filenameToSurface(thumbPath);
|
||||
Graphics::ManagedSurface *gfx = _grid->filenameToSurface(_activeEntry->thumbPath);
|
||||
|
||||
if (gfx) {
|
||||
const Graphics::ManagedSurface * scGfx = scaleGfx(gfx, _thumb->getWidth(), 512);
|
||||
|
@ -1070,17 +1066,17 @@ void GridItemWidget::update() {
|
|||
else
|
||||
_thumb->setGfx(gfx);
|
||||
|
||||
_lang->setLabel(language);
|
||||
_title->setLabel(_activeEntry->description);
|
||||
_lang->setLabel(_activeEntry->language);
|
||||
_title->setLabel(_activeEntry->title);
|
||||
|
||||
if (platform == "pc")
|
||||
gfx = _grid->platformToSurface(GridWidget::Platform::kPlatformDOS);
|
||||
else if (platform == "amiga")
|
||||
gfx = _grid->platformToSurface(GridWidget::Platform::kPlatformAmiga);
|
||||
else if (platform == "apple2")
|
||||
gfx = _grid->platformToSurface(GridWidget::Platform::kPlatformApple2);
|
||||
if (_activeEntry->platform == "pc")
|
||||
gfx = _grid->platformToSurface(kPlatformDOS);
|
||||
else if (_activeEntry->platform == "amiga")
|
||||
gfx = _grid->platformToSurface(kPlatformAmiga);
|
||||
else if (_activeEntry->platform == "apple2")
|
||||
gfx = _grid->platformToSurface(kPlatformApple2);
|
||||
else
|
||||
gfx = _grid->platformToSurface(GridWidget::Platform::kPlatformUnknown);
|
||||
gfx = _grid->platformToSurface(kPlatformUnknown);
|
||||
|
||||
if (gfx) {
|
||||
const Graphics::ManagedSurface * scGfx = scaleGfx(gfx, _plat->getWidth(), _plat->getHeight());
|
||||
|
@ -1097,19 +1093,6 @@ void GridItemWidget::drawWidget() {
|
|||
g_gui.theme()->drawWidgetBackground(Common::Rect(_x,_y,_x+kThumbnailWidth,_y+kThumbnailHeight), ThemeEngine::WidgetBackground::kThumbnailBackground);
|
||||
}
|
||||
|
||||
// void GridItemWidget::setEnabled(bool e) {
|
||||
// // Widget::setEnabled(e);
|
||||
// // _thumb->setEnabled(e);
|
||||
// // _plat->setEnabled(e);
|
||||
// // _title->setEnabled(e);
|
||||
// // _lang->setEnabled(e);
|
||||
// setVisible(e);
|
||||
// // _thumb->setVisible(e);
|
||||
// // _plat->setVisible(e);
|
||||
// // _title->setVisible(e);
|
||||
// // _lang->setVisible(e);
|
||||
// }
|
||||
|
||||
#pragma mark -
|
||||
|
||||
Graphics::ManagedSurface *loadSurfaceFromFile(Common::String &name) {
|
||||
|
@ -1163,7 +1146,7 @@ GridWidget::GridWidget(GuiObject *boss, const Common::String &name) :
|
|||
_scrollPos = 0;
|
||||
}
|
||||
|
||||
void GridWidget::setEntryList(Common::Array<LauncherEntry> *list) {
|
||||
void GridWidget::setEntryList(Common::Array<GridItemInfo> *list) {
|
||||
for (auto entryIter = list->begin(); entryIter != list->end(); ++entryIter) {
|
||||
_allEntries.push_back(*entryIter);
|
||||
}
|
||||
|
@ -1196,23 +1179,25 @@ void GridWidget::loadPlatformIcons() {
|
|||
}
|
||||
|
||||
bool GridWidget::calcVisibleEntries() {
|
||||
warning("calcingVisible entries");
|
||||
// warning("calcingVisible entries");
|
||||
bool needsReload = false;
|
||||
|
||||
int nFirstVisibleItem = 0;
|
||||
int nItemsOnScreen = 0;
|
||||
|
||||
nFirstVisibleItem = _itemsPerRow * (-_scrollPos / _gridItemHeight);
|
||||
nItemsOnScreen = ((_scrollWindowHeight / _gridItemHeight) + 1) * (_itemsPerRow);
|
||||
nFirstVisibleItem = _itemsPerRow * (-_scrollPos / (_gridItemHeight + kGridItemVPadding));
|
||||
nItemsOnScreen = (3 + (_scrollWindowHeight / (_gridItemHeight + kGridItemVPadding))) * (_itemsPerRow);
|
||||
|
||||
if ((nFirstVisibleItem != _firstVisibleItem) || (nItemsOnScreen != _itemsOnScreen)) {
|
||||
needsReload = true;
|
||||
_firstVisibleItem = nFirstVisibleItem;
|
||||
_itemsOnScreen = nItemsOnScreen;
|
||||
|
||||
int toRender = MIN(_firstVisibleItem + _itemsOnScreen, (int)_allEntries.size()-1);
|
||||
// warning("%d %d %d", _firstVisibleItem, _firstVisibleItem + _itemsOnScreen, (int)_gridItems.size());
|
||||
_visibleEntries.clear();
|
||||
for (int ind = _firstVisibleItem; ind < _firstVisibleItem + _itemsOnScreen; ++ind) {
|
||||
LauncherEntry *iter = _allEntries.begin() + ind;
|
||||
for (int ind = _firstVisibleItem; ind < toRender; ++ind) {
|
||||
GridItemInfo *iter = _allEntries.begin() + ind;
|
||||
_visibleEntries.push_back(*iter);
|
||||
}
|
||||
}
|
||||
|
@ -1223,13 +1208,13 @@ bool GridWidget::calcVisibleEntries() {
|
|||
|
||||
void GridWidget::reloadThumbnails() {
|
||||
Graphics::ManagedSurface *surf = nullptr;
|
||||
_loadedSurfaces.clear(true);
|
||||
for (Common::Array<LauncherEntry>::iterator iter = _visibleEntries.begin(); iter != _visibleEntries.end(); ++iter) {
|
||||
Common::String gameid = iter->domain->getVal("gameid");
|
||||
Common::String engineid = iter->domain->getVal("engineid");
|
||||
Common::String path = Common::String("./icons/")+Common::String::format("%s-%s.png", engineid.c_str(), gameid.c_str());
|
||||
Common::String gameid;
|
||||
Common::String engineid;
|
||||
Common::String path;
|
||||
for (Common::Array<GridItemInfo>::iterator iter = _visibleEntries.begin(); iter != _visibleEntries.end(); ++iter) {
|
||||
path = Common::String("./icons/")+iter->thumbPath;
|
||||
if (_loadedSurfaces.contains(path)) {
|
||||
warning("Thumbnail already loaded, skipping...");
|
||||
// warning("Thumbnail already loaded, skipping...");
|
||||
}
|
||||
else {
|
||||
surf = loadSurfaceFromFile(path);
|
||||
|
@ -1241,10 +1226,7 @@ void GridWidget::reloadThumbnails() {
|
|||
Graphics::ManagedSurface *GridWidget::filenameToSurface(Common::String &name) {
|
||||
Common::String path = Common::String("./icons/")+name;
|
||||
for (auto l = _visibleEntries.begin(); l!=_visibleEntries.end(); ++l) {
|
||||
Common::String gameid = l->domain->getVal("gameid");
|
||||
Common::String engineid = l->domain->getVal("engineid");
|
||||
Common::String lPath = Common::String("./icons/")+Common::String::format("%s-%s.png", engineid.c_str(), gameid.c_str());
|
||||
if (lPath == path) {
|
||||
if (l->thumbPath == name) {
|
||||
return _loadedSurfaces[path];
|
||||
}
|
||||
}
|
||||
|
@ -1254,7 +1236,7 @@ Graphics::ManagedSurface *GridWidget::filenameToSurface(Common::String &name) {
|
|||
|
||||
Graphics::ManagedSurface *GridWidget::platformToSurface(Platform platformCode) {
|
||||
if ((platformCode == kPlatformUnknown) || (platformCode < 0 || platformCode >= _platformIcons.size())) {
|
||||
warning("Unknown Platform");
|
||||
// warning("Unknown Platform");
|
||||
return nullptr;
|
||||
}
|
||||
return _platformIcons[platformCode];
|
||||
|
@ -1317,10 +1299,11 @@ void GridWidget::reflowLayout() {
|
|||
reloadThumbnails();
|
||||
}
|
||||
|
||||
Common::HashMap<Common::String, GridItemWidget *> entryById;
|
||||
// Common::HashMap<Common::String, GridItemWidget *> entryById;
|
||||
|
||||
for (Common::Array<LauncherEntry>::iterator i = _allEntries.begin(); i != _allEntries.end(); ++i) {
|
||||
GridItemWidget *newEntry = entryById[i->domain->getVal("gameid")];
|
||||
for (Common::Array<GridItemInfo>::iterator i = _allEntries.begin(); i != _allEntries.end(); ++i) {
|
||||
// GridItemWidget *newEntry = entryById[i->gameid];
|
||||
GridItemWidget *newEntry = nullptr;
|
||||
if (!newEntry) {
|
||||
newEntry = new GridItemWidget(this,
|
||||
50 + col * (kThumbnailWidth + 50),
|
||||
|
@ -1345,7 +1328,7 @@ void GridWidget::reflowLayout() {
|
|||
}
|
||||
newEntry->attachEntry(*i);
|
||||
newEntry->update();
|
||||
entryById[i->domain->getVal("gameid")] = newEntry;
|
||||
// entryById[i->domain->getVal("gameid")] = newEntry;
|
||||
}
|
||||
markAsDirty();
|
||||
}
|
||||
|
|
54
gui/widget.h
54
gui/widget.h
|
@ -461,21 +461,28 @@ protected:
|
|||
ThemeEngine::WidgetBackground _backgroundType;
|
||||
};
|
||||
|
||||
struct LauncherEntry {
|
||||
Common::String key;
|
||||
Common::String description;
|
||||
const Common::ConfigManager::Domain *domain;
|
||||
enum Platform {
|
||||
kPlatformDOS,
|
||||
kPlatformAmiga,
|
||||
kPlatformApple2,
|
||||
kPlatformUnknown = -1
|
||||
};
|
||||
|
||||
LauncherEntry(Common::String k, Common::String d, const Common::ConfigManager::Domain *v) {
|
||||
key = k; description = d, domain = v;
|
||||
struct GridItemInfo
|
||||
{
|
||||
Common::String engineid;
|
||||
Common::String gameid;
|
||||
Common::String language;
|
||||
Common::String title;
|
||||
Common::String platform;
|
||||
Common::String thumbPath;
|
||||
|
||||
GridItemInfo(Common::String &eid, Common::String &gid, Common::String &t, Common::String &l, Common::String &p) :
|
||||
gameid(gid), engineid(eid), title(t), language(l), platform(p) {
|
||||
thumbPath = Common::String::format("%s-%s.png", engineid.c_str(), gameid.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
struct LauncherEntryComparator {
|
||||
bool operator()(const LauncherEntry &x, const LauncherEntry &y) const {
|
||||
return scumm_compareDictionary(x.description.c_str(), y.description.c_str()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
class GridItemWidget;
|
||||
|
||||
|
@ -486,8 +493,8 @@ private:
|
|||
// _gridItems should be reserved to hold few more than visible items
|
||||
// Fixing it to 30 for now, 6 items * (4 rows + 1 extra row);
|
||||
Common::Array<GridItemWidget *> _gridItems;
|
||||
Common::Array<LauncherEntry> _allEntries;
|
||||
Common::Array<LauncherEntry> _visibleEntries;
|
||||
Common::Array<GridItemInfo> _allEntries;
|
||||
Common::Array<GridItemInfo> _visibleEntries;
|
||||
Common::HashMap<Common::String, Graphics::ManagedSurface *> _loadedSurfaces;
|
||||
// Common::HashMap<Common::String, EntryContainerWidget *> _entryById;
|
||||
|
||||
|
@ -510,13 +517,6 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
enum Platform {
|
||||
kPlatformDOS,
|
||||
kPlatformAmiga,
|
||||
kPlatformApple2,
|
||||
kPlatformUnknown = -1
|
||||
};
|
||||
|
||||
GridWidget(GuiObject *boss, int x, int y, int w, int h);
|
||||
GridWidget(GuiObject *boss, const Common::String &name);
|
||||
|
||||
|
@ -525,7 +525,7 @@ public:
|
|||
|
||||
|
||||
bool calcVisibleEntries(void);
|
||||
void setEntryList(Common::Array<LauncherEntry> *list);
|
||||
void setEntryList(Common::Array<GridItemInfo> *list);
|
||||
void destroyItems();
|
||||
void loadPlatformIcons();
|
||||
void updateGrid(void);
|
||||
|
@ -540,6 +540,8 @@ public:
|
|||
};
|
||||
|
||||
enum {
|
||||
kGridItemHPadding = 50,
|
||||
kGridItemVPadding = 50,
|
||||
kThumbnailWidth = 192,
|
||||
kThumbnailHeight = 192
|
||||
};
|
||||
|
@ -553,19 +555,19 @@ public:
|
|||
StaticTextWidget *_title;
|
||||
GridWidget *_grid;
|
||||
|
||||
Common::Array<LauncherEntry> _attachedEntries;
|
||||
LauncherEntry *_activeEntry;
|
||||
Common::Array<GridItemInfo> _attachedEntries;
|
||||
GridItemInfo *_activeEntry;
|
||||
|
||||
bool isHighlighted;
|
||||
void setActiveEntry(LauncherEntry &entry);
|
||||
void setActiveEntry(GridItemInfo &entry);
|
||||
|
||||
public:
|
||||
GridItemWidget(GridWidget *boss, int x, int y, int w, int h);
|
||||
GridItemWidget(GridWidget *boss, GraphicsWidget *th, GraphicsWidget *p, StaticTextWidget *l, StaticTextWidget *t);
|
||||
|
||||
void attachEntry(Common::String key, Common::String description, Common::ConfigManager::Domain *domain);
|
||||
void attachEntry(LauncherEntry &entry);
|
||||
void attachEntries(Common::Array<LauncherEntry> entry);
|
||||
void attachEntry(GridItemInfo &entry);
|
||||
void attachEntries(Common::Array<GridItemInfo> entry);
|
||||
void setActiveEntry(int i) {setActiveEntry(_attachedEntries[i]);};
|
||||
void update();
|
||||
void drawWidget() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue