Centralize game background drawing code.

No need to duplicate it everywhere.
This commit is contained in:
Unknown W. Brackets 2014-02-09 13:15:53 -08:00
parent 80704d013e
commit 274160bc22
10 changed files with 63 additions and 107 deletions

View File

@ -33,8 +33,6 @@
#include "UI/UIShader.h" #include "UI/UIShader.h"
#include "UI/GameSettingsScreen.h" #include "UI/GameSettingsScreen.h"
extern void DrawBackground(float alpha);
class ControlMapper : public UI::LinearLayout { class ControlMapper : public UI::LinearLayout {
public: public:
ControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = 0); ControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = 0);

View File

@ -37,7 +37,6 @@
static bool enableAll = false; static bool enableAll = false;
static std::vector<std::string> cheatList; static std::vector<std::string> cheatList;
extern void DrawBackground(float alpha);
static CWCheatEngine *cheatEngine2; static CWCheatEngine *cheatEngine2;
static std::deque<bool> bEnableCheat; static std::deque<bool> bEnableCheat;

View File

@ -87,36 +87,6 @@ void GameScreen::CreateViews() {
UI::SetFocusedView(play); UI::SetFocusedView(play);
} }
void DrawBackground(float alpha);
void GameScreen::DrawBackground(UIContext &dc) {
GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true);
dc.Flush();
dc.RebindTexture();
::DrawBackground(1.0f);
dc.Flush();
if (ginfo && ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color);
dc.Flush();
dc.RebindTexture();
}
/*
if (ginfo && ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
// Pic0 is drawn in the bottom right corner, overlaying pic1.
float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0;
ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color);
ui_draw2d.Flush();
dc.RebindTexture();
}*/
}
void GameScreen::update(InputState &input) { void GameScreen::update(InputState &input) {
UIScreen::update(input); UIScreen::update(input);
@ -235,7 +205,7 @@ UI::EventReturn GameScreen::OnCreateShortcut(UI::EventParams &e) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
bool GameScreen::isRecentGame(std::string gamePath) { bool GameScreen::isRecentGame(const std::string &gamePath) {
for (auto it = g_Config.recentIsos.begin(); it != g_Config.recentIsos.end(); ++it) { for (auto it = g_Config.recentIsos.begin(); it != g_Config.recentIsos.end(); ++it) {
#ifdef _WIN32 #ifdef _WIN32
if (!strcmpIgnore((*it).c_str(), gamePath.c_str(), "\\","/")) if (!strcmpIgnore((*it).c_str(), gamePath.c_str(), "\\","/"))

View File

@ -17,6 +17,7 @@
#pragma once #pragma once
#include "UI/MiscScreens.h"
#include "base/functional.h" #include "base/functional.h"
#include "ui/ui_screen.h" #include "ui/ui_screen.h"
@ -26,18 +27,17 @@
// Uses GameInfoCache heavily to implement the functionality. // Uses GameInfoCache heavily to implement the functionality.
// Should possibly merge this with the PauseScreen. // Should possibly merge this with the PauseScreen.
class GameScreen : public UIDialogScreen { class GameScreen : public UIDialogScreenWithGameBackground {
public: public:
GameScreen(std::string gamePath) : gamePath_(gamePath) {} GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
virtual void update(InputState &input); virtual void update(InputState &input);
protected: protected:
virtual void CreateViews(); virtual void CreateViews();
virtual void DrawBackground(UIContext &dc);
void CallbackDeleteSaveData(bool yes); void CallbackDeleteSaveData(bool yes);
void CallbackDeleteGame(bool yes); void CallbackDeleteGame(bool yes);
bool isRecentGame(std::string gamePath); bool isRecentGame(const std::string &gamePath);
private: private:
// Event handlers // Event handlers
@ -50,8 +50,6 @@ private:
UI::EventReturn OnRemoveFromRecent(UI::EventParams &e); UI::EventReturn OnRemoveFromRecent(UI::EventParams &e);
UI::EventReturn OnShowInFolder(UI::EventParams &e); UI::EventReturn OnShowInFolder(UI::EventParams &e);
std::string gamePath_;
// As we load metadata in the background, we need to be able to update these after the fact. // As we load metadata in the background, we need to be able to update these after the fact.
UI::TextureView *texvGameIcon_; UI::TextureView *texvGameIcon_;
UI::TextView *tvTitle_; UI::TextView *tvTitle_;

View File

@ -404,8 +404,6 @@ UI::EventReturn GameSettingsScreen::OnShaderChange(UI::EventParams &e) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
void DrawBackground(float alpha);
UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) {
if (gpu) { if (gpu) {
gpu->DumpNextFrame(); gpu->DumpNextFrame();
@ -413,34 +411,6 @@ UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
void GameSettingsScreen::DrawBackground(UIContext &dc) {
GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true);
dc.Flush();
dc.RebindTexture();
::DrawBackground(1.0f);
dc.Flush();
if (ginfo && ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color);
dc.Flush();
dc.RebindTexture();
}
/*
if (ginfo && ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
// Pic0 is drawn in the bottom right corner, overlaying pic1.
float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0;
ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color);
ui_draw2d.Flush();
dc.RebindTexture();
}*/
}
void GameSettingsScreen::update(InputState &input) { void GameSettingsScreen::update(InputState &input) {
UIScreen::update(input); UIScreen::update(input);
g_Config.iForceMaxEmulatedFPS = cap60FPS_ ? 60 : 0; g_Config.iForceMaxEmulatedFPS = cap60FPS_ ? 60 : 0;

View File

@ -22,10 +22,10 @@
// Per-game settings screen - enables you to configure graphic options, control options, etc // Per-game settings screen - enables you to configure graphic options, control options, etc
// per game. // per game.
class GameSettingsScreen : public UIDialogScreenWithBackground { class GameSettingsScreen : public UIDialogScreenWithGameBackground {
public: public:
GameSettingsScreen(std::string gamePath, std::string gameID = "") GameSettingsScreen(std::string gamePath, std::string gameID = "")
: gamePath_(gamePath), gameID_(gameID), iAlternateSpeedPercent_(3), enableReports_(false) {} : UIDialogScreenWithGameBackground(gamePath), gameID_(gameID), iAlternateSpeedPercent_(3), enableReports_(false) {}
virtual void update(InputState &input); virtual void update(InputState &input);
virtual void onFinish(DialogResult result); virtual void onFinish(DialogResult result);
@ -34,12 +34,11 @@ public:
protected: protected:
virtual void CreateViews(); virtual void CreateViews();
virtual void DrawBackground(UIContext &dc);
virtual void sendMessage(const char *message, const char *value); virtual void sendMessage(const char *message, const char *value);
void CallbackRestoreDefaults(bool yes); void CallbackRestoreDefaults(bool yes);
private: private:
std::string gamePath_, gameID_; std::string gameID_;
// As we load metadata in the background, we need to be able to update these after the fact. // As we load metadata in the background, we need to be able to update these after the fact.
UI::TextView *tvTitle_; UI::TextView *tvTitle_;

View File

@ -958,34 +958,6 @@ void GamePauseScreen::update(InputState &input) {
UIScreen::update(input); UIScreen::update(input);
} }
void DrawBackground(float alpha);
void GamePauseScreen::DrawBackground(UIContext &dc) {
GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true);
dc.Flush();
if (ginfo) {
bool hasPic = false;
if (ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
hasPic = true;
} else if (ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
hasPic = true;
}
if (hasPic) {
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1, color);
dc.Flush();
dc.RebindTexture();
} else {
::DrawBackground(1.0f);
dc.RebindTexture();
dc.Flush();
}
}
}
GamePauseScreen::~GamePauseScreen() { GamePauseScreen::~GamePauseScreen() {
if (saveSlots_ != NULL) { if (saveSlots_ != NULL) {
g_Config.iCurrentStateSlot = saveSlots_->GetSelection(); g_Config.iCurrentStateSlot = saveSlots_->GetSelection();

View File

@ -63,15 +63,14 @@ private:
bool backFromStore_; bool backFromStore_;
}; };
class GamePauseScreen : public UIDialogScreen { class GamePauseScreen : public UIDialogScreenWithGameBackground {
public: public:
GamePauseScreen(const std::string &filename) : UIDialogScreen(), gamePath_(filename), saveSlots_(NULL) {} GamePauseScreen(const std::string &filename) : UIDialogScreenWithGameBackground(filename), saveSlots_(NULL) {}
virtual ~GamePauseScreen(); virtual ~GamePauseScreen();
virtual void onFinish(DialogResult result); virtual void onFinish(DialogResult result);
protected: protected:
virtual void DrawBackground(UIContext &dc);
virtual void CreateViews(); virtual void CreateViews();
virtual void update(InputState &input); virtual void update(InputState &input);
virtual void sendMessage(const char *message, const char *value); virtual void sendMessage(const char *message, const char *value);
@ -90,8 +89,6 @@ private:
UI::EventReturn OnSwitchUMD(UI::EventParams &e); UI::EventReturn OnSwitchUMD(UI::EventParams &e);
std::string gamePath_;
UI::ChoiceStrip *saveSlots_; UI::ChoiceStrip *saveSlots_;
UI::Choice *saveStateButton_; UI::Choice *saveStateButton_;
UI::Choice *loadStateButton_; UI::Choice *loadStateButton_;

View File

@ -30,6 +30,7 @@
#include "UI/MiscScreens.h" #include "UI/MiscScreens.h"
#include "UI/EmuScreen.h" #include "UI/EmuScreen.h"
#include "UI/MainScreen.h" #include "UI/MainScreen.h"
#include "UI/GameInfoCache.h"
#include "Core/Config.h" #include "Core/Config.h"
#include "Core/Host.h" #include "Core/Host.h"
#include "Core/System.h" #include "Core/System.h"
@ -99,6 +100,32 @@ void DrawBackground(float alpha) {
} }
} }
void DrawGameBackground(UIContext &dc, const std::string &gamePath) {
GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath, true);
dc.Flush();
if (ginfo) {
bool hasPic = false;
if (ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
hasPic = true;
} else if (ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
hasPic = true;
}
if (hasPic) {
uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0;
dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1, color);
dc.Flush();
dc.RebindTexture();
} else {
::DrawBackground(1.0f);
dc.RebindTexture();
dc.Flush();
}
}
}
void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager) { void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager) {
if (!strcmp(message, "clear jit")) { if (!strcmp(message, "clear jit")) {
if (MIPSComp::jit && PSP_IsInited()) { if (MIPSComp::jit && PSP_IsInited()) {
@ -112,6 +139,14 @@ void UIScreenWithBackground::DrawBackground(UIContext &dc) {
dc.Flush(); dc.Flush();
} }
void UIScreenWithGameBackground::DrawBackground(UIContext &dc) {
DrawGameBackground(dc, gamePath_);
}
void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) {
DrawGameBackground(dc, gamePath_);
}
void UIScreenWithBackground::sendMessage(const char *message, const char *value) { void UIScreenWithBackground::sendMessage(const char *message, const char *value) {
HandleCommonMessages(message, value, screenManager()); HandleCommonMessages(message, value, screenManager());
I18NCategory *de = GetI18NCategory("Developer"); I18NCategory *de = GetI18NCategory("Developer");

View File

@ -39,6 +39,15 @@ protected:
virtual UI::EventReturn OnLanguageChange(UI::EventParams &e); virtual UI::EventReturn OnLanguageChange(UI::EventParams &e);
}; };
class UIScreenWithGameBackground : public UIScreenWithBackground {
public:
UIScreenWithGameBackground(const std::string &gamePath)
: UIScreenWithBackground(), gamePath_(gamePath) {}
virtual void DrawBackground(UIContext &dc);
protected:
std::string gamePath_;
};
class UIDialogScreenWithBackground : public UIDialogScreen { class UIDialogScreenWithBackground : public UIDialogScreen {
public: public:
UIDialogScreenWithBackground() : UIDialogScreen() {} UIDialogScreenWithBackground() : UIDialogScreen() {}
@ -48,6 +57,15 @@ protected:
virtual UI::EventReturn OnLanguageChange(UI::EventParams &e); virtual UI::EventReturn OnLanguageChange(UI::EventParams &e);
}; };
class UIDialogScreenWithGameBackground : public UIDialogScreenWithBackground {
public:
UIDialogScreenWithGameBackground(const std::string &gamePath)
: UIDialogScreenWithBackground(), gamePath_(gamePath) {}
virtual void DrawBackground(UIContext &dc);
protected:
std::string gamePath_;
};
class PromptScreen : public UIDialogScreenWithBackground { class PromptScreen : public UIDialogScreenWithBackground {
public: public:
PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText, PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText,