4 * Created by: jpeg on Sat, Nov 27 2010
11 #include "tilereg-skl.h"
17 #include "tiledef-icons.h"
25 SkillRegion::SkillRegion(const TileRegionInit
&init
) : GridRegion(init
)
29 void SkillRegion::activate()
33 void SkillRegion::draw_tag()
35 if (m_cursor
== NO_CURSOR
)
38 int curs_index
= cursor_index();
39 if (curs_index
>= (int)m_items
.size())
41 int idx
= m_items
[curs_index
].idx
;
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",
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
))
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.
77 if (you
.wizard
&& (event
.mod
& MOD_CTRL
))
79 wizard_set_skill_level(skill
);
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.");
90 tiles
.set_need_redraw();
91 you
.practise_skill
[skill
] = !you
.practise_skill
[skill
];
95 else if (skill
!= NUM_SKILLS
&& event
.button
== MouseEvent::RIGHT
)
97 describe_skill(skill
);
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");
114 bool SkillRegion::update_tip_text(std::string
& tip
)
116 if (m_cursor
== NO_CURSOR
)
119 unsigned int item_idx
= cursor_index();
120 if (item_idx
>= m_items
.size() || m_items
[item_idx
].empty())
123 const int flag
= m_items
[item_idx
].flag
;
124 if (flag
& TILEI_FLAG_INVALID
)
125 tip
= "You don't have this skill yet.";
128 const skill_type skill
= (skill_type
) m_items
[item_idx
].idx
;
131 if (you
.practise_skill
[skill
])
132 tip
+= "Lower the rate of training";
134 tip
+= "Increase the rate of training";
138 tip
+= "\n[Ctrl + L-Click] Change skill level (wizmode)";
141 tip
+= "\n[R-Click] Describe";
146 bool SkillRegion::update_alt_text(std::string
&alt
)
148 if (m_cursor
== NO_CURSOR
)
151 unsigned int item_idx
= cursor_index();
152 if (item_idx
>= m_items
.size() || m_items
[item_idx
].empty())
155 if (m_last_clicked_item
>= 0
156 && item_idx
== (unsigned int) m_last_clicked_item
)
161 int idx
= m_items
[item_idx
].idx
;
163 const skill_type skill
= (skill_type
) idx
;
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
);
176 static int _get_aptitude_tile(const int 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
;
191 default: return TILEI_NUM_ZERO
;
195 void SkillRegion::pack_buffers()
198 for (int y
= 0; y
< my
; y
++)
200 if (i
>= (int)m_items
.size())
203 for (int x
= 0; x
< mx
; x
++)
205 if (i
>= (int)m_items
.size())
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
);
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()
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
)
245 desc
.tile
= tileidx_skill(skill
,
246 you
.practise_skill
[skill
]);
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
);