2013-04-09 18:13:47 +00:00
|
|
|
#include "GuiDetectDevice.h"
|
|
|
|
#include "../Window.h"
|
|
|
|
#include "../Renderer.h"
|
2013-10-04 23:24:41 +00:00
|
|
|
#include "../resources/Font.h"
|
2013-04-09 18:13:47 +00:00
|
|
|
#include "GuiInputConfig.h"
|
2014-03-22 01:12:57 +00:00
|
|
|
#include "../components/TextComponent.h"
|
2013-04-09 18:13:47 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2014-03-22 01:12:57 +00:00
|
|
|
#include "../views/ViewController.h"
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
#define HOLD_TIME 1000
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
using namespace Eigen;
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun) : GuiComponent(window),
|
|
|
|
mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 4))
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
mHoldingConfig = NULL;
|
|
|
|
mHoldTime = 0;
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
addChild(&mBackground);
|
|
|
|
addChild(&mGrid);
|
2013-04-09 18:13:47 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
if(firstRun)
|
|
|
|
{
|
|
|
|
mDoneCallback = [window] {
|
|
|
|
window->getViewController()->goToStart();
|
|
|
|
};
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
mTitle = std::make_shared<TextComponent>(mWindow, firstRun ? "WELCOME TO EMULATIONSTATION" : "SELECT A DEVICE",
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x666666FF, TextComponent::ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true);
|
|
|
|
|
|
|
|
std::string msg = (firstRun ? "First, we need to configure your input device!\n" : "");
|
|
|
|
msg += "Hold a button on your input device to configure it.\n"
|
|
|
|
"Press F4 to quit at any time.";
|
|
|
|
mMsg = std::make_shared<TextComponent>(mWindow, msg, Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mMsg, Vector2i(0, 1), false, true);
|
|
|
|
|
|
|
|
std::stringstream deviceInfo;
|
|
|
|
int numDevices = mWindow->getInputManager()->getNumJoysticks();
|
|
|
|
|
|
|
|
if(numDevices > 0)
|
|
|
|
deviceInfo << numDevices << " joystick" << (numDevices > 1 ? "s" : "") << " detected.";
|
|
|
|
else
|
|
|
|
deviceInfo << "No joysticks detected!";
|
|
|
|
mDeviceInfo = std::make_shared<TextComponent>(mWindow, deviceInfo.str(), Font::get(FONT_SIZE_SMALL), 0x888888FF, TextComponent::ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mDeviceInfo, Vector2i(0, 2), false, true);
|
|
|
|
|
|
|
|
mDeviceHeld = std::make_shared<TextComponent>(mWindow, "", Font::get(FONT_SIZE_MEDIUM), 0x777777FF, TextComponent::ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mDeviceHeld, Vector2i(0, 3), false, true);
|
|
|
|
|
|
|
|
setSize(Renderer::getScreenWidth() * 0.6f, Renderer::getScreenHeight() * 0.5f);
|
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2);
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
void GuiDetectDevice::onSizeChanged()
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
|
|
|
|
|
|
|
// grid
|
|
|
|
mGrid.setSize(mSize);
|
|
|
|
mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y());
|
|
|
|
mGrid.setRowHeightPerc(2, mDeviceInfo->getFont()->getHeight() / mSize.y());
|
|
|
|
mGrid.setRowHeightPerc(3, mDeviceHeld->getFont()->getHeight() / mSize.y());
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
bool GuiDetectDevice::input(InputConfig* config, Input input)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
if(input.type == TYPE_BUTTON || input.type == TYPE_KEY)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
if(input.value && mHoldingConfig == NULL)
|
|
|
|
{
|
|
|
|
// started holding
|
|
|
|
mHoldingConfig = config;
|
|
|
|
mHoldTime = HOLD_TIME;
|
|
|
|
mDeviceHeld->setText(config->getDeviceName());
|
|
|
|
}else if(!input.value && mHoldingConfig == config)
|
|
|
|
{
|
|
|
|
// cancel
|
|
|
|
mHoldingConfig = NULL;
|
|
|
|
mDeviceHeld->setText("");
|
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
2014-03-22 01:12:57 +00:00
|
|
|
|
|
|
|
return true;
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
void GuiDetectDevice::update(int deltaTime)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
if(mHoldingConfig)
|
2013-04-09 18:13:47 +00:00
|
|
|
{
|
2014-03-22 01:12:57 +00:00
|
|
|
mHoldTime -= deltaTime;
|
|
|
|
if(mHoldTime <= 0)
|
|
|
|
{
|
|
|
|
// picked one!
|
|
|
|
mWindow->pushGui(new GuiInputConfig(mWindow, mHoldingConfig, true, mDoneCallback));
|
|
|
|
delete this;
|
|
|
|
}
|
2013-04-09 18:13:47 +00:00
|
|
|
}
|
|
|
|
}
|