Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gamestates/GSLevel.cc @ 5863

Last change on this file since 5863 was 5863, checked in by rgrieder, 15 years ago

New class: KeyBinderManager (yes, it really was necessary, I'm not such a Fan of zillions of classes as well) and moved the keybind command to it from GSLevel.
This new Singleton simply maps the keybind command to the right KeyBinder, selected by KeyBinderManager::setCurrent().
There is also a default KeyBinder (with keybindings.ini as file), which should do the Trick for now. Other Keybinders should only server special purposes (like in mini games or so).

DELETE YOUR keybindings.ini FILE! =
  • Property svn:eol-style set to native
File size: 5.5 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/ConfigValueIncludes.h"
40#include "core/CoreIncludes.h"
41#include "core/Game.h"
42#include "core/GameMode.h"
43#include "core/GUIManager.h"
44#include "core/Loader.h"
45#include "core/XMLFile.h"
46
47#include "LevelManager.h"
48#include "PlayerManager.h"
49
50namespace orxonox
51{
52    DeclareGameState(GSLevel, "level", false, false);
53    SetConsoleCommand(GSLevel, showIngameGUI, true);
54
55    XMLFile* GSLevel::startFile_s = NULL;
56
57    GSLevel::GSLevel(const GameStateInfo& info)
58        : GameState(info)
59        , gameInputState_(0)
60        , guiMouseOnlyInputState_(0)
61        , guiKeysOnlyInputState_(0)
62    {
63        RegisterObject(GSLevel);
64    }
65
66    GSLevel::~GSLevel()
67    {
68    }
69
70    void GSLevel::setConfigValues()
71    {
72    }
73
74    void GSLevel::activate()
75    {
76        setConfigValues();
77
78        if (GameMode::showsGraphics())
79        {
80            gameInputState_ = InputManager::getInstance().createInputState("game");
81            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
82            KeyBinderManager::getInstance().setToDefault();
83
84            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
85            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
86
87            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
88            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
89        }
90
91        if (GameMode::isMaster())
92        {
93            this->loadLevel();
94        }
95
96        if (GameMode::showsGraphics())
97        {
98            // level is loaded: we can start capturing the input
99            InputManager::getInstance().enterState("game");
100           
101            // connect the HumanPlayer to the game
102            PlayerManager::getInstance().clientConnected(0);
103        }
104    }
105
106    void GSLevel::showIngameGUI(bool show)
107    {
108        if (show)
109        {
110            GUIManager::getInstance().showGUI("inGameTest");
111            GUIManager::getInstance().executeCode("showCursor()");
112            InputManager::getInstance().enterState("guiMouseOnly");
113        }
114        else
115        {
116            GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
117            GUIManager::getInstance().executeCode("hideCursor()");
118            InputManager::getInstance().leaveState("guiMouseOnly");
119        }
120    }
121
122    void GSLevel::deactivate()
123    {
124        if (GameMode::showsGraphics())
125        {
126            // disconnect the HumanPlayer
127            PlayerManager::getInstance().clientDisconnected(0);
128           
129            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
130            Ogre::CompositorManager::getSingleton().removeAll();
131        }
132
133        // this call will delete every BaseObject!
134        // But currently this will call methods of objects that exist no more
135        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
136        // and call a sceneNode method that has already been destroy by the corresponding space ship.
137        //Loader::close();
138
139        if (GameMode::showsGraphics())
140        {
141            InputManager::getInstance().leaveState("game");
142        }
143
144        if (GameMode::isMaster())
145            this->unloadLevel();
146
147        if (GameMode::showsGraphics())
148        {
149            gameInputState_->setHandler(0);
150            guiMouseOnlyInputState_->setHandler(0);
151            guiKeysOnlyInputState_->setHandler(0);
152            InputManager::getInstance().destroyState("game");
153            InputManager::getInstance().destroyState("guiKeysOnly");
154            InputManager::getInstance().destroyState("guiMouseOnly");
155        }
156    }
157
158    void GSLevel::update(const Clock& time)
159    {
160        // Note: Temporarily moved to GSGraphics.
161        //// Call the scene objects
162        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
163        //    it->tick(time.getDeltaTime() * this->timeFactor_);
164    }
165
166    void GSLevel::loadLevel()
167    {
168        // call the loader
169        COUT(0) << "Loading level..." << std::endl;
170        startFile_s = new XMLFile(LevelManager::getInstance().getDefaultLevel());
171        Loader::open(startFile_s);
172    }
173
174    void GSLevel::unloadLevel()
175    {
176        Loader::unload(startFile_s);
177
178        delete startFile_s;
179    }
180}
Note: See TracBrowser for help on using the repository browser.