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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include "AppHdr.h"
#ifdef USE_TILE_LOCAL
#include "tilereg-grid.h"
#include "libutil.h"
#include "random.h"
#include "tile-inventory-flags.h"
#include "tiledef-icons.h"
#include "tilefont.h"
#include "tiles-build-specific.h"
InventoryTile::InventoryTile()
{
tile = 0;
idx = -1;
quantity = -1;
key = 0;
flag = 0;
special = 0;
}
bool InventoryTile::empty() const
{
return idx == -1;
}
GridRegion::GridRegion(const TileRegionInit &init) :
TileRegion(init),
m_cursor(NO_CURSOR),
m_last_clicked_item(-1),
m_grid_page(0),
m_buf(init.im)
{
}
void GridRegion::clear()
{
m_items.clear();
m_buf.clear();
}
void GridRegion::on_resize()
{
// probably needed? mimicking MenuRegion::on_resize()
m_dirty = true;
}
unsigned int GridRegion::cursor_index() const
{
ASSERT(m_cursor != NO_CURSOR);
return m_cursor.x + m_cursor.y * mx + m_grid_page*mx*my - m_grid_page*2;
}
void GridRegion::place_cursor(const coord_def &cursor)
{
if (m_cursor != NO_CURSOR && cursor_index() < m_items.size())
{
m_items[cursor_index()].flag &= ~TILEI_FLAG_CURSOR;
m_dirty = true;
}
if (m_cursor != cursor)
m_last_clicked_item = -1;
m_cursor = cursor;
if (m_cursor == NO_CURSOR || cursor_index() >= m_items.size())
return;
// Add cursor to new location
m_items[cursor_index()].flag |= TILEI_FLAG_CURSOR;
m_dirty = true;
}
void GridRegion::draw_desc(const char *desc)
{
ASSERT(m_tag_font);
ASSERT(desc);
// Always draw the description in the inventory header. (jpeg)
int x = sx + ox + dx / 2;
int y = sy + oy;
// ... unless we're using the touch UI, in which case: put at bottom
if (tiles.is_using_small_layout())
y = wy;
const coord_def min_pos(sx, sy - dy);
const coord_def max_pos(ex, ey);
m_tag_font->render_string(x, y, desc, min_pos, max_pos, WHITE, false, 200);
}
bool GridRegion::place_cursor(MouseEvent &event, unsigned int &item_idx)
{
int cx, cy;
if (!mouse_pos(event.px, event.py, cx, cy))
{
place_cursor(NO_CURSOR);
return false;
}
const coord_def cursor(cx, cy);
place_cursor(cursor);
if (mouse_control::current_mode() != MOUSE_MODE_COMMAND
&& !tiles.get_map_display())
{
return false;
}
if (event.event != MouseEvent::PRESS)
return false;
item_idx = cursor_index();
if (item_idx >= m_items.size() || m_items[item_idx].empty())
return false;
return true;
}
int GridRegion::add_quad_char(char c, int x, int y,
int ofs_x, int ofs_y)
{
int num = c - '0';
ASSERT_RANGE(num, 0, 9 + 1);
tileidx_t idx = TILEI_NUM0 + num;
m_buf.add_icons_tile(idx, x, y, ofs_x, ofs_y);
return tile_icons_info(idx).width;
}
void GridRegion::render()
{
if (m_dirty)
{
m_buf.clear();
// Ensure the cursor has been placed.
place_cursor(m_cursor);
pack_buffers();
m_dirty = false;
}
#ifdef DEBUG_TILES_REDRAW
cprintf("rendering GridRegion\n");
#endif
set_transform();
m_buf.draw();
draw_tag();
}
void GridRegion::draw_number(int x, int y, int num)
{
// If you have that many, who cares.
if (num > 9999)
num = 9999;
int offset_x = num > 1999 ? 0 : 3;
int offset_y = 1;
int help = num;
int c1000 = help/1000;
help -= c1000*1000;
if (c1000)
offset_x += add_quad_char('0' + c1000, x, y, offset_x, offset_y);
int c100 = help/100;
help -= c100*100;
if (c100 || c1000)
offset_x += add_quad_char('0' + c100, x, y, offset_x, offset_y);
int c10 = help/10;
if (c10 || c100 || c1000)
offset_x += add_quad_char('0' + c10, x, y, offset_x, offset_y);
int c1 = help % 10;
add_quad_char('0' + c1, x, y, offset_x, offset_y);
}
#endif
|