133 lines
3.8 KiB
C
133 lines
3.8 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "pokerplayerui.h"
|
|
|
|
void pokerPlayerUiInit(pokerplayerui_t *ui) {
|
|
gridInit(&ui->grid);
|
|
labelInit(&ui->label);
|
|
frameBufferInit(&ui->frame,
|
|
POKER_PLAYER_UI_IMAGE_RESOLUTION, POKER_PLAYER_UI_IMAGE_RESOLUTION
|
|
);
|
|
quadInit(&ui->quad, 0,
|
|
0, 0, 0, 1,
|
|
POKER_PLAYER_UI_IMAGE_SIZE, POKER_PLAYER_UI_IMAGE_SIZE, 1, 0
|
|
);
|
|
|
|
// Set up the grid
|
|
ui->grid.gutterX = POKER_PLAYER_UI_PADDING;
|
|
ui->grid.columns = 2;
|
|
ui->grid.rows = 2;
|
|
ui->grid.columnDefinitions[1] = POKER_PLAYER_UI_IMAGE_SIZE;
|
|
ui->grid.rowDefinitions[0] = POKER_PLAYER_UI_IMAGE_SIZE / 2.0f;
|
|
ui->grid.rowDefinitions[1] = POKER_PLAYER_UI_IMAGE_SIZE / 2.0f;
|
|
}
|
|
|
|
void pokerPlayerUiUpdate(
|
|
pokerplayerui_t *ui, pokergame_t *game, shader_t *shader, int32_t playerIndex,
|
|
engine_t *engine
|
|
) {
|
|
camera_t camera;
|
|
uint8_t seat;
|
|
pokerplayer_t *player;
|
|
float x, y, z;
|
|
|
|
player = game->poker.players + playerIndex;
|
|
|
|
// Bind the frame buffer
|
|
frameBufferUse(&ui->frame, true);
|
|
|
|
// Set up the camera perspective
|
|
cameraPerspective(&camera, 45,
|
|
(float)POKER_PLAYER_UI_IMAGE_SIZE / (float)POKER_PLAYER_UI_IMAGE_SIZE,
|
|
0.03f, 10.0f
|
|
);
|
|
|
|
// Locate the XYZ position of the camera to look at the player
|
|
seat = pokerGameSeatFromIndex(playerIndex);
|
|
x = POKER_WORLD_SEAT_POSITION_X(seat);
|
|
y = POKER_PLAYER_UI_IMAGE_Y;
|
|
z = POKER_WORLD_SEAT_POSITION_Z(seat);
|
|
|
|
// Actually look at the player, we need to get close.
|
|
cameraLookAt(&camera,
|
|
x * POKER_PLAYER_UI_IMAGE_DIST, y, z * POKER_PLAYER_UI_IMAGE_DIST,
|
|
x, y, z
|
|
);
|
|
|
|
// Render the VN character
|
|
shaderUse(shader);
|
|
shaderUseCamera(shader, &camera);
|
|
shaderUsePosition(shader, 0,0,0, 0,0,0);
|
|
vnCharacterRender(game->scene.characters + playerIndex, shader);
|
|
|
|
// Unbind the frame buffer.
|
|
frameBufferUnbind(&engine->render, false);
|
|
}
|
|
|
|
void pokerPlayerUiRender(
|
|
pokerplayerui_t *ui, pokergame_t *game, shader_t *shader, font_t *font,
|
|
engine_t *engine,
|
|
int32_t playerIndex, float x, float y
|
|
) {
|
|
pokerplayer_t *player;
|
|
char buffer[32];
|
|
float scale;
|
|
align_t align;
|
|
|
|
float gx, gy, gw, gh;
|
|
|
|
// Font crap.
|
|
scale = fontGetScale(FONT_SIZE_DEFAULT);
|
|
player = game->poker.players + playerIndex;
|
|
|
|
// Align the grid itself.
|
|
gridResize(&ui->grid, POKER_PLAYER_UI_WIDTH, POKER_PLAYER_UI_HEIGHT);
|
|
|
|
// Render face
|
|
gridGetChild(&ui->grid, 1, 0, 1, 2, &gx, &gy, &gw, &gh);
|
|
shaderUseTexture(shader, &ui->frame.texture);
|
|
shaderUsePosition(shader, x+gx, y+gy, 0, 0,0,0);
|
|
primitiveDraw(&ui->quad, 0, -1);
|
|
|
|
// Render chips
|
|
sprintf(buffer, "$%i", player->chips);
|
|
ui->label.maxWidth = -1;
|
|
labelSetText(&ui->label, font, buffer);
|
|
align = gridGetAndAlignChild(
|
|
&ui->grid, 0, 0, 1, 1,
|
|
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
|
|
ui->label.info.width, ui->label.info.height
|
|
);
|
|
labelRender(&ui->label, shader, x+align.x, y+align.y);
|
|
|
|
// Render state
|
|
if(player->state & POKER_PLAYER_STATE_OUT) {
|
|
sprintf(buffer, "Out");
|
|
} else if(player->state & POKER_PLAYER_STATE_FOLDED) {
|
|
sprintf(buffer, "Folded");
|
|
} else if(player->state & POKER_PLAYER_STATE_SHOWING) {
|
|
sprintf(buffer, "Showing");
|
|
} else if(game->poker.bet.better == playerIndex) {
|
|
sprintf(buffer, "Thinking");
|
|
} else {
|
|
sprintf(buffer, "Whatever");
|
|
}
|
|
labelSetText(&ui->label, font, buffer);
|
|
align = gridGetAndAlignChild(
|
|
&ui->grid, 0, 1, 1, 1,
|
|
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
|
|
ui->label.info.width, ui->label.info.height
|
|
);
|
|
labelRender(&ui->label, shader, x+align.x, y+align.y);
|
|
}
|
|
|
|
void pokerPlayerUiDispose(pokerplayerui_t *ui) {
|
|
primitiveDispose(&ui->quad);
|
|
frameBufferDispose(&ui->frame);
|
|
labelDispose(&ui->label);
|
|
} |