summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/scenes/collectionScene.c3
-rw-r--r--src/scenes/distractionScene.c2
-rw-r--r--src/scenes/mainMenu.c2
-rw-r--r--src/scenes/puzzlePreviewScene.c14
-rw-r--r--src/scenes/puzzleScene.c3
-rw-r--r--src/scenes/puzzleSelectionScene.c2
-rw-r--r--src/scenes/resultView.c1
-rw-r--r--src/scenes/sceneManager.c7
-rw-r--r--src/scenes/scenes.h13
-rw-r--r--src/ui_elements/Panel.c46
10 files changed, 89 insertions, 4 deletions
diff --git a/src/scenes/collectionScene.c b/src/scenes/collectionScene.c
index 1f1173e..f0f91f3 100644
--- a/src/scenes/collectionScene.c
+++ b/src/scenes/collectionScene.c
@@ -180,6 +180,9 @@ Scene *CreatePuzzleCollectionScene(CollectionElement *el, bool smooothEntry) {
outp->Deint = deinitCollectionScene;
outp->IsTransparent = false;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
+
CollectionSceneData *data = malloc(sizeof(CollectionSceneData));
if (data == NULL) {
free(outp);
diff --git a/src/scenes/distractionScene.c b/src/scenes/distractionScene.c
index f249b53..65439bd 100644
--- a/src/scenes/distractionScene.c
+++ b/src/scenes/distractionScene.c
@@ -83,6 +83,8 @@ Scene *CreateDistractionScene(DistractionPuzzle *puzzle, void (*addTime)(Scene *
outp->Draw = drawDisctractionScene;
outp->Deint = deinitDisctractionScene;
outp->IsTransparent = true;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
distractionSceneData *data = malloc(sizeof(distractionSceneData));
if (data == NULL) {
diff --git a/src/scenes/mainMenu.c b/src/scenes/mainMenu.c
index 8529e35..3a857cd 100644
--- a/src/scenes/mainMenu.c
+++ b/src/scenes/mainMenu.c
@@ -25,5 +25,7 @@ Scene *CreateMainMenu() {
outp->Draw = drawMainMenu;
outp->Deint = deinitMainMenu;
outp->IsTransparent = false;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
return outp;
}
diff --git a/src/scenes/puzzlePreviewScene.c b/src/scenes/puzzlePreviewScene.c
index 6ce3ba7..27b0541 100644
--- a/src/scenes/puzzlePreviewScene.c
+++ b/src/scenes/puzzlePreviewScene.c
@@ -34,7 +34,14 @@ void closePreviewWindow(Scene *self) {
if (self == NULL) return;
puzzlePreviewData *data = ((Scene *)self)->data;
if (data == NULL) return;
- data->state = POPUP_HIDING_ALT;
+ data->state = POPUP_HIDING_OVERLAY;
+}
+
+static PopUpState getCurrentState(void *self) {
+ if (self == NULL || ((Scene *)self)->data == NULL)
+ return POPUP_ACTIVE;
+ puzzlePreviewData *data = ((Scene *)self)->data;
+ return data->state;
}
bool updatePuzzlePreview(void *self) {
@@ -48,7 +55,7 @@ bool updatePuzzlePreview(void *self) {
}
return true;
- case POPUP_HIDING_ALT:
+ case POPUP_HIDING_OVERLAY:
data->scroll_up -= SCROLL_SPEED * GetFrameTime();
if (data->scroll_up <= 0) {
if (data->puzzle != NULL) FreePuzzle(data->puzzle);
@@ -158,6 +165,9 @@ Scene *CreatePuzzlePreview(Puzzle *puzzle) {
outp->Deint = deinitPuzzlePreview;
outp->IsTransparent = true;
+ outp->GetCurrentState = getCurrentState;
+ outp->Reopen = NULL;
+
puzzlePreviewData *data = malloc(sizeof(puzzlePreviewData));
if (data == NULL) {
free(outp);
diff --git a/src/scenes/puzzleScene.c b/src/scenes/puzzleScene.c
index 6c8f623..52652fe 100644
--- a/src/scenes/puzzleScene.c
+++ b/src/scenes/puzzleScene.c
@@ -178,6 +178,9 @@ Scene *CreatePuzzleScene(Puzzle *puzzle) {
outp->Deint = deinitPuzzleScene;
outp->IsTransparent = false;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
+
puzzleSceneData *data = malloc(sizeof(puzzleSceneData));
data->PuzzlePtr = puzzle;
data->scroll = 0;
diff --git a/src/scenes/puzzleSelectionScene.c b/src/scenes/puzzleSelectionScene.c
index 8529e35..93b5699 100644
--- a/src/scenes/puzzleSelectionScene.c
+++ b/src/scenes/puzzleSelectionScene.c
@@ -24,6 +24,8 @@ Scene *CreateMainMenu() {
outp->Update = updateMainMenu;
outp->Draw = drawMainMenu;
outp->Deint = deinitMainMenu;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
outp->IsTransparent = false;
return outp;
}
diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c
index 0017d5a..add28ea 100644
--- a/src/scenes/resultView.c
+++ b/src/scenes/resultView.c
@@ -79,6 +79,7 @@ Scene *CreateResultView(SubmitionResult *result) {
outp->Draw = drawResultView;
outp->Update = updateResultView;
outp->Deint = deinitResultView;
+ outp->Reopen = NULL;
outp->IsTransparent = true;
ResultViewData *data = malloc(sizeof(ResultViewData));
diff --git a/src/scenes/sceneManager.c b/src/scenes/sceneManager.c
index e5ab397..f500972 100644
--- a/src/scenes/sceneManager.c
+++ b/src/scenes/sceneManager.c
@@ -34,8 +34,15 @@ bool AddScene(Scene *newScene) {
void DeleteSceneFromStack() {
Scene *currentScene = getCurrentScene();
if (currentScene == NULL) return;
+ PopUpState currentSceneState = POPUP_ACTIVE;
+ if (currentScene != NULL)
+ currentSceneState = currentScene->GetCurrentState(currentScene);
currentScene->Deint(currentScene);
sceneStack[--sceneStackDepth] = NULL;
+
+ Scene *prevoiusScene = getCurrentScene();
+ if (prevoiusScene == NULL || prevoiusScene->Reopen == NULL) return;
+ prevoiusScene->Reopen(prevoiusScene, currentSceneState);
}
bool DrawScene() {
diff --git a/src/scenes/scenes.h b/src/scenes/scenes.h
index f4ba579..3c420d3 100644
--- a/src/scenes/scenes.h
+++ b/src/scenes/scenes.h
@@ -7,12 +7,18 @@
#define SCENE_STACK_SIZE 16
typedef enum {
+ /// The full screen blackout
POPUP_REVEALING,
- POPUP_REVEALING_ALT,
+ /// The popup of a transparent scene
+ POPUP_REVEALING_OVERLAY,
+ /// The scene is actively rendered
POPUP_ACTIVE,
+ /// The full screen blackout
POPUP_HIDING,
- POPUP_HIDING_ALT,
+ /// The popup of a transparent scene
+ POPUP_HIDING_OVERLAY,
} PopUpState;
+
static const int SCROLL_SPEED = 8;
static const int BLACKOUT_SPEED = 3;
@@ -23,6 +29,9 @@ typedef struct {
bool (*Update)(void *self);
bool (*Draw)(void *self);
void (*Deint)(void *self);
+ /// Is called when the scene becomes active after the next scene was popped
+ void (*Reopen)(void *self, PopUpState PreviousSceneState);
+ PopUpState (*GetCurrentState)(void *self);
/// A generic pointer to whatever data the scene needs. You will have to
/// cast it yourself
void *data;
diff --git a/src/ui_elements/Panel.c b/src/ui_elements/Panel.c
new file mode 100644
index 0000000..e9e6212
--- /dev/null
+++ b/src/ui_elements/Panel.c
@@ -0,0 +1,46 @@
+#include "UI.h"
+#include <raylib.h>
+
+void UpdatePanel(Panel *panel) {
+ if (panel == NULL) return;
+ for (size_t i = 0; i < panel->elementsCount; ++i) {
+ PanelElement *el = &panel->elements[i];
+ el->update(el->data);
+ }
+}
+
+void DrawPanel(Panel *panel, Rectangle rec, PanelDirection direction) {
+ if (panel == NULL) return;
+ float acc_x;
+
+ if (direction == RIGHT_TO_LEFT)
+ acc_x = rec.x + rec.width - PANEL_SPACING_PX;
+ else
+ acc_x = rec.x + PANEL_SPACING_PX;
+
+ for (size_t i = 0; i < panel->elementsCount; ++i) {
+ PanelElement *el = &panel->elements[i];
+ Rectangle targetRec = {
+ .x = rec.x + acc_x,
+ .y = rec.y,
+ .height = rec.height,
+ .width = rec.height * el->proportion,
+ };
+ if (direction == RIGHT_TO_LEFT) targetRec.x -= rec.height * el->proportion;
+ Rectangle zeroRec = {
+ .x = 0,
+ .y = 0,
+ .height = 0,
+ .width = 0,
+ };
+
+ el->draw(el, zeroRec);
+ if (direction == RIGHT_TO_LEFT) {
+ acc_x -= (targetRec.width + PANEL_SPACING_PX);
+ if (acc_x < rec.x) break;
+ } else {
+ acc_x += (targetRec.width + PANEL_SPACING_PX);
+ if (acc_x > rec.x + rec.width) break;
+ }
+ }
+}