void State_pickPartAction::KeyDown(const int &key, const int &unicode)
{
    if (key == SDLK_ESCAPE)
        popMe = true;
    else if (key == SDLK_u) // unequip
    {
        // Check if there is something.
        Ship& current = refToFleet.ships[page];
        if (type == 'c')
        {
            auto result = current.cannonList.find(index);
            if (result != current.cannonList.end())
            {
                ShipCannons sc = result->second;
                int e = refToFleet.ships[page].removeCannons(index, sc);
                if (e != 0)
                    refToFleet.captain.cannonInventory.push_back(sc);
            }
        }
        else if (type == 'a')
        {
            auto result = current.armorList.find(index);
            if (result != current.armorList.end())
            {
                ShipArmor sa = result->second;
                int e = refToFleet.ships[page].removeArmor(index, sa);
                if (e != 0)
                    refToFleet.captain.armorInventory.push_back(sa);
            }
        }
        else if (type == 's')
        {
            auto result = current.sailList.find(index);
            if (result != current.sailList.end())
            {
                ShipSails ss = result->second;
                int e = refToFleet.ships[page].removeSail(index, ss);
                if (e != 0) // did not fail
                    refToFleet.captain.sailInventory.push_back(ss);
            }
        }

        popMe = true;
    }
    else if (key == SDLK_e)
    {
        if (hasParts())
        {
            pickedIndex = -5;
            waiting = true;
            nextState = new State_selectPart(refToFleet, page, type, pickedIndex);
            pushSomething = true;
        }
    }
}
void State_pickPartAction::redraw()
{
    Ship& current = refToFleet.ships[page];
    
    console->setColorControl(TCOD_COLCTRL_1, TCODColor::yellow, TCODColor::black);
    int line = 1;
    console->setDefaultForeground(TCODColor::darkerYellow);

    std::string equippedName;
    if (type == 'c')
    {
        auto result = current.cannonList.find(index);
        if (result == current.cannonList.end())
            equippedName = "nothing";
        else
        {
            ShipCannons& sc = result->second;
            equippedName = sc.shopName();
        }
    }
    else if (type == 'a')
    {
        auto result = current.armorList.find(index);
        if (result == current.armorList.end())
            equippedName = "nothing";
        else
        {
            ShipArmor& sa = result->second;
            equippedName = sa.shopName();
        }
    }
    else if (type == 's')
    {
        auto result = current.sailList.find(index);
        if (result == current.sailList.end())
            equippedName = "nothing";
        else
        {
            ShipSails& ss = result->second;
            equippedName = ss.shopName();
        }
    }

    console->print(1, line++, "Equipped: %s", equippedName.c_str());
    line++;
    console->setDefaultForeground(TCODColor::white);

    if (hasParts()) // Disable equipping if there are no parts to equip!
        console->print(1, line++, "%cE%cquip %s", TCOD_COLCTRL_1, TCOD_COLCTRL_STOP, type_name.c_str());
    else
    {
        console->setDefaultForeground(TCODColor::lightGrey);
        console->print(1, line++, "Equip %s %cYou do not have any %s to equip%c", type_name.c_str(), TCOD_COLCTRL_1, type_name.c_str(), TCOD_COLCTRL_STOP);
    }
        
    if (equippedName == "nothing")
    {
        console->setDefaultForeground(TCODColor::lightGrey);
        console->print(1, line++, "Unequip %s", type_name.c_str());
    }
    else
        console->print(1, line++, "%cU%cnequip %s", TCOD_COLCTRL_1, TCOD_COLCTRL_STOP, type_name.c_str());

    console->setDefaultForeground(MabinogiBrown);
    console->printFrame(0, 0, console->getWidth(), console->getHeight(), false);
}
示例#3
0
void RenderIndicator::requestLayoutForParts()
{
    if (shouldHaveParts() || hasParts())
        setNeedsLayout(true);
}