From 6a0b1bad5ba2b91bbd4aea61097859169917106e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 18 May 2022 23:56:51 +0200 Subject: [PATCH] Added custom event script triggers on application startup, screensaver start and screensaver end. --- es-app/src/main.cpp | 3 +++ es-app/src/views/SystemView.cpp | 2 +- es-core/src/Window.cpp | 12 ++++++++++-- es-core/src/Window.h | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 43486da46..3965e100b 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -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); diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 94caaffb2..101230982 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -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; diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index cd6e3824f..17c74fba8 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -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>().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); diff --git a/es-core/src/Window.h b/es-core/src/Window.h index b9b8fc72d..51cad5d91 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -107,7 +107,7 @@ public: } void stopInfoPopup(); - void startScreensaver(); + void startScreensaver(bool onTimer); bool stopScreensaver(); void renderScreensaver(); void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); }