Working on UI MEnu

This commit is contained in:
2025-03-05 19:06:43 -06:00
parent 05bdd76508
commit b9de46a16b
3 changed files with 125 additions and 0 deletions

View File

@ -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

55
src/dusk/ui/uimenu.c Normal file
View File

@ -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.");
}

69
src/dusk/ui/uimenu.h Normal file
View File

@ -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);