Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6406


Ignore:
Timestamp:
Dec 23, 2009, 8:45:56 PM (14 years ago)
Author:
rgrieder
Message:

Mood changes should now be working and with immediate (but delayed because of loading) effect.

Location:
code/branches/presentation2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/gui/layouts/AudioMenu.layout

    r6363 r6406  
    111111            </Window>
    112112            <Window Type="TaharezLook/StaticText" Name="orxonox/AudioInfo" >
    113                 <Property Name="Text" >Theme changes require
    114 a game restart.</Property>
     113                <Property Name="Text" >Theme changes might take
     114up to a minute.</Property>
    115115                <Property Name="TextColours" Value="FF4444FF" />
    116116                <Property Name="InheritsAlpha" Value="False" />
  • code/branches/presentation2/data/gui/scripts/AudioMenu.lua

    r6403 r6406  
    4545        item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
    4646        CEGUI.toListbox(listboxwindow):addItem(item)
     47    end
     48    if orxonox.getConfig("MoodManager", "mood_") == "dnb" then
     49        listboxwindow:setItemSelectState(1,true)
     50    else
     51        listboxwindow:setItemSelectState(0,true)
    4752    end
    4853end
     
    166171function P.AudioThemeListbox_changed(e)
    167172    if listboxwindow:isItemSelected(1) then
    168         orxonox.execute("setMood dnb")
     173        orxonox.config("MoodManager", "mood_", "dnb")
    169174    else
    170         orxonox.execute("setMood default")
     175        orxonox.config("MoodManager", "mood_", "default")
    171176    end
    172177end
  • code/branches/presentation2/src/orxonox/MoodManager.cc

    r6387 r6406  
    2929#include "MoodManager.h"
    3030
    31 #include "core/ConsoleCommand.h"
    3231#include "core/ConfigValueIncludes.h"
    3332#include "core/CoreIncludes.h"
     
    4241        RegisterRootObject(MoodManager);
    4342        this->setConfigValues();
    44         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&MoodManager::setMood, this), "setMood"));
    45     }
    46 
    47     MoodManager::~MoodManager()
    48     {
    4943    }
    5044
     
    6559    }
    6660
    67     //! Gets the current mood
    68     const std::string& MoodManager::getMood()
     61    void MoodManager::checkMoodValidity()
    6962    {
    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        }
    7173    }
    7274
    73     void MoodManager::checkMoodValidity()
     75
     76    std::string MoodListener::mood_s;
     77
     78    MoodListener::MoodListener()
    7479    {
    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);
    7888    }
    7989}
  • code/branches/presentation2/src/orxonox/MoodManager.h

    r6370 r6406  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include <cassert>
    35 #include <list>
    3634#include <string>
    37 
    3835#include "util/Singleton.h"
    3936#include "core/OrxonoxClass.h"
    4037
    41 // tolua_begin
    4238namespace orxonox
    4339{
    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    {
    4859            friend class Singleton<MoodManager>;
    4960        public:
    5061            MoodManager();
    51             ~MoodManager();
    5262
    5363            void setConfigValues();
    5464
    5565            void setMood(const std::string& mood);
    56             const std::string& getMood();
     66            inline const std::string& getMood() const { return this->mood_; }
    5767
    58             static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); } // tolua_export
     68            static MoodManager& getInstance() { return Singleton<MoodManager>::getInstance(); }
    5969
    6070        private:
     71            ~MoodManager() {}
    6172            void checkMoodValidity();
    6273
    6374            // config values
    6475            std::string mood_;
    65             std::string moodOld_;
    6676
    6777            static MoodManager* singletonPtr_s;
    68     }; // tolua_export
    69 } // tolua_export
     78    };
     79}
    7080
    7181#endif /* _MoodManager_H__ */
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.cc

    r6394 r6406  
    3535#include "core/XMLPort.h"
    3636#include "SoundManager.h"
    37 #include "MoodManager.h"
    3837
    3938namespace orxonox
     
    111110    {
    112111        this->ambientSource_ = source;
     112        this->moodChanged(this->getMood());
     113    }
     114
     115    void AmbientSound::moodChanged(const std::string& mood)
     116    {
    113117        if (GameMode::playsSound())
    114118        {
    115             const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + source;
     119            const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
    116120            shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
    117121            if (fileInfo != NULL)
    118122                this->setSource(path);
    119123            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;
    121125        }
    122126    }
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.h

    r6382 r6406  
    3434
    3535#include "core/BaseObject.h"
    36 #include "sound/BaseSound.h"
    3736#include "network/synchronisable/Synchronisable.h"
     37#include "BaseSound.h"
     38#include "MoodManager.h"
    3839
    3940namespace orxonox
     
    4445     *
    4546     */
    46     class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable
     47    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable, public MoodListener
    4748    {
    4849        friend class SoundManager;
     
    7475        void registerVariables();
    7576        float getRealVolume();
     77        void moodChanged(const std::string& mood);
    7678        inline void ambientSourceChanged()
    7779            { this->setAmbientSource(this->ambientSource_); }
Note: See TracChangeset for help on using the changeset viewer.