1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

propagate turn timer state every second to ensure correct UI

This commit is contained in:
Ivan Savenko 2023-12-20 14:17:10 +02:00
parent f834cb3d99
commit fc595c5d84
4 changed files with 8 additions and 24 deletions

View File

@ -68,6 +68,8 @@ TurnTimerWidget::TurnTimerWidget(const Point & position, PlayerColor player)
pos.h += 16;
playerLabelsUnit[player] = std::make_shared<CLabel>(pos.w / 2, pos.h - 8, FONT_BIG, ETextAlignment::CENTER, graphics->playerColors[player], "");
}
updateTextLabel(player, LOCPLINT->cb->getPlayerTurnTime(player));
}
else
{
@ -86,6 +88,8 @@ TurnTimerWidget::TurnTimerWidget(const Point & position, PlayerColor player)
pos.h += 16;
playerLabelsMain[player] = std::make_shared<CLabel>(pos.w / 2, pos.h - 8, FONT_BIG, ETextAlignment::CENTER, graphics->playerColors[player], "");
updateTextLabel(player, LOCPLINT->cb->getPlayerTurnTime(player));
}
}
@ -157,26 +161,13 @@ void TurnTimerWidget::updateTextLabel(PlayerColor player, const TurnTimerInfo &
else
mainLabel->setText(msToString(timer.baseTimer + timer.turnTimer));
}
}
void TurnTimerWidget::updateTimer(PlayerColor player, uint32_t msPassed)
{
const auto & gamestateTimer = LOCPLINT->cb->getPlayerTurnTime(player);
if (!(lastUpdateTimers[player] == gamestateTimer))
{
lastUpdateTimers[player] = gamestateTimer;
countingDownTimers[player] = gamestateTimer;
}
auto & countingDownTimer = countingDownTimers[player];
if(countingDownTimer.isActive && LOCPLINT->cb->isPlayerMakingTurn(player))
countingDownTimer.substractTimer(msPassed);
updateNotifications(player, countingDownTimer.valueMs());
updateTextLabel(player, countingDownTimer);
updateNotifications(player, gamestateTimer.valueMs());
updateTextLabel(player, gamestateTimer);
}
void TurnTimerWidget::tick(uint32_t msPassed)

View File

@ -29,8 +29,6 @@ class TurnTimerWidget : public CIntObject
bool isBattleMode;
std::set<int> notificationThresholds;
std::map<PlayerColor, TurnTimerInfo> lastUpdateTimers;
std::map<PlayerColor, TurnTimerInfo> countingDownTimers;
std::map<PlayerColor, std::shared_ptr<CLabel>> playerLabelsMain;
std::map<PlayerColor, std::shared_ptr<CLabel>> playerLabelsBattle;

View File

@ -105,11 +105,8 @@ bool TurnTimerHandler::timerCountDown(int & timer, int initialTimer, PlayerColor
{
timer -= waitTime;
lastUpdate[player] += waitTime;
int frequency = (timer > turnTimePropagateThreshold
&& initialTimer - timer > turnTimePropagateThreshold)
? turnTimePropagateFrequency : turnTimePropagateFrequencyCrit;
if(lastUpdate[player] >= frequency)
if(lastUpdate[player] >= turnTimePropagateFrequency)
sendTimerUpdate(player);
return true;

View File

@ -25,9 +25,7 @@ class CGameHandler;
class TurnTimerHandler
{
CGameHandler & gameHandler;
const int turnTimePropagateFrequency = 5000;
const int turnTimePropagateFrequencyCrit = 1000;
const int turnTimePropagateThreshold = 3000;
const int turnTimePropagateFrequency = 1000;
std::map<PlayerColor, TurnTimerInfo> timers;
std::map<PlayerColor, int> lastUpdate;
std::map<PlayerColor, bool> endTurnAllowed;