UI: Allow overriding dialog logic on finish.

This seems cleaner.
This commit is contained in:
Unknown W. Brackets 2017-03-19 17:43:03 -07:00
parent d8600229f4
commit 073e056369
12 changed files with 37 additions and 31 deletions

View File

@ -310,7 +310,7 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
mapped_ = true;
KeyDef kdf(key.deviceId, key.keyCode);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
if (callback_)
callback_(kdf);
}
@ -347,7 +347,7 @@ bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (axis.value > AXIS_BIND_THRESHOLD) {
mapped_ = true;
KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, 1));
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
if (callback_)
callback_(kdf);
}
@ -355,7 +355,7 @@ bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (axis.value < -AXIS_BIND_THRESHOLD) {
mapped_ = true;
KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, -1));
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
if (callback_)
callback_(kdf);
}
@ -437,7 +437,7 @@ void JoystickHistoryView::Update() {
bool AnalogTestScreen::key(const KeyInput &key) {
bool retval = true;
if (UI::IsEscapeKey(key)) {
screenManager()->finishDialog(this, DR_BACK);
TriggerFinish(DR_BACK);
return true;
}

View File

@ -166,7 +166,7 @@ UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams &params) {
}
UI::EventReturn CwCheatScreen::OnAddCheat(UI::EventParams &params) {
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
g_Config.bReloadCheats = true;
return UI::EVENT_DONE;
}
@ -176,7 +176,7 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
if (MIPSComp::jit) {
MIPSComp::jit->ClearCache();
}
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
File::openIniFile(activeCheatFile);
return UI::EVENT_DONE;
}
@ -262,7 +262,7 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params) {
fs.close();
g_Config.bReloadCheats = true;
//Need a better way to refresh the screen, rather than exiting and having to re-enter.
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}

View File

@ -143,7 +143,7 @@ void DevMenu::dialogFinished(const Screen *dialog, DialogResult result) {
UpdateUIState(UISTATE_INGAME);
// Close when a subscreen got closed.
// TODO: a bug in screenmanager causes this not to work here.
// screenManager()->finishDialog(this, DR_OK);
// TriggerFinish(DR_OK);
}
void LogScreen::UpdateLog() {
@ -608,7 +608,7 @@ bool AddressPromptScreen::key(const KeyInput &key) {
BackspaceDigit();
} else if (key.keyCode == NKCODE_ENTER) {
OnCompleted(DR_OK);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
} else {
return UIDialogScreen::key(key);
}

View File

@ -268,7 +268,7 @@ UI::EventReturn GameScreen::OnCwCheat(UI::EventParams &e) {
}
UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}

View File

@ -1246,12 +1246,12 @@ void UmdReplaceScreen::update() {
UI::EventReturn UmdReplaceScreen::OnGameSelected(UI::EventParams &e) {
__UmdReplace(e.s);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
UI::EventReturn UmdReplaceScreen::OnCancel(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}
@ -1262,6 +1262,6 @@ UI::EventReturn UmdReplaceScreen::OnGameSettings(UI::EventParams &e) {
UI::EventReturn UmdReplaceScreen::OnGameSelectedInstant(UI::EventParams &e) {
__UmdReplace(e.s);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}

View File

@ -270,13 +270,13 @@ void PromptScreen::CreateViews() {
UI::EventReturn PromptScreen::OnYes(UI::EventParams &e) {
callback_(true);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
UI::EventReturn PromptScreen::OnNo(UI::EventParams &e) {
callback_(false);
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}
@ -550,7 +550,7 @@ UI::EventReturn CreditsScreen::OnShare(UI::EventParams &e) {
}
UI::EventReturn CreditsScreen::OnOK(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}

View File

@ -269,7 +269,7 @@ void GamePauseScreen::update() {
UIScreen::update();
if (finishNextFrame_) {
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
finishNextFrame_ = false;
}
}
@ -353,7 +353,7 @@ UI::EventReturn GamePauseScreen::OnGameSettings(UI::EventParams &e) {
}
UI::EventReturn GamePauseScreen::OnState(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}
@ -387,7 +387,7 @@ UI::EventReturn GamePauseScreen::OnScreenshotClicked(UI::EventParams &e) {
}
UI::EventReturn GamePauseScreen::OnExitToMenu(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
@ -399,7 +399,7 @@ UI::EventReturn GamePauseScreen::OnReportFeedback(UI::EventParams &e) {
UI::EventReturn GamePauseScreen::OnRewind(UI::EventParams &e) {
SaveState::Rewind(&AfterSaveStateAction);
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}

View File

@ -528,7 +528,7 @@ void RemoteISOConnectScreen::update() {
break;
case ScanStatus::LOADED:
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
screenManager()->push(new RemoteISOBrowseScreen(games_));
break;
}

View File

@ -289,7 +289,7 @@ EventReturn ReportScreen::HandleSubmit(EventParams &e) {
std::string filename = includeScreenshot_ ? screenshotFilename_ : "";
Reporting::ReportCompatibility(compat, graphics_ + 1, speed_ + 1, gameplay_ + 1, filename);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
screenManager()->push(new ReportFinishScreen(gamePath_));
return EVENT_DONE;
}

View File

@ -142,7 +142,7 @@ private:
UI::EventReturn SavedataPopupScreen::OnDeleteButtonClick(UI::EventParams &e) {
GameInfo *ginfo = g_gameInfoCache->GetInfo(nullptr, savePath_, GAMEINFO_WANTSIZE);
ginfo->Delete();
screenManager()->finishDialog(this, DR_NO);
TriggerFinish(DR_NO);
return UI::EVENT_DONE;
}

View File

@ -143,6 +143,10 @@ bool UIScreen::key(const KeyInput &key) {
return false;
}
void UIScreen::TriggerFinish(DialogResult result) {
screenManager()->finishDialog(this, result);
}
bool UIDialogScreen::key(const KeyInput &key) {
bool retval = UIScreen::key(key);
if (!retval && (key.flags & KEY_DOWN) && UI::IsEscapeKey(key)) {
@ -150,7 +154,7 @@ bool UIDialogScreen::key(const KeyInput &key) {
ELOG("Screen already finished");
} else {
finished_ = true;
screenManager()->finishDialog(this, DR_BACK);
TriggerFinish(DR_BACK);
}
return true;
}
@ -194,17 +198,17 @@ bool UIScreen::axis(const AxisInput &axis) {
}
UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_BACK);
TriggerFinish(DR_BACK);
return UI::EVENT_DONE;
}
UI::EventReturn UIScreen::OnOK(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
UI::EventReturn UIScreen::OnCancel(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}
@ -225,7 +229,7 @@ bool PopupScreen::touch(const TouchInput &touch) {
}
if (!box_->GetBounds().Contains(touch.x, touch.y))
screenManager()->finishDialog(this, DR_BACK);
TriggerFinish(DR_BACK);
return UIDialogScreen::touch(touch);
}
@ -328,13 +332,13 @@ void MessagePopupScreen::OnCompleted(DialogResult result) {
UI::EventReturn PopupScreen::OnOK(UI::EventParams &e) {
OnCompleted(DR_OK);
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
}
UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) {
OnCompleted(DR_CANCEL);
screenManager()->finishDialog(this, DR_CANCEL);
TriggerFinish(DR_CANCEL);
return UI::EVENT_DONE;
}
@ -350,7 +354,7 @@ UI::EventReturn ListPopupScreen::OnListChoice(UI::EventParams &e) {
adaptor_.SetSelected(e.a);
if (callback_)
callback_(adaptor_.GetSelected());
screenManager()->finishDialog(this, DR_OK);
TriggerFinish(DR_OK);
OnCompleted(DR_OK);
OnChoice.Dispatch(e);
return UI::EVENT_DONE;

View File

@ -26,6 +26,8 @@ public:
virtual TouchInput transformTouch(const TouchInput &touch) override;
virtual void TriggerFinish(DialogResult result);
// Some useful default event handlers
UI::EventReturn OnOK(UI::EventParams &e);
UI::EventReturn OnCancel(UI::EventParams &e);