Play tavern music file on login screen

This commit is contained in:
Kelsi 2026-02-05 15:44:42 -08:00
parent 02f8328747
commit b05089aa3f
7 changed files with 71 additions and 0 deletions

View file

@ -72,6 +72,33 @@ void MusicManager::playMusic(const std::string& mpqPath, bool loop) {
}
}
void MusicManager::playFilePath(const std::string& filePath, bool loop) {
if (filePath.empty()) return;
if (filePath == currentTrack && playing) return;
stopCurrentProcess();
std::vector<std::string> args;
args.push_back("-nodisp");
args.push_back("-autoexit");
if (loop) {
args.push_back("-loop");
args.push_back("0");
}
args.push_back("-volume");
args.push_back("30");
args.push_back(filePath);
playerPid = platform::spawnProcess(args);
if (playerPid != INVALID_PROCESS) {
playing = true;
currentTrack = filePath;
LOG_INFO("Music: Playing file ", filePath);
} else {
LOG_ERROR("Music: Failed to spawn ffplay process");
}
}
void MusicManager::stopMusic(float fadeMs) {
(void)fadeMs; // ffplay doesn't support fade easily
stopCurrentProcess();

View file

@ -1,6 +1,10 @@
#include "ui/auth_screen.hpp"
#include "auth/crypto.hpp"
#include "core/application.hpp"
#include "core/logger.hpp"
#include "rendering/renderer.hpp"
#include "pipeline/asset_manager.hpp"
#include "audio/music_manager.hpp"
#include <imgui.h>
#include <sstream>
#include <fstream>
@ -71,6 +75,23 @@ void AuthScreen::render(auth::AuthHandler& authHandler) {
}
}
if (!musicInitAttempted) {
musicInitAttempted = true;
auto& app = core::Application::getInstance();
auto* renderer = app.getRenderer();
auto* assets = app.getAssetManager();
if (renderer) {
auto* music = renderer->getMusicManager();
if (music && assets && assets->isInitialized() && !music->isInitialized()) {
music->initialize(assets);
}
if (music && !musicPlaying) {
music->playFilePath("assets/20-taverns.mp3", true);
musicPlaying = true;
}
}
}
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
ImGui::Begin("WoW 3.3.5a Authentication", nullptr, ImGuiWindowFlags_NoCollapse);
@ -197,6 +218,17 @@ void AuthScreen::render(auth::AuthHandler& authHandler) {
ImGui::End();
}
void AuthScreen::stopLoginMusic() {
if (!musicPlaying) return;
auto& app = core::Application::getInstance();
auto* renderer = app.getRenderer();
if (!renderer) return;
auto* music = renderer->getMusicManager();
if (!music) return;
music->stopMusic(500.0f);
musicPlaying = false;
}
void AuthScreen::attemptAuth(auth::AuthHandler& authHandler) {
// Validate inputs
if (strlen(username) == 0) {

View file

@ -97,30 +97,35 @@ void UIManager::render(core::AppState appState, auth::AuthHandler* authHandler,
break;
case core::AppState::REALM_SELECTION:
authScreen->stopLoginMusic();
if (authHandler) {
realmScreen->render(*authHandler);
}
break;
case core::AppState::CHARACTER_CREATION:
authScreen->stopLoginMusic();
if (gameHandler) {
characterCreateScreen->render(*gameHandler);
}
break;
case core::AppState::CHARACTER_SELECTION:
authScreen->stopLoginMusic();
if (gameHandler) {
characterScreen->render(*gameHandler);
}
break;
case core::AppState::IN_GAME:
authScreen->stopLoginMusic();
if (gameHandler) {
gameScreen->render(*gameHandler);
}
break;
case core::AppState::DISCONNECTED:
authScreen->stopLoginMusic();
// Show disconnected message
ImGui::SetNextWindowSize(ImVec2(400, 150), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * 0.5f - 200,