diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-09-03 01:54:55 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-09-03 01:54:55 +0500 |
| commit | 2f811f69c13c3ad9b05d15e6510192a7dde95c71 (patch) | |
| tree | f65eda3ceef69243de609560c24538e9bf38c7b1 /src/scenes | |
| parent | da295397942073453ed9f82cc88dafd083d4c782 (diff) | |
scene reopen API
Diffstat (limited to 'src/scenes')
| -rw-r--r-- | src/scenes/collectionScene.c | 3 | ||||
| -rw-r--r-- | src/scenes/distractionScene.c | 2 | ||||
| -rw-r--r-- | src/scenes/mainMenu.c | 2 | ||||
| -rw-r--r-- | src/scenes/puzzlePreviewScene.c | 14 | ||||
| -rw-r--r-- | src/scenes/puzzleScene.c | 3 | ||||
| -rw-r--r-- | src/scenes/puzzleSelectionScene.c | 2 | ||||
| -rw-r--r-- | src/scenes/resultView.c | 1 | ||||
| -rw-r--r-- | src/scenes/sceneManager.c | 7 | ||||
| -rw-r--r-- | src/scenes/scenes.h | 13 |
9 files changed, 43 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; |
