From 0a339a5e6412235c7aa519479a61ca8bbc0c95c4 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 20 Feb 2022 19:26:06 -0800 Subject: [PATCH] bruh? --- src/conversation/textbox.c | 59 +++++++++++++++++++++++++++++--------- src/conversation/textbox.h | 1 + src/input.h | 2 ++ 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index c9f21d6..63e5b1a 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -52,16 +52,17 @@ inline void conversationTextboxInit() { void conversationTextboxSetText(char *text) { uint8_t i, j, k, rowStart, stateFlags; 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++) { - TEXTBOX_TEXTS[i] = '4'; + TEXTBOX_TEXTS[i] = ' '; } // Reset textbox state TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE; TEXTBOX_SCROLL = 0; + TEXTBOX_ROW_COUNT = 0; TEXTBOX_ROW_CURRENT = 0; + TEXTBOX_ROW_COUNT = 1; // Copy source text to buffer, also determine wordwrapping here. i = 0, j = 0, rowStart = 0, stateFlags = 0; @@ -69,15 +70,16 @@ void conversationTextboxSetText(char *text) { if(c == ' ') { // Scan ahead and look at how many chars remain to the next space k = i + 1; - while((c2 = text[k]) != '\0') { - if(c2 == '\n' || c2 == ' ') break; - if((k - rowStart) >= TEXTBOX_CHARS_PER_ROW) break; - k++; - } + while( + (c2 = text[k]) != '\0' && + c2 != '\n' && + c2 != ' ' && + (k - rowStart) < TEXTBOX_CHARS_PER_ROW + ) k++; // IF that number is less than the remaining chars on the current row, // 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; } } else if(c == '\n') { @@ -87,9 +89,10 @@ void conversationTextboxSetText(char *text) { // Do we need to newline? if((stateFlags & (1 << 0)) != 0) { stateFlags &= ~(1 << 0); - rowStart += TEXTBOX_CHARS_PER_ROW; - j = rowStart; + rowStart = i; + j = ((j / TEXTBOX_CHARS_PER_ROW) + 1) * TEXTBOX_CHARS_PER_ROW; i++; + TEXTBOX_ROW_COUNT++; continue; } @@ -100,19 +103,27 @@ void conversationTextboxSetText(char *text) { // Now we have organized the string nicely we can prep for rendering. Fill the // 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(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) { TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK; } } + set_win_tiles( 0x01, 0x01, TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02, TEXTBOX_TILES ); - - // Show the window layer. - SHOW_WIN; } inline void conversationTextboxUpdate() { @@ -123,12 +134,32 @@ inline void conversationTextboxUpdate() { // Is the textbox visible? 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. i = TEXTBOX_ROW_CURRENT * TEXTBOX_CHARS_PER_ROW; c = TEXTBOX_TEXTS[i+TEXTBOX_SCROLL]; if(TEXTBOX_SCROLL == TEXTBOX_CHARS_MAX) { - // TEXTBOX_ + TEXTBOX_STATE |= TEXTBOX_STATE_SCROLLED; } else { tiles[0] = c - 33 + 4; set_win_tiles( diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index ca97ea8..00b1100 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -54,4 +54,5 @@ extern uint8_t TEXTBOX_SCROLL; inline void conversationTextboxInit(); void conversationTextboxSetText(char *text); +inline void textboxFillBlank(); inline void conversationTextboxUpdate(); \ No newline at end of file diff --git a/src/input.h b/src/input.h index c0d87ff..276c378 100644 --- a/src/input.h +++ b/src/input.h @@ -8,4 +8,6 @@ #pragma once #include "libs.h" +#define INPUT_BIND_TEXT_SKIP J_A + extern uint8_t INPUT_STATE; \ No newline at end of file