From: <eg...@us...> - 2006-07-30 19:14:32
|
Revision: 127 Author: egore Date: 2006-07-30 12:14:10 -0700 (Sun, 30 Jul 2006) ViewCVS: http://svn.sourceforge.net/opengate/?rev=127&view=rev Log Message: ----------- Completely rework input system Add working CEGUI menu Note: You will not see anything in the game! Modified Paths: -------------- src/client/ui/Makefile.am src/client/ui/application.cpp src/client/ui/application.h src/client/ui/framelistener.cpp src/client/ui/framelistener.h src/ogre.cfg src/opengate_client.cpp src/resources.cfg Added Paths: ----------- src/client/ui/ActionConfig.cpp src/client/ui/ActionConfig.h src/client/ui/ActionMap.cpp src/client/ui/ActionMap.h Removed Paths: ------------- src/client/ui/avatar.cpp src/client/ui/avatar.h src/client/ui/camera.cpp src/client/ui/camera.h Added: src/client/ui/ActionConfig.cpp =================================================================== --- src/client/ui/ActionConfig.cpp (rev 0) +++ src/client/ui/ActionConfig.cpp 2006-07-30 19:14:10 UTC (rev 127) @@ -0,0 +1,770 @@ +/* +The zlib/libpng License + +Copyright (c) 2005 Phillip Castaneda (pjcast -- www.wreckedgames.com) + +This software is provided 'as-is', without any express or implied warranty. In no event will +the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial +applications, and to alter it and redistribute it freely, subject to the following +restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that + you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ +#include <CEGUI/CEGUIImageset.h> +#include <CEGUI/CEGUISystem.h> +#include <CEGUI/CEGUILogger.h> +#include <CEGUI/CEGUISchemeManager.h> +#include <CEGUI/CEGUIWindowManager.h> +#include <CEGUI/CEGUIWindow.h> +#include <CEGUI/elements/CEGUIMultiColumnList.h> +#include <CEGUI/elements/CEGUIListboxTextItem.h> + +#include "OgreSceneManager.h" +#include "OgreCamera.h" +#include "OgreRoot.h" + +#include "ActionConfig.h" +#include "OISMouse.h" +#include "OISKeyboard.h" +#include "OISJoyStick.h" + +//Some Simple Configurable Action IDs +const int A_JUMP = 1; //All +const int A_FIRE = 2; //All +const int A_MOVE = 3; //Only used for mouse and joy Move +const int A_MOVE_FORWARD = 4; //Keyboard only setting +const int A_MOVE_BACKWARD = 5; //Keyboard only setting +const int A_MOVE_LEFT = 6; //Keyboard only setting +const int A_MOVE_RIGHT = 7; //Keyboard only setting +const int A_LOOK = 8; //Only used for mouse and joy move +const int A_LOOK_UP = 9; //Keyboard only setting +const int A_LOOK_DOWN = 10; //Keyboard only setting +const int A_LOOK_LEFT = 11; //Keyboard only setting +const int A_LOOK_RIGHT = 12; //Keyboard only setting +const int A_CENTER_VIEW = 13; //All + +const int A_TEST_DONE = 14; //Action that happens when Escape Pushed + + +//--------------------------------------------------------------------------------// +ActionConfig::ActionConfig( OIS::Mouse *mouse, OIS::Keyboard *key, OIS::JoyStick *joy, + Ogre::SceneManager* scnMgr ) : + mMouse(mouse), mKey(key), mJoy(joy), mSceneMgr(scnMgr) +{ + //Create an ActionMap instance + actionMap = new OIS::ActionMap(mKey, mMouse, mJoy); + + using namespace CEGUI; + WindowManager& wmgr = WindowManager::getSingleton(); + + oldKeyListener = mKey->getEventCallback(); + oldMouseListener = mMouse->getEventCallback(); + + //One time MultiList Setup + MultiColumnList *listBox; + + //Keyboard list + listBox = (MultiColumnList*)wmgr.getWindow((utf8*)"Keyboard"); + listBox->setSelectionMode(MultiColumnList::RowSingle); + listBox->addColumn("Action", 0, 0.5f); + listBox->addColumn("Trigger", 1, 0.5f); + listBox->subscribeEvent(MultiColumnList::EventSelectionChanged, + Event::Subscriber(&ActionConfig::handleKeyboardSetup, this)); + //Mouse list + listBox = (MultiColumnList*)wmgr.getWindow((utf8*)"Mouse"); + listBox->setSelectionMode(MultiColumnList::RowSingle); + listBox->addColumn("Action", 0, 0.5f); + listBox->addColumn("Trigger", 1, 0.5f); + listBox->subscribeEvent(MultiColumnList::EventSelectionChanged, + Event::Subscriber(&ActionConfig::handleMouseSetup, this)); + //Joystick list + listBox = (MultiColumnList*)wmgr.getWindow((utf8*)"Joystick"); + listBox->setSelectionMode(MultiColumnList::RowSingle); + listBox->addColumn("Action", 0, 0.5f); + listBox->addColumn("Trigger", 1, 0.5f); + listBox->subscribeEvent(MultiColumnList::EventSelectionChanged, + Event::Subscriber(&ActionConfig::handleJoystickSetup, this)); + + //Create some functors for registering with ActionMap + fireBind = new OIS::ActionBind(&ActionConfig::handleFire,this); + jumpBind = new OIS::ActionBind(&ActionConfig::handleJump,this); + moveBind = new OIS::ActionBind(&ActionConfig::handleMove,this); + lookBind = new OIS::ActionBind(&ActionConfig::handleLook,this); + doneBind = new OIS::ActionBind(&ActionConfig::handleDone,this); + + //Reset everything + createScene(); + reset(); +} + +//--------------------------------------------------------------------------------// +ActionConfig::~ActionConfig() +{ + delete fireBind; + delete jumpBind; + delete moveBind; + delete lookBind; + delete doneBind; + + delete actionMap; +} + +//--------------------------------------------------------------------------------// +void ActionConfig::createScene() +{ + //Situate Camera, place guy, etc etc +} + +//--------------------------------------------------------------------------------// +void ActionConfig::reset() +{ + using namespace OIS; + + keyEvents.clear(); + mouseEvents.clear(); + joyEvents.clear(); + + currentAction = ""; + + //This should be saved/loaded from a file.. but, we will just set it up in code + + //Jumping + keyEvents.push_back(DemoActionEventInfo(A_JUMP,KC_SPACE,OIS_Button,jumpBind,"Jump")); + mouseEvents.push_back(DemoActionEventInfo(A_JUMP,MB_Right,OIS_Button,jumpBind,"Jump")); + joyEvents.push_back(DemoActionEventInfo(A_JUMP,1,OIS_Button,jumpBind,"Jump")); + + //Firing + keyEvents.push_back(DemoActionEventInfo(A_FIRE,KC_LCONTROL,OIS_Button,fireBind,"Fire")); + mouseEvents.push_back(DemoActionEventInfo(A_FIRE,MB_Left,OIS_Button,fireBind,"Fire")); + joyEvents.push_back(DemoActionEventInfo(A_FIRE,0,OIS_Button,fireBind,"Fire")); + + //Center View + keyEvents.push_back(DemoActionEventInfo(A_CENTER_VIEW,KC_INSERT,OIS_Button,lookBind,"Center View")); + mouseEvents.push_back(DemoActionEventInfo(A_CENTER_VIEW,MB_Middle,OIS_Button,lookBind,"Center View")); + joyEvents.push_back(DemoActionEventInfo(A_CENTER_VIEW,2,OIS_Button,lookBind,"Center View")); + + //Move - joyStick & Mouse Only + mouseEvents.push_back(DemoActionEventInfo(A_MOVE,-1,OIS_Axis,moveBind,"Move")); + joyEvents.push_back(DemoActionEventInfo(A_MOVE,0,OIS_Axis,moveBind,"Move")); + + //Look - joyStick & Mouse Only + mouseEvents.push_back(DemoActionEventInfo(A_LOOK,0,OIS_Axis,lookBind,"Look")); + joyEvents.push_back(DemoActionEventInfo(A_LOOK,1,OIS_Axis,lookBind,"Look")); + + //Keyboard only movement actions + keyEvents.push_back(DemoActionEventInfo(A_MOVE_FORWARD,KC_W,OIS_Button,moveBind,"Move Forward")); + keyEvents.push_back(DemoActionEventInfo(A_MOVE_BACKWARD,KC_S,OIS_Button,moveBind,"Move Backward")); + keyEvents.push_back(DemoActionEventInfo(A_MOVE_LEFT,KC_A,OIS_Button,moveBind,"Move Left")); + keyEvents.push_back(DemoActionEventInfo(A_MOVE_RIGHT,KC_D,OIS_Button,moveBind,"Move Right")); + + //Keyboard only looking actions + keyEvents.push_back(DemoActionEventInfo(A_LOOK_UP,KC_UP,OIS_Button,lookBind,"Look Up")); + keyEvents.push_back(DemoActionEventInfo(A_LOOK_DOWN,KC_DOWN,OIS_Button,lookBind,"Look Down")); + keyEvents.push_back(DemoActionEventInfo(A_LOOK_LEFT,KC_LEFT,OIS_Button,lookBind,"Look Left")); + keyEvents.push_back(DemoActionEventInfo(A_LOOK_RIGHT,KC_RIGHT,OIS_Button,lookBind,"Look Right")); + + //Setup CEGUI stuff + fillList(); +} + +//--------------------------------------------------------------------------------// +void ActionConfig::fillList() +{ + using namespace CEGUI; + WindowManager& wmgr = WindowManager::getSingleton(); + + //--------- KEYBOARD ACTION LIST --------------// + MultiColumnList *listBox = (MultiColumnList*)wmgr.getWindow((utf8*)"Keyboard"); + listBox->resetList(); + + std::vector<DemoActionEventInfo>::iterator i = keyEvents.begin(), e = keyEvents.end(); + ListboxTextItem* item = 0; + + for( ; i != e; ++i ) + { + int row = listBox->addRow(); + //Action ID Name + item = new ListboxTextItem( i->name.c_str(), 0); + item->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(item, MCLGridRef( row, 0 )); + + //Mapped Column + if( i->trigger != -1 ) + i->li = new ListboxTextItem(mKey->getAsString((OIS::KeyCode)i->trigger), 0); + else + i->li = new ListboxTextItem(" ", 0); + i->li->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(i->li, MCLGridRef( row, 1 )); + } + + //--------- MOUSE ACTION LIST --------------// + listBox = (MultiColumnList*)wmgr.getWindow((utf8*)"Mouse"); + listBox->resetList(); + + i = mouseEvents.begin(); e = mouseEvents.end(); + for( ; i != e; ++i ) + { + int row = listBox->addRow(); + //Action ID Name + item = new ListboxTextItem( i->name.c_str(), 0); + item->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(item, MCLGridRef( row, 0 )); + + //Command Column + i->li = new ListboxTextItem(getAxisButtonName(i->cType, i->trigger), 0); + i->li->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(i->li, MCLGridRef( row, 1 )); + } + + //--------- JOYSTICK ACTION LIST --------------// + listBox = (MultiColumnList *)wmgr.getWindow((utf8*)"Joystick"); + listBox->resetList(); //Clear any old values + + i = joyEvents.begin(); e = joyEvents.end(); + for( ; i != e; ++i ) + { + int row = listBox->addRow(); + //Action ID Name + item = new ListboxTextItem( i->name.c_str(), 0); + item->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(item, MCLGridRef( row, 0 )); + + //Command Column + i->li = new ListboxTextItem(getAxisButtonName(i->cType, i->trigger), 0); + i->li->setTextColours(ColourRect(colour(.5, 0, .3))); + listBox->setItem(i->li, MCLGridRef( row, 1 )); + } + + //Hide for controls that do not exist + if( !mKey ) wmgr.getWindow((utf8*)"Keyboard")->setVisible(false); + if( !mMouse ) wmgr.getWindow((utf8*)"Mouse")->setVisible(false); + if( !mJoy ) wmgr.getWindow((utf8*)"Joystick")->setVisible(false); +} + +//----------------------------------------------------------------// +bool ActionConfig::handleKeyboardSetup(const CEGUI::EventArgs& e) +{ + + using namespace CEGUI; + + MultiColumnList *listBox = (MultiColumnList*)WindowManager::getSingleton().getWindow((utf8*)"Keyboard"); + ListboxItem* item = listBox->getFirstSelectedItem(); + if( !item ) return false; + + //Disable main window.. Start handling Key Events.. Display window prompt + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(false); + mKey->setEventCallback(this); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(true); + + std::ostringstream ss; + ss << "Push key for for \""; + //CEGUI::String op << is unresolved ??? oh well, this works for now + ss << "Push key for for \"" << item->getText().c_str() << "\" Action..." + << "\n\n Push ESCAPE to cancel"; + + WindowManager::getSingleton().getWindow((utf8*)"ActionPromptLable")->setText(ss.str()); + + currentAction = item->getText().c_str(); + + //Then, in our KeyListener.. the next keyevent we have, we assign that as the + //input. Close the window prompt. And update the MultiColumnList + return true; +} + +//----------------------------------------------------------------// +bool ActionConfig::handleMouseSetup(const CEGUI::EventArgs& e) +{ + using namespace CEGUI; + + MultiColumnList *listBox = (MultiColumnList*)WindowManager::getSingleton().getWindow((utf8*)"Mouse"); + ListboxItem* item = listBox->getFirstSelectedItem(); + if( !item ) return false; + + //Disable main window.. Start handling mouse & key Events.. Display window prompt + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(false); + mMouse->setEventCallback(this); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(true); + + std::ostringstream ss; + ss << "Click or move mouse for \"" << item->getText().c_str() << "\" Action..."; + WindowManager::getSingleton().getWindow((utf8*)"ActionPromptLable")->setText(ss.str()); + + currentAction = item->getText().c_str(); + + return true; +} + +//----------------------------------------------------------------// +bool ActionConfig::handleJoystickSetup(const CEGUI::EventArgs& e) +{ + using namespace CEGUI; + + MultiColumnList *listBox = (MultiColumnList*)WindowManager::getSingleton().getWindow((utf8*)"Joystick"); + ListboxItem* item = listBox->getFirstSelectedItem(); + if( !item ) return false; + + //Disable main window.. Start handling mouse & key Events.. Display window prompt + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(false); + mJoy->setEventCallback(this); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(true); + + std::ostringstream ss; + ss << "Click or move joystick for \"" << item->getText().c_str() << "\" Action..."; + WindowManager::getSingleton().getWindow((utf8*)"ActionPromptLable")->setText(ss.str()); + + currentAction = item->getText().c_str(); + + return true; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::keyPressed(const OIS::KeyEvent& arg) +{ + using namespace CEGUI; + // check for ESCAPE - cancel + if( arg.key != OIS::KC_ESCAPE ) + { + //Store Key press and update listbox + DemoActionEventInfo *act = getAction(keyEvents, currentAction); + if(act) + { + act->trigger = arg.key; + act->li->setText(mKey->getAsString((OIS::KeyCode)arg.key)); + ensureNoDuplicate(keyEvents, act); + } + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //Set back old listener + mKey->setEventCallback(oldKeyListener); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::mouseMoved(const OIS::MouseEvent& arg) +{ + using namespace CEGUI; + //Store Mouse Axis and update listbox + DemoActionEventInfo *act = getAction( mouseEvents, currentAction ); + if( act ) + { + act->cType = OIS::OIS_Axis; + if( arg.state.relZ != 0 ) + act->trigger = 1; //This is the mouse wheel + else + act->trigger = 0; //Normal XY mouse axis + + act->li->setText(getAxisButtonName(act->cType, act->trigger)); + ensureNoDuplicate(mouseEvents, act); + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //Set back old listener + mMouse->setEventCallback(oldMouseListener); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id) +{ + using namespace CEGUI; + //Store Mouse Button and update listbox + DemoActionEventInfo *act = getAction( mouseEvents, currentAction ); + if( act ) + { + act->trigger = id; + act->cType = OIS::OIS_Button; + act->li->setText(getAxisButtonName(act->cType, act->trigger)); + ensureNoDuplicate(mouseEvents, act); + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //Set back old listener + mMouse->setEventCallback(oldMouseListener); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::buttonPressed(const OIS::JoyStickEvent &arg, int button) +{ + using namespace CEGUI; + //Store Mouse Button and update listbox + DemoActionEventInfo *act = getAction( joyEvents, currentAction ); + if( act ) + { + act->trigger = button; + act->cType = OIS::OIS_Button; + act->li->setText(getAxisButtonName(act->cType, act->trigger)); + ensureNoDuplicate(joyEvents, act); + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::axisMoved(const OIS::JoyStickEvent &arg, int axis) +{ + using namespace CEGUI; + + DemoActionEventInfo *act = getAction( joyEvents, currentAction ); + if( act ) + { + act->cType = OIS::OIS_Axis; + act->trigger = axis; + act->li->setText(getAxisButtonName(act->cType, act->trigger)); + ensureNoDuplicate(joyEvents, act); + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::povMoved(const OIS::JoyStickEvent &arg, int pov) +{ + using namespace CEGUI; + //Store Mouse Button and update listbox + DemoActionEventInfo *act = getAction( joyEvents, currentAction ); + if( act ) + { + act->cType = OIS::OIS_POV; + act->trigger = pov; + act->li->setText(getAxisButtonName(act->cType, act->trigger)); + ensureNoDuplicate(joyEvents, act); + } + + WindowManager::getSingleton().getWindow((utf8*)"Main")->setEnabled(true); + WindowManager::getSingleton().getWindow((utf8*)"ActionPrompt")->setVisible(false); + + //We return false, because we care not for any more events + return false; +} + +//--------------------------------------------------------------------------------// +DemoActionEventInfo* ActionConfig::getAction( std::vector<DemoActionEventInfo>& list, std::string name ) +{ + std::vector<DemoActionEventInfo>::iterator i = list.begin(), e = list.end(); + for(; i != e; ++i) + if( i->name == name ) return &(*i); + return 0; +} + +//--------------------------------------------------------------------------------// +void ActionConfig::ensureNoDuplicate( std::vector<DemoActionEventInfo>& list, DemoActionEventInfo* act ) +{ + std::vector<DemoActionEventInfo>::iterator i = list.begin(), e = list.end(); + for(; i != e; ++i) + { + if( i->trigger == act->trigger && + i->cType == act->cType && + i->name != act->name ) + { + //Opps.. one dup existed.. clear it + i->trigger = -1; + i->li->setText(""); + } + } +} + +//--------------------------------------------------------------------------------// +std::string ActionConfig::getAxisButtonName( OIS::ComponentType type, int trigger ) +{ + std::ostringstream ss; + + if( trigger != -1 ) + { + if( type == OIS::OIS_Button ) + ss << "Button "; + else if( type == OIS::OIS_Axis ) + ss << "Axis "; + else if( type == OIS::OIS_POV ) + ss << "POV "; + ss << trigger; + return ss.str(); + } + + return " "; +} + +//--------------------------------------------------------------------------------// +void ActionConfig::startTest() +{ + actionMap->reset(); + + //Configure the action map for each device + std::vector<DemoActionEventInfo>::iterator i = keyEvents.begin(), e = keyEvents.end(); + for( ; i != e; ++i ) + actionMap->addKeyboardAction( i->id, i->trigger, i->bound ); + + i = mouseEvents.begin(); e = mouseEvents.end(); + for( ; i != e; ++i ) + actionMap->addMouseAction( i->id, i->trigger, i->cType, i->bound ); + + i = joyEvents.begin(); e = joyEvents.end(); + for( ; i != e; ++i ) + actionMap->addJoyStickAction( i->id, i->trigger, i->cType, i->bound); + + //Setup a Key Event for exiting test - Escape Key + actionMap->addKeyboardAction( A_TEST_DONE, OIS::KC_ESCAPE, doneBind ); + + //Enable it.. this disables any registered buffered callbacks + actionMap->setEnabled(true); + + //Hide CEGUI Window + CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Main")->setVisible(false); + CEGUI::System::getSingleton().setDefaultMouseCursor(0); + + Ogre::Root::getSingleton().addFrameListener(this); + + mMoveScale = 1.0f; + mRotXScale = 0.0f; + mRotYScale = 0.0f; +} + +//--------------------------------------------------------------------------------// +bool ActionConfig::frameStarted(const Ogre::FrameEvent& evt) +{ + Ogre::Camera *cam = mSceneMgr->getCamera("PlayerCam"); + + // Move about 100 units per second, + mMoveScale = 100 * evt.timeSinceLastFrame; + + cam->yaw(Ogre::Degree(mRotXScale)); + cam->pitch(Ogre::Degree(mRotYScale)); + cam->moveRelative(mTranslateVector); + return true; +} + +//--------------------------------------------------------------------------------// +void ActionConfig::handleJump( const OIS::ActionMapArg& arg ) +{ + //Don't really care if axis or not. we only want to do this on keydown & not on keyup + //if( arg.flags & OIS::OIS::ActionMapArg::AM_Button ) + //{ + // if( arg.flags & OIS::OIS::ActionMapArg::AM_ButtonDown ) + // do fire + // return; + //} + + //do Fire +} + +//--------------------------------------------------------------------------------// +void ActionConfig::handleFire( const OIS::ActionMapArg& arg ) +{ + //Don't really care if axis or not.. but, we only want to do this once + //if( arg.flags & OIS::OIS::ActionMapArg::AM_Button ) + //{ + // if( arg.flags & OIS::ActionMapArg::AM_ButtonDown ) + // do fire + // return; + //} + + //do Fire +} + +//--------------------------------------------------------------------------------// +void ActionConfig::handleMove( const OIS::ActionMapArg& arg ) +{ + switch( arg.ActionID ) + { + //Axis Event + case A_MOVE: + { + //User set button as move event - just ignore + if( arg.component->cType == OIS::OIS_Button ) + { + break; + } + else if( arg.component->cType == OIS::OIS_Axis ) + { + const OIS::Axis* axis = static_cast<const OIS::Axis*>(arg.component); + if( axis->absOnly == false ) + { + //Not an absolute only axis + mSceneMgr->getCamera("PlayerCam")->moveRelative( + Ogre::Vector3( axis->relX * 0.13f, //Move left/right + axis->relZ * 0.1f, //Up/Down + axis->relY * 0.13f ) ); //F/B + } + else + { + //Is an absolute only axis + //Up/Down + mTranslateVector.y = mMoveScale * axis->abZ/(float)OIS::JoyStick::MAX_AXIS; + //Move left/right + mTranslateVector.x = mMoveScale * axis->abX/(float)OIS::JoyStick::MAX_AXIS; + //Move forward/back + mTranslateVector.z = -mMoveScale * axis->abY/(float)OIS::JoyStick::MAX_AXIS; + } + } + else if( arg.component->cType == OIS::OIS_POV ) + { + using namespace OIS; + const Pov* pov = static_cast<const Pov*>(arg.component); + + if( pov->direction & Pov::North ) //Going up + mTranslateVector.z = -mMoveScale; + else if( pov->direction & Pov::South ) //Going down + mTranslateVector.z = mMoveScale; + + if( pov->direction & Pov::East ) //Going right + mTranslateVector.x = mMoveScale; + else if( pov->direction & Pov::West ) //Going left + mTranslateVector.x = -mMoveScale; + + if( pov->direction == Pov::Centered ) //stopped/centered out + mTranslateVector.x = mTranslateVector.z = 0; + } + break; + } + //Moves forward - Key event only + case A_MOVE_FORWARD: + if( arg.component->cType == OIS::OIS_Button ) + { + if( static_cast<const OIS::Button*>(arg.component)->pushed ) + mTranslateVector.z = -mMoveScale; + else + mTranslateVector.z = 0; + } + break; + //Moves Backwards - Key event only + case A_MOVE_BACKWARD: + if( arg.component->cType == OIS::OIS_Button ) + { + if( static_cast<const OIS::Button*>(arg.component)->pushed ) + mTranslateVector.z = mMoveScale; + else + mTranslateVector.z = 0; + } + break; + //Strafe Left - Key event only + case A_MOVE_LEFT: + if( arg.component->cType == OIS::OIS_Button ) + { + if( static_cast<const OIS::Button*>(arg.component)->pushed ) + mTranslateVector.x = -mMoveScale; + else + mTranslateVector.x = 0; + } + break; + //Strafe Right - Key event only + case A_MOVE_RIGHT: + if( arg.component->cType == OIS::OIS_Button ) + { + if( static_cast<const OIS::Button*>(arg.component)->pushed ) + mTranslateVector.x = mMoveScale; + else + mTranslateVector.x = 0; + } + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------// +void ActionConfig::handleLook( const OIS::ActionMapArg& arg ) +{ + //Look - handles the camera looking.. Could just as well control + //the players view instead + switch( arg.ActionID ) + { + //Axis Event - hopefully + case A_LOOK: + { + //User set button as look axis - just ignore + if( arg.component->cType == OIS::OIS_Button ) + { + break; + } + else if( arg.component->cType == OIS::OIS_Axis ) + { + const OIS::Axis* axis = static_cast<const OIS::Axis*>(arg.component); + if( axis->absOnly == false ) + { + //Move using relative Axis + Ogre::Camera *cam = mSceneMgr->getCamera("PlayerCam"); + + cam->yaw(Ogre::Radian(Ogre::Degree(-axis->relX * 0.13f))); + cam->pitch(Ogre::Radian(Ogre::Degree(-axis->relY * 0.13f))); + } + else + { + //absolute only axis + mRotXScale = -axis->abX/OIS::JoyStick::MAX_AXIS * 0.05; + mRotYScale = -axis->abY/OIS::JoyStick::MAX_AXIS * 0.01; + } + } + break; + } + //Tilt View Up - Key Event only + case A_LOOK_UP: + break; + //Tilt view Down - Key Event only + case A_LOOK_DOWN: + break; + //Turn Left - Key Event only + case A_LOOK_LEFT: + break; + //Turn Right - Key Event only + case A_LOOK_RIGHT: + break; + //Centers/levels out - Don't care if button or axes + case A_CENTER_VIEW: + break; + default: break; + } +} + +//--------------------------------------------------------------------------------// +void ActionConfig::handleDone( const OIS::ActionMapArg& arg ) +{ + //ESCAPE Key event - only do once, though, they keyup should never reach us + //anyway + if( static_cast<const OIS::Button*>(arg.component)->pushed ) + { + //Stop the test, and reset listeners + actionMap->setEnabled(false); + + //Restore the old listeners.. which were replaced with the ActionMap + mKey->setEventCallback(oldKeyListener); + mMouse->setEventCallback(oldMouseListener); + + //Show CEGUI Window + CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"Main")->setVisible(true); + CEGUI::System::getSingleton().setDefaultMouseCursor((CEGUI::utf8*)"WindowsLook", + (CEGUI::utf8*)"MouseArrow"); + + Ogre::Root::getSingleton().removeFrameListener(this); + } +} Property changes on: src/client/ui/ActionConfig.cpp ___________________________________________________________________ Name: svn:mime-type + text/x-c++src Name: svn:eol-style + native Added: src/client/ui/ActionConfig.h =================================================================== --- src/client/ui/ActionConfig.h (rev 0) +++ src/client/ui/ActionConfig.h 2006-07-30 19:14:10 UTC (rev 127) @@ -0,0 +1,162 @@ +/* +The zlib/libpng License + +Copyright (c) 2005 Phillip Castaneda (pjcast -- www.wreckedgames.com) + +This software is provided 'as-is', without any express or implied warranty. In no event will +the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial +applications, and to alter it and redistribute it freely, subject to the following +restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that + you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef ActionConfig_Header +#define ActionConfig_Header +#include <CEGUI/CEGUIForwardRefs.h> + +#include "OISPrereqs.h" +#include "OISEvents.h" + +#include "OgrePrerequisites.h" +#include "OgreFrameListener.h" +#include "OgreVector3.h" + +#include "ActionMap.h" + +//Simple utility structure that extends the one from ActionMap.. As we want to store +//some additional info for configuring things +struct DemoActionEventInfo : public OIS::ActionEventInfo +{ + //! Constructor + DemoActionEventInfo(int iID,int iTrigger,OIS::ComponentType type,OIS::ActionBind* pBind,const std::string& sName ) : + ActionEventInfo(iID,iTrigger,type,pBind), name(sName), + li(0) {}; + + //! Friendly text name of the Action + std::string name; + //! The listboxitem that the Mapped Action will be displayed in + CEGUI::ListboxTextItem* li; +}; + +/** + This class is kinda a one stop class right now. This class handles setup, config, + and testing of ActionMap. Ideally, the actionmap should be loaded from a file. But, + for clarity, and less parsing code, it is setup via code. And also, the ActionMap class + could be configured from here, but should be passed back to wherever you want to + implement it at. + + This class inheirits from The three listeners for setting up the ActionMap + action triggers. + + And the framelistener is used for actionmap testing.. for movements +*/ +class ActionConfig : public OIS::KeyListener, public OIS::MouseListener, + public OIS::JoyStickListener, public Ogre::FrameListener +{ +public: + ActionConfig( OIS::Mouse *mouse, OIS::Keyboard *key, OIS::JoyStick *joy, + Ogre::SceneManager* scnMgr ); + ~ActionConfig(); + + //Resets everything back to default - lists, actions, scene + void reset(); + + //Go into test mode + void startTest(); + + //cegui event handlers + bool handleKeyboardSetup(const CEGUI::EventArgs& e); + bool handleMouseSetup(const CEGUI::EventArgs& e); + bool handleJoystickSetup(const CEGUI::EventArgs& e); + + //Example Methods used for recieveing Action Events + void handleJump( const OIS::ActionMapArg& ); + void handleFire( const OIS::ActionMapArg& ); + void handleMove( const OIS::ActionMapArg& ); + void handleLook( const OIS::ActionMapArg& ); //Handle Look and Center Actions + void handleDone( const OIS::ActionMapArg& ); + + //We only listen when we are configuring an action, and restore old listener + bool keyPressed(const OIS::KeyEvent& arg); + bool mouseMoved(const OIS::MouseEvent& arg); + bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID); + bool buttonPressed(const OIS::JoyStickEvent &arg, int button); + bool axisMoved(const OIS::JoyStickEvent &arg, int axis ); + bool povMoved( const OIS::JoyStickEvent &arg, int pov ); + + //We ignore these + bool keyReleased(const OIS::KeyEvent&) {return false;} + bool mouseReleased(const OIS::MouseEvent&, OIS::MouseButtonID) {return false;} + bool buttonReleased(const OIS::JoyStickEvent &, int) {return false;} + + //Process frame events + bool frameStarted(const Ogre::FrameEvent& evt); + +protected: + //Internal helper methods + void fillList(); + void createScene(); + + //Returns a pointer to an actionevent based on the sent name + DemoActionEventInfo* getAction( std::vector<DemoActionEventInfo>& list, + std::string name ); + + //If an input event exists than remove that one + void ensureNoDuplicate( std::vector<DemoActionEventInfo>& list, + DemoActionEventInfo* act ); + + //Convert params into a string representing a button/axes number or " " + std::string getAxisButtonName( OIS::ComponentType type, int trigger ); + + //Keep a hold of some devices + OIS::Mouse *mMouse; + OIS::Keyboard *mKey; + OIS::JoyStick *mJoy; + + //Keep old listeners stored when we start messing with the current one + OIS::KeyListener* oldKeyListener; + OIS::MouseListener* oldMouseListener; + + //We keep seperate lists for each tyoe of device we want to support.. + //We then assign a default button, or -1 if it will be blank - to allow + //for assignment later, for each action + std::vector<DemoActionEventInfo> keyEvents; + std::vector<DemoActionEventInfo> mouseEvents; + std::vector<DemoActionEventInfo> joyEvents; + + //Use this to ensure that the same joystick type that was used previously, + //is still the one connected here + std::string joyName; + + //Represents the row (Action) that the user clicked.. and is configuring + std::string currentAction; + + //Our ActionMap instance + OIS::ActionMap* actionMap; + + //Functors for registering with ActionMap + OIS::ActionBind* fireBind; + OIS::ActionBind* jumpBind; + OIS::ActionBind* moveBind; + OIS::ActionBind* lookBind; + OIS::ActionBind* doneBind; + + //Ogre Scene Stuff - For testing the controls + Ogre::SceneManager* mSceneMgr; + Ogre::Vector3 mTranslateVector; + float mMoveScale; + float mRotXScale; + float mRotYScale; +}; + +#endif Property changes on: src/client/ui/ActionConfig.h ___________________________________________________________________ Name: svn:mime-type + text/x-c++hdr Name: svn:eol-style + native Added: src/client/ui/ActionMap.cpp =================================================================== --- src/client/ui/ActionMap.cpp (rev 0) +++ src/client/ui/ActionMap.cpp 2006-07-30 19:14:10 UTC (rev 127) @@ -0,0 +1,200 @@ +#include "ActionMap.h" +#include "OISMouse.h" +#include "OISKeyboard.h" +#include "OISJoyStick.h" + +using namespace OIS; + +//---------------------------------------------------------------------------// +ActionMap::~ActionMap() +{ + setEnabled(false); +} + +//---------------------------------------------------------------------------// +void ActionMap::setCallbacks( KeyListener* kl, MouseListener* ml ) +{ + keyCallback = kl; + mouseCallback = ml; +} + +//---------------------------------------------------------------------------// +void ActionMap::setEnabled( bool enabled ) +{ + if( enabled ) + { + if( mKey ) mKey->setEventCallback( this ); + if( mMouse ) mMouse->setEventCallback( this ); + if( mJoy ) mJoy->setEventCallback( this ); + } + else + { + if( mKey ) mKey->setEventCallback(0); + if( mMouse ) mMouse->setEventCallback(0); + if( mJoy ) mJoy->setEventCallback(0); + } +} + +//---------------------------------------------------------------------------// +void ActionMap::reset() +{ + mouseButtonEvents.clear(); + mouseXY.setProperties(-1, -1, OIS_Button, 0); + mouseZ.setProperties(-1, -1, OIS_Button, 0); + + joyButtonEvents.clear(); + joyAxisEvents.clear(); +} + +//---------------------------------------------------------------------------// +void ActionMap::addKeyboardAction(int iID, int iTrigger, ActionBind *pBind) +{ + keyEvents[iTrigger] = ActionEventInfo(iID, iTrigger, OIS_Button, pBind); +} + +//---------------------------------------------------------------------------// +void ActionMap::addMouseAction(int iID, int iTrigger, ComponentType type, ActionBind *pBind) +{ + if( type == OIS_Axis ) + { + if( iTrigger == 0 ) //XY Axis + mouseXY.setProperties( iID, iTrigger, type, pBind ); + else //Z Axis + mouseZ.setProperties( iID, iTrigger, type, pBind ); + } + else + mouseButtonEvents[iTrigger] = ActionEventInfo(iID, iTrigger, type, pBind); +} + +//---------------------------------------------------------------------------// +void ActionMap::addJoyStickAction(int iID, int iTrigger, ComponentType type, ActionBind *pBind) +{ + if( type == OIS_Button ) + joyButtonEvents[iTrigger] = ActionEventInfo(iID, iTrigger, type, pBind); + else if( type == OIS_Axis ) + joyAxisEvents[iTrigger] = ActionEventInfo(iID, iTrigger, type, pBind); + else if( type == OIS_POV ) + joyPovEvents[iTrigger] = ActionEventInfo(iID, iTrigger, type, pBind); +} + +//---------------------------------------------------------------------------// +bool ActionMap::keyPressed(const KeyEvent& arg) +{ + ActionList::iterator i = keyEvents.find(arg.key); + if( i != keyEvents.end() ) + i->second.bound->callMethod( ActionMapArg(i->second.id,&Button(true)) ); + + if( keyCallback ) + return keyCallback->keyPressed(arg); + else + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::keyReleased(const KeyEvent& arg) +{ + ActionList::iterator i = keyEvents.find(arg.key); + if( i != keyEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Button(false))); + + if( keyCallback ) + return keyCallback->keyReleased(arg); + else + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::mouseMoved(const MouseEvent& arg) +{ + if( arg.state.relZ == 0 ) //XY Axis + { + if( mouseXY.trigger != -1 ) + { + Axis axis(arg.state); + axis.abZ = axis.relZ = 0; //Zero out Z axis, as that is seperate + mouseXY.bound->callMethod(ActionMapArg(mouseXY.id,&axis)); + } + } + else //Z Axis + { + if( mouseZ.trigger != -1 ) + { + Axis axis; + axis.abZ = arg.state.abZ; + axis.relZ = arg.state.relZ; + mouseZ.bound->callMethod(ActionMapArg(mouseZ.id,&axis)); + } + } + + if( mouseCallback ) + return mouseCallback->mouseMoved(arg); + else + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::mousePressed(const MouseEvent& arg, MouseButtonID button) +{ + ActionList::iterator i = mouseButtonEvents.find(button); + if( i != mouseButtonEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Button(true))); + + if( mouseCallback ) + return mouseCallback->mousePressed(arg, button); + else + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::mouseReleased(const MouseEvent& arg, MouseButtonID button) +{ + ActionList::iterator i = mouseButtonEvents.find(button); + if( i != mouseButtonEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Button(false))); + + if( mouseCallback ) + return mouseCallback->mouseReleased(arg, button); + else + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::axisMoved(const JoyStickEvent &arg, int axis) +{ + ActionList::iterator i = joyAxisEvents.find(axis); + if( i != joyAxisEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id, + &arg.state.mAxes[axis])); + + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::povMoved(const JoyStickEvent &arg, int pov) +{ + ActionList::iterator i = joyPovEvents.find(pov); + if( i != joyPovEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Pov(arg.state.mPOV[pov]))); + + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::buttonPressed(const JoyStickEvent &arg, int button) +{ + ActionList::iterator i = joyButtonEvents.find(button); + if( i != joyButtonEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Button(true))); + + return true; +} + +//---------------------------------------------------------------------------// +bool ActionMap::buttonReleased(const JoyStickEvent& arg, int button) +{ + ActionList::iterator i = joyButtonEvents.find(button); + if( i != joyButtonEvents.end() ) + i->second.bound->callMethod(ActionMapArg(i->second.id,&Button(false))); + + return true; +} Property changes on: src/client/ui/ActionMap.cpp ___________________________________________________________________ Name: svn:mime-type + text/x-c++src Name: svn:eol-style + native Added: src/client/ui/ActionMap.h =================================================================== --- src/client/ui/ActionMap.h (rev 0) +++ src/client/ui/ActionMap.h 2006-07-30 19:14:10 UTC (rev 127) @@ -0,0 +1,281 @@ +/* +The zlib/libpng License + +Copyright (c) 2005 Phillip Castaneda (pjcast -- www.wreckedgames.com) + +This software is provided 'as-is', without any express or implied warranty. In no event will +the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial +applications, and to alter it and redistribute it freely, subject to the following +restrictions: + + 1. The origin of this software must not be misrepresented; you must not claim that + you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef _OIS_ACTIONMAPHEADERS_ +#define _OIS_ACTIONMAPHEADERS_ +#include "OISPrereqs.h" +#include "OISJoyStick.h" +#include "OISMouse.h" +#include "OISKeyboard.h" + +namespace OIS +{ + //*********** Base binding class ***************** + template <typename returnT, typename args> + class IBind + { + public: + virtual returnT operator()(args) const = 0; + virtual ~IBind() {} + }; + + //******** Implement of binding for member funtions + template <class T, typename returnT, typename Args> + class memberBind : public IBind<returnT, Args> + { + public: + typedef returnT(T::*F)(Args); + memberBind(F function, T* object) : + mFunction(function), mObject(object) {} + + virtual returnT operator()(Args args) const {return (mObject->*mFunction)(args);} + protected: + F mFunction; + T* mObject; + }; + + //***** Generic Binder (WIP) ************** + template <typename returnT, typename Args> + class Binder + { + Binder() : mObject(0) {} + public: + ~Binder() { delete mObject; } + + //Member Binding + template <class T> + Binder(returnT (T::*function)(Args), T* object) { + mObject = new memberBind<T, returnT, Args>(function, object); + } + //Todo regular function binding + + returnT callMethod(Args args) const { return (*mObject)(args); } + + protected: + IBind<returnT, Args>* mObject; + }; + + /** + Class used as parameter for handing out ActionMap Events + */ + class ActionMapArg + { + public: + ActionMapArg(int id, const Component* comp) : + ActionID(id), component(comp) {}; + + //! The ActionID + int ActionID; + + //! The component (button, Axis, POV, etc) + const Component* component; + }; + + //! function pointer that returns void and takes 'const ActionMapArg&' param + typedef Binder<void, const ActionMapArg&> ActionBind; + + /** + Utility structure used for storing event info + */ + struct ActionEventInfo + { + //! Default constructor + ActionEventInfo() : id(0), trigger(-1), cType(OIS_Button), bound(0) {}; + + /** + @remarks + Constructor + @param iID + ActionID + @param iTrigger + Trigger - KeyCode, Axis num, etc + @param bButton + True - button; false - other (axis) + @param pBind + Function pointer + */ + ActionEventInfo( int iID, int iTrigger, ComponentType type, ActionBind* pBind ) : + id(iID), trigger(iTrigger), cType(type), bound(pBind) {}; + + //! Utility method for setting up members + void setProperties( int iID, int iTrigger, ComponentType type, ActionBind* pBind ) + { + id = iID; + trigger = iTrigger; + cType = type; + bound = pBind; + } + + //! Action ID Numbercd + int id; + //! KeyCode/Axis number/Button number/etc + int trigger; + //! Type of component + ComponentType cType; + //! A function pointer for event callback + ActionBind* bound; + }; + + /** + Utility class for dispatching events based on Actions. + @Note Buttons get two events for pushed/released. + @See ActionMapArg for info on whether or not the button is pushed or not + */ + class ActionMap : public KeyListener, public MouseListener, public JoyStickListener + { + ActionMap() {}; + public: + /** + @remarks + Constructs ActionMap class + @param kb + Pointer to a keyboard device for events. Or null for no key device + @param mouse + Pointer to a mouse device for events. Or null for no mouse device + @param joy + Pointer to a joystick device for events. Or null for no joy device + */ + ActionMap( Keyboard* kb, Mouse* mouse, JoyStick* joy ) : + mKey(kb), mMouse(mouse), mJoy(joy), + keyCallback(0), mouseCallback(0) {}; + + virtual ~ActionMap(); + + /** + @remarks + If you want key and/or mouse events to also 'pass' through back to + your listener, pass in your listeners here + @param kl + KeyListener + @param ml + MouseListener + */ + void setCallbacks( KeyListener* kl, MouseListener* ml ); + + /** + @remarks + If you want key and/or mouse events to also 'pass' through back to + your listener, pass in your listeners here. Setting this true + will replace your listeners (of the valid devices you passed in earlier). + If you want to continue getting your own events too, refer to setCallbacks + @param enabled + true - start recieving/passing events. False - stop + */ + void setEnabled( bool enabled ); + + /** + @remarks + Clears out all event lists + */ + void reset(); + + /** + @remarks + Add an event for keyboard device + @param iID + ActionID number you want to pass through + @param iTrigger + The actual trigger value (KeyCode, Button number, Axis number). Must be unique for each button/axis of the same device (i.e. cannot register + two events for key '2'). + @param pBind + A valid function pointer used to call for event + */ + void addKeyboardAction(int iID, int iTrigger, ActionBind *pBind); + + /** + @remarks + Add an event for mouse device + @param iID + ActionID number you want to pass through + @param iTrigger + The actual trigger value (KeyCode, Button number, Axis number). Must be unique for each button/axis of the same device (i.e. cannot register + two events for button '0' left mouse). + @param type + type of component + @param pBind + A valid function pointer used to call for event + */ + void addMouseAction(int iID, int iTrigger, ComponentType type, ActionBind *pBind); + + /** + @remarks + Add an event for joystick device + @param iID + ActionID number you want to pass through + @param iTrigger + The actual trigger value (KeyCode, Button number, Axis number). Must be unique for each button/axis of the same device (i.e. cannot register + two events for button '0'). + @param type + type of component + @param pBind + A valid function pointer used to call for event + */ + void addJoyStickAction(int iID, int iTrigger, ComponentType type, ActionBind *pBind); + + protected: + //------ Buffered Device events ------------------------ + bool keyPressed(const KeyEvent& arg); + bool keyReleased(const KeyEvent&); + + bool mouseMoved(const MouseEvent& arg); + bool mousePressed(const MouseEvent& arg, MouseButtonID); + bool mouseReleased(const MouseEvent&, MouseButtonID); + + bool axisMoved(const JoyStickEvent &arg, int axis); + bool povMoved(const JoyStickEvent &arg, int pov); + bool buttonPressed(const JoyStickEvent &arg, int button); + bool buttonReleased(const JoyStickEvent&, int); + + //! Typedef for easy iteration int = Trigger number + typedef std::map<int, ActionEventInfo> ActionList; + + //! Keyboard events + ActionList keyEvents; + + //! Mouse button events + ActionList mouseButtonEvents; + //! Mouse XY axes events + ActionEventInfo mouseXY; + //! Mouse Z (wheel) axis events + ActionEventInfo mouseZ; + + //! Joy button events + ActionList joyButtonEvents; + //! Joy axes events + ActionList joyAxisEvents; + //! Joy POV events + ActionList joyPovEvents; + + //! Keyboard device + Keyboard* mKey; + //! Mouse device + Mouse* mMouse; + //! JoyStick device + JoyStick* mJoy; + + //! Keyboard callback pointer used to pass through events + KeyListener* keyCallback; + //! Mouse callback pointer used to pass through events + MouseListener* mouseCallback; + }; +} +#endif Property changes on: src/client/ui/ActionMap.h ___________________________________________________________________ Name: svn:mime-type + text/x-c++hdr Name: svn:eol-style + native Modified: src/client/ui/Makefile.am =================================================================== --- src/client/ui/Makefile.am 2006-07-30 18:46:33 UTC (rev 126) +++ src/client/ui/Makefile.am 2006-07-30 19:14:10 UTC (rev 127) @@ -1,6 +1,6 @@ INCLUDES = $(all_includes) METASOURCES = AUTO noinst_LTLIBRARIES = libopengate-ui.la -libopengate_ui_la_SOURCES = application.cpp camera.cpp framelistener.cpp \ - avatar.cpp -noinst_HEADERS = application.h camera.h framelistener.h avatar.h +libopengate_ui_la_SOURCES = application.cpp framelistener.cpp ActionConfig.cpp \ + ActionMap.cpp +noinst_HEADERS = application.h framelistener.h ActionConfig.h ActionMap.h Modified: src/client/ui/application.cpp =================================================================== --- src/client/ui/application.cpp 2006-07-30 18:46:33 UTC (rev 126) +++ src/client/ui/application.cpp 2006-07-30 19:14:10 UTC (rev 127) @@ -22,40 +22,26 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <OgreNode.h> -#include <OgreEntity.h> -#include <OgreTextureManager.h> -#include <OgreViewport.h> -#include <CEGUI/elements/CEGUIPushButton.h> #include "application.h" -OpengateApp::OpengateApp() : mGUIRenderer(NULL), mGUISystem(NULL), mEditorGuiSheet(NULL){ - mFrameListener = NULL; - mRoot = NULL; +#include <CEGUI/CEGUISystem.h> +#include <CEGUI/CEGUILogger.h> +#include <CEGUI/CEGUISchemeManager.h> +#include <CEGUI/CEGUIWindowManager.h> +#include <CEGUI/CEGUIWindow.h> +#include <CEGUI/elements/CEGUIPushButton.h> + +OpengateApp::OpengateApp() : mGUIRenderer(0), mGUISystem(0), actionConfig(0) { + mFrameListener = 0; + mRoot = 0; } OpengateApp::~OpengateApp() { - if (mGamestate) { - delete mGamestate; - } - if (mEditorGuiSheet) { - CEGUI::WindowManager::getSingleton().destroyWindow(mEditorGuiSheet); - } - if (mGUISystem) { - delete mGUISystem; - } - if (mGUIRenderer) { - delete mGUIRenderer; - } - if (mFrameListener) { - delete mFrameListener; - } - if (mCamera) { - delete mCamera; - } - if (mRoot) { - delete mRoot; - } + delete actionConfig; + delete mGUISystem; + delete mGUIRenderer; + delete mFrameListener; + delete mRoot; } void OpengateApp::go(void) { @@ -70,13 +56,15 @@ bool OpengateApp::setup(void) { mRoot = new Ogre::Root(); - + setupResources(); if (!configure()) return false; chooseSceneManager(); + createCamera(); + createViewports(); // Set default mipmap level (NB some APIs ignore this) Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); @@ -85,26 +73,18 @@ createResourceListener(); // Load resources loadResources(); - // Create the scene createScene(); - - mCamera = new Camera(mSceneMgr, mWindow, mAvatarNode, true); - mGamestate = new Gamestate(); - setupEventHandlers(); - createFrameListener(); - setupEventHandlers(); - return true; - } bool OpengateApp::configure(void) { // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg - if(mRoot->restoreConfig()) { + //mRoot->showConfigDialog() + if (mRoot->restoreConfig()) { // If returned true, user clicked OK so initialise // Here we choose to let the system create a default rendering window by passing 'true' mWindow = mRoot->initialise(true); @@ -115,52 +95,57 @@ } void OpengateApp::chooseSceneManager(void) { - // Get the SceneManager, in this case a generic one + // Create the SceneManager, in this case a generic one mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "ExampleSMInstance"); } -void OpengateApp::createScene() { +void OpengateApp::createScene(void) { // create an ambient light for the scene mSceneMgr->setAmbientLight(Ogre::ColourValue( 1, 1, 1 )); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); - // setup GUI system - mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr); + Ogre::Light* l = mSceneMgr->createLight("MainLight"); + l->setPosition(20,80,50); + + Ogre::Entity* ent = mSceneMgr->createEntity( "Octavius Apteryx", "Ships/Octavius/Apteryx/octavius_apteryx.mesh" ); + mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); + + //--------------- setup GUI system ---------------------// + mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, + false, 3000, mSceneMgr); mGUISystem = new CEGUI::System(mGUIRenderer); - CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme"); - mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); + CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative); + CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*) + "WindowsLook.scheme"); + mGUISystem->setDefaultMouseCursor((CEGUI::utf8*)"WindowsLook",(CEGUI::utf8*) + "MouseArrow"); + mGUISystem->injectMousePosition(0,0); mGUISystem->setDefaultFont((CEGUI::utf8*)"Tahoma-12"); - mEditorGuiSheet= CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"Sheet"); - mGUISystem->setGUISheet(mEditorGuiSheet); CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative); - CEGUI::PushButton* quitButton = (CEGUI::PushButton*)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Quit"); - mEditorGuiSheet->addChildWindow(quitButton); - quitButton->setPosition(CEGUI::Point(0.35f, 0.45f)); - quitButton->setSize(CEGUI::Size(0.3f, 0.1f)); - quitButton->setText("Quit"); - - // Create an entity - Ogre::Entity* ent = mSceneMgr->createEntity( "Octavius Apteryx", "Ships/Octavius/Apteryx/octavius_apteryx.mesh" ); - mAvatarNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); - mAvatarNode->attachObject(ent); - mAvatarNode->setPosition(Ogre::Vector3(0,0,30)); - mAvatarNode->rotate(Ogre::Vector3(0.,1.,0.), Ogre::Degree(-90)); - mAvatar = new Avatar(mAvatarNode); - - //ent = mSceneMgr->createEntity( "Quantar Storm", "Ships/Quantar/Storm/quantar_storm.mesh" ); - //Ogre::SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(); - //node2->attachObject(ent); + CEGUI::Window* sheet = CEGUI::WindowManager::getSingleton().loadWindowLayout + ((CEGUI::utf8*)"ActionMapping.layout"); + mGUISystem->setGUISheet(sheet); + //Register our handlers for the three bottom buttons + setupEventHandlers(); } void OpengateApp::destroyScene(void) { - + } - + void OpengateApp::createFrameListener(void) { - mFrameListener = new OpengateListener(mWindow, mCamera, mAvatar, mGUIRenderer, mGamestate); - mFrameListener->showDebugOverlay(true); + mFrameListener= new OpengateListener(mWindow, mCamera, mGUIRenderer); mRoot->addFrameListener(mFrameListener); + + //Get Mouse & Keyboard, and create joystick if present + OpengateListener* gUI = static_cast<OpengateListener*>(mFrameListener); + OIS::Mouse* mouse = gUI->getMouse(); + OIS::Keyboard* kb = gUI->getKeyboard(); + OIS::JoyStick* joy = gUI->getJoyStick(); + + //Utility class for configuring, & testing ActionMap + actionConfig = new ActionConfig( mouse, kb, joy, mSceneMgr ); } void OpengateApp::setupResources(void) { @@ -187,8 +172,7 @@ } } -void OpengateApp::createResourceListener(void) -{ +void OpengateApp::createResourceListener(void) { } @@ -199,10 +183,50 @@ void OpengateApp::setupEventHandlers(void) { CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton(); - wmgr.getWindow((CEGUI::utf8*)"Quit")->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&OpengateApp::handleQuit, this)); + wmgr.getWindow((CEGUI::utf8*)"Test")->subscribeEvent( + CEGUI::PushButton::EventClicked, + CEGUI::Event::Subscriber(&OpengateApp::handleTest, this)); + wmgr.getWindow((CEGUI::utf8*)"Reset")->subscribeEvent( + CEGUI::PushButton::EventClicked, + CEGUI::Event::Subscriber(&OpengateApp::handleReset, this)); + wmgr.getWindow((CEGUI::utf8*)"Quit")->subscribeEvent( + CEGUI::PushButton::EventClicked, + CEGUI::Event::Subscriber(&OpengateApp::handleQuit, this)); } +bool OpengateApp::handleTest(const CEGUI::EventArgs& e) { + actionConfig->startTest(); + return true; +} + +bool OpengateApp::handleReset(const CEGUI::EventArgs& e) { + actionConfig->reset(); + return true; +} + bool OpengateApp::handleQuit(const CEGUI::EventArgs& e) { static_cast<OpengateListener*>(mFrameListener)->requestShutdown(); return true; } + +void OpengateApp::createCamera(void) { + // Create the camera + mCamera = mSceneMgr->createCamera("PlayerCam"); + + // Position it at 500 in Z direction + mCamera->setPosition(Ogre::Vector3(0,0,500)); + // Look back along -Z + mCamera->lookAt(Ogre::Vector3(0,0,-300)); + mCamera->setNearClipDistance(5); +} + +void OpengateApp::createViewports(void) { + // Create one viewport, entire window + Ogre::Viewport* vp = mWindow->addViewport(mCamera); + vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); + + // Alter the camera aspect ratio to match the viewport + mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); +} + + Modified: src/client/ui/application.h =================================================================== --- src/client/ui/application.h 2006-07-30 18:46:33 UTC (rev 126) +++ src/client/ui/application.h 2006-07-30 19:14:10 UTC (rev 127) @@ -22,118 +22,68 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef _APPLICATION_H -#define _APPLICATION_H +#ifndef _OPENGATE_APPLICATION_ +#define _OPENGATE_APPLICATION_ -#include <OgreConfigFile.h> -#include <OgreRoot.h> -#include <OgreCamera.h> -#include <OgreRenderWindow.h> +#include <OGRE/Ogre.h> + +#include "ActionConfig.h" #include "framelistener.h" -#include "avatar.h" -#include "camera.h" -#include "../../common/gamestate.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif -/*! - * - */ class OpengateApp { -public: - /*! \brief This default constructor instantiates an Application - * - * The default constructor is used to instantiates the Application. The - * Application can be considered as the object, that holds references to - * everything within the game. So here you can find the Scene, the Viewport - * to the scene, the camera(s) and the FrameListener. - */ +public: OpengateApp(); - - /*! \brief This destructor closes the application - * - * When this destructor is called, the game is done and will quit. - */ ~OpengateApp(); + void go(void); - /*! \brief The main "loop" of the game - * - * This method is running while the game is running. When this method is - * done, we are completely done. - */ - void go(); - -protected: - +private: CEGUI::OgreCEGUIRenderer* mGUIRenderer; CEGUI::System* mGUISystem; - CEGUI::Window* mEditorGuiSheet; - Gamestate* mGamestate; + ActionConfig *actionConfig; - Avatar* mAvatar; - Ogre::SceneNode* mAvatarNode; + Ogre::Root *mRoot; + Ogre::Camera* mCamera; + Ogre::SceneManager* mSceneMgr; + OpengateListener* mFrameListener; + Ogre::RenderWindow* mWindow; - Ogre::Root* mRoot; - Camera* mCamera; - Ogre::SceneManager* mSceneMgr; + void createScene(void); - OpengateListener* mFrameListener; - Ogre::RenderWindow* mWindow; + void createFrameListener(void); - Ogre::SceneManager* mGuiSceneMgr; + void setupEventHandlers(void); - /** Sets up the application - returns false if the user chooses to abandon configuration. */ - bool setup(void); + bool handleTest(const CEGUI::EventArgs& e); - /** Configures the application - returns false if the user chooses to abandon c... [truncated message content] |