bool CKeyBinds::ControlFunctionExists ( const char* szControl, CLuaMain* pLuaMain, bool bCheckHitState, bool bHitState, const CLuaFunctionRef& iLuaFunction ) { bool bFound = false; list < CKeyBind* > cloneList = m_List; list < CKeyBind* > ::iterator iter = cloneList.begin (); for ( ; iter != cloneList.end () ; ++iter ) { if ( (*iter)->GetType () == KEY_BIND_CONTROL_FUNCTION ) { CControlFunctionBind* pBind = static_cast < CControlFunctionBind* > ( *iter ); if ( stricmp ( szControl, pBind->boundControl->szControl ) == 0 ) { if ( pLuaMain == NULL || pBind->luaMain == pLuaMain ) { if ( !bCheckHitState || pBind->bHitState == bHitState ) { if ( IS_REFNIL ( iLuaFunction ) || pBind->m_iLuaFunction == iLuaFunction ) { bFound = true; } } } } } } return bFound; }
bool CKeyBinds::AddKeyFunction ( const char* szKey, bool bHitState, CLuaMain* pLuaMain, const CLuaFunctionRef& iLuaFunction, CLuaArguments& Arguments ) { if ( szKey == NULL || IS_REFNIL ( iLuaFunction ) ) return false; const SBindableKey* pKey = GetBindableFromKey ( szKey ); if ( pKey ) { CKeyFunctionBind* pBind = new CKeyFunctionBind; pBind->boundKey = pKey; pBind->bHitState = bHitState; pBind->luaMain = pLuaMain; pBind->m_iLuaFunction = iLuaFunction; pBind->m_Arguments = Arguments; m_List.push_back ( pBind ); return true; } return false; }
bool CKeyBinds::RemoveKeyFunction(const char* szKey, CLuaMain* pLuaMain, bool bCheckHitState, bool bHitState, const CLuaFunctionRef& iLuaFunction) { bool bFound = false; CKeyFunctionBind* pBind = NULL; list<CKeyBind*> cloneList = m_List; list<CKeyBind*>::iterator iter = cloneList.begin(); while (iter != cloneList.end()) { if (!(*iter)->IsBeingDeleted() && (*iter)->GetType() == KEY_BIND_FUNCTION) { pBind = static_cast<CKeyFunctionBind*>(*iter); if (!stricmp(szKey, pBind->boundKey->szKey)) { if (pBind->luaMain == pLuaMain) { if (!bCheckHitState || pBind->bHitState == bHitState) { if (IS_REFNIL(iLuaFunction) || pBind->m_iLuaFunction == iLuaFunction) { bFound = true; if (m_bProcessingKey) pBind->beingDeleted = true; else { m_List.remove(pBind); delete pBind; iter = cloneList.erase(iter); continue; } } } } } } ++iter; } return bFound; }