From 34cc3ee5d9832be20c635849dc592611c4697f2c Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 30 Jun 2007 15:17:02 +0000 Subject: The tutorial now uses set_more() to display the ability-menu help (so Menu doesn't need to be aware of the tutorial.) set_more() support with multi-line strings will only work if there are enough free lines; it doesn't (yet) reduce pagesize. Also, it doesn't handle newlines which aren't EOLs. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1700 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 12 ++++++++++-- crawl-ref/source/format.cc | 19 +++++++++++++++++++ crawl-ref/source/format.h | 1 + crawl-ref/source/items.cc | 4 ---- crawl-ref/source/menu.cc | 12 ++++-------- crawl-ref/source/menu.h | 4 ++-- crawl-ref/source/tutorial.cc | 30 +++++++++++++++--------------- crawl-ref/source/tutorial.h | 2 +- 8 files changed, 52 insertions(+), 32 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 492d5cf247..70f215b7e2 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -62,6 +62,7 @@ #include "spells4.h" #include "stuff.h" #include "transfor.h" +#include "tutorial.h" #include "view.h" @@ -1724,8 +1725,15 @@ int choose_ability_menu(const std::vector& talents) } } - bool tutorial = (Options.tutorial_left > 0); - std::vector sel = abil_menu.show(false, tutorial); + if ( Options.tutorial_left ) + { + // XXX This could be buggy if manage to pick up lots and lots + // of abilities during the tutorial. + abil_menu.set_more(tut_abilities_info()); + abil_menu.set_flags(MF_SINGLESELECT | MF_ANYPRINTABLE | + MF_ALWAYS_SHOW_MORE); + } + std::vector sel = abil_menu.show(false); redraw_screen(); if ( sel.empty() ) { diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc index 390133f3d5..9eb82cb8d3 100644 --- a/crawl-ref/source/format.cc +++ b/crawl-ref/source/format.cc @@ -314,3 +314,22 @@ void formatted_string::fs_op::display() const break; } } + +int count_linebreaks(const formatted_string& fs) +{ + std::string::size_type where = 0; + const std::string s = fs; + int count = 0; + while ( 1 ) + { + where = s.find(EOL, where); + if ( where == std::string::npos ) + break; + else + { + ++count; + ++where; + } + } + return count; +} diff --git a/crawl-ref/source/format.h b/crawl-ref/source/format.h index 3360aa34d5..af0231e23b 100644 --- a/crawl-ref/source/format.h +++ b/crawl-ref/source/format.h @@ -89,5 +89,6 @@ public: std::vector ops; }; +int count_linebreaks(const formatted_string& fs); #endif diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 80d9edbc56..ac28060190 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -617,10 +617,6 @@ static int item_name_specialness(const item_def& item) return 0; } -/* - * Takes keyin as an argument because it will only display a long list of items - * if ; is pressed. - */ void item_check(bool verbose) { diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index e4a3ea7904..85f596b1db 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -97,7 +97,7 @@ void Menu::reset() first_entry = 0; } -std::vector Menu::show(bool reuse_selections, bool tut_abil) +std::vector Menu::show(bool reuse_selections) { cursor_control cs(false); @@ -111,18 +111,14 @@ std::vector Menu::show(bool reuse_selections, bool tut_abil) if (max_pagesize > 0 && pagesize > max_pagesize) pagesize = max_pagesize; - do_menu(tut_abil); + do_menu(); return (sel); } -void Menu::do_menu(bool tut_abil) +void Menu::do_menu() { draw_menu(); - if (tut_abil) - { - tut_describe_abilities(); - } alive = true; while (alive) @@ -477,7 +473,7 @@ void Menu::draw_menu() } if (end < (int) items.size() || is_set(MF_ALWAYS_SHOW_MORE)) { - gotoxy( 1, y_offset + pagesize ); + gotoxy( 1, y_offset + pagesize - count_linebreaks(more) ); more.display(); } } diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 2607a02702..cfe710efd5 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -198,7 +198,7 @@ public: unsigned char getkey() const { return lastch; } void reset(); - std::vector show(bool reuse_selections = false, bool tut_abil = false); + std::vector show(bool reuse_selections = false); std::vector selected_entries() const; size_t item_count() const { return items.size(); } @@ -235,7 +235,7 @@ protected: bool alive; protected: - void do_menu(bool tut_abil = false); + void do_menu(); virtual void draw_select_count(int count, bool force = false); virtual void draw_item( int index ) const; virtual void draw_index_item(int index, const MenuEntry *me) const; diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index f221e2eec8..10ac59b00c 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -1321,20 +1321,20 @@ void learned_something_new(tutorial_event_type seen_what, int x, int y) Options.tutorial_left--; } -void tut_describe_abilities() +formatted_string tut_abilities_info() { - const int bottom_line = (get_number_of_lines() > 30) ? 30 : get_number_of_lines(); - textcolor(MAGENTA); - gotoxy(1, bottom_line-5); - std::string text = - "This screen shows your character's set of talents. You can gain new " EOL - "abilities via certain items, through religion or by way of mutations. " EOL - "Activation of an ability usually comes at a cost, e.g. nutrition or " EOL - "Magic power. "; - if (you.religion == GOD_TROG) text += - "Renounce Religion will make your character leave your god" EOL - "(and usually anger said god), while Berserk temporarily increases your" EOL - "damage output in melee fights."; - - formatted_string::parse_block(text, false).display(); + std::string text = "" + "This screen shows your character's set of talents. You can gain new " EOL + "abilities via certain items, through religion or by way of mutations. " EOL + "Activation of an ability usually comes at a cost, e.g. nutrition or " EOL + "Magic power. "; + + if (you.religion == GOD_TROG) + { + text += + "Renounce Religion will make your character leave your god" EOL + "(and usually anger said god), while Berserk temporarily increases your" EOL + "damage output in melee fights."; + } + return formatted_string::parse_string(text, false); } diff --git a/crawl-ref/source/tutorial.h b/crawl-ref/source/tutorial.h index 33fc630129..e3d0d84f7a 100644 --- a/crawl-ref/source/tutorial.h +++ b/crawl-ref/source/tutorial.h @@ -36,6 +36,6 @@ void taken_new_item(unsigned char item_type); void tutorial_first_monster(const monsters& mon); void tutorial_first_item(const item_def& item); void learned_something_new(tutorial_event_type seen_what, int x=0, int y=0); -void tut_describe_abilities(void); +formatted_string tut_abilities_info(); #endif -- cgit v1.2.3-54-g00ecf