sound volumes are now read from and saved to config.rc + bugfix
- fixed calling of IMGUIClear() when the view state changed (was previously called only when the game state changed)
This commit is contained in:
@@ -10,7 +10,7 @@ BEGIN_ENUM(Event)
|
||||
DECL_ENUM_ELEMENT(EventAccelerateStart),
|
||||
DECL_ENUM_ELEMENT(EventAccelerateStop),
|
||||
DECL_ENUM_ELEMENT(EventLevelComplete),
|
||||
DECL_ENUM_ELEMENT(EventChangeGameState),
|
||||
DECL_ENUM_ELEMENT(EventChangeViewState),
|
||||
DECL_ENUM_ELEMENT(EventGameOver),
|
||||
DECL_ENUM_ELEMENT(EventShipExplode),
|
||||
DECL_ENUM_ELEMENT(EventPlayerDied),
|
||||
|
||||
@@ -17,13 +17,13 @@ int Controller::OnInit (int argc, char *argv[]) {
|
||||
mBindings[SDLK_F8] = "toggleconsole";
|
||||
mBindings[SDLK_F9] = "set playerspeed 5.0";
|
||||
|
||||
Engine::RegisterListener (this, EventChangeGameState);
|
||||
Engine::RegisterListener (this, EventChangeViewState);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||
if (event->mEventType == EventChangeGameState) {
|
||||
if (event->mEventType == EventChangeViewState) {
|
||||
IMGUIClear();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -374,11 +374,6 @@ void Model::ProceedToNextLevel () {
|
||||
|
||||
void Model::SetGameState (const unsigned int &state) {
|
||||
mLastGameState = mGameState;
|
||||
|
||||
Engine::EventBasePtr changegamestate_event (new Engine::EventBase());
|
||||
changegamestate_event->mEventType = EventChangeGameState;
|
||||
QueueEvent (changegamestate_event);
|
||||
|
||||
mGameState = state;
|
||||
}
|
||||
|
||||
|
||||
+4
-7
@@ -663,22 +663,19 @@ void View::DrawUiHighscore() {
|
||||
void View::DrawUiOptions() {
|
||||
DrawPageTitle ("Options");
|
||||
SelectFont ("console.ttf size=23");
|
||||
|
||||
// Enter your name
|
||||
std::string player_name = GetModel()->GetPlayerName();
|
||||
|
||||
Engine::GUI::Label (1, "Effects Volume: ", screen_right * 0.5 - 150, 240);
|
||||
Engine::GUI::Label (10, "Effects Volume: ", screen_right * 0.5 - 150, 240);
|
||||
|
||||
float effects_volume = Engine::GetEffectsVolume();
|
||||
if (Engine::GUI::VerticalSlider (2, screen_right * 0.5 - 100, 250, 250, 16, 0., 1., effects_volume)) {
|
||||
if (Engine::GUI::VerticalSlider (1, screen_right * 0.5 - 100, 250, 250, 16, 0., 1., effects_volume)) {
|
||||
Engine::LogDebug ("Setting effects volume to: %f", effects_volume);
|
||||
Engine::SetEffectsVolume(effects_volume);
|
||||
}
|
||||
|
||||
Engine::GUI::Label (3, "Music Volume: ", screen_right * 0.5 - 150, 300);
|
||||
Engine::GUI::Label (11, "Music Volume: ", screen_right * 0.5 - 150, 300);
|
||||
|
||||
float music_volume = Engine::GetMusicVolume();
|
||||
if (Engine::GUI::VerticalSlider (4, screen_right * 0.5 - 100, 310, 250, 16, 0., 1., music_volume)) {
|
||||
if (Engine::GUI::VerticalSlider (2, screen_right * 0.5 - 100, 310, 250, 16, 0., 1., music_volume)) {
|
||||
Engine::LogDebug ("Setting music volume to: %f", music_volume);
|
||||
Engine::SetMusicVolume(music_volume);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ class View : public Engine::ViewBase {
|
||||
void PushViewState (const ViewState state) {
|
||||
Engine::LogDebug ("Pushing ViewState %s", GetStringViewState(state));
|
||||
mViewStateStack.push(state);
|
||||
|
||||
// Fire the view state change event to properly clear the IMGUI state
|
||||
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
|
||||
changeviewstate_event->mEventType = EventChangeViewState;
|
||||
QueueEvent (changeviewstate_event);
|
||||
}
|
||||
/** \brief Returns the current ViewState */
|
||||
ViewState GetViewState () {
|
||||
@@ -92,12 +97,22 @@ class View : public Engine::ViewBase {
|
||||
current_name = GetStringViewState(mViewStateStack.top());
|
||||
|
||||
Engine::LogDebug("Popped ViewState: %s current %s remaining: %u", popped_name.c_str(), current_name.c_str(), mViewStateStack.size());
|
||||
|
||||
// Fire the view state change event to properly clear the IMGUI state
|
||||
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
|
||||
changeviewstate_event->mEventType = EventChangeViewState;
|
||||
QueueEvent (changeviewstate_event);
|
||||
}
|
||||
/** \brief Removes all elements of the ViewState stack */
|
||||
void ResetViewState() {
|
||||
Engine::LogDebug ("Resetting ViewState stack");
|
||||
while (mViewStateStack.size())
|
||||
mViewStateStack.pop();
|
||||
|
||||
// Fire the view state change event to properly clear the IMGUI state
|
||||
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
|
||||
changeviewstate_event->mEventType = EventChangeViewState;
|
||||
QueueEvent (changeviewstate_event);
|
||||
}
|
||||
|
||||
// \todo [high] add Resource Manager!
|
||||
|
||||
+8
-4
@@ -44,14 +44,18 @@ int main (int argc, char* argv[]) {
|
||||
engine.GetView()->SetGridSize (8,8);
|
||||
dynamic_cast<asteroids::Physics*>(engine.GetPhysics())->SetWorldSize (28, 20);
|
||||
|
||||
// run the default commands and load the configuration
|
||||
Engine::RunCommand ("exec asteroids.rc");
|
||||
|
||||
Engine::LogMessage("Warning: muting sound!");
|
||||
Engine::SetEffectsVolume(0.);
|
||||
Engine::SetMusicVolume(0.);
|
||||
Engine::RunCommand ("exec config.rc");
|
||||
|
||||
engine.MainLoop ();
|
||||
|
||||
// save the configuration
|
||||
std::ofstream config_file ("config.rc");
|
||||
config_file << "set effects_volume " << Engine::GetEffectsVolume() << std::endl;
|
||||
config_file << "set music_volume " << Engine::GetMusicVolume() << std::endl;
|
||||
config_file.close();
|
||||
|
||||
SDL_WM_SetIcon(NULL,NULL);
|
||||
SDL_FreeSurface (image);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user