2013-08-16 14:48:43 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2014-09-05 21:21:07 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <deque>
|
|
|
|
|
2016-09-11 16:59:06 +00:00
|
|
|
#include "base/mutex.h"
|
2014-09-05 21:21:07 +00:00
|
|
|
#include "base/colorutil.h"
|
2013-08-16 14:48:43 +00:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "i18n/i18n.h"
|
|
|
|
#include "input/keycodes.h"
|
|
|
|
#include "input/input_state.h"
|
|
|
|
#include "ui/ui.h"
|
|
|
|
#include "ui/ui_context.h"
|
2013-08-17 08:34:38 +00:00
|
|
|
#include "ui/view.h"
|
|
|
|
#include "ui/viewgroup.h"
|
2013-08-16 14:48:43 +00:00
|
|
|
|
|
|
|
#include "Core/HLE/sceCtrl.h"
|
2013-09-07 15:29:44 +00:00
|
|
|
#include "Core/System.h"
|
2013-08-16 14:48:43 +00:00
|
|
|
#include "Common/KeyMap.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "UI/ui_atlas.h"
|
|
|
|
#include "UI/ControlMappingScreen.h"
|
2013-09-24 17:37:25 +00:00
|
|
|
#include "UI/GameSettingsScreen.h"
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
class ControlMapper : public UI::LinearLayout {
|
|
|
|
public:
|
2014-06-08 13:38:13 +00:00
|
|
|
ControlMapper(ControlMappingScreen *ctrlScreen, int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = 0);
|
2013-08-17 08:34:38 +00:00
|
|
|
|
|
|
|
virtual void Update(const InputState &input);
|
2014-06-08 13:38:13 +00:00
|
|
|
int GetPspKey() const { return pspKey_; }
|
2013-08-17 08:34:38 +00:00
|
|
|
private:
|
|
|
|
void Refresh();
|
|
|
|
|
|
|
|
UI::EventReturn OnAdd(UI::EventParams ¶ms);
|
|
|
|
UI::EventReturn OnDelete(UI::EventParams ¶ms);
|
|
|
|
UI::EventReturn OnReplace(UI::EventParams ¶ms);
|
|
|
|
UI::EventReturn OnReplaceAll(UI::EventParams ¶ms);
|
|
|
|
|
|
|
|
void MappedCallback(KeyDef key);
|
|
|
|
|
|
|
|
enum Action {
|
|
|
|
NONE,
|
|
|
|
REPLACEONE,
|
|
|
|
REPLACEALL,
|
|
|
|
ADD,
|
|
|
|
};
|
|
|
|
|
2014-06-08 13:38:13 +00:00
|
|
|
ControlMappingScreen *ctrlScreen_;
|
2013-08-17 08:34:38 +00:00
|
|
|
Action action_;
|
|
|
|
int actionIndex_;
|
|
|
|
int pspKey_;
|
|
|
|
std::string keyName_;
|
|
|
|
ScreenManager *scrm_;
|
|
|
|
bool refresh_;
|
|
|
|
};
|
|
|
|
|
2014-06-08 13:38:13 +00:00
|
|
|
ControlMapper::ControlMapper(ControlMappingScreen *ctrlScreen, int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams)
|
|
|
|
: UI::LinearLayout(UI::ORIENT_VERTICAL, layoutParams), ctrlScreen_(ctrlScreen), action_(NONE), pspKey_(pspKey), keyName_(keyName), scrm_(scrm), refresh_(false) {
|
2013-08-17 08:34:38 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlMapper::Update(const InputState &input) {
|
|
|
|
if (refresh_) {
|
|
|
|
refresh_ = false;
|
|
|
|
Refresh();
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
void ControlMapper::Refresh() {
|
2014-06-08 13:38:13 +00:00
|
|
|
bool hasFocus = UI::GetFocusedView() == this;
|
2013-08-17 08:34:38 +00:00
|
|
|
Clear();
|
2013-12-06 15:45:25 +00:00
|
|
|
I18NCategory *mc = GetI18NCategory("MappableControls");
|
2013-08-30 14:01:17 +00:00
|
|
|
|
|
|
|
std::map<std::string, int> keyImages;
|
|
|
|
keyImages["Circle"] = I_CIRCLE;
|
|
|
|
keyImages["Cross"] = I_CROSS;
|
|
|
|
keyImages["Square"] = I_SQUARE;
|
|
|
|
keyImages["Triangle"] = I_TRIANGLE;
|
|
|
|
keyImages["Start"] = I_START;
|
|
|
|
keyImages["Select"] = I_SELECT;
|
|
|
|
keyImages["L"] = I_L;
|
|
|
|
keyImages["R"] = I_R;
|
2013-08-17 08:34:38 +00:00
|
|
|
|
|
|
|
using namespace UI;
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-12-06 15:45:25 +00:00
|
|
|
float itemH = 45;
|
|
|
|
|
2014-06-09 20:26:23 +00:00
|
|
|
LinearLayout *root = Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(550, WRAP_CONTENT)));
|
2013-12-06 15:45:25 +00:00
|
|
|
root->SetSpacing(3.0f);
|
|
|
|
|
|
|
|
const int padding = 4;
|
2013-08-30 14:01:17 +00:00
|
|
|
|
|
|
|
auto iter = keyImages.find(keyName_);
|
|
|
|
// First, look among images.
|
|
|
|
if (iter != keyImages.end()) {
|
2013-12-06 15:45:25 +00:00
|
|
|
Choice *c = root->Add(new Choice(iter->second, new LinearLayoutParams(200, itemH)));
|
|
|
|
c->OnClick.Handle(this, &ControlMapper::OnReplaceAll);
|
2013-08-30 14:01:17 +00:00
|
|
|
} else {
|
|
|
|
// No image? Let's translate.
|
2013-12-06 15:45:25 +00:00
|
|
|
Choice *c = new Choice(mc->T(keyName_.c_str()), new LinearLayoutParams(200, itemH));
|
|
|
|
c->SetCentered(true);
|
|
|
|
root->Add(c)->OnClick.Handle(this, &ControlMapper::OnReplaceAll);
|
2013-08-30 14:01:17 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 03:40:44 +00:00
|
|
|
Choice *p = root->Add(new Choice(" + ", new LayoutParams(WRAP_CONTENT, itemH)));
|
2014-06-09 20:26:23 +00:00
|
|
|
p->OnClick.Handle(this, &ControlMapper::OnAdd);
|
|
|
|
|
2013-12-06 15:45:25 +00:00
|
|
|
LinearLayout *rightColumn = root->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)));
|
2013-08-20 13:40:19 +00:00
|
|
|
rightColumn->SetSpacing(2.0f);
|
2013-08-17 08:34:38 +00:00
|
|
|
std::vector<KeyDef> mappings;
|
|
|
|
KeyMap::KeyFromPspButton(pspKey_, &mappings);
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
for (size_t i = 0; i < mappings.size(); i++) {
|
|
|
|
std::string deviceName = GetDeviceName(mappings[i].deviceId);
|
2013-08-17 09:18:45 +00:00
|
|
|
std::string keyName = KeyMap::GetKeyOrAxisName(mappings[i].keyCode);
|
2013-08-17 08:34:38 +00:00
|
|
|
int image = -1;
|
|
|
|
|
|
|
|
LinearLayout *row = rightColumn->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2013-12-06 15:45:25 +00:00
|
|
|
row->SetSpacing(1.0f);
|
2013-08-17 08:34:38 +00:00
|
|
|
|
2013-12-06 15:45:25 +00:00
|
|
|
Choice *c = row->Add(new Choice(deviceName + "." + keyName, new LinearLayoutParams(FILL_PARENT, itemH, 1.0f)));
|
2013-08-17 11:26:19 +00:00
|
|
|
char tagbuf[16];
|
2013-08-20 17:20:03 +00:00
|
|
|
sprintf(tagbuf, "%i", (int)i);
|
2013-08-17 11:26:19 +00:00
|
|
|
c->SetTag(tagbuf);
|
2013-08-17 08:34:38 +00:00
|
|
|
c->OnClick.Handle(this, &ControlMapper::OnReplace);
|
2013-08-20 17:20:03 +00:00
|
|
|
|
2016-08-16 03:40:44 +00:00
|
|
|
Choice *d = row->Add(new Choice(" X ", new LayoutParams(WRAP_CONTENT, itemH)));
|
2013-08-17 11:26:19 +00:00
|
|
|
d->SetTag(tagbuf);
|
2013-08-17 08:34:38 +00:00
|
|
|
d->OnClick.Handle(this, &ControlMapper::OnDelete);
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
if (mappings.size() == 0) {
|
|
|
|
// look like an empty line
|
2013-12-06 15:45:25 +00:00
|
|
|
Choice *c = rightColumn->Add(new Choice("", new LinearLayoutParams(FILL_PARENT, itemH)));
|
|
|
|
c->OnClick.Handle(this, &ControlMapper::OnAdd);
|
2013-08-17 08:34:38 +00:00
|
|
|
}
|
2014-06-08 13:38:13 +00:00
|
|
|
|
|
|
|
if (hasFocus)
|
|
|
|
this->SetFocus();
|
2013-08-17 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlMapper::MappedCallback(KeyDef kdf) {
|
|
|
|
switch (action_) {
|
2013-08-17 09:18:45 +00:00
|
|
|
case ADD:
|
|
|
|
KeyMap::SetKeyMapping(pspKey_, kdf, false);
|
|
|
|
break;
|
2013-08-17 08:34:38 +00:00
|
|
|
case REPLACEALL:
|
|
|
|
KeyMap::SetKeyMapping(pspKey_, kdf, true);
|
|
|
|
break;
|
|
|
|
case REPLACEONE:
|
|
|
|
KeyMap::g_controllerMap[pspKey_][actionIndex_] = kdf;
|
|
|
|
break;
|
2013-08-17 11:26:19 +00:00
|
|
|
default:
|
|
|
|
;
|
2013-08-17 08:34:38 +00:00
|
|
|
}
|
|
|
|
refresh_ = true;
|
2014-06-08 13:38:13 +00:00
|
|
|
ctrlScreen_->KeyMapped(pspKey_);
|
|
|
|
// After this, we do not exist any more. So the refresh_ = true is probably irrelevant.
|
2013-08-17 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ControlMapper::OnReplace(UI::EventParams ¶ms) {
|
|
|
|
actionIndex_ = atoi(params.v->Tag().c_str());
|
|
|
|
action_ = REPLACEONE;
|
2016-10-12 09:32:24 +00:00
|
|
|
scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&ControlMapper::MappedCallback, this, std::placeholders::_1)));
|
2013-08-17 08:34:38 +00:00
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ControlMapper::OnReplaceAll(UI::EventParams ¶ms) {
|
|
|
|
action_ = REPLACEALL;
|
2016-10-12 09:32:24 +00:00
|
|
|
scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&ControlMapper::MappedCallback, this, std::placeholders::_1)));
|
2013-08-17 08:34:38 +00:00
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ControlMapper::OnAdd(UI::EventParams ¶ms) {
|
2013-08-17 09:18:45 +00:00
|
|
|
action_ = ADD;
|
2016-10-12 09:32:24 +00:00
|
|
|
scrm_->push(new KeyMappingNewKeyDialog(pspKey_, true, std::bind(&ControlMapper::MappedCallback, this, std::placeholders::_1)));
|
2013-08-17 08:34:38 +00:00
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI::EventReturn ControlMapper::OnDelete(UI::EventParams ¶ms) {
|
2013-08-17 09:18:45 +00:00
|
|
|
int index = atoi(params.v->Tag().c_str());
|
|
|
|
KeyMap::g_controllerMap[pspKey_].erase(KeyMap::g_controllerMap[pspKey_].begin() + index);
|
2013-08-17 08:34:38 +00:00
|
|
|
refresh_ = true;
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlMappingScreen::CreateViews() {
|
|
|
|
using namespace UI;
|
2014-06-08 13:38:13 +00:00
|
|
|
mappers_.clear();
|
2013-08-17 08:34:38 +00:00
|
|
|
|
2015-07-01 21:54:35 +00:00
|
|
|
I18NCategory *km = GetI18NCategory("KeyMapping");
|
2013-08-17 08:34:38 +00:00
|
|
|
|
|
|
|
root_ = new LinearLayout(ORIENT_HORIZONTAL);
|
|
|
|
|
2015-07-04 15:01:32 +00:00
|
|
|
LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT, Margins(10, 0, 0, 10)));
|
2015-07-01 21:54:35 +00:00
|
|
|
leftColumn->Add(new Choice(km->T("Clear All")))->OnClick.Handle(this, &ControlMappingScreen::OnClearMapping);
|
|
|
|
leftColumn->Add(new Choice(km->T("Default All")))->OnClick.Handle(this, &ControlMappingScreen::OnDefaultMapping);
|
2015-10-04 11:25:22 +00:00
|
|
|
|
|
|
|
std::string sysName = System_GetProperty(SYSPROP_NAME);
|
|
|
|
// If there's a builtin controller, restore to default should suffice. No need to conf the controller on top.
|
|
|
|
if (!KeyMap::HasBuiltinController(sysName) && KeyMap::GetSeenPads().size()) {
|
2015-07-01 21:54:35 +00:00
|
|
|
leftColumn->Add(new Choice(km->T("Autoconfigure")))->OnClick.Handle(this, &ControlMappingScreen::OnAutoConfigure);
|
2014-05-19 21:29:35 +00:00
|
|
|
}
|
2015-07-01 21:54:35 +00:00
|
|
|
leftColumn->Add(new Choice(km->T("Test Analogs")))->OnClick.Handle(this, &ControlMappingScreen::OnTestAnalogs);
|
2013-08-17 08:34:38 +00:00
|
|
|
leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f)));
|
2015-07-04 15:01:32 +00:00
|
|
|
AddStandardBack(leftColumn);
|
2013-12-02 14:15:19 +00:00
|
|
|
|
2014-06-08 13:38:13 +00:00
|
|
|
rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
|
2016-01-23 06:52:13 +00:00
|
|
|
rightScroll_->SetTag("ControlMapping");
|
2014-06-08 13:38:13 +00:00
|
|
|
rightScroll_->SetScrollToTop(false);
|
2013-08-17 08:34:38 +00:00
|
|
|
LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
|
2014-06-08 13:38:13 +00:00
|
|
|
rightScroll_->Add(rightColumn);
|
2013-08-17 08:34:38 +00:00
|
|
|
|
|
|
|
root_->Add(leftColumn);
|
2014-06-08 13:38:13 +00:00
|
|
|
root_->Add(rightScroll_);
|
2013-08-17 08:34:38 +00:00
|
|
|
|
|
|
|
std::vector<KeyMap::KeyMap_IntStrPair> mappableKeys = KeyMap::GetMappableKeys();
|
|
|
|
for (size_t i = 0; i < mappableKeys.size(); i++) {
|
2014-06-08 13:38:13 +00:00
|
|
|
ControlMapper *mapper = rightColumn->Add(new ControlMapper(this, mappableKeys[i].key, mappableKeys[i].name, screenManager(), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
|
|
|
mappers_.push_back(mapper);
|
2013-08-17 08:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-14 05:53:28 +00:00
|
|
|
void ControlMappingScreen::sendMessage(const char *message, const char *value) {
|
2013-10-21 20:52:44 +00:00
|
|
|
// Always call the base class method first to handle the most common messages.
|
|
|
|
UIDialogScreenWithBackground::sendMessage(message, value);
|
|
|
|
|
2013-09-24 05:03:59 +00:00
|
|
|
if (!strcmp(message, "settings")) {
|
|
|
|
UpdateUIState(UISTATE_MENU);
|
2013-09-24 17:37:25 +00:00
|
|
|
screenManager()->push(new GameSettingsScreen(""));
|
2013-09-24 05:03:59 +00:00
|
|
|
}
|
2013-09-14 05:53:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
UI::EventReturn ControlMappingScreen::OnClearMapping(UI::EventParams ¶ms) {
|
|
|
|
KeyMap::g_controllerMap.clear();
|
2013-08-17 22:41:19 +00:00
|
|
|
RecreateViews();
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
2013-08-17 08:34:38 +00:00
|
|
|
|
2013-08-17 22:41:19 +00:00
|
|
|
UI::EventReturn ControlMappingScreen::OnDefaultMapping(UI::EventParams ¶ms) {
|
|
|
|
KeyMap::RestoreDefault();
|
2013-08-17 08:34:38 +00:00
|
|
|
RecreateViews();
|
|
|
|
return UI::EVENT_DONE;
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 21:29:35 +00:00
|
|
|
UI::EventReturn ControlMappingScreen::OnAutoConfigure(UI::EventParams ¶ms) {
|
|
|
|
std::vector<std::string> items;
|
2014-05-21 15:40:00 +00:00
|
|
|
const auto seenPads = KeyMap::GetSeenPads();
|
|
|
|
for (auto s = seenPads.begin(), end = seenPads.end(); s != end; ++s) {
|
|
|
|
items.push_back(*s);
|
2014-05-19 21:29:35 +00:00
|
|
|
}
|
2015-07-01 21:54:35 +00:00
|
|
|
I18NCategory *km = GetI18NCategory("KeyMapping");
|
|
|
|
ListPopupScreen *autoConfList = new ListPopupScreen(km->T("Autoconfigure for device"), items, -1);
|
2014-05-19 21:29:35 +00:00
|
|
|
screenManager()->push(autoConfList);
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:21:07 +00:00
|
|
|
UI::EventReturn ControlMappingScreen::OnTestAnalogs(UI::EventParams ¶ms) {
|
|
|
|
screenManager()->push(new AnalogTestScreen());
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2014-05-19 21:29:35 +00:00
|
|
|
void ControlMappingScreen::dialogFinished(const Screen *dialog, DialogResult result) {
|
|
|
|
if (result == DR_OK && dialog->tag() == "listpopup") {
|
|
|
|
ListPopupScreen *popup = (ListPopupScreen *)dialog;
|
|
|
|
KeyMap::AutoConfForPad(popup->GetChoiceString());
|
|
|
|
RecreateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 13:38:13 +00:00
|
|
|
void ControlMappingScreen::KeyMapped(int pspkey) { // Notification to let us refocus the same one after recreating views.
|
2014-06-15 17:01:54 +00:00
|
|
|
for (size_t i = 0; i < mappers_.size(); i++) {
|
2014-06-08 13:38:13 +00:00
|
|
|
if (mappers_[i]->GetPspKey() == pspkey)
|
|
|
|
SetFocusedView(mappers_[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:16:11 +00:00
|
|
|
void KeyMappingNewKeyDialog::CreatePopupContents(UI::ViewGroup *parent) {
|
|
|
|
using namespace UI;
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2015-07-01 21:54:35 +00:00
|
|
|
I18NCategory *km = GetI18NCategory("KeyMapping");
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-08-16 15:16:11 +00:00
|
|
|
std::string pspButtonName = KeyMap::GetPspButtonName(this->pspBtn_);
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2015-07-01 21:54:35 +00:00
|
|
|
parent->Add(new TextView(std::string(km->T("Map a new key for")) + " " + pspButtonName, new LinearLayoutParams(Margins(10,0))));
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 11:04:59 +00:00
|
|
|
bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
|
2014-06-08 13:38:13 +00:00
|
|
|
if (mapped_)
|
2014-06-15 11:04:59 +00:00
|
|
|
return false;
|
2013-08-16 14:48:43 +00:00
|
|
|
if (key.flags & KEY_DOWN) {
|
2013-08-16 15:16:11 +00:00
|
|
|
if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1) {
|
2014-06-15 11:04:59 +00:00
|
|
|
return true;
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
2013-08-19 22:49:25 +00:00
|
|
|
|
2014-06-08 13:38:13 +00:00
|
|
|
mapped_ = true;
|
2013-08-17 08:34:38 +00:00
|
|
|
KeyDef kdf(key.deviceId, key.keyCode);
|
2013-08-16 15:16:11 +00:00
|
|
|
screenManager()->finishDialog(this, DR_OK);
|
2013-08-17 08:34:38 +00:00
|
|
|
if (callback_)
|
|
|
|
callback_(kdf);
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
2014-06-15 11:04:59 +00:00
|
|
|
return true;
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 16:47:21 +00:00
|
|
|
static bool IgnoreAxisForMapping(int axis) {
|
|
|
|
switch (axis) {
|
|
|
|
// Ignore the accelerometer for mapping for now.
|
2014-01-06 22:58:59 +00:00
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_X:
|
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_Y:
|
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_Z:
|
2016-09-11 16:47:21 +00:00
|
|
|
return true;
|
2014-01-06 23:01:41 +00:00
|
|
|
|
2016-09-11 16:47:21 +00:00
|
|
|
// Also ignore some weird axis events we get on Ouya.
|
2014-01-06 23:01:41 +00:00
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN1:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN2:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN3:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN4:
|
2016-09-11 16:47:21 +00:00
|
|
|
return true;
|
2014-01-06 23:01:41 +00:00
|
|
|
|
2014-01-06 22:58:59 +00:00
|
|
|
default:
|
2016-09-11 16:47:21 +00:00
|
|
|
return false;
|
2014-01-06 22:58:59 +00:00
|
|
|
}
|
2016-09-11 16:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
|
|
|
|
if (mapped_)
|
|
|
|
return false;
|
|
|
|
if (IgnoreAxisForMapping(axis.axisId))
|
|
|
|
return false;
|
2014-01-06 22:58:59 +00:00
|
|
|
|
2013-08-16 14:48:43 +00:00
|
|
|
if (axis.value > AXIS_BIND_THRESHOLD) {
|
2014-06-08 13:38:13 +00:00
|
|
|
mapped_ = true;
|
2013-08-17 08:34:38 +00:00
|
|
|
KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, 1));
|
2013-08-16 15:16:11 +00:00
|
|
|
screenManager()->finishDialog(this, DR_OK);
|
2013-08-17 08:34:38 +00:00
|
|
|
if (callback_)
|
|
|
|
callback_(kdf);
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
2013-08-16 15:16:11 +00:00
|
|
|
|
2013-08-16 14:48:43 +00:00
|
|
|
if (axis.value < -AXIS_BIND_THRESHOLD) {
|
2014-06-08 13:38:13 +00:00
|
|
|
mapped_ = true;
|
2013-08-17 08:34:38 +00:00
|
|
|
KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, -1));
|
2013-08-16 14:48:43 +00:00
|
|
|
screenManager()->finishDialog(this, DR_OK);
|
2013-08-17 08:34:38 +00:00
|
|
|
if (callback_)
|
|
|
|
callback_(kdf);
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
2014-06-15 11:04:59 +00:00
|
|
|
return true;
|
2013-08-16 14:48:43 +00:00
|
|
|
}
|
2014-09-05 21:21:07 +00:00
|
|
|
|
|
|
|
class JoystickHistoryView : public UI::InertView {
|
|
|
|
public:
|
2017-02-19 13:33:59 +00:00
|
|
|
JoystickHistoryView(int xAxis, int xDevice, int xDir, int yAxis, int yDevice, int yDir, UI::LayoutParams *layoutParams = nullptr)
|
2014-09-05 21:21:07 +00:00
|
|
|
: UI::InertView(layoutParams),
|
2017-02-19 13:33:59 +00:00
|
|
|
xAxis_(xAxis), xDevice_(xDevice), xDir_(xDir),
|
|
|
|
yAxis_(yAxis), yDevice_(yDevice), yDir_(xDir),
|
2014-09-05 21:21:07 +00:00
|
|
|
curX_(0.0f), curY_(0.0f),
|
|
|
|
maxCount_(500) {}
|
2014-09-09 20:28:35 +00:00
|
|
|
void Draw(UIContext &dc) override;
|
|
|
|
void Update(const InputState &input_state) override;
|
2016-05-21 15:18:08 +00:00
|
|
|
void Axis(const AxisInput &input) override {
|
|
|
|
// TODO: Check input.deviceId?
|
2014-09-09 20:28:35 +00:00
|
|
|
if (input.axisId == xAxis_) {
|
2017-02-19 13:33:59 +00:00
|
|
|
curX_ = input.value * xDir_;
|
2014-09-09 20:28:35 +00:00
|
|
|
} else if (input.axisId == yAxis_) {
|
2017-02-19 13:33:59 +00:00
|
|
|
curY_ = input.value * yDir_;
|
2014-09-09 20:28:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Location {
|
|
|
|
Location() : x(0.0f), y(0.0f) {}
|
|
|
|
Location(float xx, float yy) : x(xx), y(yy) {}
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
|
|
|
|
|
|
|
int xAxis_;
|
|
|
|
int xDevice_;
|
2017-02-19 13:33:59 +00:00
|
|
|
int xDir_;
|
2015-09-17 18:29:37 +00:00
|
|
|
int yAxis_;
|
2014-09-09 20:28:35 +00:00
|
|
|
int yDevice_;
|
2017-02-19 13:33:59 +00:00
|
|
|
int yDir_;
|
2014-09-09 20:28:35 +00:00
|
|
|
|
|
|
|
float curX_;
|
|
|
|
float curY_;
|
|
|
|
|
|
|
|
std::deque<Location> locations_;
|
|
|
|
int maxCount_;
|
2014-09-05 21:21:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void JoystickHistoryView::Draw(UIContext &dc) {
|
|
|
|
if (xAxis_ > -1 && yAxis_ > -1) {
|
|
|
|
const AtlasImage &image = dc.Draw()->GetAtlas()->images[I_CROSS];
|
|
|
|
float minRadius = std::min(bounds_.w, bounds_.h) * 0.5f - image.w;
|
|
|
|
|
|
|
|
int a = maxCount_ - (int)locations_.size();
|
|
|
|
for (auto iter = locations_.begin(); iter != locations_.end(); ++iter) {
|
|
|
|
float x = bounds_.centerX() + minRadius * iter->x;
|
|
|
|
float y = bounds_.centerY() - minRadius * iter->y;
|
|
|
|
float alpha = (float)a / maxCount_;
|
|
|
|
if (alpha < 0.0f) alpha = 0.0f;
|
|
|
|
dc.Draw()->DrawImage(I_CROSS, x, y, 0.8f, colorAlpha(0xFFFFFF, alpha), ALIGN_CENTER);
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
dc.End();
|
|
|
|
dc.BeginNoTex();
|
|
|
|
dc.Draw()->RectOutline(bounds_.centerX() - minRadius, bounds_.centerY() - minRadius, minRadius * 2, minRadius * 2, 0x80FFFFFF);
|
|
|
|
dc.End();
|
|
|
|
dc.Begin();
|
|
|
|
} else {
|
|
|
|
dc.DrawText("N/A", bounds_.centerX(), bounds_.centerY(), 0xFFFFFFFF, ALIGN_CENTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JoystickHistoryView::Update(const InputState &input_state) {
|
|
|
|
locations_.push_back(Location(curX_, curY_));
|
2014-10-12 16:48:47 +00:00
|
|
|
if ((int)locations_.size() > maxCount_) {
|
2014-09-05 21:21:07 +00:00
|
|
|
locations_.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 16:55:15 +00:00
|
|
|
bool AnalogTestScreen::key(const KeyInput &key) {
|
2015-09-17 20:46:59 +00:00
|
|
|
bool retval = true;
|
|
|
|
if (UI::IsEscapeKey(key)) {
|
|
|
|
screenManager()->finishDialog(this, DR_BACK);
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-11 16:59:06 +00:00
|
|
|
|
2015-01-03 16:55:15 +00:00
|
|
|
char buf[512];
|
|
|
|
snprintf(buf, sizeof(buf), "Keycode: %d Device ID: %d [%s%s%s%s]", key.keyCode, key.deviceId,
|
|
|
|
(key.flags & KEY_IS_REPEAT) ? "REP" : "",
|
|
|
|
(key.flags & KEY_UP) ? "UP" : "",
|
|
|
|
(key.flags & KEY_DOWN) ? "DOWN" : "",
|
|
|
|
(key.flags & KEY_CHAR) ? "CHAR" : "");
|
2016-09-11 16:47:21 +00:00
|
|
|
if (lastLastKeyEvent_ && lastKeyEvent_) {
|
|
|
|
lastLastKeyEvent_->SetText(lastKeyEvent_->GetText());
|
|
|
|
lastKeyEvent_->SetText(buf);
|
|
|
|
}
|
2015-09-17 20:46:59 +00:00
|
|
|
return retval;
|
2015-01-03 16:55:15 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 23:22:45 +00:00
|
|
|
bool AnalogTestScreen::axis(const AxisInput &axis) {
|
2015-09-07 20:25:38 +00:00
|
|
|
UIScreen::axis(axis);
|
2015-08-27 23:22:45 +00:00
|
|
|
// This is mainly to catch axis events that would otherwise get translated
|
|
|
|
// into arrow keys, since seeing keyboard arrow key events appear when using
|
|
|
|
// a controller would be confusing for the user.
|
|
|
|
char buf[512];
|
2016-09-11 16:47:21 +00:00
|
|
|
|
|
|
|
if (IgnoreAxisForMapping(axis.axisId))
|
|
|
|
return false;
|
|
|
|
|
2015-08-27 23:22:45 +00:00
|
|
|
if (axis.value > AXIS_BIND_THRESHOLD || axis.value < -AXIS_BIND_THRESHOLD) {
|
|
|
|
snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d",
|
|
|
|
axis.axisId, axis.value, axis.deviceId);
|
2016-09-11 16:47:21 +00:00
|
|
|
// Null-check just in case they weren't created yet.
|
|
|
|
if (lastLastKeyEvent_ && lastKeyEvent_) {
|
|
|
|
lastLastKeyEvent_->SetText(lastKeyEvent_->GetText());
|
|
|
|
lastKeyEvent_->SetText(buf);
|
|
|
|
}
|
2015-08-27 23:22:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:21:07 +00:00
|
|
|
void AnalogTestScreen::CreateViews() {
|
2015-01-03 16:55:15 +00:00
|
|
|
using namespace UI;
|
|
|
|
|
2015-07-01 21:26:55 +00:00
|
|
|
I18NCategory *di = GetI18NCategory("Dialog");
|
2015-01-04 01:01:05 +00:00
|
|
|
|
2015-01-03 16:55:15 +00:00
|
|
|
root_ = new LinearLayout(ORIENT_VERTICAL);
|
2014-09-05 21:21:07 +00:00
|
|
|
|
2015-01-03 16:55:15 +00:00
|
|
|
LinearLayout *theTwo = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(1.0f));
|
2014-09-05 21:21:07 +00:00
|
|
|
|
|
|
|
int axis1, device1, dir1;
|
|
|
|
int axis2, device2, dir2;
|
|
|
|
|
|
|
|
if (!KeyMap::AxisFromPspButton(VIRTKEY_AXIS_X_MAX, &device1, &axis1, &dir1)) axis1 = -1;
|
|
|
|
if (!KeyMap::AxisFromPspButton(VIRTKEY_AXIS_Y_MAX, &device2, &axis2, &dir2)) axis2 = -1;
|
|
|
|
|
2017-02-19 13:33:59 +00:00
|
|
|
theTwo->Add(new JoystickHistoryView(axis1, device1, dir1, axis2, device2, dir2, new LinearLayoutParams(1.0f)));
|
2014-09-05 21:21:07 +00:00
|
|
|
|
|
|
|
if (!KeyMap::AxisFromPspButton(VIRTKEY_AXIS_RIGHT_X_MAX, &device1, &axis1, &dir1)) axis1 = -1;
|
|
|
|
if (!KeyMap::AxisFromPspButton(VIRTKEY_AXIS_RIGHT_Y_MAX, &device2, &axis2, &dir2)) axis2 = -1;
|
|
|
|
|
2017-02-19 13:33:59 +00:00
|
|
|
theTwo->Add(new JoystickHistoryView(axis1, device1, dir1, axis2, device2, dir2, new LinearLayoutParams(1.0f)));
|
2014-09-05 21:21:07 +00:00
|
|
|
|
|
|
|
root_->Add(theTwo);
|
|
|
|
|
2015-09-17 20:46:59 +00:00
|
|
|
lastLastKeyEvent_ = root_->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
|
|
|
lastLastKeyEvent_->SetTextColor(0x80FFFFFF); // semi-transparent
|
|
|
|
lastKeyEvent_ = root_->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
2015-01-03 16:55:15 +00:00
|
|
|
|
2015-07-01 21:26:55 +00:00
|
|
|
root_->Add(new Button(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
|
2014-09-05 21:21:07 +00:00
|
|
|
}
|