Changeset 6406 for code/branches/presentation2/src/orxonox
- Timestamp:
- Dec 23, 2009, 8:45:56 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/MoodManager.cc
r6387 r6406 29 29 #include "MoodManager.h" 30 30 31 #include "core/ConsoleCommand.h"32 31 #include "core/ConfigValueIncludes.h" 33 32 #include "core/CoreIncludes.h" … … 42 41 RegisterRootObject(MoodManager); 43 42 this->setConfigValues(); 44 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&MoodManager::setMood, this), "setMood"));45 }46 47 MoodManager::~MoodManager()48 {49 43 } 50 44 … … 65 59 } 66 60 67 //! Gets the current mood 68 const std::string& MoodManager::getMood() 61 void MoodManager::checkMoodValidity() 69 62 { 70 return mood_; 63 // TODO: Insert new moods here & make this generic 64 if (mood_ != "default" && mood_ != "dnb") 65 { 66 ResetConfigValue(mood_); 67 } 68 else 69 { 70 COUT(3) << "Mood changed to " << mood_ << std::endl; 71 MoodListener::changedMood(mood_); 72 } 71 73 } 72 74 73 void MoodManager::checkMoodValidity() 75 76 std::string MoodListener::mood_s; 77 78 MoodListener::MoodListener() 74 79 { 75 if (mood_ != "default" && mood_ != "dnb") // Insert new moods here; TODO: make this generic 76 ResetConfigValue(mood_); 77 COUT(4) << "MoodManager: Mood set to " << mood_ << std::endl; 80 RegisterRootObject(MoodListener); 81 } 82 83 /*static*/ void MoodListener::changedMood(const std::string& mood) 84 { 85 mood_s = mood; 86 for (ObjectList<MoodListener>::iterator it = ObjectList<MoodListener>::begin(); it; ++it) 87 it->moodChanged(mood_s); 78 88 } 79 89 } -
code/branches/presentation2/src/orxonox/MoodManager.h
r6370 r6406 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <cassert>35 #include <list>36 34 #include <string> 37 38 35 #include "util/Singleton.h" 39 36 #include "core/OrxonoxClass.h" 40 37 41 // tolua_begin42 38 namespace orxonox 43 39 { 44 class _OrxonoxExport MoodManager 45 // tolua_end 46 : public Singleton<MoodManager>, public OrxonoxClass 47 { // tolua_export 40 class _OrxonoxExport MoodListener : virtual public OrxonoxClass 41 { 42 friend class MoodManager; 43 44 protected: 45 MoodListener(); 46 virtual ~MoodListener() {} 47 48 const std::string& getMood() const { return mood_s; } 49 50 private: 51 virtual void moodChanged(const std::string& mood) = 0; 52 53 static void changedMood(const std::string& mood); 54 static std::string mood_s; 55 }; 56 57 class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass 58 { 48 59 friend class Singleton<MoodManager>; 49 60 public: 50 61 MoodManager(); 51 ~MoodManager();52 62 53 63 void setConfigValues(); 54 64 55 65 void setMood(const std::string& mood); 56 const std::string& getMood();66 inline const std::string& getMood() const { return this->mood_; } 57 67 58 static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); } // tolua_export68 static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); } 59 69 60 70 private: 71 ~MoodManager() {} 61 72 void checkMoodValidity(); 62 73 63 74 // config values 64 75 std::string mood_; 65 std::string moodOld_;66 76 67 77 static MoodManager* singletonPtr_s; 68 }; // tolua_export69 } // tolua_export78 }; 79 } 70 80 71 81 #endif /* _MoodManager_H__ */ -
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
r6394 r6406 35 35 #include "core/XMLPort.h" 36 36 #include "SoundManager.h" 37 #include "MoodManager.h"38 37 39 38 namespace orxonox … … 111 110 { 112 111 this->ambientSource_ = source; 112 this->moodChanged(this->getMood()); 113 } 114 115 void AmbientSound::moodChanged(const std::string& mood) 116 { 113 117 if (GameMode::playsSound()) 114 118 { 115 const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + source;119 const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_; 116 120 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path); 117 121 if (fileInfo != NULL) 118 122 this->setSource(path); 119 123 else 120 COUT(3) << "Sound: " << source<< ": Not a valid name! Ambient sound will not change." << std::endl;124 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl; 121 125 } 122 126 } -
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
r6382 r6406 34 34 35 35 #include "core/BaseObject.h" 36 #include "sound/BaseSound.h"37 36 #include "network/synchronisable/Synchronisable.h" 37 #include "BaseSound.h" 38 #include "MoodManager.h" 38 39 39 40 namespace orxonox … … 44 45 * 45 46 */ 46 class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable 47 class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener 47 48 { 48 49 friend class SoundManager; … … 74 75 void registerVariables(); 75 76 float getRealVolume(); 77 void moodChanged(const std::string& mood); 76 78 inline void ambientSourceChanged() 77 79 { this->setAmbientSource(this->ambientSource_); }
Note: See TracChangeset
for help on using the changeset viewer.