From d04f647d2a64423af89b497c4daab8b452e7bf1c Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 20 Mar 2007 16:54:00 +0000 Subject: Tutorial tweaks: * Fixed status display commentary wiping out the status display on curses. * Fixed doubled %% on Unix (a plague on whoever wrote cprintf() in libw32c.cc). * Fixed reference to get_number_of_cols() before curses initialisation. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1073 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/format.cc | 27 ++++++++++++- crawl-ref/source/format.h | 5 +++ crawl-ref/source/libw32c.cc | 7 +--- crawl-ref/source/menu.cc | 2 - crawl-ref/source/tutorial.cc | 92 +++++++++++++++++++++++--------------------- 5 files changed, 80 insertions(+), 53 deletions(-) diff --git a/crawl-ref/source/format.cc b/crawl-ref/source/format.cc index 3de867c8ee..d8942e5d08 100644 --- a/crawl-ref/source/format.cc +++ b/crawl-ref/source/format.cc @@ -31,6 +31,29 @@ int formatted_string::get_colour(const std::string &tag) return (colour != -1? colour : LIGHTGREY); } +formatted_string formatted_string::parse_block( + const std::string &s, + bool eol_ends_format, + bool (*process)(const std::string &tag)) +{ + std::vector lines = split_string("\n", s, false, true); + + formatted_string fs; + for (int i = 0, size = lines.size(); i < size; ++i) + { + if (i) + { + // Artificial newline - some terms erase to eol when printing a + // newline. + fs.gotoxy(1, -1); // CR + fs.movexy(0, 1); // LF + } + fs += parse_string(lines[i], eol_ends_format, process); + } + + return (fs); +} + formatted_string formatted_string::parse_string( const std::string &s, bool eol_ends_format, @@ -103,12 +126,12 @@ formatted_string formatted_string::parse_string( } const int new_colour = invert_colour? LIGHTGREY : get_colour(tagtext); - if (new_colour != curr_colour) + if (!currs.empty()) { fs.cprintf(currs); currs.clear(); - fs.textcolor( curr_colour = new_colour ); } + fs.textcolor( curr_colour = new_colour ); tag += tagtext.length() + 1; } if (currs.length()) diff --git a/crawl-ref/source/format.h b/crawl-ref/source/format.h index a3f51c1ced..3360aa34d5 100644 --- a/crawl-ref/source/format.h +++ b/crawl-ref/source/format.h @@ -44,6 +44,11 @@ public: const std::string &s, bool eol_ends_format = true, bool (*process_tag)(const std::string &tag) = NULL ); + + static formatted_string parse_block( + const std::string &s, + bool eol_ends_format = true, + bool (*process_tag)(const std::string &tag) = NULL ); static int get_colour(const std::string &tag); diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc index 0625331013..3032b5602e 100644 --- a/crawl-ref/source/libw32c.cc +++ b/crawl-ref/source/libw32c.cc @@ -653,12 +653,7 @@ static void cprintf_aux(const char *s) char *p = (char *)s; while(*p) { - if (p[0] == '%' && p[1] == '%') - { - p++; - continue; - } - writeChar(*p++); + writeChar(*p++); } // reset buffering diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 35e054f0d9..74e0044e4c 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1218,13 +1218,11 @@ void print_formatted_paragraph(std::string &s, int maxcol, int channel) { if (s[loc] == '\n') { text = s.substr(oldloc, loc-oldloc); -// formatted_mpr( formatted_string::parse_string(text), channel ); formatted_message_history( text, channel ); oldloc = ++loc; } loc++; } -// formatted_mpr( formatted_string::parse_string( s.substr(oldloc, loc-oldloc) ), channel ); formatted_message_history( s.substr(oldloc, loc-oldloc), channel ); } diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index 3c3b04cbc2..39960a7275 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -22,7 +22,11 @@ //#define TUTORIAL_DEBUG #define TUTORIAL_VERSION 110 -int COLS = (get_number_of_cols() > 80) ? 80 : get_number_of_cols(); +static int get_tutorial_cols() +{ + int ncols = get_number_of_cols(); + return (ncols > 80? 80 : ncols); +} void save_tutorial( FILE* fp ) { @@ -349,7 +353,7 @@ static formatted_string tutorial_debug() bool lbreak = false; snprintf(info, INFO_SIZE, "Tutorial Debug Screen"); - int i = COLS/2-1 - strlen(info) / 2; + int i = get_tutorial_cols()/2-1 - strlen(info) / 2; result += std::string(i, ' '); result += ""; result += info; @@ -363,14 +367,14 @@ static formatted_string tutorial_debug() result += info; // break text into 2 columns where possible - if (strlen(info) >= COLS/2 || lbreak) + if (strlen(info) >= get_tutorial_cols()/2 || lbreak) { result += EOL; lbreak = false; } else { - result += std::string(COLS/2-1 - strlen(info), ' '); + result += std::string(get_tutorial_cols()/2-1 - strlen(info), ' '); lbreak = true; } } @@ -402,7 +406,7 @@ static formatted_string tutorial_map_intro() "" EOL; result += " --more-- Press Escape to skip the basics"; - linebreak_string2(result,COLS); + linebreak_string2(result,get_tutorial_cols()); return formatted_string::parse_string(result); } @@ -411,33 +415,34 @@ static formatted_string tutorial_stats_intro() std::string result; result += ""; - result += "To the right, important properties of " EOL; - result += "the character are displayed. The most " EOL; - result += "basic one is your health, measured as " EOL; - snprintf(info, INFO_SIZE, "HP: %d/%d. ", you.hp, you.hp_max); + result += "To the right, important properties of \n"; + result += "the character are displayed. The most \n"; + result += "basic one is your health, measured as \n"; + snprintf(info, INFO_SIZE, "HP: %d/%d. ", + you.hp, you.hp_max); result += info; if (Options.tutorial_type==TUT_MAGIC_CHAR) result += " "; - result += "These are your current out " EOL; - result += "of maximum health points. When health " EOL; - result += "drops to zero, you die. " EOL; + result += "These are your current out \n"; + result += "of maximum health points. When health \n"; + result += "drops to zero, you die. \n"; snprintf(info, INFO_SIZE, "Magic: %d/%d", you.magic_points, you.max_magic_points); result += info; - result += " is your energy for casting " EOL; - result += "spells, although more mundane actions " EOL; - result += "often draw from Magic, too. " EOL; - result += "Further down, Strength, Dexterity and " EOL; - result += "Intelligence are shown and provide an " EOL; - result += "all-around account of the character's " EOL; - result += "attributes. " EOL; - - result += ""; - result += " " EOL; - result += " --more-- Press Escape to skip the basics" EOL; - result += " " EOL; - result += " " EOL; - - return formatted_string::parse_string(result); + result += " is your energy for casting \n"; + result += "spells, although more mundane actions \n"; + result += "often draw from Magic, too. \n"; + result += "Further down, Strength, Dexterity and \n"; + result += "Intelligence are shown and provide an \n"; + result += "all-around account of the character's \n"; + result += "attributes. \n"; + + result += ""; + result += " \n"; + result += " --more-- Press Escape to skip the basics\n"; + result += " \n"; + result += " \n"; + + return formatted_string::parse_block(result, false); } static formatted_string tutorial_message_intro() @@ -452,7 +457,7 @@ static formatted_string tutorial_message_intro() "" EOL; result += " --more-- Press Escape to skip the basics"; - linebreak_string2(result,COLS); + linebreak_string2(result,get_tutorial_cols()); return formatted_string::parse_string(result); } @@ -464,7 +469,8 @@ static void tutorial_movement_info() "keys, movement is also possible with hjklyubn. A basic " "command list can be found under ?, and the most important " "commands will be explained to you as it becomes necessary. "; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + mesclr(); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); } // copied from display_mutations and adapted @@ -481,7 +487,7 @@ void tut_starting_screen() for (int i=0; i<=MAX_INFO; i++) { x1 = 1; y1 = 1; - x2 = COLS; y2 = get_number_of_lines(); + x2 = get_tutorial_cols(); y2 = get_number_of_lines(); if (i==1 || i==3) { @@ -604,7 +610,7 @@ void tutorial_death_screen() text = "Sorry, no hint this time, though there should have been one."; } } - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); more(); mpr( "See you next game!", MSGCH_TUTORIAL); @@ -624,7 +630,7 @@ void tutorial_finished() text = "Congrats! You survived until the end of this tutorial - be sure to " "try the other ones as well. Note that the help screen (?) " "will look different from now on. Here's a last playing hint:"; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); more(); if (Options.tut_explored) @@ -682,7 +688,7 @@ void tutorial_finished() text = "Oops... No hint for now. Better luck next time!"; } } - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); more(); for ( long i = 0; i < TUT_EVENTS_NUM; ++i ) @@ -705,7 +711,7 @@ void tutorial_prayer_reminder() "Dissecting it as a sacrifice to "; text += god_name(you.religion); text += ", as well."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); } } @@ -730,7 +736,7 @@ void tutorial_healing_reminder() text = "Remember to rest between fights and to enter unexplored " "terrain with full hitpoints and/or magic. For resting, " "press 5 or Shift-numpad 5."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); } Options.tut_last_healed = you.num_turns; } @@ -859,7 +865,7 @@ void tutorial_first_monster(monsters mon) "information about it by pressing x, moving the cursor " "on the monster and then pressing v. To attack it with " "your wielded weapon, just move into it."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); more(); @@ -872,7 +878,7 @@ void tutorial_first_monster(monsters mon) "- allow you to select the proper monster. Finally, " "Enter or . fire. If you miss, " "ff fires at the previous target again."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); } else if (Options.tutorial_type == TUT_MAGIC_CHAR) { @@ -884,7 +890,7 @@ void tutorial_first_monster(monsters mon) "allow you to select the proper target. Finally, Enter " "or . fire. If you miss, Zap will " "fire at the previous target again."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); } Options.tutorial_events[TUT_SEEN_MONSTER] = 0; @@ -905,10 +911,10 @@ void tutorial_first_item(item_def item) text += ch; text += " is an item. If you move there and press g or " ", you will pick it up. Generally, items are shown by " - "non-letter symbols like %%?!\"=()[. Once it is in your " + "non-letter symbols like %?!\"=()[. Once it is in your " "inventory, you can drop it again with d. Several types " "of objects will usually be picked up automatically."; - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); Options.tutorial_events[TUT_SEEN_FIRST_OBJECT] = 0; Options.tutorial_left--; @@ -1014,11 +1020,11 @@ void learned_something_new(unsigned int seen_what, int x, int y) "the greater the potential value of an item."; break; case TUT_SEEN_FOOD: - text = "You have picked up some food ('%%'). You can eat it " + text = "You have picked up some food ('%'). You can eat it " "by typing e."; break; case TUT_SEEN_CARRION: - text = "You have picked up a corpse ('%%'). When a corpse " + text = "You have picked up a corpse ('%'). When a corpse " "is lying on the ground, you can Dissect with a " "sharp implement. Once hungry you can eat the " "resulting chunks (though they may not be healthy)."; @@ -1326,7 +1332,7 @@ void learned_something_new(unsigned int seen_what, int x, int y) text += "You've found something new (but I don't know what)!"; } if (seen_what != TUT_SEEN_MONSTER && seen_what != TUT_SEEN_FIRST_OBJECT) - print_formatted_paragraph(text, COLS, MSGCH_TUTORIAL); + print_formatted_paragraph(text, get_tutorial_cols(), MSGCH_TUTORIAL); // more(); -- cgit v1.2.3-54-g00ecf