Apply the new ground_level method.
[crawl.git] / crawl-ref / source / tilereg-skl.cc
blobddc9c8dfb6239156d0ed4f579ec362d39971aff1
1 /*
2 * File: tilereg-skl.cc
4 * Created by: jpeg on Sat, Nov 27 2010
5 */
7 #include "AppHdr.h"
9 #ifdef USE_TILE
11 #include "tilereg-skl.h"
13 #include "cio.h"
14 #include "libutil.h"
15 #include "skills2.h"
16 #include "stuff.h"
17 #include "tiledef-icons.h"
18 #include "tilepick.h"
19 #include "viewgeom.h"
21 #ifdef WIZARD
22 #include "wiz-you.h"
23 #endif
25 SkillRegion::SkillRegion(const TileRegionInit &init) : GridRegion(init)
29 void SkillRegion::activate()
33 void SkillRegion::draw_tag()
35 if (m_cursor == NO_CURSOR)
36 return;
38 int curs_index = cursor_index();
39 if (curs_index >= (int)m_items.size())
40 return;
41 int idx = m_items[curs_index].idx;
42 if (idx == -1)
43 return;
45 const skill_type skill = (skill_type) idx;
46 const int apt = species_apt(skill, you.species);
48 std::string progress = "";
49 // Don't display progress when unskilled or expert.
50 if (you.skills[skill] > 0 && you.skills[skill] < 27)
52 progress = make_stringf("(%d%%) ",
53 get_skill_percentage(skill));
56 std::string desc = make_stringf("%-14s Skill %2d %s Aptitude %c%d",
57 skill_name(skill),
58 you.skills[skill],
59 progress.c_str(),
60 apt > 0 ? '+' : ' ',
61 apt);
63 draw_desc(desc.c_str());
66 int SkillRegion::handle_mouse(MouseEvent &event)
68 unsigned int item_idx;
69 if (!place_cursor(event, item_idx))
70 return (0);
72 const skill_type skill = (skill_type) m_items[item_idx].idx;
73 if (event.button == MouseEvent::LEFT)
75 // TODO: Handle skill transferral using MOD_SHIFT.
76 #ifdef WIZARD
77 if (you.wizard && (event.mod & MOD_CTRL))
79 wizard_set_skill_level(skill);
80 return CK_MOUSE_CMD;
82 #endif
83 m_last_clicked_item = item_idx;
84 if (you.skills[skill] == 0)
85 mpr("You cannot toggle a skill you don't have yet.");
86 else if (you.skills[skill] >= 27)
87 mpr("There's no point to toggling this skill anymore.");
88 else
90 tiles.set_need_redraw();
91 you.practise_skill[skill] = !you.practise_skill[skill];
93 return CK_MOUSE_CMD;
95 else if (skill != NUM_SKILLS && event.button == MouseEvent::RIGHT)
97 describe_skill(skill);
98 redraw_screen();
99 return CK_MOUSE_CMD;
101 return (0);
104 bool SkillRegion::update_tab_tip_text(std::string &tip, bool active)
106 const char *prefix = active ? "" : "[L-Click] ";
108 tip = make_stringf("%s%s",
109 prefix, "Manage skills");
111 return (true);
114 bool SkillRegion::update_tip_text(std::string& tip)
116 if (m_cursor == NO_CURSOR)
117 return (false);
119 unsigned int item_idx = cursor_index();
120 if (item_idx >= m_items.size() || m_items[item_idx].empty())
121 return (false);
123 const int flag = m_items[item_idx].flag;
124 if (flag & TILEI_FLAG_INVALID)
125 tip = "You don't have this skill yet.";
126 else
128 const skill_type skill = (skill_type) m_items[item_idx].idx;
130 tip = "[L-Click] ";
131 if (you.practise_skill[skill])
132 tip += "Lower the rate of training";
133 else
134 tip += "Increase the rate of training";
136 #ifdef WIZARD
137 if (you.wizard)
138 tip += "\n[Ctrl + L-Click] Change skill level (wizmode)";
139 #endif
141 tip += "\n[R-Click] Describe";
143 return (true);
146 bool SkillRegion::update_alt_text(std::string &alt)
148 if (m_cursor == NO_CURSOR)
149 return (false);
151 unsigned int item_idx = cursor_index();
152 if (item_idx >= m_items.size() || m_items[item_idx].empty())
153 return (false);
155 if (m_last_clicked_item >= 0
156 && item_idx == (unsigned int) m_last_clicked_item)
158 return (false);
161 int idx = m_items[item_idx].idx;
163 const skill_type skill = (skill_type) idx;
165 describe_info inf;
166 // TODO: Nicer display for level, aptitude and crosstraining.
167 inf.body << get_skill_description(skill, true);
169 alt_desc_proc proc(crawl_view.msgsz.x, crawl_view.msgsz.y);
170 process_description<alt_desc_proc>(proc, inf);
171 proc.get_string(alt);
173 return (true);
176 static int _get_aptitude_tile(const int apt)
178 switch (apt)
180 case -5: return TILEI_NUM_MINUS5;
181 case -4: return TILEI_NUM_MINUS4;
182 case -3: return TILEI_NUM_MINUS3;
183 case -2: return TILEI_NUM_MINUS2;
184 case -1: return TILEI_NUM_MINUS1;
185 case 1: return TILEI_NUM_PLUS1;
186 case 2: return TILEI_NUM_PLUS2;
187 case 3: return TILEI_NUM_PLUS3;
188 case 4: return TILEI_NUM_PLUS4;
189 case 5: return TILEI_NUM_PLUS5;
190 case 0:
191 default: return TILEI_NUM_ZERO;
195 void SkillRegion::pack_buffers()
197 int i = 0;
198 for (int y = 0; y < my; y++)
200 if (i >= (int)m_items.size())
201 break;
203 for (int x = 0; x < mx; x++)
205 if (i >= (int)m_items.size())
206 break;
208 InventoryTile &item = m_items[i++];
209 const skill_type skill = (skill_type) item.idx;
211 if (item.flag & TILEI_FLAG_INVALID)
212 m_buf.add_icons_tile(TILEI_MESH, x, y);
214 if (item.quantity > 0)
215 draw_number(x, y, item.quantity, true);
217 const int apt = species_apt(skill, you.species);
218 m_buf.add_icons_tile(_get_aptitude_tile(apt), x, y);
220 if (item.tile)
221 m_buf.add_skill_tile(item.tile, x, y);
223 if (item.flag & TILEI_FLAG_CURSOR)
224 m_buf.add_icons_tile(TILEI_CURSOR, x, y);
229 void SkillRegion::update()
231 m_items.clear();
232 m_dirty = true;
234 if (mx * my == 0)
235 return;
237 for (int idx = 0; idx < NUM_SKILLS; ++idx)
239 const skill_type skill = (skill_type) idx;
241 if (skill > SK_UNARMED_COMBAT && skill < SK_SPELLCASTING)
242 continue;
244 InventoryTile desc;
245 desc.tile = tileidx_skill(skill,
246 you.practise_skill[skill]);
247 desc.idx = idx;
248 desc.quantity = you.skills[skill];
250 if (you.skills[skill] == 0 || you.skills[skill] >= 27)
251 desc.flag |= TILEI_FLAG_INVALID;
253 m_items.push_back(desc);
257 #endif