#include #include #include "scenes.h" #include "../resources/resources.h" #include "../ui_elements/UI.h" typedef struct { Puzzle *PuzzlePtr; TextArea *EditorInfo; int scroll; } puzzleSceneData; const int HEADER_FONT_SIZE = 50; const int PADDING = 10; const int BORDER = 2; const int FOOTER_HEIGHT = 40; void DrawPuzzleName(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); } Rectangle GetBodyRect() { int HeaderOffset = PADDING * 2 + HEADER_FONT_SIZE; Rectangle outp = { .x = PADDING, .y = HeaderOffset, .width = GetScreenWidth() - PADDING * 2, .height = GetScreenHeight() - HeaderOffset - PADDING * 3 - FOOTER_HEIGHT, }; return outp; } void GetPanesSplit(Rectangle *pane1, Rectangle *pane2, Rectangle body, float proportion_h, float proportion_v) { if (body.height >= body.width) { // vertical split pane1->x = body.x; pane1->y = body.y; pane1->width = body.width; pane1->height = (body.height - PADDING) * proportion_v; pane2->x = body.x; pane2->y = body.y + pane1->height + PADDING; pane2->width = body.width; pane2->height = (body.height - PADDING) * (1 - proportion_v); return; } // horizontal split pane1->x = body.x; pane1->y = body.y; pane1->height = body.height; pane1->width = (body.width - PADDING) * proportion_h; pane2->y = body.y; pane2->x = body.x + pane1->width + PADDING; pane2->height = body.height; pane2->width = (body.width - PADDING) * (1 - proportion_h); } bool drawPuzzleScene(void *self) { puzzleSceneData *data = ((Scene *)self)->data; DrawBackground(); DrawPuzzleName(data->PuzzlePtr->Name); Rectangle body = GetBodyRect(); // DrawRecBordered(body, WHITE, COLORSCHEME_ORANGE, BORDER); // DrawTextArea(data->EditorInfo, body, GetMonoFont(), 20, 2, &data->editor_scroll); // return true; Rectangle pane1, pane2; GetPanesSplit(&pane1, &pane2, body, 0.35, 0.4); DrawRecBordered(pane1, WHITE, COLORSCHEME_ORANGE, BORDER); DrawRecBordered(pane2, WHITE, COLORSCHEME_ORANGE, BORDER); DrawTextInRec(pane1, data->PuzzlePtr->Description, GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll); DrawTextArea(data->EditorInfo, pane2); return true; } bool updatePuzzleScene(void *self) { puzzleSceneData *data = ((Scene *)self)->data; Rectangle body = GetBodyRect(); Rectangle pane1, pane2; GetPanesSplit(&pane1, &pane2, body, 0.35, 0.4); UpdateTextArea(data->EditorInfo, pane2); if (IsKeyPressed(KEY_F5)) { char *script = GetText(data->EditorInfo); SubmitionResult *res = SubmitSolution(data->PuzzlePtr, script); if (res != NULL) AddScene(CreateResultView(res)); } return true; } void deinitPuzzleScene(void *self) { puzzleSceneData *data = ((Scene *)self)->data; TraceLog(LOG_INFO, "Deleting a puzzle scene"); FreeTextArea(data->EditorInfo); free(data); free((Scene *)self); } Scene *CreatePuzzleScene(Puzzle *puzzle) { Scene *outp = malloc(sizeof(Scene)); outp->Update = updatePuzzleScene; outp->Draw = drawPuzzleScene; outp->Deint = deinitPuzzleScene; outp->IsTransparent = false; puzzleSceneData *data = malloc(sizeof(puzzleSceneData)); data->PuzzlePtr = puzzle; TextAreaDisplayParams *EditorDisplayParams = malloc(sizeof(TextAreaDisplayParams)); if (EditorDisplayParams != NULL) { EditorDisplayParams->font = GetMonoFont(); EditorDisplayParams->spacing = 1; EditorDisplayParams->font_size = 20; // this will change EditorDisplayParams->scroll_h = 0; EditorDisplayParams->scroll_v = 0; } if (puzzle->InitialCode != NULL) { data->EditorInfo = CreateTextAreaFromText(EditorDisplayParams, puzzle->InitialCode); } else { data->EditorInfo = CreateTextArea(EditorDisplayParams); } outp->data = data; return outp; }