Merge pull request #499 from raelgc/all-directionals

Work with dpad and analogs
This commit is contained in:
Jools Wills 2018-11-19 05:35:35 +00:00 committed by GitHub
commit 6576dd7ba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 60 additions and 44 deletions

View file

@ -251,13 +251,13 @@ bool TextListComponent<T>::input(InputConfig* config, Input input)
{
if(input.value != 0)
{
if(config->isMappedTo("down", input))
if(config->isMappedLike("down", input))
{
listInput(1);
return true;
}
if(config->isMappedTo("up", input))
if(config->isMappedLike("up", input))
{
listInput(-1);
return true;
@ -274,7 +274,7 @@ bool TextListComponent<T>::input(InputConfig* config, Input input)
return true;
}
}else{
if(config->isMappedTo("down", input) || config->isMappedTo("up", input) ||
if(config->isMappedLike("down", input) || config->isMappedLike("up", input) ||
config->isMappedTo("pagedown", input) || config->isMappedTo("pageup", input))
{
stopScrolling();

View file

@ -55,7 +55,7 @@ bool GuiFastSelect::input(InputConfig* config, Input input)
return true;
}
if(config->isMappedTo("up", input))
if(config->isMappedLike("up", input))
{
if(input.value != 0)
setScrollDir(-1);
@ -63,7 +63,7 @@ bool GuiFastSelect::input(InputConfig* config, Input input)
setScrollDir(0);
return true;
}else if(config->isMappedTo("down", input))
}else if(config->isMappedLike("down", input))
{
if(input.value != 0)
setScrollDir(1);
@ -71,12 +71,12 @@ bool GuiFastSelect::input(InputConfig* config, Input input)
setScrollDir(0);
return true;
}else if(config->isMappedTo("left", input) && input.value != 0)
}else if(config->isMappedLike("left", input) && input.value != 0)
{
mSortId = (mSortId + 1) % FileSorts::SortTypes.size();
updateSortText();
return true;
}else if(config->isMappedTo("right", input) && input.value != 0)
}else if(config->isMappedLike("right", input) && input.value != 0)
{
mSortId--;
if(mSortId < 0)

View file

@ -150,12 +150,12 @@ bool SystemView::input(InputConfig* config, Input input)
{
case VERTICAL:
case VERTICAL_WHEEL:
if (config->isMappedTo("up", input))
if (config->isMappedLike("up", input))
{
listInput(-1);
return true;
}
if (config->isMappedTo("down", input))
if (config->isMappedLike("down", input))
{
listInput(1);
return true;
@ -164,12 +164,12 @@ bool SystemView::input(InputConfig* config, Input input)
case HORIZONTAL:
case HORIZONTAL_WHEEL:
default:
if (config->isMappedTo("left", input))
if (config->isMappedLike("left", input))
{
listInput(-1);
return true;
}
if (config->isMappedTo("right", input))
if (config->isMappedLike("right", input))
{
listInput(1);
return true;
@ -191,10 +191,10 @@ bool SystemView::input(InputConfig* config, Input input)
return true;
}
}else{
if(config->isMappedTo("left", input) ||
config->isMappedTo("right", input) ||
config->isMappedTo("up", input) ||
config->isMappedTo("down", input))
if(config->isMappedLike("left", input) ||
config->isMappedLike("right", input) ||
config->isMappedLike("up", input) ||
config->isMappedLike("down", input))
listInput(0);
if(!UIModeController::getInstance()->isUIModeKid() && config->isMappedTo("select", input) && Settings::getInstance()->getBool("ScreenSaverControls"))
{

View file

@ -64,7 +64,7 @@ bool UIModeController::inputIsMatch(InputConfig * config, Input input)
{
for (auto valstring : mInputVals)
{
if (config->isMappedTo(valstring, input) &&
if (config->isMappedLike(valstring, input) &&
(mPassKeySequence[mPassKeyCounter] == valstring[0]))
{
mPassKeyCounter++;

View file

@ -104,7 +104,7 @@ std::string GridGameListView::getQuickSystemSelectLeftButton()
bool GridGameListView::input(InputConfig* config, Input input)
{
if(config->isMappedTo("left", input) || config->isMappedTo("right", input))
if(config->isMappedLike("left", input) || config->isMappedLike("right", input))
return GuiComponent::input(config, input);
return ISimpleGameListView::input(config, input);

View file

@ -118,7 +118,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
}
return true;
}else if(config->isMappedTo(getQuickSystemSelectRightButton(), input))
}else if(config->isMappedLike(getQuickSystemSelectRightButton(), input))
{
if(Settings::getInstance()->getBool("QuickSystemSelect"))
{
@ -126,7 +126,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
ViewController::get()->goToNextGameList();
return true;
}
}else if(config->isMappedTo(getQuickSystemSelectLeftButton(), input))
}else if(config->isMappedLike(getQuickSystemSelectLeftButton(), input))
{
if(Settings::getInstance()->getBool("QuickSystemSelect"))
{

View file

@ -111,6 +111,21 @@ bool InputConfig::isMappedTo(const std::string& name, Input input)
return false;
}
bool InputConfig::isMappedLike(const std::string& name, Input input)
{
if(name == "left")
{
return isMappedTo("left", input) || isMappedTo("leftanalogleft", input) || isMappedTo("rightanalogleft", input);
}else if(name == "right"){
return isMappedTo("right", input) || isMappedTo("leftanalogright", input) || isMappedTo("rightanalogright", input);
}else if(name == "up"){
return isMappedTo("up", input) || isMappedTo("leftanalogup", input) || isMappedTo("rightanalogup", input);
}else if(name == "down"){
return isMappedTo("down", input) || isMappedTo("leftanalogdown", input) || isMappedTo("rightanalogdown", input);
}
return isMappedTo(name, input);
}
std::vector<std::string> InputConfig::getMappedTo(Input input)
{
std::vector<std::string> maps;

View file

@ -108,6 +108,7 @@ public:
//Returns true if Input is mapped to this name, false otherwise.
bool isMappedTo(const std::string& name, Input input);
bool isMappedLike(const std::string& name, Input input);
//Returns a list of names this input is mapped to.
std::vector<std::string> getMappedTo(Input input);

View file

@ -120,9 +120,9 @@ void Window::input(InputConfig* config, Input input)
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(mScreenSaver->getCurrentGame() != NULL && (config->isMappedLike("right", input) || config->isMappedTo("start", input) || config->isMappedTo("select", input)))
{
if(config->isMappedTo("right", input) || config->isMappedTo("select", input))
if(config->isMappedLike("right", input) || config->isMappedTo("select", input))
{
if (input.value != 0) {
// handle screensaver control

View file

@ -233,19 +233,19 @@ bool ComponentGrid::input(InputConfig* config, Input input)
if(!input.value)
return false;
if(config->isMappedTo("down", input))
if(config->isMappedLike("down", input))
{
return moveCursor(Vector2i(0, 1));
}
if(config->isMappedTo("up", input))
if(config->isMappedLike("up", input))
{
return moveCursor(Vector2i(0, -1));
}
if(config->isMappedTo("left", input))
if(config->isMappedLike("left", input))
{
return moveCursor(Vector2i(-1, 0));
}
if(config->isMappedTo("right", input))
if(config->isMappedLike("right", input))
{
return moveCursor(Vector2i(1, 0));
}

View file

@ -75,10 +75,10 @@ bool ComponentList::input(InputConfig* config, Input input)
}
// input handler didn't consume the input - try to scroll
if(config->isMappedTo("up", input))
if(config->isMappedLike("up", input))
{
return listInput(input.value != 0 ? -1 : 0);
}else if(config->isMappedTo("down", input))
}else if(config->isMappedLike("down", input))
{
return listInput(input.value != 0 ? 1 : 0);

View file

@ -54,9 +54,9 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
}
int incDir = 0;
if(config->isMappedTo("up", input) || config->isMappedTo("pageup", input))
if(config->isMappedLike("up", input) || config->isMappedTo("pageup", input))
incDir = 1;
else if(config->isMappedTo("down", input) || config->isMappedTo("pagedown", input))
else if(config->isMappedLike("down", input) || config->isMappedTo("pagedown", input))
incDir = -1;
if(incDir != 0)
@ -103,7 +103,7 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
return true;
}
if(config->isMappedTo("right", input))
if(config->isMappedLike("right", input))
{
mEditIndex++;
if(mEditIndex >= (int)mCursorBoxes.size())
@ -111,7 +111,7 @@ bool DateTimeEditComponent::input(InputConfig* config, Input input)
return true;
}
if(config->isMappedTo("left", input))
if(config->isMappedLike("left", input))
{
mEditIndex--;
if(mEditIndex < 0)

View file

@ -117,13 +117,13 @@ bool ImageGridComponent<T>::input(InputConfig* config, Input input)
if(input.value != 0)
{
Vector2i dir = Vector2i::Zero();
if(config->isMappedTo("up", input))
if(config->isMappedLike("up", input))
dir[1 ^ mScrollDirection] = -1;
else if(config->isMappedTo("down", input))
else if(config->isMappedLike("down", input))
dir[1 ^ mScrollDirection] = 1;
else if(config->isMappedTo("left", input))
else if(config->isMappedLike("left", input))
dir[0 ^ mScrollDirection] = -1;
else if(config->isMappedTo("right", input))
else if(config->isMappedLike("right", input))
dir[0 ^ mScrollDirection] = 1;
if(dir != Vector2i::Zero())
@ -132,7 +132,7 @@ bool ImageGridComponent<T>::input(InputConfig* config, Input input)
return true;
}
}else{
if(config->isMappedTo("up", input) || config->isMappedTo("down", input) || config->isMappedTo("left", input) || config->isMappedTo("right", input))
if(config->isMappedLike("up", input) || config->isMappedLike("down", input) || config->isMappedLike("left", input) || config->isMappedLike("right", input))
{
stopScrolling();
}

View file

@ -190,7 +190,7 @@ public:
}
if(!mMultiSelect)
{
if(config->isMappedTo("left", input))
if(config->isMappedLike("left", input))
{
// move selection to previous
unsigned int i = getSelectedId();
@ -203,7 +203,7 @@ public:
onSelectedChanged();
return true;
}else if(config->isMappedTo("right", input))
}else if(config->isMappedLike("right", input))
{
// move selection to next
unsigned int i = getSelectedId();

View file

@ -22,7 +22,7 @@ SliderComponent::SliderComponent(Window* window, float min, float max, float inc
bool SliderComponent::input(InputConfig* config, Input input)
{
if(config->isMappedTo("left", input))
if(config->isMappedLike("left", input))
{
if(input.value)
setValue(mValue - mSingleIncrement);
@ -31,7 +31,7 @@ bool SliderComponent::input(InputConfig* config, Input input)
mMoveAccumulator = -MOVE_REPEAT_DELAY;
return true;
}
if(config->isMappedTo("right", input))
if(config->isMappedLike("right", input))
{
if(input.value)
setValue(mValue + mSingleIncrement);

View file

@ -90,9 +90,9 @@ void TextEditComponent::stopEditing()
bool TextEditComponent::input(InputConfig* config, Input input)
{
bool const cursor_left = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("left", input)) ||
bool const cursor_left = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("left", input)) ||
(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_LEFT);
bool const cursor_right = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("right", input)) ||
bool const cursor_right = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("right", input)) ||
(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_RIGHT);
if(input.value == 0)
@ -129,10 +129,10 @@ bool TextEditComponent::input(InputConfig* config, Input input)
return true;
}
if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("up", input))
if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("up", input))
{
// TODO
}else if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("down", input))
}else if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("down", input))
{
// TODO
}else if(cursor_left || cursor_right)