Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc @ 6003

Last change on this file since 6003 was 6003, checked in by dafrick, 15 years ago

Implemented support for multiple simultaniously showing GUIs. What happens now, in essence, is, that every root-window of a gui, that is to be showed, is attached to a global root window, which is always displayed and therefore needs to be fully transparent (alpha = 0.0). To not inherit the transparency (and thus be fully transparent as well) each root-window of a gui must (or should) set the property 'InheritsAlpha' to false.

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
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 *      Reto Grieder
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *      Benjamin Knecht
27 *
28 */
29
30#include "GSLevel.h"
31
32#include <OgreCompositorManager.h>
33
34#include "util/Clock.h"
35#include "core/input/InputManager.h"
36#include "core/input/InputState.h"
37#include "core/input/KeyBinderManager.h"
38#include "core/ConsoleCommand.h"
39#include "core/Game.h"
40#include "core/GameMode.h"
41#include "core/GUIManager.h"
42#include "core/Loader.h"
43#include "core/XMLFile.h"
44
45#include "LevelManager.h"
46#include "PlayerManager.h"
47
48namespace orxonox
49{
50    DeclareGameState(GSLevel, "level", false, false);
51
52    GSLevel::GSLevel(const GameStateInfo& info)
53        : GameState(info)
54        , gameInputState_(0)
55        , guiMouseOnlyInputState_(0)
56        , guiKeysOnlyInputState_(0)
57        , startFile_(0)
58    {
59    }
60
61    GSLevel::~GSLevel()
62    {
63    }
64
65    void GSLevel::activate()
66    {
67        if (GameMode::showsGraphics())
68        {
69            gameInputState_ = InputManager::getInstance().createInputState("game");
70            gameInputState_->setMouseMode(MouseMode::Exclusive);
71            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
72            KeyBinderManager::getInstance().setToDefault();
73
74            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
75            guiMouseOnlyInputState_->setMouseMode(MouseMode::Exclusive);
76            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
77
78            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
79            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
80
81            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
82        }
83
84        if (GameMode::isMaster())
85        {
86            this->loadLevel();
87        }
88
89        if (GameMode::showsGraphics())
90        {
91            // level is loaded: we can start capturing the input
92            InputManager::getInstance().enterState("game");
93           
94            // connect the HumanPlayer to the game
95            PlayerManager::getInstance().clientConnected(0);
96        }
97    }
98
99    void GSLevel::showIngameGUI(bool show)
100    {
101        if (show)
102        {
103            GUIManager::showGUI("inGameTest");
104        }
105        else
106        {
107            GUIManager::hideGUI("inGameTest");
108        }
109    }
110
111    void GSLevel::deactivate()
112    {
113        if (GameMode::showsGraphics())
114        {
115            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
116            Ogre::CompositorManager::getSingleton().removeAll();
117
118            InputManager::getInstance().leaveState("game");
119        }
120       
121        // disconnect all HumanPlayers
122        PlayerManager::getInstance().disconnectAllClients();
123
124        if (GameMode::isMaster())
125            this->unloadLevel();
126
127        if (GameMode::showsGraphics())
128        {
129            gameInputState_->setHandler(0);
130            guiMouseOnlyInputState_->setHandler(0);
131            guiKeysOnlyInputState_->setHandler(0);
132            InputManager::getInstance().destroyState("game");
133            InputManager::getInstance().destroyState("guiKeysOnly");
134            InputManager::getInstance().destroyState("guiMouseOnly");
135        }
136    }
137
138    void GSLevel::update(const Clock& time)
139    {
140        // Note: Temporarily moved to GSRoot.
141        //// Call the scene objects
142        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
143        //    it->tick(time.getDeltaTime() * this->timeFactor_);
144    }
145
146    void GSLevel::loadLevel()
147    {
148        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
149            this->staticObjects_.insert(*it);
150       
151        // call the loader
152        COUT(0) << "Loading level..." << std::endl;
153        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
154        Loader::open(startFile_);
155    }
156
157    void GSLevel::unloadLevel()
158    {
159        Loader::unload(startFile_);
160        delete startFile_;
161
162        COUT(3) << "Unloaded level. Remaining objects:" << std::endl;
163        unsigned int i = 0;
164        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
165        {
166            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
167            if (find == this->staticObjects_.end())
168            {
169                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ")" << std::endl;
170            }
171        }
172        COUT(3) << i << " objects remaining.";
173        if (i == 0)
174            COUT(3) << " Well done!" << std::endl;
175        else
176            COUT(3) << " Try harder!" << std::endl;
177    }
178}
Note: See TracBrowser for help on using the repository browser.