GuiFastSelect is working.

Should be able to map a joystick input to Fast Select too, but untested.
This commit is contained in:
Aloshi 2012-10-05 08:44:18 -05:00
parent 31aebf3a7d
commit a3c128f4ce
8 changed files with 72 additions and 11 deletions

View file

@ -1,3 +1,6 @@
October 5
-GuiFastSelect is working, but ugly.
September 30
-Began implementing GuiFastSelect, currently invoked by holding F2. Unfortunately, it doesn't do anything yet.
-Added <listSelectedColor>.

View file

@ -3,10 +3,10 @@
#include <iostream>
const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int GuiFastSelect::SCROLLSPEED = 120;
const int GuiFastSelect::SCROLLSPEED = 100;
const int GuiFastSelect::SCROLLDELAY = 507;
GuiFastSelect::GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter)
GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList<FileData*>* list, char startLetter)
{
mLetterID = LETTERS.find(toupper(startLetter));
if(mLetterID == std::string::npos)
@ -16,7 +16,7 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, SystemData* system, char star
InputManager::registerComponent(this);
mParent = parent;
mSystem = system;
mList = list;
mScrolling = false;
mScrollTimer = 0;
@ -64,6 +64,7 @@ void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown)
if(button == InputManager::SELECT && !keyDown)
{
setListPos();
delete this;
return;
}
@ -98,3 +99,33 @@ void GuiFastSelect::setLetterID(int id)
mLetterID = (size_t)id;
}
void GuiFastSelect::setListPos()
{
char letter = LETTERS[mLetterID];
int min = 0;
int max = mList->getObjectCount() - 1;
int mid;
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);
}

View file

@ -3,11 +3,13 @@
#include "../GuiComponent.h"
#include "../SystemData.h"
#include "../FolderData.h"
#include "GuiList.h"
class GuiFastSelect : GuiComponent
{
public:
GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter);
GuiFastSelect(GuiComponent* parent, GuiList<FileData*>* list, char startLetter);
~GuiFastSelect();
void onRender();
@ -18,11 +20,15 @@ private:
static const int SCROLLSPEED;
static const int SCROLLDELAY;
void setListPos();
void setLetterID(int id);
SystemData* mSystem;
GuiList<FileData*>* mList;
size_t mLetterID;
GuiComponent* mParent;
int mScrollTimer, mScrollOffset;
bool mScrolling;
};

View file

@ -154,8 +154,7 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
if(button == InputManager::SELECT && keyDown)
{
std::cout << "Creating GuiFastSelect\n";
new GuiFastSelect(this, mSystem, mList->getSelectedObject()->getName()[0]);
new GuiFastSelect(this, mList, mList->getSelectedObject()->getName()[0]);
}
if(mDetailed)

View file

@ -5,7 +5,7 @@
std::string GuiInputConfig::sConfigPath = "./input.cfg";
std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)" }; //must be same order as InputManager::InputButton enum
int GuiInputConfig::sInputCount = 8; //set to 9 after fast select is in
int GuiInputConfig::sInputCount = 9;
GuiInputConfig::GuiInputConfig()
{

View file

@ -231,3 +231,21 @@ void GuiList<listType>::setTextOffsetX(int textoffsetx)
{
mTextOffsetX = textoffsetx;
}
template <typename listType>
int GuiList<listType>::getObjectCount()
{
return mRowVector.size();
}
template <typename listType>
listType GuiList<listType>::getObject(int i)
{
return mRowVector.at(i).object;
}
template <typename listType>
void GuiList<listType>::setSelection(int i)
{
mSelection = i;
}

View file

@ -37,6 +37,10 @@ public:
void setTextOffsetX(int textoffsetx);
int getObjectCount();
listType getObject(int i);
void setSelection(int i);
private:
static const int SCROLLDELAY = 507;
static const int SCROLLTIME = 200;

View file

@ -77,7 +77,7 @@ void GuiTheme::readXML(std::string path)
if(path.empty())
return;
std::cout << "Loading theme \"" << path << "\"...\n";
//std::cout << "Loading theme \"" << path << "\"...\n";
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(path.c_str());
@ -108,7 +108,7 @@ void GuiTheme::readXML(std::string path)
//recursively create children for all <components> with proper parenting
createComponentChildren(root, this);
std::cout << "Finished parsing theme.\n";
//std::cout << "Finished parsing theme.\n";
}
void GuiTheme::createComponentChildren(pugi::xml_node node, GuiComponent* parent)
@ -152,7 +152,7 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent)
std::string originX, originY;
splitString(origin, ' ', &originX, &originY);
std::cout << "image, x: " << posX << " y: " << posY << " w: " << dimW << " h: " << dimH << " ox: " << originX << " oy: " << originY << " tiled: " << tiled << "\n";
//std::cout << "image, x: " << posX << " y: " << posY << " w: " << dimW << " h: " << dimH << " ox: " << originX << " oy: " << originY << " tiled: " << tiled << "\n";
//resolve to pixels from percentages/variables
int x = resolveExp(posX) * Renderer::getScreenWidth();