1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Merge branch 'develop' into end_autocombat

This commit is contained in:
Laserlicht 2024-01-29 21:36:11 +01:00 committed by GitHub
commit 4aaebc834e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 81 additions and 35 deletions

View File

@ -13,14 +13,15 @@
"vcmi.adventureMap.monsterThreat.levels.10" : "Deadly",
"vcmi.adventureMap.monsterThreat.levels.11" : "Impossible",
"vcmi.adventureMap.confirmRestartGame" : "Are you sure you want to restart the game?",
"vcmi.adventureMap.noTownWithMarket" : "There are no available marketplaces!",
"vcmi.adventureMap.noTownWithTavern" : "There are no available towns with taverns!",
"vcmi.adventureMap.spellUnknownProblem" : "There is an unknown problem with this spell! No more information is available.",
"vcmi.adventureMap.playerAttacked" : "Player has been attacked: %s",
"vcmi.adventureMap.moveCostDetails" : "Movement points - Cost: %TURNS turns + %POINTS points, Remaining points: %REMAINING",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Movement points - Cost: %POINTS points, Remaining points: %REMAINING",
"vcmi.adventureMap.confirmRestartGame" : "Are you sure you want to restart the game?",
"vcmi.adventureMap.noTownWithMarket" : "There are no available marketplaces!",
"vcmi.adventureMap.noTownWithTavern" : "There are no available towns with taverns!",
"vcmi.adventureMap.spellUnknownProblem" : "There is an unknown problem with this spell! No more information is available.",
"vcmi.adventureMap.playerAttacked" : "Player has been attacked: %s",
"vcmi.adventureMap.moveCostDetails" : "Movement points - Cost: %TURNS turns + %POINTS points, Remaining points: %REMAINING",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Movement points - Cost: %POINTS points, Remaining points: %REMAINING",
"vcmi.adventureMap.replayOpponentTurnNotImplemented" : "Sorry, replay opponent turn is not implemented yet!",
"vcmi.capitalColors.0" : "Red",
"vcmi.capitalColors.1" : "Blue",
"vcmi.capitalColors.2" : "Tan",

View File

@ -13,14 +13,15 @@
"vcmi.adventureMap.monsterThreat.levels.10" : "Tödlich",
"vcmi.adventureMap.monsterThreat.levels.11" : "Unmöglich",
"vcmi.adventureMap.confirmRestartGame" : "Seid Ihr sicher, dass Ihr das Spiel neu starten wollt?",
"vcmi.adventureMap.noTownWithMarket" : "Kein Marktplatz verfügbar!",
"vcmi.adventureMap.noTownWithTavern" : "Keine Stadt mit Taverne verfügbar!",
"vcmi.adventureMap.spellUnknownProblem" : "Unbekanntes Problem mit diesem Zauberspruch, keine weiteren Informationen verfügbar.",
"vcmi.adventureMap.playerAttacked" : "Spieler wurde attackiert: %s",
"vcmi.adventureMap.moveCostDetails" : "Bewegungspunkte - Kosten: %TURNS Runden + %POINTS Punkte, Verbleibende Punkte: %REMAINING",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Bewegungspunkte - Kosten: %POINTS Punkte, Verbleibende Punkte: %REMAINING",
"vcmi.adventureMap.confirmRestartGame" : "Seid Ihr sicher, dass Ihr das Spiel neu starten wollt?",
"vcmi.adventureMap.noTownWithMarket" : "Kein Marktplatz verfügbar!",
"vcmi.adventureMap.noTownWithTavern" : "Keine Stadt mit Taverne verfügbar!",
"vcmi.adventureMap.spellUnknownProblem" : "Unbekanntes Problem mit diesem Zauberspruch, keine weiteren Informationen verfügbar.",
"vcmi.adventureMap.playerAttacked" : "Spieler wurde attackiert: %s",
"vcmi.adventureMap.moveCostDetails" : "Bewegungspunkte - Kosten: %TURNS Runden + %POINTS Punkte, Verbleibende Punkte: %REMAINING",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Bewegungspunkte - Kosten: %POINTS Punkte, Verbleibende Punkte: %REMAINING",
"vcmi.adventureMap.replayOpponentTurnNotImplemented" : "Das Wiederholen des gegnerischen Zuges ist aktuell noch nicht implementiert!",
"vcmi.capitalColors.0" : "Rot",
"vcmi.capitalColors.1" : "Blau",
"vcmi.capitalColors.2" : "Braun",

View File

@ -183,6 +183,30 @@ void CSoundHandler::ambientStopSound(const AudioPath & soundId)
setChannelVolume(ambientChannels[soundId], volume);
}
uint32_t CSoundHandler::getSoundDurationMilliseconds(const AudioPath & sound)
{
if (!initialized || sound.empty())
return 0;
auto data = CResourceHandler::get()->load(sound.addPrefix("SOUNDS/"))->readAll();
SDL_AudioSpec spec;
uint32_t audioLen;
uint8_t *audioBuf;
uint32_t miliseconds = 0;
if(SDL_LoadWAV_RW(SDL_RWFromMem(data.first.get(), (int)data.second), 1, &spec, &audioBuf, &audioLen) != nullptr)
{
SDL_FreeWAV(audioBuf);
uint32_t sampleSize = SDL_AUDIO_BITSIZE(spec.format) / 8;
uint32_t sampleCount = audioLen / sampleSize;
uint32_t sampleLen = sampleCount / spec.channels;
miliseconds = 1000 * sampleLen / spec.freq;
}
return miliseconds ;
}
// Plays a sound, and return its channel so we can fade it out later
int CSoundHandler::playSound(soundBase::soundID soundID, int repeats)
{

View File

@ -77,6 +77,7 @@ public:
void setChannelVolume(int channel, ui32 percent);
// Sounds
uint32_t getSoundDurationMilliseconds(const AudioPath & sound);
int playSound(soundBase::soundID soundID, int repeats=0);
int playSound(const AudioPath & sound, int repeats=0, bool cache=false);
int playSound(std::pair<std::unique_ptr<ui8 []>, si64> & data, int repeats=0, bool cache=false);

View File

@ -23,6 +23,7 @@
#include "../../CCallback.h"
#include "../../lib/StartInfo.h"
#include "../../lib/CGeneralTextHandler.h"
AdventureOptions::AdventureOptions()
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("ADVOPTS"))
@ -30,12 +31,7 @@ AdventureOptions::AdventureOptions()
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
viewWorld = std::make_shared<CButton>(Point(24, 23), AnimationPath::builtin("ADVVIEW.DEF"), CButton::tooltip(), [&](){ close(); }, EShortcut::ADVENTURE_VIEW_WORLD);
viewWorld->addCallback( [] { LOCPLINT->viewWorldMap(); });
exit = std::make_shared<CButton>(Point(204, 313), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(), std::bind(&AdventureOptions::close, this), EShortcut::GLOBAL_RETURN);
scenInfo = std::make_shared<CButton>(Point(24, 198), AnimationPath::builtin("ADVINFO.DEF"), CButton::tooltip(), [&](){ close(); }, EShortcut::ADVENTURE_VIEW_SCENARIO);
scenInfo->addCallback(AdventureOptions::showScenarioInfo);
viewWorld->addCallback([] { LOCPLINT->viewWorldMap(); });
puzzle = std::make_shared<CButton>(Point(24, 81), AnimationPath::builtin("ADVPUZ.DEF"), CButton::tooltip(), [&](){ close(); }, EShortcut::ADVENTURE_VIEW_PUZZLE);
puzzle->addCallback(std::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT));
@ -45,6 +41,14 @@ AdventureOptions::AdventureOptions()
dig->addCallback(std::bind(&CPlayerInterface::tryDigging, LOCPLINT, h));
else
dig->block(true);
scenInfo = std::make_shared<CButton>(Point(24, 198), AnimationPath::builtin("ADVINFO.DEF"), CButton::tooltip(), [&](){ close(); }, EShortcut::ADVENTURE_VIEW_SCENARIO);
scenInfo->addCallback(AdventureOptions::showScenarioInfo);
replay = std::make_shared<CButton>(Point(24, 257), AnimationPath::builtin("ADVTURN.DEF"), CButton::tooltip(), [&](){ close(); });
replay->addCallback([]{ LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.replayOpponentTurnNotImplemented")); });
exit = std::make_shared<CButton>(Point(203, 313), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(), std::bind(&AdventureOptions::close, this), EShortcut::GLOBAL_RETURN);
}
void AdventureOptions::showScenarioInfo()

View File

@ -21,7 +21,7 @@ class AdventureOptions : public CWindowObject
std::shared_ptr<CButton> puzzle;
std::shared_ptr<CButton> dig;
std::shared_ptr<CButton> scenInfo;
/*std::shared_ptr<CButton> replay*/
std::shared_ptr<CButton> replay;
public:
AdventureOptions();

View File

@ -14,16 +14,18 @@
#include "../CGameInfo.h"
#include "../CMusicHandler.h"
#include "../CVideoHandler.h"
#include "../gui/WindowHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/FramerateManager.h"
#include "../widgets/TextControls.h"
#include "../render/Canvas.h"
CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback)
: CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback)
: CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), videoSoundHandle(-1), exitCb(callback), elapsedTimeMilliseconds(0)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
addUsedEvents(LCLICK);
addUsedEvents(LCLICK | TIME);
pos = center(Rect(0, 0, 800, 600));
updateShadow();
@ -31,15 +33,33 @@ CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::f
videoSoundHandle = CCS->soundh->playSound(audioData);
CCS->videoh->open(spe.prologVideo);
CCS->musich->playMusic(spe.prologMusic, true, true);
voiceDurationMilliseconds = CCS->soundh->getSoundDurationMilliseconds(spe.prologVoice);
voiceSoundHandle = CCS->soundh->playSound(spe.prologVoice);
auto onVoiceStop = [this]()
{
voiceStopped = true;
elapsedTimeMilliseconds = 0;
};
CCS->soundh->setCallback(voiceSoundHandle, onVoiceStop);
text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText.toString());
text->scrollTextTo(-100);
text->scrollTextTo(-50); // beginning of text in the vertical middle of black area
}
void CPrologEpilogVideo::tick(uint32_t msPassed)
{
elapsedTimeMilliseconds += msPassed;
const uint32_t speed = (voiceDurationMilliseconds == 0) ? 150 : (voiceDurationMilliseconds / (text->textSize.y));
if(elapsedTimeMilliseconds > speed && text->textSize.y - 50 > positionCounter)
{
text->scrollTextBy(1);
elapsedTimeMilliseconds -= speed;
++positionCounter;
}
else if(elapsedTimeMilliseconds > (voiceDurationMilliseconds == 0 ? 8000 : 3000) && voiceStopped) // pause after completed scrolling (longer for intros missing voice)
clickPressed(GH.getCursorPosition());
}
void CPrologEpilogVideo::show(Canvas & to)
@ -48,15 +68,7 @@ void CPrologEpilogVideo::show(Canvas & to)
//some videos are 800x600 in size while some are 800x400
CCS->videoh->update(pos.x, pos.y + (CCS->videoh->size().y == 400 ? 100 : 0), to.getInternalSurface(), true, false);
//move text every 5 calls/frames; seems to be good enough
++positionCounter;
if(positionCounter % 5 == 0)
text->scrollTextBy(1);
else
text->showAll(to); // blit text over video, if needed
if(text->textSize.y + 100 < positionCounter / 5 && voiceStopped)
clickPressed(GH.getCursorPosition());
text->showAll(to); // blit text over video, if needed
}
void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)

View File

@ -19,6 +19,8 @@ class CPrologEpilogVideo : public CWindowObject
CampaignScenarioPrologEpilog spe;
int positionCounter;
int voiceSoundHandle;
uint32_t voiceDurationMilliseconds;
uint32_t elapsedTimeMilliseconds;
int videoSoundHandle;
std::function<void()> exitCb;
@ -29,6 +31,7 @@ class CPrologEpilogVideo : public CWindowObject
public:
CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback);
void tick(uint32_t msPassed) override;
void clickPressed(const Point & cursorPosition) override;
void show(Canvas & to) override;
};