Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gamestates/GSGraphics.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: 4.0 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 *      Benjamin Knecht
26 *
27 */
28
29/**
30@file
31@brief
32    Implementation of Graphics GameState class.
33 */
34
35#include "GSGraphics.h"
36
37#include "util/Clock.h"
38#include "util/Convert.h"
39#include "core/CommandExecutor.h"
40#include "core/ConsoleCommand.h"
41#include "core/Game.h"
42#include "core/GUIManager.h"
43#include "core/Loader.h"
44#include "core/XMLFile.h"
45
46// HACK:
47#include "overlays/Map.h"
48
49namespace orxonox
50{
51    DeclareGameState(GSGraphics, "graphics", false, true);
52
53    GSGraphics::GSGraphics(const GameStateInfo& info)
54        : GameState(info)
55        , debugOverlay_(0)
56    {
57    }
58
59    GSGraphics::~GSGraphics()
60    {
61    }
62
63    /**
64    @brief
65        This function is called when we enter this game state.
66
67        Since graphics is very important for our game this function does quite a lot:
68        \li starts graphics manager
69        \li loads debug overlay
70        \li manages render window
71        \li creates input manager
72        \li loads master key bindings
73        \li loads the SoundManager
74        \li loads ingame console
75        \li loads GUI interface (GUIManager)
76        \li creates console command to toggle GUI
77    */
78    void GSGraphics::activate()
79    {
80        // load debug overlay
81        COUT(3) << "Loading Debug Overlay..." << std::endl;
82        this->debugOverlay_ = new XMLFile("debug.oxo");
83        Loader::open(debugOverlay_);
84
85        // add console command to toggle GUI
86        this->ccToggleGUI_ = createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI");
87        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
88    }
89
90    /**
91    @brief
92        This function is called when the game state is left
93
94        Created references, input states and console commands are deleted.
95    */
96    void GSGraphics::deactivate()
97    {
98/*
99        if (this->ccToggleGUI_)
100        {
101            delete this->ccToggleGUI_;
102            this->ccToggleGUI_ = 0;
103        }
104*/
105
106        Loader::unload(this->debugOverlay_);
107        delete this->debugOverlay_;
108
109        // HACK: (destroys a resource smart pointer)
110        Map::hackDestroyMap();
111    }
112
113    /**
114    @brief
115        Toggles the visibility of the current GUI
116
117        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
118        For more details on this function check out the Lua code.
119    */
120    void GSGraphics::toggleGUI()
121    {
122        GUIManager::getInstance().executeCode("toggleGUI()");
123    }
124
125    /**
126    @note
127        A note about the Ogre::FrameListener: Even though we don't use them,
128        they still get called. However, the delta times are not correct (except
129        for timeSinceLastFrame, which is the most important). A little research
130        as shown that there is probably only one FrameListener that doesn't even
131        need the time. So we shouldn't run into problems.
132    */
133    void GSGraphics::update(const Clock& time)
134    {
135        if (this->getActivity().topState)
136        {
137            // This state can not 'survive' on its own.
138            // Load a user interface therefore
139            Game::getInstance().requestState("mainMenu");
140        }
141    }
142}
Note: See TracBrowser for help on using the repository browser.