2012-10-01 03:29:55 +00:00
|
|
|
#include "GuiFastSelect.h"
|
|
|
|
#include "../Renderer.h"
|
|
|
|
#include <iostream>
|
2013-04-08 17:40:15 +00:00
|
|
|
#include "GuiGameList.h"
|
2012-10-01 03:29:55 +00:00
|
|
|
|
|
|
|
const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
2012-10-05 13:44:18 +00:00
|
|
|
const int GuiFastSelect::SCROLLSPEED = 100;
|
2012-10-01 03:29:55 +00:00
|
|
|
const int GuiFastSelect::SCROLLDELAY = 507;
|
|
|
|
|
2013-06-30 17:24:09 +00:00
|
|
|
GuiFastSelect::GuiFastSelect(Window* window, GuiGameList* parent, TextListComponent<FileData*>* list, char startLetter, ThemeComponent * theme)
|
|
|
|
: GuiComponent(window), mParent(parent), mList(list), mTheme(theme)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
|
|
|
mLetterID = LETTERS.find(toupper(startLetter));
|
|
|
|
if(mLetterID == std::string::npos)
|
|
|
|
mLetterID = 0;
|
|
|
|
|
2013-06-30 17:24:09 +00:00
|
|
|
mScrollSound = mTheme->getSound("menuScroll");
|
|
|
|
mTextColor = mTheme->getColor("fastSelect");
|
2012-10-01 03:29:55 +00:00
|
|
|
|
|
|
|
mScrolling = false;
|
|
|
|
mScrollTimer = 0;
|
|
|
|
mScrollOffset = 0;
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight();
|
2013-05-13 19:53:28 +00:00
|
|
|
mBox = new GuiBox(window, (int)(sw * 0.2f), (int)(sh * 0.2f), (int)(sw * 0.6f), (int)(sh * 0.6f));
|
2013-06-30 17:24:09 +00:00
|
|
|
mBox->setData(mTheme->getBoxData());
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiFastSelect::~GuiFastSelect()
|
|
|
|
{
|
2013-04-08 17:40:15 +00:00
|
|
|
mParent->updateDetailData();
|
2012-10-05 20:04:12 +00:00
|
|
|
delete mBox;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiFastSelect::render()
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
2012-10-05 20:04:12 +00:00
|
|
|
unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight();
|
2012-10-01 03:29:55 +00:00
|
|
|
|
2012-10-10 13:51:48 +00:00
|
|
|
if(!mBox->hasBackground())
|
2013-06-30 17:24:09 +00:00
|
|
|
Renderer::drawRect((int)(sw * 0.3f), (int)(sh * 0.3f), (int)(sw * 0.4f), (int)(sh * 0.4f), 0x000FF0AA);
|
2012-10-10 13:51:48 +00:00
|
|
|
|
2012-10-10 13:56:34 +00:00
|
|
|
mBox->render();
|
|
|
|
|
2013-06-30 17:24:09 +00:00
|
|
|
Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, (int)(sh * 0.5f - (mTheme->getFastSelectFont()->getHeight() * 0.5f)), mTextColor, mTheme->getFastSelectFont());
|
|
|
|
Renderer::drawCenteredText("Sort order:", 0, (int)(sh * 0.6f - (mTheme->getDescriptionFont()->getHeight() * 0.5f)), mTextColor, mTheme->getDescriptionFont());
|
|
|
|
std::string sortString = "<- " + mParent->getSortState().description + " ->";
|
|
|
|
Renderer::drawCenteredText(sortString, 0, (int)(sh * 0.6f + (mTheme->getDescriptionFont()->getHeight() * 0.5f)), mTextColor, mTheme->getDescriptionFont());
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
bool GuiFastSelect::input(InputConfig* config, Input input)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("up", input) && input.value != 0)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
|
|
|
mScrollOffset = -1;
|
2012-10-13 20:05:43 +00:00
|
|
|
scroll();
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("down", input) && input.value != 0)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
|
|
|
mScrollOffset = 1;
|
2012-10-13 20:05:43 +00:00
|
|
|
scroll();
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 17:24:09 +00:00
|
|
|
if(config->isMappedTo("left", input) && input.value != 0)
|
|
|
|
{
|
|
|
|
mParent->setPreviousSortIndex();
|
|
|
|
mScrollSound->play();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(config->isMappedTo("right", input) && input.value != 0)
|
|
|
|
{
|
|
|
|
mParent->setNextSortIndex();
|
|
|
|
mScrollSound->play();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
if((config->isMappedTo("up", input) || config->isMappedTo("down", input)) && input.value == 0)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
|
|
|
mScrolling = false;
|
|
|
|
mScrollTimer = 0;
|
|
|
|
mScrollOffset = 0;
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
if(config->isMappedTo("select", input) && input.value == 0)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
2012-10-05 13:44:18 +00:00
|
|
|
setListPos();
|
2012-10-01 03:29:55 +00:00
|
|
|
delete this;
|
2013-06-02 15:08:32 +00:00
|
|
|
return true;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
2013-06-02 15:08:32 +00:00
|
|
|
|
|
|
|
return false;
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void GuiFastSelect::update(int deltaTime)
|
2012-10-01 03:29:55 +00:00
|
|
|
{
|
|
|
|
if(mScrollOffset != 0)
|
|
|
|
{
|
|
|
|
mScrollTimer += deltaTime;
|
|
|
|
|
|
|
|
if(!mScrolling && mScrollTimer >= SCROLLDELAY)
|
|
|
|
{
|
|
|
|
mScrolling = true;
|
|
|
|
mScrollTimer = SCROLLSPEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mScrolling && mScrollTimer >= SCROLLSPEED)
|
|
|
|
{
|
|
|
|
mScrollTimer = 0;
|
2012-10-13 20:05:43 +00:00
|
|
|
scroll();
|
2012-10-01 03:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-13 20:05:43 +00:00
|
|
|
void GuiFastSelect::scroll()
|
|
|
|
{
|
|
|
|
setLetterID(mLetterID + mScrollOffset);
|
|
|
|
mScrollSound->play();
|
|
|
|
}
|
|
|
|
|
2012-10-01 03:29:55 +00:00
|
|
|
void GuiFastSelect::setLetterID(int id)
|
|
|
|
{
|
|
|
|
while(id < 0)
|
|
|
|
id += LETTERS.length();
|
|
|
|
while(id >= (int)LETTERS.length())
|
|
|
|
id -= LETTERS.length();
|
|
|
|
|
|
|
|
mLetterID = (size_t)id;
|
|
|
|
}
|
2012-10-05 13:44:18 +00:00
|
|
|
|
|
|
|
void GuiFastSelect::setListPos()
|
|
|
|
{
|
|
|
|
char letter = LETTERS[mLetterID];
|
|
|
|
|
|
|
|
int min = 0;
|
|
|
|
int max = mList->getObjectCount() - 1;
|
|
|
|
|
2012-10-28 23:07:05 +00:00
|
|
|
int mid = 0;
|
2012-10-05 13:44:18 +00:00
|
|
|
|
|
|
|
while(max >= min)
|
|
|
|
{
|
|
|
|
mid = ((max - min) / 2) + min;
|
|
|
|
|
|
|
|
char checkLetter = toupper(mList->getObject(mid)->getName()[0]);
|
|
|
|
|
|
|
|
if(checkLetter < letter)
|
|
|
|
{
|
|
|
|
min = mid + 1;
|
|
|
|
}else if(checkLetter > letter)
|
|
|
|
{
|
|
|
|
max = mid - 1;
|
|
|
|
}else{
|
|
|
|
//exact match found
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mList->setSelection(mid);
|
|
|
|
}
|