[Orxonox-commit 1688] r6406 - in code/branches/presentation2: data/gui/layouts data/gui/scripts src/orxonox src/orxonox/sound

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Dec 23 20:45:56 CET 2009


Author: rgrieder
Date: 2009-12-23 20:45:56 +0100 (Wed, 23 Dec 2009)
New Revision: 6406

Modified:
   code/branches/presentation2/data/gui/layouts/AudioMenu.layout
   code/branches/presentation2/data/gui/scripts/AudioMenu.lua
   code/branches/presentation2/src/orxonox/MoodManager.cc
   code/branches/presentation2/src/orxonox/MoodManager.h
   code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
   code/branches/presentation2/src/orxonox/sound/AmbientSound.h
Log:
Mood changes should now be working and with immediate (but delayed because of loading) effect.

Modified: code/branches/presentation2/data/gui/layouts/AudioMenu.layout
===================================================================
--- code/branches/presentation2/data/gui/layouts/AudioMenu.layout	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/data/gui/layouts/AudioMenu.layout	2009-12-23 19:45:56 UTC (rev 6406)
@@ -110,8 +110,8 @@
                 </Window>
             </Window>
             <Window Type="TaharezLook/StaticText" Name="orxonox/AudioInfo" >
-                <Property Name="Text" >Theme changes require
-a game restart.</Property>
+                <Property Name="Text" >Theme changes might take
+up to a minute.</Property>
                 <Property Name="TextColours" Value="FF4444FF" />
                 <Property Name="InheritsAlpha" Value="False" />
                 <Property Name="HorzFormatting" Value="HorzCentred" />

Modified: code/branches/presentation2/data/gui/scripts/AudioMenu.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/AudioMenu.lua	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/data/gui/scripts/AudioMenu.lua	2009-12-23 19:45:56 UTC (rev 6406)
@@ -45,6 +45,11 @@
         item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
         CEGUI.toListbox(listboxwindow):addItem(item)
     end
+    if orxonox.getConfig("MoodManager", "mood_") == "dnb" then
+        listboxwindow:setItemSelectState(1,true)
+    else
+        listboxwindow:setItemSelectState(0,true)
+    end
 end
 
 function P.AudioMasterScrollbar_changed(e)
@@ -165,9 +170,9 @@
 
 function P.AudioThemeListbox_changed(e)
     if listboxwindow:isItemSelected(1) then
-        orxonox.execute("setMood dnb")
+        orxonox.config("MoodManager", "mood_", "dnb")
     else
-        orxonox.execute("setMood default")
+        orxonox.config("MoodManager", "mood_", "default")
     end
 end
 

Modified: code/branches/presentation2/src/orxonox/MoodManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/MoodManager.cc	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/src/orxonox/MoodManager.cc	2009-12-23 19:45:56 UTC (rev 6406)
@@ -28,7 +28,6 @@
 
 #include "MoodManager.h"
 
-#include "core/ConsoleCommand.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/CoreIncludes.h"
 #include "core/ScopedSingletonManager.h"
@@ -41,13 +40,8 @@
     {
         RegisterRootObject(MoodManager);
         this->setConfigValues();
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&MoodManager::setMood, this), "setMood"));
     }
 
-    MoodManager::~MoodManager()
-    {
-    }
-
     void MoodManager::setConfigValues()
     {
         SetConfigValue(mood_, "default")
@@ -64,16 +58,32 @@
         ModifyConfigValue(mood_, set, mood);
     }
 
-    //! Gets the current mood
-    const std::string& MoodManager::getMood()
+    void MoodManager::checkMoodValidity()
     {
-        return mood_;
+        // TODO: Insert new moods here & make this generic
+        if (mood_ != "default" && mood_ != "dnb")
+        {
+            ResetConfigValue(mood_);
+        }
+        else
+        {
+            COUT(3) << "Mood changed to " << mood_ << std::endl;
+            MoodListener::changedMood(mood_);
+        }
     }
 
-    void MoodManager::checkMoodValidity()
+
+    std::string MoodListener::mood_s;
+
+    MoodListener::MoodListener()
     {
-        if (mood_ != "default" && mood_ != "dnb") // Insert new moods here; TODO: make this generic
-            ResetConfigValue(mood_);
-        COUT(4) << "MoodManager: Mood set to " << mood_ << std::endl;
+        RegisterRootObject(MoodListener);
     }
+
+    /*static*/ void MoodListener::changedMood(const std::string& mood)
+    {
+        mood_s = mood;
+        for (ObjectList<MoodListener>::iterator it = ObjectList<MoodListener>::begin(); it; ++it)
+            it->moodChanged(mood_s);
+    }
 }

Modified: code/branches/presentation2/src/orxonox/MoodManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/MoodManager.h	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/src/orxonox/MoodManager.h	2009-12-23 19:45:56 UTC (rev 6406)
@@ -31,41 +31,51 @@
 
 #include "OrxonoxPrereqs.h"
 
-#include <cassert>
-#include <list>
 #include <string>
-
 #include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 
-// tolua_begin
 namespace orxonox
 {
-    class _OrxonoxExport MoodManager
-    // tolua_end
-        : public Singleton<MoodManager>, public OrxonoxClass
-    { // tolua_export
+    class _OrxonoxExport MoodListener : virtual public OrxonoxClass
+    {
+        friend class MoodManager;
+
+        protected:
+            MoodListener();
+            virtual ~MoodListener() {}
+
+            const std::string& getMood() const { return mood_s; }
+
+        private:
+            virtual void moodChanged(const std::string& mood) = 0;
+
+            static void changedMood(const std::string& mood);
+            static std::string mood_s;
+    };
+
+    class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
+    {
             friend class Singleton<MoodManager>;
         public:
             MoodManager();
-            ~MoodManager();
 
             void setConfigValues();
 
             void setMood(const std::string& mood);
-            const std::string& getMood();
+            inline const std::string& getMood() const { return this->mood_; }
 
-            static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); } // tolua_export
+            static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); }
 
         private:
+            ~MoodManager() {}
             void checkMoodValidity();
 
             // config values
             std::string mood_;
-            std::string moodOld_;
 
             static MoodManager* singletonPtr_s;
-    }; // tolua_export
-} // tolua_export
+    };
+}
 
 #endif /* _MoodManager_H__ */

Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.cc	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.cc	2009-12-23 19:45:56 UTC (rev 6406)
@@ -34,7 +34,6 @@
 #include "core/Resource.h"
 #include "core/XMLPort.h"
 #include "SoundManager.h"
-#include "MoodManager.h"
 
 namespace orxonox
 {
@@ -110,14 +109,19 @@
     void AmbientSound::setAmbientSource(const std::string& source)
     {
         this->ambientSource_ = source;
+        this->moodChanged(this->getMood());
+    }
+
+    void AmbientSound::moodChanged(const std::string& mood)
+    {
         if (GameMode::playsSound())
         {
-            const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + source;
+            const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
             shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
             if (fileInfo != NULL)
                 this->setSource(path);
             else
-                COUT(3) << "Sound: " << source << ": Not a valid name! Ambient sound will not change." << std::endl;
+                COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
         }
     }
 

Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.h	2009-12-23 19:27:17 UTC (rev 6405)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.h	2009-12-23 19:45:56 UTC (rev 6406)
@@ -33,8 +33,9 @@
 #include "OrxonoxPrereqs.h"
 
 #include "core/BaseObject.h"
-#include "sound/BaseSound.h"
 #include "network/synchronisable/Synchronisable.h"
+#include "BaseSound.h"
+#include "MoodManager.h"
 
 namespace orxonox
 {
@@ -43,7 +44,7 @@
      * It server as main interface to the OpenAL library.
      *
      */
-    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable
+    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener
     {
         friend class SoundManager;
 
@@ -73,6 +74,7 @@
         void preDestroy();
         void registerVariables();
         float getRealVolume();
+        void moodChanged(const std::string& mood);
         inline void ambientSourceChanged()
             { this->setAmbientSource(this->ambientSource_); }
         inline void playOnLoadChanged()




More information about the Orxonox-commit mailing list