Skip to content

Commit

Permalink
Merge pull request #18589 from hrydgard/organize-bindings
Browse files Browse the repository at this point in the history
Control Mappings: Organize bindings into categories
  • Loading branch information
hrydgard committed Dec 20, 2023
2 parents eff01d1 + 607f272 commit e40ec0c
Show file tree
Hide file tree
Showing 50 changed files with 246 additions and 16 deletions.
10 changes: 10 additions & 0 deletions Common/UI/View.cpp
Expand Up @@ -182,6 +182,16 @@ Point View::GetFocusPosition(FocusDirection dir) const {
}
}

Point CollapsibleHeader::GetFocusPosition(FocusDirection dir) const {
// Bias the focus position to the left.
switch (dir) {
case FOCUS_UP: return Point(bounds_.x + 50, bounds_.y + 2);
case FOCUS_DOWN: return Point(bounds_.x + 50, bounds_.y2() - 2);
default:
return View::GetFocusPosition(dir);
}
}

bool View::SetFocus() {
if (IsFocusMovementEnabled()) {
if (CanBeFocused()) {
Expand Down
4 changes: 3 additions & 1 deletion Common/UI/View.h
Expand Up @@ -468,7 +468,7 @@ class View {
virtual bool IsViewGroup() const { return false; }
virtual bool ContainsSubview(const View *view) const { return false; }

Point GetFocusPosition(FocusDirection dir) const;
virtual Point GetFocusPosition(FocusDirection dir) const;

template <class T>
T *AddTween(T *t) {
Expand Down Expand Up @@ -871,6 +871,8 @@ class CollapsibleHeader : public CheckBox {
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;

Point GetFocusPosition(FocusDirection dir) const override;

void SetHasSubitems(bool hasSubItems) { hasSubItems_ = hasSubItems; }
private:
bool hasSubItems_ = true;
Expand Down
10 changes: 7 additions & 3 deletions Common/UI/ViewGroup.cpp
Expand Up @@ -1186,9 +1186,7 @@ CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *l
heading_->OnClick.Add([=](UI::EventParams &) {
// Change the visibility of all children except the first one.
// Later maybe try something more ambitious.
for (size_t i = 1; i < views_.size(); i++) {
views_[i]->SetVisibility(open_ ? V_VISIBLE : V_GONE);
}
UpdateVisibility();
return UI::EVENT_DONE;
});
}
Expand All @@ -1198,4 +1196,10 @@ void CollapsibleSection::Update() {
heading_->SetHasSubitems(views_.size() > 1);
}

void CollapsibleSection::UpdateVisibility() {
for (size_t i = 1; i < views_.size(); i++) {
views_[i]->SetVisibility(open_ ? V_VISIBLE : V_GONE);
}
}

} // namespace UI
6 changes: 6 additions & 0 deletions Common/UI/ViewGroup.h
Expand Up @@ -327,7 +327,13 @@ class CollapsibleSection : public LinearLayout {

void Update() override;

void SetOpen(bool open) {
open_ = open;
UpdateVisibility();
}

private:
void UpdateVisibility();
bool open_ = true;
CollapsibleHeader *heading_;
};
Expand Down
18 changes: 10 additions & 8 deletions Core/KeyMap.cpp
Expand Up @@ -399,9 +399,13 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_AXIS_Y_MIN, "An.Down"},
{VIRTKEY_AXIS_X_MIN, "An.Left"},
{VIRTKEY_AXIS_X_MAX, "An.Right"},
{VIRTKEY_ANALOG_LIGHTLY, "Analog limiter"},

{VIRTKEY_ANALOG_ROTATE_CW, "Rotate Analog (CW)"},
{VIRTKEY_ANALOG_ROTATE_CCW, "Rotate Analog (CCW)"},
{VIRTKEY_ANALOG_LIGHTLY, "Analog limiter"},
{VIRTKEY_RAPID_FIRE, "RapidFire"},
{VIRTKEY_AXIS_SWAP, "AxisSwap"},

{VIRTKEY_FASTFORWARD, "Fast-forward"},
{VIRTKEY_SPEED_TOGGLE, "SpeedToggle"},
{VIRTKEY_SPEED_CUSTOM1, "Alt speed 1"},
Expand All @@ -421,20 +425,13 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_TOGGLE_FULLSCREEN, "Toggle Fullscreen"},
#endif

{VIRTKEY_AXIS_RIGHT_Y_MAX, "RightAn.Up"},
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
{VIRTKEY_AXIS_RIGHT_X_MIN, "RightAn.Left"},
{VIRTKEY_AXIS_RIGHT_X_MAX, "RightAn.Right"},
{VIRTKEY_OPENCHAT, "OpenChat" },

{VIRTKEY_AXIS_SWAP, "AxisSwap"},
{VIRTKEY_DEVMENU, "DevMenu"},
{VIRTKEY_TEXTURE_DUMP, "Texture Dumping"},
{VIRTKEY_TEXTURE_REPLACE, "Texture Replacement"},
{VIRTKEY_SCREENSHOT, "Screenshot"},
{VIRTKEY_MUTE_TOGGLE, "Mute toggle"},
{VIRTKEY_ANALOG_ROTATE_CW, "Rotate Analog (CW)"},
{VIRTKEY_ANALOG_ROTATE_CCW, "Rotate Analog (CCW)"},

#ifdef OPENXR
{VIRTKEY_VR_CAMERA_ADJUST, "VR camera adjust"},
Expand All @@ -449,6 +446,11 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_TOGGLE_WLAN, "Toggle WLAN"},
{VIRTKEY_EXIT_APP, "Exit App"},

{VIRTKEY_AXIS_RIGHT_Y_MAX, "RightAn.Up"},
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
{VIRTKEY_AXIS_RIGHT_X_MIN, "RightAn.Left"},
{VIRTKEY_AXIS_RIGHT_X_MAX, "RightAn.Right"},

{CTRL_HOME, "Home"},
{CTRL_HOLD, "Hold"},
{CTRL_WLAN, "Wlan"},
Expand Down
35 changes: 32 additions & 3 deletions UI/ControlMappingScreen.cpp
Expand Up @@ -275,13 +275,40 @@ void ControlMappingScreen::CreateViews() {
root_->Add(rightScroll_);

std::vector<KeyMap::KeyMap_IntStrPair> mappableKeys = KeyMap::GetMappableKeys();

struct Cat {
const char *catName;
int firstKey;
bool openByDefault;
};
// Category name, first input from psp_button_names.
static const Cat cats[] = {
{"Standard PSP controls", CTRL_UP, true},
{"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, true},
{"Emulator controls", VIRTKEY_FASTFORWARD, true},
{"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, false},
};

int curCat = -1;
CollapsibleSection *curSection = nullptr;
for (size_t i = 0; i < mappableKeys.size(); i++) {
SingleControlMapper *mapper = rightColumn->Add(
if (curCat < (int)ARRAY_SIZE(cats) && mappableKeys[i].key == cats[curCat + 1].firstKey) {
if (curCat >= 0 && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
}
curCat++;
curSection = rightColumn->Add(new CollapsibleSection(km->T(cats[curCat].catName)));
curSection->SetSpacing(6.0f);
}
SingleControlMapper *mapper = curSection->Add(
new SingleControlMapper(mappableKeys[i].key, mappableKeys[i].name, screenManager(),
new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
mapper->SetTag(StringFromFormat("KeyMap%s", mappableKeys[i].name));
mappers_.push_back(mapper);
}
if (curCat >= 0 && curSection && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
}

keyMapGeneration_ = KeyMap::g_controllerMapGeneration;
}
Expand Down Expand Up @@ -423,7 +450,8 @@ void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
InputMapping mapping(axis.deviceId, axis.axisId, 1);
triggeredAxes_.insert(mapping);
if (!g_Config.bAllowMappingCombos && !mapping_.mappings.empty()) {
comboMappingsNotEnabled_->SetVisibility(UI::V_VISIBLE);
if (mapping_.mappings.size() == 1 && mapping != mapping_.mappings[0])
comboMappingsNotEnabled_->SetVisibility(UI::V_VISIBLE);
} else if (!mapping_.mappings.contains(mapping)) {
mapping_.mappings.push_back(mapping);
RecreateViews();
Expand All @@ -432,7 +460,8 @@ void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
InputMapping mapping(axis.deviceId, axis.axisId, -1);
triggeredAxes_.insert(mapping);
if (!g_Config.bAllowMappingCombos && !mapping_.mappings.empty()) {
comboMappingsNotEnabled_->SetVisibility(UI::V_VISIBLE);
if (mapping_.mappings.size() == 1 && mapping != mapping_.mappings[0])
comboMappingsNotEnabled_->SetVisibility(UI::V_VISIBLE);
} else if (!mapping_.mappings.contains(mapping)) {
mapping_.mappings.push_back(mapping);
RecreateViews();
Expand Down
7 changes: 6 additions & 1 deletion UI/ControlMappingScreen.h
Expand Up @@ -36,7 +36,10 @@ class SingleControlMapper;

class ControlMappingScreen : public UIDialogScreenWithGameBackground {
public:
explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
categoryToggles_[0] = true;
categoryToggles_[1] = true;
}
const char *tag() const override { return "ControlMapping"; }

protected:
Expand All @@ -51,6 +54,8 @@ class ControlMappingScreen : public UIDialogScreenWithGameBackground {
UI::ScrollView *rightScroll_ = nullptr;
std::vector<SingleControlMapper *> mappers_;
int keyMapGeneration_ = -1;

bool categoryToggles_[10]{};
};

class KeyMappingNewKeyDialog : public PopupScreen {
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/ar_AE.ini
Expand Up @@ -709,12 +709,16 @@ Autoconfigure for device = ‎إعداد تلقائي للعبة
Bind All = Bind All
Clear All = ‎إخلاء الكل
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = ‎إرجاع للإفتراضي
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = ‎خريطة مفتاح جديدة لـ
Map Key = ‎خريطة مفتاح
Map Mouse = ‎خريطة الفأرة
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = ‎يمكنك ضغط علي زر الخروج للإلغاء.

[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/az_AZ.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigure for device
Bind All = Bind All
Clear All = Clear all
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Restore defaults
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Map a new key for
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/bg_BG.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigure for device
Bind All = Bind All
Clear All = Изчисти всички
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Първоначални
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Избери нов клавиш за
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/ca_ES.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigurar per a dispositiu
Bind All = Assignar tots
Clear All = Esborrar tot
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Restaurar
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Prem una tecla per
Map Key = Mapejar tecla
Map Mouse = Mapejar ratolí
Replace = Reemplaçar
Show PSP = Mostra PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = Podeu prémer ESC per cancel·lar.
[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/cz_CZ.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Automaticky nastavit pro zařízení
Bind All = Bind All
Clear All = Vše vyčistit
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Obnovit výchozí
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Mapovat novou klávesu pro
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/da_DK.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autokonfiguration af enhed
Bind All = Bind All
Clear All = Slet alt
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Sæt til standard
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Map en ny taste for
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = Du kan trykke Esc for at afbryde.

[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/de_DE.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autokonfiguration für Gerät
Bind All = Bind All
Clear All = Alle löschen
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Zurücksetzen
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Drücke zuzuweisende Taste für
Map Key = Taste zuweisen
Map Mouse = Maus zuweisen
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = Drücken Sie ESC zum abbrechen.

[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/dr_ID.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigure for device
Bind All = Bind All
Clear All = Paccingngi nasan
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Poleboko' nasan
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Garaganni tombol baru
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/en_US.ini
Expand Up @@ -725,12 +725,16 @@ Autoconfigure for device = Autoconfigure for device
Bind All = Bind All
Clear All = Clear all
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Restore defaults
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Map a new key for
Map Key = Map key
Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/es_ES.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigurar para dispositivo
Bind All = Asignar todos
Clear All = Borrar todo
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Restaurar
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Pulsa una tecla para
Map Key = Mapear tecla
Map Mouse = Mapear ratón
Replace = Remplazar
Show PSP = Mostrar PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = Puedes presionar ESC para cancelar.

[MainMenu]
Expand Down
4 changes: 4 additions & 0 deletions assets/lang/es_LA.ini
Expand Up @@ -701,12 +701,16 @@ Autoconfigure for device = Autoconfigurar para dispositivo
Bind All = Ocultar todo
Clear All = Borrar todo
Combo mappings are not enabled = Combo mappings are not enabled
Control modifiers = Control modifiers
Default All = Restaurar
Emulator controls = Emulator controls
Extended PSP controls = Extended PSP controls
Map a new key for = Presiona una tecla para
Map Key = Asignar tecla
Map Mouse = Asignar ratón
Replace = Reemplazar
Show PSP = Mostrar PSP
Standard PSP controls = Standard PSP controls
You can press ESC to cancel. = Puedes presionar Esc para cancelar.

[MainMenu]
Expand Down

0 comments on commit e40ec0c

Please sign in to comment.