summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-09-03 19:11:39 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-09-03 19:11:39 +0500
commitc88bb49416aaeb13c3969727a305bc7ed3263963 (patch)
tree997c136ee0cfc0a5ba6c153c78ab268d0195ac4a
parentaaefc10681cc2bcb30268c67de1a4784e0ca891f (diff)
more transitionsHEADmaster
-rw-r--r--src/puzzles/collection.c7
-rw-r--r--src/puzzles/puzzle.h4
-rw-r--r--src/scenes/collectionScene.c68
-rw-r--r--src/scenes/resultView.c4
-rw-r--r--src/scenes/sceneManager.c3
-rw-r--r--src/ui_elements/Button.c2
6 files changed, 72 insertions, 16 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c
index 5a46239..ea1a3b1 100644
--- a/src/puzzles/collection.c
+++ b/src/puzzles/collection.c
@@ -99,7 +99,7 @@ size_t getElementCount(DIR *dir, CollectionElement *el) {
return outp;
}
-void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionElement *)) {
+void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionElement *), void *callbackData) {
if (el == NULL) return;
TraceLog(LOG_INFO, "Initializing a collection element from %s/", el->path);
@@ -145,6 +145,7 @@ void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionEle
read_el->path = strdup(full_path_buf);
read_el->name = getName(entry->d_name);
read_el->callback = callback;
+ read_el->callbackData = callbackData;
idx += 1;
}
@@ -155,7 +156,7 @@ void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionEle
closedir(dir);
}
-void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *)) {
+void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *), void *callbackData) {
if (el == NULL) {
TraceLog(LOG_ERROR, "Failed to initialize collection element: the element is NULL");
return;
@@ -163,7 +164,7 @@ void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElem
switch (el->type) {
case COLLECTION_ELEMENT_PUZZLE: break;
case COLLECTION_ELEMENT_COLLECTION:
- initCollectionFromDir(el, callback);
+ initCollectionFromDir(el, callback, callbackData);
break;
default:
TraceLog(LOG_WARNING, "Invalid CollectionElement type for %s", el->path);
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index 5af6d6e..b269282 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -116,6 +116,8 @@ typedef struct CollectionElement {
size_t childCount;
/// OnClick callback
void (*callback)(struct CollectionElement *);
+ /// The data that will be passed with the callback
+ void *callbackData;
/// If the element is initialized it has children and an icon loaded into mem
bool IsInitialized;
/// The element has an icon
@@ -127,7 +129,7 @@ typedef struct CollectionElement {
/// Accepts an element which children will be created and a generic callback that
/// will be called when the collection enement is selected.
/// The element passes a selected element as a callback argummment
-void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *));
+void InitializeCollection(CollectionElement *el, void (*callback)(CollectionElement *), void *callbackData);
void DrawCollectionElement(CollectionElement *el, CollectionElement *parent, Rectangle rec);
void UpdateCollectionElement(CollectionElement *el);
void DeinitCollectionElement(CollectionElement *el);
diff --git a/src/scenes/collectionScene.c b/src/scenes/collectionScene.c
index f0f91f3..b8c1bc3 100644
--- a/src/scenes/collectionScene.c
+++ b/src/scenes/collectionScene.c
@@ -22,22 +22,51 @@ static const uint8_t ARROWS_ALPHA = 128;
static const float ELEMENT_WIDTH_RATIO = 0.45f;
typedef struct {
+ /// The collection we are displaying
CollectionElement *collection;
+ /// The collection we selected. Used in the transitions
CollectionElement *selected;
Button *backButton;
- size_t count;
float blackout_state;
PopUpState state;
float scroll;
} CollectionSceneData;
+
CollectionSceneData *getData(void *self) {
return ((Scene *)self)->data;
}
+PopUpState getCollectionSceneState(void *self) {
+ if (self == NULL) return POPUP_ACTIVE;
+ CollectionSceneData *data = getData(self);
+ if (data == NULL) return POPUP_ACTIVE;
+ return data->state;
+}
+
+
+void reopenCollectionScene(void *self, PopUpState PreviousSceneState) {
+ if (self == NULL) return;
+ CollectionSceneData *data = getData(self);
+ if (data == NULL) return;
+ if (data->state != POPUP_HIDING) printf("xdx\n");
+ switch (PreviousSceneState) {
+ case POPUP_HIDING:
+ data->state = POPUP_REVEALING;
+ data->blackout_state = 1.0f;
+ break;
+ default:
+ data->state = POPUP_ACTIVE;
+ break;
+ }
+}
+
static void backButton_onClick(Scene *self) {
- // CollectionSceneData *data = getData(self);
- DeleteSceneFromStack();
+ CollectionSceneData *data = getData(self);
+ data->state = POPUP_HIDING;
+ data->selected = NULL;
+ data->blackout_state = 0;
+ // DeleteSceneFromStack();
}
void collectionElement_onSelect(CollectionElement *caller) {
@@ -46,9 +75,18 @@ void collectionElement_onSelect(CollectionElement *caller) {
switch (caller->type) {
case COLLECTION_ELEMENT_PUZZLE:
AddScene(CreatePuzzlePreview(ReadPuzzleFromFile(caller->path)));
- break;
case COLLECTION_ELEMENT_COLLECTION:
- AddScene(CreatePuzzleCollectionScene(caller, false));
+ if (caller->callbackData == NULL) {
+ TraceLog(LOG_WARNING, "The callback data is NULL. Cannot initiate the smooth transition");
+ AddScene(CreatePuzzlePreview(ReadPuzzleFromFile(caller->path)));
+ } else {
+ TraceLog(LOG_WARNING, "The callback data is not NULL");
+ CollectionSceneData *data = ((Scene *)caller->callbackData)->data;
+ data->selected = caller;
+ data->state = POPUP_HIDING;
+ data->blackout_state = 0;
+ }
+ // AddScene(CreatePuzzleCollectionScene(caller, false));
break;
default:
TraceLog(LOG_WARNING, "Invalid CollectionElement type for %s", caller->path);
@@ -77,6 +115,7 @@ char *getCollectionName(char *path) {
bool updateCollectionScene(void *self) {
CollectionSceneData *data = getData(self);
+
if (data->state == POPUP_REVEALING) {
data->blackout_state -= BLACKOUT_SPEED * GetFrameTime();
if (data->blackout_state <= 0) {
@@ -87,6 +126,18 @@ bool updateCollectionScene(void *self) {
return true;
}
+ if (data->state == POPUP_HIDING) {
+ data->blackout_state += BLACKOUT_SPEED * GetFrameTime();
+ if (data->blackout_state >= 1) {
+ TraceLog(LOG_INFO, "Done hiding");
+ if (data->selected == NULL)
+ DeleteSceneFromStack();
+ else
+ AddScene(CreatePuzzleCollectionScene(data->selected, true));
+ }
+ return true;
+ }
+
if (data->collection != NULL) {
for (size_t i = 0; i < data->collection->childCount; ++i) {
UpdateCollectionElement(&data->collection->children[i]);
@@ -101,7 +152,6 @@ bool drawCollectionScene(void *self) {
CollectionSceneData *data = getData(self);
DrawBackground();
DrawCollectionName(data->collection->name);
- DrawPageView(GetScreenHeight() - 60, 5, 2);
if (data->backButton != NULL)
DrawButton(data->backButton, &(Rectangle) {
.x = 10,
@@ -180,8 +230,8 @@ Scene *CreatePuzzleCollectionScene(CollectionElement *el, bool smooothEntry) {
outp->Deint = deinitCollectionScene;
outp->IsTransparent = false;
- outp->Reopen = NULL;
- outp->GetCurrentState = NULL;
+ outp->Reopen = reopenCollectionScene;
+ outp->GetCurrentState = getCollectionSceneState;
CollectionSceneData *data = malloc(sizeof(CollectionSceneData));
if (data == NULL) {
@@ -189,7 +239,7 @@ Scene *CreatePuzzleCollectionScene(CollectionElement *el, bool smooothEntry) {
return NULL;
}
- if (!el->IsInitialized) InitializeCollection(el, collectionElement_onSelect);
+ if (!el->IsInitialized) InitializeCollection(el, collectionElement_onSelect, outp);
data->collection = el;
data->selected = NULL;
data->state = smooothEntry? POPUP_REVEALING : POPUP_ACTIVE;
diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c
index add28ea..842c824 100644
--- a/src/scenes/resultView.c
+++ b/src/scenes/resultView.c
@@ -79,9 +79,11 @@ Scene *CreateResultView(SubmitionResult *result) {
outp->Draw = drawResultView;
outp->Update = updateResultView;
outp->Deint = deinitResultView;
- outp->Reopen = NULL;
outp->IsTransparent = true;
+ outp->Reopen = NULL;
+ outp->GetCurrentState = NULL;
+
ResultViewData *data = malloc(sizeof(ResultViewData));
if (data == NULL) {
free(outp);
diff --git a/src/scenes/sceneManager.c b/src/scenes/sceneManager.c
index 8baa18e..c1ed257 100644
--- a/src/scenes/sceneManager.c
+++ b/src/scenes/sceneManager.c
@@ -36,8 +36,9 @@ void DeleteSceneFromStack() {
Scene *currentScene = getCurrentScene();
if (currentScene == NULL) return;
PopUpState currentSceneState = POPUP_ACTIVE;
- if (currentScene->GetCurrentState != NULL)
+ if (currentScene->GetCurrentState != NULL) {
currentSceneState = currentScene->GetCurrentState(currentScene);
+ }
currentScene->Deint(currentScene);
sceneStack[--sceneStackDepth] = NULL;
diff --git a/src/ui_elements/Button.c b/src/ui_elements/Button.c
index e7293c8..a12e3a7 100644
--- a/src/ui_elements/Button.c
+++ b/src/ui_elements/Button.c
@@ -2,7 +2,7 @@
#include <raylib.h>
void UpdateButton(Button *btn) {
- if (IsMouseInRec(btn->previousFramePosition) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+ if (IsMouseInRec(btn->previousFramePosition) && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
btn->OnClick(btn->parent);
}
}