mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
KeyMap: Simplify UI updates.
Better to avoid tightly coupled notifications of updates.
This commit is contained in:
parent
f7b92ebb29
commit
e7666e472f
5 changed files with 30 additions and 6 deletions
|
@ -43,7 +43,8 @@ namespace KeyMap {
|
|||
KeyDef AxisDef(int deviceId, int axisId, int direction);
|
||||
|
||||
KeyMapping g_controllerMap;
|
||||
int g_controllerMapGeneration = 0; // Just used to check if we need to update the Windows menu or not.
|
||||
// Incremented on modification, so we know when to update menus.
|
||||
int g_controllerMapGeneration = 0;
|
||||
std::set<std::string> g_seenPads;
|
||||
std::set<int> g_seenDeviceIds;
|
||||
|
||||
|
@ -622,6 +623,7 @@ void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool repla
|
|||
|
||||
void RestoreDefault() {
|
||||
g_controllerMap.clear();
|
||||
g_controllerMapGeneration++;
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_KEYBOARD, true);
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_XINPUT, false);
|
||||
|
@ -765,4 +767,12 @@ void SwapAxis() {
|
|||
g_swapped_keys = !g_swapped_keys;
|
||||
}
|
||||
|
||||
bool HasChanged(int &prevGeneration) {
|
||||
if (prevGeneration != g_controllerMapGeneration) {
|
||||
prevGeneration = g_controllerMapGeneration;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // KeyMap
|
||||
|
|
|
@ -158,4 +158,6 @@ namespace KeyMap {
|
|||
void AutoConfForPad(const std::string &name);
|
||||
|
||||
bool IsKeyMapped(int device, int key);
|
||||
|
||||
bool HasChanged(int &prevGeneration);
|
||||
}
|
||||
|
|
|
@ -264,17 +264,26 @@ void ControlMappingScreen::CreateViews() {
|
|||
new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
|
||||
mappers_.push_back(mapper);
|
||||
}
|
||||
|
||||
keyMapGeneration_ = KeyMap::g_controllerMapGeneration;
|
||||
}
|
||||
|
||||
void ControlMappingScreen::update() {
|
||||
if (KeyMap::HasChanged(keyMapGeneration_)) {
|
||||
RecreateViews();
|
||||
}
|
||||
|
||||
UIDialogScreenWithBackground::update();
|
||||
}
|
||||
|
||||
UI::EventReturn ControlMappingScreen::OnClearMapping(UI::EventParams ¶ms) {
|
||||
KeyMap::g_controllerMap.clear();
|
||||
RecreateViews();
|
||||
KeyMap::g_controllerMapGeneration++;
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
UI::EventReturn ControlMappingScreen::OnDefaultMapping(UI::EventParams ¶ms) {
|
||||
KeyMap::RestoreDefault();
|
||||
RecreateViews();
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
@ -302,7 +311,6 @@ void ControlMappingScreen::dialogFinished(const Screen *dialog, DialogResult res
|
|||
if (result == DR_OK && dialog->tag() == "listpopup") {
|
||||
ListPopupScreen *popup = (ListPopupScreen *)dialog;
|
||||
KeyMap::AutoConfForPad(popup->GetChoiceString());
|
||||
RecreateViews();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1126,6 +1134,7 @@ void VisualMappingScreen::CreateViews() {
|
|||
}
|
||||
|
||||
void VisualMappingScreen::resized() {
|
||||
UIDialogScreenWithBackground::resized();
|
||||
RecreateViews();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,9 @@ public:
|
|||
std::string tag() const override { return "control mapping"; }
|
||||
|
||||
protected:
|
||||
virtual void CreateViews() override;
|
||||
void CreateViews() override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
UI::EventReturn OnDefaultMapping(UI::EventParams ¶ms);
|
||||
UI::EventReturn OnClearMapping(UI::EventParams ¶ms);
|
||||
|
@ -50,6 +52,7 @@ private:
|
|||
|
||||
UI::ScrollView *rightScroll_;
|
||||
std::vector<SingleControlMapper *> mappers_;
|
||||
int keyMapGeneration_ = -1;
|
||||
};
|
||||
|
||||
class KeyMappingNewKeyDialog : public PopupScreen {
|
||||
|
|
|
@ -351,7 +351,7 @@ namespace MainWindow {
|
|||
bool changed = false;
|
||||
|
||||
const std::string curLanguageID = i18nrepo.LanguageID();
|
||||
if (curLanguageID != menuLanguageID || menuKeymapGeneration != KeyMap::g_controllerMapGeneration) {
|
||||
if (curLanguageID != menuLanguageID || KeyMap::HasChanged(menuKeymapGeneration)) {
|
||||
DoTranslateMenus(hWnd, menu);
|
||||
menuLanguageID = curLanguageID;
|
||||
changed = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue