unfinished ui textbox

This commit is contained in:
2025-06-21 23:14:24 -05:00
parent 907d3234a9
commit 0ed65d3703
22 changed files with 553 additions and 11 deletions

View File

@ -8,4 +8,5 @@ target_sources(${DUSK_TARGET_NAME}
PRIVATE
drawscene.c
drawoverworld.c
drawui.c
)

View File

@ -47,7 +47,6 @@ void drawOverworldDraw(void) {
};
uint8_t colorCount = sizeof(colors) / sizeof(Color);
BeginBlendMode(BLEND_ALPHA_PREMULTIPLY);
do {
// Base layer
for(uint8_t i = 0; i < CHUNK_TILE_COUNT; i++) {
@ -99,7 +98,6 @@ void drawOverworldDraw(void) {
chunk++;
} while(chunk < CHUNK_MAP.chunks + CHUNK_MAP_COUNT);
EndBlendMode();
// Entities
entity_t *entity = ENTITIES;

View File

@ -0,0 +1,83 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "drawui.h"
#include "ui/uitextbox.h"
#include "util/memory.h"
#include "assert/assert.h"
void drawUIInit(void) {
}
void drawUI() {
drawUITextbox();
}
void drawUITextbox() {
if(!UI_TEXTBOX.visible) return;
// Semi-transparent dark blue
Color background = (Color){ 0, 0, 128, 128 };
DrawRectangle(
0, RENDER_HEIGHT - UI_TEXTBOX_HEIGHT,
UI_TEXTBOX_WIDTH, UI_TEXTBOX_HEIGHT,
background
);
BeginBlendMode(BLEND_ALPHA);
if(UI_TEXTBOX.charsRevealed > 0) {
char_t buffer[UI_TEXTBOX_CHARS_PER_LINE + 1];// +1 for null term
uint8_t charsRendered = 0;
// For each line
for(uint8_t i = 0; i < UI_TEXTBOX_LINES_PER_PAGE; i++) {
// Get count of chars in the line
uint8_t lineLength = UI_TEXTBOX.lineLengths[i];
if(lineLength == 0) continue;
// Determine how many chars left to render
uint8_t lineChars = UI_TEXTBOX.charsRevealed - charsRendered;
// Don't render more than in line
if(lineChars > lineLength) lineChars = lineLength;
assertTrue(lineChars > 0, "Line chars must be greater than 0");
// Update how many rendered
charsRendered += lineChars;
// Copy string from VN Textbox...
memoryCopy(
buffer,
UI_TEXTBOX.text + (UI_TEXTBOX.page * UI_TEXTBOX_PAGE_CHARS) +
(i * UI_TEXTBOX_CHARS_PER_LINE),
lineChars
);
// Null term string
buffer[lineChars] = '\0'; // Null-terminate the string
// Render the text
DrawText(
buffer,
UI_TEXTBOX_PADDING_X + UI_TEXTBOX_BORDER_WIDTH,
(
(RENDER_HEIGHT - UI_TEXTBOX_HEIGHT) +
UI_TEXTBOX_PADDING_Y + UI_TEXTBOX_BORDER_HEIGHT +
(i * FONT_LINE_HEIGHT)
),
FONT_HEIGHT,
WHITE
);
// Check if we're done rendering text
if(UI_TEXTBOX.charsRevealed - charsRendered == 0) break;
}
}
EndBlendMode();
}

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "duskraylib.h"
/**
* Initializes the UI drawing system.
*/
void drawUIInit(void);
/**
* Draws all the UI elements to the screen in the correct order.
*/
void drawUI(void);
/**
* Draws the UI textbox to the screen.
*/
void drawUITextbox(void);

View File

@ -8,6 +8,7 @@
#include "render.h"
#include "display/draw/drawscene.h"
#include "display/draw/drawoverworld.h"
#include "display/draw/drawui.h"
#include "assert/assert.h"
RenderTexture2D RENDER_SCREEN_TEXTURE;
@ -32,14 +33,17 @@ void renderInit(void) {
RENDER_ENTITIES_TEXTURE = LoadTexture("../data/entities.png");
drawOverworldInit();
drawUIInit();
}
void renderDraw(void) {
// Draw the actual game.
BeginBlendMode(BLEND_ALPHA_PREMULTIPLY);
BeginTextureMode(RENDER_SCREEN_TEXTURE);
ClearBackground(BLACK);
drawScene();
drawUI();
EndTextureMode();
@ -69,7 +73,10 @@ void renderDraw(void) {
0.0f,
WHITE
);
EndDrawing();
EndBlendMode();
}
void renderDispose(void) {