Improved Language Support
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "../../poker/poker.h"
|
||||
#include "../../vn/vnconversation.h"
|
||||
#include "../../vn/vnscene.h"
|
||||
#include "pokerui.h"
|
||||
|
||||
/** Name of the Poker Game */
|
||||
#define POKER_GAME_NAME "Dawn Poker Game"
|
||||
@ -24,4 +25,7 @@ typedef struct {
|
||||
|
||||
/** Assets for the game. */
|
||||
pokergameassets_t assets;
|
||||
|
||||
/** UI For the Game */
|
||||
pokerui_t ui;
|
||||
} pokergame_t;
|
@ -8,7 +8,13 @@
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../ui/label.h"
|
||||
#include "../../poker/player.h"
|
||||
|
||||
typedef struct {
|
||||
label_t labelTest;
|
||||
label_t labelChips;
|
||||
label_t labelName;
|
||||
} pokerplayerui_t;
|
||||
|
||||
typedef struct {
|
||||
pokerplayerui_t players[POKER_PLAYER_COUNT];
|
||||
} pokerui_t;
|
@ -17,6 +17,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
char *key;
|
||||
char *text;
|
||||
} languagestring_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -20,6 +20,8 @@ typedef struct {
|
||||
float scaleX, scaleY;
|
||||
float blinkStart;
|
||||
|
||||
char *name;
|
||||
|
||||
bool talking;
|
||||
|
||||
tileset_t tilesetEyes;
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <dawn/dawn.h>
|
||||
#include "../engine/engine.h"
|
||||
|
||||
#include "../locale/language.h"
|
||||
|
||||
#if SETTING_GAME == SETTING_GAME_POKER
|
||||
#include "poker/pokergame.h"
|
||||
#elif SETTING_GAME == SETTING_GAME_DAWN
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
#include "pokergame.h"
|
||||
|
||||
label_t label;
|
||||
|
||||
bool pokerGameInit(game_t *game) {
|
||||
pokergame_t *pokerGame = &game->pokerGame;
|
||||
|
||||
@ -18,25 +16,12 @@ bool pokerGameInit(game_t *game) {
|
||||
// Load the Assets
|
||||
pokerGameAssetsInit(&pokerGame->assets);
|
||||
|
||||
// Initialize the UI.
|
||||
pokerUiInit(pokerGame);
|
||||
|
||||
// Prep the VN Conversation Engine.
|
||||
vnSceneInit(&pokerGame->scene, &pokerGame->assets.font);
|
||||
pokerGameActionStartAdd(pokerGame);
|
||||
|
||||
labelInit(&label);
|
||||
label.y = 32;
|
||||
label.fontSize = 8.0;
|
||||
labelSetText(&label, &pokerGame->assets.font, "Hello World");
|
||||
|
||||
// pokerActionMatchAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionMatchAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionRoundAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionBlindsAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// pokerActionDealAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
// vnConversationTalk(&pokerGame->scene.conversation, "Betting Round", NULL);
|
||||
// pokerActionFlopAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker);
|
||||
|
||||
|
||||
// Begin the VN conversation queue.
|
||||
queueNext(&pokerGame->scene.conversation.actionQueue);
|
||||
|
||||
return true;
|
||||
@ -54,11 +39,13 @@ 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);
|
||||
labelRender(&label, &pokerGame->assets.shader);
|
||||
pokerUiRender(pokerGame);
|
||||
}
|
||||
|
||||
void pokerGameDispose(game_t *game) {
|
||||
pokerUiDispose(&game->pokerGame);
|
||||
vnSceneDispose(&game->pokerGame.scene);
|
||||
pokerGameAssetsDispose(&game->pokerGame.assets);
|
||||
}
|
@ -12,8 +12,7 @@
|
||||
#include "../../vn/conversation/talk.h"
|
||||
#include "../../vn/vnscene.h"
|
||||
#include "actions/start.h"
|
||||
|
||||
#include "../../ui/label.h"
|
||||
#include "pokerui.h"
|
||||
|
||||
/**
|
||||
* Initializes the game state for the poker game.
|
||||
|
@ -7,6 +7,55 @@
|
||||
|
||||
#include "pokerui.h"
|
||||
|
||||
void pokerUiInit(pokerui_t *ui) {
|
||||
void pokerUiInit(pokergame_t *pokerGame) {
|
||||
pokerplayerui_t *playerUi;
|
||||
pokerplayer_t *playerPoker;
|
||||
vncharacter_t *character;
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
playerUi = pokerGame->ui.players + i;
|
||||
playerPoker = pokerGame->poker.players + i;
|
||||
character = pokerGame->scene.characters + i;
|
||||
|
||||
// Chips label
|
||||
labelInit(&playerUi->labelChips);
|
||||
playerUi->labelChips.fontSize = 12.0;
|
||||
|
||||
// Name Label
|
||||
labelInit(&playerUi->labelName);
|
||||
playerUi->labelName.fontSize = 12.0;
|
||||
// labelSetText(&playerUi->labelChips, &pokerGame->assets.font, character->name);
|
||||
}
|
||||
}
|
||||
|
||||
void pokerUiRender(pokergame_t *pokerGame) {
|
||||
pokerplayerui_t *playerUi;
|
||||
pokerplayer_t *playerPoker;
|
||||
uint8_t i;
|
||||
char buffer[256];
|
||||
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
playerUi = pokerGame->ui.players + i;
|
||||
playerPoker = pokerGame->poker.players + i;
|
||||
|
||||
// Player Chips
|
||||
sprintf(buffer, "%u chips", playerPoker->chips);
|
||||
playerUi->labelChips.y = (i+1) * 32;
|
||||
labelSetText(&playerUi->labelChips, &pokerGame->assets.font, buffer);
|
||||
labelRender(&playerUi->labelChips, &pokerGame->assets.shader);
|
||||
|
||||
// Player Name
|
||||
labelRender(&playerUi->labelName, &pokerGame->assets.shader);
|
||||
}
|
||||
}
|
||||
|
||||
void pokerUiDispose(pokergame_t *pokerGame) {
|
||||
pokerplayerui_t *player;
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = pokerGame->ui.players + i;
|
||||
labelDispose(&player->labelChips);
|
||||
}
|
||||
}
|
@ -9,4 +9,8 @@
|
||||
#include <dawn/dawn.h>
|
||||
#include "../../ui/label.h"
|
||||
|
||||
void pokerUiInit(pokerui_t *ui);
|
||||
void pokerUiInit(pokergame_t *pokerGame);
|
||||
|
||||
void pokerUiRender(pokergame_t *pokerGame);
|
||||
|
||||
void pokerUiDispose(pokergame_t *pokerGame);
|
@ -7,13 +7,29 @@
|
||||
|
||||
#include "language.h"
|
||||
|
||||
void languageInit(language_t *language) {
|
||||
language->stringCount = 0;
|
||||
}
|
||||
|
||||
languagestring_t * languageAddString(language_t *lang, char *key, char *text) {
|
||||
languagestring_t *string;
|
||||
|
||||
string = lang->strings + lang->stringCount;
|
||||
string->key = key;
|
||||
string->text = text;
|
||||
|
||||
lang->stringCount++;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
languagestring_t * languageGetStringByKey(language_t *language, char *key) {
|
||||
int32_t i;
|
||||
languagestring_t *string;
|
||||
|
||||
for(i = 0; i < language->stringCount; i++) {
|
||||
string = language->strings + i;
|
||||
if(string->key != key) continue;
|
||||
if(strcmp(string->key, key) != 0) continue;
|
||||
return string;
|
||||
}
|
||||
|
||||
@ -21,25 +37,103 @@ languagestring_t * languageGetStringByKey(language_t *language, char *key) {
|
||||
}
|
||||
|
||||
char * languageGetText(language_t *language, languagestring_t *string) {
|
||||
// Try and find the value
|
||||
|
||||
// Load the value into memory.
|
||||
|
||||
// Return the value
|
||||
return NULL;
|
||||
// TODO: Buffer this from somewhere.
|
||||
return string->text;
|
||||
}
|
||||
|
||||
char * languageGetTextWithVariables(
|
||||
language_t *language, languagestring_t *string, languagevariable_t *variable
|
||||
int32_t languageGetTextWithVariables(
|
||||
language_t *language, languagestring_t *string,
|
||||
languagevariable_t *variables, int32_t variableCount,
|
||||
char *buffer
|
||||
) {
|
||||
char *text = languageGetText(language, string);
|
||||
if(text == NULL) return NULL;
|
||||
int32_t i, l, n;
|
||||
char *text;
|
||||
char c;
|
||||
char keyBuffer[32];
|
||||
languagevariable_t *variable;
|
||||
|
||||
// Scan the string, determine the new length and positions of the variables
|
||||
text = languageGetText(language, string);
|
||||
if(text == NULL) return 0;
|
||||
|
||||
// Now create some memory for the new string
|
||||
// Start two counters. I holds source index, L holds target index.
|
||||
i = 0;
|
||||
l = 0;
|
||||
|
||||
// Now buffer the old string into the new string and take the language
|
||||
while(true) {
|
||||
c = text[i];
|
||||
if(c == '\0') break;// Break on end of string.
|
||||
|
||||
return text;
|
||||
// Look for {{, if not {{ then just treat as normal string.
|
||||
if(c != '{' || text[i + 1] != '{') {
|
||||
buffer[l] = c;
|
||||
i++;
|
||||
l++;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Ignore those two chars
|
||||
i += 2;
|
||||
|
||||
// Skip space(s)
|
||||
while(true) {
|
||||
c = text[i];
|
||||
if(c != ' ') break;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Get the key name
|
||||
n = 0;// Will hold the index within keyBuffer to copy chars into.
|
||||
while(true) {
|
||||
c = text[i];
|
||||
|
||||
// Don't overflow
|
||||
if(c == '\0') break;
|
||||
|
||||
// Skip spaces
|
||||
if(c == ' ') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle end of key
|
||||
if(c == '}') {
|
||||
i++;
|
||||
if(text[i] == '}') i++;// For }} then skip the second }
|
||||
break;
|
||||
}
|
||||
|
||||
// Add to buffer.
|
||||
keyBuffer[n] = c;
|
||||
n++;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Seal the keyBuffer string
|
||||
keyBuffer[n] = '\0';
|
||||
|
||||
// Now check each variable for a match.
|
||||
for(n = 0; n < variableCount; n++) {
|
||||
variable = variables + n;
|
||||
if(strcmp(keyBuffer, variable->name) != 0) continue;// Does the key match?
|
||||
|
||||
// Begin copying the variables' value into the string.
|
||||
n = 0;
|
||||
while(true) {
|
||||
if(variable->value[n] == '\0') break;// Handle end of variable value
|
||||
buffer[l] = variable->value[n];
|
||||
l++;
|
||||
n++;
|
||||
}
|
||||
// We found the value, so break.
|
||||
break;
|
||||
}
|
||||
|
||||
// Continue looking for next {{ variable }}...
|
||||
}
|
||||
|
||||
// Buffer has been fully cloned, seal the string.
|
||||
buffer[l] = '\0';
|
||||
|
||||
// Return the count of chars we wrote to the buffer. -1 due to null term.
|
||||
return l - 1;
|
||||
}
|
@ -8,6 +8,21 @@
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initializes a language.
|
||||
* @param language Language to initialize.
|
||||
*/
|
||||
void languageInit(language_t *language);
|
||||
|
||||
/**
|
||||
* Adds a string to a language.
|
||||
* @param lang Language to add to.
|
||||
* @param key Key to use for the string.
|
||||
* @param text Value to use for the language string
|
||||
* @return The language string added to the language.
|
||||
*/
|
||||
languagestring_t * languageAddString(language_t *lang, char *key, char *text);
|
||||
|
||||
/**
|
||||
* Returns the language string for a given language string key.
|
||||
*
|
||||
@ -26,6 +41,19 @@ languagestring_t * languageGetStringByKey(language_t *language, char *key);
|
||||
*/
|
||||
char * languageGetText(language_t *language, languagestring_t *string);
|
||||
|
||||
char * languageGetTextWithVariables(
|
||||
language_t *language, languagestring_t *string, languagevariable_t *variable
|
||||
/**
|
||||
* Retreives the value of a given language string, and replaces the variables in
|
||||
* the string with the provided variable values.
|
||||
*
|
||||
* @param language Language to read from.
|
||||
* @param string String to get and parse.
|
||||
* @param variables Variables to use in the parsing.
|
||||
* @param variableCount How many variables in the array.
|
||||
* @param buffer The buffer to write the output data to.
|
||||
* @return The count of characters that were written to the buffer.
|
||||
*/
|
||||
int32_t languageGetTextWithVariables(
|
||||
language_t *language, languagestring_t *string,
|
||||
languagevariable_t *variables, int32_t variableCount,
|
||||
char *buffer
|
||||
);
|
@ -23,7 +23,7 @@ void labelSetText(label_t *label, font_t *font, char *text) {
|
||||
}
|
||||
|
||||
label->font = font;
|
||||
fontTextClamp(font, &label->info, text, -1, 16.0);
|
||||
fontTextClamp(font, &label->info, text, -1, label->fontSize);
|
||||
fontTextInit(font, &label->primitive, &label->info);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ void vnCharacterInit(vncharacter_t *character,
|
||||
character->talking = false;
|
||||
character->blinkStart = randFloatRange(0, VN_CHARACTER_BLINK_TIME_RANGE_MAX);
|
||||
|
||||
character->name = "";
|
||||
|
||||
// Setup Textures
|
||||
character->textureEyes = textureEyes;
|
||||
character->textureBody = textureBody;
|
||||
|
Reference in New Issue
Block a user