mirror of
https://github.com/DarkStore-3DS/Universal-Core.git
synced 2026-07-03 00:39:23 +00:00
Optional: Add stack of screens.
Use this if you're relying on the screens from before.
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "screenCommon.hpp"
|
#include "screenCommon.hpp"
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
|
#include <stack>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
C3D_RenderTarget* Top;
|
C3D_RenderTarget* Top;
|
||||||
@@ -37,9 +38,9 @@ C3D_RenderTarget* Bottom;
|
|||||||
C2D_TextBuf TextBuf;
|
C2D_TextBuf TextBuf;
|
||||||
C2D_Font Font;
|
C2D_Font Font;
|
||||||
std::unique_ptr<Screen> usedScreen, tempScreen; // tempScreen used for "fade" effects.
|
std::unique_ptr<Screen> usedScreen, tempScreen; // tempScreen used for "fade" effects.
|
||||||
|
std::stack<std::unique_ptr<Screen>> screens;
|
||||||
bool currentScreen = false;
|
bool currentScreen = false;
|
||||||
bool fadeout = false;
|
bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false;
|
||||||
bool fadein = false;
|
|
||||||
int fadealpha = 0;
|
int fadealpha = 0;
|
||||||
int fadecolor = 0;
|
int fadecolor = 0;
|
||||||
|
|
||||||
@@ -244,32 +245,48 @@ bool Gui::Draw_Rect(float x, float y, float w, float h, u32 color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw's the current screen's draw.
|
// Draw's the current screen's draw.
|
||||||
void Gui::DrawScreen() {
|
void Gui::DrawScreen(bool stack) {
|
||||||
|
if (!stack) {
|
||||||
if (usedScreen != nullptr) usedScreen->Draw();
|
if (usedScreen != nullptr) usedScreen->Draw();
|
||||||
|
} else {
|
||||||
|
if (!screens.empty()) screens.top()->Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the current screen's logic.
|
// Do the current screen's logic.
|
||||||
void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade) {
|
void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade, bool stack) {
|
||||||
if (waitFade) {
|
if (waitFade) {
|
||||||
if (!fadein && !fadeout) {
|
if (!fadein && !fadeout && !fadein2 && !fadeout2) {
|
||||||
|
if (!stack) {
|
||||||
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
|
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
|
||||||
|
} else {
|
||||||
|
if (!screens.empty()) screens.top()->Logic(hDown, hHeld, touch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (!stack) {
|
||||||
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
|
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
|
||||||
|
} else {
|
||||||
|
if (!screens.empty()) screens.top()->Logic(hDown, hHeld, touch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move's the tempScreen to the used one.
|
// Move's the tempScreen to the used one.
|
||||||
void Gui::transferScreen() {
|
void Gui::transferScreen(bool stack) {
|
||||||
|
if (!stack) {
|
||||||
if (tempScreen != nullptr) usedScreen = std::move(tempScreen);
|
if (tempScreen != nullptr) usedScreen = std::move(tempScreen);
|
||||||
|
} else {
|
||||||
|
if (tempScreen != nullptr) screens.push(std::move(tempScreen));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the current Screen.
|
// Set the current Screen.
|
||||||
void Gui::setScreen(std::unique_ptr<Screen> screen, bool fade) {
|
void Gui::setScreen(std::unique_ptr<Screen> screen, bool fade, bool stack) {
|
||||||
tempScreen = std::move(screen);
|
tempScreen = std::move(screen);
|
||||||
// Switch screen without fade.
|
// Switch screen without fade.
|
||||||
if (!fade) {
|
if (!fade) {
|
||||||
Gui::transferScreen();
|
Gui::transferScreen(stack);
|
||||||
} else {
|
} else {
|
||||||
// Fade, then switch.
|
// Fade, then switch.
|
||||||
fadeout = true;
|
fadeout = true;
|
||||||
@@ -278,7 +295,7 @@ void Gui::setScreen(std::unique_ptr<Screen> screen, bool fade) {
|
|||||||
|
|
||||||
// Fade's the screen in and out and transfer the screen.
|
// Fade's the screen in and out and transfer the screen.
|
||||||
// Credits goes to RocketRobz & SavvyManager.
|
// Credits goes to RocketRobz & SavvyManager.
|
||||||
void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames) {
|
void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames, bool stack) {
|
||||||
if (fadein) {
|
if (fadein) {
|
||||||
fadealpha -= fadeinFrames;
|
fadealpha -= fadeinFrames;
|
||||||
if (fadealpha < 0) {
|
if (fadealpha < 0) {
|
||||||
@@ -288,17 +305,50 @@ void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stack) {
|
||||||
|
if (fadein2) {
|
||||||
|
fadealpha -= fadeinFrames;
|
||||||
|
if (fadealpha < 0) {
|
||||||
|
fadealpha = 0;
|
||||||
|
fadecolor = 255;
|
||||||
|
fadein2 = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fadeout) {
|
if (fadeout) {
|
||||||
fadealpha += fadeoutFrames;
|
fadealpha += fadeoutFrames;
|
||||||
if (fadealpha > 255) {
|
if (fadealpha > 255) {
|
||||||
fadealpha = 255;
|
fadealpha = 255;
|
||||||
Gui::transferScreen(); // Transfer Temp screen to the used one.
|
Gui::transferScreen(stack); // Transfer Temp screen to the stack / used one.
|
||||||
fadein = true;
|
fadein = true;
|
||||||
fadeout = false;
|
fadeout = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stack) {
|
||||||
|
if (fadeout2) {
|
||||||
|
fadealpha += fadeoutFrames;
|
||||||
|
if (fadealpha > 255) {
|
||||||
|
fadealpha = 255;
|
||||||
|
Gui::screenBack2(); // Go screen back.
|
||||||
|
fadein2 = true;
|
||||||
|
fadeout2 = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Go a screen back. (Stack only!)
|
||||||
|
void Gui::screenBack(bool fade) {
|
||||||
|
if (!fade) {
|
||||||
|
if (screens.size() > 0) screens.pop();
|
||||||
|
} else {
|
||||||
|
if (screens.size() > 0) fadeout2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Gui::screenBack2() { if (screens.size() > 0) screens.pop(); }
|
||||||
|
|
||||||
// Select, on which Screen should be drawn.
|
// Select, on which Screen should be drawn.
|
||||||
void Gui::ScreenDraw(C3D_RenderTarget * screen) {
|
void Gui::ScreenDraw(C3D_RenderTarget * screen) {
|
||||||
C2D_SceneBegin(screen);
|
C2D_SceneBegin(screen);
|
||||||
|
|||||||
@@ -133,32 +133,40 @@ namespace Gui {
|
|||||||
bool Draw_Rect(float x, float y, float w, float h, u32 color);
|
bool Draw_Rect(float x, float y, float w, float h, u32 color);
|
||||||
|
|
||||||
// Used for the current Screen's Draw. (Optional!)
|
// Used for the current Screen's Draw. (Optional!)
|
||||||
void DrawScreen();
|
// stack: Is it the stack variant?
|
||||||
|
void DrawScreen(bool stack = false);
|
||||||
|
|
||||||
/* Used for the current Screen's Logic. (Optional!)
|
/* Used for the current Screen's Logic. (Optional!)
|
||||||
* hDown: the hidKeysDown() variable.
|
* hDown: the hidKeysDown() variable.
|
||||||
* hHeld: the HidKeysHeld() variable.
|
* hHeld: the HidKeysHeld() variable.
|
||||||
* touch: The TouchPosition variable.
|
* touch: The TouchPosition variable.
|
||||||
* waitFade: Wheter to wait until the fade ends.
|
* waitFade: Wheter to wait until the fade ends.
|
||||||
|
* stack: Is it the stack variant?
|
||||||
*/
|
*/
|
||||||
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true);
|
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true, bool stack = false);
|
||||||
|
|
||||||
/* Transfer the Temp Screen to the used one. (Optional!)
|
/* Transfer the Temp Screen to the used one. (Optional!)
|
||||||
|
* stack: Is it the stack variant?
|
||||||
* It will check, if the tempScreen variable is not nullptr, so don't worry.
|
* It will check, if the tempScreen variable is not nullptr, so don't worry.
|
||||||
*/
|
*/
|
||||||
void transferScreen();
|
void transferScreen(bool stack = false);
|
||||||
|
|
||||||
/* Set a specific Screen with switch function. (Optional!)
|
/* Set a specific Screen with switch function. (Optional!)
|
||||||
* screen: unique_ptr of the screen. (Optional by using the screen class.)
|
* screen: unique_ptr of the screen. (Optional by using the screen class.)
|
||||||
* screenSwitch: Wheter to switch to the current screen.
|
* screenSwitch: Wheter to switch to the current screen.
|
||||||
|
* stack: Is it the stack variant?
|
||||||
*/
|
*/
|
||||||
void setScreen(std::unique_ptr<Screen> screen, bool fade = false);
|
void setScreen(std::unique_ptr<Screen> screen, bool fade = false, bool stack = false);
|
||||||
|
|
||||||
/* Fades into screens and calls the constructor after it. (Optional!)
|
/* Fades into screens and calls the constructor after it. (Optional!)
|
||||||
* fadeoutFrames: Amount of frames for fadeout.
|
* fadeoutFrames: Amount of frames for fadeout.
|
||||||
* fadeinFrames: Amount of frames for fadein.
|
* fadeinFrames: Amount of frames for fadein.
|
||||||
|
* stack: Is it the stack variant?
|
||||||
*/
|
*/
|
||||||
void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6);
|
void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6, bool stack = false);
|
||||||
|
|
||||||
|
void screenBack(bool fade = false); // Goes a screen back. (Set!) (Stack only!)
|
||||||
|
void screenBack2(); // Goes a screen back.(Action!) (Stack only!)
|
||||||
|
|
||||||
/* Set on which screen to draw.
|
/* Set on which screen to draw.
|
||||||
* screen: The render target. (Targets are inside the screenCommon.hpp file.)
|
* screen: The render target. (Targets are inside the screenCommon.hpp file.)
|
||||||
|
|||||||
+2
-4
@@ -33,9 +33,7 @@
|
|||||||
extern C3D_RenderTarget* Top;
|
extern C3D_RenderTarget* Top;
|
||||||
extern C3D_RenderTarget* TopRight;
|
extern C3D_RenderTarget* TopRight;
|
||||||
extern C3D_RenderTarget* Bottom;
|
extern C3D_RenderTarget* Bottom;
|
||||||
extern bool fadeout;
|
extern bool fadeout, fadein, fadeout2, fadein2;
|
||||||
extern bool fadein;
|
extern int fadealpha, fadecolor;
|
||||||
extern int fadealpha;
|
|
||||||
extern int fadecolor;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user