From 1c4769ba7330219e99836988dc161104b8deba45 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 12 Aug 2021 08:56:34 -0700 Subject: [PATCH] Added frame to the VN Textbox --- assets/test_texture.png | Bin 371 -> 30365 bytes include/dawn/ui/frame.h | 3 +- include/dawn/vn/vntextbox.h | 6 ++-- src/display/gui/font.c | 7 ++-- src/game/poker/pokergame.c | 16 +++------ src/game/poker/pokergameassets.c | 1 + src/game/poker/pokergameassets.h | 1 + src/game/poker/pokerui.c | 1 + src/test/testscene.c | 2 +- src/ui/frame.c | 3 +- src/vn/conversation/vnconversation.c | 4 +-- src/vn/conversation/vnconversation.h | 3 +- src/vn/gui/vntextbox.c | 48 +++++++++++++++------------ src/vn/gui/vntextbox.h | 4 ++- src/vn/vnscene.c | 4 +-- src/vn/vnscene.h | 2 +- 16 files changed, 55 insertions(+), 50 deletions(-) diff --git a/assets/test_texture.png b/assets/test_texture.png index f98cd41edfe991ce466550f4e64bfeeb1f105c64..b2835b2df2002e54ef9e02fdd2b6642e9874f84b 100644 GIT binary patch literal 30365 zcmeI5-Aj{E9LJ9>bGlp!3cgLl3y~nwya@%j`I64kM1&I2=Ed|zP?2Rt;Y-0R1fwGI zDy0jpR4lMWP?pgPDJ2wIG%;JGu@C}r(WLcz_Gj2<@Gzd8!?}2P&N<)j_jAtK)r#`s z=%~afrBt-7q_9#c!=!fUb@I!xx$xui71mZ+oUg{-CjXF|-Hp~Vt5T2p4BPeLa&N9U zQB@RW*6XGpsG#Y>UNGmgqR8I)X~wOG#0s9r}{9&tmU4 zH)UKrpB7Y}p1<$srK!l4lIk|4jI-Jm7MD@lsg!fgR%op{SNC)AlQmAozHqy~?m5`K zb>^XY=$fZL{YJ!se=~A8u=m>`pQXRmHRCktYZkkXc#W5QIs2cC=o~Lie-@nwnyMq- z^yY4k`YazG8*e4Fuh%SfjXO*k*&7Q_$8_~`ITa0_!RFeC+1t*6`N@KnDdQCyYR zm(YIHJy~$K)s^QpM#Q(TOSfqBtSVWk7b;J-dj{Wy%5|a2Qr^-Tsx0NkOs%q%KM$iZ zo*AzO-HB0y!I252HxUsA7Y zTNlL}pO)?Ha&DSrrf%8PEN7(M5u>DSZI$!TBt96IT5_0LgJ-oH*JzSw$xB4i!p(3c2n90gVi4~cmuH6Ske-*cki z=h4f%ls#TwpZ0ylmp9a%p6(_-BZ?%0C444z2RFc308EfIkRmJY3V>^oCO|{#S9F5 zhe4R}c>anMpx{GK7srr_TW`-@WMEJfU_B7*@lYhlL$OsPDB_L8z3=A)&PttY`)AmrealLength; i++) { quad = info->quads + i; quadBuffer(primitive, 0, quad->x0, quad->y0, quad->s0, quad->t0, quad->x1, quad->y1, quad->s1, quad->t1, - i*QUAD_VERTICE_COUNT, i*QUAD_INDICE_COUNT + i * QUAD_VERTICE_COUNT, i * QUAD_INDICE_COUNT ); } } void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info) { primitiveInit(primitive, - QUAD_VERTICE_COUNT * info->realLength, QUAD_INDICE_COUNT * info->realLength + QUAD_VERTICE_COUNT * info->realLength, + QUAD_INDICE_COUNT * info->realLength ); fontTextBuffer(font, primitive, info); } diff --git a/src/game/poker/pokergame.c b/src/game/poker/pokergame.c index 9011a86e..99b6feb5 100644 --- a/src/game/poker/pokergame.c +++ b/src/game/poker/pokergame.c @@ -7,8 +7,6 @@ #include "pokergame.h" -frame_t frame; - bool pokerGameInit(game_t *game) { pokergame_t *pokerGame = &game->pokerGame; @@ -20,16 +18,11 @@ bool pokerGameInit(game_t *game) { // Initialize the UI. pokerUiInit(pokerGame); - - frameInit(&frame); - frame.texture = &pokerGame->assets.testTexture; // Prep the VN Conversation Engine. - vnSceneInit(&pokerGame->scene, &pokerGame->assets.font); - // pokerGameActionStartAdd(pokerGame); - // queueNext(&pokerGame->scene.conversation.actionQueue); - - + vnSceneInit(&pokerGame->scene, &pokerGame->assets.font, &pokerGame->assets.testTexture); + pokerGameActionStartAdd(pokerGame); + queueNext(&pokerGame->scene.conversation.actionQueue); return true; } @@ -48,8 +41,7 @@ void pokerGameUpdate(game_t *game) { // Render the visual novel scene // vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); - frameRender(&frame, &pokerGame->assets.shader); - // pokerUiRender(pokerGame); + pokerUiRender(pokerGame); } void pokerGameDispose(game_t *game) { diff --git a/src/game/poker/pokergameassets.c b/src/game/poker/pokergameassets.c index 302dd805..ae564922 100644 --- a/src/game/poker/pokergameassets.c +++ b/src/game/poker/pokergameassets.c @@ -17,6 +17,7 @@ bool pokerGameAssetsInit(pokergameassets_t *assets) { } void pokerGameAssetsDispose(pokergameassets_t *assets) { + textureDispose(&assets->testTexture); languageDispose(&assets->language); shaderDispose(&assets->shader); fontDispose(&assets->font); diff --git a/src/game/poker/pokergameassets.h b/src/game/poker/pokergameassets.h index 768bb59e..63276180 100644 --- a/src/game/poker/pokergameassets.h +++ b/src/game/poker/pokergameassets.h @@ -9,6 +9,7 @@ #include #include "../../file/asset.h" #include "../../locale/language.h" +#include "../../display/texture.h" bool pokerGameAssetsInit(pokergameassets_t *assets); void pokerGameAssetsDispose(pokergameassets_t *assets); \ No newline at end of file diff --git a/src/game/poker/pokerui.c b/src/game/poker/pokerui.c index 92f37908..f3d7a174 100644 --- a/src/game/poker/pokerui.c +++ b/src/game/poker/pokerui.c @@ -36,6 +36,7 @@ void pokerUiRender(pokergame_t *pokerGame) { char buffer[256]; for(i = 0; i < POKER_PLAYER_COUNT; i++) { + break; playerUi = pokerGame->ui.players + i; playerPoker = pokerGame->poker.players + i; diff --git a/src/test/testscene.c b/src/test/testscene.c index f7205a5e..a7992aab 100644 --- a/src/test/testscene.c +++ b/src/test/testscene.c @@ -14,7 +14,7 @@ void testSceneInit(testscene_t *scene, game_t *game) { ); // Init Conversation - vnConversationInit(&scene->conversation, &scene->font); + // vnConversationInit(&scene->conversation, &scene->font); scene->conversation.textbox.linesMax = 3; scene->conversation.textbox.widthMax = game->engine.render.width; diff --git a/src/ui/frame.c b/src/ui/frame.c index 336431d6..635b0e23 100644 --- a/src/ui/frame.c +++ b/src/ui/frame.c @@ -10,7 +10,6 @@ void frameInit(frame_t *frame) { frame->x = 0; frame->y = 0; - frame->z = 0; primitiveInit( &frame->primitive, @@ -105,7 +104,7 @@ void frameSetInnerSize(frame_t *frame, float width, float height) { } void frameRender(frame_t *frame, shader_t *shader) { - shaderUsePosition(shader, frame->x, frame->y, frame->z, 0, 0, 0); + shaderUsePosition(shader, frame->x, frame->y, 0, 0, 0, 0); shaderUseTexture(shader, frame->texture); primitiveDraw(&frame->primitive, 0, -1); } diff --git a/src/vn/conversation/vnconversation.c b/src/vn/conversation/vnconversation.c index ed4588d7..1c16bce5 100644 --- a/src/vn/conversation/vnconversation.c +++ b/src/vn/conversation/vnconversation.c @@ -7,8 +7,8 @@ #include "vnconversation.h" -void vnConversationInit(vnconversation_t *convo, font_t *font) { - vnTextBoxInit(&convo->textbox, font); +void vnConversationInit(vnconversation_t *convo, font_t *font, texture_t *tex) { + vnTextBoxInit(&convo->textbox, font, tex); queueInit(&convo->actionQueue); } diff --git a/src/vn/conversation/vnconversation.h b/src/vn/conversation/vnconversation.h index 4412c3f8..a74201b7 100644 --- a/src/vn/conversation/vnconversation.h +++ b/src/vn/conversation/vnconversation.h @@ -17,8 +17,9 @@ * then ensure you call vnConversationNext to begin the conversation. * @param convo Conversation to initialize. * @param font Font to initialize with. + * @param tex GUI Texture. */ -void vnConversationInit(vnconversation_t *convo, font_t *font); +void vnConversationInit(vnconversation_t *convo, font_t *font, texture_t *text); /** * Add a text element to the conversation. diff --git a/src/vn/gui/vntextbox.c b/src/vn/gui/vntextbox.c index b37b2cf6..768ce07a 100644 --- a/src/vn/gui/vntextbox.c +++ b/src/vn/gui/vntextbox.c @@ -7,7 +7,7 @@ #include "vntextbox.h" -void vnTextBoxInit(vntextbox_t *box, font_t *font) { +void vnTextBoxInit(vntextbox_t *box, font_t *font, texture_t *texture) { box->font = font; box->widthMax = 400; box->text = NULL; @@ -15,6 +15,10 @@ void vnTextBoxInit(vntextbox_t *box, font_t *font) { box->linesMax = 3; box->lineCurrent = 0; box->state = 0; + + + frameInit(&box->frame); + box->frame.texture = texture; } void vnTextBoxSetText(vntextbox_t *box, char *text) { @@ -27,29 +31,25 @@ void vnTextBoxSetText(vntextbox_t *box, char *text) { void vnTextBoxRebuffer(vntextbox_t *box) { if(box->primitive.indiceCount > 0) { - vnTextBoxDispose(box); + primitiveDispose(&box->primitive); + box->primitive.indiceCount = 0; } if(box->text == NULL) return; + // Determine size of the textbox inside the frame. + float textMaxWidth = box->widthMax - FRAME_BORDER_SIZE_FULL; + // Rebuffer the text. fontTextClamp( - box->font, &box->textInfo, box->text, box->widthMax, VN_TEXTBOX_FONT_SIZE + box->font, &box->textInfo, box->text, textMaxWidth, VN_TEXTBOX_FONT_SIZE ); fontTextInit(box->font, &box->primitive, &box->textInfo); - // Test "Background" - quadInit(&box->testPrimitive, 0, - 0, 0, 0.3, 0.3, - box->textInfo.width, box->textInfo.height, 0.6, 0.6 + // Resize the frame + frameSetSize( + &box->frame, box->widthMax, FONT_LINE_HEIGHT * box->linesMax ); - - pixel_t pixels[25]; - for(uint8_t i = 0; i < 25; i++) { - pixels[i].r = pixels[i].a = 0xFF; - pixels[i].g = pixels[i].b = 0x00; - } - textureInit(&box->testTexture, 5, 5, pixels); } void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) { @@ -110,20 +110,26 @@ void vnTextBoxRender(vntextbox_t *box, shader_t *shader) { if(charCount < 1) return; // Render the debug box. - shaderUsePosition(shader, box->x,box->y - yOffset,0, 0,0,0); - shaderUseTexture(shader, &box->testTexture); - primitiveDraw(&box->testPrimitive, 0, -1); + box->frame.x = box->x; + box->frame.y = box->y - yOffset; + frameRender(&box->frame, shader); // Render the Text Box + shaderUsePosition(shader, + box->x + FRAME_BORDER_SIZE, box->y - yOffset + FRAME_BORDER_SIZE, 0, + 0,0,0 + ); shaderUseTexture(shader, &box->font->texture); primitiveDraw(&box->primitive, charStart, charCount); } void vnTextBoxDispose(vntextbox_t *box) { - primitiveDispose(&box->primitive); - primitiveDispose(&box->testPrimitive); - textureDispose(&box->testTexture); - box->primitive.indiceCount = 0; + frameDispose(&box->frame); + + if(box->primitive.indiceCount > 0) { + primitiveDispose(&box->primitive); + box->primitive.indiceCount = 0; + } } bool vnTextBoxHasScrolled(vntextbox_t *box) { diff --git a/src/vn/gui/vntextbox.h b/src/vn/gui/vntextbox.h index 9e860c10..0d66030a 100644 --- a/src/vn/gui/vntextbox.h +++ b/src/vn/gui/vntextbox.h @@ -13,14 +13,16 @@ #include "../../display/gui/font.h" #include "../../display/primitives/quad.h" #include "../../input/input.h" +#include "../../ui/frame.h" /** * Initializes the Visual Novel Text Box to its initial state. * * @param box The box to initialize. * @param font Font for the text box to use by default. + * @param texture Texture for the GUI Frame Element. */ -void vnTextBoxInit(vntextbox_t *box, font_t *font); +void vnTextBoxInit(vntextbox_t *box, font_t *font, texture_t *texture); /** * Sets just the text and does all necessary changes to the text. Set up your diff --git a/src/vn/vnscene.c b/src/vn/vnscene.c index 99d241dd..05d7946f 100644 --- a/src/vn/vnscene.c +++ b/src/vn/vnscene.c @@ -7,9 +7,9 @@ #include "vnscene.h" -void vnSceneInit(vnscene_t *scene, font_t *font) { +void vnSceneInit(vnscene_t *scene, font_t *font, texture_t *text) { // Init the conversation - vnConversationInit(&scene->conversation, font); + vnConversationInit(&scene->conversation, font, text); scene->conversation.textbox.linesMax = 3; // Reset character count diff --git a/src/vn/vnscene.h b/src/vn/vnscene.h index 3b1d5008..e44286ed 100644 --- a/src/vn/vnscene.h +++ b/src/vn/vnscene.h @@ -13,7 +13,7 @@ #include "../display/camera.h" #include "../display/shader.h" -void vnSceneInit(vnscene_t *scene, font_t *font); +void vnSceneInit(vnscene_t *scene, font_t *font, texture_t *text); void vnSceneUpdate(vnscene_t *scene, engine_t *engine);