diff --git a/src/dusk/display/tilesetdefs.h b/src/dusk/display/tilesetdefs.h index 62e0b76..ac47d3c 100644 --- a/src/dusk/display/tilesetdefs.h +++ b/src/dusk/display/tilesetdefs.h @@ -10,6 +10,7 @@ #define TILESET_SLOT_2 2 #define TILESET_SLOT_3 3 +#define TILESET_SLOT_UI TILESET_SLOT_0 #define TILESET_SLOT_ENTITIES TILESET_SLOT_1 #define TILESET_SLOT_MAP TILESET_SLOT_2 diff --git a/src/dusk/ui/uimenu.c b/src/dusk/ui/uimenu.c new file mode 100644 index 0000000..510ba54 --- /dev/null +++ b/src/dusk/ui/uimenu.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "uimenu.h" +#include "util/memory.h" +#include "assert/assert.h" +#include "input.h" + +void uiMenuInit( + uimenu_t *menu, + const uint8_t columns, + const uint8_t rows +) { + assertNotNull(menu, "Menu cannot be NULL."); + + memoryZero(menu, sizeof(uimenu_t)); + + menu->columns = columns; + menu->rows = rows; +} + +void uiMenuSetCursor( + uimenu_t *menu, + const uint8_t x, + const uint8_t y +) { + assertNotNull(menu, "Menu cannot be NULL."); + assert(x < menu->columns, "X position out of bounds."); + assert(y < menu->rows, "Y position out of bounds."); + + menu->x = x; + menu->y = y; +} + +void uiMenuMoveCursor( + uimenu_t *menu, + const int8_t x, + const int8_t y +) { + assertNotNull(menu, "Menu cannot be NULL."); + uiMenuSetCursor( + menu, + (menu->x + x) % menu->columns, + (menu->y + y) % menu->rows + ); +} + +uimenuaction_t uiMenuUpdate(uimenu_t *menu) { + assertNotNull(menu, "Menu cannot be NULL."); + +} \ No newline at end of file diff --git a/src/dusk/ui/uimenu.h b/src/dusk/ui/uimenu.h new file mode 100644 index 0000000..9188f54 --- /dev/null +++ b/src/dusk/ui/uimenu.h @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef enum { + UI_MENU_ACTION_NOTHING, + UI_MENU_ACTION_CURSOR_MOVE, + UI_MENU_ACTION_CURSOR_ACCEPT, + UI_MENU_ACTION_CURSOR_CANCEL +} uimenuaction_t; + +typedef struct { + uint8_t columns; + uint8_t rows; + uint8_t x; + uint8_t y; +} uimenu_t; + +/** + * Initializes a menu. + * + * @param menu The menu to initialize. + * @param columns The amount of columns in the menu. + * @param rows The amount of rows in the menu. + */ +void uiMenuInit( + uimenu_t *menu, + const uint8_t columns, + const uint8_t rows +); + +/** + * Sets the cursor of a menu. + * + * @param menu The menu to set the cursor of. + * @param x The x position of the cursor. + * @param y The y position of the cursor. + */ +void uiMenuSetCursor( + uimenu_t *menu, + const uint8_t x, + const uint8_t y +); + +/** + * Moves the cursor of a menu. + * + * @param menu The menu to move the cursor of. + * @param x The amount to move the cursor on the x axis. + * @param y The amount to move the cursor on the y axis. + */ +void uiMenuMoveCursor( + uimenu_t *menu, + const int8_t x, + const int8_t y +); + +/** + * Handles updating of a menu, this will accept input basically. + * + * @param menu The menu to update. + */ +uimenuaction_t uiMenuUpdate(uimenu_t *menu); \ No newline at end of file