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"
|
|
|
|
#include "Renderer.h"
|
|
|
|
#include <iomanip>
|
2013-04-08 14:41:25 +00:00
|
|
|
|
2017-03-25 17:02:28 +00:00
|
|
|
Window::Window() : mNormalizeNextUpdate(false), mFrameTimeElapsed(0), mFrameCountElapsed(0), mAverageDeltaTime(10),
|
2017-06-12 16:38:59 +00:00
|
|
|
mAllowSleep(true), mSleeping(false), mTimeSinceLastInput(0), mScreenSaver(NULL), mRenderScreenSaver(false), mInfoPopup(NULL)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2014-01-25 23:34:29 +00:00
|
|
|
mHelp = new HelpComponent(this);
|
2014-03-04 22:48:33 +00:00
|
|
|
mBackgroundOverlay = new ImageComponent(this);
|
2017-09-08 14:49:47 +00:00
|
|
|
mPassKeyListener = new PassKeyListener;
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2014-03-04 22:48:33 +00:00
|
|
|
delete mBackgroundOverlay;
|
2013-12-12 19:48:29 +00:00
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
// delete all our GUIs
|
2013-07-09 10:37:37 +00:00
|
|
|
while(peekGui())
|
|
|
|
delete peekGui();
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2014-01-25 23:34:29 +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
|
|
|
{
|
2017-01-25 15:00:56 +00:00
|
|
|
if (mGuiStack.size() > 0)
|
|
|
|
{
|
|
|
|
auto& top = mGuiStack.back();
|
|
|
|
top->topWindow(false);
|
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
mGuiStack.push_back(gui);
|
2014-05-29 20:41:47 +00:00
|
|
|
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
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto i = mGuiStack.cbegin(); i != mGuiStack.cend(); i++)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
if(*i == gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2014-01-25 23:34:29 +00:00
|
|
|
i = mGuiStack.erase(i);
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
if(i == mGuiStack.cend() && mGuiStack.size()) // we just popped the stack and the stack is not empty
|
2017-01-25 15:00:56 +00:00
|
|
|
{
|
2014-05-29 20:41:47 +00:00
|
|
|
mGuiStack.back()->updateHelpPrompts();
|
2017-01-25 15:00:56 +00:00
|
|
|
mGuiStack.back()->topWindow(true);
|
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
if(mGuiStack.size() == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
return mGuiStack.back();
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
bool Window::init(unsigned int width, unsigned int height)
|
2013-04-08 17:40:15 +00:00
|
|
|
{
|
2013-07-09 10:37:37 +00:00
|
|
|
if(!Renderer::init(width, height))
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Renderer failed to initialize!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:07:32 +00:00
|
|
|
InputManager::getInstance()->init();
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2013-10-04 23:09:54 +00:00
|
|
|
ResourceManager::getInstance()->reloadAll();
|
2013-04-10 17:29:07 +00:00
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
//keep a reference to the default fonts, so they don't keep getting destroyed/recreated
|
|
|
|
if(mDefaultFonts.empty())
|
2013-04-08 17:40:15 +00:00
|
|
|
{
|
2013-10-04 23:09:54 +00:00
|
|
|
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-04-08 17:40:15 +00:00
|
|
|
}
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2017-05-28 16:43:41 +00:00
|
|
|
mBackgroundOverlay->setImage(":/scroll_gradient.png");
|
2014-03-04 22:48:33 +00:00
|
|
|
mBackgroundOverlay->setResize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
// update our help because font sizes probably changed
|
|
|
|
if(peekGui())
|
2014-05-29 20:41:47 +00:00
|
|
|
peekGui()->updateHelpPrompts();
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
return true;
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinit()
|
|
|
|
{
|
2016-12-04 23:47:34 +00:00
|
|
|
// Hide all GUI elements on uninitialisation - this disable
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto i = mGuiStack.cbegin(); i != mGuiStack.cend(); i++)
|
2016-12-04 23:47:34 +00:00
|
|
|
{
|
|
|
|
(*i)->onHide();
|
|
|
|
}
|
2014-04-18 18:07:32 +00:00
|
|
|
InputManager::getInstance()->deinit();
|
2013-10-04 23:09:54 +00:00
|
|
|
ResourceManager::getInstance()->unloadAll();
|
2013-04-10 17:29:07 +00:00
|
|
|
Renderer::deinit();
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 18:07:32 +00:00
|
|
|
void Window::textInput(const char* text)
|
|
|
|
{
|
|
|
|
if(peekGui())
|
|
|
|
peekGui()->textInput(text);
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void Window::input(InputConfig* config, Input input)
|
|
|
|
{
|
2017-06-01 20:08:44 +00:00
|
|
|
if (mScreenSaver) {
|
|
|
|
if(mScreenSaver->isScreenSaverActive() && Settings::getInstance()->getBool("ScreenSaverControls") &&
|
|
|
|
(Settings::getInstance()->getString("ScreenSaverBehavior") == "random video"))
|
|
|
|
{
|
|
|
|
if(mScreenSaver->getCurrentGame() != NULL && (config->isMappedTo("right", input) || config->isMappedTo("start", input) || config->isMappedTo("select", input)))
|
|
|
|
{
|
|
|
|
if(config->isMappedTo("right", input) || config->isMappedTo("select", input))
|
|
|
|
{
|
|
|
|
if (input.value != 0) {
|
|
|
|
// handle screensaver control
|
|
|
|
mScreenSaver->nextVideo();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
else if(config->isMappedTo("start", input) && input.value != 0)
|
2017-06-01 20:08:44 +00:00
|
|
|
{
|
|
|
|
// launch game!
|
|
|
|
cancelScreenSaver();
|
|
|
|
mScreenSaver->launchGame();
|
|
|
|
// to force handling the wake up process
|
|
|
|
mSleeping = true;
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
/*else if(input.value != 0)
|
2017-06-01 20:08:44 +00:00
|
|
|
{
|
|
|
|
return;
|
2017-06-12 16:38:59 +00:00
|
|
|
}*/
|
2017-06-01 20:08:44 +00:00
|
|
|
}
|
2017-03-25 17:02:28 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 00:14:22 +00:00
|
|
|
if(mSleeping)
|
|
|
|
{
|
|
|
|
// wake up
|
|
|
|
mTimeSinceLastInput = 0;
|
2016-12-14 08:30:54 +00:00
|
|
|
cancelScreenSaver();
|
2014-06-02 00:14:22 +00:00
|
|
|
mSleeping = false;
|
|
|
|
onWake();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeSinceLastInput = 0;
|
2016-12-14 08:30:54 +00:00
|
|
|
cancelScreenSaver();
|
2014-06-02 00:14:22 +00:00
|
|
|
|
2014-03-25 22:46:58 +00:00
|
|
|
if(config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_g && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug"))
|
|
|
|
{
|
2014-04-05 17:48:38 +00:00
|
|
|
// toggle debug grid with Ctrl-G
|
2014-03-25 22:46:58 +00:00
|
|
|
Settings::getInstance()->setBool("DebugGrid", !Settings::getInstance()->getBool("DebugGrid"));
|
2014-04-05 17:48:38 +00:00
|
|
|
}
|
|
|
|
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"));
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
else
|
|
|
|
{
|
2017-09-08 14:49:47 +00:00
|
|
|
if (!mPassKeyListener->isUIModeChanged(config, input, this) && // check if UI mode has changed due to passphrase completion
|
|
|
|
peekGui())
|
|
|
|
{
|
|
|
|
this->peekGui()->input(config, input); // this is where the majority of inputs will be consumed: the GuiComponent Stack
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::update(int deltaTime)
|
|
|
|
{
|
2013-07-17 06:47:02 +00:00
|
|
|
if(mNormalizeNextUpdate)
|
|
|
|
{
|
|
|
|
mNormalizeNextUpdate = false;
|
|
|
|
if(deltaTime > mAverageDeltaTime)
|
|
|
|
deltaTime = mAverageDeltaTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed += deltaTime;
|
|
|
|
mFrameCountElapsed++;
|
|
|
|
if(mFrameTimeElapsed > 500)
|
|
|
|
{
|
|
|
|
mAverageDeltaTime = mFrameTimeElapsed / mFrameCountElapsed;
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2014-03-08 19:00:18 +00:00
|
|
|
if(Settings::getInstance()->getBool("DrawFramerate"))
|
2013-07-17 06:47:02 +00:00
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2014-03-27 21:47:25 +00:00
|
|
|
// fps
|
2013-07-17 06:47:02 +00:00
|
|
|
ss << std::fixed << std::setprecision(1) << (1000.0f * (float)mFrameCountElapsed / (float)mFrameTimeElapsed) << "fps, ";
|
|
|
|
ss << std::fixed << std::setprecision(2) << ((float)mFrameTimeElapsed / (float)mFrameCountElapsed) << "ms";
|
2014-03-27 21:47:25 +00:00
|
|
|
|
|
|
|
// vram
|
2017-01-22 23:28:06 +00:00
|
|
|
float textureVramUsageMb = TextureResource::getTotalMemUsage() / 1000.0f / 1000.0f;
|
|
|
|
float textureTotalUsageMb = TextureResource::getTotalTextureSize() / 1000.0f / 1000.0f;
|
2014-05-22 20:11:19 +00:00
|
|
|
float fontVramUsageMb = Font::getTotalMemUsage() / 1000.0f / 1000.0f;;
|
2014-03-27 21:47:25 +00:00
|
|
|
|
2017-01-22 23:28:06 +00:00
|
|
|
ss << "\nFont VRAM: " << fontVramUsageMb << " Tex VRAM: " << textureVramUsageMb <<
|
|
|
|
" Tex Max: " << textureTotalUsageMb;
|
2014-04-12 00:42:04 +00:00
|
|
|
mFrameDataText = std::unique_ptr<TextCache>(mDefaultFonts.at(1)->buildTextCache(ss.str(), 50.f, 50.f, 0xFF00FFFF));
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mFrameTimeElapsed = 0;
|
|
|
|
mFrameCountElapsed = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-02 00:14:22 +00:00
|
|
|
mTimeSinceLastInput += deltaTime;
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
if(peekGui())
|
|
|
|
peekGui()->update(deltaTime);
|
2016-12-14 08:30:54 +00:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
Transform4x4f transform = Transform4x4f::Identity();
|
2014-03-04 22:48:33 +00:00
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
mRenderedHelpPrompts = false;
|
|
|
|
|
2014-03-12 23:24:34 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
if(!mRenderedHelpPrompts)
|
|
|
|
mHelp->render(transform);
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2014-04-12 01:48:13 +00:00
|
|
|
if(Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
2013-07-17 06:47:02 +00:00
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
2014-04-12 00:42:04 +00:00
|
|
|
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
2014-06-02 00:14:22 +00:00
|
|
|
|
|
|
|
unsigned int screensaverTime = (unsigned int)Settings::getInstance()->getInt("ScreenSaverTime");
|
2016-12-14 08:30:54 +00:00
|
|
|
if(mTimeSinceLastInput >= screensaverTime && screensaverTime != 0)
|
|
|
|
startScreenSaver();
|
|
|
|
|
|
|
|
// Always call the screensaver render function regardless of whether the screensaver is active
|
|
|
|
// or not because it may perform a fade on transition
|
|
|
|
renderScreenSaver();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
|
|
|
if(!mRenderScreenSaver && mInfoPopup)
|
|
|
|
{
|
|
|
|
mInfoPopup->render(transform);
|
|
|
|
}
|
2016-12-14 08:30:54 +00:00
|
|
|
|
2016-09-17 13:21:24 +00:00
|
|
|
if(mTimeSinceLastInput >= screensaverTime && screensaverTime != 0)
|
2014-06-02 00:14:22 +00:00
|
|
|
{
|
2016-12-14 08:30:54 +00:00
|
|
|
if (!isProcessing() && mAllowSleep && (!mScreenSaver || mScreenSaver->allowSleep()))
|
2016-09-17 13:21:24 +00:00
|
|
|
{
|
|
|
|
// go to sleep
|
|
|
|
mSleeping = true;
|
|
|
|
onSleep();
|
|
|
|
}
|
2014-06-02 00:14:22 +00:00
|
|
|
}
|
2013-07-17 06:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::normalizeNextUpdate()
|
|
|
|
{
|
|
|
|
mNormalizeNextUpdate = true;
|
|
|
|
}
|
|
|
|
|
2013-10-13 21:40:36 +00:00
|
|
|
bool Window::getAllowSleep()
|
|
|
|
{
|
|
|
|
return mAllowSleep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setAllowSleep(bool sleep)
|
|
|
|
{
|
|
|
|
mAllowSleep = sleep;
|
|
|
|
}
|
2013-12-12 19:48:29 +00:00
|
|
|
|
|
|
|
void Window::renderLoadingScreen()
|
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
Transform4x4f trans = Transform4x4f::Identity();
|
2014-05-01 19:47:33 +00:00
|
|
|
Renderer::setMatrix(trans);
|
2016-06-24 01:47:41 +00:00
|
|
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000FF);
|
2014-05-28 21:43:23 +00:00
|
|
|
|
2017-01-22 23:28:06 +00:00
|
|
|
ImageComponent splash(this, true);
|
2014-05-28 21:43:23 +00:00
|
|
|
splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f);
|
|
|
|
splash.setImage(":/splash.svg");
|
|
|
|
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("LOADING...", 0, 0, 0x656565FF);
|
2017-11-13 22:16:38 +00:00
|
|
|
trans = trans.translate(Vector3f(Math::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f),
|
|
|
|
Math::round(Renderer::getScreenHeight() * 0.835f), 0.0f));
|
2014-05-01 19:47:33 +00:00
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
font->renderTextCache(cache);
|
|
|
|
delete cache;
|
|
|
|
|
2013-12-12 19:48:29 +00:00
|
|
|
Renderer::swapBuffers();
|
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2014-05-15 01:58:16 +00:00
|
|
|
void Window::renderHelpPromptsEarly()
|
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
mHelp->render(Transform4x4f::Identity());
|
2014-05-15 01:58:16 +00:00
|
|
|
mRenderedHelpPrompts = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
mHelp->clearPrompts();
|
2014-05-29 20:41:47 +00:00
|
|
|
mHelp->setStyle(style);
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2014-03-24 01:33:27 +00:00
|
|
|
std::vector<HelpPrompt> addPrompts;
|
|
|
|
|
2014-05-15 00:20:18 +00:00
|
|
|
std::map<std::string, bool> inputSeenMap;
|
|
|
|
std::map<std::string, int> mappedToSeenMap;
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto it = prompts.cbegin(); it != prompts.cend(); it++)
|
2014-01-25 23:34:29 +00:00
|
|
|
{
|
|
|
|
// only add it if the same icon hasn't already been added
|
2017-08-22 23:21:33 +00:00
|
|
|
if(inputSeenMap.emplace(it->first, true).second)
|
2014-05-15 00:20:18 +00:00
|
|
|
{
|
|
|
|
// this symbol hasn't been seen yet, what about the action name?
|
|
|
|
auto mappedTo = mappedToSeenMap.find(it->second);
|
2017-11-11 14:56:22 +00:00
|
|
|
if(mappedTo != mappedToSeenMap.cend())
|
2014-05-15 00:20:18 +00:00
|
|
|
{
|
|
|
|
// yes, it has!
|
|
|
|
|
|
|
|
// can we combine? (dpad only)
|
2017-08-22 23:21:33 +00:00
|
|
|
if((it->first == "up/down" && addPrompts.at(mappedTo->second).first != "left/right") ||
|
|
|
|
(it->first == "left/right" && addPrompts.at(mappedTo->second).first != "up/down"))
|
2014-05-15 00:20:18 +00:00
|
|
|
{
|
|
|
|
// 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!
|
2017-11-17 14:58:52 +00:00
|
|
|
mappedToSeenMap.emplace(it->second, (int)addPrompts.size());
|
2014-05-15 00:20:18 +00:00
|
|
|
addPrompts.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
}
|
2014-03-24 01:33:27 +00:00
|
|
|
|
2014-04-07 00:24:01 +00:00
|
|
|
// 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 {
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2014-04-07 00:24:01 +00:00
|
|
|
static const char* map[] = {
|
|
|
|
"up/down/left/right",
|
|
|
|
"up/down",
|
|
|
|
"left/right",
|
2017-03-25 17:02:28 +00:00
|
|
|
"a", "b", "x", "y", "l", "r",
|
|
|
|
"start", "select",
|
2014-04-07 00:24:01 +00:00
|
|
|
NULL
|
|
|
|
};
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2014-04-07 00:24:01 +00:00
|
|
|
int i = 0;
|
2014-04-12 01:48:13 +00:00
|
|
|
int aVal = 0;
|
|
|
|
int bVal = 0;
|
2014-04-07 00:24:01 +00:00
|
|
|
while(map[i] != NULL)
|
|
|
|
{
|
|
|
|
if(a.first == map[i])
|
2014-04-12 01:48:13 +00:00
|
|
|
aVal = i;
|
|
|
|
if(b.first == map[i])
|
|
|
|
bVal = i;
|
2014-04-07 00:24:01 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:48:13 +00:00
|
|
|
return aVal > bVal;
|
2014-04-07 00:24:01 +00:00
|
|
|
});
|
|
|
|
|
2014-03-24 01:33:27 +00:00
|
|
|
mHelp->setPrompts(addPrompts);
|
2014-01-25 23:34:29 +00:00
|
|
|
}
|
2014-06-02 00:14:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Window::onSleep()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::onWake()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2016-09-12 11:31:44 +00:00
|
|
|
|
|
|
|
bool Window::isProcessing()
|
|
|
|
{
|
2017-11-11 14:56:22 +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
|
|
|
|
2017-06-01 20:08:44 +00:00
|
|
|
void Window::startScreenSaver()
|
|
|
|
{
|
|
|
|
if (mScreenSaver && !mRenderScreenSaver)
|
|
|
|
{
|
|
|
|
// Tell the GUI components the screensaver is starting
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto i = mGuiStack.cbegin(); i != mGuiStack.cend(); i++)
|
2017-06-01 20:08:44 +00:00
|
|
|
(*i)->onScreenSaverActivate();
|
|
|
|
|
|
|
|
mScreenSaver->startScreenSaver();
|
|
|
|
mRenderScreenSaver = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::cancelScreenSaver()
|
|
|
|
{
|
|
|
|
if (mScreenSaver && mRenderScreenSaver)
|
|
|
|
{
|
|
|
|
mScreenSaver->stopScreenSaver();
|
|
|
|
mRenderScreenSaver = false;
|
|
|
|
|
|
|
|
// Tell the GUI components the screensaver has stopped
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto i = mGuiStack.cbegin(); i != mGuiStack.cend(); i++)
|
2017-06-01 20:08:44 +00:00
|
|
|
(*i)->onScreenSaverDeactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::renderScreenSaver()
|
|
|
|
{
|
|
|
|
if (mScreenSaver)
|
|
|
|
mScreenSaver->renderScreenSaver();
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
2017-06-01 20:08:44 +00:00
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
bool Window::PassKeyListener::isUIModeChanged(InputConfig * config, Input input, Window* /*window*/)
|
2017-09-08 14:49:47 +00:00
|
|
|
{
|
|
|
|
// This function reads the current input to listen for the passkey
|
|
|
|
// sequence to unlock the UI mode. The progress is saved in mPassKeyCounter
|
|
|
|
// supported sequence-inputs: u (up), d (down), l (left), r (right), a, b, x, y
|
|
|
|
// default passkeyseq = "uuddlrlrba", as defined in the setting 'UIMode_passkey'.
|
|
|
|
|
|
|
|
if ((Settings::getInstance()->getString("UIMode") == "Full") || (!input.value))
|
|
|
|
{
|
|
|
|
return false; // Already unlocked, or no keydown, nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundMatch = false;
|
|
|
|
|
|
|
|
for (auto valstring : mInputVals)
|
|
|
|
{
|
|
|
|
if (config->isMappedTo(valstring, input) &&
|
|
|
|
(this->mPassKeySequence[this->mPassKeyCounter] == valstring[0]))
|
|
|
|
{
|
|
|
|
this->mPassKeyCounter ++;
|
|
|
|
foundMatch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundMatch)
|
|
|
|
{
|
|
|
|
this->mPassKeyCounter = 0; // current input is incorrect, reset counter
|
|
|
|
}
|
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
if (this->mPassKeyCounter == (int)(this->mPassKeySequence.length()))
|
2017-09-08 14:49:47 +00:00
|
|
|
{
|
|
|
|
// When we have reached the end of the list, trigger UI_mode unlock
|
|
|
|
LOG(LogDebug) << " Window::PassKeyListener::isUIModeChanged(): Passkey sequence completed, switching UIMode to full";
|
|
|
|
Settings::getInstance()->setString("UIMode", "Full");
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
this->mPassKeyCounter = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|