From 0282f209e8d708396f20c99e8b212cfa488aca37 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Wed, 14 Mar 2007 16:48:11 +0000 Subject: Major overhaul of tutorial messages and clean-up of tutorial.cc I've also hopefully fixed a bug concerning entry vaults during the tutorial. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1038 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/menu.cc | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'crawl-ref/source/menu.cc') diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 49f4f52e84..163f50cb4d 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1150,6 +1150,82 @@ int linebreak_string( std::string& s, int wrapcol, int maxcol ) return breakcount; } +int linebreak_string2( std::string& s, int maxcol ) +{ + size_t loc = 0; + int xpos = 0, spacepos = 0; + int breakcount = 0; + while ( loc < s.size() ) + { + if ( s[loc] == '<' ) // tag + { + // << escape + if ( loc + 1 < s.size() && s[loc+1] == '<' ) + { + ++xpos; + loc += 2; + // Um, we never break on <<. That's a feature. Right. + continue; + } + // skip tag + while ( loc < s.size() && s[loc] != '>' ) + ++loc; + ++loc; + } + else + { + // user-forced newline + if ( s[loc] == '\n' ) + xpos = 0; + // hard linebreak + else if ( xpos > maxcol ) + { + if (spacepos >= xpos-maxcol) + { + loc = spacepos; + s.replace(loc, 1, "\n"); + } + else + s.insert(loc, "\n"); + xpos = 0; + ++breakcount; + } + // soft linebreak + else if ( s[loc] == ' ' && xpos > 0) + { + spacepos = loc; + ++xpos; + } + // bog-standard + else + ++xpos; + + ++loc; + } + } + return breakcount; +} + +// takes a (possibly tagged) string, breaks it into lines and +// prints it into the given message channel +void print_formatted_paragraph(std::string &s, int maxcol, int channel) +{ + linebreak_string2(s,maxcol); + std::string text; + + size_t loc = 0, oldloc = 0; + while ( loc < s.size() ) + { + if (s[loc] == '\n') { + text = s.substr(oldloc, loc-oldloc); + formatted_mpr( formatted_string::parse_string(text), channel ); + oldloc = ++loc; + } + loc++; + } + formatted_mpr( formatted_string::parse_string( s.substr(oldloc, loc-oldloc) ), channel ); +} + bool formatted_scroller::jump_to( int i ) { if ( i == first_entry + 1 ) -- cgit v1.2.3-54-g00ecf