Game Development Reference
In-Depth Information
auto selectedControl = m_items[m_currentItemIndex]->Control();
m_onSelection.Invoke(this, * selectedControl);
return true;
}
else
if (keyboard->KeyPressed(DIK_DOWN) )
{
++m_currentItemIndex;
if ( m_wrapAround && m_currentItemIndex >= m_items.size() )
m_currentItemIndex = 0 ;
auto selectedControl = m_items[m_currentItemIndex]->Control();
m_onSelection.Invoke(this, *selectedControl);
return true;
}
else
if ( keyboard->KeyPressed(DIK_RETURN) || keyboard->KeyPressed(DIK_NUMPADENTER) )
{
auto selectedControl = m_items[m_currentItemIndex]->Control();
m_onAccept.Invoke(this, *selectedControl);
return true;
}
else
if ( keyboard->KeyPressed(DIK_ESCAPE) )
{
auto selectedControl = m_items[m_currentItemIndex]->Control();
m_onCancel.Invoke(this, *selectedControl);
return true;
}
}
int index = 0;
for ( auto it : m_items )
{
if ( it->Control()->HandleInput(deltaTime, inputState) )
{
m_currentItem = it;
m_currentItemIndex = index;
return true;
}
++index;
}
return control::HandleInput(deltaTime, inputState);
}
Anytimeaninputishandled,wetriggertheappropriateeventtoallowustoreacttothedif-
ferent situations. Finally since our menu items consist of controls, we give them a chance
to handle any inputs themselves, this way we ensure that any inputs a control handles will
get properly managed.
The next step is to draw the menu. Given that we are using controls to populate our menu,
what we need to do is to iterate over the controls and allow them to draw themselves.
void menu::InternalDraw()
{
Search WWH ::




Custom Search