Add option for showing a 2nd character

This commit is contained in:
RocketRobz 2020-07-10 01:43:16 -06:00
parent 9b678a375c
commit 581680c9ee
7 changed files with 186 additions and 72 deletions

View File

@ -28,19 +28,21 @@ extern bool shiftBySubPixel;
namespace GFX {
// Load & Unload default sheets.
void resetCharStatus(void);
Result loadSheets();
Result unloadSheets();
void loadGameSelSheets();
void unloadGameSelSheets();
// Sprite Functions.
bool loadCharSprite(const char* t3xPathAllSeasons, const char* t3xPathOneSeason);
bool loadCharSprite(int num, const char* t3xPathAllSeasons, const char* t3xPathOneSeason);
void loadCharSpriteMem(int num);
void loadBgSprite(void);
void unloadBgSprite(void);
void reloadBgSprite(void);
void showBgSprite(int zoomIn);
void animateBgSprite(void);
void showCharSprite(int zoomIn, int fadeAlpha, bool lightingEffects = false);
void showCharSprite(int num, int zoomIn, int fadeAlpha, bool lightingEffects = false);
void DrawSprite(int img, int x, int y, float ScaleX = 1, float ScaleY = 1, GPU_TEXTURE_FILTER_PARAM filter = GPU_NEAREST);
void DrawSpriteBlend(int img, float x, float y, u32 color, float ScaleX = 1, float ScaleY = 1, GPU_TEXTURE_FILTER_PARAM filter = GPU_NEAREST);

View File

@ -37,6 +37,7 @@ private:
int photo_highlightedGame = 0;
int char_highlightedGame = 0;
int seasonNo = 0;
int currentCharNum = 0;
char chrFilePath[256];
char chrFilePath2[256];
@ -44,11 +45,11 @@ private:
bool displayNothing = false;
bool displayStudioBg = false;
bool showScrollingBg = true;
bool characterPicked = false;
bool characterPicked[2] = {false};
mutable int charFadeAlpha = 0;
bool previewCharacter = false;
bool previewCharacterFound = false;
bool previewCharacterFound[2] = {false};
bool showMessage = false;
int messageNo = 0;

View File

@ -4,8 +4,6 @@
// List all common screen variables here.
extern u8 sysRegion;
extern bool showCursor;
extern float bg_xPos;
extern float bg_yPos;
extern int cursorAlpha;
extern int studioBg;
extern bool cinemaWide;

View File

@ -3,11 +3,13 @@
#include <unistd.h>
static char bgSpriteMem[4][0x200000];
static char charSpriteMem[2][0x80000];
static C2D_SpriteSheet sprites;
static C2D_SpriteSheet bgSprite;
static C2D_SpriteSheet chracterSprite;
static bool chracterSpriteLoaded = false;
static bool chracterSpriteFound[2] = {false};
static bool bgSpriteLoaded = false;
extern int studioBg;
@ -31,6 +33,11 @@ static int timeOutside = 0; // 0 == Day, 1 == Sunset, 2 == Night
bool shiftBySubPixel = false;
void GFX::resetCharStatus(void) {
chracterSpriteFound[0] = false;
chracterSpriteFound[1] = false;
}
Result GFX::loadSheets() {
sprites = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
GFX::loadBgSprite();
@ -317,28 +324,47 @@ void GFX::reloadBgSprite() {
loadBgSprite();
}
bool GFX::loadCharSprite(const char* t3xPathAllSeasons, const char* t3xPathOneSeason) {
bool GFX::loadCharSprite(int num, const char* t3xPathAllSeasons, const char* t3xPathOneSeason) {
if (chracterSpriteLoaded) {
C2D_SpriteSheetFree(chracterSprite);
chracterSpriteLoaded = false;
}
chracterSpriteFound[num] = false;
bool allSeasons = true;
bool fileFound = false;
fileFound = (access(t3xPathAllSeasons, F_OK) == 0);
if (!fileFound) {
allSeasons = false;
fileFound = (access(t3xPathOneSeason, F_OK) == 0);
}
if (!fileFound) {
return false;
}
FILE* charFile = fopen((allSeasons ? t3xPathAllSeasons : t3xPathOneSeason), "rb");
fread((void*)charSpriteMem[num], 1, 0x80000, charFile);
fclose(charFile);
//chracterSprite = C2D_SpriteSheetLoadFromMem(charSpriteMem[num], 0x80000);
chracterSpriteFound[num] = true;
return true;
}
void GFX::loadCharSpriteMem(int num) {
if (chracterSpriteLoaded) {
C2D_SpriteSheetFree(chracterSprite);
}
if (access(t3xPathAllSeasons, F_OK) == 0) {
chracterSprite = C2D_SpriteSheetLoad(t3xPathAllSeasons);
chracterSpriteLoaded = true;
return true;
} else {
chracterSpriteLoaded = false;
}
if (access(t3xPathOneSeason, F_OK) == 0) {
chracterSprite = C2D_SpriteSheetLoad(t3xPathOneSeason);
chracterSpriteLoaded = true;
return true;
} else {
chracterSpriteLoaded = false;
}
return false;
if (!chracterSpriteFound[num]) return;
chracterSprite = C2D_SpriteSheetLoadFromMem(charSpriteMem[num], 0x80000);
chracterSpriteLoaded = true;
}
void GFX::showBgSprite(int zoomIn) {
if (!bgSpriteLoaded) return;
int yPos = -(240*zoomIn);
if (cinemaWide==true) yPos -= 16;
@ -368,7 +394,31 @@ void GFX::animateBgSprite(void) {
}
}
void GFX::showCharSprite(int zoomIn, int fadeAlpha, bool lightingEffects) {
void GFX::showCharSprite(int num, int zoomIn, int fadeAlpha, bool lightingEffects) {
if (!chracterSpriteLoaded) return;
int xPos = (cinemaWide==true ? 60 : 0);
if (chracterSpriteFound[0] && chracterSpriteFound[1]) {
if (zoomIn == 1) {
switch (num) {
case 0:
xPos -= 80;
break;
case 1:
xPos += 80;
break;
}
} else {
switch (num) {
case 0:
xPos -= 32;
break;
case 1:
xPos += 32;
break;
}
}
}
int yPos = -((cinemaWide==true ? 168 : 240)*zoomIn);
if (cinemaWide==true) yPos += 36;
@ -406,10 +456,10 @@ void GFX::showCharSprite(int zoomIn, int fadeAlpha, bool lightingEffects) {
break;
}
}
C2D_DrawImageAt(image, (cinemaWide==true ? 60 : 0), yPos-(shiftBySubPixel ? 0.5f : 0), 0.5f, &tint, (cinemaWide==true ? 0.35f : 0.5), (cinemaWide==true ? 0.7f : 1));
C2D_DrawImageAt(image, xPos, yPos-(shiftBySubPixel ? 0.5f : 0), 0.5f, &tint, (cinemaWide==true ? 0.35f : 0.5), (cinemaWide==true ? 0.7f : 1));
} else {
C2D_PlainImageTint(&tint, C2D_Color32(255, 255, 255, fadeAlpha), 1);
C2D_DrawImageAt(image, (cinemaWide==true ? 60 : 0), yPos-(shiftBySubPixel ? 0.5f : 0), 0.5f, &tint, (cinemaWide==true ? 0.35f : 0.5), (cinemaWide==true ? 0.7f : 1));
C2D_DrawImageAt(image, xPos, yPos-(shiftBySubPixel ? 0.5f : 0), 0.5f, &tint, (cinemaWide==true ? 0.35f : 0.5), (cinemaWide==true ? 0.7f : 1));
}
}

View File

@ -47,6 +47,8 @@ static bool musicLoopPlaying = false;
static int musicLoopDelay = 0;
static bool screenoff_ran = false;
static bool screenon_ran = true;
bool clearTop = true; // Disable in order to render a second character
bool renderTop = true; // Disable to prevent second character from flickering
void loadSettings(void) {
CIniFile settingsini(settingsIni);
@ -131,8 +133,6 @@ void screenon(void)
u8 sysRegion = CFG_REGION_USA;
u64 appID = 0;
float bg_xPos = 0.0f;
float bg_yPos = 0.0f;
bool showCursor = false;
int cursorAlpha = 0;
@ -190,6 +190,7 @@ int main()
loadSettings();
Gui::init();
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
GFX::loadSheets();
fadein = true;
fadealpha = 0;
@ -261,7 +262,9 @@ int main()
// Here we draw the actual screen.
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
if (clearTop) {
C2D_TargetClear(Top, TRANSPARENT);
}
C2D_TargetClear(Bottom, TRANSPARENT);
Gui::clearTextBufs();
Gui::DrawScreen();
@ -291,25 +294,6 @@ int main()
Screenshot_Capture();
}
// Scroll background
switch (iFps) {
default:
bg_xPos += 0.3;
bg_yPos -= 0.3;
break;
case 30:
bg_xPos += 0.6;
bg_yPos -= 0.6;
break;
case 24:
bg_xPos += 0.9;
bg_yPos -= 0.9;
break;
}
if (bg_xPos >= 72) bg_xPos = 0.0f;
if (bg_yPos <= -136) bg_yPos = 0.0f;
if (hDown) {
svcSignalEvent(threadRequest);
}

View File

@ -16,9 +16,14 @@
#include <unistd.h>
static int currentCharacterRendered = 0;
extern bool musicPlayStarted;
extern bool clearTop;
extern bool renderTop;
PhotoStudio::PhotoStudio() {
currentCharacterRendered = 0;
GFX::resetCharStatus();
this->getList();
}
@ -182,11 +187,14 @@ void PhotoStudio::loadChrImage(bool Robz) {
} else {
sprintf(this->chrFilePath, "romfs:/gfx/null.t3x"); // All Seasons
}
this->previewCharacterFound = GFX::loadCharSprite(this->chrFilePath, this->chrFilePath);
this->previewCharacterFound[currentCharNum] = GFX::loadCharSprite(currentCharNum, this->chrFilePath, this->chrFilePath);
} else {
sprintf(this->chrFilePath, "romfs:/gfx/ss%i_%s.t3x", 4, (Robz ? "Robz" : import_characterName())); // All Seasons
sprintf(this->chrFilePath2, "romfs:/gfx/ss%i_%s%i.t3x", 4, (Robz ? "Robz" : import_characterName()), this->seasonNo); // One Season
this->previewCharacterFound = GFX::loadCharSprite(this->chrFilePath, this->chrFilePath2);
this->previewCharacterFound[currentCharNum] = GFX::loadCharSprite(currentCharNum, this->chrFilePath, this->chrFilePath2);
}
if (previewCharacterFound[0] && !characterPicked[1]) {
GFX::loadCharSpriteMem(0);
}
this->previewCharacter = true;
}
@ -201,26 +209,47 @@ void PhotoStudio::Draw(void) const {
musicPlayStarted = true;
}
if (renderTop) {
Gui::ScreenDraw(Top);
if (this->displayStudioBg) {
GFX::showBgSprite(zoomIn);
} else if (this->showScrollingBg) {
GFX::DrawSprite(sprites_title_idx, 0, 0, 0.5);
} else {
Gui::Draw_Rect(0, 0, 400, 240, WHITE);
}
if (this->previewCharacter) {
if (this->previewCharacterFound) {
GFX::showCharSprite(this->zoomIn, this->charFadeAlpha, this->displayStudioBg);
} else {
Gui::DrawStringCentered(0, 104, 0.65, WHITE, (this->char_highlightedGame==4 ? "Preview not found." : "Preview unavailable."));
}
}
this->preview();
if (currentCharacterRendered == 0) {
if (this->displayStudioBg) {
GFX::showBgSprite(zoomIn);
} else if (this->showScrollingBg) {
GFX::DrawSprite(sprites_title_idx, 0, 0, 0.5);
} else {
Gui::Draw_Rect(0, 0, 400, 240, WHITE);
}
if (this->previewCharacter) {
if (this->previewCharacterFound[0]) {
if (characterPicked[1]) {
GFX::loadCharSpriteMem(0);
}
GFX::showCharSprite(0, this->zoomIn, this->charFadeAlpha, this->displayStudioBg);
} else {
Gui::DrawStringCentered(0, 104, 0.65, WHITE, (this->char_highlightedGame==4 ? "Preview not found." : "Preview unavailable."));
}
}
} else if (currentCharacterRendered == 1) {
if (characterPicked[1] && this->previewCharacterFound[1]) {
GFX::loadCharSpriteMem(1);
GFX::showCharSprite(1, this->zoomIn, this->charFadeAlpha, this->displayStudioBg);
}
}
if (renderTop && subScreenMode!=1 && previewCharacter && previewCharacterFound[0] && previewCharacterFound[1]) {
currentCharacterRendered++;
if (currentCharacterRendered > 1) {
currentCharacterRendered = 0;
renderTop = false;
}
clearTop = (currentCharacterRendered == 0);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
if (cinemaWide) {
Gui::Draw_Rect(0, 0, 400, 36, C2D_Color32(0, 0, 0, 255));
@ -359,7 +388,11 @@ void PhotoStudio::Draw(void) const {
Gui::DrawString(32, i2, 0.65, WHITE, "Change location");
i2 += 48;
GFX::DrawSprite(sprites_item_button_idx, 16, i2-20);
Gui::DrawString(32, i2, 0.65, WHITE, "Change character");
if (currentCharNum==1) {
Gui::DrawString(32, i2, 0.65, WHITE, "Change character < 2 >");
} else {
Gui::DrawString(32, i2, 0.65, WHITE, "Change character < 1 >");
}
}
if (this->subScreenMode != 0) {
@ -379,7 +412,9 @@ void PhotoStudio::Draw(void) const {
}
void PhotoStudio::preview() const {
if (this->previewCharacter) {
if (characterPicked[1]) {
this->charFadeAlpha = 255;
} else if (this->previewCharacter) {
switch (iFps) {
default:
this->charFadeAlpha += 20;
@ -400,14 +435,23 @@ void PhotoStudio::preview() const {
void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->subScreenMode==0 || this->subScreenMode==2) {
if ((this->subScreenMode==0 || this->subScreenMode==2)) {
int zoomLimit = characterPicked[1] ? 1 : 2;
if (hDown & KEY_CPAD_UP) {
this->zoomIn++;
if (this->zoomIn > 2) this->zoomIn = 2;
if (this->zoomIn > zoomLimit) {
this->zoomIn = zoomLimit;
} else {
renderTop = true;
}
}
if (hDown & KEY_CPAD_DOWN) {
this->zoomIn--;
if (this->zoomIn < 0) this->zoomIn = 0;
if (this->zoomIn < 0) {
this->zoomIn = 0;
} else {
renderTop = true;
}
}
}
@ -431,6 +475,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->importCharacterList_cursorPositionOnScreen < 0) {
this->importCharacterList_cursorPositionOnScreen = 0;
}
renderTop = true;
this->loadChrImage(false);
}
@ -451,6 +496,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->importCharacterList_cursorPositionOnScreen > 2) {
this->importCharacterList_cursorPositionOnScreen = 2;
}
renderTop = true;
this->loadChrImage(false);
}
}
@ -461,6 +507,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} else if (hDown & KEY_SELECT) {
sndSelect();
this->subScreenMode = 0;
renderTop = true;
this->loadChrImage(true); // Load Robz
}
@ -469,6 +516,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->char_highlightedGame--;
if (this->char_highlightedGame < 0) this->char_highlightedGame = 4;
this->getMaxChars();
renderTop = true;
}
if (hDown & KEY_DRIGHT) {
@ -476,6 +524,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->char_highlightedGame++;
if (this->char_highlightedGame > 4) this->char_highlightedGame = 0;
this->getMaxChars();
renderTop = true;
}
if ((hDown & KEY_DLEFT) || (hDown & KEY_DRIGHT)) {
@ -493,6 +542,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
this->getMaxChars();
renderTop = true;
this->loadChrImage(false);
}
@ -502,6 +552,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->seasonNo--;
if (this->seasonNo < 0) this->seasonNo = 3;
this->loadChrImage(false);
renderTop = true;
}
if ((hDown & KEY_R) || (hDown & KEY_ZR)) {
@ -509,6 +560,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->seasonNo++;
if (this->seasonNo > 3) this->seasonNo = 0;
this->loadChrImage(false);
renderTop = true;
}
}
@ -593,7 +645,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_A) {
sndSelect();
this->subScreenMode = 0;
this->previewCharacter = this->characterPicked;
this->previewCharacter = this->characterPicked[currentCharNum];
}
if (hDown & KEY_DLEFT) {
@ -638,7 +690,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || ((hDown & KEY_TOUCH) && touchingBackButton())) {
sndBack();
this->subScreenMode = 0;
this->previewCharacter = this->characterPicked;
this->previewCharacter = this->characterPicked[currentCharNum];
}
} else {
@ -666,6 +718,23 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->characterChangeMenu_cursorPositionOnScreen = 1;
}
}
if (this->characterChangeMenu_cursorPosition == 1) {
if (hDown & KEY_DLEFT) {
sndHighlight();
currentCharNum--;
if (currentCharNum < 0) {
currentCharNum = 0;
}
}
if (hDown & KEY_DRIGHT) {
sndHighlight();
currentCharNum++;
if (currentCharNum > 1) {
currentCharNum = 1;
}
}
}
}
if (hDown & KEY_A) {
@ -698,6 +767,7 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->displayStudioBg = true;
//}
this->zoomIn = 0;
renderTop = true;
} else if (this->characterChangeMenu_cursorPosition == 1) {
sndSelect();
this->displayNothing = true;
@ -709,8 +779,12 @@ void PhotoStudio::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
this->getMaxChars();
this->displayNothing = false;
this->characterPicked[currentCharNum] = true;
if (characterPicked[0] && characterPicked[1] && this->zoomIn > 1) {
this->zoomIn = 1;
}
renderTop = true;
this->loadChrImage(false);
this->characterPicked = true;
}
}

View File

@ -2,10 +2,15 @@
#include "settings.hpp"
#include "screenvars.h"
extern bool clearTop;
extern bool renderTop;
char txt_cinemaWide[24];
char txt_frameRate[24];
void Settings::Draw(void) const {
clearTop = true;
renderTop = true;
Gui::ScreenDraw(Top);
GFX::DrawSprite(sprites_title_idx, 0, 0, 0.5);