From ed548e587716c1b33babe9a53a99981c9751a3de Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sat, 22 Oct 2022 21:24:40 -0300 Subject: [PATCH 01/18] Declare "Window" block. --- blockly/apps/blocklyduino/index.html | 1 + blockly/blocks/base.js | 35 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/blockly/apps/blocklyduino/index.html b/blockly/apps/blocklyduino/index.html index c61c811..a86c9ba 100644 --- a/blockly/apps/blocklyduino/index.html +++ b/blockly/apps/blocklyduino/index.html @@ -384,6 +384,7 @@

./img/portrait_placeholder.png + diff --git a/blockly/blocks/base.js b/blockly/blocks/base.js index 8d2c679..c0de5fc 100644 --- a/blockly/blocks/base.js +++ b/blockly/blocks/base.js @@ -326,3 +326,38 @@ Blockly.Blocks['vn_character'] = { } } }; + +Blockly.Blocks['vn_window'] = { + init: function() { + var TARGETS = [ + ['text', 'TEXT'], + ['menu', 'MENU'] + ]; + + var COMMANDS = [ + ['starting at', 'STARTING_AT'], + ['ending at', 'ENDING_AT'], + ['size', 'SIZE'] + ]; + + var UNITS = [ + ['in chars', 'CHARS'], + ['%', 'PERCENT'] + ]; + + this.setColour(230); + this.appendDummyInput() + .appendField('Window for') + .appendField(new Blockly.FieldDropdown(TARGETS), 'TARGET') + .appendField(new Blockly.FieldDropdown(COMMANDS), 'COMMAND') + .appendField('(') + .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'X') + .appendField(',') + .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'Y') + .appendField(')') + .appendField(new Blockly.FieldDropdown(UNITS), 'UNIT'); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setTooltip('Says something.'); + } +}; \ No newline at end of file From f433601cd41047159909de06f10d44fc6d041f4d Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sat, 22 Oct 2022 21:27:46 -0300 Subject: [PATCH 02/18] Declare "Window reset" block. --- blockly/apps/blocklyduino/index.html | 1 + blockly/blocks/base.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/blockly/apps/blocklyduino/index.html b/blockly/apps/blocklyduino/index.html index a86c9ba..47b1169 100644 --- a/blockly/apps/blocklyduino/index.html +++ b/blockly/apps/blocklyduino/index.html @@ -385,6 +385,7 @@

./img/portrait_placeholder.png + diff --git a/blockly/blocks/base.js b/blockly/blocks/base.js index c0de5fc..1f9625f 100644 --- a/blockly/blocks/base.js +++ b/blockly/blocks/base.js @@ -358,6 +358,17 @@ Blockly.Blocks['vn_window'] = { .appendField(new Blockly.FieldDropdown(UNITS), 'UNIT'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip('Says something.'); + this.setTooltip('Configures window coordinates.'); + } +}; + +Blockly.Blocks['vn_window_reset'] = { + init: function() { + this.setColour(230); + this.appendDummyInput() + .appendField('Window reset'); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setTooltip('Resets window coordinates.'); } }; \ No newline at end of file From 0258ded40fbe0a43ef6a4bb3aba79aaf973db94e Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 10:00:46 -0300 Subject: [PATCH 03/18] Refactor `msgLines` to be allocated dinamically. --- .../blocklyduino/base-project/src/vn_engine.c | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 6a4187e..58a0bfa 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -1,4 +1,3 @@ -#include #include #include "unity.h" @@ -13,11 +12,16 @@ typedef struct _menuEntry { unsigned char idx; } menuEntry; +typedef struct _lineConfig { + unsigned char width, height; + unsigned char** lines; +} lineConfig; + menuEntry menuEntries[MENU_ENTRY_COUNT]; unsigned char usedMenuEntries; unsigned char menuCursor; -unsigned char* msgLines[MSG_LINE_COUNT]; +lineConfig msgLines; char characterName[32]; char *backgroundImage; @@ -83,7 +87,7 @@ char *bufferWrappedTextLine(char *s, char x, char y, char w) { // Skips initial spaces for current line for (o = startOfLine; *o == ' '; o++) { - msgLines[y][tx] = ' '; + msgLines.lines[y][tx] = ' '; tx++; currW++; bestW = currW; @@ -91,7 +95,7 @@ char *bufferWrappedTextLine(char *s, char x, char y, char w) { startOfLine = o; if (!*o || currW >= w) { - msgLines[y][tx] = 0; + msgLines.lines[y][tx] = 0; return 0; } @@ -120,7 +124,7 @@ char *bufferWrappedTextLine(char *s, char x, char y, char w) { for (o = startOfLine; o <= endOfLine; o++) { ch = *o; if (ch && ch != '\n') { - msgLines[y][tx] = ch; + msgLines.lines[y][tx] = ch; tx++; } } @@ -135,7 +139,7 @@ char *bufferWrappedTextLine(char *s, char x, char y, char w) { endOfLine++; } - msgLines[y][tx] = 0; + msgLines.lines[y][tx] = 0; return *endOfLine ? endOfLine : 0; } @@ -152,11 +156,23 @@ char *bufferWrappedText(char *s, char x, char y, char w, char h) { return o; } +void bufferResize() { + unsigned char i; + + msgLines.width = MSG_COL_COUNT; + msgLines.height = MSG_LINE_COUNT; + msgLines.lines = calloc(msgLines.height, sizeof(char *)); + + for (i = 0; i != msgLines.height; i++) { + msgLines.lines[i] = malloc(msgLines.width + 1); + } +} + void bufferClear() { unsigned char i; for (i = 0; i != MSG_LINE_COUNT; i++) { - msgLines[i][0] = 0; + msgLines.lines[i][0] = 0; } } @@ -199,9 +215,7 @@ void initGfx() { EnterBitmapMode(); - for (i = 0; i != MSG_LINE_COUNT; i++) { - msgLines[i] = malloc(MSG_COL_COUNT); - } + bufferResize(); bufferClear(); } @@ -238,7 +252,7 @@ void vnText(char *text) { bufferClear(); textToDisplay = bufferWrappedText(textToDisplay, 0, 0, MSG_COL_COUNT, MSG_LINE_COUNT); - ListBox(1, CHR_ROWS - MSG_LINE_COUNT - 4, MSG_COL_COUNT, MSG_LINE_COUNT + 2, characterName, msgLines, MSG_LINE_COUNT); + ListBox(1, CHR_ROWS - MSG_LINE_COUNT - 4, MSG_COL_COUNT, MSG_LINE_COUNT + 2, characterName, msgLines.lines, MSG_LINE_COUNT); #ifdef __LYNX__ // Wait until the joystick button is pressed From f86003a4e45b53d8fd504aa5aa45feca2a841919 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 10:24:14 -0300 Subject: [PATCH 04/18] Refactor dialog drawing to be dynamic. --- .../blocklyduino/base-project/src/vn_engine.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 58a0bfa..711c00c 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -3,8 +3,6 @@ #include "unity.h" #include "vn_engine.h" -#define MSG_COL_COUNT (CHR_COLS - 2) -#define MSG_LINE_COUNT 4 #define MENU_ENTRY_COUNT 8 typedef struct _menuEntry { @@ -156,22 +154,23 @@ char *bufferWrappedText(char *s, char x, char y, char w, char h) { return o; } -void bufferResize() { +void bufferResize(char width, char height) { unsigned char i; - msgLines.width = MSG_COL_COUNT; - msgLines.height = MSG_LINE_COUNT; + msgLines.width = width; + msgLines.height = height; msgLines.lines = calloc(msgLines.height, sizeof(char *)); for (i = 0; i != msgLines.height; i++) { msgLines.lines[i] = malloc(msgLines.width + 1); + msgLines.lines[i][0] = 0; } } void bufferClear() { unsigned char i; - for (i = 0; i != MSG_LINE_COUNT; i++) { + for (i = 0; i != msgLines.height; i++) { msgLines.lines[i][0] = 0; } } @@ -215,7 +214,7 @@ void initGfx() { EnterBitmapMode(); - bufferResize(); + bufferResize(CHR_COLS - 2, 4); bufferClear(); } @@ -250,9 +249,9 @@ void vnText(char *text) { waitNextButtonRelease(); bufferClear(); - textToDisplay = bufferWrappedText(textToDisplay, 0, 0, MSG_COL_COUNT, MSG_LINE_COUNT); + textToDisplay = bufferWrappedText(textToDisplay, 0, 0, msgLines.width, msgLines.height); - ListBox(1, CHR_ROWS - MSG_LINE_COUNT - 4, MSG_COL_COUNT, MSG_LINE_COUNT + 2, characterName, msgLines.lines, MSG_LINE_COUNT); + ListBox(1, CHR_ROWS - msgLines.height - 4, msgLines.width, msgLines.height + 2, characterName, msgLines.lines, msgLines.height); #ifdef __LYNX__ // Wait until the joystick button is pressed From e8e168c007858a7876c1fc73fef13a81c66846d7 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 11:20:16 -0300 Subject: [PATCH 05/18] Implement `vnWindowFrom()` function. --- .../blocklyduino/base-project/src/vn_engine.c | 28 +++++++++++++++++++ .../blocklyduino/base-project/src/vn_engine.h | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 711c00c..08650ea 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -11,6 +11,7 @@ typedef struct _menuEntry { } menuEntry; typedef struct _lineConfig { + unsigned char x, y; unsigned char width, height; unsigned char** lines; } lineConfig; @@ -18,6 +19,10 @@ typedef struct _lineConfig { menuEntry menuEntries[MENU_ENTRY_COUNT]; unsigned char usedMenuEntries; unsigned char menuCursor; +struct { + unsigned char x, y; + unsigned char width, height; +} menuConfig; lineConfig msgLines; char characterName[32]; @@ -218,6 +223,16 @@ void initGfx() { bufferClear(); } +int convertCoordinate(int coord, int max, char unit) { + // Percent to chars + if (unit == WND_UNIT_PERCENT) coord = coord * max / 100; + + // Negative coordinates + if (coord < 0) coord = max - coord; + + return coord; +} + void initVN() { initGfx(); InitJoy(); @@ -242,6 +257,19 @@ void vnChar(char *charName) { strcpy(characterName, charName); } +void vnWindowFrom(char target, int x, int y, char unit) { + x = convertCoordinate(x, CHR_COLS, unit); + y = convertCoordinate(x, CHR_ROWS, unit); + + if (unit == WND_TARGET_MENU) { + menuConfig.x = x; + menuConfig.y = y; + } else { + msgLines.x = x; + msgLines.y = y; + } +} + void vnText(char *text) { char *textToDisplay; diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.h b/blockly/apps/blocklyduino/base-project/src/vn_engine.h index 1503123..48a9f89 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.h +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.h @@ -1,7 +1,13 @@ #ifndef _VN_ENGINE_H #define _VN_ENGINE_H +#define WND_TARGET_TEXT (1) +#define WND_TARGET_MENU (2) +#define WND_UNIT_CHARS (1) +#define WND_UNIT_PERCENT (2) + extern void initVN(); +extern void vnWindowFrom(char target, int x, int y, char unit); extern void vnScene(char *scene); extern void vnShow(char *actor); extern void vnChar(char *charName); From d46e85692f84d1b6b5952d70c134a55948b2c4ad Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 11:43:29 -0300 Subject: [PATCH 06/18] Implement dynamic top/left coords for text window. --- .../blocklyduino/base-project/src/vn_engine.c | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 08650ea..3157399 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -228,7 +228,22 @@ int convertCoordinate(int coord, int max, char unit) { if (unit == WND_UNIT_PERCENT) coord = coord * max / 100; // Negative coordinates - if (coord < 0) coord = max - coord; + if (coord < 0) coord = max + coord; + + return coord; +} + +int convertCoordinate2(int coord, int max, char unit) { + PrintNum(0, 12, -coord); + + // Percent to chars + if (unit == WND_UNIT_PERCENT) coord = coord * max / 100; + PrintNum(0, 13, -coord); + + // Negative coordinates + if (coord < 0) coord = max + coord; + PrintNum(0, 14, coord); + PrintNum(5, 14, max); return coord; } @@ -240,6 +255,8 @@ void initVN() { backgroundImage = 0; actorImage = 0; + + vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); strcpy(characterName, ""); } @@ -259,8 +276,8 @@ void vnChar(char *charName) { void vnWindowFrom(char target, int x, int y, char unit) { x = convertCoordinate(x, CHR_COLS, unit); - y = convertCoordinate(x, CHR_ROWS, unit); - + y = convertCoordinate(y, CHR_ROWS, unit); + if (unit == WND_TARGET_MENU) { menuConfig.x = x; menuConfig.y = y; @@ -279,7 +296,14 @@ void vnText(char *text) { bufferClear(); textToDisplay = bufferWrappedText(textToDisplay, 0, 0, msgLines.width, msgLines.height); - ListBox(1, CHR_ROWS - msgLines.height - 4, msgLines.width, msgLines.height + 2, characterName, msgLines.lines, msgLines.height); + ListBox(msgLines.x, msgLines.y, msgLines.width, msgLines.height + 2, characterName, msgLines.lines, msgLines.height); + + /* + PrintNum(0, 12, msgLines.y); + PrintNum(0, 13, convertCoordinate(-8, CHR_ROWS, WND_UNIT_CHARS)); + PrintNum(0, 14, CHR_ROWS - 8); + */ + convertCoordinate2(-8, CHR_ROWS, WND_UNIT_CHARS); #ifdef __LYNX__ // Wait until the joystick button is pressed From 6402eb2dc7ea2c82f864ee3b16f296e89b4b0f30 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 11:45:38 -0300 Subject: [PATCH 07/18] Cleanup code. --- .../blocklyduino/base-project/src/vn_engine.c | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 3157399..92b3620 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -10,12 +10,6 @@ typedef struct _menuEntry { unsigned char idx; } menuEntry; -typedef struct _lineConfig { - unsigned char x, y; - unsigned char width, height; - unsigned char** lines; -} lineConfig; - menuEntry menuEntries[MENU_ENTRY_COUNT]; unsigned char usedMenuEntries; unsigned char menuCursor; @@ -24,7 +18,12 @@ struct { unsigned char width, height; } menuConfig; -lineConfig msgLines; +struct { + unsigned char x, y; + unsigned char width, height; + unsigned char** lines; +} msgLines; + char characterName[32]; char *backgroundImage; @@ -233,21 +232,6 @@ int convertCoordinate(int coord, int max, char unit) { return coord; } -int convertCoordinate2(int coord, int max, char unit) { - PrintNum(0, 12, -coord); - - // Percent to chars - if (unit == WND_UNIT_PERCENT) coord = coord * max / 100; - PrintNum(0, 13, -coord); - - // Negative coordinates - if (coord < 0) coord = max + coord; - PrintNum(0, 14, coord); - PrintNum(5, 14, max); - - return coord; -} - void initVN() { initGfx(); InitJoy(); @@ -298,13 +282,6 @@ void vnText(char *text) { ListBox(msgLines.x, msgLines.y, msgLines.width, msgLines.height + 2, characterName, msgLines.lines, msgLines.height); - /* - PrintNum(0, 12, msgLines.y); - PrintNum(0, 13, convertCoordinate(-8, CHR_ROWS, WND_UNIT_CHARS)); - PrintNum(0, 14, CHR_ROWS - 8); - */ - convertCoordinate2(-8, CHR_ROWS, WND_UNIT_CHARS); - #ifdef __LYNX__ // Wait until the joystick button is pressed while (GetJoy(0) & JOY_BTN1); From 1e6af38eb6d6d276980c52b1ffe683aa5d51be27 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 12:03:55 -0300 Subject: [PATCH 08/18] Implement menu position configuration. --- .../apps/blocklyduino/base-project/src/vn_engine.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 92b3620..21167b5 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -45,17 +45,17 @@ unsigned char addMenuItem(char *s) { } unsigned char menuTop() { - return (CHR_ROWS - usedMenuEntries - 2) >> 1; + return menuConfig.y - (usedMenuEntries >> 1); } void drawMenuLine(int number) { int y = menuTop() + number - 1; #ifdef __LYNX__ - PrintStr(1, y, number == menuCursor ? "*" : " "); + PrintStr(menuConfig.x, y, number == menuCursor ? "*" : " "); #else - PrintNum(1, y, number); + PrintNum(menuConfig.x, y, number); #endif - PrintStr(3, y, menuEntries[number - 1].s); + PrintStr(menuConfig.x + 2, y, menuEntries[number - 1].s); } unsigned char drawMenu() { @@ -64,7 +64,7 @@ unsigned char drawMenu() { char selected; y = menuTop(); - Panel(1, y - 1, CHR_COLS - 2, usedMenuEntries + 1, ""); + Panel(menuConfig.x, y - 1, CHR_COLS - 2, usedMenuEntries + 1, ""); for (i = 1; i <= usedMenuEntries; i++) { drawMenuLine(i); @@ -241,6 +241,7 @@ void initVN() { actorImage = 0; vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); + vnWindowFrom(WND_TARGET_MENU, 1, (CHR_ROWS - 2) >> 1, WND_UNIT_CHARS); strcpy(characterName, ""); } @@ -262,7 +263,7 @@ void vnWindowFrom(char target, int x, int y, char unit) { x = convertCoordinate(x, CHR_COLS, unit); y = convertCoordinate(y, CHR_ROWS, unit); - if (unit == WND_TARGET_MENU) { + if (target == WND_TARGET_MENU) { menuConfig.x = x; menuConfig.y = y; } else { From a3920f4fe6a9ad5b8f88989236bdea57488cc493 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:29:35 -0300 Subject: [PATCH 09/18] Implement `vnWindowSize()` function. --- .../blocklyduino/base-project/src/vn_engine.c | 22 ++++++++++++++++--- .../blocklyduino/base-project/src/vn_engine.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 21167b5..00f3e98 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -217,9 +217,6 @@ void initGfx() { InitBitmap(); EnterBitmapMode(); - - bufferResize(CHR_COLS - 2, 4); - bufferClear(); } int convertCoordinate(int coord, int max, char unit) { @@ -240,8 +237,15 @@ void initVN() { backgroundImage = 0; actorImage = 0; + // Text window + msgLines.lines = 0; vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); + vnWindowSize(WND_TARGET_TEXT, CHR_COLS - 2, 4, WND_UNIT_CHARS); + + // Menu window vnWindowFrom(WND_TARGET_MENU, 1, (CHR_ROWS - 2) >> 1, WND_UNIT_CHARS); + vnWindowSize(WND_TARGET_MENU, CHR_COLS - 2, MENU_ENTRY_COUNT, WND_UNIT_CHARS); + strcpy(characterName, ""); } @@ -272,6 +276,18 @@ void vnWindowFrom(char target, int x, int y, char unit) { } } +void vnWindowSize(char target, int width, int height, char unit) { + width = convertCoordinate(width, CHR_COLS, unit); + height = convertCoordinate(height, CHR_ROWS, unit); + + if (target == WND_TARGET_MENU) { + menuConfig.width = width; + menuConfig.height = height; + } else { + bufferResize(width, height); + } +} + void vnText(char *text) { char *textToDisplay; diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.h b/blockly/apps/blocklyduino/base-project/src/vn_engine.h index 48a9f89..873daa0 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.h +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.h @@ -8,6 +8,7 @@ extern void initVN(); extern void vnWindowFrom(char target, int x, int y, char unit); +extern void vnWindowSize(char target, int width, int height, char unit); extern void vnScene(char *scene); extern void vnShow(char *actor); extern void vnChar(char *charName); From 790f5e91c33c5f3df18a1a6fa3912a70ff50f6d6 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:32:06 -0300 Subject: [PATCH 10/18] Make the menu use the configured width. --- blockly/apps/blocklyduino/base-project/src/vn_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 00f3e98..d4ef06e 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -64,7 +64,7 @@ unsigned char drawMenu() { char selected; y = menuTop(); - Panel(menuConfig.x, y - 1, CHR_COLS - 2, usedMenuEntries + 1, ""); + Panel(menuConfig.x, y - 1, menuConfig.width, usedMenuEntries + 1, ""); for (i = 1; i <= usedMenuEntries; i++) { drawMenuLine(i); From e0b65478305d56f50694a66e7a63d5d2596aa6cd Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:36:03 -0300 Subject: [PATCH 11/18] Implement support for negative width/height. --- .../blocklyduino/base-project/src/vn_engine.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index d4ef06e..5d398eb 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -277,6 +277,24 @@ void vnWindowFrom(char target, int x, int y, char unit) { } void vnWindowSize(char target, int width, int height, char unit) { + if (width < 0) { + if (target == WND_TARGET_MENU) { + menuConfig.x -= width; + } else { + msgLines.x -= width; + } + width = -width; + } + + if (height < 0) { + if (target == WND_TARGET_MENU) { + menuConfig.y -= height; + } else { + msgLines.y -= height; + } + height = -height; + } + width = convertCoordinate(width, CHR_COLS, unit); height = convertCoordinate(height, CHR_ROWS, unit); From d5628d5a6c2ffb4b1b3c364d2ffff439b9198ab2 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:39:55 -0300 Subject: [PATCH 12/18] Implement `vnWindowReset()` function. --- .../blocklyduino/base-project/src/vn_engine.c | 18 +++++++++++------- .../blocklyduino/base-project/src/vn_engine.h | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 5d398eb..c2bb776 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -237,14 +237,8 @@ void initVN() { backgroundImage = 0; actorImage = 0; - // Text window msgLines.lines = 0; - vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); - vnWindowSize(WND_TARGET_TEXT, CHR_COLS - 2, 4, WND_UNIT_CHARS); - - // Menu window - vnWindowFrom(WND_TARGET_MENU, 1, (CHR_ROWS - 2) >> 1, WND_UNIT_CHARS); - vnWindowSize(WND_TARGET_MENU, CHR_COLS - 2, MENU_ENTRY_COUNT, WND_UNIT_CHARS); + vnWindowReset(); strcpy(characterName, ""); } @@ -306,6 +300,16 @@ void vnWindowSize(char target, int width, int height, char unit) { } } +void vnWindowReset() { + // Text window + vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); + vnWindowSize(WND_TARGET_TEXT, CHR_COLS - 2, 4, WND_UNIT_CHARS); + + // Menu window + vnWindowFrom(WND_TARGET_MENU, 1, (CHR_ROWS - 2) >> 1, WND_UNIT_CHARS); + vnWindowSize(WND_TARGET_MENU, CHR_COLS - 2, MENU_ENTRY_COUNT, WND_UNIT_CHARS); +} + void vnText(char *text) { char *textToDisplay; diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.h b/blockly/apps/blocklyduino/base-project/src/vn_engine.h index 873daa0..c716119 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.h +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.h @@ -7,8 +7,11 @@ #define WND_UNIT_PERCENT (2) extern void initVN(); + extern void vnWindowFrom(char target, int x, int y, char unit); extern void vnWindowSize(char target, int width, int height, char unit); +extern void vnWindowReset(); + extern void vnScene(char *scene); extern void vnShow(char *actor); extern void vnChar(char *charName); From 77ddc92d7cf109f9959deef494af13894d86f5ce Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:42:46 -0300 Subject: [PATCH 13/18] Deallocate existing line buffers before resizing. --- .../apps/blocklyduino/base-project/src/vn_engine.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index c2bb776..663ac65 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -160,7 +160,18 @@ char *bufferWrappedText(char *s, char x, char y, char w, char h) { void bufferResize(char width, char height) { unsigned char i; + + // Deallocate existing buffers + if (msgLines.lines) { + for (i = 0; i != msgLines.height; i++) { + free(msgLines.lines[i]); + } + free(msgLines.lines); + msgLines.lines = 0; + } + // Reallocate according to the new size + msgLines.width = width; msgLines.height = height; msgLines.lines = calloc(msgLines.height, sizeof(char *)); From 4e4372c4b87585b42f4a9379fc78b733fdb14ba9 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 14:54:13 -0300 Subject: [PATCH 14/18] Add window testing to the project. --- .../blocklyduino/base-project/src/vn_engine.c | 8 +- projects/test/blockly.xml | 156 ++++++++++++------ projects/test/project.json | 2 +- 3 files changed, 112 insertions(+), 54 deletions(-) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index 663ac65..b2b4165 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -284,18 +284,18 @@ void vnWindowFrom(char target, int x, int y, char unit) { void vnWindowSize(char target, int width, int height, char unit) { if (width < 0) { if (target == WND_TARGET_MENU) { - menuConfig.x -= width; + menuConfig.x -= convertCoordinate(width, CHR_COLS, unit); } else { - msgLines.x -= width; + msgLines.x -= convertCoordinate(width, CHR_COLS, unit); } width = -width; } if (height < 0) { if (target == WND_TARGET_MENU) { - menuConfig.y -= height; + menuConfig.y -= convertCoordinate(height, CHR_ROWS, unit); } else { - msgLines.y -= height; + msgLines.y -= convertCoordinate(height, CHR_ROWS, unit); } height = -height; } diff --git a/projects/test/blockly.xml b/projects/test/blockly.xml index 58f12eb..9edbd31 100644 --- a/projects/test/blockly.xml +++ b/projects/test/blockly.xml @@ -1,67 +1,67 @@ - + Sylvie - + club C:\Users\Haroldo\Projetos\32x\BlocklyVN32X\projects\test\bg\club.png - + sylvie_normal C:\Temp\blocklyvn32x-portable-0.4.0\projects\test\portrait\sylvie_normal.png - + val - + 456 - + - + Variable 'val' has value ${val} - + - + Hello. - + - + This is a demonstration of BlocklyVN8bit. - + - + Combined with 8bit-Unity, it allows you to build visual novels for multiple 8-bit platforms. - + - + Option 1 - + - + xxxx - + variable - + 1 @@ -70,20 +70,20 @@ - + Option 2 - + - + zzzz - + variable - + 2 @@ -91,14 +91,28 @@ + + + Test resizing + + + + + + + + + + + - + - + @@ -121,97 +135,141 @@ - + + + test resize + + + TEXT + STARTING_AT + 2 + 3 + CHARS + + + TEXT + SIZE + 50 + 50 + PERCENT + + + + + Testing resized window. + + + + + + + + + Back to normal. + + + + + + + + + + + + + + another scene - + Someone else - + lecturehall C:\Temp\blocklyvn32x-portable-0.4.0\projects\test\bg\lecturehall.png - + sylvie_giggle C:\Temp\blocklyvn32x-portable-0.4.0\projects\test\portrait\sylvie_giggle.png - + - + Seems to be working. - + - + EQ - + variable - + 1 - + - + You chose option 1 previously! - + EQ - + variable - + 2 - + - + You chose option 2 previously! - + - + One option - + Another option - + - + One more option - + Yet another option diff --git a/projects/test/project.json b/projects/test/project.json index 7998010..dc5f4b6 100644 --- a/projects/test/project.json +++ b/projects/test/project.json @@ -2,6 +2,6 @@ "format": 1, "ide": { "name": "BlocklyVN8bit", - "version": "0.2.4" + "version": "0.2.8" } } \ No newline at end of file From da39936342cae9e71d4428dcc01362c9a03a0184 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 15:11:38 -0300 Subject: [PATCH 15/18] Implement code generator for the menu commands. --- blockly/generators/arduino/base.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/blockly/generators/arduino/base.js b/blockly/generators/arduino/base.js index 80bb174..9104cad 100644 --- a/blockly/generators/arduino/base.js +++ b/blockly/generators/arduino/base.js @@ -201,3 +201,29 @@ Blockly.Arduino.vn_character = function() { var code = 'vnChar(' + charName + ');\n'; return code; } + +Blockly.Arduino.vn_window = function() { + var COMMAND_MAP = { + 'STARTING_AT': 'vnWindowFrom', + 'ENDING_AT': 'vnWindowTo', + 'SIZE': 'vnWindowSize' + }; + + var target = this.getFieldValue('TARGET'); + var command = this.getFieldValue('COMMAND'); + var x = window.parseFloat(this.getFieldValue('X')); + var y = window.parseFloat(this.getFieldValue('Y')); + var unit = this.getFieldValue('UNIT'); + + var code = COMMAND_MAP[command] + '(' + + 'WND_TARGET_' + target + ',' + + x + ',' + y + ',' + + 'WND_UNIT_' + unit + + ');\n'; + return code; +} + +Blockly.Arduino.vn_window_reset = function() { + var code = 'vnWindowReset();\n'; + return code; +} From 494c349ef27fc69e0b6c3bb17768fe1cce369f66 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 15:18:00 -0300 Subject: [PATCH 16/18] Implement `vnWindowTo()` function. --- .../blocklyduino/base-project/src/vn_engine.c | 17 +++++++++++++++++ .../blocklyduino/base-project/src/vn_engine.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.c b/blockly/apps/blocklyduino/base-project/src/vn_engine.c index b2b4165..fd21961 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.c +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.c @@ -311,6 +311,23 @@ void vnWindowSize(char target, int width, int height, char unit) { } } +void vnWindowTo(char target, int x, int y, char unit) { + int width, height; + + x = convertCoordinate(x, CHR_COLS, unit); + y = convertCoordinate(y, CHR_ROWS, unit); + + if (target == WND_TARGET_MENU) { + width = x - menuConfig.x + 1; + height = y - menuConfig.y + 1; + } else { + width = x - msgLines.x + 1; + height = y - msgLines.y + 1; + } + + vnWindowSize(target, width, height, WND_UNIT_CHARS); +} + void vnWindowReset() { // Text window vnWindowFrom(WND_TARGET_TEXT, 1, -8, WND_UNIT_CHARS); diff --git a/blockly/apps/blocklyduino/base-project/src/vn_engine.h b/blockly/apps/blocklyduino/base-project/src/vn_engine.h index c716119..f5737ac 100644 --- a/blockly/apps/blocklyduino/base-project/src/vn_engine.h +++ b/blockly/apps/blocklyduino/base-project/src/vn_engine.h @@ -10,6 +10,8 @@ extern void initVN(); extern void vnWindowFrom(char target, int x, int y, char unit); extern void vnWindowSize(char target, int width, int height, char unit); +extern void vnWindowTo(char target, int x, int y, char unit); +extern void vnWindowTo(char target, int x, int y, char unit); extern void vnWindowReset(); extern void vnScene(char *scene); From 72db092faed937fa4a6bd29a41ff3a9bf832c34e Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 15:25:33 -0300 Subject: [PATCH 17/18] Enrich the example. --- projects/test/blockly.xml | 132 +++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 39 deletions(-) diff --git a/projects/test/blockly.xml b/projects/test/blockly.xml index 9edbd31..75fe6e1 100644 --- a/projects/test/blockly.xml +++ b/projects/test/blockly.xml @@ -92,12 +92,12 @@ - + Test resizing - + - + @@ -110,9 +110,9 @@ - + - + @@ -135,39 +135,93 @@ - + test resize - + TEXT STARTING_AT 2 3 CHARS - + TEXT SIZE 50 50 PERCENT - + - + Testing resized window. - + + TEXT + STARTING_AT + 60 + 20 + PERCENT - - - - Back to normal. + + TEXT + ENDING_AT + 90 + 50 + PERCENT + + + + + Another resized window + + + + + MENU + STARTING_AT + -20 + 8 + CHARS + + + MENU + ENDING_AT + -3 + 18 + CHARS + + + + + Resized menu + + + + + + + + + Back to normal. + + + + + + + + + + + + - + @@ -179,97 +233,97 @@ - + another scene - + Someone else - + lecturehall C:\Temp\blocklyvn32x-portable-0.4.0\projects\test\bg\lecturehall.png - + sylvie_giggle C:\Temp\blocklyvn32x-portable-0.4.0\projects\test\portrait\sylvie_giggle.png - + - + Seems to be working. - + - + EQ - + variable - + 1 - + - + You chose option 1 previously! - + EQ - + variable - + 2 - + - + You chose option 2 previously! - + - + One option - + Another option - + - + One more option - + Yet another option From e13b1576ea790221018347a295c46ab0c0d6aa5a Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Sun, 23 Oct 2022 15:28:02 -0300 Subject: [PATCH 18/18] Bump version to 0.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b708b1..add84b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "BlocklyVN8bit", - "version": "0.2.8", + "version": "0.3.0", "description": "Uses blockly to generate visual novels for 8bit-Unity", "main": "main.js", "scripts": {