Hackish way to play music in frontend... to be fixed
authorunc0rr
Sat, 16 Aug 2008 14:28:44 +0000
changeset 1223 41d7283934c1
parent 1222 bc94a25d867a
child 1224 0b9fbee5ceda
Hackish way to play music in frontend... to be fixed
QTfrontend/CMakeLists.txt
QTfrontend/SDLs.cpp
QTfrontend/SDLs.h
QTfrontend/gameuiconfig.cpp
QTfrontend/hwform.cpp
QTfrontend/hwform.h
--- a/QTfrontend/CMakeLists.txt	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/CMakeLists.txt	Sat Aug 16 14:28:44 2008 +0000
@@ -13,6 +13,7 @@
 
 # Configure for SDL
 find_package(SDL REQUIRED)
+find_package(SDL_mixer REQUIRED)
 
 include_directories(${SDL_INCLUDE_DIR})
 if(UNIX)
@@ -151,6 +152,7 @@
 set(HW_LINK_LIBS 
 	${QT_LIBRARIES}
 	${SDL_LIBRARY}
+	${SDLMIXER_LIBRARY}
 	)
 
 if(WIN32 AND NOT UNIX)
--- a/QTfrontend/SDLs.cpp	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/SDLs.cpp	Sat Aug 16 14:28:44 2008 +0000
@@ -19,15 +19,22 @@
 #include "SDLs.h"
 
 #include "SDL.h"
+#include "hwconsts.h"
 
 SDLInteraction::SDLInteraction()
 {
 	SDL_Init(SDL_INIT_VIDEO);
+	SDL_Init(SDL_INIT_AUDIO);
+	Mix_OpenAudio(22050, 0x8010, 2, 512);
+	
+	Mix_Volume(-1, 50);
+	music = Mix_LoadMUS(QString(datadir->absolutePath() + "/Music/main theme.ogg").toAscii().constData());
+	StartMusic();
 }
 
 SDLInteraction::~SDLInteraction()
 {
-	SDL_Quit();
+//	SDL_Quit();
 }
 
 QStringList SDLInteraction::getResolutions() const
@@ -50,3 +57,12 @@
 
 	return result;
 }
+void SDLInteraction::StartMusic()
+{
+	Mix_PlayMusic(music, -1);
+}
+
+void SDLInteraction::StopMusic()
+{
+
+}
--- a/QTfrontend/SDLs.h	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/SDLs.h	Sat Aug 16 14:28:44 2008 +0000
@@ -21,14 +21,22 @@
 
 #include <QStringList>
 
+#include "SDL_mixer.h"
+
+
 class SDLInteraction : public QObject
 {
 	Q_OBJECT
 
-	public:
+private:
+	Mix_Music * music;
+
+public:
 	SDLInteraction();
 	~SDLInteraction();
 	QStringList getResolutions() const;
+	void StartMusic();
+	void StopMusic();
 };
 
 #endif
--- a/QTfrontend/gameuiconfig.cpp	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Sat Aug 16 14:28:44 2008 +0000
@@ -77,7 +77,7 @@
 
 void GameUIConfig::resizeToConfigValues()
 {
-  Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt());
+  Form->resize(value("window/width", 720).toUInt(), value("window/height", 450).toUInt());
 }
 
 void GameUIConfig::SaveOptions()
--- a/QTfrontend/hwform.cpp	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/hwform.cpp	Sat Aug 16 14:28:44 2008 +0000
@@ -54,6 +54,8 @@
 	UpdateTeamsLists();
 	UpdateWeapons();
 
+	StartMusic();
+
 	connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool)));
 	onFrontendFullscreen(config->isFrontendFullscreen());
 
@@ -544,6 +546,8 @@
 {
 	switch(gameState) {
 		case gsStarted: {
+			StopMusic();
+			GoToPage(ID_PAGE_INGAME);
 			ui.pageGameStats->labelGameStats->setText("");
 			if (pRegisterServer)
 			{
@@ -554,6 +558,7 @@
 		}
 		case gsFinished: {
 			GoBack();
+			StartMusic();
 			GoToPage(ID_PAGE_GAMESTATS);
 			break;
 		}
@@ -612,8 +617,6 @@
 	connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &)));
 	connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
 	connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
-
-	GoToPage(ID_PAGE_INGAME);
 }
 
 void HWForm::ShowErrorMessage(const QString & msg)
@@ -679,3 +682,13 @@
 	config->SaveOptions();
 	event->accept();
 }
+
+void HWForm::StartMusic()
+{
+
+}
+
+void HWForm::StopMusic()
+{
+
+}
--- a/QTfrontend/hwform.h	Sat Aug 16 13:29:18 2008 +0000
+++ b/QTfrontend/hwform.h	Sat Aug 16 14:28:44 2008 +0000
@@ -84,6 +84,8 @@
 	void UpdateWeapons();
 	void NetWeaponNameChanged(const QString& name);
 	void onFrontendFullscreen(bool value);
+	void StartMusic();
+	void StopMusic();
 
 private:
 	void _NetConnect(const QString & hostName, quint16 port, const QString & nick);