VASTLY improved how I generate tiles and tiledata

This commit is contained in:
2022-05-07 21:57:15 -07:00
parent bee024c3e1
commit 4ff43893d0
66 changed files with 3472 additions and 3186 deletions

View File

@@ -1,87 +1,87 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "questionbox.h"
uint8_t QUESTION_BOX_OPTION_COUNT;
uint8_t QUESTION_BOX_OPTION_CURRENT;
void questionBoxSetOptions(char *title, char **options, uint8_t count) {
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 {
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
);
}
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "questionbox.h"
uint8_t QUESTION_BOX_OPTION_COUNT;
uint8_t QUESTION_BOX_OPTION_CURRENT;
void questionBoxSetOptions(char *title, char **options, uint8_t count) {
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 {
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] = spriteFontTileFromChar(QUESTION_BOX_CURSOR);
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] = spriteFontTileFromChar(QUESTION_BOX_CURSOR);
} else {
tiles[0] = spriteFontTileFromChar(' ');
}
set_bkg_tiles(
0x01 + ((i % 0x02) * QUESTION_BOX_QUESTION_SPACES),
TEXTBOX_WIN_Y + 0x02 + (i / 0x02),
1, 1,
tiles
);
}
}