2010-05-06 00:08:41 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
|
|
|
#include "nel/misc/i_xml.h"
|
|
|
|
#include "nel/misc/file.h"
|
|
|
|
#include "nel/misc/game_device_events.h"
|
|
|
|
|
2012-02-08 00:58:15 +00:00
|
|
|
#include "nel/misc/xml_auto_ptr.h"
|
2010-05-06 00:08:41 +00:00
|
|
|
|
|
|
|
#include "input_handler_manager.h"
|
|
|
|
#include "interface_manager.h"
|
|
|
|
#include "../actions.h"
|
|
|
|
#include "../input.h"
|
|
|
|
#include "../client_cfg.h"
|
|
|
|
#include "../motion/user_controls.h"
|
|
|
|
#include "../init.h"
|
|
|
|
#include "../release.h"
|
|
|
|
|
|
|
|
#include "../r2/editor.h"
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// USING //
|
|
|
|
///////////
|
|
|
|
using namespace std;
|
|
|
|
using namespace NLMISC;
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// GLOBAL //
|
|
|
|
////////////
|
|
|
|
|
|
|
|
extern CActionsManager Actions;
|
|
|
|
extern CActionsManager EditActions;
|
|
|
|
|
2010-11-12 13:26:38 +00:00
|
|
|
// Hierarchical timer
|
2010-05-06 00:08:41 +00:00
|
|
|
H_AUTO_DECL ( RZ_Client_Pump_Events )
|
|
|
|
|
|
|
|
CInputHandlerManager* CInputHandlerManager::_Instance = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
CInputHandlerManager::CInputHandlerManager()
|
|
|
|
{
|
|
|
|
_EventServer= NULL;
|
|
|
|
_MouseButtonsState = noButton;
|
|
|
|
_MouseX = _MouseY = _MouseLastX = _MouseLastY = 0;
|
|
|
|
_Focus = true;
|
|
|
|
_MouseWheel = 0;
|
|
|
|
_SkipInterfaceManager=false;
|
|
|
|
_RecoverFocusLost = false;
|
2012-05-17 01:28:50 +00:00
|
|
|
|
|
|
|
inputHandler.setListener( CInterfaceManager::getInstance() );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
CInputHandlerManager::~CInputHandlerManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// ********************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CInputHandlerManager::releaseInstance()
|
|
|
|
{
|
|
|
|
if( _Instance )
|
|
|
|
{
|
|
|
|
delete _Instance;
|
|
|
|
_Instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::addToServer(NLMISC::CEventServer * server)
|
|
|
|
{
|
|
|
|
_EventServer = server;
|
|
|
|
|
|
|
|
// System
|
|
|
|
server->addListener(EventGDMouseMove, this);
|
|
|
|
server->addListener(EventDestroyWindowId, this);
|
|
|
|
server->addListener(EventSetFocusId, this);
|
|
|
|
server->addListener(EventDisplayChangeId, this);
|
|
|
|
|
|
|
|
// Mouse
|
|
|
|
server->addListener(EventMouseMoveId, this);
|
|
|
|
server->addListener(EventMouseDownId, this);
|
|
|
|
server->addListener(EventMouseUpId, this);
|
|
|
|
server->addListener(EventMouseWheelId, this);
|
|
|
|
server->addListener(EventMouseDblClkId, this);
|
|
|
|
|
|
|
|
// Keyboard
|
2010-10-17 14:38:43 +00:00
|
|
|
server->addListener(EventStringId, this);
|
2010-05-06 00:08:41 +00:00
|
|
|
server->addListener(EventCharId, this);
|
|
|
|
server->addListener(EventKeyDownId, this);
|
|
|
|
server->addListener(EventKeyUpId, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::release()
|
|
|
|
{
|
|
|
|
// System
|
|
|
|
_EventServer->removeListener(EventGDMouseMove, this);
|
|
|
|
_EventServer->removeListener(EventDestroyWindowId, this);
|
|
|
|
_EventServer->removeListener(EventSetFocusId, this);
|
|
|
|
_EventServer->removeListener(EventDisplayChangeId, this);
|
|
|
|
|
|
|
|
// Mouse
|
|
|
|
_EventServer->removeListener(EventMouseMoveId, this);
|
|
|
|
_EventServer->removeListener(EventMouseDownId, this);
|
|
|
|
_EventServer->removeListener(EventMouseUpId, this);
|
|
|
|
_EventServer->removeListener(EventMouseWheelId, this);
|
|
|
|
_EventServer->removeListener(EventMouseDblClkId, this);
|
|
|
|
|
|
|
|
// Keyboard
|
2010-10-17 14:38:43 +00:00
|
|
|
_EventServer->removeListener(EventStringId, this);
|
2010-05-06 00:08:41 +00:00
|
|
|
_EventServer->removeListener(EventCharId, this);
|
|
|
|
_EventServer->removeListener(EventKeyDownId, this);
|
|
|
|
_EventServer->removeListener(EventKeyUpId, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::operator ()(const NLMISC::CEvent &event)
|
|
|
|
{
|
|
|
|
HandleSystemCursorCapture(event);
|
|
|
|
|
|
|
|
if (event == EventDisplayChangeId)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process message to InterfaceManager
|
|
|
|
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
|
|
|
|
|
|
|
if (event==EventSetFocusId)
|
|
|
|
{
|
|
|
|
CEventSetFocus *pEvent=(CEventSetFocus *)&event;
|
|
|
|
if (!pEvent->Get)
|
|
|
|
{
|
2010-11-04 21:22:29 +00:00
|
|
|
// Deactivate all keys
|
2010-05-06 00:08:41 +00:00
|
|
|
_MouseButtonsState = noButton;
|
|
|
|
_Focus = false;
|
|
|
|
|
|
|
|
if (!_SkipInterfaceManager)
|
|
|
|
{
|
|
|
|
// if there was some control capturing the mouse, warn them that they lost the focus
|
2012-05-17 01:28:50 +00:00
|
|
|
inputHandler.handleSetFocusEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
UserControls.stopFreeLook();
|
|
|
|
}
|
|
|
|
// be nice with other app : let the mouse reappear (useful in direct 3D mode with no hardware cursor)
|
2012-02-11 00:41:46 +00:00
|
|
|
CInterfaceManager::getInstance()->getViewRenderer().getDriver()->showCursor(true);
|
2010-11-02 18:45:05 +00:00
|
|
|
// Driver->setSystemArrow();
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_RecoverFocusLost = true; // force to update mouse pos on next click or move
|
2012-02-11 00:41:46 +00:00
|
|
|
CInterfaceManager::getInstance()->getViewRenderer().getDriver()->showCursor(IsMouseCursorHardware());
|
2010-05-06 00:08:41 +00:00
|
|
|
_Focus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!_SkipInterfaceManager)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
if (R2::getEditor().isInitialized()
|
|
|
|
&& (ClientCfg.R2EDEnabled || R2::getEditor().getCurrentTool())
|
|
|
|
)
|
|
|
|
{
|
2012-05-10 21:31:39 +00:00
|
|
|
R2::getEditor().handleEvent(NLGUI::CEventDescriptorSetFocus(pEvent->Get));
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-post
|
|
|
|
FilteredEventServer.postEvent( event.clone() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If want to skip the interface Manager
|
|
|
|
if(_SkipInterfaceManager)
|
|
|
|
{
|
|
|
|
// redirect to FilteredEventServer
|
|
|
|
FilteredEventServer.postEvent( event.clone() );
|
|
|
|
/* Invalidate Actions managers by simulate keyUp on all. Else can have this scenario:
|
|
|
|
- keyDown ("forward" action valide) before teleporting
|
|
|
|
- keyUp while teleporting (=> _SkipInterfaceManager==true)
|
|
|
|
- action still valide when teleported
|
|
|
|
*/
|
|
|
|
EditActions.releaseAllKeyNoRunning();
|
|
|
|
Actions.releaseAllKeyNoRunning();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// **** Event Focus
|
|
|
|
|
|
|
|
// **** Event Keyboard
|
|
|
|
if( event == EventKeyDownId ||
|
|
|
|
event == EventKeyUpId ||
|
2010-10-17 14:38:43 +00:00
|
|
|
event == EventCharId ||
|
|
|
|
event == EventStringId)
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
// if not handled, post to Action Manager
|
2012-05-17 01:28:50 +00:00
|
|
|
if( !inputHandler.handleKeyboardEvent( event ) )
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
// See if handled by editor
|
|
|
|
bool handled = false;
|
|
|
|
if (R2::getEditor().isInitialized()
|
|
|
|
&& (ClientCfg.R2EDEnabled || R2::getEditor().getCurrentTool())
|
|
|
|
)
|
|
|
|
{
|
2012-05-10 21:31:39 +00:00
|
|
|
handled = R2::getEditor().handleEvent(NLGUI::CEventDescriptorKey((const CEventKey &) event) );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
if (!handled)
|
|
|
|
{
|
|
|
|
// Event from the Keyboard (DOWN KEYS)
|
|
|
|
if(event == EventKeyDownId)
|
|
|
|
{
|
|
|
|
CEventKeyDown* downEvent=(CEventKeyDown*)&event;
|
|
|
|
if (!pIM->getCaptureKeyboard () || !EditActions.keyPushed (*downEvent))
|
|
|
|
Actions.keyPushed (*downEvent);
|
|
|
|
}
|
|
|
|
// Event from the Keyboard (UP KEYS)
|
|
|
|
else if(event == EventKeyUpId)
|
|
|
|
{
|
|
|
|
CEventKeyUp* upEvent=(CEventKeyUp*)&event;
|
|
|
|
EditActions.keyReleased (*upEvent);
|
|
|
|
Actions.keyReleased (*upEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if handled, still post released key for the following bug:
|
|
|
|
- I press 'Z' to go 'forward' before entering chat
|
|
|
|
- I enter chat, keeping Z pressed
|
|
|
|
- I release 'Z' in chat (thus handled by pIM->handleEvent())
|
|
|
|
- the player continue running...
|
|
|
|
*/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// don't send keydown to action managers
|
|
|
|
if(event==EventKeyUpId)
|
|
|
|
{
|
|
|
|
CEventKeyUp* upEvent=(CEventKeyUp*)&event;
|
|
|
|
EditActions.keyReleased (*upEvent);
|
|
|
|
Actions.keyReleased (*upEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// **** Event Mouse
|
|
|
|
else if(pIM->getPointer() && _Focus /* && pIM->isMouseHandlingEnabled() */ &&
|
|
|
|
( event == EventMouseMoveId ||
|
|
|
|
event == EventMouseDownId ||
|
|
|
|
event == EventMouseUpId ||
|
|
|
|
event == EventMouseWheelId ||
|
|
|
|
event == EventMouseDblClkId )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
CViewPointer &rIP = *pIM->getPointer();
|
|
|
|
|
2012-05-10 21:31:39 +00:00
|
|
|
NLGUI::CEventDescriptorMouse eventDesc;
|
2012-05-17 01:28:50 +00:00
|
|
|
|
2010-05-06 00:08:41 +00:00
|
|
|
sint32 x,y;
|
|
|
|
rIP.getPointerDispPos (x, y);
|
|
|
|
eventDesc.setX (x);
|
|
|
|
eventDesc.setY (y);
|
|
|
|
|
|
|
|
bool handled= false;
|
|
|
|
|
|
|
|
// button down ?
|
|
|
|
static volatile bool doTest = false;
|
|
|
|
|
|
|
|
if (!doTest || (doTest && pIM->isMouseHandlingEnabled()))
|
|
|
|
{
|
|
|
|
if (event==EventMouseDownId)
|
|
|
|
{
|
|
|
|
if (_RecoverFocusLost)
|
|
|
|
{
|
|
|
|
handled |= updateMousePos((CEventMouse&)event, eventDesc); // must update mouse pos here,
|
|
|
|
// because when app window focus is gained by a mouse click, this is
|
|
|
|
// the only place where we can retrieve mouse pos before a mouse move
|
|
|
|
_RecoverFocusLost = false;
|
|
|
|
}
|
|
|
|
if (!handled)
|
|
|
|
{
|
|
|
|
if (R2::getEditor().isInitialized()
|
|
|
|
&& (R2::isEditionCurrent() || R2::getEditor().getCurrentTool())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
handled |= R2::getEditor().handleEvent(eventDesc);
|
|
|
|
}
|
|
|
|
}
|
2012-05-17 01:28:50 +00:00
|
|
|
handled |= inputHandler.handleMouseButtonDownEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
// button up ?
|
|
|
|
else if (event==EventMouseUpId)
|
|
|
|
{
|
2012-05-17 01:28:50 +00:00
|
|
|
handled |= inputHandler.handleMouseButtonUpEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
// db click ?
|
|
|
|
else if (event == EventMouseDblClkId )
|
|
|
|
{
|
|
|
|
// TODO: yoyo make it work if needed (for now, seems preferable to manage in each ActionHandler)
|
2012-05-17 01:28:50 +00:00
|
|
|
handled |= inputHandler.handleMouseDblClickEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
// mouse move?
|
|
|
|
else if(event == EventMouseMoveId)
|
|
|
|
{
|
|
|
|
handled |= updateMousePos((CEventMouse&)event, eventDesc);
|
|
|
|
}
|
|
|
|
else if (event == EventMouseWheelId)
|
|
|
|
{
|
2012-05-17 01:28:50 +00:00
|
|
|
handled |= inputHandler.handleMouseWheelEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if Event not handled, post to Action Manager
|
|
|
|
if( !handled )
|
|
|
|
{
|
|
|
|
bool handled = false;
|
|
|
|
if (R2::getEditor().isInitialized()
|
|
|
|
&& (R2::isEditionCurrent() || R2::getEditor().getCurrentTool())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
handled = R2::getEditor().handleEvent(eventDesc);
|
|
|
|
}
|
|
|
|
if (!handled)
|
|
|
|
{
|
|
|
|
// post to Action Manager
|
|
|
|
FilteredEventServer.postEvent( event.clone() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// **** Others
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FilteredEventServer.postEvent( event.clone() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
2012-05-10 21:31:39 +00:00
|
|
|
bool CInputHandlerManager::updateMousePos(NLMISC::CEventMouse &event, NLGUI::CEventDescriptorMouse &eventDesc)
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
if (!IsMouseFreeLook())
|
2012-05-17 01:28:50 +00:00
|
|
|
return inputHandler.handleMouseMoveEvent( event );
|
2010-05-06 00:08:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
2012-05-10 21:31:39 +00:00
|
|
|
void CInputHandlerManager::CComboKey::init(const NLGUI::CEventDescriptorKey &rDK)
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
Key= rDK.getKey();
|
|
|
|
CtrlFlags= 0;
|
|
|
|
if( rDK.getKeyCtrl() )
|
|
|
|
CtrlFlags|= CtrlKey;
|
|
|
|
if( rDK.getKeyShift() )
|
|
|
|
CtrlFlags|= ShiftKey;
|
|
|
|
if( rDK.getKeyAlt() )
|
|
|
|
CtrlFlags|= AltKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
bool CInputHandlerManager::CComboKey::operator<(const CComboKey &c) const
|
|
|
|
{
|
|
|
|
if(Key!=c.Key)
|
|
|
|
return Key<c.Key;
|
|
|
|
else
|
|
|
|
return CtrlFlags<c.CtrlFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
2012-05-10 21:31:39 +00:00
|
|
|
bool CInputHandlerManager::isComboKeyChat(const NLGUI::CEventDescriptorKey &edk) const
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
CComboKey ckey;
|
|
|
|
ckey.init(edk);
|
|
|
|
return _ComboKeyChat.find(ckey)!=_ComboKeyChat.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
bool CInputHandlerManager::readInputConfigFile(const std::string & fileName)
|
|
|
|
{
|
|
|
|
// parse the XML input config file to build the events to actions map
|
|
|
|
CIXml read;
|
|
|
|
CIFile file;
|
|
|
|
xmlNodePtr root;
|
|
|
|
if (!file.open(fileName))
|
|
|
|
{
|
|
|
|
nlinfo(" could not open file %s",fileName.c_str());
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
read.init (file);
|
|
|
|
root = read.getRootNode();
|
|
|
|
|
|
|
|
}
|
2011-06-03 08:35:25 +00:00
|
|
|
catch (const Exception &e)
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
// Output error
|
|
|
|
root = NULL;
|
|
|
|
nlwarning ("CFormLoader: Error while loading the xml input file : %s", e.what());
|
|
|
|
}
|
|
|
|
if (!root)
|
|
|
|
{
|
|
|
|
nlinfo ("no root element in xml file %s",fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//the root node name should be input_config
|
|
|
|
if (strcmp( (char*)root->name,"input_config") )
|
|
|
|
{
|
|
|
|
nlinfo("in a xml input config, the root node must be <input_config>");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//get all system nodes
|
|
|
|
xmlNodePtr cur = root->xmlChildrenNode;
|
|
|
|
while (cur)
|
|
|
|
{
|
|
|
|
// Read all combo_key_chat setup.
|
|
|
|
if ( !strcmp((char*)cur->name,"combo_key_chat") )
|
|
|
|
parseComboKeyChat(cur);
|
|
|
|
|
|
|
|
cur= cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::pumpEvents()
|
|
|
|
{
|
|
|
|
H_AUTO_USE ( RZ_Client_Pump_Events )
|
|
|
|
|
|
|
|
nlassert(_EventServer);
|
|
|
|
|
|
|
|
// pump the src EventServer
|
|
|
|
_EventServer->pump(true);
|
|
|
|
|
|
|
|
// pump the filtered ones
|
|
|
|
FilteredEventServer.pump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::pumpEventsNoIM()
|
|
|
|
{
|
|
|
|
nlassert(_EventServer);
|
|
|
|
|
|
|
|
// Set Mode to skip InterfaceManager Handling
|
|
|
|
_SkipInterfaceManager= true;
|
|
|
|
|
|
|
|
// pump the src EventServer
|
|
|
|
_EventServer->pump(true);
|
|
|
|
|
|
|
|
// pump the filtered ones
|
|
|
|
FilteredEventServer.pump(true);
|
|
|
|
|
|
|
|
// reset
|
|
|
|
_SkipInterfaceManager= false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::resetPos (sint x, sint y)
|
|
|
|
{
|
|
|
|
_MouseLastX = x;
|
|
|
|
_MouseX = x;
|
|
|
|
_MouseY = y;
|
|
|
|
_MouseLastY = y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::parseComboKeyChat(xmlNodePtr cur)
|
|
|
|
{
|
|
|
|
xmlNodePtr keySon = cur->xmlChildrenNode;
|
|
|
|
while (keySon)
|
|
|
|
{
|
|
|
|
// check its a key
|
|
|
|
if ( strcmp((char*)keySon->name,"key") )
|
|
|
|
{
|
|
|
|
keySon= keySon->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<CComboKey> v;
|
|
|
|
parseKey(keySon, v);
|
|
|
|
|
|
|
|
for (uint i = 0; i < v.size(); ++i)
|
|
|
|
_ComboKeyChat.insert(v[i]);
|
|
|
|
|
|
|
|
// next
|
|
|
|
keySon= keySon->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
void CInputHandlerManager::parseKey(xmlNodePtr cur, std::vector<CComboKey> &out)
|
|
|
|
{
|
|
|
|
// read it
|
|
|
|
CXMLAutoPtr prop;
|
|
|
|
string keyStr;
|
|
|
|
string flagStr;
|
|
|
|
|
|
|
|
// read id
|
|
|
|
prop= (char*) xmlGetProp( cur, (xmlChar*) "id" );
|
|
|
|
if(prop)
|
|
|
|
keyStr= (const char*)prop;
|
|
|
|
|
|
|
|
// read flags
|
|
|
|
prop= (char*) xmlGetProp( cur, (xmlChar*) "mod" );
|
|
|
|
if(prop)
|
|
|
|
flagStr= (const char*)prop;
|
|
|
|
|
|
|
|
|
|
|
|
// Build the Key
|
|
|
|
CComboKey comboKey;
|
|
|
|
// If an hexa code, translate
|
|
|
|
if( keyStr.find("0x")!=string::npos )
|
|
|
|
{
|
|
|
|
sint value;
|
|
|
|
sscanf(keyStr.c_str(), "%x", &value);
|
|
|
|
comboKey.Key= (TKey)value;
|
|
|
|
}
|
|
|
|
// else translate from enum
|
|
|
|
else
|
|
|
|
{
|
|
|
|
comboKey.Key= CEventKey::getKeyFromString(keyStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If valid key
|
|
|
|
if(comboKey.Key==NLMISC::KeyCount)
|
|
|
|
{
|
|
|
|
nlwarning("Unknown Key Id in xml input file: %s", keyStr.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Test All flags if match flagStr
|
|
|
|
for(uint i=0;i<8;i++)
|
|
|
|
{
|
|
|
|
comboKey.CtrlFlags= i;
|
|
|
|
|
|
|
|
// Test if Control match
|
|
|
|
if(comboKey.CtrlFlags & CComboKey::CtrlKey)
|
|
|
|
{
|
|
|
|
// If don't find c or C, abort
|
|
|
|
if( flagStr.find('c')== string::npos && flagStr.find('C')== string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if find 'c', then abort
|
|
|
|
if( flagStr.find('c')!= string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if Shift match
|
|
|
|
if(comboKey.CtrlFlags & CComboKey::ShiftKey)
|
|
|
|
{
|
|
|
|
// If don't find s or S, abort
|
|
|
|
if( flagStr.find('s')== string::npos && flagStr.find('S')== string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if find 's', then abort
|
|
|
|
if( flagStr.find('s')!= string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if Alt match
|
|
|
|
if(comboKey.CtrlFlags & CComboKey::AltKey)
|
|
|
|
{
|
|
|
|
// If don't find a or A, abort
|
|
|
|
if( flagStr.find('a')== string::npos && flagStr.find('A')== string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if find 'a', then abort
|
|
|
|
if( flagStr.find('a')!= string::npos )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If pass, Insert this combo
|
|
|
|
out.push_back(comboKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|