Skip to content

Commit

Permalink
Merge pull request #18785 from hrydgard/ux-fixes
Browse files Browse the repository at this point in the history
Fix issue with the collapsible sections in control mapping collapsing on every change, plus, combo fix
  • Loading branch information
hrydgard committed Jan 29, 2024
2 parents f02142c + 04ea498 commit f3cf05a
Show file tree
Hide file tree
Showing 51 changed files with 77 additions and 19 deletions.
5 changes: 4 additions & 1 deletion Common/UI/View.h
Expand Up @@ -899,14 +899,17 @@ class CheckBox : public ClickableItem {

class CollapsibleHeader : public CheckBox {
public:
CollapsibleHeader(bool *toggle, const std::string &text, LayoutParams *layoutParams = nullptr);
CollapsibleHeader(bool *open, const std::string &text, LayoutParams *layoutParams = nullptr);
void Draw(UIContext &dc) override;
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; }
void SetOpenPtr(bool *open) {
toggle_ = open;
}
private:
bool hasSubItems_ = true;
};
Expand Down
11 changes: 6 additions & 5 deletions Common/UI/ViewGroup.cpp
Expand Up @@ -1175,11 +1175,12 @@ StickyChoice *ChoiceStrip::Choice(int index) {
}

CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *layoutParams) : LinearLayout(ORIENT_VERTICAL, layoutParams) {
open_ = &localOpen_;
SetSpacing(0.0f);

heading_ = new CollapsibleHeader(&open_, title);
views_.push_back(heading_);
heading_->OnClick.Add([=](UI::EventParams &) {
header_ = new CollapsibleHeader(open_, title);
views_.push_back(header_);
header_->OnClick.Add([=](UI::EventParams &) {
// Change the visibility of all children except the first one.
// Later maybe try something more ambitious.
UpdateVisibility();
Expand All @@ -1189,12 +1190,12 @@ CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *l

void CollapsibleSection::Update() {
ViewGroup::Update();
heading_->SetHasSubitems(views_.size() > 1);
header_->SetHasSubitems(views_.size() > 1);
}

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

Expand Down
10 changes: 8 additions & 2 deletions Common/UI/ViewGroup.h
Expand Up @@ -332,14 +332,20 @@ class CollapsibleSection : public LinearLayout {
void Update() override;

void SetOpen(bool open) {
*open_ = open;
UpdateVisibility();
}
void SetOpenPtr(bool *open) {
header_->SetOpenPtr(open);
open_ = open;
UpdateVisibility();
}

private:
void UpdateVisibility();
bool open_ = true;
CollapsibleHeader *heading_;
bool localOpen_ = true;
bool *open_;
CollapsibleHeader *header_;
};

} // namespace UI
1 change: 1 addition & 0 deletions Core/Config.cpp
Expand Up @@ -836,6 +836,7 @@ static const ConfigSetting controlSettings[] = {
ConfigSetting("AnalogTriggerThreshold", &g_Config.fAnalogTriggerThreshold, 0.75f, CfgFlag::DEFAULT),

ConfigSetting("AllowMappingCombos", &g_Config.bAllowMappingCombos, false, CfgFlag::DEFAULT),
ConfigSetting("StrictComboOrder", &g_Config.bStrictComboOrder, false, CfgFlag::DEFAULT),

ConfigSetting("LeftStickHeadScale", &g_Config.fLeftStickHeadScale, 1.0f, CfgFlag::PER_GAME),
ConfigSetting("RightStickHeadScale", &g_Config.fRightStickHeadScale, 1.0f, CfgFlag::PER_GAME),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Expand Up @@ -407,6 +407,7 @@ struct Config {

// Sets whether combo mapping is enabled.
bool bAllowMappingCombos;
bool bStrictComboOrder;

bool bMouseControl;
bool bMapMouse; // Workaround for mapping screen:|
Expand Down
4 changes: 2 additions & 2 deletions Core/ControlMapper.cpp
Expand Up @@ -365,7 +365,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double no
continue;
}
// Stop reverse ordering from triggering.
if (iter->second.timestamp < curTime) {
if (g_Config.bStrictComboOrder && iter->second.timestamp < curTime) {
all = false;
break;
} else {
Expand Down Expand Up @@ -416,7 +416,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double no

if (iter != curInput_.end()) {
// Stop reverse ordering from triggering.
if (iter->second.timestamp < curTime) {
if (g_Config.bStrictComboOrder && iter->second.timestamp < curTime) {
product = 0.0f;
break;
} else {
Expand Down
19 changes: 10 additions & 9 deletions UI/ControlMappingScreen.cpp
Expand Up @@ -262,6 +262,7 @@ void ControlMappingScreen::CreateViews() {
return UI::EVENT_DONE;
});
leftColumn->Add(new CheckBox(&g_Config.bAllowMappingCombos, km->T("Allow combo mappings")));
leftColumn->Add(new CheckBox(&g_Config.bStrictComboOrder, km->T("Strict combo input order")));

leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f)));
AddStandardBack(leftColumn);
Expand All @@ -280,22 +281,22 @@ void ControlMappingScreen::CreateViews() {
struct Cat {
const char *catName;
int firstKey;
bool openByDefault;
bool *open;
};
// 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},
{"Standard PSP controls", CTRL_UP, &categoryToggles_[0]},
{"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, &categoryToggles_[1]},
{"Emulator controls", VIRTKEY_FASTFORWARD, &categoryToggles_[2]},
{"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, &categoryToggles_[3]},
};

int curCat = -1;
CollapsibleSection *curSection = nullptr;
for (size_t i = 0; i < numMappableKeys; i++) {
if (curCat < (int)ARRAY_SIZE(cats) && mappableKeys[i].key == cats[curCat + 1].firstKey) {
if (curCat >= 0 && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
if (curCat >= 0) {
curSection->SetOpenPtr(cats[curCat].open);
}
curCat++;
curSection = rightColumn->Add(new CollapsibleSection(km->T(cats[curCat].catName)));
Expand All @@ -307,8 +308,8 @@ void ControlMappingScreen::CreateViews() {
mapper->SetTag(StringFromFormat("KeyMap%s", mappableKeys[i].name));
mappers_.push_back(mapper);
}
if (curCat >= 0 && curSection && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
if (curCat >= 0 && curSection) {
curSection->SetOpenPtr(cats[curCat].open);
}

keyMapGeneration_ = KeyMap::g_controllerMapGeneration;
Expand Down
2 changes: 2 additions & 0 deletions UI/ControlMappingScreen.h
Expand Up @@ -39,6 +39,8 @@ class ControlMappingScreen : public UIDialogScreenWithGameBackground {
explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
categoryToggles_[0] = true;
categoryToggles_[1] = true;
categoryToggles_[2] = true;
categoryToggles_[3] = false;
}
const char *tag() const override { return "ControlMapping"; }

Expand Down
1 change: 1 addition & 0 deletions assets/lang/ar_AE.ini
Expand Up @@ -728,6 +728,7 @@ Map Mouse = ‎خريطة الفأرة
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = ‎يمكنك ضغط علي زر الخروج للإلغاء.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/az_AZ.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/bg_BG.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ca_ES.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Mapejar ratolí
Replace = Reemplaçar
Show PSP = Mostra PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Podeu prémer ESC per cancel·lar.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/cz_CZ.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/da_DK.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Du kan trykke Esc for at afbryde.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/de_DE.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Maus zuweisen
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Drücken Sie ESC zum abbrechen.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/dr_ID.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en_US.ini
Expand Up @@ -744,6 +744,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_ES.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Mapear ratón
Replace = Remplazar
Show PSP = Mostrar PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Puedes presionar ESC para cancelar.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_LA.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Asignar ratón
Replace = Reemplazar
Show PSP = Mostrar PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Puedes presionar Esc para cancelar.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fa_IR.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fi_FI.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Kartoita hiiri
Replace = Korvaa
Show PSP = Näytä PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Voit peruuttaa painamalla Esc.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fr_FR.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Assigner un contrôle de souris
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Vous pouvez presser "Échap" pour annuler.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gl_ES.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/gr_EL.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = ΡύΘμιση ποντικού
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Μπορείτε να πατήσετε Esc για ακύρωση.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/he_IL_invert.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hr_HR.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Postavi miš
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Možes pritisnuti ESC za odustati.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/hu_HU.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Egér társítása
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Megszakításhoz használj ESC-et.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/id_ID.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Tetapkan mouse
Replace = Timpa
Show PSP = Tampilkan PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Kamu dapat membatalkan dengan menekan ESC.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/it_IT.ini
Expand Up @@ -721,6 +721,7 @@ Map Mouse = Mappa Mouse
Replace = Sostituisci
Show PSP = Mostra PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Puoi premere Esc per annullare.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ja_JP.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = マウスの割り当て指定
Replace = 置き換える
Show PSP = PSP画像を表示
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Escを押すとキャンセルできます。

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/jv_ID.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ko_KR.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = 마우스 매핑
Replace = 교체
Show PSP = PSP 표시
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Esc를 눌러 취소할 수 있습니다.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/lo_LA.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = ເຈົ້າສາມາດກົດ Esc ເພື່ອຍົກເລີກ.
[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/lt-LT.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ms_MY.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Map mouse
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = You can press Esc to cancel.

[MainMenu]
Expand Down
1 change: 1 addition & 0 deletions assets/lang/nl_NL.ini
Expand Up @@ -720,6 +720,7 @@ Map Mouse = Muis indelen
Replace = Replace
Show PSP = Show PSP
Standard PSP controls = Standard PSP controls
Strict combo input order = Strict combo input order
You can press ESC to cancel. = Druk op Esc om te annuleren.
[MainMenu]
Expand Down

0 comments on commit f3cf05a

Please sign in to comment.