-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDisplay.h
320 lines (292 loc) · 6.38 KB
/
Display.h
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#pragma once
#include "Ogre.h"
#include "global.h"
#include "LuaHelperFunctions.h"
#include "DisplayLuaCallback.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <list>
#define ELISA
#ifdef ELISA
#include "Eliza.h"
#endif
using namespace Ogre;
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
//#define LUASTRINGDISPLAYMACROS
//String toWrite;
class Display: public Ogre::Singleton<Display>, FrameListener
{
public:
Display();
~Display();
void init(bool shows,lua_State* pL);
void setVisible(bool visible);
bool isVisible(){return visible;}
void shutdown();
void show();
void hide();
void setText();
void appendText();
void writeLnD(String& text);
void runScript(String luas);
void activateElisa()
{
LogManager::getSingleton().logMessage("Initializing Elisa...");
#ifdef ELISA
if (elisa_chat)
return;
try
{
eliza.load_data();
eliza.start();
}
catch(...)
{
LogManager::getSingleton().logMessage("Error initializing Elisa!");
}
#endif
LogManager::getSingleton().logMessage("Chatterbot Eliza v2.0 Copyright(c) 2005 - 2006 Gonzales Cenelia");
elisa_chat=true;
writeLnD(String("**** STARTED CHAT ****"));
}
void deactivateElisa()
{
LogManager::getSingleton().logMessage("Saving Elisa database...");
#ifdef ELISA
try
{
if(eliza.learn()) {
eliza.save_data();
}
eliza.save_unknown_sentences();
}
catch(...)
{
LogManager::getSingleton().logMessage("Error saving Elisa!");
}
#endif
elisa_chat=false;
writeLnD(String("**** ENDED CHAT ****"));
}
void setAllowVirtualDisplay(bool allow)
{
allowVirtualDisplay=allow;
}
void clrScr()
{
lines.clear();
}
void setColor(ColourValue c)
{
textbox->setColour(c);
};
virtual bool frameStarted(const Ogre::FrameEvent &evt);
virtual bool frameEnded(const Ogre::FrameEvent &evt);
void onKeyPressed(const OIS::KeyEvent &arg);
void setMaterial(String name);
void processLuaFunction(vector<String> params);
void reset();
String getCommand()
{
String mCmd = mCommand;
mCommand="";
return mCmd;
}
static int setDimensions(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=4)
{
return 0;
}
if (lua_isstring(pL, 1)&&lua_isstring(pL, 2)&&lua_isstring(pL, 3)&&lua_isstring(pL, 4))
{
DisplayLuaCallback::getSingleton().setDimensions(StringConverter::parseReal(lua_tostring(pL, 1)),StringConverter::parseReal(lua_tostring(pL, 2)),StringConverter::parseReal(lua_tostring(pL, 3)),StringConverter::parseReal(lua_tostring(pL, 4)));
}
return 1;
}
static int resetDimensions(lua_State* pL)
{
DisplayLuaCallback::getSingleton().resetDimensions();
return 0;
}
static int s_activateElisa(lua_State* pL)
{
Display::getSingleton().activateElisa();
return 0;
}
static int s_deactivateElisa(lua_State* pL)
{
Display::getSingleton().deactivateElisa();
return 0;
}
static int s_activateKeyExit(lua_State* pL)
{
Display::getSingleton().activateEasyExit(true);
return 0;
}
static int s_deactivateKeyExit(lua_State* pL)
{
Display::getSingleton().activateEasyExit(false);
return 0;
}
static int turnOff(lua_State* pL)
{
LogManager::getSingleton().logMessage("Display lua: turn off");
DisplayLuaCallback::getSingleton().shutdown();
return 0;
}
static int writeLn(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
DisplayLuaCallback::getSingleton().setWriteLnText(lua_tostring(pL, 1));//toWrite=
global::getSingleton().getRoot()->renderOneFrame();
return 1;
}
static int setInChar(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
{
String tex = lua_tostring(pL, 1);
DisplayLuaCallback::getSingleton().setFirstChar(tex);
}
return 1;
}
static int setMaxLines(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
{
String tex = lua_tostring(pL, 1);
DisplayLuaCallback::getSingleton().setLines(tex);
}
return 1;
}
static int setTextColor(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=4)
{
return 0;
}
if (lua_isstring(pL, 1)&&lua_isstring(pL, 2)&&lua_isstring(pL,3)&&lua_isstring(pL, 4))
{
ColourValue c(StringConverter::parseReal(lua_tostring(pL,1)),StringConverter::parseReal(lua_tostring(pL,2)),StringConverter::parseReal(lua_tostring(pL,3)),StringConverter::parseReal(lua_tostring(pL,4)));
Display::getSingleton().setColor(c);
}
return 1;
}
static int newLine(lua_State* pL)
{
DisplayLuaCallback::getSingleton().setNewLine();
global::getSingleton().getRoot()->renderOneFrame();
return 1;
}
static int setFontSize(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
{
String tex = lua_tostring(pL, 1);
DisplayLuaCallback::getSingleton().setFontSize(tex);
}
return 1;
}
static int setFont(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
{
String tex = lua_tostring(pL, 1);
DisplayLuaCallback::getSingleton().setFont(tex);
}
return 1;
}
static int clearScreen(lua_State* pL)
{
DisplayLuaCallback::getSingleton().setClear();
return 1;
}
static int setTexture(lua_State* pL)
{
int n = lua_gettop(pL);
if (n!=1)
{
return 0;
}
if (lua_isstring(pL, 1))
{
String tex = lua_tostring(pL, 1);
DisplayLuaCallback::getSingleton().setDTex(tex);//toWrite=
}
return 1;
}
void activateEasyExit(bool ac)
{
mEasyExit=ac;
}
//int cpp_GetAIMove(lua_State* pL);
//int cpp_writeLn(lua_State* pL);
void* curcomputer;
OverlayElement *textbox;
private:
bool elisa_chat;
#ifdef ELISA
Eliza eliza;
#endif
String prevTex;
bool initialized;
bool mEasyExit;
Ogre::Overlay* dispOverlay;
lua_State* pLuaState;
Ogre::String fontName;
bool visible;
Root *root;
int maxLines;
String mCommand;
SceneManager *scene;
Rectangle2D *rect;
SceneNode *noder;
Ogre::TexturePtr lTextureWithRtt;
Ogre::Camera * lRttCamera;
Ogre::SceneNode* lRTTCameraNode;
Ogre::Viewport* lRttViewport1;
Overlay *overlay;
OverlayContainer* dispCont;
MaterialPtr dispMat;
Technique* dispTech;
String prefix;
Pass* dispPass;
TextureUnitState* dispTUstate;
float height;
bool update_overlay;
bool allowVirtualDisplay;
int start_line;
list<String> lines;
String prompt;
};
#endif