summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/menu.cc
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-14 16:48:11 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-14 16:48:11 +0000
commit0282f209e8d708396f20c99e8b212cfa488aca37 (patch)
tree8a8cb0f6196a24b315bbad36c96c1306e1da8196 /crawl-ref/source/menu.cc
parent49aa51c728460641dbe953544464b8135d069406 (diff)
downloadcrawl-ref-0282f209e8d708396f20c99e8b212cfa488aca37.tar.gz
crawl-ref-0282f209e8d708396f20c99e8b212cfa488aca37.zip
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
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r--crawl-ref/source/menu.cc76
1 files changed, 76 insertions, 0 deletions
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 )