Testing some UI interactions.

This commit is contained in:
2021-09-20 11:42:53 -07:00
parent b3e06a3837
commit c0ce11a44a
5 changed files with 117 additions and 21 deletions

View File

@ -7,6 +7,17 @@
#include "bet.h"
void _pokerGameActionBetOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
bool isHuman;
pokergame_t *game = (pokergame_t *)action->data;
// Reset the UI state.
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
if(isHuman) pokerUiBetShow(&game->ui);
}
void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i
) {
@ -24,12 +35,8 @@ void _pokerGameActionBetOnUpdate(
// Handle as an AI
if(isHuman) {
if(inputIsPressed(&game->engine.input, INPUT_DOWN)) {
} else if(inputIsPressed(&game->engine.input, INPUT_RIGHT)) {
} else if(inputIsPressed(&game->engine.input, INPUT_UP)) {
}
turn = game->ui.betTurn;
turnMade = game->ui.betTurnMade;
} else {
turn = pokerTurnGet(&game->poker, game->poker.bet.better);
turnMade = true;
@ -93,7 +100,11 @@ void _pokerGameActionBetOnEnd(
// Are we waiting on any players?
if(game->poker.bet.better != 0xFF) {
pokerGameActionLookAdd(game, game->poker.bet.better);
if(game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX) {
pokerGameActionLookAdd(game, POKER_DEALER_INDEX);
} else {
pokerGameActionLookAdd(game, game->poker.bet.better);
}
pokerGameActionBetAdd(game);
return;
}
@ -123,6 +134,7 @@ void _pokerGameActionBetOnEnd(
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionBetOnStart;
action->onUpdate = &_pokerGameActionBetOnUpdate;
action->onEnd = &_pokerGameActionBetOnEnd;
return action;

View File

@ -41,6 +41,9 @@ void pokerUiInit(pokerui_t *ui) {
POKER_UI_PLAYER_IMAGE_RESOLUTION
);
}
// Rest the betting ui
ui->betShow = false;
}
void pokerUiUpdate(
@ -61,6 +64,7 @@ void pokerUiUpdate(
// Render the face of each player.
j = 0;
shaderUse(shader);
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
if(i == POKER_PLAYER_HUMAN_INDEX) continue;
player = players + j;
@ -77,13 +81,12 @@ void pokerUiUpdate(
);
// Bind the frame buffer
frameBufferUse(ui->frames+j, true);
frameBufferUse(ui->frames + j, true);
// Render the VN character
shaderUse(shader);
shaderUseCamera(shader, &camera);
shaderUsePosition(shader, 0,0,0, 0,0,0);
vnCharacterRender(characters + j, shader);
vnCharacterRender(characters + i, shader);
// Increment
j++;
@ -116,22 +119,31 @@ void pokerUiRender(
}
}
player = poker->players + POKER_PLAYER_HUMAN_INDEX;
if(poker->bet.better == POKER_PLAYER_HUMAN_INDEX) {
// Betting UI
if(ui->betShow) {
sprintf(message, "Press down to fold, up to bet, right to check/call.");
labelSetText(&ui->label, &assets->font, message);
labelRender(&ui->label, &assets->shader, 300, 100);
if(inputIsPressed(&engine->input, INPUT_DOWN)) {
ui->betTurn = pokerTurnFold(poker, poker->bet.better);
ui->betTurnMade = true;
} else if(inputIsPressed(&engine->input, INPUT_RIGHT)) {
ui->betTurn = pokerTurnCall(poker, poker->bet.better);
}
if(ui->betTurnMade) ui->betShow = false;
}
// </testing>
// Player UI
j = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
if(i == POKER_PLAYER_HUMAN_INDEX) continue;
// Get the player.
player = poker->players + i;
// Position the grid itself.
x = 0;
x = engine->render.width - POKER_UI_PLAYER_WIDTH;
y = (float)(POKER_UI_PLAYER_HEIGHT * j);
// Render face
@ -198,4 +210,9 @@ void pokerUiSetImageToCard(image_t *image, texture_t *texture, card_t card) {
cardGetSuit(card) * 96.0f,
71, 96
);
}
void pokerUiBetShow(pokerui_t *ui) {
ui->betShow = true;
ui->betTurnMade = false;
}

View File

@ -15,6 +15,7 @@
#include "../../display/primitives/cube.h"
#include "../../display/shader.h"
#include "../../engine/engine.h"
#include "../../input/input.h"
#include "../../display/camera.h"
#include "../../vn/vncharacter.h"
#include "../../ui/grid.h"
@ -22,6 +23,7 @@
#include "../../poker/player.h"
#include "../../poker/poker.h"
#include "../../poker/bet.h"
#include "../../poker/turn.h"
#include "../../vn/vnscene.h"
#include "pokerworld.h"
#include "pokergameassets.h"
@ -36,12 +38,21 @@
#define POKER_UI_PLAYER_PADDING 8
#define POKER_UI_PLAYER_CHIPS_ANIMATION_SPEED 0.5f
#define POKER_UI_BET_ACTION_NONE 0x00
#define POKER_UI_BET_ACTION_FOLD 0x01
#define POKER_UI_BET_ACTION_BET 0x02
typedef struct {
primitive_t quad;
label_t label;
grid_t grid;
image_t card;
framebuffer_t frames[POKER_PLAYER_COUNT];
/** Betting UI */
bool betShow;
pokerturn_t betTurn;
bool betTurnMade;
} pokerui_t;
/**
@ -91,4 +102,11 @@ void pokerUiDispose(pokerui_t *ui);
* @param texture Texture to use.
* @param card Card to set to.
*/
void pokerUiSetImageToCard(image_t *image, texture_t *texture, card_t card);
void pokerUiSetImageToCard(image_t *image, texture_t *texture, card_t card);
/**
* Show and reset the betting UI.
*
* @param ui UI to reset the bet state for.
*/
void pokerUiBetShow(pokerui_t *ui);

View File

@ -7,10 +7,10 @@
#include "turn.h"
pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
pokerturn_t turn;
pokerplayer_t *player;
bool canCheck;
player = poker->players + playerIndex;
@ -19,9 +19,7 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
if(player->state & POKER_PLAYER_STATE_FOLDED) return turn;
if(player->state & POKER_PLAYER_STATE_OUT) return turn;
canCheck = player->currentBet >= poker->bet.currentBet;
if(canCheck) {
if(pokerTurnCanPlayerCheck(poker, playerIndex)) {
turn.type = POKER_TURN_TYPE_CHECK;
return turn;
}
@ -42,10 +40,42 @@ void pokerTurnAction(poker_t *poker, pokerplayer_t *player, pokerturn_t *turn) {
pokerBetPlayer(poker, player, turn->chips);
break;
case POKER_TURN_TYPE_CHECK:
break;
case POKER_TURN_TYPE_FOLD:
player->state |= POKER_PLAYER_STATE_FOLDED;
break;
}
player->state |= POKER_PLAYER_STATE_ROUND_MOVE;
}
pokerturn_t pokerTurnFold(poker_t *poker, uint8_t player) {
pokerturn_t turn;
turn.type = POKER_TURN_TYPE_FOLD;
return turn;
}
void pokerTurnCheck(poker_t *poker, uint8_t player) {
pokerturn_t turn;
turn.type = POKER_TURN_TYPE_CHECK;
turn.chips = 0;
return turn;
}
void pokerTurnCall(poker_t *poker, uint8_t playerIndex) {
pokerturn_t turn;
pokerplayer_t *player;
bool canCheck;
player = poker->players + playerIndex;
turn.type = POKER_TURN_TYPE_CHECK;
turn.chips = poker->bet.currentBet - player->chips;
return turn;
}
bool pokerTurnCanPlayerCheck(poker_t *poker, uint8_t playerIndex) {
return (poker->players + playerIndex)->currentBet >= poker->bet.currentBet;
}

View File

@ -35,6 +35,15 @@ typedef struct {
*/
pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex);
/**
* Return a turn action for the given player to fold.
*
* @param poker Poker game instance.
* @param player Player index.
* @return A turn for a fold action.
*/
pokerturn_t pokerTurnFold(poker_t *poker, uint8_t player);
/**
* Perform the turn's action.
*
@ -42,4 +51,14 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex);
* @param player Player instance.
* @param turn Turn to action.
*/
void pokerTurnAction(poker_t *poker, pokerplayer_t *player, pokerturn_t *turn);
void pokerTurnAction(poker_t *poker, pokerplayer_t *player, pokerturn_t *turn);
/**
* Determine whether or not a player CAN check, given the current max bet and
* the players current bet.
*
* @param poker Poker game instance.
* @param playerIndex Poker player index.
* @return True if the player can check, false if they need to call first.
*/
bool pokerTurnCanPlayerCheck(poker_t *poker, uint8_t playerIndex);