Skip to content

Commit

Permalink
Add play/pause button to the bottom right of the pause screen
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 11, 2023
1 parent 8d8ff58 commit 6e369e5
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,18 @@ class Spacer : public InertView {
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
w = size_; h = size_;
}

void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override {
if (horiz.type == AT_MOST || horiz.type == EXACTLY)
w = horiz.size;
else
w = size_;
if (vert.type == AT_MOST || vert.type == EXACTLY)
h = vert.size;
else
h = size_;
}

void Draw(UIContext &dc) override {}
std::string DescribeText() const override { return ""; }

Expand Down
10 changes: 9 additions & 1 deletion Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace UI {

static constexpr Size ITEM_HEIGHT = 64.f;

void ApplyGravity(const Bounds outer, const Margins &margins, float w, float h, int gravity, Bounds &inner) {
void ApplyGravity(const Bounds &outer, const Margins &margins, float w, float h, int gravity, Bounds &inner) {
inner.w = w;
inner.h = h;

Expand Down Expand Up @@ -495,6 +495,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
if (views_.empty())
return;

if (tag_ == "debug") {
tag_ = "debug";
}

float sum = 0.0f;
float maxOther = 0.0f;
float totalWeight = 0.0f;
Expand Down Expand Up @@ -666,6 +670,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
void LinearLayout::Layout() {
const Bounds &bounds = bounds_;

if (tag_ == "debug") {
tag_ = "debug";
}

Bounds itemBounds;
float pos;

Expand Down
21 changes: 17 additions & 4 deletions UI/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,12 @@ void GamePauseScreen::CreateViews() {
leftColumnItems->Add(new NoticeView(NoticeLevel::INFO, notAvailable, ""));
}

ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(vertical ? 200 : 300, FILL_PARENT, actionMenuMargins));
root_->Add(rightColumn);
ViewGroup *rightColumnHolder = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(vertical ? 200 : 300, FILL_PARENT, actionMenuMargins));

ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
rightColumnHolder->Add(rightColumn);

root_->Add(rightColumnHolder);

LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
rightColumn->Add(rightColumnItems);
Expand Down Expand Up @@ -414,8 +418,17 @@ void GamePauseScreen::CreateViews() {
} else {
rightColumnItems->Add(new Choice(pa->T("Exit to menu")))->OnClick.Handle(this, &GamePauseScreen::OnExitToMenu);
}
rightColumnItems->Add(new Spacer(25.0f));
rightColumnItems->Add(new CheckBox(&g_Config.bRunBehindPauseMenu, "Run Behind"));

ViewGroup *playControls = rightColumnHolder->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
playControls->SetTag("debug");
playControls->Add(new Spacer(new LinearLayoutParams(1.0f)));
playButton_ = playControls->Add(new Button("", g_Config.bRunBehindPauseMenu ? ImageID("I_PAUSE") : ImageID("I_PLAY"), new LinearLayoutParams(0.0f, G_RIGHT)));
playButton_->OnClick.Add([=](UI::EventParams &e) {
g_Config.bRunBehindPauseMenu = !g_Config.bRunBehindPauseMenu;
playButton_->SetImageID(g_Config.bRunBehindPauseMenu ? ImageID("I_PAUSE") : ImageID("I_PLAY"));
return UI::EVENT_DONE;
});
rightColumnHolder->Add(new Spacer(10.0f));
}

UI::EventReturn GamePauseScreen::OnGameSettings(UI::EventParams &e) {
Expand Down
2 changes: 1 addition & 1 deletion UI/PauseScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {
bool finishNextFrame_ = false;
PauseScreenMode mode_ = PauseScreenMode::MAIN;

UI::Button *pauseButton_ = nullptr;
UI::Button *playButton_ = nullptr;
};
Binary file modified assets/ui_atlas.meta
Binary file not shown.
Binary file modified assets/ui_atlas.zim
Binary file not shown.
8 changes: 4 additions & 4 deletions buildatlas.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Note that we do not copy the big font atlas to Android assets. No longer needed!

./ext/native/tools/build/atlastool ui_atlasscript.txt ui 8888 && cp ui_atlas.zim ui_atlas.meta assets && rm ui_atlas.cpp ui_atlas.h
./ext/native/tools/build/atlastool font_atlasscript.txt font 8888 && cp font_atlas.zim font_atlas.meta assets && rm font_atlas.cpp font_atlas.h
./ext/native/tools/build/atlastool asciifont_atlasscript.txt asciifont 8888 && cp asciifont_atlas.zim asciifont_atlas.meta assets && rm asciifont_atlas.cpp asciifont_atlas.h
#./ext/native/tools/build/atlastool font_atlasscript.txt font 8888 && cp font_atlas.zim font_atlas.meta assets && rm font_atlas.cpp font_atlas.h
#./ext/native/tools/build/atlastool asciifont_atlasscript.txt asciifont 8888 && cp asciifont_atlas.zim asciifont_atlas.meta assets && rm asciifont_atlas.cpp asciifont_atlas.h

rm ui_atlas.zim ui_atlas.meta
rm font_atlas.zim font_atlas.meta
rm asciifont_atlas.zim asciifont_atlas.meta
#rm font_atlas.zim font_atlas.meta
#rm asciifont_atlas.zim asciifont_atlas.meta
File renamed without changes
1 change: 1 addition & 0 deletions ui_atlasscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ image I_RETROACHIEVEMENTS_LOGO source_assets/image/retroachievements_logo.png co
image I_CHECKMARK source_assets/image/checkmark.png copy
image I_PLAY source_assets/image/play.png copy
image I_STOP source_assets/image/stop.png copy
image I_PAUSE source_assets/image/pause.png copy
image I_FASTFORWARD source_assets/image/fast_forward.png copy
image I_RECORD source_assets/image/record.png copy
image I_SPEAKER source_assets/image/speaker.png copy
Expand Down

0 comments on commit 6e369e5

Please sign in to comment.