Skip to content

Commit

Permalink
UI: Keep focus on game after displaying details.
Browse files Browse the repository at this point in the history
Fixes #8539.
  • Loading branch information
unknownbrackets committed Feb 8, 2016
1 parent 4a38a41 commit 862e6ff
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
1 change: 0 additions & 1 deletion UI/GameScreen.cpp
Expand Up @@ -41,7 +41,6 @@ GameScreen::GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBack
}

GameScreen::~GameScreen() {
SetBackgroundAudioGame("");
}

void GameScreen::CreateViews() {
Expand Down
2 changes: 2 additions & 0 deletions UI/GameScreen.h
Expand Up @@ -34,6 +34,8 @@ class GameScreen : public UIDialogScreenWithGameBackground {

virtual void update(InputState &input);

virtual std::string tag() const { return "game"; }

protected:
virtual void CreateViews();
void CallbackDeleteConfig(bool yes);
Expand Down
57 changes: 48 additions & 9 deletions UI/MainScreen.cpp
Expand Up @@ -402,6 +402,12 @@ GameBrowser::GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle,
Refresh();
}

void GameBrowser::FocusGame(std::string gamePath) {
focusGamePath_ = gamePath;
Refresh();
focusGamePath_.clear();
}

UI::EventReturn GameBrowser::LayoutChange(UI::EventParams &e) {
*gridStyle_ = e.a == 0 ? true : false;
Refresh();
Expand Down Expand Up @@ -566,6 +572,10 @@ void GameBrowser::Refresh() {
b->OnClick.Handle(this, &GameBrowser::GameButtonClick);
b->OnHoldClick.Handle(this, &GameBrowser::GameButtonHoldClick);
b->OnHighlight.Handle(this, &GameBrowser::GameButtonHighlight);

if (!focusGamePath_.empty() && b->GamePath() == focusGamePath_) {
b->SetFocus();
}
}

// Show a button to toggle pinning at the very end.
Expand Down Expand Up @@ -710,6 +720,7 @@ void MainScreen::CreateViews() {
TabHolder *leftColumn = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
tabHolder_ = leftColumn;
tabHolder_->SetTag("MainScreenGames");
gameBrowsers_.clear();

leftColumn->SetClip(true);

Expand All @@ -720,6 +731,8 @@ void MainScreen::CreateViews() {
"!RECENT", false, &g_Config.bGridView1, "", "", 0,
new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
scrollRecentGames->Add(tabRecentGames);
gameBrowsers_.push_back(tabRecentGames);

leftColumn->AddTab(mm->T("Recent"), scrollRecentGames);
tabRecentGames->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant);
tabRecentGames->OnHoldChoice.Handle(this, &MainScreen::OnGameSelected);
Expand All @@ -746,7 +759,9 @@ void MainScreen::CreateViews() {
}

scrollAllGames->Add(tabAllGames);
gameBrowsers_.push_back(tabAllGames);
scrollHomebrew->Add(tabHomebrew);
gameBrowsers_.push_back(tabHomebrew);

leftColumn->AddTab(mm->T("Games"), scrollAllGames);
leftColumn->AddTab(mm->T("Homebrew & Demos"), scrollHomebrew);
Expand Down Expand Up @@ -999,6 +1014,8 @@ UI::EventReturn MainScreen::OnGameSelected(UI::EventParams &e) {
return UI::EVENT_DONE;
}

// Restore focus if it was highlighted (e.g. by gamepad.)
restoreFocusGamePath_ = highlightedGamePath_;
SetBackgroundAudioGame(path);
lockBackgroundAudio_ = true;
screenManager()->push(new GameScreen(path));
Expand All @@ -1014,16 +1031,19 @@ UI::EventReturn MainScreen::OnGameHighlight(UI::EventParams &e) {
std::string path = e.s;
#endif

if (!highlightedGamePath_.empty() || (e.a == FF_LOSTFOCUS && highlightedGamePath_ == path)) {
if (prevHighlightedGamePath_.empty() || prevHighlightProgress_ >= 0.75f) {
prevHighlightedGamePath_ = highlightedGamePath_;
prevHighlightProgress_ = 1.0 - highlightProgress_;
// Don't change when re-highlighting what's already highlighted.
if (path != highlightedGamePath_ || e.a == FF_LOSTFOCUS) {
if (!highlightedGamePath_.empty()) {
if (prevHighlightedGamePath_.empty() || prevHighlightProgress_ >= 0.75f) {
prevHighlightedGamePath_ = highlightedGamePath_;
prevHighlightProgress_ = 1.0 - highlightProgress_;
}
highlightedGamePath_.clear();
}
if (e.a == FF_GOTFOCUS) {
highlightedGamePath_ = path;
highlightProgress_ = 0.0f;
}
highlightedGamePath_.clear();
}
if (e.a == FF_GOTFOCUS) {
highlightedGamePath_ = path;
highlightProgress_ = 0.0f;
}

if ((!highlightedGamePath_.empty() || e.a == FF_LOSTFOCUS) && !lockBackgroundAudio_)
Expand Down Expand Up @@ -1114,6 +1134,25 @@ void MainScreen::dialogFinished(const Screen *dialog, DialogResult result) {
backFromStore_ = true;
RecreateViews();
}
if (dialog->tag() == "game") {
if (!restoreFocusGamePath_.empty()) {
// Prevent the background from fading, since we just were displaying it.
highlightedGamePath_ = restoreFocusGamePath_;
highlightProgress_ = 1.0f;

// Refocus the game button itself.
int tab = tabHolder_->GetCurrentTab();
if (tab >= 0 && tab < gameBrowsers_.size()) {
gameBrowsers_[tab]->FocusGame(restoreFocusGamePath_);
}

// Don't get confused next time.
restoreFocusGamePath_.clear();
} else {
// Not refocusing, so we need to stop the audio.
SetBackgroundAudioGame("");
}
}
}

void UmdReplaceScreen::CreateViews() {
Expand Down
6 changes: 6 additions & 0 deletions UI/MainScreen.h
Expand Up @@ -33,6 +33,8 @@ class GameBrowser : public UI::LinearLayout {

UI::Choice *HomebrewStoreButton() { return homebrewStoreButton_; }

void FocusGame(std::string gamePath);

private:
void Refresh();
bool IsCurrentPathPinned();
Expand All @@ -56,6 +58,7 @@ class GameBrowser : public UI::LinearLayout {
std::string lastLink_;
int flags_;
UI::Choice *homebrewStoreButton_;
std::string focusGamePath_;
};

class MainScreen : public UIScreenWithBackground {
Expand Down Expand Up @@ -98,6 +101,9 @@ class MainScreen : public UIScreenWithBackground {
UI::LinearLayout *upgradeBar_;
UI::TabHolder *tabHolder_;

std::string restoreFocusGamePath_;
std::vector<GameBrowser *> gameBrowsers_;

std::string highlightedGamePath_;
std::string prevHighlightedGamePath_;
float highlightProgress_;
Expand Down

0 comments on commit 862e6ff

Please sign in to comment.