Basic animations

This commit is contained in:
2022-12-04 15:36:40 -08:00
parent ba9881e39d
commit b5d7c927c5
15 changed files with 314 additions and 28 deletions

View File

@ -29,6 +29,7 @@ namespace Dawn {
std::vector<Asset*> assets;
vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan));
vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan));
return assets;
}
@ -50,12 +51,12 @@ namespace Dawn {
auto pokerGameItem = this->createSceneItem();
auto pokerGame = pokerGameItem->addComponent<PokerGame>();
for(int32_t i = 0; i < 4; i++) {
for(int32_t i = 0; i < 5; i++) {
auto pokerPlayerInstance = this->createSceneItem();
auto pokerPlayer = pokerPlayerInstance->addComponent<PokerPlayer>();
auto uiPlayer = canvas->addElement<PokerPlayerDisplay>();
uiPlayer->setTransform(UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, glm::vec4(0, 0, 0, 0), 0);
uiPlayer->setTransform(UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, glm::vec4(i * 220, 0, 0, 0), 0);
uiPlayer->setPlayer(pokerPlayer);
}

View File

@ -8,24 +8,16 @@
using namespace Dawn;
void PokerPlayerDisplay::updatePositions() {
UIEmpty::updatePositions();
this->labelChips.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, this->labelName.getHeight(), 0, 0),
0
);
}
PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
UIEmpty(canvas),
labelName(canvas),
labelChips(canvas)
{
this->font = canvas->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
this->font = getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
// Player Name
this->addChild(&this->labelName);
this->labelName.setText("Player Name");
this->labelName.setFont(&this->font->font);
this->labelName.setFontSize(40);
this->labelName.setTransform(
@ -34,29 +26,53 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
0.0f
);
// Chips label
this->addChild(&this->labelChips);
this->labelChips.setFont(&this->font->font);
this->labelChips.setFontSize(40);
this->labelChips.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, this->labelName.getContentHeight(), 0, 0),
0.0f
);
this->font->eventLoaded.addListener(this, &PokerPlayerDisplay::onFontLoaded);
// Events
getScene()->eventSceneUnpausedUpdate.addListener(this, &PokerPlayerDisplay::onSceneUpdate);
}
void PokerPlayerDisplay::setPlayer(PokerPlayer *player) {
assertNull(this->player);
this->player = player;
this->labelName.setText("Player");
this->labelChips.setText("Chips");
player->eventChipsChanged.addListener(this, &PokerPlayerDisplay::onPlayerChipsChanged);
this->labelName.setText("Name");
this->animChips.clear();
this->animChips.restart();
this->animChipsValue = player->chips;
this->updatePositions();
}
void PokerPlayerDisplay::onFontLoaded() {
this->labelName.setFont(&this->font->font);
this->labelChips.setFont(&this->font->font);
void PokerPlayerDisplay::onSceneUpdate() {
this->animChips.tick(getGame()->timeManager.delta);
this->updatePositions();
std::stringstream stream;
stream.precision(0);
stream << "$";
stream << this->animChipsValue;
this->labelChips.setText(stream.str());
}
void PokerPlayerDisplay::onPlayerChipsChanged() {
std::cout << "Chips" << player->chips << std::endl;
this->animChips.clear();
this->animChips.addKeyframe(&this->animChipsValue, 0.0f, this->animChipsValue);
this->animChips.addKeyframe(&this->animChipsValue, 1.0f, this->player->chips);
this->animChips.restart();
}
PokerPlayerDisplay::~PokerPlayerDisplay() {
this->font->eventLoaded.removeListener(this, &PokerPlayerDisplay::onFontLoaded);
this->canvas->getScene()->eventSceneUnpausedUpdate.removeListener(this, &PokerPlayerDisplay::onSceneUpdate);
}

View File

@ -7,12 +7,15 @@
#include "ui/UILabel.hpp"
#include "ui/UIEmpty.hpp"
#include "poker/PokerPlayer.hpp"
#include "asset/AssetManager.hpp"
#include "asset/assets/TrueTypeAsset.hpp"
#include "display/animation/Animation.hpp"
namespace Dawn {
class PokerPlayerDisplay : public UIEmpty {
private:
void onFontLoaded();
Animation<int32_t> animChips;
int32_t animChipsValue;
protected:
PokerPlayer *player = nullptr;
@ -20,9 +23,16 @@ namespace Dawn {
UILabel labelChips;
TrueTypeAsset *font;
void updatePositions() override;
void onPlayerChipsChanged();
void onSceneUpdate();
public:
static std::vector<Asset*> getAssets(AssetManager *assMan) {
return std::vector<Asset*>{
assMan->get<TrueTypeAsset>("truetype_ark")
};
}
PokerPlayerDisplay(UICanvas *canvas);
void setPlayer(PokerPlayer *player);