| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "SoundAgent.h" |
| 10 |
|
| 11 |
#include "OptionAgent.h" |
| 12 |
#include "StringMsg.h" |
| 13 |
#include "UnknownMsgException.h" |
| 14 |
|
| 15 |
//----------------------------------------------------------------- |
| 16 |
/** |
| 17 |
* Set sound and music volume. |
| 18 |
*/ |
| 19 |
void |
| 20 |
SoundAgent::own_init() |
| 21 |
{ |
| 22 |
reinit(); |
| 23 |
|
| 24 |
registerWatcher("volume_sound"); |
| 25 |
registerWatcher("volume_music"); |
| 26 |
} |
| 27 |
//----------------------------------------------------------------- |
| 28 |
/** |
| 29 |
* Reininitalize the sound system. |
| 30 |
*/ |
| 31 |
void |
| 32 |
SoundAgent::reinit() |
| 33 |
{ |
| 34 |
OptionAgent *options = OptionAgent::agent(); |
| 35 |
options->setDefault("volume_sound", 90); |
| 36 |
options->setDefault("volume_music", 50); |
| 37 |
setSoundVolume(options->getAsInt("volume_sound")); |
| 38 |
setMusicVolume(options->getAsInt("volume_music")); |
| 39 |
} |
| 40 |
//----------------------------------------------------------------- |
| 41 |
/** |
| 42 |
* Handle incoming message. |
| 43 |
* Messages: |
| 44 |
* - param_changed(volume_sound) ... set sound volume |
| 45 |
* - param_changed(volume_music) ... set music volume |
| 46 |
* |
| 47 |
* @throws UnknownMsgException |
| 48 |
*/ |
| 49 |
void |
| 50 |
SoundAgent::receiveString(const StringMsg *msg) |
| 51 |
{ |
| 52 |
if (msg->equalsName("param_changed")) { |
| 53 |
std::string param = msg->getValue(); |
| 54 |
if ("volume_sound" == param) { |
| 55 |
int volume = OptionAgent::agent()->getAsInt("volume_sound"); |
| 56 |
setSoundVolume(volume); |
| 57 |
} |
| 58 |
else if ("volume_music" == param) { |
| 59 |
int volume = OptionAgent::agent()->getAsInt("volume_music"); |
| 60 |
setMusicVolume(volume); |
| 61 |
} |
| 62 |
} |
| 63 |
else { |
| 64 |
throw UnknownMsgException(msg); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|