Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12377


Ignore:
Timestamp:
May 16, 2019, 2:27:40 PM (4 months ago)
Author:
tkuonen
Message:

Improve MouseAPI
Add Comments
Cleanup

Location:
code/branches/MouseAPI_FS19
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw

    r12363 r12377  
    1010  include("HUDTemplates3.oxo")
    1111  include("MouseCursor.oxo")
    12   include("tetrisHUD.oxo")
    1312  include("templates/lodInformation.oxt")
    14 ?>
    15 
    16 <?lua
    17   include("templates/spaceshipEscort.oxt")
    1813?>
    1914
     
    2318    <Template link=lodtemplate_default />
    2419  </templates>
     20  <!--<?lua include("includes/notifications.oxi") ?>-->
    2521
    2622  <Scene
     
    5147</MouseAPIExample>
    5248
    53 <!--<MouseAPICursor></MouseAPICursor>
    54 <MouseCursor></MouseCursor>-->
    5549  </Scene>
    5650</Level>
  • code/branches/MouseAPI_FS19/data/overlays/MouseCursor.oxo

    r12363 r12377  
    11<Template name="MouseCursor">
    22<OverlayGroup name = "MouseCursorGroup" scale = "1, 1">
    3     <MouseAPICursor name="cursor" position = "0, 0" size="0.03, 0.03" cursorShape="cursor.png"></MouseAPICursor>
     3    <MouseAPICursor name="cursor" position = "0, 0" size="0.03, 0.03" cursorShape="cursor.png" cursorColor="1,0,1"></MouseAPICursor>
    44</OverlayGroup>
    55</Template>
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12363 r12377  
    11#include "mouseapi.h"
    2 
    3 #if OGRE_VERSION >= 0x010900
    4 #   include <Overlay/OgreOverlayManager.h>
    5 #   include <Overlay/OgrePanelOverlayElement.h>
    6 #else
    7 #   include <OgreOverlayManager.h>
    8 #   include <OgrePanelOverlayElement.h>
    9 #endif
    10 
    11 #include "util/StringUtils.h"
    122
    133namespace orxonox{
     
    2717        if(InputManager::exists())
    2818        {
    29             //cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
    3019            state = InputManager::getInstance().createInputState("MouseAPI",true,true,99);
    3120            state->setMouseExclusive(false);//does this work
    3221            state->setMouseHandler(this);
     22            gameInputActivated = false;
    3323            state->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
    3424            InputManager::getInstance().enterState("guiMouseOnly");
    3525            InputManager::getInstance().enterState("MouseAPI");
    3626            InputManager::getInstance().setMouseExclusive("game",false);
    37             //InputManager::getInstance().setMouseExclusive("guiMouseOnly",false);
    38             //InputManager::getInstance().getState("game")->
    39         }
    40         //GUIManager::getInstance().showGUI("MouseAPICursor", true);//Display a mouse cursor by displaying a empty menu
    41         /*cursor = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    42                                                                .createOverlayElement("Panel", "MouseAPI_cursor_" + getUniqueNumberString()));
    43         cursor->setMaterialName("Orxonox/RadarMarker");//todo: better material
    44         cursor->setPosition(0,0);
    45         cursor->setDimensions(0.1,0.1);
    46         Ogre::Overlay* overlay = Ogre::OverlayManager::getSingleton().create( "MouseAPI_cursor_" + getUniqueNumberString() );
    47         overlay->show();*/
    48         //this->overlay_->add2D(this->cursor);
     27        }
    4928    }
    5029
     
    5534    if(active)
    5635    {
    57         GUIManager::getInstance().showGUI("MouseAPICursor", true);
    5836        active = false;
    5937        if(InputManager::exists())
     
    6644        clickEvents.clear();
    6745        scrollEvents.clear();
     46        gameInputActivated=false;
    6847    }
    6948}
     
    7655void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)
    7756{
    78     cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();//todo: trycatch
     57    cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
    7958    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
    8059    int mouseposX = InputManager::getInstance().getMousePosition().first;
     
    9473void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    9574{
    96     //mousePos = abs;
    9775}
    9876
    9977void MouseAPI::tick(float dt)
    10078{
    101     if(active)
    102     {
    103         InputManager::getInstance().leaveState("game");//hack: todo: crate 2nd input state with prioritz 98 for cegui(cursor)
    104         //GUIManager::getInstance().showGUI("MouseAPICursor", false);//hack todo: only if gui not shown & evt better if not in mouse mooved
     79    if(active && !gameInputActivated)
     80    {
     81        InputManager::getInstance().leaveState("game");
    10582    }
    10683
     
    239216}
    240217
    241 //returns relative Position of the Mouse
    242218Vector2 MouseAPI::getMousePosition()
    243219{
     
    246222}
    247223
    248 }
     224void MouseAPI::activateGameInput()
     225{
     226    gameInputActivated = true;
     227    state->setKeyHandler(nullptr);
     228}
     229
     230void MouseAPI::deactivateGameInput()
     231{
     232    gameInputActivated = false;
     233    state->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
     234}
     235
     236}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12363 r12377  
    22#define MOUSEAPI_H
    33
    4 #include "OrxonoxPrereqs.h"
    5 #include "util/OgreForwardRefs.h"
    6 #include "graphics/Camera.h"
     4#include <OrxonoxPrereqs.h>
     5#include <util/OgreForwardRefs.h>
     6#include <graphics/Camera.h>
    77#include <util/Math.h>
    88#include <list>
     
    1313#include <OgreCamera.h>
    1414#include <OgreViewport.h>
    15 #include "CameraManager.h"
     15#include <CameraManager.h>
    1616#include <functional>
    17 #include "core/GUIManager.h"
    18 #include "core/input/KeyBinderManager.h"
    19 #include "tools/interfaces/Tickable.h"
    20 #include "core/singleton/ScopedSingletonIncludes.h"
     17#include <core/GUIManager.h>
     18#include <core/input/KeyBinderManager.h>
     19#include <tools/interfaces/Tickable.h>
     20#include <core/singleton/ScopedSingletonIncludes.h>
    2121
    2222/* this class implements a basic mouse-api
     
    3535 * to make it work, one has to add mouseapi in LINK_LIBRARIES in the file CMakeLists.txt of the level
    3636 * see CMakeLists.txt in MouseAPIExample
     37 *
     38 * MouseAPI: C++ API to access Mouse
     39 * MouseGametype: Enable Mouse Cursor & Prevent that each click kills Player if no spaceship is used
     40 * MouseAPICursor: Internal API which implements cursor. Usable from custom Gametype (not necessary if MouseGametype is used):
     41 *                 add "this->setHUDTemplate("MouseCursor");" in constructor of Gametype. (Or by inheritance)
    3742 */
    3843
     
    96101    bool active = false;
    97102
    98     Ogre::PanelOverlayElement* cursor;
     103    //true => allow ship-controller to get mouse input; Default: false; Gets reset after each transition from deactivated to activated
     104    bool gameInputActivated = false;
     105
    99106
    100107public:
     
    240247     */
    241248    void deactivate();
     249
     250    /*
     251     * allow ship-controller to get mouse input
     252     */
     253    void activateGameInput();
     254
     255    /*
     256     * do not allow ship-controller to get mouse input
     257     * This is the default. This gets set after each transition from deactivated to activated
     258     */
     259    void deactivateGameInput();
    242260};
    243261}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapicursor.cc

    r12363 r12377  
    1010    cursor = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    1111                                                          .createOverlayElement("Panel", "MouseAPI_cursor_" + getUniqueNumberString()));
    12     cursor->setMaterialName(TextureGenerator::getMaterialName(
    13                                       cursorname, Ogre::ColourValue::White));
    14 
     12    updateCursor();
    1513    overlay_->add2D(this->cursor);
    1614    scale(Vector2(0.03,0.03));
     
    2220    if(running)
    2321        MouseAPI::getInstance().deactivate();
     22    if(this->isInitialized())
     23        Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->cursor);
    2424}
    2525
     
    3030    SUPER(MouseAPICursor, XMLPort, xmlelement, mode);
    3131    XMLPortParam(MouseAPICursor, "cursorShape", setCursorName, getCursorName,xmlelement, mode);
    32     //XMLPortParam(MouseAPICursor, "cursorColor", setCursorColor, getCursorColor,xmlelement, mode);//TODO: ColoValue::setAsARGB()
     32    XMLPortParam(MouseAPICursor, "cursorColor", setCursorColor, getCursorColor,xmlelement, mode);
    3333}
    3434
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapicursor.h

    r12363 r12377  
    22#define MOUSEAPICURSOR_H
    33#include <overlays/OrxonoxOverlay.h>
    4 #include "core/CoreIncludes.h"
    5 #include "tools/interfaces/Tickable.h"
    6 #include "overlays/OverlayGroup.h"
     4#include <core/CoreIncludes.h>
     5#include <tools/interfaces/Tickable.h>
    76#include "mouseapi.h"
    8 #include "core/XMLPort.h"
    9 
     7#include <core/XMLPort.h>
    108
    119#if OGRE_VERSION >= 0x010900
     
    1715#endif
    1816
    19 #include "tools/TextureGenerator.h"
    20 #include "util/StringUtils.h"
     17#include <tools/TextureGenerator.h>
     18#include <util/StringUtils.h>
    2119
    2220namespace orxonox{
     
    2523{
    2624private:
     25    //Pointer to the cursor overlay
    2726    Ogre::PanelOverlayElement* cursor;
     27    //Is Cursor activated?
    2828    bool running = false;
     29    //Name of the image-file used as the cursor shape
    2930    std::string cursorname = "cursor.png";
     31    //Color of the cursor
     32    Vector3 color = {1,1,1};
    3033public:
    3134    MouseAPICursor(Context* context);
    3235    ~MouseAPICursor();
     36    //Update cursor position
    3337    virtual void tick(float dt) override;
     38    //XMLPort: ability to set cursor shape & color
    3439    virtual void XMLPort(ticpp::Element &xmlelement, XMLPort::Mode mode) override;
     40    //Update cursol look (shape & color)
     41    inline void updateCursor(){
     42        cursor->setMaterialName(TextureGenerator::getMaterialName(
     43                                                      cursorname, Ogre::ColourValue(color[0],color[1],color[2],1)));
     44    }
    3545    inline void setCursorName(const std::string& name)
    3646    {
    3747        cursorname = name;
    38         cursor->setMaterialName(TextureGenerator::getMaterialName(
    39                                                       cursorname, Ogre::ColourValue::White));
     48        updateCursor();
    4049    }
    4150    inline std::string getCursorName(void) const
    4251    {
    4352        return cursorname;
     53    }
     54    inline void setCursorColor(const Vector3& cl)
     55    {
     56        color = cl;
     57        updateCursor();
     58    }
     59    inline Vector3 getCursorColor(void) const
     60    {
     61        return color;
    4462    }
    4563
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mousegametype.cc

    r12363 r12377  
    88    player_ =nullptr;
    99
     10    //Activate the Mouse Cursor
    1011    this->setHUDTemplate("MouseCursor");
    1112
     
    1415void MouseGametype::start()
    1516{
    16     bool temp = this->bForceSpawn_;
    17     this->bForceSpawn_ = true;
    18 
    19     // Call start for the parent class.
    2017    Gametype::start();
    21 
    22     // Reset the variable.
    23     this->bForceSpawn_ = temp;
    24 
    2518}
    2619
     
    3730{
    3831    assert(player);
    39 
     32    //Only Spawn once
    4033    if(this->player_ == nullptr)
    4134    {
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mousegametype.h

    r12309 r12377  
    11#ifndef MOUSEGAMETYPE_H
    22#define MOUSEGAMETYPE_H
    3 #include "gametypes/Gametype.h"
    4 #include "core/CoreIncludes.h"
    5 #include "infos/PlayerInfo.h"
     3#include <gametypes/Gametype.h>
     4#include <core/CoreIncludes.h>
     5#include <infos/PlayerInfo.h>
    66#include <core/input/InputState.h>
    7 #include "core/GUIManager.h"
     7#include <core/GUIManager.h>
    88
    99namespace orxonox
  • code/branches/MouseAPI_FS19/src/modules/MouseAPIExample/mouseapiexample.h

    r12352 r12377  
    22#define MOUSEAPIEXAMPLE_H
    33
    4 #include "core/XMLPort.h"
    5 #include "MouseAPI/mouseapi.h"
    6 #include "core/CoreIncludes.h"
    7 #include "worldentities/ControllableEntity.h"
     4#include <core/XMLPort.h>
     5#include <MouseAPI/mouseapi.h>
     6#include <core/CoreIncludes.h>
     7#include <worldentities/ControllableEntity.h>
    88#include <list>
    99
Note: See TracChangeset for help on using the changeset viewer.