Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6537


Ignore:
Timestamp:
Mar 16, 2010, 1:49:16 PM (15 years ago)
Author:
rgrieder
Message:

Linked every GUI sheet to exactly one InputState.
Also added util/TriBool that has states {true, false, Dontcare}.

Location:
code/branches/gamestate
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/data/gui/scripts/BasicGUI.lua

    r6459 r6537  
    88end
    99
    10 -- useless?
     10-- useless, even wrong? P is the class, not the object..
    1111P.overlay = nil
    1212
    1313-- constructor of the GUI
    14 function P:new(_filename, _visible, _gui)
     14function P:new(_filename, _gui, _visible)
    1515    local newElement = {
    1616        filename = _filename,
     
    2323end
    2424
     25-- Override this function if you need to
    2526function P:init()
    26 -- this function is empty and intended for inheriting GUIs to use
     27end
     28
     29-- Override this function if you need to
     30-- But don't forget to stick to the naming convention ("GUI_" .. self.filename)
     31function P:createInputState()
     32    self.inputState = guiMgr:createInputState("GUI_" .. self.filename)
    2733end
    2834
     
    4147function P:load()
    4248    self.window = winMgr:loadWindowLayout(self.filename .. ".layout")
     49    self:createInputState()
    4350    self:init()
    4451    return self
  • code/branches/gamestate/data/gui/scripts/DecisionPopup.lua

    r6459 r6537  
    77else
    88    _G[_REQUIREDNAME] = P
    9 end
    10 
    11 function P:init()
    129end
    1310
  • code/branches/gamestate/data/gui/scripts/InGameMenu.lua

    r6459 r6537  
    88    _G[_REQUIREDNAME] = P
    99end
    10 
    11 
    12 function P:init()
    13 end
    14 
    1510
    1611-- events for ingamemenu
  • code/branches/gamestate/data/gui/scripts/InfoPopup.lua

    r6459 r6537  
    88else
    99    _G[_REQUIREDNAME] = P
    10 end
    11 
    12 function P:init()
    1310end
    1411
     
    2320end
    2421
    25 function P.setText( text )
     22function P.setText(text)
    2623    winMgr:getWindow("orxonox/InfoPopup_text"):setText( text )
    2724end
     
    3936-- events for ingamemenu
    4037function P.close(e)
    41     hideGUI("InfoPopup")
     38    hideGUI(P.filename)
    4239end
    4340
  • code/branches/gamestate/data/gui/scripts/InitialiseGUI.lua

    r6417 r6537  
     1winMgr   = CEGUI.WindowManager:getSingleton()
     2guiMgr   = orxonox.GUIManager:getInstance()
     3inputMgr = orxonox.InputManager:getInstance()
     4
    15local schemeMgr = CEGUI.SchemeManager:getSingleton()
    2 winMgr = CEGUI.WindowManager:getSingleton()
    3 local logger = CEGUI.Logger:getSingleton()
    4 local system = CEGUI.System:getSingleton()
    5 local cursor = CEGUI.MouseCursor:getSingleton()
     6local system    = CEGUI.System:getSingleton()
     7local cursor    = CEGUI.MouseCursor:getSingleton()
    68
    79schemeMgr:loadScheme("TaharezLookSkin.scheme")
     
    8789    else
    8890        if nrOfActiveSheets == 0 then
    89             orxonox.InputManager:getInstance():enterState("guiMouseOnly")
     91            --orxonox.InputManager:getInstance():enterState("guiMouseOnly")
    9092            orxonox.HumanController:pauseControl()
    9193        end
    9294    end
     95    orxonox.InputManager:getInstance():enterState(currentGUI.inputState)
     96
    9397    nrOfActiveSheets = nrOfActiveSheets + 1
    9498    table.insert(activeSheets, filename)
     
    161165    bHidePrevious[filename] = nil
    162166    if nrOfActiveSheets == 0 then
    163         orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
     167        --orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
    164168        orxonox.HumanController:resumeControl()
    165169        hideCursor()
    166170    end
     171    orxonox.InputManager:getInstance():leaveState(currentGUI.inputState)
    167172end
    168173
  • code/branches/gamestate/src/libraries/core/Core.cc

    r6417 r6537  
    225225
    226226        // Load the CEGUI interface
    227         guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
    228             inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
     227        guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
    229228
    230229        bGraphicsLoaded_ = true;
  • code/branches/gamestate/src/libraries/core/GUIManager.cc

    r6441 r6537  
    5757#include "ConsoleCommand.h"
    5858#include "Core.h"
     59#include "GraphicsManager.h"
    5960#include "LuaState.h"
    6061#include "PathConfig.h"
    6162#include "Resource.h"
     63#include "input/InputManager.h"
     64#include "input/InputState.h"
     65#include "input/KeyBinderManager.h"
    6266
    6367namespace orxonox
     
    108112    @return true if success, otherwise false
    109113    */
    110     GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
    111         : renderWindow_(renderWindow)
    112         , resourceProvider_(0)
     114    GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
     115        : resourceProvider_(NULL)
    113116        , camera_(NULL)
    114         , bShowIngameGUI_(false)
    115117    {
    116118        using namespace CEGUI;
     
    119121
    120122        // Note: No SceneManager specified yet
    121         guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
     123        guiRenderer_.reset(new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
    122124        resourceProvider_ = guiRenderer_->createResourceProvider();
    123125        resourceProvider_->setDefaultResourceGroup("GUI");
     
    141143        guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
    142144
     145        // Align CEGUI mouse with OIS mouse
     146        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
     147
     148        // Hide the mouse cursor unless playing in full screen mode
     149        if (!GraphicsManager::getInstance().isFullScreen())
     150            CEGUI::MouseCursor::getSingleton().hide();
     151
    143152        // Initialise the basic Lua code
    144153        this->luaState_->doFile("InitialiseGUI.lua");
    145 
    146         // Align CEGUI mouse with OIS mouse
    147         guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
    148 
    149         // Hide the mouse cursor unless playing in full screen mode
    150         if (!bFullScreen)
    151             CEGUI::MouseCursor::getSingleton().hide();
    152154    }
    153155
     
    251253    }
    252254
     255    const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showMouse, TriBool::Value useKeyboard, bool bBlockJoyStick)
     256    {
     257        InputState* state = InputManager::getInstance().createInputState(name);
     258
     259        if (GraphicsManager::getInstance().isFullScreen() && showMouse == TriBool::True ||
     260           !GraphicsManager::getInstance().isFullScreen() && showMouse == TriBool::False)
     261            state->setMouseExclusive(TriBool::True);
     262        else
     263            state->setMouseExclusive(TriBool::Dontcare);
     264
     265        if (showMouse == TriBool::True)
     266            state->setMouseHandler(this);
     267        else if (showMouse == TriBool::False)
     268            state->setMouseHandler(&InputHandler::EMPTY);
     269
     270        if (useKeyboard == TriBool::True)
     271            state->setKeyHandler(this);
     272        else if (useKeyboard == TriBool::False)
     273            state->setKeyHandler(&InputHandler::EMPTY);
     274
     275        if (bBlockJoyStick)
     276            state->setJoyStickHandler(&InputHandler::EMPTY);
     277
     278        return state->getName();
     279    }
     280
    253281    void GUIManager::keyESC()
    254282    {
  • code/branches/gamestate/src/libraries/core/GUIManager.h

    r6441 r6537  
    4141
    4242#include "util/OgreForwardRefs.h"
     43#include "util/TriBool.h"
    4344#include "util/Singleton.h"
    4445#include "input/InputHandler.h"
     46
     47// Tolua includes (have to be relative to the current directory)
     48/*
     49$cfile "../util/TriBool.h" // tolua_export
     50*/
    4551
    4652namespace orxonox // tolua_export
     
    5460
    5561        The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.
    56         Creation of the GUIManager is therefore not possible and the cunstructor is private.
    5762
    5863        Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
     
    6469        friend class Singleton<GUIManager>;
    6570    public:
    66         GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
     71        GUIManager(const std::pair<int, int>& mousePosition);
    6772        ~GUIManager();
    6873
     
    7681        void setBackground(const std::string& name);
    7782
     83        const std::string& createInputState(const std::string& name, TriBool::Value showMouse = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
     84
    7885        void setCamera(Ogre::Camera* camera);
    7986        Ogre::Camera* getCamera() { return this->camera_; }
    80 
    81         static GUIManager* getInstancePtr() { return singletonPtr_s; }
    8287
    8388        inline void setPlayer(const std::string& guiname, PlayerInfo* player)
     
    8893        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
    8994        static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
     95
     96        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
    9097
    9198    private:
     
    103110        void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    104111        void mouseScrolled (int abs, int rel);
    105 
    106112        scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
    107113        scoped_ptr<LuaState>                 luaState_;         //!< LuaState, access point to the Lua engine
     
    109115        scoped_ptr<CEGUI::System>            guiSystem_;        //!< CEGUI's main system
    110116        shared_ptr<ResourceInfo>             rootFileInfo_;     //!< Resource information about the root script
    111         Ogre::RenderWindow*                  renderWindow_;     //!< Ogre's render window to give CEGUI access to it
    112117        CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
    113118        CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
    114         std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each gui
     119        std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each GUI
    115120        Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
    116121
    117122        static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
    118         bool                                 bShowIngameGUI_;
    119123
    120124    }; // tolua_export
  • code/branches/gamestate/src/libraries/core/input/InputManager.cc

    r6422 r6537  
    8787        , oisInputManager_(0)
    8888        , devices_(2)
    89         , mouseMode_(MouseMode::Nonexclusive)
     89        , exclusiveMouse_(TriBool::False)
    9090        , emptyState_(0)
    9191        , calibratorCallbackHandler_(0)
     
    9898
    9999        if (GraphicsManager::getInstance().isFullScreen())
    100             mouseMode_ = MouseMode::Exclusive;
     100            exclusiveMouse_ = TriBool::True;
    101101        this->loadDevices();
    102102
     
    155155        paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
    156156        paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
    157         if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
     157        if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
    158158        {
    159159            // Disable Windows key plus special keys (like play, stop, next, etc.)
     
    168168        paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
    169169
    170         if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
     170        if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
    171171        {
    172172            if (CommandLineParser::getValue("keyboard_no_grab").getBool())
     
    504504
    505505        // Check whether we have to change the mouse mode
    506         MouseMode::Value requestedMode = MouseMode::Dontcare;
     506        TriBool::Value requestedMode = TriBool::Dontcare;
    507507        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
    508508        if (mouseStates.empty())
    509             requestedMode = MouseMode::Nonexclusive;
     509            requestedMode = TriBool::False;
    510510        else
    511             requestedMode = mouseStates.front()->getMouseMode();
    512         if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode)
    513         {
    514             mouseMode_ = requestedMode;
     511            requestedMode = mouseStates.front()->getMouseExclusive();
     512        if (requestedMode != TriBool::Dontcare && exclusiveMouse_ != requestedMode)
     513        {
     514            exclusiveMouse_ = requestedMode;
    515515            if (!GraphicsManager::getInstance().isFullScreen())
    516516                this->reloadInternal();
  • code/branches/gamestate/src/libraries/core/input/InputManager.h

    r6417 r6537  
    3838
    3939#include "util/Singleton.h"
     40#include "util/TriBool.h"
    4041#include "core/WindowEventListener.h"
    4142#include "InputState.h"
     
    159160            - The removal process is being postponed if InputManager::preUpdate() is currently running.
    160161        */
    161         bool destroyState(const std::string& name);
     162        bool destroyState(const std::string& name); // tolua_export
    162163
    163164        //-------------------------------
     
    196197        OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
    197198        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    198         MouseMode::Value                    mouseMode_;            //!< Currently applied mouse mode
     199        TriBool::Value                      exclusiveMouse_;       //!< Currently applied mouse mode
    199200
    200201        // some internally handled states and handlers
  • code/branches/gamestate/src/libraries/core/input/InputState.cc

    r6417 r6537  
    3737        , bAlwaysGetsInput_(bAlwaysGetsInput)
    3838        , bTransparent_(bTransparent)
    39         , mouseMode_(MouseMode::Dontcare)
     39        , exclusiveMouse_(TriBool::Dontcare)
    4040        , bExpired_(true)
    4141        , handlers_(2)
  • code/branches/gamestate/src/libraries/core/input/InputState.h

    r5929 r6537  
    3737
    3838#include "util/OrxEnum.h"
     39#include "util/TriBool.h"
    3940#include "InputHandler.h"
    4041#include "JoyStickQuantityListener.h"
     
    5657    };
    5758
    58     namespace MouseMode
    59     {
    60         enum Value
    61         {
    62             Exclusive,
    63             Nonexclusive,
    64             Dontcare
    65         };
    66     }
    6759
    6860    /**
     
    7365        that stack and only the top one gets the input events. This is done for
    7466        every device (keyboard, mouse, all joy sticks) separately to allow
    75         for intance keyboard input capturing for the console while you can still
     67        for instance keyboard input capturing for the console while you can still
    7668        steer a ship with the mouse.
    7769        There are two exceptions to this behaviour though:
     
    8375          the state will always receive input as long as it is activated.
    8476        - Note: If you mark an InputState with both parameters on, then it will
    85           not influence ony other InputState at all.
     77          not influence only other InputState at all.
    8678
    8779    @par Priorities
     
    9587    @par Exclusive/Non-Exclusive mouse Mode
    9688        You can select a specific mouse mode that tells whether the application
    97         should have exclusive accessto it or not.
     89        should have exclusive access to it or not.
    9890        When in non-exclusive mode, you can move the mouse out of the window
    9991        like with any other normal window (only for windowed mode!).
     
    130122        void setHandler        (InputHandler* handler);
    131123
    132         void setMouseMode(MouseMode::Value value) { mouseMode_ = value; this->bExpired_ = true; }
    133         MouseMode::Value getMouseMode() const { return mouseMode_; }
     124        void setMouseExclusive(TriBool::Value value) { exclusiveMouse_ = value; this->bExpired_ = true; }
     125        TriBool::Value getMouseExclusive() const { return exclusiveMouse_; }
    134126
    135127        //! Returns the name of the state (which is unique!)
     
    184176        const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
    185177        const bool                  bTransparent_;          //!< See class declaration for explanation
    186         MouseMode::Value            mouseMode_;             //!< See class declaration for explanation
     178        TriBool::Value              exclusiveMouse_;        //!< See class declaration for explanation
    187179        int                         priority_;              //!< Current priority (might change)
    188180        bool                        bExpired_;              //!< See hasExpired()
  • code/branches/gamestate/src/orxonox/gamestates/GSLevel.cc

    r6417 r6537  
    6969        {
    7070            gameInputState_ = InputManager::getInstance().createInputState("game");
    71             gameInputState_->setMouseMode(MouseMode::Exclusive);
     71            gameInputState_->setMouseExclusive(TriBool::True);
    7272            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
    7373            KeyBinderManager::getInstance().setToDefault();
    7474
    7575            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
    76             guiMouseOnlyInputState_->setMouseMode(MouseMode::Exclusive);
    77             guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
     76            guiMouseOnlyInputState_->setMouseExclusive(TriBool::True);
     77            guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
    7878
    7979            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
    80             guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
     80            guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
    8181        }
    8282
  • code/branches/gamestate/src/orxonox/gamestates/GSMainMenu.cc

    r6417 r6537  
    5353        RegisterRootObject(GSMainMenu);
    5454        inputState_ = InputManager::getInstance().createInputState("mainMenu");
    55         inputState_->setMouseMode(MouseMode::Nonexclusive);
    56         inputState_->setHandler(GUIManager::getInstancePtr());
     55        inputState_->setMouseExclusive(TriBool::False);
     56        inputState_->setHandler(&GUIManager::getInstance());
    5757        inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
    5858        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
     
    101101
    102102        KeyBinderManager::getInstance().setToDefault();
    103         InputManager::getInstance().enterState("mainMenu");
     103        //InputManager::getInstance().enterState("mainMenu");
    104104
    105105        this->setConfigValues();
     
    119119        }
    120120
    121         InputManager::getInstance().leaveState("mainMenu");
     121        //InputManager::getInstance().leaveState("mainMenu");
    122122
    123123        GUIManager::getInstance().setCamera(0);
Note: See TracChangeset for help on using the changeset viewer.