From 631dff0b53511c53e67f3ca9b2b88becf7f7c84c Mon Sep 17 00:00:00 2001 From: ennewalker Date: Sat, 3 Jan 2009 02:38:47 +0000 Subject: Tile menus now support multiple tiles per entry (see MenuEntry::get_tiles). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8153 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/invent.cc | 12 ++++++++---- crawl-ref/source/invent.h | 2 +- crawl-ref/source/menu.h | 4 ++-- crawl-ref/source/tilebuf.h | 2 +- crawl-ref/source/tilereg.cc | 41 ++++++++++++++++++++++------------------- crawl-ref/source/tilereg.h | 5 ++--- crawl-ref/source/tiletex.h | 9 ++++++++- 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index ac1e6f5b86..7d96c65819 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -417,15 +417,19 @@ void InvMenu::load_inv_items(int item_selector, int excluded_slot, } #ifdef USE_TILE -bool InvEntry::tile(int &idx, TextureID &tex) const +bool InvEntry::get_tiles(std::vector& tileset) const { if (quantity <= 0) return (false); - idx = tileidx_item(*item); - tex = TEX_DEFAULT; + int idx = tileidx_item(*item); + if (!idx) + return (false); + + tileset.push_back(tile_def(TILE_ITEM_SLOT, TEX_DUNGEON)); + tileset.push_back(tile_def(idx, TEX_DEFAULT)); - return (idx != 0); + return (true); } #endif diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h index 25dcb6aa7c..c8debaac6e 100644 --- a/crawl-ref/source/invent.h +++ b/crawl-ref/source/invent.h @@ -104,7 +104,7 @@ public: virtual std::string get_filter_text() const; #ifdef USE_TILE - virtual bool tile(int &tile, TextureID &tex) const; + virtual bool get_tiles(std::vector& tiles) const; #endif private: diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 9ddc336e65..7ac3fc90b8 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -144,9 +144,9 @@ struct MenuEntry } #ifdef USE_TILE - virtual bool tile(int &idx, TextureID &tex) const + virtual bool get_tiles(std::vector& tileset) const { - return false; + return (false); } #endif }; diff --git a/crawl-ref/source/tilebuf.h b/crawl-ref/source/tilebuf.h index 6b0ae7eab4..5d3b4201b3 100644 --- a/crawl-ref/source/tilebuf.h +++ b/crawl-ref/source/tilebuf.h @@ -87,7 +87,7 @@ protected: class TileBuffer : public VertBuffer { public: - TileBuffer(const TilesTexture *tex); + TileBuffer(const TilesTexture *tex = NULL); void add(int idx, float x, float y); // Note: this could invalidate previous additions if they were diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index b895815e63..ee97fc6089 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -2390,7 +2390,7 @@ int CRTRegion::handle_mouse(MouseEvent &event) MenuRegion::MenuRegion(ImageManager *im, FTFont *entry) : m_image(im), m_font_entry(entry), m_mouse_idx(-1), - m_max_columns(1), m_dirty(false), m_font_buf(entry), m_tile_buf(NULL) + m_max_columns(1), m_dirty(false), m_font_buf(entry) { ASSERT(m_image); ASSERT(m_font_entry); @@ -2399,6 +2399,9 @@ MenuRegion::MenuRegion(ImageManager *im, FTFont *entry) : dy = 1; m_entries.resize(128); + + for (int i = 0; i < TEX_MAX; i++) + m_tile_buf[i].set_tex(&m_image->m_textures[i]); } void MenuRegion::set_num_columns(int columns) @@ -2495,11 +2498,10 @@ void MenuRegion::place_entries() const VColour selected_colour(50, 50, 10, 255); m_font_buf.clear(); - m_tile_buf.clear(); m_shape_buf.clear(); m_line_buf.clear(); - - TextureID tex = TEX_MAX; + for (int t = 0; t < TEX_MAX; t++) + m_tile_buf[t].clear(); int column = 0; const int max_columns = std::min(2, m_max_columns); @@ -2554,18 +2556,20 @@ void MenuRegion::place_entries() int entry_height; - if (m_entries[i].tile) + if (m_entries[i].tiles.size() > 0) { m_entries[i].sx = entry_start + tile_indent; entry_height = std::max(max_tile_height, text_height); - // Currently, menus only support one texture at a time. - tex = m_entries[i].texture; - ASSERT(m_entries[i].texture == tex || tex == TEX_MAX); - - m_tile_buf.set_tex(&m_image->m_textures[tex]); - m_tile_buf.add(m_entries[i].tile, m_entries[i].sx, - m_entries[i].sy); + for (unsigned int t = 0; t < m_entries[i].tiles.size(); t++) + { + // NOTE: This is not perfect. Tiles will be drawn + // sorted by texture first, e.g. you can never draw + // a dungeon tile over a monster tile. + int tile = m_entries[i].tiles[t].tile; + TextureID tex = m_entries[i].tiles[t].tex; + m_tile_buf[tex].add(tile, m_entries[i].sx, m_entries[i].sy); + } } else { @@ -2646,7 +2650,8 @@ void MenuRegion::render() m_shape_buf.draw(); m_line_buf.draw(); - m_tile_buf.draw(); + for (int i = 0; i < TEX_MAX; i++) + m_tile_buf[i].draw(); m_font_buf.draw(); } @@ -2654,7 +2659,8 @@ void MenuRegion::clear() { m_shape_buf.clear(); m_line_buf.clear(); - m_tile_buf.clear(); + for (int i = 0; i < TEX_MAX; i++) + m_tile_buf[i].clear(); m_font_buf.clear(); m_more.clear(); @@ -2685,8 +2691,8 @@ void MenuRegion::set_entry(int idx, const std::string &str, int colour, e.selected = me->selected(); e.key = me->hotkeys.size() > 0 ? me->hotkeys[0] : 0; e.sx = e.sy = e.ex = e.ey = 0; - if (!me->tile(e.tile, e.texture)) - e.tile = 0; + e.tiles.clear(); + me->get_tiles(e.tiles); m_dirty = true; } @@ -2740,9 +2746,6 @@ bool ImageManager::load_textures() if (!m_textures[TEX_DOLL].load_texture("player.png", mip)) return false; - if (!m_textures[TEX_TITLE].load_texture("title.png", mip)) - return false; - m_textures[TEX_DUNGEON].set_info(TILE_DNGN_MAX, &tile_dngn_info); m_textures[TEX_DOLL].set_info(TILEP_PLAYER_MAX, &tile_player_info); diff --git a/crawl-ref/source/tilereg.h b/crawl-ref/source/tilereg.h index e9a053fb98..f2846e0024 100644 --- a/crawl-ref/source/tilereg.h +++ b/crawl-ref/source/tilereg.h @@ -202,13 +202,12 @@ protected: struct MenuRegionEntry { formatted_string text; - int tile; - TextureID texture; int sx, ex, sy, ey; bool selected; bool heading; char key; bool valid; + std::vector tiles; }; ImageManager *m_image; @@ -223,7 +222,7 @@ protected: ShapeBuffer m_shape_buf; LineBuffer m_line_buf; FontBuffer m_font_buf; - TileBuffer m_tile_buf; + FixedVector m_tile_buf; }; class TileRegion : public Region diff --git a/crawl-ref/source/tiletex.h b/crawl-ref/source/tiletex.h index 5158ea6411..9299305789 100644 --- a/crawl-ref/source/tiletex.h +++ b/crawl-ref/source/tiletex.h @@ -14,10 +14,17 @@ enum TextureID TEX_DUNGEON, TEX_DEFAULT, TEX_DOLL, - TEX_TITLE, TEX_MAX }; +struct tile_def +{ + tile_def(int _tile, TextureID _tex) : tile(_tile), tex(_tex) {} + + int tile; + TextureID tex; +}; + class GenericTexture { public: -- cgit v1.2.3-54-g00ecf