diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 37f8e9ab02..2e5bd83cde 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -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()) { diff --git a/Common/UI/View.h b/Common/UI/View.h index 87941167cc..a84b68a38b 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -468,7 +468,7 @@ public: 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 T *AddTween(T *t) { @@ -871,6 +871,8 @@ public: 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; diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index b78781f20f..7fbb4aa7fd 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -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; }); } @@ -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 diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index b0bceb3f6a..7d19525844 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -327,7 +327,13 @@ public: void Update() override; + void SetOpen(bool open) { + open_ = open; + UpdateVisibility(); + } + private: + void UpdateVisibility(); bool open_ = true; CollapsibleHeader *heading_; }; diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index e3a746841d..05f9a2564c 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -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"}, @@ -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"}, @@ -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"}, diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 246e2007ad..722a89a74d 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -275,13 +275,40 @@ void ControlMappingScreen::CreateViews() { root_->Add(rightScroll_); std::vector 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; } diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index b2202bd3a8..fb70f5cc6e 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -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: @@ -51,6 +54,8 @@ private: UI::ScrollView *rightScroll_ = nullptr; std::vector mappers_; int keyMapGeneration_ = -1; + + bool categoryToggles_[10]{}; }; class KeyMappingNewKeyDialog : public PopupScreen {