Reads all questions from database/FAQ.txt, outputs them in the form of a selectable menu and prints the corresponding answer for a chosen question.
| 454 | // Reads all questions from database/FAQ.txt, outputs them in the form of |
| 455 | // a selectable menu and prints the corresponding answer for a chosen question. |
| 456 | static void _handle_FAQ() |
| 457 | { |
| 458 | vector<string> question_keys = getAllFAQKeys(); |
| 459 | if (question_keys.empty()) |
| 460 | { |
| 461 | mpr("No questions found in FAQ! Please submit a bug report!"); |
| 462 | return; |
| 463 | } |
| 464 | Menu FAQmenu(MF_SINGLESELECT | MF_ANYPRINTABLE | MF_ALLOW_FORMATTING); |
| 465 | MenuEntry *title = new MenuEntry("Frequently Asked Questions"); |
| 466 | title->colour = YELLOW; |
| 467 | FAQmenu.set_title(title); |
| 468 | |
| 469 | for (unsigned int i = 0, size = question_keys.size(); i < size; i++) |
| 470 | { |
| 471 | const char letter = index_to_letter(i); |
| 472 | string question = getFAQ_Question(question_keys[i]); |
| 473 | trim_string_right(question); |
| 474 | MenuEntry *me = new MenuEntry(question, MEL_ITEM, 1, letter); |
| 475 | me->data = &question_keys[i]; |
| 476 | FAQmenu.add_entry(me); |
| 477 | } |
| 478 | |
| 479 | while (true) |
| 480 | { |
| 481 | vector<MenuEntry*> sel = FAQmenu.show(); |
| 482 | if (sel.empty()) |
| 483 | return; |
| 484 | else |
| 485 | { |
| 486 | ASSERT(sel.size() == 1); |
| 487 | ASSERT(sel[0]->hotkeys.size() == 1); |
| 488 | |
| 489 | string key = *((string*) sel[0]->data); |
| 490 | string answer = getFAQ_Answer(key); |
| 491 | if (answer.empty()) |
| 492 | { |
| 493 | answer = "No answer found in the FAQ! Please submit a " |
| 494 | "bug report!"; |
| 495 | } |
| 496 | answer = "Q: " + getFAQ_Question(key) + "\n" + answer; |
| 497 | show_description(answer); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | //////////////////////////////////////////////////////////////////////////// |
| 505 |
no test coverage detected