[go: up one dir, main page]

Menu

[r59]: / engine / gui / editarea.cpp  Maximize  Restore  History

Download this file

458 lines (374 with data), 10.8 kB

  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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
* Stand-alone editor for defining Large Object sizes
* (Actually part of the world editor, invoked with ed -area <object>)
*/
#include <stdio.h>
#include "../ithelib.h"
#include "../gui/igui.hpp"
#include "../console.h"
#include "../core.hpp"
#include "../gamedata.h"
#include "../media.h"
#include "../init.h"
#include "../gui/menusys.h"
// defines
#undef VIEWX // Need to override this
#undef VIEWY
#define VIEWX 64
#define VIEWY 112
// variables
static int Polarity=0,Direction=0;
static int Edit_H_Id,Edit_V_Id,sol_x_Id,sol_y_Id,sol_w_Id,sol_h_Id,act_x_Id,act_y_Id,act_w_Id,act_h_Id;
static int curchr=0;
static char sol_x_str[] ="0 ";
static char sol_y_str[] ="0 ";
static char sol_w_str[] ="0 ";
static char sol_h_str[] ="0 ";
static char act_x_str[] ="0 ";
static char act_y_str[] ="0 ";
static char act_w_str[] ="0 ";
static char act_h_str[] ="0 ";
static char Out1_str[32];
static char Out2_str[32];
static char Out3_str[32];
static char Out4_str[32];
// functions
static void EditSize();
static void Size_Update();
static void SetPolarityV();
static void SetPolarityH();
static void SetSolidX();
static void SetSolidY();
static void SetSolidW();
static void SetSolidH();
static void SetActiveX();
static void SetActiveY();
static void SetActiveW();
static void SetActiveH();
static void Flip();
static void Finish();
static void PickChar();
extern void GetOBFromList( int x0, int y0, char *prompt, int listsize, char **list, char *name);
//extern void OB_Thumb(int x,int y,char *name);
// code
/*
* Entry point (from editor startup)
*/
void EditArea(char *obj)
{
curchr=getnum4char(obj);
if(curchr == -1)
ithe_panic("Cannot find object called",obj);
// Start the GUI engine
irecon_term();
ilog_break=0; // Disable break now we're ready
IG_Init(128); // Set up the iGUI for max 128 buttons
focus=0;
// Backing
SetColor(ITG_BLACK);
IG_KillAll();
IG_Panel(0,0,640,480);
show_mouse(NULL); // MOUSE HACK
EditSize();
show_mouse(swapscreen); // MOUSE HACK
do
{
IG_Dispatch();
} while(running); // Loop until quit
IG_Term(); // Free the iGUI resources
term_media();
exit(1);
}
void EditSize()
{
focus=0;
Polarity=0; // V
Direction=CHAR_L;
IG_KillAll();
DrawScreenBox3D(32,32,608,400);
setcolor(ITG_WHITE);
Edit_H_Id = IG_Tab(48,48,"Horizontal",SetPolarityH,NULL,NULL);
Edit_V_Id = IG_Tab(152,48,"Vertical",SetPolarityV,NULL,NULL);
IG_TextButton(240,48,"Flip direction",Flip,NULL,NULL);
IG_TextButton(368,352,"New Object",PickChar,NULL,NULL);
IG_TextButton(528,352,"Quit",Finish,NULL,NULL);
IG_BlackPanel(VIEWX-2,VIEWY-2,260,260);
setcolor(ITG_WHITE);
DrawScreenText(384,96,"SOLID X offset:");
DrawScreenText(384,128,"SOLID Y offset:");
DrawScreenText(384,160,"SOLID Width:");
DrawScreenText(384,192,"SOLID Height:");
sol_x_Id = IG_InputButton(524,88,sol_x_str,SetSolidX,NULL,NULL);
sol_y_Id = IG_InputButton(524,120,sol_y_str,SetSolidY,NULL,NULL);
sol_w_Id = IG_InputButton(524,152,sol_w_str,SetSolidW,NULL,NULL);
sol_h_Id = IG_InputButton(524,184,sol_h_str,SetSolidH,NULL,NULL);
setcolor(ITG_DARKRED);
DrawScreenText(384,224,"ACTIVE X offset:");
DrawScreenText(384,256,"ACTIVE Y offset:");
DrawScreenText(384,288,"ACTIVE Width:");
DrawScreenText(384,320,"ACTIVE Height:");
act_x_Id = IG_InputButton(524,216,act_x_str,SetActiveX,NULL,NULL);
act_y_Id = IG_InputButton(524,248,act_y_str,SetActiveY,NULL,NULL);
act_w_Id = IG_InputButton(524,280,act_w_str,SetActiveW,NULL,NULL);
act_h_Id = IG_InputButton(524,312,act_h_str,SetActiveH,NULL,NULL);
IG_AddKey(KEY_SPACE,Flip);
IG_AddKey(KEY_ESC,Finish);
Size_Update();
}
void Size_Update()
{
SEQ_POOL *form;
// Recalc WxH levels for this object
Init_Areas(&CHlist[curchr]);
if(Polarity == 0)
{
IG_SetFocus(Edit_H_Id);
IG_ResetFocus(Edit_V_Id);
}
else
{
IG_ResetFocus(Edit_H_Id);
IG_SetFocus(Edit_V_Id);
}
form = &SQlist[CHlist[curchr].dir[Direction]];
fbox2(0,0,256,256,ITG_BLUE,gamewin);
if(Polarity == 0)
{
// Horizontal
draw_rle_sprite(gamewin,form->seq[0]->image,0,0);
if(form->overlay)
draw_rle_sprite(gamewin,form->overlay->image,0,0);
ClipBox(CHlist[curchr].hblock[BLK_X]*32,CHlist[curchr].hblock[BLK_Y]*32,(CHlist[curchr].hblock[BLK_W]*32),(CHlist[curchr].hblock[BLK_H]*32),ITG_WHITE,gamewin);
ClipBox((CHlist[curchr].harea[BLK_X]*32)+1,CHlist[curchr].harea[BLK_Y]*32+1,(CHlist[curchr].harea[BLK_W]*32)-1,(CHlist[curchr].harea[BLK_H]*32)-1,ITG_RED,gamewin);
sprintf(sol_x_str,"%-3d",CHlist[curchr].hblock[BLK_X]);
sprintf(sol_y_str,"%-3d",CHlist[curchr].hblock[BLK_Y]);
sprintf(sol_w_str,"%-3d",CHlist[curchr].hblock[BLK_W]);
sprintf(sol_h_str,"%-3d",CHlist[curchr].hblock[BLK_H]);
sprintf(act_x_str,"%-3d",CHlist[curchr].harea[BLK_X]);
sprintf(act_y_str,"%-3d",CHlist[curchr].harea[BLK_Y]);
sprintf(act_w_str,"%-3d",CHlist[curchr].harea[BLK_W]);
sprintf(act_h_str,"%-3d",CHlist[curchr].harea[BLK_H]);
}
else
{
// Vertical
draw_rle_sprite(gamewin,form->seq[0]->image,0,0);
if(form->overlay)
draw_rle_sprite(gamewin,form->overlay->image,0,0);
ClipBox(CHlist[curchr].vblock[BLK_X]*32,CHlist[curchr].vblock[BLK_Y]*32,(CHlist[curchr].vblock[BLK_W]*32),(CHlist[curchr].vblock[BLK_H]*32),ITG_WHITE,gamewin);
ClipBox((CHlist[curchr].varea[BLK_X]*32)+1,(CHlist[curchr].varea[BLK_Y]*32)+1,(CHlist[curchr].varea[BLK_W]*32)-1,(CHlist[curchr].varea[BLK_H]*32)-1,ITG_RED,gamewin);
sprintf(sol_x_str,"%-3d",CHlist[curchr].vblock[BLK_X]);
sprintf(sol_y_str,"%-3d",CHlist[curchr].vblock[BLK_Y]);
sprintf(sol_w_str,"%-3d",CHlist[curchr].vblock[BLK_W]);
sprintf(sol_h_str,"%-3d",CHlist[curchr].vblock[BLK_H]);
sprintf(act_x_str,"%-3d",CHlist[curchr].varea[BLK_X]);
sprintf(act_y_str,"%-3d",CHlist[curchr].varea[BLK_Y]);
sprintf(act_w_str,"%-3d",CHlist[curchr].varea[BLK_W]);
sprintf(act_h_str,"%-3d",CHlist[curchr].varea[BLK_H]);
}
IG_UpdateText(sol_x_Id,sol_x_str);
IG_UpdateText(sol_y_Id,sol_y_str);
IG_UpdateText(sol_w_Id,sol_w_str);
IG_UpdateText(sol_h_Id,sol_h_str);
IG_UpdateText(act_x_Id,act_x_str);
IG_UpdateText(act_y_Id,act_y_str);
IG_UpdateText(act_w_Id,act_w_str);
IG_UpdateText(act_h_Id,act_h_str);
// Draw it
draw_sprite(swapscreen,gamewin,VIEWX,VIEWY);
// Write out the goodies
sprintf(Out1_str,"setsolid V %d %d %d %d",CHlist[curchr].vblock[BLK_X],CHlist[curchr].vblock[BLK_Y],CHlist[curchr].vblock[BLK_W],CHlist[curchr].vblock[BLK_H]);
sprintf(Out2_str,"setsolid H %d %d %d %d",CHlist[curchr].hblock[BLK_X],CHlist[curchr].hblock[BLK_Y],CHlist[curchr].hblock[BLK_W],CHlist[curchr].hblock[BLK_H]);
sprintf(Out3_str,"setactivearea V %d %d %d %d",CHlist[curchr].varea[BLK_X],CHlist[curchr].varea[BLK_Y],CHlist[curchr].varea[BLK_W],CHlist[curchr].varea[BLK_H]);
sprintf(Out4_str,"setactivearea H %d %d %d %d",CHlist[curchr].harea[BLK_X],CHlist[curchr].harea[BLK_Y],CHlist[curchr].harea[BLK_W],CHlist[curchr].harea[BLK_H]);
//fbox2(32,416,256,32,makecol(200,200,200),gamewin);
IG_BlackPanel(36,416,256,44);
DrawScreenText(40,424,Out1_str);
DrawScreenText(40,432,Out2_str);
DrawScreenText(40,440,Out3_str);
DrawScreenText(40,448,Out4_str);
}
void SetPolarityH()
{
Polarity=0;
Direction=CHAR_L;
Size_Update();
}
void SetPolarityV()
{
Polarity=1;
Direction=CHAR_D;
Size_Update();
}
void SetSolidX()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].hblock[BLK_X];
CHlist[curchr].hblock[BLK_X] = InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].vblock[BLK_X];
CHlist[curchr].vblock[BLK_X]= InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetSolidY()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].hblock[BLK_Y];
CHlist[curchr].hblock[BLK_Y] = InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].vblock[BLK_Y];
CHlist[curchr].vblock[BLK_Y] = InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetSolidW()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].hblock[BLK_W];
CHlist[curchr].hblock[BLK_W]= InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].vblock[BLK_W];
CHlist[curchr].vblock[BLK_W]= InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetSolidH()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].hblock[BLK_H];
CHlist[curchr].hblock[BLK_H]= InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].vblock[BLK_H];
CHlist[curchr].vblock[BLK_H]= InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetActiveX()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].harea[BLK_X];
CHlist[curchr].harea[BLK_X]= InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].varea[BLK_X];
CHlist[curchr].varea[BLK_X]= InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetActiveY()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].harea[BLK_Y];
CHlist[curchr].harea[BLK_Y] = InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].varea[BLK_Y];
CHlist[curchr].varea[BLK_Y] = InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetActiveW()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].harea[BLK_W];
CHlist[curchr].harea[BLK_W] = InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].varea[BLK_W];
CHlist[curchr].varea[BLK_W] = InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
void SetActiveH()
{
int i;
if(Polarity == 0)
{
i = CHlist[curchr].harea[BLK_H];
CHlist[curchr].harea[BLK_H] = InputIntegerValue(-1,-1,0,255,i);
}
else
{
i = CHlist[curchr].varea[BLK_H];
CHlist[curchr].varea[BLK_H] = InputIntegerValue(-1,-1,0,255,i);
}
Size_Update();
}
// Flip sprite polarity
void Flip()
{
switch(Direction)
{
case CHAR_U:
Direction = CHAR_D;
break;
case CHAR_D:
Direction = CHAR_U;
break;
case CHAR_L:
Direction = CHAR_R;
break;
case CHAR_R:
Direction = CHAR_L;
break;
}
Size_Update();
}
// Quit
void Finish()
{
running=0;
}
void PickChar()
{
char **list;
char Name[256];
int ctr;
// Allocate a list of possible characters
list=(char **)M_get(CHtot+1,sizeof(char *));
// Set it up, convert to uppercase for Wyber's ordered selection routine.
for(ctr=0;ctr<CHtot;ctr++)
{
list[ctr]=CHlist[ctr].name;
strupr(list[ctr]); // Affects the original too
}
strcpy(Name,CHlist[curchr].name); // Set up the default string
qsort(list,CHtot,sizeof(char*),CMP); // Sort them for the dialog box
// This is the graphical dialog box, taken from DEU.
GetOBFromList( -1,-1, "Choose a character:", CHtot-1, list, Name);
// If the user didn't press ESC instead of choosing, modify the character
if(Name[0]) // It's ok, do it
{
ctr=getnum4char(Name);
if(ctr>=0)
curchr=ctr;
}
free(list); // Dispose of the list
EditSize(); // Redraw all
}