This commit is contained in:
2022-02-20 19:26:06 -08:00
parent 59571f6089
commit 0a339a5e64
3 changed files with 48 additions and 14 deletions

View File

@@ -52,16 +52,17 @@ inline void conversationTextboxInit() {
void conversationTextboxSetText(char *text) { void conversationTextboxSetText(char *text) {
uint8_t i, j, k, rowStart, stateFlags; uint8_t i, j, k, rowStart, stateFlags;
char c, c2; char c, c2;
uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW];
for(i = 0; i < TEXTBOX_SCROLL_ROWS_MAX * TEXTBOX_CHARS_PER_ROW; i++) { for(i = 0; i < TEXTBOX_SCROLL_ROWS_MAX * TEXTBOX_CHARS_PER_ROW; i++) {
TEXTBOX_TEXTS[i] = '4'; TEXTBOX_TEXTS[i] = ' ';
} }
// Reset textbox state // Reset textbox state
TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE; TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE;
TEXTBOX_SCROLL = 0; TEXTBOX_SCROLL = 0;
TEXTBOX_ROW_COUNT = 0;
TEXTBOX_ROW_CURRENT = 0; TEXTBOX_ROW_CURRENT = 0;
TEXTBOX_ROW_COUNT = 1;
// Copy source text to buffer, also determine wordwrapping here. // Copy source text to buffer, also determine wordwrapping here.
i = 0, j = 0, rowStart = 0, stateFlags = 0; i = 0, j = 0, rowStart = 0, stateFlags = 0;
@@ -69,15 +70,16 @@ void conversationTextboxSetText(char *text) {
if(c == ' ') { if(c == ' ') {
// Scan ahead and look at how many chars remain to the next space // Scan ahead and look at how many chars remain to the next space
k = i + 1; k = i + 1;
while((c2 = text[k]) != '\0') { while(
if(c2 == '\n' || c2 == ' ') break; (c2 = text[k]) != '\0' &&
if((k - rowStart) >= TEXTBOX_CHARS_PER_ROW) break; c2 != '\n' &&
k++; c2 != ' ' &&
} (k - rowStart) < TEXTBOX_CHARS_PER_ROW
) k++;
// IF that number is less than the remaining chars on the current row, // IF that number is less than the remaining chars on the current row,
// then treat this space like a newline. // then treat this space like a newline.
if(k == (rowStart + TEXTBOX_CHARS_PER_ROW)) { if(k >= (rowStart + TEXTBOX_CHARS_PER_ROW - 1)) {
stateFlags |= 1 << 0; stateFlags |= 1 << 0;
} }
} else if(c == '\n') { } else if(c == '\n') {
@@ -87,9 +89,10 @@ void conversationTextboxSetText(char *text) {
// Do we need to newline? // Do we need to newline?
if((stateFlags & (1 << 0)) != 0) { if((stateFlags & (1 << 0)) != 0) {
stateFlags &= ~(1 << 0); stateFlags &= ~(1 << 0);
rowStart += TEXTBOX_CHARS_PER_ROW; rowStart = i;
j = rowStart; j = ((j / TEXTBOX_CHARS_PER_ROW) + 1) * TEXTBOX_CHARS_PER_ROW;
i++; i++;
TEXTBOX_ROW_COUNT++;
continue; continue;
} }
@@ -100,19 +103,27 @@ void conversationTextboxSetText(char *text) {
// Now we have organized the string nicely we can prep for rendering. Fill the // Now we have organized the string nicely we can prep for rendering. Fill the
// tiles with blank chars. // tiles with blank chars.
textboxFillBlank();
// Show the window layer.
SHOW_WIN;
}
inline void textboxFillBlank() {
uint8_t i, j;
uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW];
for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) { for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) {
for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) { for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) {
TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK; TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK;
} }
} }
set_win_tiles( set_win_tiles(
0x01, 0x01, 0x01, 0x01,
TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02, TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02,
TEXTBOX_TILES TEXTBOX_TILES
); );
// Show the window layer.
SHOW_WIN;
} }
inline void conversationTextboxUpdate() { inline void conversationTextboxUpdate() {
@@ -123,12 +134,32 @@ inline void conversationTextboxUpdate() {
// Is the textbox visible? // Is the textbox visible?
if((TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE) == 0) return; if((TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE) == 0) return;
// Have we finished scrolling?
if(TEXTBOX_STATE & TEXTBOX_STATE_SCROLLED) {
// Is the user trying to go to the next line?
BGB_printf("has scrolled");
if(INPUT_STATE & INPUT_BIND_TEXT_SKIP) {
// First, lets figure out if there's any more text to reveal or not.
if((TEXTBOX_ROW_COUNT - TEXTBOX_ROW_CURRENT) >= TEXTBOX_TILES_ROWS) {
TEXTBOX_STATE &= ~TEXTBOX_STATE_VISIBLE;
return;
}
TEXTBOX_STATE &= ~(TEXTBOX_STATE_SCROLLED);
TEXTBOX_ROW_CURRENT += TEXTBOX_TILES_ROWS;
textboxFillBlank();
BGB_printf("tst");
}
return;
}
// Move to the next character. // Move to the next character.
i = TEXTBOX_ROW_CURRENT * TEXTBOX_CHARS_PER_ROW; i = TEXTBOX_ROW_CURRENT * TEXTBOX_CHARS_PER_ROW;
c = TEXTBOX_TEXTS[i+TEXTBOX_SCROLL]; c = TEXTBOX_TEXTS[i+TEXTBOX_SCROLL];
if(TEXTBOX_SCROLL == TEXTBOX_CHARS_MAX) { if(TEXTBOX_SCROLL == TEXTBOX_CHARS_MAX) {
// TEXTBOX_ TEXTBOX_STATE |= TEXTBOX_STATE_SCROLLED;
} else { } else {
tiles[0] = c - 33 + 4; tiles[0] = c - 33 + 4;
set_win_tiles( set_win_tiles(

View File

@@ -54,4 +54,5 @@ extern uint8_t TEXTBOX_SCROLL;
inline void conversationTextboxInit(); inline void conversationTextboxInit();
void conversationTextboxSetText(char *text); void conversationTextboxSetText(char *text);
inline void textboxFillBlank();
inline void conversationTextboxUpdate(); inline void conversationTextboxUpdate();

View File

@@ -8,4 +8,6 @@
#pragma once #pragma once
#include "libs.h" #include "libs.h"
#define INPUT_BIND_TEXT_SKIP J_A
extern uint8_t INPUT_STATE; extern uint8_t INPUT_STATE;