added multiple image searching delay

This commit is contained in:
Thomas Jentzsch 2022-08-14 00:53:03 +02:00
parent 40f472b913
commit 8f8efafd98
4 changed files with 56 additions and 24 deletions

View File

@ -475,6 +475,9 @@ void LauncherDialog::tick()
if(myPendingReload && myReloadTime < TimerManager::getTicks() / 1000)
reload();
if(myPendingRomInfo && myRomInfoTime < TimerManager::getTicks() / 1000)
loadRomInfo(true);
Dialog::tick();
}
@ -548,8 +551,10 @@ void LauncherDialog::updateUI()
<< (myShortCount ? " items" : " items found");
myRomCount->setLabel(buf.str());
// Update ROM info UI item
loadRomInfo();
// Update ROM info UI item, delayed
myRomInfoTime = TimerManager::getTicks() / 1000 + 250; // TODO: define delay
myPendingRomInfo = true;
loadRomInfo(false);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -668,18 +673,20 @@ void LauncherDialog::setRomInfoFont(const Common::Size& area)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::loadRomInfo()
void LauncherDialog::loadRomInfo(bool complete)
{
myPendingRomInfo = !complete;
if(!myRomImageWidget || !myROMInfoFont)
return;
const string& md5 = selectedRomMD5();
if(md5 != EmptyString)
{
myRomImageWidget->setProperties(currentNode(), md5);
myRomInfoWidget->setProperties(currentNode(), md5);
myRomImageWidget->setProperties(currentNode(), md5, complete);
myRomInfoWidget->setProperties(currentNode(), md5); // TODO: skip controller detector?
}
else
else if(!complete)
{
myRomImageWidget->clearProperties();
myRomInfoWidget->clearProperties();

View File

@ -147,7 +147,7 @@ class LauncherDialog : public Dialog, CommandSender
void setRomInfoFont(const Common::Size& area);
void loadRom();
void loadRomInfo();
void loadRomInfo(bool complete);
void openSettings();
void openGameProperties();
void openContextMenu(int x = -1, int y = -1);
@ -209,6 +209,8 @@ class LauncherDialog : public Dialog, CommandSender
bool myShortCount{false};
bool myPendingReload{false};
uInt64 myReloadTime{0};
bool myPendingRomInfo{false};
uInt64 myRomInfoTime{0};
enum {
kAllfilesCmd = 'lalf', // show all files (or ROMs only)

View File

@ -40,7 +40,7 @@ RomImageWidget::RomImageWidget(GuiObject* boss, const GUI::Font& font,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::setProperties(const FSNode& node, const string& md5)
void RomImageWidget::setProperties(const FSNode& node, const string& md5, bool complete)
{
myHaveProperties = true;
@ -52,7 +52,7 @@ void RomImageWidget::setProperties(const FSNode& node, const string& md5)
// Decide whether the information should be shown immediately
if(instance().eventHandler().state() == EventHandlerState::LAUNCHER)
parseProperties(node);
parseProperties(node, complete);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -74,11 +74,11 @@ void RomImageWidget::reloadProperties(const FSNode& node)
// by saving a different image or through a change in video renderer,
// so we reload the properties
if(myHaveProperties)
parseProperties(node);
parseProperties(node, true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomImageWidget::parseProperties(const FSNode& node)
void RomImageWidget::parseProperties(const FSNode& node, bool complete)
{
if(myNavSurface == nullptr)
{
@ -123,17 +123,32 @@ void RomImageWidget::parseProperties(const FSNode& node)
myImageList.clear();
myImageIdx = 0;
// 1. Try to load snapshots by property name
getImageList(myProperties.get(PropType::Cart_Name));
// 2. Also try to load snapshot images by filename
getImageList(node.getNameWithExt());
if(complete)
{
// Try to load snapshots by property name and ROM file name
getImageList(myProperties.get(PropType::Cart_Name), node.getNameWithExt());
if(myImageList.size())
mySurfaceIsValid = loadPng(myImageList[0].getPath());
}
else
{
const string& path = instance().snapshotLoadDir().getPath();
string filename = path + myProperties.get(PropType::Cart_Name) + ".png";
mySurfaceIsValid = loadPng(filename);
if(!mySurfaceIsValid)
{
filename = path + node.getNameWithExt("png");
mySurfaceIsValid = loadPng(filename);
}
if(mySurfaceIsValid)
myImageList.emplace_back(filename);
}
if(!mySurfaceIsValid)
{
// 3. If no ROM snapshots exist, try to load a default snapshot
// If no ROM snapshots exist, try to load a default snapshot
mySurfaceIsValid = loadPng(instance().snapshotLoadDir().getPath() + "default_snapshot.png");
}
@ -159,14 +174,22 @@ bool RomImageWidget::changeImage(int direction)
#ifdef PNG_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomImageWidget::getImageList(const string& filename)
bool RomImageWidget::getImageList(const string& propname, const string& filename)
{
const string pngName = filename + ".png";
// TODO: search for consecutive digits and letters instead of getChildren
//std::ifstream in(filename, std::ios_base::binary);
//if(!in.is_open())
// loadImageERROR("No snapshot found");
// or use a timer before updating the images
const string pngPropName = propname + ".png";
const string pngFileName = filename + ".png";
FSNode::NameFilter filter = ([&](const FSNode& node)
{
const string& nodeName = node.getName();
return (!node.isDirectory() &&
(nodeName == pngName ||
(nodeName == pngPropName || nodeName == pngFileName ||
(nodeName.find(propname + " #") == 0 && nodeName.find(".png") == nodeName.length() - 4) ||
(nodeName.find(filename + " #") == 0 && nodeName.find(".png") == nodeName.length() - 4)));
}
);

View File

@ -36,7 +36,7 @@ class RomImageWidget : public Widget, public CommandSender
return font.getFontHeight() * 9 / 8;
}
void setProperties(const FSNode& node, const string& md5);
void setProperties(const FSNode& node, const string& md5, bool complete);
void clearProperties();
void reloadProperties(const FSNode& node);
bool changeImage(int direction = 1);
@ -49,9 +49,9 @@ class RomImageWidget : public Widget, public CommandSender
#endif
private:
void parseProperties(const FSNode& node);
void parseProperties(const FSNode& node, bool complete);
#ifdef PNG_SUPPORT
bool getImageList(const string& filename);
bool getImageList(const string& propname, const string& filename);
bool loadPng(const string& filename);
#endif