@@ -1160,7 +1160,7 @@ std::string format_item_info( const std::vector<iteminfo> &vItemDisplay,
1160
1160
bool bIsNewLine = true ;
1161
1161
1162
1162
for ( const iteminfo &i : vItemDisplay ) {
1163
- if ( i.sType == " DESCRIPTION" ) {
1163
+ if ( i.sType == " DESCRIPTION" || i. sType == " SPECIAL_ARMOR_GRAPH " ) {
1164
1164
// Always start a new line for sType == "DESCRIPTION"
1165
1165
if ( !bIsNewLine ) {
1166
1166
buffer += " \n " ;
@@ -1268,6 +1268,75 @@ static nc_color get_comparison_color( const iteminfo &i,
1268
1268
return thisColor;
1269
1269
}
1270
1270
1271
+ static std::vector<std::string> delimit_armor_text ( const iteminfo &i )
1272
+ {
1273
+ const std::string &raw_text = i.sName ;
1274
+ // The various lines of text that can be passed in from item::armor_protection_info():
1275
+ //
1276
+ // Protection:
1277
+ // Bash: 2.00, 8.00, 20.00
1278
+ // Foo: 6.00, 12.00
1279
+ //
1280
+ // Yes that first one has no numbers. It puts the value into sValue.
1281
+ // So we need multiple passes.
1282
+ std::vector<std::string> first_pass = string_split ( raw_text, ' :' );
1283
+ if ( first_pass.size () == 2 && i.sValue != " -999" ) {
1284
+ // Then the value is in sValue and we need to extract it.
1285
+ // So just overwrite the second (empty) string that we just split off.
1286
+ first_pass[1 ] = i.sValue ;
1287
+ }
1288
+ const std::string mega_string = string_join ( first_pass, " , " );
1289
+ const std::vector<std::string> delimited_strings = string_split ( mega_string, ' ,' );
1290
+ return delimited_strings;
1291
+ }
1292
+
1293
+ static void draw_armor_table ( const std::vector<iteminfo> &vItemDisplay, const iteminfo &i )
1294
+ {
1295
+ if ( ImGui::BeginTable ( " ##ITEMINFO_ARMOR_TABLE" , delimit_armor_text ( i ).size (),
1296
+ ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV ) ) {
1297
+ auto info_iter = vItemDisplay.begin () + std::distance ( vItemDisplay.data (), &i );
1298
+ if ( info_iter == vItemDisplay.end () ) {
1299
+ // PANIC!
1300
+ ImGui::EndTable ();
1301
+ return ;
1302
+ }
1303
+
1304
+ const std::vector<std::string> chopped_up = delimit_armor_text ( *info_iter );
1305
+ for ( const std::string &cell_text : chopped_up ) {
1306
+ // this prefix prevents imgui from drawing the text. We still have color tags, which imgui won't parse, so we don't want those exposed to the user.
1307
+ // But we still want proper column IDs. So we put them in, but we *hide them* with this.
1308
+ // This results in a column with an ID of e.g.
1309
+ // ##<color_white>Protection:</color>
1310
+ //
1311
+ // Not great for debugging, but better than having a column with default (randomly generated number) ID!
1312
+ const std::string invisible_ID_label = " ##" + cell_text;
1313
+ ImGui::TableSetupColumn ( invisible_ID_label.c_str (), ImGuiTableColumnFlags_WidthStretch );
1314
+ }
1315
+ ImGui::TableHeadersRow ();
1316
+ // After putting in the invisible labels in the last for-loop, this writes the actual text. Just the same text without the ## marker, and
1317
+ // with our native functions doing the drawing. (So we parse color tags)
1318
+ for ( size_t i = 0 ; i < chopped_up.size (); i++ ) {
1319
+ ImGui::TableSetColumnIndex ( i );
1320
+ cataimgui::draw_colored_text ( chopped_up[i], c_unset );
1321
+ }
1322
+
1323
+ info_iter++;
1324
+
1325
+ while ( info_iter != vItemDisplay.end () && info_iter->sType == " ARMOR" ) {
1326
+ ImGui::TableNextRow ();
1327
+ const std::vector<std::string> delimited_strings = delimit_armor_text ( *info_iter );
1328
+ for ( const std::string &text : delimited_strings ) {
1329
+ ImGui::TableNextColumn ();
1330
+ cataimgui::draw_colored_text ( text, c_unset );
1331
+ }
1332
+ info_iter++;
1333
+ }
1334
+
1335
+
1336
+ ImGui::EndTable ();
1337
+ }
1338
+ }
1339
+
1271
1340
void display_item_info ( const std::vector<iteminfo> &vItemDisplay,
1272
1341
const std::vector<iteminfo> &vItemCompare )
1273
1342
{
@@ -1276,7 +1345,9 @@ void display_item_info( const std::vector<iteminfo> &vItemDisplay,
1276
1345
if ( i.bIsArt ) {
1277
1346
cataimgui::PushMonoFont ();
1278
1347
}
1279
- if ( i.sType == " DESCRIPTION" ) {
1348
+ if ( i.sType == " SPECIAL_ARMOR_GRAPH" ) {
1349
+ draw_armor_table ( vItemDisplay, i );
1350
+ } else if ( i.sType == " DESCRIPTION" ) {
1280
1351
if ( i.bDrawName ) {
1281
1352
if ( i.sName == " --" ) {
1282
1353
if ( !bAlreadyHasNewLine ) {
@@ -1298,7 +1369,7 @@ void display_item_info( const std::vector<iteminfo> &vItemDisplay,
1298
1369
bAlreadyHasNewLine = false ;
1299
1370
}
1300
1371
}
1301
- } else {
1372
+ } else if ( i. sType != " ARMOR " ) { // ARMOR is handled by draw_armor_table()
1302
1373
if ( i.bDrawName ) {
1303
1374
cataimgui::TextColoredParagraph ( c_light_gray, i.sName );
1304
1375
bAlreadyHasNewLine = false ;
0 commit comments