diff --git a/Mods/vcmi/Sounds/we5.wav b/Mods/vcmi/Sounds/we5.wav new file mode 100644 index 000000000..47901221e Binary files /dev/null and b/Mods/vcmi/Sounds/we5.wav differ diff --git a/Mods/vcmi/mod.json b/Mods/vcmi/mod.json index 0a0702f0b..8f7618196 100644 --- a/Mods/vcmi/mod.json +++ b/Mods/vcmi/mod.json @@ -190,6 +190,10 @@ "MAPS/": [ {"type" : "dir", "path" : "/Maps"} + ], + "SOUNDS/": + [ + {"type" : "dir", "path" : "/Sounds"} ] } } diff --git a/client/adventureMap/TurnTimerWidget.cpp b/client/adventureMap/TurnTimerWidget.cpp index 5d47a4e45..476ffe0c8 100644 --- a/client/adventureMap/TurnTimerWidget.cpp +++ b/client/adventureMap/TurnTimerWidget.cpp @@ -10,6 +10,8 @@ #include "StdInc.h" #include "TurnTimerWidget.h" +#include "../CGameInfo.h" +#include "../CMusicHandler.h" #include "../CPlayerInterface.h" #include "../render/EFont.h" @@ -44,6 +46,11 @@ TurnTimerWidget::TurnTimerWidget(): const JsonNode config(ResourceID("config/widgets/turnTimer.json")); build(config); + + std::transform(variables["notificationTime"].Vector().begin(), + variables["notificationTime"].Vector().end(), + std::inserter(notifications, notifications.begin()), + [](const JsonNode & node){ return node.Integer(); }); } std::shared_ptr TurnTimerWidget::buildDrawRect(const JsonNode & config) const @@ -61,7 +68,10 @@ void TurnTimerWidget::show(Canvas & to) void TurnTimerWidget::setTime(int time) { - turnTime = time / 1000; + int newTime = time / 1000; + if((newTime != turnTime) && notifications.count(newTime)) + CCS->soundh->playSound(variables["notificationSound"].String()); + turnTime = newTime; if(auto w = widget("timer")) { std::ostringstream oss; @@ -79,28 +89,25 @@ void TurnTimerWidget::tick(uint32_t msPassed) cachedTurnTime -= msPassed; if(cachedTurnTime < 0) cachedTurnTime = 0; //do not go below zero + auto timeCheckAndUpdate = [&](int time) + { + if(time / 1000 != lastTurnTime / 1000) + { + //do not update timer on this tick + lastTurnTime = time; + cachedTurnTime = time; + } + else setTime(cachedTurnTime); + }; + if(LOCPLINT->battleInt) { if(time.isBattleEnabled()) - { - if(time.creatureTimer / 1000 != lastTurnTime / 1000) - { - //do not update timer on this tick - lastTurnTime = time.creatureTimer; - cachedTurnTime = time.creatureTimer; - } - else setTime(cachedTurnTime); - } + timeCheckAndUpdate(time.creatureTimer); } else { - if(time.turnTimer / 1000 != lastTurnTime / 1000) - { - //do not update timer on this tick - lastTurnTime = time.turnTimer; - cachedTurnTime = time.turnTimer; - } - else setTime(cachedTurnTime); + timeCheckAndUpdate(time.turnTimer); } } } diff --git a/client/adventureMap/TurnTimerWidget.h b/client/adventureMap/TurnTimerWidget.h index 63432e0a0..592143e79 100644 --- a/client/adventureMap/TurnTimerWidget.h +++ b/client/adventureMap/TurnTimerWidget.h @@ -36,14 +36,12 @@ private: int lastTurnTime; int cachedTurnTime; - //std::shared_ptr watches; - //std::shared_ptr label; + std::set notifications; std::shared_ptr buildDrawRect(const JsonNode & config) const; public: - //void tick(uint32_t msPassed) override; void show(Canvas & to) override; void tick(uint32_t msPassed) override; diff --git a/config/widgets/turnTimer.json b/config/widgets/turnTimer.json index 704646f83..fce385ab2 100644 --- a/config/widgets/turnTimer.json +++ b/config/widgets/turnTimer.json @@ -23,5 +23,11 @@ "text": "", "position": {"x": 24, "y": 2} }, - ] + ], + + "variables": + { + "notificationTime": [0, 1, 2, 3, 4, 5, 20], + "notificationSound": "WE5" + } }