static int _choose_form(void)
{
    int choice = -1;
    int ct = 0;
    int i;

    for (i = 0; ; i++)
    {
        if (_forms[i].race == MIMIC_NONE) break;
        if (_forms[i].level > p_ptr->lev) break;
        ct++;
    }

    if (ct == 0) return -1;

    if (REPEAT_PULL(&choice))
    {
        if (choice >= 0 && choice < ct)
            return choice;
    }

    screen_save();
    choice = _choose_form_imp(ct);
    REPEAT_PUSH(choice);
    screen_load();

    return choice;
}
Beispiel #2
0
int menu_choose(menu_ptr menu)
{
    int choice = -1;

    if (REPEAT_PULL(&choice))
    {
        if (choice >= 0 && choice < menu->count)
            return choice;
    }

    screen_save();

    choice = _choose(menu);
    REPEAT_PUSH(choice);

    screen_load();

    return choice;
}
Beispiel #3
0
int choose_spell(spell_info* spells, int ct, cptr desc, int max_cost)
{
    int choice = -1;

    if (REPEAT_PULL(&choice))
    {
        if (choice >= 0 && choice < ct)
            return choice;
    }

    screen_save();

    choice = _choose_spell(spells, ct, desc, max_cost);
    REPEAT_PUSH(choice);

    screen_load();

    return choice;
}
Beispiel #4
0
static _slot_info_ptr _choose(cptr verb, int options)
{
    _slot_info_ptr result = NULL;
    int            slot = 0;
    int            cmd;
    rect_t         r = _menu_rect();
    string_ptr     prompt = NULL;
    bool           done = FALSE;
    bool           exchange = FALSE;
    int            slot1 = _INVALID_SLOT, slot2 = _INVALID_SLOT;

    if (REPEAT_PULL(&cmd))
    {
        slot = A2I(cmd);
        if (0 <= slot && slot < _MAX_SLOTS)
            return &_spells[slot];
    }

    prompt = string_alloc();
    screen_save();
    while (!done)
    {
        string_clear(prompt);

        if (exchange)
        {
            if (slot1 == _INVALID_SLOT)
                string_append_s(prompt, "Select the first spell:");
            else
                string_append_s(prompt, "Select the second spell:");
        }
        else
        {
            string_printf(prompt, "%s which spell", verb);
            if (options & _ALLOW_EXCHANGE)
                string_append_s(prompt, " [Press 'X' to Exchange]");
            string_append_c(prompt, ':');
        }
        prt(string_buffer(prompt), 0, 0);
        _display(r, options);

        cmd = inkey_special(FALSE);

        if (cmd == ESCAPE || cmd == 'q' || cmd == 'Q')
            done = TRUE;

        if (options & _ALLOW_EXCHANGE)
        {
            if (!exchange && (cmd == 'x' || cmd == 'X'))
            {
                exchange = TRUE;
                slot1 = slot2 = _INVALID_SLOT;
            }
        }

        if ('a' <= cmd && cmd < 'a' + _MAX_SLOTS)
        {
            slot = A2I(cmd);
            if (exchange)
            {
                if (slot1 == _INVALID_SLOT)
                    slot1 = slot;
                else
                {
                    slot2 = slot;
                    if (slot1 != slot2)
                    {
                        _slot_info_t  tmp = _spells[slot1];
                        _spells[slot1] = _spells[slot2];
                        _spells[slot2] = tmp;
                    }
                    exchange = FALSE;
                    slot1 = slot2 = _INVALID_SLOT;
                }
            }
            else
            {
                if (_spells[slot].realm != REALM_NONE || (options & _ALLOW_EMPTY))
                {
                    result = &_spells[slot];
                    done = TRUE;
                }
            }
        }
    }

    if (result)
    {
        REPEAT_PUSH(I2A(slot));
    }

    screen_load();
    string_free(prompt);
    return result;
}