Beispiel #1
0
void PlayerPanel::changeHand()
{
    auto player = Game::getInstance()->player();
    auto lastSlot = player->currentHandSlot();
    auto takeOut = [player](Event::Event* evt)
        {
            if (player->currentHandSlot())
            {
                player->setWeaponAnimation('C'); // takeout
            }
        };
    if (lastSlot)
    {
        // put away
        auto anim = player->setWeaponAnimation('D');
        Event::Handler origHandler = anim->animationEndedHandler();
        anim->animationEndedHandler().clear();
        anim->animationEndedHandler().add(takeOut);
        anim->animationEndedHandler().add(origHandler);
    }
    player->setCurrentHand(player->currentHand() == HAND::RIGHT ? HAND::LEFT : HAND::RIGHT);
    if (!lastSlot)
    {
        takeOut(nullptr);
    }    
    playWindowOpenSfx();

}
GameItemObject* GameCritterObject::currentHandSlot()
{
    return currentHand() == HAND_RIGHT ? rightHandSlot() : leftHandSlot();
}
ItemObject* CritterObject::currentHandSlot() const
{
    return currentHand() == HAND::RIGHT ? rightHandSlot() : leftHandSlot();
}