Still working on my scrolling text and bug fixing.

This commit is contained in:
2021-07-16 22:26:04 -07:00
parent 06202f6f7e
commit f619b7c9d2
26 changed files with 495 additions and 115 deletions

63
temp/talk.c Normal file
View File

@ -0,0 +1,63 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "talk.h"
void pokerTalkInit(poker_t *poker) {
poker->talkText = NULL;
poker->talkTextInfo = NULL;
poker->textLastWidth = 0;
}
void pokerTalkDispose(poker_t *poker) {
if(poker->talkTextInfo == NULL) return;
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
}
void pokerTalkTextRebuffer(poker_t *poker) {
// Check if we need to force a redraw or not.
if(poker->talkText == NULL || poker->textLastWidth != poker->guiWidth) {
if(poker->talkTextInfo != NULL) {
fontTextInfoDispose(poker->talkTextInfo);
primitiveDispose(&poker->talkPrimitive);
poker->talkTextInfo = NULL;
}
}
if(poker->talkText == NULL) return;
// Rebuffer
poker->talkTextInfo = fontTextClamp(&poker->font, poker->talkText, poker->guiWidth);
fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo);
}
void pokerTalkRender(poker_t *poker, input_t *input) {
pokerTalkTextRebuffer(poker);
if(poker->talkTextInfo == NULL) return;
// Render text
shaderUsePosition(&poker->shader,
0,POKER_GUI_HEIGHT-poker->talkTextInfo->height,0,
0,0,0
);
shaderUseTexture(&poker->shader, &poker->font.texture);
primitiveDraw(&poker->talkPrimitive, 0, -1);
if(inputIsPressed(input, INPUT_ACCEPT)) {
poker->talkText = NULL;
}
}
void pokerTalk(poker_t *poker, char *text) {
poker->talkText = text;
poker->roundTextCounter++;
}
bool pokerTalkIsTalking(poker_t *poker) {
return poker->talkText != NULL || poker->talkTextInfo != NULL;
}

53
temp/talk.h Normal file
View File

@ -0,0 +1,53 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/gui/font.h"
#include "../../display/primitive.h"
#include "../../display/shader.h"
#include "../../input/input.h"
/**
* Initializes the talk manager.
* @param poker The poker game context.
*/
void pokerTalkInit(poker_t *poker);
/**
* Disposes and cleans the talk manager context.
* @param poker Poker instance.
*/
void pokerTalkDispose(poker_t *poker);
/**
* Internal method. Checks for changes and rebuffers the talk text information
* when scene changes occur.
* @param poker Poker game context to buffer for.
*/
void pokerTalkTextRebuffer(poker_t *poker);
/**
* Tick render method for the poker talk manager.
* @param poker Poker manager context.
* @param input Input manager to listen to.
*/
void pokerTalkRender(poker_t *poker, input_t *input);
/**
* Requests the talk manager to begin speaking some text.
* @param poker Poker game context
* @param text Text to speak. Please ensure this is kept alive during talk.
*/
void pokerTalk(poker_t *poker, char *text);
/**
* Returns true if the poker text manager is still running the talk.
* @param poker Poker manager.
* @returns True while the game is still running active text.
*/
bool pokerTalkIsTalking(poker_t *poker);