Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions UI/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "UI/MiscScreens.h"
#include "UI/MainScreen.h"
#include "UI/BackgroundAudio.h"
#include "Core/Reporting.h"

GameScreen::GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
g_BackgroundAudio.SetGame(gamePath);
Expand All @@ -48,6 +49,27 @@ GameScreen::GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBack
GameScreen::~GameScreen() {
}

template <typename I> std::string int2hexstr(I w, size_t hex_len = sizeof(I) << 1) {
static const char* digits = "0123456789ABCDEF";
std::string rc(hex_len, '0');
for (size_t i = 0, j = (hex_len - 1) * 4; i < hex_len; ++i, j -= 4)
rc[i] = digits[(w >> j) & 0x0f];
return rc;
}

void GameScreen::update() {
UIScreen::update();

// Has the user requested a CRC32?
if (CRC32string == "...") {
// Wait until the CRC32 is ready. It might take time on some devices.
if (Reporting::HasCRC(gamePath_)) {
uint32_t crcvalue = Reporting::RetrieveCRC(gamePath_);
CRC32string = int2hexstr(crcvalue);
}
}
}

void GameScreen::CreateViews() {
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(NULL, gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE);

Expand Down Expand Up @@ -143,6 +165,7 @@ void GameScreen::CreateViews() {
btnSetBackground_ = rightColumnItems->Add(new Choice(ga->T("Use UI background")));
btnSetBackground_->OnClick.Handle(this, &GameScreen::OnSetBackground);
btnSetBackground_->SetVisibility(V_GONE);
rightColumnItems->Add(new ChoiceWithValueDisplay(&CRC32string, ga->T("CRC32 CALC"), (const char*)nullptr))->OnClick.Handle(this, &GameScreen::OnDoCRC32);
}

UI::Choice *GameScreen::AddOtherChoice(UI::Choice *choice) {
Expand Down Expand Up @@ -265,6 +288,12 @@ UI::EventReturn GameScreen::OnCwCheat(UI::EventParams &e) {
return UI::EVENT_DONE;
}

UI::EventReturn GameScreen::OnDoCRC32(UI::EventParams& e) {
CRC32string = "...";
return UI::EVENT_DONE;
}


UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) {
TriggerFinish(DR_OK);
return UI::EVENT_DONE;
Expand Down
4 changes: 4 additions & 0 deletions UI/GameScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class GameScreen : public UIDialogScreenWithGameBackground {
GameScreen(const std::string &gamePath);
~GameScreen();

void update() override;

void render() override;

std::string tag() const override { return "game"; }
Expand All @@ -43,6 +45,7 @@ class GameScreen : public UIDialogScreenWithGameBackground {
void CallbackDeleteSaveData(bool yes);
void CallbackDeleteGame(bool yes);
bool isRecentGame(const std::string &gamePath);
std::string CRC32string = "";

private:
UI::Choice *AddOtherChoice(UI::Choice *choice);
Expand All @@ -60,6 +63,7 @@ class GameScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnDeleteConfig(UI::EventParams &e);
UI::EventReturn OnCwCheat(UI::EventParams &e);
UI::EventReturn OnSetBackground(UI::EventParams &e);
UI::EventReturn OnDoCRC32(UI::EventParams& e);

// As we load metadata in the background, we need to be able to update these after the fact.
UI::TextView *tvTitle_;
Expand Down