Subversion Repositories spk

Rev

Rev 1 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 242
Line 6... Line 6...
6
#include "LcdCustomScreen.h"
6
#include "LcdCustomScreen.h"
7
 
7
 
8
//////////////////////////////////////////////////////////////////////
8
//////////////////////////////////////////////////////////////////////
9
// Construction/Destruction
9
// Construction/Destruction
10
//////////////////////////////////////////////////////////////////////
10
//////////////////////////////////////////////////////////////////////
-
 
11
 
-
 
12
Utils::WString GetEndOfLine(FILE* id, int* line, bool upper)
-
 
13
{
-
 
14
	std::string word;
-
 
15
 
-
 
16
	char c = fgetc(id);
-
 
17
	if (c == -1)
-
 
18
		return L"";
-
 
19
 
-
 
20
	while ((c != 13) && (!feof(id)) && (c != '\n'))
-
 
21
	{
-
 
22
		word += c;
-
 
23
		c = fgetc(id);
-
 
24
	}
-
 
25
 
-
 
26
	if (line)
-
 
27
		++(*line);
-
 
28
 
-
 
29
	if (upper)
-
 
30
		return Utils::WString(word).upper();
-
 
31
 
-
 
32
	return Utils::WString(word);
-
 
33
}
-
 
34
 
11
 
35
 
12
CLcdCustomScreen::CLcdCustomScreen( CEzLcd *lcd )
36
CLcdCustomScreen::CLcdCustomScreen( CEzLcd *lcd )
13
{
37
{
14
	m_pLcd = lcd;
38
	m_pLcd = lcd;
15
	m_iArraySize = 10;
39
	m_iArraySize = 10;
16
	m_pHandles = (HANDLE *)malloc(sizeof(HANDLE) * m_iArraySize);
40
	m_pHandles = (HANDLE *)malloc(sizeof(HANDLE) * m_iArraySize);
17
	m_iCycles = 10;
41
	m_iCycles = 10;
18
	m_bDebug = false;
42
	m_bDebug = false;
19
	m_pMoveObject = m_pEndMoveObject = NULL;
43
	m_pMoveObject = m_pEndMoveObject = NULL;
20
	m_pText = m_pEndText = NULL;
44
	m_pText = m_pEndText = NULL;
21
}
45
}
22
 
46
 
23
CLcdCustomScreen::~CLcdCustomScreen()
47
CLcdCustomScreen::~CLcdCustomScreen()
24
{
48
{
25
	Reset ();
49
	Reset ();
26
	free ( m_pHandles );
50
	free ( m_pHandles );
27
}
51
}
Line 30... Line 54...
30
{
54
{
31
	m_iArraySize += 5;
55
	m_iArraySize += 5;
32
	m_pHandles = (HANDLE *)realloc(m_pHandles, sizeof(HANDLE) * m_iArraySize);
56
	m_pHandles = (HANDLE *)realloc(m_pHandles, sizeof(HANDLE) * m_iArraySize);
33
}
57
}
34
 
58
 
35
CyString CLcdCustomScreen::ParseFilename(CyString &filename, CyString &dir)
59
Utils::WString CLcdCustomScreen::parseFilename(const Utils::WString &filename, const Utils::WString &dir)
36
{
60
{
37
	CyString f = filename;
61
	Utils::WString f = filename;
38
	
62
	
39
	f = f.FindReplace("$progdir", m_sProgDir);
63
	f = f.findReplace(L"$progdir", m_sProgDir);
40
	f = f.FindReplace("$gamedir", m_sGameDir);
64
	f = f.findReplace(L"$gamedir", m_sGameDir);
41
 
65
 
42
	// relative filename
66
	// relative filename
43
	if ( !f.IsIn(":") )
67
	if ( !f.contains(L":") )
44
		f = dir + "/" + f;
68
		f = dir + L"/" + f;
45
 
69
 
46
	f = f.FindReplace("/", "\\");
70
	f = f.findReplace(L"/", L"\\");
47
	f = f.FindReplace("\\\\", "\\");
71
	f = f.findReplace(L"\\\\", L"\\");
48
	return f;
72
	return f;
49
}
73
}
50
bool CLcdCustomScreen::LoadScript ( CyString sDir, CyString sProgDir, const char *filename )
74
bool CLcdCustomScreen::loadScript (const Utils::WString &sDir, const Utils::WString& sProgDir, const Utils::WString& filename)
51
{
75
{
52
	m_lDebugLog.Clear();
76
	_lDebugLog.clear();
53
	m_lVaribles.Clear();
77
	_lVaribles.clear();
54
 
78
 
55
	int iCurrentPos = 0;
79
	int iCurrentPos = 0;
56
 
80
 
57
	m_iStartPage = m_pLcd->AddNewPage () - 1;
81
	m_iStartPage = m_pLcd->AddNewPage () - 1;
58
    m_pLcd->ModifyControlsOnPage( m_iStartPage );
82
    m_pLcd->ModifyControlsOnPage( m_iStartPage );
59
 
83
 
60
	int iLastX, iLastY;
84
	int iLastX, iLastY;
61
 
85
 
62
	m_bDebug = false;
86
	m_bDebug = false;
63
	CyString fname = filename;
87
	Utils::WString fname = filename;
64
	fname = fname.FindReplace("$progdir", sProgDir);
88
	fname = fname.findReplace(L"$progdir", sProgDir);
65
 
89
 
66
	// relative path
90
	// relative path
67
	if ( !fname.IsIn(":") )
91
	if ( !fname.contains(L":") )
68
		fname = sDir + "/" + filename;
92
		fname = sDir + L"/" + filename;
69
	fname = fname.FindReplace("\\", "/"); // make sure we're using the correct slash
93
	fname = fname.findReplace(L"\\", L"/"); // make sure we're using the correct slash
70
	fname = fname.FindReplace("//", "/"); // remove any double slashes
94
	fname = fname.findReplace(L"//", L"/"); // remove any double slashes
71
	CyString dir = fname.GetToken("/", 1, -1);
95
	Utils::WString dir = fname.tokens(L"/", 1);
72
 
96
 
73
	m_sScriptDir = dir;
97
	m_sScriptDir = dir;
74
	m_sProgDir = sProgDir;
98
	m_sProgDir = sProgDir;
75
	m_sGameDir = sDir;
99
	m_sGameDir = sDir;
76
 
100
 
77
	FILE *id = fopen ( fname.c_str(), "r" );
101
	FILE *id = _wfopen ( fname.c_str(), L"r" );
78
	if ( id )
102
	if ( id )
79
	{
103
	{
80
		int iLine = 0;
104
		int iLine = 0;
81
		while ( !feof(id) )
105
		while ( !feof(id) )
82
		{
106
		{
83
			CyString line;
107
			Utils::WString line;
84
			line = line.GetEndOfLine ( id, &iLine, false );
108
			line = GetEndOfLine ( id, &iLine, false );
85
			if ( (line.Left (2) == "//") || (line.Empty()) )
109
			if ( (line.left (2) == L"//") || (line.empty()) )
86
				continue;
110
				continue;
87
			CyString arg = line.GetToken ( 1, ' ' ).ToLower();
111
			Utils::WString arg = line.token(L" ", 1).lower();
88
			if ( arg == "displayfor:" )
112
			if ( arg == L"displayfor:" )
89
			{
113
			{
90
				m_iCycles = line.GetToken ( 2, ' ' ).ToInt();
114
				m_iCycles = line.token(L" ", 2).toInt();
91
				if ( (!m_iCycles) || (m_iCycles < 0) )
115
				if ( (!m_iCycles) || (m_iCycles < 0) )
92
					m_lDebugLog.PushBack ( CyString((long)iLine) + (CyString(": Invalid argument for \"DisplayFor\" (") + line.GetToken ( 2, ' &apos; )) + ")", false );
116
					_lDebugLog.pushBack (Utils::WString((long)iLine) + L": Invalid argument for \"DisplayFor\" (" + line.token(L" ";, 2) + L")");
93
			}
117
			}
94
			else if ( arg == "debug" )
118
			else if ( arg == L"debug" )
95
				m_bDebug = true;
119
				m_bDebug = true;
96
			else if ( arg == "varible:" )
120
			else if ( arg == L"varible:" )
97
			{
121
			{
98
				if ( line.NumToken ( ' &apos; ) < 2 )
122
				if ( line.countToken(L" ";) < 2)
99
					m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(&quot;: Missing Argument for \"Varible\""), false );
123
					_lDebugLog.pushBack(Utils::WString((long)iLine) + L&quot;: Missing Argument for \"Varible\"");
100
				else
124
				else
101
					m_lVaribles.PushBack ( line.GetToken ( 2, ' &apos; ) );
125
					_lVaribles.pushBack(line.token(L&quot; ", 2));
102
			}
126
			}
103
			else if ( arg == "icon:" )
127
			else if ( arg == L"icon:" )
104
			{
128
			{
105
				if ( line.NumToken ( ' &apos; ) < 6 )
129
				if ( line.countToken(L" ";) < 6)
106
					m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(&quot;: Missing Arguments for \"Icon\""), false );
130
					_lDebugLog.pushBack(Utils::WString((long)iLine) + L&quot;: Missing Arguments for \"Icon\"");
107
				else
131
				else
108
				{
132
				{
109
					CyString sIcon = line.GetToken ( 6, -1, &apos; &apos; );
133
					Utils::WString sIcon = line.tokens(L&quot; &quot;, 6);
110
					int iSizeX = line.GetToken ( 4, &apos; &apos; ).ToInt();
134
					int iSizeX = line.token(L&quot; &quot;, 4).toInt();
111
					int iSizeY = line.GetToken ( 5, &apos; &apos; ).ToInt();
135
					int iSizeY = line.token(L&quot; &quot;, 5).toInt();
112
					HICON hIcon = static_cast<HICON>(LoadImage(0, (LPCTSTR)ParseFilename(sIcon, dir).c_str(), IMAGE_ICON, iSizeX, iSizeY, LR_LOADFROMFILE));
136
					HICON hIcon = static_cast<HICON>(LoadImage(0, (LPCTSTR)parseFilename(sIcon, dir).c_str(), IMAGE_ICON, iSizeX, iSizeY, LR_LOADFROMFILE));
113
					if ( FAILED (hIcon) )
137
					if ( FAILED (hIcon) )
114
						m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(": Unable to open icon file: ") + sIcon, false );
138
						_lDebugLog.pushBack (Utils::WString((long)iLine) + L": Unable to open icon file: " + sIcon);
115
					else
139
					else
116
					{
140
					{
117
						m_pHandles[iCurrentPos] = m_pLcd->AddIcon(hIcon, iSizeX, iSizeY);
141
						m_pHandles[iCurrentPos] = m_pLcd->AddIcon(hIcon, iSizeX, iSizeY);
118
						int iX = line.GetToken ( 2, ' &apos; ).ToInt ();
142
						int iX = line.token(L&quot; ", 2).toInt();
119
						int iY = line.GetToken ( 3, ' &apos; ).ToInt ();
143
						int iY = line.token (L&quot; ", 3).toInt();
120
						m_pLcd->SetOrigin ( m_pHandles[iCurrentPos], iX, iY );
144
						m_pLcd->SetOrigin ( m_pHandles[iCurrentPos], iX, iY );
121
						iLastX = iX;
145
						iLastX = iX;
122
						iLastY = iY;
146
						iLastY = iY;
123
						iCurrentPos++;
147
						iCurrentPos++;
124
					}
148
					}
125
				}
149
				}
126
			}
150
			}
127
			else if ( (arg == "move:") || (arg == "moverepeat:") )
151
			else if ( (arg == L"move:") || (arg == L"moverepeat:") )
128
			{
152
			{
129
				if ( line.NumToken ( ' &apos; ) < 4 )
153
				if ( line.countToken(L" ";) < 4)
130
					m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(&quot;: Missing Argument for \"Move\""), false );
154
					_lDebugLog.pushBack(Utils::WString((long)iLine) + L&quot;: Missing Argument for \"Move\"");
131
				else if ( !iCurrentPos )
155
				else if ( !iCurrentPos )
132
					m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(": No object before move command"), false );
156
					_lDebugLog.pushBack(Utils::WString((long)iLine) + L": No object before move command");
133
				else
157
				else
134
				{
158
				{
135
					SMoveObject *o = new SMoveObject;
159
					SMoveObject *o = new SMoveObject;
136
					o->hObject = m_pHandles[iCurrentPos - 1];
160
					o->hObject = m_pHandles[iCurrentPos - 1];
137
					if ( arg == "moverepeat:" )
161
					if ( arg == L"moverepeat:" )
138
						o->bRepeat = true;
162
						o->bRepeat = true;
139
					else
163
					else
140
						o->bRepeat = false;
164
						o->bRepeat = false;
141
					o->iStartX = iLastX;
165
					o->iStartX = iLastX;
142
					o->iStartY = iLastY;
166
					o->iStartY = iLastY;
143
					if ( line.GetToken ( 2, ' ' ) == ";-" )
167
					if ( line.token(L" ", 2) == L";-")
144
						o->iEndX = o->iStartX;
168
						o->iEndX = o->iStartX;
145
					else
169
					else
146
						o->iEndX = line.GetToken ( 2, &apos; &apos; ).ToInt();
170
						o->iEndX = line.token(L&quot; &quot;, 2).toInt();
147
					if ( line.GetToken ( 3, ' ' ) == ";-" )
171
					if ( line.token(L" ", 3) == L";-")
148
						o->iEndY = o->iStartY;
172
						o->iEndY = o->iStartY;
149
					else
173
					else
150
						o->iEndY = line.GetToken ( 3, &apos; &apos; ).ToInt();
174
						o->iEndY = line.token(L&quot; &quot;, 3).toInt();
151
					o->iTimeRemaining = o->iTotalTime = line.GetToken ( 4, &apos; &apos; ).ToInt();
175
					o->iTimeRemaining = o->iTotalTime = line.token(L&quot; &quot;, 4).toInt();
152
					AddMoveObject ( o );
176
					AddMoveObject ( o );
153
				}
177
				}
154
			}
178
			}
155
			else if ( ((arg.Left(9) == "textsmall") || (arg.Left(10) == "textmedium") || (arg.Left(9) == "textlarge")) && (arg.Right(1) == ":") )
179
			else if ( ((arg.left(9) == L"textsmall") || (arg.left(10) == L"textmedium") || (arg.left(9) == L"textlarge")) && (arg.right(1) == L":") )
156
			{
180
			{
157
				if ( line.NumToken ( ' &apos; ) < 6 )
181
				if ( line.countToken(L" ";) < 6)
158
					m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(&quot;: Missing Argument for \"Text\""), false );
182
					_lDebugLog.pushBack(Utils::WString((long)iLine) + L&quot;: Missing Argument for \"Text\"");
159
				else
183
				else
160
				{
184
				{
161
					CyString align = line.GetToken ( 5, &apos; &apos; ).ToLower();
185
					Utils::WString align = line.token(L&quot; &quot;, 5).lower();
162
					int iAlign = DT_CENTER;
186
					int iAlign = DT_CENTER;
163
					if ( align == "center" )
187
					if ( align == "center" )
164
						iAlign = DT_CENTER;
188
						iAlign = DT_CENTER;
165
					else if ( align == "left" )
189
					else if ( align == "left" )
166
						iAlign = DT_LEFT;
190
						iAlign = DT_LEFT;
167
					else if ( align == "right" )
191
					else if ( align == "right" )
168
						iAlign = DT_RIGHT;
192
						iAlign = DT_RIGHT;
169
					else
193
					else
170
						m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(": Invalid alignment setting \"") + align + "\"", false );
194
						_lDebugLog.pushBack(Utils::WString((long)iLine) + L": Invalid alignment setting \"" + align + L"\"");
171
 
195
 
172
					LGTextSize iSize = LG_SMALL;
196
					LGTextSize iSize = LG_SMALL;
173
					if ( arg.Left(10) == "textmedium" )
197
					if ( arg.left(10) == L"textmedium" )
174
						iSize = LG_MEDIUM;
198
						iSize = LG_MEDIUM;
175
					else if ( arg.Left(9) == "textsmall" )
199
					else if ( arg.left(9) == L"textsmall" )
176
						iSize = LG_SMALL;
200
						iSize = LG_SMALL;
177
					else if ( arg.Left(9) == "textlarge" )
201
					else if ( arg.left(9) == L"textlarge" )
178
						iSize = LG_BIG;
202
						iSize = LG_BIG;
179
 
203
 
180
					bool scroll = false;
204
					bool scroll = false;
181
					if ( arg.Right (7) == "Scroll:" )
205
					if ( arg.right (7) == L"Scroll:" )
182
						scroll = true;
206
						scroll = true;
183
 
207
 
184
					int len = line.GetToken ( 4, &apos; &apos; ).ToInt();
208
					int len = line.token(L&quot; &quot;, 4).toInt();
185
					int x = line.GetToken ( 2, ' &apos; ).ToInt ();
209
					int x = line.token(L&quot; ", 2).toInt();
186
					int y = line.GetToken ( 3, ' &apos; ).ToInt ();
210
					int y = line.token(L&quot; ", 3).toInt();
187
					CyString str = line.GetToken ( 6, -1, &apos; &apos; );
211
					Utils::WString str = line.tokens(L&quot; &quot;, 6);
188
					m_pHandles[iCurrentPos] = m_pLcd->AddText ( (scroll) ? LG_SCROLLING_TEXT : LG_STATIC_TEXT, iSize, iAlign, len );
212
					m_pHandles[iCurrentPos] = m_pLcd->AddText ( (scroll) ? LG_SCROLLING_TEXT : LG_STATIC_TEXT, iSize, iAlign, len );
189
					m_pLcd->SetOrigin ( m_pHandles[iCurrentPos], x, y );
213
					m_pLcd->SetOrigin ( m_pHandles[iCurrentPos], x, y );
190
					m_pLcd->SetText ( m_pHandles[iCurrentPos], (LPCTSTR)str.c_str() );
214
					m_pLcd->SetText ( m_pHandles[iCurrentPos], (LPCTSTR)str.c_str() );
191
 
215
 
192
					SText *text = new SText;
216
					SText *text = new SText;
Line 195... Line 219...
195
					AddText ( text );
219
					AddText ( text );
196
					iCurrentPos++;
220
					iCurrentPos++;
197
				}
221
				}
198
			}
222
			}
199
			else
223
			else
200
				m_lDebugLog.PushBack ( CyString((long)iLine) + CyString(": Invalid Command: ") + arg );
224
				_lDebugLog.pushBack(Utils::WString((long)iLine) + L": Invalid Command: " + arg );
201
 
225
 
202
			if ( iCurrentPos >= m_iArraySize )
226
			if ( iCurrentPos >= m_iArraySize )
203
				IncreaseArraySize();
227
				IncreaseArraySize();
204
		}
228
		}
205
 
229
 
Line 219... Line 243...
219
		m_iCycles = 100;
243
		m_iCycles = 100;
220
 
244
 
221
	return true;
245
	return true;
222
}
246
}
223
 
247
 
224
void CLcdCustomScreen::SetVarible ( CyString v, int pos )
248
void CLcdCustomScreen::setVarible(const Utils::WString &v, size_t pos )
225
{
249
{
226
	if ( pos >= m_lVaribles.Count() )
250
	if ( pos >= _lVaribles.size() )
227
		return;
251
		return;
228
 
252
 
229
	m_lVaribles.GetAt ( pos )->data = v;
253
	_lVaribles[pos]->data = v;
230
}
254
}
231
 
255
 
232
void CLcdCustomScreen::Reset ()
256
void CLcdCustomScreen::Reset ()
233
{
257
{
234
	m_pLcd->RemovePage ( m_iStartPage + 1 );
258
	m_pLcd->RemovePage ( m_iStartPage + 1 );
235
	m_pLcd->RemovePage ( m_iStartPage );
259
	m_pLcd->RemovePage ( m_iStartPage );
236
 
260
 
237
	m_lDebugLog.Clear();
261
	_lDebugLog.clear();
238
	m_lVaribles.Clear();
262
	_lVaribles.clear();
239
 
263
 
240
	SMoveObject *o = m_pMoveObject;
264
	SMoveObject *o = m_pMoveObject;
241
	while ( o )
265
	while ( o )
242
	{
266
	{
243
		SMoveObject *next = o->pNext;
267
		SMoveObject *next = o->pNext;
244
		delete o;
268
		delete o;
245
		o = next;
269
		o = next;
246
	}
270
	}
247
 
271
 
248
	SText *t = m_pText;
272
	SText *t = m_pText;
249
	while ( t )
273
	while ( t )
250
	{
274
	{
251
		SText *next = t->pNext;
275
		SText *next = t->pNext;
252
		delete t;
276
		delete t;
Line 286... Line 310...
286
 
310
 
287
	if ( m_bDebug )
311
	if ( m_bDebug )
288
	{
312
	{
289
		m_pLcd->ShowPage ( m_iStartPage + 1 );
313
		m_pLcd->ShowPage ( m_iStartPage + 1 );
290
	    m_pLcd->ModifyControlsOnPage ( m_iStartPage + 1 );
314
	    m_pLcd->ModifyControlsOnPage ( m_iStartPage + 1 );
-
 
315
 
291
		SStringList *str = m_lDebugLog.Head();
316
		if (_lDebugLog.empty())
292
		for ( int i = 0; i &lt; 5; i++ )
317
			m_pLcd->SetText(m_hDebug[0], _T(&quot;No errors found!"));
-
 
318
		else
293
		{
319
		{
294
			if ( !str )
320
			size_t max = _lDebugLog.size() > 5 ? 5 : _lDebugLog.size();
295
				break;
321
			for (size_t i = 0; i < max; i++)
296
			m_pLcd->SetText ( m_hDebug[i], (LPCTSTR)str->str.c_str() );
322
				m_pLcd->SetText(m_hDebug[i], _lDebugLog[i]->str);
297
			str = str->next;
-
 
298
		}
323
		}
299
 
324
 
300
		if ( !m_lDebugLog.Head() )
-
 
301
			m_pLcd->SetText ( m_hDebug[0], _T("No errors found!") );
-
 
302
	}
325
	}
303
	else
326
	else
304
	{
327
	{
305
		m_pLcd->ShowPage ( m_iStartPage );
328
		m_pLcd->ShowPage ( m_iStartPage );
306
	    m_pLcd->ModifyControlsOnPage ( m_iStartPage );
329
	    m_pLcd->ModifyControlsOnPage ( m_iStartPage );
307
 
330
 
308
		for ( SText *text = m_pText; text; text = text->pNext )
331
		for ( SText *text = m_pText; text; text = text->pNext )
309
		{
332
		{
310
 
-
 
311
			CyString newtext = text->sText;
333
			Utils::WString newtext = text->sText;
312
			for ( SStringList *v = m_lVaribles.Head(); v; v = v->;next )
334
			for(auto itr = _lVaribles.begin(); itr != _lVaribles.end(); itr++)
313
				newtext.FindReplace ( CyString("$&quot;) + v->str, v->data );
335
				newtext = newtext.findReplace(L"$&quot; + (*itr)->str, (*itr)->data );
314
			m_pLcd->SetText ( text->hObject, (LPCTSTR)newtext.c_str() );
336
			m_pLcd->SetText ( text->hObject, newtext);
315
		}
337
		}
316
 
338
 
317
		// now do moving objects
339
		// now do moving objects
318
		for ( SMoveObject *o = m_pMoveObject; o; o = o->pNext )
340
		for ( SMoveObject *o = m_pMoveObject; o; o = o->pNext )
319
		{
341
		{