From d51d95b66dee211ef654693fb23238d5a234f48c Mon Sep 17 00:00:00 2001 From: physick Date: Sat, 29 Aug 2026 14:12:24 +0500 Subject: merged branches --- src/scenes/collectionScene.c | 74 +++++++++++++++++++++++++++++++++++++++++++ src/scenes/distractionScene.c | 2 -- src/scenes/puzzleScene.c | 5 --- src/scenes/resultView.c | 1 - src/scenes/scenes.h | 2 ++ 5 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 src/scenes/collectionScene.c (limited to 'src/scenes') diff --git a/src/scenes/collectionScene.c b/src/scenes/collectionScene.c new file mode 100644 index 0000000..2173619 --- /dev/null +++ b/src/scenes/collectionScene.c @@ -0,0 +1,74 @@ +#include "scenes.h" +#include +#include +#include "../ui_elements/UI.h" +#include "../resources/resources.h" + +typedef struct { + char *DirPath; + char *Name; +} CollectionSceneData; + +CollectionSceneData *getData(void *self) { + return ((Scene *)self)->data; +} + +void DrawCollectionName(char *name) { + Vector2 width = MeasureTextEx(*GetMainFont(), name, 50, 1); + int screen_width = GetScreenWidth(); + Vector2 pos = { .y = 20, .x = (screen_width - width.x) / 2, }; + DrawTextEx(*GetMainFont(), name, pos, HEADER_FONT_SIZE, 1, COLORSCHEME_BROWN); +} + +// Does not allocate the memory +char *getCollectionName(char *path) { + char *outp = path; + size_t len = strlen(path); + for (size_t i = 0; i < len; ++i) { + if ((path[i] == '/' || path[i] == '\\') && path[i+1] != 0x0) { + outp = path + i + 1; + } + } + return outp; +} + +bool updateCollectionScene(void *self) { + return true; +} + +bool drawCollectionScene(void *self) { + CollectionSceneData *data = getData(self); + DrawBackground(); + DrawCollectionName(data->Name); + DrawPageView(GetScreenHeight() - 60, 5, 2); + return true; +} + +void deinitCollectionScene(void *self) { + TraceLog(LOG_INFO, "Deleting a collection scene"); + CollectionSceneData *data = getData(self); + if (data != NULL) free(data); + free((Scene *)self); +} + +Scene *CreatePuzzleCollectionScene(char *path) { + TraceLog(LOG_INFO, "Creating a collection scene"); + Scene *outp = malloc(sizeof(Scene)); + if (outp == NULL) return NULL; + outp->Update = updateCollectionScene; + outp->Draw = drawCollectionScene; + outp->Deint = deinitCollectionScene; + outp->IsTransparent = false; + + CollectionSceneData *data = malloc(sizeof(CollectionSceneData)); + if (data == NULL) { + free(outp); + return NULL; + } + data->DirPath = strdup(path); + data->Name = getCollectionName(path); + + outp->data = data; + + return outp; +} diff --git a/src/scenes/distractionScene.c b/src/scenes/distractionScene.c index 1f12aae..f249b53 100644 --- a/src/scenes/distractionScene.c +++ b/src/scenes/distractionScene.c @@ -5,8 +5,6 @@ #include "../resources/resources.h" static const float BODY_PADDING = 0.05f; -static const int BORDER = 2; -static const int EDITOR_PADDING = 3; typedef struct { DistractionPuzzle *puzzle; diff --git a/src/scenes/puzzleScene.c b/src/scenes/puzzleScene.c index c3e48c1..1671cf8 100644 --- a/src/scenes/puzzleScene.c +++ b/src/scenes/puzzleScene.c @@ -17,11 +17,6 @@ typedef struct { float time_acc; } puzzleSceneData; -const int HEADER_FONT_SIZE = 50; -const int EDITOR_PADDING = 3; -const int BORDER = 2; -const int FOOTER_HEIGHT = 30; - // Time in seconds const size_t BASE_TIME_LEFT = 1; // 5 * 60; diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c index 1cbc182..e51898e 100644 --- a/src/scenes/resultView.c +++ b/src/scenes/resultView.c @@ -7,7 +7,6 @@ #include "../ui_elements/UI.h" #include "../resources/resources.h" -static const int BORDER = 2; static const int SCROLL_SPEED = 10; static const uint8_t MAX_TINT = 96; diff --git a/src/scenes/scenes.h b/src/scenes/scenes.h index 335a139..828f2f3 100644 --- a/src/scenes/scenes.h +++ b/src/scenes/scenes.h @@ -33,4 +33,6 @@ Scene *CreatePuzzleScene(Puzzle *puzzle); Scene *CreateDistractionScene(DistractionPuzzle *puzzle, void (*addTime)(Scene *, size_t)); Scene *CreateResultView(SubmitionResult *result); +Scene *CreatePuzzleCollectionScene(char *path); + #endif // SCENES_H -- cgit v1.3