summaryrefslogtreecommitdiff
path: root/src/scenes/collectionScene.c
blob: 217361971c920c1e7bdfa42d0ba0df3c89658af8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
}