Conversation code cleaned up a lot.
This commit is contained in:
43
src/vn/conversation/talk.c
Normal file
43
src/vn/conversation/talk.c
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "talk.h"
|
||||
|
||||
void _vnConversationTalkStart(queue_t *queue,queueaction_t *action,uint8_t i) {
|
||||
vnconversationitemdata_t *data;
|
||||
data = (vnconversationitemdata_t *)action->data;
|
||||
vnTextBoxSetText(&data->conversation->textbox, data->text);
|
||||
if(data->character != NULL) data->character->talking = true;
|
||||
}
|
||||
|
||||
void _vnConversationTalkUpdate(queue_t *queue,queueaction_t *action,uint8_t i) {
|
||||
vnconversationitemdata_t *data;
|
||||
data = (vnconversationitemdata_t *)action->data;
|
||||
if(data->conversation->textbox.state & VN_TEXTBOX_STATE_CLOSED) {
|
||||
if(data->character != NULL) data->character->talking = false;
|
||||
queueNext(queue);
|
||||
}
|
||||
}
|
||||
|
||||
queueaction_t * vnConversationTalk(
|
||||
vnconversation_t *conversation,
|
||||
char *text,
|
||||
vncharacter_t *character
|
||||
) {
|
||||
queueaction_t *action;
|
||||
vnconversationitemdata_t *data;
|
||||
|
||||
action = vnConversationAdd(conversation);
|
||||
action->onStart = &_vnConversationTalkStart;
|
||||
action->onUpdate = &_vnConversationTalkUpdate;
|
||||
|
||||
data = (vnconversationitemdata_t *)action->data;
|
||||
data->text = text;
|
||||
data->character = character;
|
||||
|
||||
return action;
|
||||
}
|
31
src/vn/conversation/talk.h
Normal file
31
src/vn/conversation/talk.h
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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 "vnconversation.h"
|
||||
#include "../../display/animation/queue.h"
|
||||
|
||||
/** Event Callback for when the talk action starts */
|
||||
void _vnConversationTalkStart(queue_t *q, queueaction_t *a, uint8_t i);
|
||||
|
||||
/** Event Callback for when the talk action updates */
|
||||
void _vnConversationTalkUpdate(queue_t *q, queueaction_t *a, uint8_t i);
|
||||
|
||||
/**
|
||||
* Adds text to the conversation queue.
|
||||
*
|
||||
* @param conversation Conversation to add the text to.
|
||||
* @param text Text to add.
|
||||
* @param character Character that is talking, or NULL.
|
||||
* @return Pointer to the queue item that was added for this text.
|
||||
*/
|
||||
queueaction_t * vnConversationTalk(
|
||||
vnconversation_t *conversation,
|
||||
char *text,
|
||||
vncharacter_t *character
|
||||
);
|
42
src/vn/conversation/vnconversation.c
Normal file
42
src/vn/conversation/vnconversation.c
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "vnconversation.h"
|
||||
|
||||
void vnConversationInit(vnconversation_t *convo, font_t *font) {
|
||||
vnTextBoxInit(&convo->textbox, font);
|
||||
queueInit(&convo->actionQueue);
|
||||
}
|
||||
|
||||
queueaction_t * vnConversationAdd(vnconversation_t *conversation) {
|
||||
queueaction_t *action;
|
||||
vnconversationitemdata_t *data;
|
||||
|
||||
// Update action queue data item.
|
||||
data = conversation->itemData + conversation->actionQueue.count;
|
||||
data->conversation = conversation;
|
||||
|
||||
// Add to queue
|
||||
action = queueAdd(&conversation->actionQueue);
|
||||
action->data = data;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
void vnConversationUpdate(vnconversation_t *convo, engine_t *engine) {
|
||||
queueUpdate(&convo->actionQueue, engine);
|
||||
vnTextBoxUpdate(&convo->textbox, engine);
|
||||
}
|
||||
|
||||
void vnConversationRender(vnconversation_t *convo, shader_t *shader) {
|
||||
vnTextBoxRender(&convo->textbox, shader);
|
||||
}
|
||||
|
||||
void vnConversationDispose(vnconversation_t *convo) {
|
||||
queueDispose(&convo->actionQueue);
|
||||
vnTextBoxDispose(&convo->textbox);
|
||||
}
|
48
src/vn/conversation/vnconversation.h
Normal file
48
src/vn/conversation/vnconversation.h
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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 "../gui/vntextbox.h"
|
||||
#include "../../util/array.h"
|
||||
#include "../../display/animation/timeline.h"
|
||||
#include "../../display/animation/queue.h"
|
||||
|
||||
/**
|
||||
* Initialize the conversation set. After adding your first conversation element
|
||||
* then ensure you call vnConversationNext to begin the conversation.
|
||||
* @param convo Conversation to initialize.
|
||||
* @param font Font to initialize with.
|
||||
*/
|
||||
void vnConversationInit(vnconversation_t *convo, font_t *font);
|
||||
|
||||
/**
|
||||
* Add a text element to the conversation.
|
||||
* @param convo Conversation to add to.
|
||||
* @return The pointer to the queue element.
|
||||
*/
|
||||
queueaction_t * vnConversationAdd(vnconversation_t *convo);
|
||||
|
||||
/**
|
||||
* Updates the conversation logic and the wrapped textbox.
|
||||
* @param convo Conversation to update.
|
||||
* @param engine Engine used to update.
|
||||
*/
|
||||
void vnConversationUpdate(vnconversation_t *convo, engine_t *engine);
|
||||
|
||||
/**
|
||||
* Renders the conversation, mostly just a wrapper for the textbox.
|
||||
* @param convo Conversation to render.
|
||||
* @param shader Shader to use while rendering.
|
||||
*/
|
||||
void vnConversationRender(vnconversation_t *convo, shader_t *shader);
|
||||
|
||||
/**
|
||||
* Dispose the conversation when finished.
|
||||
* @param convo Conversation to dispose.
|
||||
*/
|
||||
void vnConversationDispose(vnconversation_t *convo);
|
Reference in New Issue
Block a user