+ Added callback for button B released.
+ Implemented unit selection cancelation.
This commit is contained in:
parent
37070c559d
commit
6ecb59761a
|
@ -55,7 +55,7 @@ void HumanPlayer::buttonHandler(void)
|
||||||
* according to pressed button. */
|
* according to pressed button. */
|
||||||
cameraButtonPressedHandler(szBtn);
|
cameraButtonPressedHandler(szBtn);
|
||||||
}
|
}
|
||||||
else
|
else if (gb.buttons.released(static_cast<uint8_t>(szBtn)))
|
||||||
{
|
{
|
||||||
/* Key has not been pressed. */
|
/* Key has not been pressed. */
|
||||||
|
|
||||||
|
@ -166,7 +166,8 @@ void HumanPlayer::playerButtonReleasedHandler(const size_t szBtn)
|
||||||
[BTN_UP] = NULL,
|
[BTN_UP] = NULL,
|
||||||
[BTN_RIGHT] = NULL,
|
[BTN_RIGHT] = NULL,
|
||||||
[BTN_DOWN] = NULL,
|
[BTN_DOWN] = NULL,
|
||||||
[BTN_A] = &HumanPlayer::onABtnReleased
|
[BTN_A] = &HumanPlayer::onABtnReleased,
|
||||||
|
[BTN_B] = &HumanPlayer::onBBtnReleased
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Key has been pressed. Execute both
|
/* Key has been pressed. Execute both
|
||||||
|
@ -228,6 +229,45 @@ void HumanPlayer::onABtnPressed(void)
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
void HumanPlayer::onBBtnPressed(void)
|
void HumanPlayer::onBBtnPressed(void)
|
||||||
{
|
{
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
/* Number of frames that B button must
|
||||||
|
* be pressed in order to cancel unit selection. */
|
||||||
|
CANCEL_SELECTION_FRAMES = 10
|
||||||
|
};
|
||||||
|
|
||||||
|
if (++_BBtnFrames >= CANCEL_SELECTION_FRAMES)
|
||||||
|
{
|
||||||
|
switch (_eState)
|
||||||
|
{
|
||||||
|
case PLAYER_STATE_UNIT_SELECTED:
|
||||||
|
{
|
||||||
|
/* Iterator that will be used
|
||||||
|
* to move along _unitsMap. */
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < (sizeof (_unitsMap) / sizeof (_unitsMap[0])); i++)
|
||||||
|
{
|
||||||
|
Unit& u = _unitsMap[i];
|
||||||
|
|
||||||
|
/* Reset selected flags. */
|
||||||
|
u.setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset to default state. */
|
||||||
|
_eState = PLAYER_STATE_IDLE;
|
||||||
|
}
|
||||||
|
/* Fall through. */
|
||||||
|
case PLAYER_STATE_IDLE:
|
||||||
|
/* Fall through. */
|
||||||
|
default:
|
||||||
|
/* Reset pressed B button frames counter. */
|
||||||
|
_BBtnFrames = 0;
|
||||||
|
|
||||||
|
/* Undefined player state. Exit. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************//**
|
/*****************************************************************//**
|
||||||
|
@ -260,13 +300,60 @@ void HumanPlayer::onABtnReleased(void)
|
||||||
/* Short button press. Exit. */
|
/* Short button press. Exit. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
/* Fall through. */
|
||||||
|
case PLAYER_STATE_IDLE:
|
||||||
|
/* Fall through. */
|
||||||
default:
|
default:
|
||||||
/* Undefined state. Exit. */
|
/* Undefined player state. Exit. */
|
||||||
|
|
||||||
|
/* Reset pressed A button frames counter. */
|
||||||
|
_ABtnFrames = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************//**
|
||||||
|
*
|
||||||
|
* \brief Event handler executed when human player releases
|
||||||
|
* B button.
|
||||||
|
*
|
||||||
|
*********************************************************************/
|
||||||
|
void HumanPlayer::onBBtnReleased(void)
|
||||||
|
{
|
||||||
|
switch (_eState)
|
||||||
|
{
|
||||||
|
case PLAYER_STATE_UNIT_SELECTED:
|
||||||
|
{
|
||||||
|
/* Iterator that will be used
|
||||||
|
* to move along _unitsMap. */
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < (sizeof (_unitsMap) / sizeof (_unitsMap[0])); i++)
|
||||||
|
{
|
||||||
|
Unit& u = _unitsMap[i];
|
||||||
|
|
||||||
|
if (u.isSelected())
|
||||||
|
{
|
||||||
|
/* Get cursor coordinates. */
|
||||||
|
const uint16_t x = _cursor.getX();
|
||||||
|
const uint16_t y = _cursor.getY();
|
||||||
|
|
||||||
|
/* Move unit to cursor position. */
|
||||||
|
u.moveTo(x, y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Unit is not selected by the player. Continue. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Fall through.*/
|
||||||
|
case PLAYER_STATE_IDLE:
|
||||||
|
/* Fall through. */
|
||||||
|
default:
|
||||||
|
/* Undefined player state. Exit. */
|
||||||
|
/* Reset pressed B button frames counter. */
|
||||||
|
_BBtnFrames = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset pressed A button frames counter. */
|
|
||||||
_ABtnFrames = 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue