/**************************************************************************************** * Call this function to hook a function to a given button input on the given controller * @param iButton can have multiple buttons * Call this from an overriden InitControllerInputs() function ***************************************************************************************/ public void HookInputFunction(CBaseController pController, ulong iButton, bool bTouchInput, bool bActivateOnRelease, EntityControllerInputDelegate pFunction) { //Find our button object to register with CButtonSet bs = bTouchInput ? pController.ButtonsTouched() : pController.ButtonsPressed(); List <CButton> bl = new List <CButton>(); for (int i = 0; i < bs.m_pButtons.Count; i++) { if ((bs.m_pButtons[i].m_iFlag & iButton) > 0) { bl.Add(bs.m_pButtons[i]); } } EntityControllerInputEvent ecie; ecie.m_pEnt = this; ecie.m_pFunction = pFunction; for (int i = 0; i < bl.Count; i++) { CButton b = bl[i]; if (bActivateOnRelease) { b.m_pReleasedEvents.Add(ecie); } else { b.m_pPressedEvents.Add(ecie); } } }
public void Start(CBaseController pController, CBaseEntity pEnt) { //builds flags from our booleans ulong pressPressedFlags = m_pPressPressed.GetFlags(); ulong pressReleasedFlags = m_pPressReleased.GetFlags(); ulong touchPressedFlags = m_pTouchPressed.GetFlags(); ulong touchReleasedFlags = m_pTouchReleased.GetFlags(); CButtonSet touch = pController.ButtonsTouched(); CButtonSet press = pController.ButtonsPressed(); //iterate through all the buttons if (pEnt.m_bInputEventsTriggersUse) { EntityControllerInputEvent input = new EntityControllerInputEvent(); input.m_pEnt = pEnt; input.m_pFunction = CBaseEntity.Hook_Use; for (int i = 0; i < g.IN_NUM_BUTTONS; i++) { CButton b = press.m_pButtons[i]; if ((pressPressedFlags & b.m_iFlag) > 0) { b.m_pPressedEvents.Add(input); } if ((pressReleasedFlags & b.m_iFlag) > 0) { b.m_pReleasedEvents.Add(input); } } for (int i = 0; i < g.IN_NUM_BUTTONS; i++) { CButton b = touch.m_pButtons[i]; if ((touchPressedFlags & b.m_iFlag) > 0) { b.m_pPressedEvents.Add(input); } if ((touchReleasedFlags & b.m_iFlag) > 0) { b.m_pReleasedEvents.Add(input); } } } }
//This is called from update to keep track of what controllers are being pressed //returns true if buttons have changed, false otherwise public bool UpdateToMatch(ulong iButtons) { ulong oldButtons = m_iButtons; ulong addedButtons = iButtons & ~oldButtons; ulong removedButtons = oldButtons & ~iButtons; //apply locks addedButtons &= ~m_iLockedButtons; removedButtons &= ~m_iLockedButtons; ulong changedButtons = addedButtons | removedButtons; //change buttons m_iButtons ^= changedButtons; bool bChanged = m_iButtons != oldButtons; if (bChanged) { //check events //check pressed events first for (byte i = 0; i < g.IN_NUM_BUTTONS; i++) { CButton b = m_pButtons[i]; if ((b.m_iFlag & addedButtons) > 0) { b.PressedEvent(m_pParent); } else if ((b.m_iFlag & removedButtons) > 0) { b.ReleasedEvent(m_pParent); } } } return(bChanged); }