MCPcopy Create free account
hub / github.com/crawl/crawl / _handle_FAQ

Function _handle_FAQ

crawl-ref/source/command.cc:456–502  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
456static 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

Callers 1

_show_help_specialFunction · 0.85

Calls 11

getAllFAQKeysFunction · 0.85
mprFunction · 0.85
getFAQ_QuestionFunction · 0.85
getFAQ_AnswerFunction · 0.85
show_descriptionFunction · 0.85
index_to_letterFunction · 0.70
emptyMethod · 0.45
set_titleMethod · 0.45
sizeMethod · 0.45
add_entryMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected