diff options
Diffstat (limited to 'src/puzzles/collection.c')
| -rw-r--r-- | src/puzzles/collection.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c index bb95eba..8abc3fa 100644 --- a/src/puzzles/collection.c +++ b/src/puzzles/collection.c @@ -1,6 +1,9 @@ #include <dirent.h> #include "puzzle.h" +#include "../resources/resources.h" +#include "../ui_elements/UI.h" #include <raylib.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> @@ -28,6 +31,15 @@ bool isIcon(struct dirent *entry) { void addIcon(CollectionElement *el, struct dirent *entry) { if (el == NULL || entry == NULL) return; char fullPath[1024]; + snprintf(fullPath, sizeof(fullPath), "%s/%s", el->path, entry->d_name); +} + +bool isPuzzle(char *path) { + size_t entry_name_len = strlen(path); + if (entry_name_len < 4) return false; + char *last_bytes = path + entry_name_len - 3; + if (strncmp(last_bytes, ".pz", 3) != 0) return false; + return true; } bool isElement(struct dirent *entry, char *basePath) { @@ -41,12 +53,23 @@ bool isElement(struct dirent *entry, char *basePath) { if (stat(full_path_buf, &st) != 0) return false; if (S_ISDIR(st.st_mode)) return true; - size_t entry_name_len = strlen(entry->d_name); - if (entry_name_len < 4) return false; - char *last_bytes = entry->d_name + entry_name_len - 3; - if (strncmp(last_bytes, ".pz", 3) != 0) return false; + return isPuzzle(entry->d_name); +} - return true; +char *getName(char *name) { + char buf[1024]; + strncpy(buf, name, sizeof(buf)); + size_t len = strlen(name); + + // Cutting a file extention + for (size_t i = 0; i < len; ++i) { + if (buf[i] == '.') { + buf[i] = 0x0; + break; + } + } + + return strdup(buf); } size_t getElementCount(DIR *dir, CollectionElement *el) { @@ -102,6 +125,8 @@ void initCollectionFromDir(CollectionElement *el) { } read_el->IsInitialized = false; read_el->path = strdup(full_path_buf); + read_el->name = getName(entry->d_name); + read_el->icon = NULL; idx += 1; } @@ -124,3 +149,20 @@ void InitializeCollection(CollectionElement *el) { break; } } + +void DrawCollectionElement(CollectionElement *el, Rectangle rec) { + if (el == NULL) return; + if (el->icon != NULL) { + printf("xdx\n"); + DrawTexturePro(*el->icon, (Rectangle) { + .x = 0, + .y = 0, + .width = el->icon->width, + .height = el->icon->height, + }, rec, (Vector2) { .x = 0, .y = 0 }, 0, WHITE); + } else { + DrawRecBordered(rec, COLORSCHEME_WHITE, COLORSCHEME_ORANGE, BORDER); + } + int scroll = 0; + DrawTextInRec(rec, el->name, GetMainFont(), 20, COLORSCHEME_BROWN, 1, &scroll); +} |
