1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  
     | 
    
      /*
 *  File:       tilereg-mem.cc
 *
 *  Created by: ennewalker on Sat Jan 5 01:33:53 2008 UTC
 */
#include "AppHdr.h"
#ifdef USE_TILE
#include "tilereg-mem.h"
#include "cio.h"
#include "libutil.h"
#include "macro.h"
#include "spl-book.h"
#include "spl-cast.h"
#include "spl-util.h"
#include "stuff.h"
#include "tilepick.h"
MemoriseRegion::MemoriseRegion(const TileRegionInit &init) : SpellRegion(init)
{
}
void MemoriseRegion::activate()
{
    // Print a fitting message if we can't memorise anything.
    has_spells_to_memorise(false);
}
int MemoriseRegion::get_max_slots()
{
    return (m_items.size());
}
void MemoriseRegion::draw_tag()
{
    if (m_cursor == NO_CURSOR)
        return;
    int curs_index = cursor_index();
    if (curs_index >= (int)m_items.size())
        return;
    int idx = m_items[curs_index].idx;
    if (idx == -1)
        return;
    const spell_type spell = (spell_type) idx;
    std::string desc = make_stringf("%s    (%s)    %d/%d spell slot%s",
                                    spell_title(spell),
                                    failure_rate_to_string(spell_fail(spell)),
                                    spell_levels_required(spell),
                                    player_spell_levels(),
                                    spell_levels_required(spell) > 1 ? "s" : "");
    draw_desc(desc.c_str());
}
int MemoriseRegion::handle_mouse(MouseEvent &event)
{
    unsigned int item_idx;
    if (!place_cursor(event, item_idx))
        return (0);
    const spell_type spell = (spell_type) m_items[item_idx].idx;
    if (event.button == MouseEvent::LEFT)
    {
        m_last_clicked_item = item_idx;
        tiles.set_need_redraw();
        if (learn_spell(spell, m_items[item_idx].special))
            tiles.update_inventory();
        else
            flush_input_buffer(FLUSH_ON_FAILURE);
        return CK_MOUSE_CMD;
    }
    else if (event.button == MouseEvent::RIGHT)
    {
        describe_spell(spell);
        redraw_screen();
        return CK_MOUSE_CMD;
    }
    return (0);
}
bool MemoriseRegion::update_tab_tip_text(std::string &tip, bool active)
{
    const char *prefix1 = active ? "" : "[L-Click] ";
    const char *prefix2 = active ? "" : "          ";
    tip = make_stringf("%s%s\n%s%s",
                       prefix1, "Display spells in carried books",
                       prefix2, "Memorise spells");
    return (true);
}
bool MemoriseRegion::update_tip_text(std::string& tip)
{
    if (m_cursor == NO_CURSOR)
        return (false);
    unsigned int item_idx = cursor_index();
    if (item_idx >= m_items.size() || m_items[item_idx].empty())
        return (false);
    int flag = m_items[item_idx].flag;
    std::vector<command_type> cmd;
    if (flag & TILEI_FLAG_INVALID)
        tip = "You cannot memorise this spell now.";
    else
    {
        tip = "[L-Click] Memorise (%)";
        cmd.push_back(CMD_MEMORISE_SPELL);
    }
    tip += "\n[R-Click] Describe";
    insert_commands(tip, cmd);
    return (true);
}
void MemoriseRegion::update()
{
    m_items.clear();
    m_dirty = true;
    if (mx * my == 0)
        return;
    if (!has_spells_to_memorise())
        return;
    const unsigned int max_spells = mx * my;
    std::vector<int>  books;
    std::vector<spell_type> spells = get_mem_spell_list(books);
    for (unsigned int i = 0; m_items.size() < max_spells && i < spells.size();
         ++i)
    {
        const spell_type spell = spells[i];
        InventoryTile desc;
        desc.tile     = tileidx_spell(spell);
        desc.idx      = (int) spell;
        desc.special  = books[i];
        desc.quantity = spell_difficulty(spell);
        if (!can_learn_spell(true)
            || spell_difficulty(spell) > you.experience_level
            || player_spell_levels() < spell_levels_required(spell))
        {
            desc.flag |= TILEI_FLAG_INVALID;
        }
        m_items.push_back(desc);
    }
}
#endif
 
     |