Play music in menu also, with fading effects when run game
authorunc0rr
Sat, 16 Aug 2008 20:36:18 +0000
changeset 1225 f882a92ef872
parent 1224 0b9fbee5ceda
child 1226 d4432bae258e
Play music in menu also, with fading effects when run game
QTfrontend/SDLs.cpp
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/pages.cpp
hedgewars/SDLh.pas
hedgewars/uSound.pas
--- a/QTfrontend/SDLs.cpp	Sat Aug 16 20:15:27 2008 +0000
+++ b/QTfrontend/SDLs.cpp	Sat Aug 16 20:36:18 2008 +0000
@@ -29,7 +29,6 @@
 	
 	Mix_Volume(-1, 50);
 	music = Mix_LoadMUS(QString(datadir->absolutePath() + "/Music/main theme.ogg").toAscii().constData());
-	StartMusic();
 }
 
 SDLInteraction::~SDLInteraction()
@@ -59,10 +58,10 @@
 }
 void SDLInteraction::StartMusic()
 {
-	Mix_PlayMusic(music, -1);
+	Mix_FadeInMusic(music, -1, 3000);
 }
 
 void SDLInteraction::StopMusic()
 {
-
+	Mix_FadeOutMusic(2000);
 }
--- a/QTfrontend/hwform.cpp	Sat Aug 16 20:15:27 2008 +0000
+++ b/QTfrontend/hwform.cpp	Sat Aug 16 20:36:18 2008 +0000
@@ -49,13 +49,14 @@
   : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
 {
 	ui.setupUi(this);
+
+	ui.pageOptions->CBResolution->addItems(sdli.getResolutions());
+
 	config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
 
 	UpdateTeamsLists();
 	UpdateWeapons();
 
-	StartMusic();
-
 	connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool)));
 	onFrontendFullscreen(config->isFrontendFullscreen());
 
@@ -130,6 +131,8 @@
 		this, SLOT(GoBack())); // executed third
 
 	GoToPage(ID_PAGE_MAIN);
+
+	sdli.StartMusic();
 }
 
 void HWForm::onFrontendFullscreen(bool value)
@@ -546,7 +549,7 @@
 {
 	switch(gameState) {
 		case gsStarted: {
-			StopMusic();
+			sdli.StopMusic();
 			GoToPage(ID_PAGE_INGAME);
 			ui.pageGameStats->labelGameStats->setText("");
 			if (pRegisterServer)
@@ -558,13 +561,16 @@
 		}
 		case gsFinished: {
 			GoBack();
-			StartMusic();
+			sdli.StartMusic();
 			GoToPage(ID_PAGE_GAMESTATS);
 			break;
 		}
 		default: {
 			quint8 id = ui.Pages->currentIndex();
-			if (id == ID_PAGE_INGAME) GoBack();
+			if (id == ID_PAGE_INGAME) {
+				GoBack();
+				sdli.StartMusic();
+			}
 		};
 	}
 
@@ -682,13 +688,3 @@
 	config->SaveOptions();
 	event->accept();
 }
-
-void HWForm::StartMusic()
-{
-
-}
-
-void HWForm::StopMusic()
-{
-
-}
--- a/QTfrontend/hwform.h	Sat Aug 16 20:15:27 2008 +0000
+++ b/QTfrontend/hwform.h	Sat Aug 16 20:36:18 2008 +0000
@@ -26,6 +26,7 @@
 #include "netserver.h"
 #include "game.h"
 #include "ui_hwform.h"
+#include "SDLs.h"
 
 class HWGame;
 class HWTeam;
@@ -84,8 +85,6 @@
 	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);
@@ -116,6 +115,7 @@
 	HWNetServer* pnetserver;
 	HWNetRegisterServer* pRegisterServer;
 	QTime eggTimer;
+	SDLInteraction sdli;
 	void AddStatText(const QString & msg);
 	void OnPageShown(quint8 id, quint8 lastid=0);
 };
--- a/QTfrontend/pages.cpp	Sat Aug 16 20:15:27 2008 +0000
+++ b/QTfrontend/pages.cpp	Sat Aug 16 20:36:18 2008 +0000
@@ -47,7 +47,6 @@
 #include "netudpwidget.h"
 #include "netwwwwidget.h"
 #include "chatwidget.h"
-#include "SDLs.h"
 #include "playrecordpage.h"
 #include "selectWeapon.h"
 #include "igbox.h"
@@ -335,8 +334,6 @@
 	GBAreslayout->addWidget(resolution);
 
 	CBResolution = new QComboBox(AGGroupBox);
-	SDLInteraction sdli;
-	CBResolution->addItems(sdli.getResolutions());
 	GBAreslayout->addWidget(CBResolution);
 	GBAlayout->addLayout(GBAreslayout);
 
--- a/hedgewars/SDLh.pas	Sat Aug 16 20:15:27 2008 +0000
+++ b/hedgewars/SDLh.pas	Sat Aug 16 20:36:18 2008 +0000
@@ -341,6 +341,7 @@
 
 function  Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 function  Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName;
+function  Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 
 function  Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 function  Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName;
--- a/hedgewars/uSound.pas	Sat Aug 16 20:15:27 2008 +0000
+++ b/hedgewars/uSound.pas	Sat Aug 16 20:36:18 2008 +0000
@@ -109,7 +109,7 @@
 TryDo(Mus <> nil, msgFailed, false);
 WriteLnToConsole(msgOK);
 
-Mix_PlayMusic(Mus, -1)
+SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
 end;
 
 function ChangeVolume(voldelta: LongInt): LongInt;