NewUI: Load games directly by press-and-hold on the main menu
This commit is contained in:
parent
9d76ba7dd2
commit
09c7aaacad
2 changed files with 52 additions and 3 deletions
|
@ -45,7 +45,7 @@ namespace MainWindow {
|
||||||
class GameButton : public UI::Clickable {
|
class GameButton : public UI::Clickable {
|
||||||
public:
|
public:
|
||||||
GameButton(const std::string &gamePath, UI::LayoutParams *layoutParams = 0)
|
GameButton(const std::string &gamePath, UI::LayoutParams *layoutParams = 0)
|
||||||
: UI::Clickable(layoutParams), gamePath_(gamePath) {}
|
: UI::Clickable(layoutParams), gamePath_(gamePath), holdFrameCount_(0) {}
|
||||||
|
|
||||||
virtual void Draw(UIContext &dc);
|
virtual void Draw(UIContext &dc);
|
||||||
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const {
|
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const {
|
||||||
|
@ -53,9 +53,30 @@ public:
|
||||||
h = 80;
|
h = 80;
|
||||||
}
|
}
|
||||||
const std::string &GamePath() const { return gamePath_; }
|
const std::string &GamePath() const { return gamePath_; }
|
||||||
|
virtual void Touch(const TouchInput &input) {
|
||||||
|
UI::Clickable::Touch(input);
|
||||||
|
if (input.flags & TOUCH_UP) {
|
||||||
|
holdFrameCount_ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual void Update(const InputState &input_state) {
|
||||||
|
if (down_)
|
||||||
|
holdFrameCount_++;
|
||||||
|
// Hold button for 1.5 seconds to launch the game directly
|
||||||
|
if (holdFrameCount_ > 90) {
|
||||||
|
UI::EventParams e;
|
||||||
|
e.v = this;
|
||||||
|
e.s = gamePath_;
|
||||||
|
OnHoldClick.Trigger(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UI::Event OnHoldClick;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string gamePath_;
|
std::string gamePath_;
|
||||||
|
|
||||||
|
int holdFrameCount_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void GameButton::Draw(UIContext &dc) {
|
void GameButton::Draw(UIContext &dc) {
|
||||||
|
@ -109,6 +130,11 @@ void GameButton::Draw(UIContext &dc) {
|
||||||
if (texture) {
|
if (texture) {
|
||||||
dc.Draw()->Flush();
|
dc.Draw()->Flush();
|
||||||
texture->Bind(0);
|
texture->Bind(0);
|
||||||
|
if (holdFrameCount_ > 60) {
|
||||||
|
// Blink before launching by holding
|
||||||
|
if (((holdFrameCount_ >> 3) & 1) == 0)
|
||||||
|
color = darkenColor(color);
|
||||||
|
}
|
||||||
dc.Draw()->DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, color);
|
dc.Draw()->DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, color);
|
||||||
dc.Draw()->Flush();
|
dc.Draw()->Flush();
|
||||||
dc.RebindTexture();
|
dc.RebindTexture();
|
||||||
|
@ -209,6 +235,7 @@ public:
|
||||||
GameBrowser(std::string path, bool allowBrowsing, UI::LayoutParams *layoutParams = 0);
|
GameBrowser(std::string path, bool allowBrowsing, UI::LayoutParams *layoutParams = 0);
|
||||||
|
|
||||||
UI::Event OnChoice;
|
UI::Event OnChoice;
|
||||||
|
UI::Event OnHoldChoice;
|
||||||
|
|
||||||
virtual void Update(const InputState &input_state) {
|
virtual void Update(const InputState &input_state) {
|
||||||
UI::GridLayout::Update(input_state);
|
UI::GridLayout::Update(input_state);
|
||||||
|
@ -218,6 +245,7 @@ private:
|
||||||
void Refresh();
|
void Refresh();
|
||||||
|
|
||||||
UI::EventReturn GameButtonClick(UI::EventParams &e);
|
UI::EventReturn GameButtonClick(UI::EventParams &e);
|
||||||
|
UI::EventReturn GameButtonHoldClick(UI::EventParams &e);
|
||||||
UI::EventReturn NavigateClick(UI::EventParams &e);
|
UI::EventReturn NavigateClick(UI::EventParams &e);
|
||||||
|
|
||||||
PathBrowser path_;
|
PathBrowser path_;
|
||||||
|
@ -268,7 +296,9 @@ void GameBrowser::Refresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < gameButtons.size(); i++) {
|
for (size_t i = 0; i < gameButtons.size(); i++) {
|
||||||
Add(gameButtons[i])->OnClick.Handle(this, &GameBrowser::GameButtonClick);
|
GameButton *b = Add(gameButtons[i]);
|
||||||
|
b->OnClick.Handle(this, &GameBrowser::GameButtonClick);
|
||||||
|
b->OnHoldClick.Handle(this, &GameBrowser::GameButtonHoldClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +311,15 @@ UI::EventReturn GameBrowser::GameButtonClick(UI::EventParams &e) {
|
||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI::EventReturn GameBrowser::GameButtonHoldClick(UI::EventParams &e) {
|
||||||
|
GameButton *button = static_cast<GameButton *>(e.v);
|
||||||
|
UI::EventParams e2;
|
||||||
|
e2.s = button->GamePath();
|
||||||
|
// Insta-update - here we know we are already on the right thread.
|
||||||
|
OnHoldChoice.Trigger(e2);
|
||||||
|
return UI::EVENT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
UI::EventReturn GameBrowser::NavigateClick(UI::EventParams &e) {
|
UI::EventReturn GameBrowser::NavigateClick(UI::EventParams &e) {
|
||||||
UI::Button *button = static_cast<UI::Button *>(e.v);
|
UI::Button *button = static_cast<UI::Button *>(e.v);
|
||||||
std::string text = button->GetText();
|
std::string text = button->GetText();
|
||||||
|
@ -323,6 +362,9 @@ void MainScreen::CreateViews() {
|
||||||
tabRecentGames->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
tabRecentGames->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
||||||
tabAllGames->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
tabAllGames->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
||||||
tabHomebrew->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
tabHomebrew->OnChoice.Handle(this, &MainScreen::OnGameSelected);
|
||||||
|
tabRecentGames->OnHoldChoice.Handle(this, &MainScreen::OnGameHoldSelected);
|
||||||
|
tabAllGames->OnHoldChoice.Handle(this, &MainScreen::OnGameHoldSelected);
|
||||||
|
tabHomebrew->OnHoldChoice.Handle(this, &MainScreen::OnGameHoldSelected);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (info) {
|
if (info) {
|
||||||
|
@ -371,6 +413,12 @@ UI::EventReturn MainScreen::OnGameSelected(UI::EventParams &e) {
|
||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI::EventReturn MainScreen::OnGameHoldSelected(UI::EventParams &e) {
|
||||||
|
// Go directly into the game.
|
||||||
|
screenManager()->switchScreen(new EmuScreen(e.s));
|
||||||
|
return UI::EVENT_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
UI::EventReturn MainScreen::OnSettings(UI::EventParams &e) {
|
UI::EventReturn MainScreen::OnSettings(UI::EventParams &e) {
|
||||||
// screenManager()->push(new SettingsScreen());
|
// screenManager()->push(new SettingsScreen());
|
||||||
screenManager()->push(new GlobalSettingsScreen());
|
screenManager()->push(new GlobalSettingsScreen());
|
||||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UI::EventReturn OnGameSelected(UI::EventParams &e);
|
UI::EventReturn OnGameSelected(UI::EventParams &e);
|
||||||
|
UI::EventReturn OnGameHoldSelected(UI::EventParams &e);
|
||||||
// Event handlers
|
// Event handlers
|
||||||
UI::EventReturn OnLoadFile(UI::EventParams &e);
|
UI::EventReturn OnLoadFile(UI::EventParams &e);
|
||||||
UI::EventReturn OnSettings(UI::EventParams &e);
|
UI::EventReturn OnSettings(UI::EventParams &e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue