Added custom event script triggers on application startup, screensaver start and screensaver end.

This commit is contained in:
Leon Styhre 2022-05-18 23:56:51 +02:00
parent 09992b5bee
commit 6a0b1bad5b
4 changed files with 15 additions and 4 deletions

View file

@ -25,6 +25,7 @@
#include "MameNames.h"
#include "MediaViewer.h"
#include "Screensaver.h"
#include "Scripting.h"
#include "Settings.h"
#include "Sound.h"
#include "SystemData.h"
@ -550,6 +551,8 @@ int main(int argc, char* argv[])
return 0;
}
Scripting::fireEvent("startup");
#if defined(__EMSCRIPTEN__)
// TODO: Remove when application window resizing has been implemented.
Settings::getInstance()->setBool("Debug", true);

View file

@ -119,7 +119,7 @@ bool SystemView::input(InputConfig* config, Input input)
if (!mWindow->isScreensaverActive()) {
ViewController::getInstance()->stopScrolling();
ViewController::getInstance()->cancelViewTransitions();
mWindow->startScreensaver();
mWindow->startScreensaver(false);
mWindow->renderScreensaver();
}
return true;

View file

@ -11,6 +11,7 @@
#include "InputManager.h"
#include "Log.h"
#include "Scripting.h"
#include "Sound.h"
#include "components/HelpComponent.h"
#include "components/ImageComponent.h"
@ -200,12 +201,14 @@ void Window::input(InputConfig* config, Input input)
}
else if (config->isMappedTo("a", input) && input.value != 0) {
// Launch game.
Scripting::fireEvent("screensaver-end", "game-start");
stopScreensaver();
mScreensaver->launchGame();
return;
}
else if (config->isMappedTo("y", input) && input.value != 0) {
// Jump to the game in its gamelist, but do not launch it.
Scripting::fireEvent("screensaver-end", "game-jump");
stopScreensaver();
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
mScreensaver->goToGame();
@ -217,6 +220,7 @@ void Window::input(InputConfig* config, Input input)
// Any keypress cancels the screensaver.
if (input.value != 0 && isScreensaverActive()) {
Scripting::fireEvent("screensaver-end", "cancel");
stopScreensaver();
return;
}
@ -566,7 +570,7 @@ void Window::render()
else if (mGameLaunchedState)
mTimeSinceLastInput = 0;
else if (!isProcessing() && !mScreensaver->isScreensaverActive())
startScreensaver();
startScreensaver(true);
}
if (mInfoPopup)
@ -713,9 +717,13 @@ void Window::stopInfoPopup()
std::queue<std::pair<std::string, int>>().swap(mInfoPopupQueue);
}
void Window::startScreensaver()
void Window::startScreensaver(bool onTimer)
{
if (mScreensaver && !mRenderScreensaver) {
if (onTimer)
Scripting::fireEvent("screensaver-start", "timer");
else
Scripting::fireEvent("screensaver-start", "manual");
setAllowTextScrolling(false);
setAllowFileAnimation(false);
mScreensaver->startScreensaver(true);

View file

@ -107,7 +107,7 @@ public:
}
void stopInfoPopup();
void startScreensaver();
void startScreensaver(bool onTimer);
bool stopScreensaver();
void renderScreensaver();
void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); }