2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
// Window.cpp
|
|
|
|
//
|
|
|
|
// Window management, screensaver and help prompts.
|
|
|
|
//
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
#include "Window.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
#include "components/HelpComponent.h"
|
2014-03-04 22:48:33 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "resources/Font.h"
|
|
|
|
#include "resources/TextureResource.h"
|
|
|
|
#include "InputManager.h"
|
|
|
|
#include "Log.h"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <algorithm>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <iomanip>
|
2013-04-08 14:41:25 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Window::Window()
|
|
|
|
: mNormalizeNextUpdate(false),
|
|
|
|
mFrameTimeElapsed(0),
|
|
|
|
mFrameCountElapsed(0),
|
|
|
|
mAverageDeltaTime(10),
|
|
|
|
mAllowSleep(true),
|
|
|
|
mSleeping(false),
|
|
|
|
mTimeSinceLastInput(0),
|
|
|
|
mScreenSaver(nullptr),
|
|
|
|
mRenderScreenSaver(false),
|
2020-07-18 21:07:02 +00:00
|
|
|
mGameLaunchedState(false),
|
2020-06-21 12:25:28 +00:00
|
|
|
mInfoPopup(nullptr)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp = new HelpComponent(this);
|
|
|
|
mBackgroundOverlay = new ImageComponent(this);
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mBackgroundOverlay;
|
2013-12-12 19:48:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Delete all our GUIs.
|
|
|
|
while (peekGui())
|
|
|
|
delete peekGui();
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mHelp;
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::pushGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mGuiStack.size() > 0) {
|
|
|
|
auto& top = mGuiStack.back();
|
|
|
|
top->topWindow(false);
|
|
|
|
}
|
|
|
|
mGuiStack.push_back(gui);
|
|
|
|
gui->updateHelpPrompts();
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::removeGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++) {
|
|
|
|
if (*it == gui) {
|
|
|
|
it = mGuiStack.erase(it);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// We just popped the stack and the stack is not empty.
|
2020-07-18 11:21:44 +00:00
|
|
|
if (it == mGuiStack.cend() && mGuiStack.size()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
mGuiStack.back()->updateHelpPrompts();
|
|
|
|
mGuiStack.back()->topWindow(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiComponent* Window::peekGui()
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mGuiStack.size() == 0)
|
|
|
|
return nullptr;
|
2013-04-08 14:41:25 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mGuiStack.back();
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 17:42:27 +00:00
|
|
|
bool Window::init()
|
2013-04-08 17:40:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Renderer::init()) {
|
|
|
|
LOG(LogError) << "Renderer failed to initialize!";
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
InputManager::getInstance()->init();
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
ResourceManager::getInstance()->reloadAll();
|
2013-04-10 17:29:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Keep a reference to the default fonts, so they don't keep getting destroyed/recreated.
|
|
|
|
if (mDefaultFonts.empty()) {
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_SMALL));
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_MEDIUM));
|
|
|
|
mDefaultFonts.push_back(Font::get(FONT_SIZE_LARGE));
|
|
|
|
}
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2020-06-21 17:35:43 +00:00
|
|
|
mBackgroundOverlay->setImage(":/graphics/scroll_gradient.png");
|
2020-06-21 12:25:28 +00:00
|
|
|
mBackgroundOverlay->setResize((float)Renderer::getScreenWidth(),
|
|
|
|
(float)Renderer::getScreenHeight());
|
2014-03-04 22:48:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update our help because font sizes probably changed.
|
|
|
|
if (peekGui())
|
|
|
|
peekGui()->updateHelpPrompts();
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinit()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Hide all GUI elements on uninitialisation - this disable.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onHide();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
InputManager::getInstance()->deinit();
|
|
|
|
ResourceManager::getInstance()->unloadAll();
|
|
|
|
Renderer::deinit();
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 18:07:32 +00:00
|
|
|
void Window::textInput(const char* text)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (peekGui())
|
|
|
|
peekGui()->textInput(text);
|
2014-04-18 18:07:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void Window::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mScreenSaver) {
|
|
|
|
if (mScreenSaver->isScreenSaverActive() &&
|
|
|
|
Settings::getInstance()->getBool("ScreenSaverControls") &&
|
2020-07-27 14:53:54 +00:00
|
|
|
((Settings::getInstance()->getString("ScreenSaverBehavior") == "random video") ||
|
|
|
|
(Settings::getInstance()->getString("ScreenSaverBehavior") == "slideshow"))) {
|
2020-07-14 17:16:21 +00:00
|
|
|
if (mScreenSaver->getCurrentGame() != nullptr &&
|
2020-07-27 14:53:54 +00:00
|
|
|
(config->isMappedTo("a", input) ||
|
|
|
|
config->isMappedLike("left", input) || config->isMappedLike("right", input))) {
|
|
|
|
// Left or right browses to the next video or image.
|
|
|
|
if (config->isMappedLike("left", input) || config->isMappedLike("right", input)) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (input.value != 0) {
|
|
|
|
// Handle screensaver control.
|
|
|
|
mScreenSaver->nextVideo();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-07-27 14:53:54 +00:00
|
|
|
else if (config->isMappedTo("a", input) && input.value != 0) {
|
2020-07-14 17:16:21 +00:00
|
|
|
// Launch game.
|
2020-06-21 12:25:28 +00:00
|
|
|
cancelScreenSaver();
|
|
|
|
mScreenSaver->launchGame();
|
|
|
|
// To force handling the wake up process.
|
|
|
|
mSleeping = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSleeping) {
|
|
|
|
// Wake up.
|
|
|
|
mTimeSinceLastInput = 0;
|
|
|
|
cancelScreenSaver();
|
|
|
|
mSleeping = false;
|
|
|
|
onWake();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeSinceLastInput = 0;
|
|
|
|
if (!config->isMappedTo("select", input))
|
|
|
|
if (cancelScreenSaver())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_g &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
|
|
|
// Toggle debug grid with Ctrl-G.
|
|
|
|
Settings::getInstance()->setBool("DebugGrid",
|
|
|
|
!Settings::getInstance()->getBool("DebugGrid"));
|
|
|
|
}
|
|
|
|
else if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_t &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
|
|
|
// Toggle TextComponent debug view with Ctrl-T.
|
|
|
|
Settings::getInstance()->setBool("DebugText",
|
|
|
|
!Settings::getInstance()->getBool("DebugText"));
|
|
|
|
}
|
|
|
|
else if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_i &&
|
|
|
|
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {
|
|
|
|
// Toggle TextComponent debug view with Ctrl-I.
|
|
|
|
Settings::getInstance()->setBool("DebugImage",
|
|
|
|
!Settings::getInstance()->getBool("DebugImage"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (peekGui())
|
|
|
|
// This is where the majority of inputs will be consumed: the GuiComponent Stack.
|
|
|
|
this->peekGui()->input(config, input);
|
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::update(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mNormalizeNextUpdate) {
|
|
|
|
mNormalizeNextUpdate = false;
|
|
|
|
if (deltaTime > mAverageDeltaTime)
|
|
|
|
deltaTime = mAverageDeltaTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed += deltaTime;
|
|
|
|
mFrameCountElapsed++;
|
|
|
|
if (mFrameTimeElapsed > 500) {
|
|
|
|
mAverageDeltaTime = mFrameTimeElapsed / mFrameCountElapsed;
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("DrawFramerate")) {
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
// FPS.
|
|
|
|
ss << std::fixed << std::setprecision(1) <<
|
|
|
|
(1000.0f * (float)mFrameCountElapsed / (float)mFrameTimeElapsed) << "fps, ";
|
|
|
|
ss << std::fixed << std::setprecision(2) <<
|
|
|
|
((float)mFrameTimeElapsed / (float)mFrameCountElapsed) << "ms";
|
|
|
|
|
|
|
|
// VRAM.
|
|
|
|
float textureVramUsageMb = TextureResource::getTotalMemUsage() / 1000.0f / 1000.0f;
|
|
|
|
float textureTotalUsageMb = TextureResource::getTotalTextureSize() / 1000.0f / 1000.0f;
|
|
|
|
float fontVramUsageMb = Font::getTotalMemUsage() / 1000.0f / 1000.0f;
|
|
|
|
|
|
|
|
ss << "\nFont VRAM: " << fontVramUsageMb << " Tex VRAM: " << textureVramUsageMb <<
|
2020-07-14 17:16:21 +00:00
|
|
|
" Tex Max: " << textureTotalUsageMb;
|
2020-06-21 12:25:28 +00:00
|
|
|
mFrameDataText = std::unique_ptr<TextCache>
|
|
|
|
(mDefaultFonts.at(1)->buildTextCache(ss.str(), 50.f, 50.f, 0xFF00FFFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed = 0;
|
|
|
|
mFrameCountElapsed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeSinceLastInput += deltaTime;
|
|
|
|
|
|
|
|
if (peekGui())
|
|
|
|
peekGui()->update(deltaTime);
|
|
|
|
|
|
|
|
// Update the screensaver.
|
|
|
|
if (mScreenSaver)
|
|
|
|
mScreenSaver->update(deltaTime);
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 06:47:02 +00:00
|
|
|
void Window::render()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f transform = Transform4x4f::Identity();
|
|
|
|
|
|
|
|
mRenderedHelpPrompts = false;
|
|
|
|
|
|
|
|
// Draw only bottom and top of GuiStack (if they are different).
|
|
|
|
if (mGuiStack.size()) {
|
|
|
|
auto& bottom = mGuiStack.front();
|
|
|
|
auto& top = mGuiStack.back();
|
|
|
|
|
|
|
|
bottom->render(transform);
|
|
|
|
if (bottom != top) {
|
|
|
|
mBackgroundOverlay->render(transform);
|
|
|
|
top->render(transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRenderedHelpPrompts)
|
|
|
|
mHelp->render(transform);
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
|
|
|
{
|
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
|
|
|
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int screensaverTime = (unsigned int)Settings::getInstance()->getInt("ScreenSaverTime");
|
2020-07-18 11:21:44 +00:00
|
|
|
// If a game has been launched, reset the screensaver timer when it's been reached as we
|
|
|
|
// don't want to start the screensaver in the background when running a game.
|
|
|
|
if (mTimeSinceLastInput >= screensaverTime && screensaverTime != 0) {
|
|
|
|
if (mGameLaunchedState)
|
|
|
|
mTimeSinceLastInput = 0;
|
|
|
|
else
|
|
|
|
startScreenSaver();
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Always call the screensaver render function regardless of whether the screensaver is active
|
|
|
|
// or not because it may perform a fade on transition.
|
|
|
|
renderScreenSaver();
|
|
|
|
|
|
|
|
if (!mRenderScreenSaver && mInfoPopup)
|
|
|
|
mInfoPopup->render(transform);
|
|
|
|
|
|
|
|
if (mTimeSinceLastInput >= screensaverTime && screensaverTime != 0) {
|
|
|
|
if (!isProcessing() && mAllowSleep && (!mScreenSaver || mScreenSaver->allowSleep())) {
|
|
|
|
// Go to sleep.
|
|
|
|
if (mSleeping == false) {
|
|
|
|
mSleeping = true;
|
|
|
|
onSleep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::normalizeNextUpdate()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mNormalizeNextUpdate = true;
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 21:40:36 +00:00
|
|
|
bool Window::getAllowSleep()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mAllowSleep;
|
2013-10-13 21:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setAllowSleep(bool sleep)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mAllowSleep = sleep;
|
2013-10-13 21:40:36 +00:00
|
|
|
}
|
2013-12-12 19:48:29 +00:00
|
|
|
|
2019-01-31 20:19:34 +00:00
|
|
|
void Window::renderLoadingScreen(std::string text)
|
2013-12-12 19:48:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f trans = Transform4x4f::Identity();
|
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
|
|
|
|
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
|
|
|
|
|
|
|
|
ImageComponent splash(this, true);
|
|
|
|
splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f);
|
2020-06-21 17:35:43 +00:00
|
|
|
splash.setImage(":/graphics/splash.svg");
|
2020-06-21 12:25:28 +00:00
|
|
|
splash.setPosition((Renderer::getScreenWidth() - splash.getSize().x()) / 2,
|
|
|
|
(Renderer::getScreenHeight() - splash.getSize().y()) / 2 * 0.6f);
|
|
|
|
splash.render(trans);
|
|
|
|
|
|
|
|
auto& font = mDefaultFonts.at(1);
|
|
|
|
TextCache* cache = font->buildTextCache(text, 0, 0, 0x656565FF);
|
|
|
|
|
|
|
|
float x = Math::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f);
|
|
|
|
float y = Math::round(Renderer::getScreenHeight() * 0.835f);
|
|
|
|
trans = trans.translate(Vector3f(x, y, 0.0f));
|
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
font->renderTextCache(cache);
|
|
|
|
delete cache;
|
|
|
|
|
|
|
|
Renderer::swapBuffers();
|
2013-12-12 19:48:29 +00:00
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
void Window::renderHelpPromptsEarly()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp->render(Transform4x4f::Identity());
|
|
|
|
mRenderedHelpPrompts = true;
|
2014-05-15 01:58:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 20:41:47 +00:00
|
|
|
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style)
|
2014-01-25 23:34:29 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mHelp->clearPrompts();
|
|
|
|
mHelp->setStyle(style);
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> addPrompts;
|
|
|
|
|
|
|
|
std::map<std::string, bool> inputSeenMap;
|
|
|
|
std::map<std::string, int> mappedToSeenMap;
|
|
|
|
for (auto it = prompts.cbegin(); it != prompts.cend(); it++) {
|
|
|
|
// Only add it if the same icon hasn't already been added.
|
|
|
|
if (inputSeenMap.emplace(it->first, true).second) {
|
|
|
|
// This symbol hasn't been seen yet, what about the action name?
|
|
|
|
auto mappedTo = mappedToSeenMap.find(it->second);
|
|
|
|
if (mappedTo != mappedToSeenMap.cend()) {
|
|
|
|
// Yes, it has!
|
|
|
|
|
|
|
|
// Can we combine? (dpad only).
|
|
|
|
if ((it->first == "up/down" &&
|
|
|
|
addPrompts.at(mappedTo->second).first != "left/right") ||
|
|
|
|
(it->first == "left/right" &&
|
|
|
|
addPrompts.at(mappedTo->second).first != "up/down")) {
|
|
|
|
// Yes!
|
|
|
|
addPrompts.at(mappedTo->second).first = "up/down/left/right";
|
|
|
|
// Don't need to add this to addPrompts since we just merged.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No, we can't combine!
|
|
|
|
addPrompts.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No, it hasn't!
|
|
|
|
mappedToSeenMap.emplace(it->second, (int)addPrompts.size());
|
|
|
|
addPrompts.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort prompts so it goes [dpad_all] [dpad_u/d] [dpad_l/r] [a/b/x/y/l/r] [start/select].
|
|
|
|
std::sort(addPrompts.begin(), addPrompts.end(),
|
|
|
|
[](const HelpPrompt& a, const HelpPrompt& b) -> bool {
|
|
|
|
|
|
|
|
static const char* map[] = {
|
|
|
|
"up/down/left/right",
|
|
|
|
"up/down",
|
|
|
|
"left/right",
|
|
|
|
"a", "b", "x", "y", "l", "r",
|
|
|
|
"start", "select",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
int aVal = 0;
|
|
|
|
int bVal = 0;
|
2020-07-14 17:16:21 +00:00
|
|
|
while (map[i] != nullptr) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (a.first == map[i])
|
|
|
|
aVal = i;
|
|
|
|
if (b.first == map[i])
|
|
|
|
bVal = i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aVal > bVal;
|
|
|
|
});
|
|
|
|
|
|
|
|
mHelp->setPrompts(addPrompts);
|
2014-01-25 23:34:29 +00:00
|
|
|
}
|
2014-06-02 00:14:22 +00:00
|
|
|
|
|
|
|
void Window::onSleep()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Scripting::fireEvent("sleep");
|
2014-06-02 00:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::onWake()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Scripting::fireEvent("wake");
|
2014-06-02 00:14:22 +00:00
|
|
|
}
|
2016-09-12 11:31:44 +00:00
|
|
|
|
|
|
|
bool Window::isProcessing()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return count_if (mGuiStack.cbegin(), mGuiStack.cend(),
|
|
|
|
[](GuiComponent* c) { return c->isProcessing(); }) > 0;
|
2016-09-12 11:31:44 +00:00
|
|
|
}
|
2016-09-17 13:21:24 +00:00
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
void Window::setLaunchedGame()
|
|
|
|
{
|
|
|
|
// Tell the GUI components that a game has been launched.
|
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onGameLaunchedActivate();
|
|
|
|
|
|
|
|
mGameLaunchedState = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::unsetLaunchedGame()
|
|
|
|
{
|
|
|
|
// Tell the GUI components that the user is back in ES again.
|
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onGameLaunchedDeactivate();
|
|
|
|
|
|
|
|
mGameLaunchedState = false;
|
|
|
|
}
|
|
|
|
|
2017-06-01 20:08:44 +00:00
|
|
|
void Window::startScreenSaver()
|
2019-04-07 12:52:36 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mScreenSaver && !mRenderScreenSaver) {
|
|
|
|
// Tell the GUI components the screensaver is starting.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onScreenSaverActivate();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
mScreenSaver->startScreenSaver();
|
|
|
|
mRenderScreenSaver = true;
|
|
|
|
}
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 12:54:06 +00:00
|
|
|
bool Window::cancelScreenSaver()
|
2019-04-07 12:52:36 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mScreenSaver && mRenderScreenSaver) {
|
|
|
|
mScreenSaver->stopScreenSaver();
|
|
|
|
mRenderScreenSaver = false;
|
|
|
|
mScreenSaver->resetCounts();
|
2019-04-07 12:52:36 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Tell the GUI components the screensaver has stopped.
|
2020-07-18 11:21:44 +00:00
|
|
|
for (auto it = mGuiStack.cbegin(); it != mGuiStack.cend(); it++)
|
|
|
|
(*it)->onScreenSaverDeactivate();
|
2019-04-07 12:54:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-07 12:54:06 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::renderScreenSaver()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mScreenSaver)
|
|
|
|
mScreenSaver->renderScreenSaver();
|
2019-04-07 12:52:36 +00:00
|
|
|
}
|