mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 21:59:17 +00:00
ENGINES: Add a dialog for reporting unknown games
Thanks to the great help of @criezy, here's my implementation of an GUI dialog that appears when an unknown game is detected. Features: - Allows copying the data collected by game detector to the clipboard - Allows opening the bug tracker and pre-filling the form fiels This closes https://bugs.scummvm.org/ticket/10435.
This commit is contained in:
parent
05c1e593c0
commit
4220e14522
@ -30,6 +30,8 @@
|
||||
#include "common/textconsole.h"
|
||||
#include "common/translation.h"
|
||||
#include "gui/EventRecorder.h"
|
||||
#include "gui/gui-manager.h"
|
||||
#include "engines/unknown-game-dialog.h"
|
||||
#include "engines/advancedDetector.h"
|
||||
#include "engines/obsolete.h"
|
||||
|
||||
@ -326,36 +328,55 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine)
|
||||
}
|
||||
|
||||
void AdvancedMetaEngine::reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps, const ADGameIdList &matchedGameIds) const {
|
||||
Common::String report = Common::String::format(
|
||||
_("The game in '%s' seems to be an unknown %s engine game "
|
||||
"variant.\n\nPlease report the following data to the ScummVM "
|
||||
"team at %s along with the name of the game you tried to add and "
|
||||
"its version, language, etc.:"),
|
||||
path.getPath().c_str(), getName(), "https://bugs.scummvm.org/");
|
||||
const char *reportCommon = "The game in '%s' seems to be an unknown %s engine game "
|
||||
"variant.\n\nPlease report the following data to the ScummVM "
|
||||
"team at %s along with the name of the game you tried to add and "
|
||||
"its version, language, etc.:";
|
||||
Common::String report = Common::String::format(reportCommon, path.getPath().c_str(), getName(), "https://bugs.scummvm.org/");
|
||||
Common::String reportTranslated = Common::String::format(_(reportCommon), path.getPath().c_str(), getName(), "https://bugs.scummvm.org/");
|
||||
Common::String bugtrackerAffectedEngine = getName();
|
||||
|
||||
if (matchedGameIds.size()) {
|
||||
report += "\n\n";
|
||||
report += _("Matched game IDs:");
|
||||
reportTranslated += "\n\n";
|
||||
report += "Matched game IDs:";
|
||||
reportTranslated += _("Matched game IDs:");
|
||||
report += " ";
|
||||
reportTranslated += " ";
|
||||
|
||||
for (ADGameIdList::const_iterator gameId = matchedGameIds.begin(); gameId != matchedGameIds.end(); ++gameId) {
|
||||
if (gameId != matchedGameIds.begin()) {
|
||||
report += ", ";
|
||||
reportTranslated += ", ";
|
||||
}
|
||||
report += *gameId;
|
||||
reportTranslated += *gameId;
|
||||
}
|
||||
}
|
||||
|
||||
report += "\n\n";
|
||||
reportTranslated += "\n\n";
|
||||
|
||||
report.wordWrap(80);
|
||||
reportTranslated.wordWrap(65);
|
||||
Common::String reportLog = report;
|
||||
reportLog.wordWrap(80);
|
||||
|
||||
Common::String unknownFiles;
|
||||
for (ADFilePropertiesMap::const_iterator file = filesProps.begin(); file != filesProps.end(); ++file)
|
||||
report += Common::String::format(" {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
|
||||
unknownFiles += Common::String::format(" {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
|
||||
|
||||
report += "\n";
|
||||
report += unknownFiles;
|
||||
reportTranslated += unknownFiles;
|
||||
reportLog += unknownFiles + "\n";
|
||||
|
||||
g_system->logMessage(LogMessageType::kInfo, report.c_str());
|
||||
// Write the original message about the unknown game to the log file
|
||||
g_system->logMessage(LogMessageType::kInfo, reportLog.c_str());
|
||||
|
||||
// Check if the GUI is running, show the UnknownGameDialog and print the translated unknown game information
|
||||
if (GUI::GuiManager::hasInstance() && g_gui.isActive()) {
|
||||
UnknownGameDialog dialog(report, reportTranslated, bugtrackerAffectedEngine);
|
||||
dialog.runModal();
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedMetaEngine::composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth, const Common::String &parentName) const {
|
||||
|
@ -6,7 +6,8 @@ MODULE_OBJS := \
|
||||
engine.o \
|
||||
game.o \
|
||||
obsolete.o \
|
||||
savestate.o
|
||||
savestate.o \
|
||||
unknown-game-dialog.o
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
|
145
engines/unknown-game-dialog.cpp
Normal file
145
engines/unknown-game-dialog.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/translation.h"
|
||||
#include "common/str-array.h"
|
||||
#include "gui/gui-manager.h"
|
||||
#include "gui/message.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "gui/widgets/popup.h"
|
||||
#include "engines/unknown-game-dialog.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
|
||||
enum {
|
||||
kCopyToClipboard = 'cpcl',
|
||||
kOpenBugtrackerURL = 'ourl',
|
||||
kClose = 'clse'
|
||||
};
|
||||
|
||||
UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Common::String &reportTranslated, const Common::String &bugtrackerAffectedEngine)
|
||||
: Dialog(30, 20, 260, 124) {
|
||||
|
||||
_reportData = reportData;
|
||||
_reportTranslated = reportTranslated;
|
||||
_bugtrackerAffectedEngine = bugtrackerAffectedEngine;
|
||||
|
||||
//Check if we have clipboard functionality and expand the reportTranslated message if needed...
|
||||
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
|
||||
_reportTranslated += "\n";
|
||||
_reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
|
||||
}
|
||||
|
||||
//Check if we have support for opening URLs and expand the reportTranslated message if needed...
|
||||
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
|
||||
_reportTranslated += "\n";
|
||||
_reportTranslated += _("You can also directly report your game to the Bug Tracker!");
|
||||
}
|
||||
|
||||
const int screenW = g_system->getOverlayWidth();
|
||||
const int screenH = g_system->getOverlayHeight();
|
||||
|
||||
int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
|
||||
int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
|
||||
|
||||
//Calculate the size the dialog needs
|
||||
Common::Array<Common::String> lines;
|
||||
int maxlineWidth = g_gui.getFont().wordWrapText(_reportTranslated, screenW - 2 * 20, lines);
|
||||
int lineCount = lines.size() + 1;
|
||||
|
||||
_h = 3 * kLineHeight + lineCount * kLineHeight;
|
||||
|
||||
// Buttons
|
||||
int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Close")) + 10);
|
||||
int copyToClipboardButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Copy to clipboard")) + 10);
|
||||
int openBugtrackerURLButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Report game")) + 10);
|
||||
int totalButtonWidth = closeButtonWidth;
|
||||
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport))
|
||||
totalButtonWidth += 10 + copyToClipboardButtonWidth;
|
||||
if (g_system->hasFeature(OSystem::kFeatureOpenUrl))
|
||||
totalButtonWidth += 10 + openBugtrackerURLButtonWidth;
|
||||
|
||||
_w = MAX(MAX(maxlineWidth, 0), totalButtonWidth) + 20;
|
||||
|
||||
int buttonPos = _w - closeButtonWidth - 10;
|
||||
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, _("Close"), 0, kClose);
|
||||
|
||||
//Check if we have clipboard functionality
|
||||
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
|
||||
buttonPos -= copyToClipboardButtonWidth + 5;
|
||||
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight, _("Copy to clipboard"), 0, kCopyToClipboard);
|
||||
}
|
||||
|
||||
//Check if we have support for opening URLs
|
||||
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
|
||||
buttonPos -= openBugtrackerURLButtonWidth + 5;
|
||||
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight, _("Report game"), 0, kOpenBugtrackerURL);
|
||||
//Formatting the reportData for bugtracker submission [replace line breaks]...
|
||||
_bugtrackerGameData = _reportData;
|
||||
while (_bugtrackerGameData.contains("\n")) {
|
||||
Common::replace(_bugtrackerGameData, "\n", "%0A");
|
||||
}
|
||||
}
|
||||
|
||||
// Each line is represented by one static text item.
|
||||
// TODO: Use a ScrollContainer widget instead of truncated text.
|
||||
uint y = 10;
|
||||
for (uint i = 0; i < lines.size(); i++) {
|
||||
new GUI::StaticTextWidget(this, 10, y, _w, kLineHeight, lines[i], Graphics::kTextAlignLeft);
|
||||
y += kLineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void UnknownGameDialog::reflowLayout() {
|
||||
_x = (g_system->getOverlayWidth() - _w) / 2;
|
||||
_y = (g_system->getOverlayHeight() - _h) / 2;
|
||||
GUI::Dialog::reflowLayout();
|
||||
}
|
||||
|
||||
Common::String UnknownGameDialog::generateBugtrackerURL() {
|
||||
return Common::String::format((
|
||||
"https://bugs.scummvm.org/newticket?"
|
||||
"summary=[UNK] Unknown game for engine %s:"
|
||||
"&description=%s"
|
||||
"&component=Engine%%3A%s"
|
||||
"&type=enhancement"
|
||||
"&keywords=unknown-game,%s"),
|
||||
_bugtrackerAffectedEngine.c_str(), _bugtrackerGameData.c_str(), _bugtrackerAffectedEngine.c_str(), _bugtrackerAffectedEngine.c_str());
|
||||
}
|
||||
|
||||
void UnknownGameDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
switch(cmd) {
|
||||
case kCopyToClipboard:
|
||||
g_system->setTextInClipboard(_reportData);
|
||||
if (g_system->setTextInClipboard(_reportData)) {
|
||||
g_system->displayMessageOnOSD(_("All necessary information about your game has been copied into the clipboard"));
|
||||
} else {
|
||||
g_system->displayMessageOnOSD(_("Copying the game information to the clipboard has failed!"));
|
||||
}
|
||||
break;
|
||||
case kClose:
|
||||
close();
|
||||
break;
|
||||
case kOpenBugtrackerURL:
|
||||
g_system->openUrl(generateBugtrackerURL());
|
||||
break;
|
||||
}
|
||||
}
|
37
engines/unknown-game-dialog.h
Normal file
37
engines/unknown-game-dialog.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gui/dialog.h"
|
||||
|
||||
class UnknownGameDialog : public GUI::Dialog {
|
||||
public:
|
||||
UnknownGameDialog(const Common::String &reportData, const Common::String &reportTranslated, const Common::String &bugtrackerAffectedEngine);
|
||||
void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
|
||||
virtual Common::String generateBugtrackerURL();
|
||||
virtual void reflowLayout();
|
||||
|
||||
private:
|
||||
Common::String _reportData;
|
||||
Common::String _reportTranslated;
|
||||
Common::String _bugtrackerGameData;
|
||||
Common::String _bugtrackerAffectedEngine;
|
||||
};
|
@ -35,6 +35,7 @@ common/updates.cpp
|
||||
engines/advancedDetector.cpp
|
||||
engines/dialogs.cpp
|
||||
engines/engine.cpp
|
||||
engines/unknown-game-dialog.cpp
|
||||
|
||||
audio/adlib.cpp
|
||||
audio/fmopl.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user