1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Zero-Pad displayed money value and slowly update it

This commit is contained in:
Jannik Vogel 2016-09-01 23:44:35 +02:00
parent fd6be733e0
commit 70f777c685
3 changed files with 40 additions and 4 deletions

View File

@ -86,7 +86,12 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world, GameRenderer* re
infoTextY += ui_textHeight; infoTextY += ui_textHeight;
ti.text = GameSymbols::Money + GameStringUtil::fromString(std::to_string(world->state->playerInfo.money)); {
std::stringstream ss;
ss << std::setw(8) << std::setfill('0') << world->state->playerInfo.displayedMoney;
ti.text = GameSymbols::Money + GameStringUtil::fromString(ss.str());
}
ti.baseColour = ui_shadowColour; ti.baseColour = ui_shadowColour;
ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f); ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f);
render->text.renderText(ti); render->text.renderText(ti);

View File

@ -174,10 +174,39 @@ void IngameState::exit()
void IngameState::tick(float dt) void IngameState::tick(float dt)
{ {
auto world = getWorld();
autolookTimer = std::max(autolookTimer - dt, 0.f); autolookTimer = std::max(autolookTimer - dt, 0.f);
// Update displayed money value
// @todo the game uses another algorithm which is non-linear
{
float moneyFrequency = 1.0f / 30.0f;
moneyTimer += dt;
while (moneyTimer >= moneyFrequency) {
int32_t difference = world->state->playerInfo.money - world->state->playerInfo.displayedMoney;
// Generates 0, 1 (difference < 100), 12 (difference < 1000), 123 (difference < 10000), .. etc.
// Negative input will result in negative output
auto GetIncrement = [](int32_t difference) -> int32_t {
// @todo is this correct for difference >= 1000000000 ?
int32_t r = 1;
int32_t i = 2;
if (difference == 0) { return 0; }
while (std::abs(difference) >= 100) {
difference /= 10;
r = r * 10 + i;
i++;
}
return (difference < 0) ? -r : r;
};
world->state->playerInfo.displayedMoney += GetIncrement(difference);
moneyTimer -= moneyFrequency;
}
}
auto player = game->getPlayer(); auto player = game->getPlayer();
const auto& input = getWorld()->state->input; const auto& input = world->state->input;
if( player && player->isInputEnabled() ) if( player && player->isInputEnabled() )
{ {
float viewDistance = 4.f; float viewDistance = 4.f;
@ -199,7 +228,7 @@ void IngameState::tick(float dt)
viewDistance = 4.f; viewDistance = 4.f;
} }
auto target = getWorld()->pedestrianPool.find(getWorld()->state->cameraTarget); auto target = world->pedestrianPool.find(world->state->cameraTarget);
if( target == nullptr ) if( target == nullptr )
{ {
@ -374,7 +403,7 @@ void IngameState::tick(float dt)
auto from = btVector3(rayStart.x, rayStart.y, rayStart.z); auto from = btVector3(rayStart.x, rayStart.y, rayStart.z);
ClosestNotMeRayResultCallback ray(physTarget, from, to); ClosestNotMeRayResultCallback ray(physTarget, from, to);
getWorld()->dynamicsWorld->rayTest(from, to, ray); world->dynamicsWorld->rayTest(from, to, ray);
if( ray.hasHit() && ray.m_closestHitFraction < 1.f ) if( ray.hasHit() && ray.m_closestHitFraction < 1.f )
{ {
cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(), cameraPosition = glm::vec3(ray.m_hitPointWorld.x(), ray.m_hitPointWorld.y(),

View File

@ -32,6 +32,8 @@ class IngameState : public State
bool m_invertedY; bool m_invertedY;
/// Free look in vehicles. /// Free look in vehicles.
bool m_vehicleFreeLook; bool m_vehicleFreeLook;
float moneyTimer; // Timer used to updated displayed money value
public: public:
/** /**
* @brief IngameState * @brief IngameState