Finished basic question box

This commit is contained in:
2022-04-30 09:48:00 -07:00
parent 768c73bba5
commit bee024c3e1
7 changed files with 74 additions and 24 deletions

View File

@@ -11,26 +11,77 @@ uint8_t QUESTION_BOX_OPTION_COUNT;
uint8_t QUESTION_BOX_OPTION_CURRENT;
void questionBoxSetOptions(char *title, char **options, uint8_t count) {
uint8_t i;
uint8_t i, j;
char buffer[TEXTBOX_CHARS_MAX + 1];
char spaces[QUESTION_BOX_QUESTION_SPACES];
sprintf(buffer, title);
i = 0;
QUESTION_BOX_OPTION_CURRENT = 0;
QUESTION_BOX_OPTION_COUNT = count;
for(i = 0; i < QUESTION_BOX_QUESTION_SPACES; i++) {
spaces[i] = ' ';
}
// For each row...
for(i = 0; i < count; i++) {
if((i & 1) == 0) {
j = strlen(options[i]);
sprintf(buffer, "%s\n %s", buffer, options[i]);
} else {
sprintf(buffer, "%s %s", buffer, options[i]);
j = QUESTION_BOX_QUESTION_SPACES - j;
spaces[j + 1] = '\0';
sprintf(buffer, "%s%s%s", buffer, spaces, options[i]);
spaces[j + 1] = ' ';
}
}
conversationTextboxSetText(buffer);
// Modify the textbox state
TEXTBOX_STATE |= TEXTBOX_STATE_IS_QUESTION;
// Repurpose old array and draw arrow
spaces[0] = QUESTION_BOX_CURSOR - TEXTBOX_FONT_START + FONT_DATA_POSITION;
set_bkg_tiles(0x01, TEXTBOX_WIN_Y + 0x02, 1, 1, spaces);
}
inline void questionBoxUpdate() {
uint8_t tiles[1];
uint8_t i;
if((TEXTBOX_STATE & (TEXTBOX_STATE_VISIBLE|TEXTBOX_STATE_IS_QUESTION)) == 0) return;
// Detect input
if(INPUT_PRESSED & J_RIGHT) {
QUESTION_BOX_OPTION_CURRENT++;
} else if(INPUT_PRESSED & J_LEFT) {
QUESTION_BOX_OPTION_CURRENT--;
} else if(INPUT_PRESSED & J_UP) {
QUESTION_BOX_OPTION_CURRENT -= 2;
} else if(INPUT_PRESSED & J_DOWN) {
QUESTION_BOX_OPTION_CURRENT += 2;
} else {
return;
}
// Bound.
QUESTION_BOX_OPTION_CURRENT = QUESTION_BOX_OPTION_CURRENT % QUESTION_BOX_OPTION_COUNT;
// Decide where to render arrow
for(i = 0; i < QUESTION_BOX_OPTION_COUNT; i++) {
if(i == QUESTION_BOX_OPTION_CURRENT) {
tiles[0] = QUESTION_BOX_CURSOR - TEXTBOX_FONT_START + FONT_DATA_POSITION;
} else {
tiles[0] = ' ' - TEXTBOX_FONT_START + FONT_DATA_POSITION;
}
set_bkg_tiles(
0x01 + ((i % 0x02) * QUESTION_BOX_QUESTION_SPACES),
TEXTBOX_WIN_Y + 0x02 + (i / 0x02),
1, 1,
tiles
);
}
}

View File

@@ -15,6 +15,8 @@
#include "textbox.h"
#define QUESTION_BOX_OPTIONS_MAX ((TEXTBOX_CHAR_ROWS-1)*2)
#define QUESTION_BOX_CURSOR '>'
#define QUESTION_BOX_QUESTION_SPACES 9
extern uint8_t QUESTION_BOX_OPTION_COUNT;
extern uint8_t QUESTION_BOX_OPTION_CURRENT;

View File

@@ -57,7 +57,7 @@ void conversationTextboxSetText(char *text) {
// 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 - 1)) {
if(k >= (rowStart + TEXTBOX_CHARS_PER_ROW + 1)) {
stateFlags |= 1 << 0;
}
} else if(c == '\n') {
@@ -70,7 +70,7 @@ void conversationTextboxSetText(char *text) {
i++;
rowStart = i;// Update the row start (Should this be i+1?)
//TODO: can I optimize the next line by using rowStart somehow?
j = ((j / TEXTBOX_CHARS_PER_ROW) + 1) * TEXTBOX_CHARS_PER_ROW;// Update destination character position.
j = ((j / TEXTBOX_CHARS_PER_ROW)+1) * TEXTBOX_CHARS_PER_ROW;// Update destination character position.
TEXTBOX_ROW_COUNT++;
continue;
}
@@ -109,7 +109,7 @@ inline void conversationTextboxUpdate() {
// Have we finished scrolling?
if(TEXTBOX_STATE & TEXTBOX_STATE_SCROLLED) {
// Is the user trying to go to the next line?
if(INPUT_STATE & J_A) {
if(INPUT_PRESSED & J_A) {
// 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;

View File

@@ -16,6 +16,7 @@
#define TEXTBOX_STATE_VISIBLE (1 << 0)
#define TEXTBOX_STATE_SCROLLED (1 << 1)
#define TEXTBOX_STATE_IS_QUESTION (1 << 2)
#define TEXTBOX_WIDTH_IN_TILES 20
#define TEXTBOX_HEIGHT_IN_TILES 5

View File

@@ -8,3 +8,5 @@
#include "input.h"
uint8_t INPUT_STATE = 0x00;
uint8_t INPUT_PRESSED = 0x00;
uint8_t INPUT_LAST = 0x00;

View File

@@ -9,3 +9,5 @@
#include "libs.h"
extern uint8_t INPUT_STATE;
extern uint8_t INPUT_PRESSED;
extern uint8_t INPUT_LAST;

View File

@@ -159,7 +159,6 @@ inline void mainDebugDraw() {
void main() {
int16_t j;
uint8_t filled[GB_BACKGROUND_COLUMNS*GB_BACKGROUND_ROWS];
// Set up the GAMEBOY's registers.
@@ -172,14 +171,11 @@ void main() {
// Init the random seed
initarand(DIV_REG);
// Prepare time and input
INPUT_STATE = joypad();
// Init things
commonTilesInit();
conversationTextboxInit();
// conversationQueueInit();
// pokerInit();
conversationQueueInit();
pokerInit();
// Fill screen white
for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) filled[j] = COMMON_TILE_3;
@@ -187,24 +183,23 @@ void main() {
SCX_REG = 0x00;
SCY_REG = 0x00;
// Alright begin the game logic here.
char *options[2] = {
"Yes", "No"
};
questionBoxSetOptions("Title", options, 0x02);
// Now turn the screen on
DISPLAY_ON;
enable_interrupts();
wait_vbl_done();
// Begin game
conversationQueueNext();
// Begin the loop
while(1) {
// Perform non-graphical code updates
wait_vbl_done();
// Update the input state
INPUT_LAST = INPUT_STATE;
INPUT_STATE = joypad();
INPUT_PRESSED = (~INPUT_LAST) & INPUT_STATE;
// Tick time.
timeUpdate();
@@ -212,15 +207,12 @@ void main() {
// Update conversation pause effect
conversationPauseUpdate();
// Update question box.
// Update question box and textbox
questionBoxUpdate();
// Update conversation textbox
conversationTextboxUpdate();
// Update conversation fade effect
conversationFadeUpdate();
// mainDebugDraw();
mainDebugDraw();
}
}