-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextManager.cpp
213 lines (159 loc) · 4.83 KB
/
TextManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// --------------------------------------------------------------------------------------------------------------------------------
// DEMISERL
// Copyright 2014 Corremn
//
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
// $HeadURL: $
// --------------------------------------------------------------------------------------------------------------------------------
#pragma warning(disable : 4786)
#include "TextManager.h"
#include "WorldBuilder.h"
#define STEP 90 //max characters on screen before the -more- is used
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TextManager::TextManager() :
death_print(0)
{
newLine("The Warlock of Firetop Mountain bids you welcome. 'Mahahahahah!!'");
m_step = 0;
}
TextManager::~TextManager()
{
}
void TextManager::ClearDisplayLines()
{
for (int i = 0; i < 40; i++)
SetDisplayLine(i, " ");
}
int TextManager::newLine(char * fmt, ...)
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return 0; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap);
m_step = 0;
display_line.append(text);
if (messageList.size() > 0 && strcmp(text, messageList.back().c_str()) == 0) //bunch up messages of the same
{
messageList.back().append(" x2");
}
else
messageList.push_back(text);
// remove first
if (messageList.size() > 30)
messageList.erase(messageList.begin());
// messageList.pop_front();
return 1;
}
int TextManager::clear()
{
display_line = "";
return 1;
}
void TextManager::MoreStep(int clear)
{
if (clear)
m_step = 0;
else
m_step++;
}
int TextManager::More()
{
std::string temp;//= display_line.copy(0,10);;
char tt[STEP + 1];
int step = m_step*STEP;
display_line1.erase();
eDisplayState preState = World.State();
if (preState == sMore)
preState = sNormal;
int count = display_line.size() - STEP * m_step;
if (display_line.size() > STEP && count > STEP) //use more flag
{
display_line.copy(tt, STEP, 0 + step);
display_line1.append(tt, STEP);
display_line1 += " -more-";
World.SetState(sMore);
}
else if (display_line.size() != count && count > 0) //last line after more
{
display_line.copy(tt, count, 0 + step);
display_line1.append(tt, count);
World.SetState(preState);
}
else //no need to use more
{
display_line1 = display_line;
World.SetState(preState);
m_step = 0;
}
return 1;
}
std::string * TextManager::GetMessageLine(int id)
{
More();
return &display_line1;
}
std::string * TextManager::GetDisplayLine(int id)
{
return &display_lines[id];
}
void TextManager::SetDisplayLine(int id, char * str, ...)
{
if (id >= 40)
return;
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (str == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, str); // Parses The String For Variables
vsprintf(text, str, ap); // And Converts Symbols To Actual Numbers
va_end(ap);
display_lines[id] = text;
}
void TextManager::ShowMessages()
{
STRINGLIST::iterator it;
World.getTextManager().ClearDisplayLines();
SetDisplayLine(0, "Previous Messages");
SetDisplayLine(1, "=================");
SetDisplayLine(2, "");
int i = 3;
for (it = messageList.begin(); it != messageList.end(); it++, i++)
{
SetDisplayLine(i, (char *)it->c_str());
}
SetDisplayLine(39, "[+/-] scroll - [x] to exit");
}
void TextManager::PrintDisplay(const char * filename, int print_lines)
{
if (print_lines > 40)
print_lines = 40;
std::ofstream ofile;
std::string new_file = filename;
new_file.append(".txt");
ofile.open(new_file.c_str());
if (!ofile.is_open())
{
char err[128];
sprintf(err, "Could not open %s", new_file.c_str());
throw std::exception(err);
}
for (int i = 0; i < print_lines; i++)
{
ofile << display_lines[i] << std::endl;
}
ofile << std::endl;
//STRINGLIST::iterator inv;
/* STRINGLIST::iterator it;
for (it = messageList.begin(); it != messageList.end(); it++)
{
ofile << it->c_str() << std::endl;
}*/
ofile.close();
}