Filter:   InfoImg
download interface.cc
Language: C++
LOC: 294
Project Info
Ultima Online Project(uop)
Server: SourceForge
Type: cvs
SourceForge\u\uop\uop\uop\
   acinclude.m4
   aclocal.m4
   action.cc
   action.h
   animation.cc
   animation.h
   artexport.cc
   artfactory.cc
   artfactory.h
   audio.cc
   audio.h
   btree.cc
   btree.h
   cache.h
   cliloc.cc
   cliloc.h
   config.h.in
   configure.in
   cvs2cl.pl
   entity.cc
   entity.h
   gumps.cc
   gumps.h
   interface.cc
   interface.h
   interfacegumps.cc
   interfacegumps.h
   interfacehandler.cc
   interfacehandler.h
   intrface.def
   Makefile.am
   Makefile.in
   message.cc
   message.h
   musicmap.def
   network.cc
   network.h
   patchhandler.cc
   patchhandler.h
   readable.pl
   serverhandler.cc
   serverhandler.h
   sprite.cc
   sprite.h
   stamp-h.in
   texthandler.cc
   texthandler.h
   tiledata.cc
   tiledata.h
   unreadable.pl
   uop.cc
   uop.cfg
   uop.dox
   uop.h
   uopconfig.cc
   uopconfig.h
   uosprite.h
   uostub.pl
   world.cc
   world.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
// vim:ts=2 sw=2
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "uop.h"
#include <iostream>
#include "interface.h"
#include "gumps.h"
#include "uopconfig.h"
#include "action.h"
#include "network.h"
#include "interfacehandler.h"
#include "world.h"

extern UOPConfig *config;
extern Gumps *gumps;
extern Action *action;
extern Network *network;
extern Interface *intrface;
extern InterfaceHandler *interfaceHandler;

Interface::Interface()
{
}
Interface::~Interface()
{
}

void Interface::loadDef()
{
	string line;

	string intrfname=config->encapDatLoc("intrface.def");
	deffile.open(intrfname.c_str());
	if (!deffile.is_open())
	{
#ifdef HAVE_CONFIG_H
		intrfname = DATADIR;
		intrfname += "/intrface.def";
		deffile.open(intrfname.c_str());
		if (!deffile.is_open())
		{
#endif
			cerr<<"Couldn't open "<<intrfname<<endl;
			exit(1);
#ifdef HAVE_CONFIG_H
		}
#endif
	}
	deffile.seekg(0,ios::end);
	deflen=deffile.tellg();
	deffile.seekg(4);
	deflen-=4;
	defbuffer=new char[deflen];
	deffile.read(defbuffer,deflen);
	deffile.close();
	defptr=0;

	string *workingLines=new string[256];
	int numLines=0;
	int numObjects=0;
	InterfaceObject *workingObjects[40];

	while (readLine(line))
	{
		int comments=line.find("//");
		if (comments>=0)
			line=line.substr(0,comments);
		int triml=line.find_first_not_of(" ");
		int trimr=line.find_last_not_of(" ");
		if (triml<0 || trimr<0) continue;
		line=line.substr(triml,trimr-triml);
		if (line.length()==0) continue;
		if (line[0]=='#')
		{
			triml=line.find_first_not_of(" ",1);
			if (triml<0) continue;
			line=line.substr(triml);
			if (line=="enddef")
			{
				for (int i=0;i<numObjects;i++)
				{
					workingObjects[i]->numLines=numLines;
					workingObjects[i]->lines=new string[numLines];
					for (int l=0;l<numLines;l++)
						workingObjects[i]->lines[l]=workingLines[l];
					objects[workingObjects[i]->name]=workingObjects[i];
				}
				numObjects=0;
				numLines=0;
			}
			else
				workingObjects[numObjects++]=new InterfaceObject(line);
		}
		else
			workingLines[numLines++]=line;
	}
	delete [] defbuffer;
}

bool Interface::readLine(string &line)
{
	char ch;
	line="";
	do {
		ch=defbuffer[defptr++];
		if (ch!='\n') line+=ch;
		defptr++;
	} while (defptr<deflen && ch!='\n');
	return defptr<deflen;
}

GumpMain *Interface::getGump(string gump)
{
	if (objects[gump]) return objects[gump]->getGump();
	return NULL;
}



InterfaceObject::InterfaceObject(string &name)
{
	this->name=name;
}

GumpMain *InterfaceObject::getGump()
{
	GumpMain *gump=new GumpMain(name);
	for (int i=0;i<numLines;i++)
	{
		int tokenlen=lines[i].find_first_of(" ");
		string args="";
		if (tokenlen<0)
			tokenlen=lines[i].length();
		else
			args=lines[i].substr(tokenlen+1);
		string token=lines[i].substr(0,tokenlen);

		//cerr<<token<<endl;
		if (token[0]=='\t') // tabbed continuation of previous gump
		{
			token=token.substr(1);
			if (token=="fontnumber")
			{
				GumpFontNumber *fn=new GumpFontNumber(args);
				gump->getLast()->fontNumber=fn->fontNumber;
				delete fn;
			}
			if (token=="emboss")
				gump->getLast()->emboss=true;
			if (token=="engrave")
				gump->getLast()->engrave=true;
		}
		if (token=="rect") {
			GumpRect *r=new GumpRect(args);
			gump->sx=r->sx;
			gump->sy=r->sy;
			gump->sw=r->sw;
			gump->sh=r->sh;
			gump->hasRect=true;
			delete r;
		}
		if (token=="partialhue") {
			GumpPartialHue *ph=new GumpPartialHue(args);
			gump->partial=ph->partial;
			delete ph;
		}
		if (token=="fontcolor") {
			GumpFontColor *fc=new GumpFontColor(args);
			gump->fontcolor=fc->fontcolor;
			delete fc;
		}
		if (token=="fancypantsaccountlogincastleandsunthingy") {
			string tempCastle("9001 0 0 0");
			gump->add(new GumpBackground(tempCastle));
		}
		if (token=="background") gump->add(new GumpBackground(args));
		if (token=="interface") gump->add(new GumpInterface(args));
		if (token=="sizablebackground") gump->add(new GumpSizableBackground(args));
		if (token=="button") gump->add(new GumpButton(args));
		if (token=="include") {
			GumpMain *inc=intrface->getGump(args);
			if (inc->hasRect)
			{
				gump->sx=inc->sx;
				gump->sy=inc->sy;
				gump->sw=inc->sw;
				gump->sh=inc->sh;
				inc->sx="0"; inc->sy="0";
				inc->sw="R"; inc->sh="B";
			}
			gump->add(inc);
		}
		if (token=="layoutbutton") gump->add(new GumpLayoutButton(args));
		if (token=="decoration") gump->add(new GumpDecoration(args));
		if (token=="text") gump->add(new GumpText(args));
		if (token=="interfacebutton") gump->add(new GumpInterfaceButton(args));
		if (token=="interfaceradiobutton")
			gump->add(new GumpInterfaceRadioButton(args));
		if (token=="textarea")
			gump->add(interfaceHandler->registerTextArea(new GumpTextArea(args)));
		if (token=="numerictextarea")
			gump->add(interfaceHandler->registerTextArea(new GumpTextArea(args)));
		if (token=="layouttoggle") gump->add(new GumpLayoutToggle(args));
		if (token=="toggle") gump->add(new GumpToggle(args));
		if (token=="vlist")
			gump->add(interfaceHandler->registerVList(new GumpVList(args)));
		if (token=="colorpicker") gump->add(interfaceHandler->registerColorPicker(new GumpColorPicker(args)));
		if (token=="hscrollbar") gump->add(new GumpHScrollBar(args));
		if (token=="scene") gump->add(new Scene());
	}
	return gump;
}

/****** eval stuff ******/

static bool isOperator(char op,int &level)
{
	if (op=='*' || op=='/') level=2;
	else if (op=='+' || op=='-') level=1;
	else return false;
	return true;
}

static int findLowOp(const string &s)
{
	int n=-1,level,min=3;
	char ch;
	int numParens=0;
	for (unsigned int i=0;i<s.length();i++)
	{
		ch=s[i];
		if (ch=='(') numParens++;
		else if (ch==')') numParens--;
		else if (isOperator(ch,level) && !numParens)
			if (level<=min)
			{
				n=i;
				min=level;
			}
	}
	return n;
}

Sint16 myEval(string s,Sint16 w,Sint16 h)
{
	if (s=="") return 0;
	int numParens;
	int n;
	if (s[0]=='(' && s[s.length()-1]==')')
	{
		numParens=1;
		n=0;
		while (numParens)	//this will totally hose if the parens are unbalanced
		{
			n++;
			if (s[n]=='(') numParens++;
			else if (s[n]==')') numParens--;
		}
		if (n==(int)s.length()-1)
			return myEval(s.substr(1,s.length()-2),w,h); //unwrap parens
	}
	n=findLowOp(s);
	if (n==-1)
	{
		if (s=="R") return w;
		if (s=="B") return h;
		if (s[0]=='g' && s[1]=='w' && (s[2]=='w' || s[2]=='h'))
		{
			if (s[2]=='w') return 640;
			if (s[2]=='h') return 480;
		}
		if (s[0]=='g' && (s[1]=='w' || s[1]=='h'))
		{
			Sint16 v=0;
			for (unsigned int i=2;i<s.length();i++)
			{
				v*=10;
				v+=s[i]-'0';
			}
			GumpIndex &idx=gumps->getIndex(v);
			if (s[1]=='w') return idx.width;
			else return idx.height;
		}
		if (s[0]=='s' && (s[1]=='w' || s[1]=='h'))
		{
			if (s[1]=='w') return 640;
			else return 480;
		}
		Sint16 v=0;
		for (unsigned int i=0;i<s.length();i++)
		{
			v*=10;
			v+=s[i]-'0';
		}
		return v;
	}
	else
	{
		char oper=s[n];
		Sint16 l,r;
		l=myEval(s.substr(0,n),w,h);
		r=myEval(s.substr(n+1,s.length()-n-1),w,h);
		switch (oper)
		{
			case '+': return l+r;
			case '-': return l-r;
			case '*': return l*r;
			case '/':	return l/r;
			default: cerr<<"DOH"<<endl; break;
		}
	}
	return 0;
}