Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/MoodManager.cc @ 12389

Last change on this file since 12389 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.4 KB
RevLine 
[6119]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Kevin 'youngk' Young
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "MoodManager.h"
30
[10624]31#include "core/singleton/ScopedSingletonIncludes.h"
[9667]32#include "core/config/ConfigValueIncludes.h"
[6119]33#include "core/CoreIncludes.h"
[7163]34#include "core/Resource.h"
[6119]35
36namespace orxonox
37{
[10624]38    ManageScopedSingleton(MoodManager, ScopeID::ROOT, false);
[6119]39
[7163]40    // Note: I'm (Kevin Young) not entirely sure whether that's good code style:
41    const std::string MoodManager::defaultMood_ = "default";
42
[10624]43    RegisterAbstractClass(MoodListener).inheritsFrom<OrxonoxInterface>();
44    RegisterAbstractClass(MoodManager).inheritsFrom<Configurable>();
45
[6119]46    MoodManager::MoodManager()
47    {
[9667]48        RegisterObject(MoodManager);
[6119]49        this->setConfigValues();
[7163]50
51        // Need to use a variable to store old data because ResetConfigValues() doesn't seem to work.
52        oldMood_ = MoodManager::defaultMood_;
[7284]53
[7163]54        // Checking for the existence of the folder for the default mood
55        const std::string& path = "ambient/" + MoodManager::defaultMood_ + "/.";
56        if (!Resource::exists(path))
57        {
58            // TODO: Non-fatal error handling (non-critical resource missing)
[8858]59            orxout(internal_warning) << "Mood Warning: Folder for default mood (" << MoodManager::defaultMood_ << ") does not exist!" << endl;
[7163]60        }
[8351]61       
62        // @TODO
63        // Creating a vector of the available moods to enable easy mood selection by Lua/CEGUI       
[6119]64    }
65
66    void MoodManager::setConfigValues()
67    {
[7163]68        SetConfigValue(mood_, MoodManager::defaultMood_)
[6119]69            .description("Sets the mood for the current level.")
70            .callback(this, &MoodManager::checkMoodValidity);
71    }
72
[7163]73    /** Set a new mood
74     */
[6119]75    void MoodManager::setMood(const std::string& mood)
76    {
[7163]77        oldMood_ = mood_;
[6119]78        ModifyConfigValue(mood_, set, mood);
79    }
[6387]80
[6406]81    void MoodManager::checkMoodValidity()
[6119]82    {
[7163]83        //  Generic mood validation
84        const std::string& path = "ambient/" + mood_ + "/.";
85        if (!Resource::exists(path))
[6406]86        {
[8858]87            orxout(internal_warning) << "Mood " << mood_ << " does not exist. Will not change." << endl;
[7163]88            this->setMood(oldMood_);
[6406]89        }
90        else
91        {
[8858]92            orxout(internal_info) << "Mood changed to " << mood_ << endl;
[6406]93            MoodListener::changedMood(mood_);
94        }
[6119]95    }
96
[6406]97
98    MoodListener::MoodListener()
[6119]99    {
[9667]100        RegisterObject(MoodListener);
[6119]101    }
[6406]102
103    /*static*/ void MoodListener::changedMood(const std::string& mood)
104    {
[11071]105        for (MoodListener* listener : ObjectList<MoodListener>())
106            listener->moodChanged(mood);
[6406]107    }
[6119]108}
Note: See TracBrowser for help on using the repository browser.