summaryrefslogtreecommitdiff
path: root/src/scenes/collectionScene.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scenes/collectionScene.c')
-rw-r--r--src/scenes/collectionScene.c74
1 files changed, 74 insertions, 0 deletions
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 <raylib.h>
+#include <string.h>
+#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;
+}