[go: up one dir, main page]

Menu

[r61]: / engine / gui / roof.cpp  Maximize  Restore  History

Download this file

504 lines (404 with data), 9.9 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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/*
* - Background menu tab
*/
#include <stdio.h>
#include "igui.hpp"
#include "../ithelib.h"
#include "../console.h"
#include "../core.hpp"
#include "../gamedata.h"
#include "menusys.h"
// defines
// variables
extern int focus,TL_Id;
extern int MapXpos_Id,MapYpos_Id; // Map X/Y Coordinate boxes
extern char mapxstr[],mapystr[];
extern long M_core; // Total amount of core, from memory.cc
extern int s_proj; // Flag, are sprites being displayed?
extern int st_proj; // Flag, are standunder tiles being highlighted?
extern long mapx,mapy; // Current map position
static int curoff=0; // Current position on the tile list at the bottom
static int L=0,R=0; // Current tile for each button, Lclick and Rclick
int L_rooftile=0;
static int cycleflag=0,cycleptr=0;
static int lastx=-666,lasty=-666;
// functions
extern void Toolbar();
extern void DrawMap(int x,int y,char s_proj,char l_proj,char f_proj);
extern void WriteRoof(int x,int y,int tile);
extern int ReadRoof(int x,int y);
extern void (*EdUpdateFunc)(void);
static void Nothing();
static void clipmap();
void TLBl();
void TLBll();
void TLBr();
void TLBrr();
void TL_bar();
void TLBend();
void TLBstart();
void TL_up();
void TL_down();
void TL_left();
void TL_right();
static void GetL(); // Get a tile for the left click
static void GetR(); // Get a tile for the right click
static void SetR(); // Write a right-click tile to map
static void SetL(); // Write a left-click tile to map
static void Get_Prefab(); // Copy to clipboard
static void Put_Prefab(); // Copy to map
static void ClearL();
static void ClearR();
static void Set_Roof(int tile); // Write a tile to the map, helper
static int Get_Roof(); // Get a tile from the map, helper
static void GetMapX(); // Get map position
static void GetMapY();
static unsigned short prefab[8][8]; //
//static unsigned short blkundo[8][8]; // Undo block op
// GoFocal - The menu tab function. This is called from the toolbar
void TL_GoFocal()
{
int temp; // Used to get button handles
if(focus==3) // Make sure we don't redraw if the user clicks again
return;
focus=3; // This is now the focus
Toolbar(); // Build up the menu system again from scratch
IG_SetFocus(TL_Id); // And make the button stick inwards
// Set up Map window
IG_BlackPanel(VIEWX-1,VIEWY-1,258,258);
IG_Region(VIEWX,VIEWY,256,256,SetL,NULL,SetR);
// Write sprite drawing status
temp = IG_ToggleButton(486,72,"Sprites OFF",Nothing,NULL,NULL,&s_proj);
IG_SetInText(temp,"Sprites ON ");
temp = IG_ToggleButton(486,104,"Normal View",Nothing,NULL,NULL,&st_proj);
IG_SetInText(temp,"Stand Under");
temp = IG_ToggleButton(96,348,"Cycling off",Nothing,NULL,NULL,&cycleflag);
IG_SetInText(temp,"Cycling ON ");
// Draw the VCR buttons on the Tile selector
IG_TextButton(8,410,__left,TLBl,NULL,NULL); // Normal speed
IG_TextButton(616,410,__right,TLBr,NULL,NULL);
IG_TextButton(8,440,__left2,TLBll,NULL,TLBstart); // Fast Forward
IG_TextButton(608,440,__right2,TLBrr,NULL,TLBend);
// Draw the contents of Left and Right buttons
IG_BlackPanel(400,192,32,32);
DrawScreenText(400,182," L");
if(L)
draw_rle_sprite(swapscreen,RTlist[L].image,400,192);
IG_BlackPanel(448,192,32,32);
DrawScreenText(448,182," R");
if(R)
draw_rle_sprite(swapscreen,RTlist[R].image,448,192);
TL_bar(); // Draw the Tile bar
IG_Region(32,400,576,32,GetL,NULL,GetR); // Add clickable region
// Set up the X and Y map position counter at the top
MapXpos_Id = IG_InputButton(24,40,mapxstr,GetMapX,NULL,NULL);
MapYpos_Id = IG_InputButton(112,40,mapystr,GetMapY,NULL,NULL);
// Get and Put prefab (clipboard)
IG_TextButton(300,300,"Cut screen",Get_Prefab,NULL,NULL); // Fast Forward
IG_TextButton(400,300,"Paste screen",Put_Prefab,NULL,NULL); // Fast Forward
IG_TextButton(300,348,"Fill L tile",ClearL,NULL,NULL); // Fast Forward
IG_TextButton(400,348,"Fill R tile",ClearR,NULL,NULL); // Fast Forward
DrawMap(mapx,mapy,s_proj,1,0); // Draw the map
IG_TextButton(416,104,__up,TL_up,NULL,NULL); // Pan up button
IG_TextButton(400,128,__left,TL_left,NULL,NULL); // Pan left button
IG_TextButton(432,128,__right,TL_right,NULL,NULL); // Pan right button
IG_TextButton(416,150,__down,TL_down,NULL,NULL); // Pan down button
IG_AddKey(KEY_UP,TL_up); // Pan up key binding
IG_AddKey(KEY_DOWN,TL_down); // Pan down key binding
IG_AddKey(KEY_LEFT,TL_left); // Pan left key binding
IG_AddKey(KEY_RIGHT,TL_right); // Pan right key binding
IG_AddKey(KEY_C,Get_Prefab); // get prefab key binding
IG_AddKey(KEY_V,Put_Prefab); // put prefab key binding
EdUpdateFunc=NULL;
}
void Nothing()
{
DrawMap(mapx,mapy,s_proj,1,0); // Do something anyway
return;
}
void TLBr()
{
curoff++;
if(curoff>(RTtot-17))
curoff=(RTtot-17);
if(curoff<0) curoff=0;
TL_bar();
}
void TLBl()
{
curoff--;
if(curoff<0) curoff=0;
TL_bar();
}
void TLBrr()
{
curoff+=10;
if(curoff>(RTtot-17))
curoff=(RTtot-17);
if(curoff<0) curoff=0;
TL_bar();
}
void TLBll()
{
curoff-=10;
if(curoff<0) curoff=0;
TL_bar();
}
void TLBend()
{
curoff=(RTtot-17);
if(curoff<0) curoff=0;
TL_bar();
}
void TLBstart()
{
curoff=0;
TL_bar();
}
void TL_bar()
{
int co;
co=17;
if(RTtot<17)
co=RTtot;
IG_BlackPanel(31,399,578,34);
for(int ctr=0;ctr<co;ctr++)
if(ctr+curoff < 1)
fbox2(33,401,32,32,0,swapscreen);
else
{
draw_rle_sprite(swapscreen,RTlist[ctr+curoff].image,33+(34*ctr),401);
if(!(RTlist[ctr+curoff].flags & KILLROOF))
textout_ex(swapscreen,font,"S",33+(34*ctr),401,ITG_BLUE,-1);
}
}
void GetL()
{
int co;
co=17;
if(RTtot<17)
co=RTtot;
for(int ctr=0;ctr<co;ctr++)
if(x>33+(34*ctr) && x<65+(34*ctr))
{
L=ctr+curoff;
L_rooftile=L; // For big-map painting
IG_BlackPanel(400,192,32,32);
if(L)
draw_rle_sprite(swapscreen,RTlist[L].image,400,192);
// If we're tile-cycling, reset and ensure sanity
cycleptr=L;
lastx=-666; // force a lastx,y reset
return;
}
}
void GetR()
{
int co;
co=17;
if(RTtot<17)
co=RTtot;
for(int ctr=0;ctr<co;ctr++)
if(x>33+(34*ctr) && x<65+(34*ctr))
{
R=ctr+curoff;
IG_BlackPanel(448,192,32,32);
if(R)
draw_rle_sprite(swapscreen,RTlist[R].image,448,192);
// If we're tile-cycling, ensure sanity
if(cycleflag)
if(cycleptr>R)
cycleptr=R;
return;
}
}
void SetL()
{
int l;
// If shift is pressed, grab tile instead of drawing
if(key_shifts & KEY_LSHIFT)
{
l=Get_Roof();
if(l>=RTtot)
l=RTtot-1;
if(l != -1)
L=l;
L_rooftile=L; // For big-map painting
cycleptr=L;
IG_BlackPanel(400,192,32,32);
if(L)
draw_rle_sprite(swapscreen,RTlist[L].image,400,192);
return;
}
Set_Roof(L);
}
void SetR()
{
int r;
// If shift is pressed, grab tile instead of drawing
if(key_shifts & KEY_LSHIFT)
{
r=Get_Roof();
if(r>=RTtot)
r=RTtot-1;
if(r != -1)
R=r;
IG_BlackPanel(448,192,32,32);
if(R)
draw_rle_sprite(swapscreen,RTlist[R].image,448,192);
return;
}
Set_Roof(R);
}
void Set_Roof(int tile)
{
int t,xx,yy,yyy,xxx;
yyy=-1;
xxx=-1;
for(xx=0;xx<VSW;xx++)
{
t=32*xx+(VIEWX-1);
if(x>=t &&x<(t+32))
xxx=xx;
}
for(yy=0;yy<VSH;yy++)
{
t=32*yy+(VIEWY-1);
if(y>=t && y<(t+32))
yyy=yy;
}
if(xxx!=-1 && yyy!=-1)
{
// Convert to map coordinates
xxx+=mapx;
yyy+=mapy;
// If we are tile-cycling, only write if tile isn't same as last
if(cycleflag)
if(xxx == lastx && yyy == lasty)
return;
// Handle any tile-cycling
if(cycleflag)
{
if(L>R)
return;
tile=cycleptr++;
if(cycleptr>R)
cycleptr=L;
}
WriteRoof(xxx,yyy,tile);
lastx=xxx;
lasty=yyy;
}
DrawMap(mapx,mapy,s_proj,1,0);
}
int Get_Roof()
{
int t,xx,yy,yyy,xxx;
yyy=-1;
xxx=-1;
for(xx=0;xx<VSW;xx++)
{
t=32*xx+(VIEWX-1);
if(x>=t &&x<(t+32))
xxx=xx;
}
for(yy=0;yy<VSH;yy++)
{
t=32*yy+(VIEWY-1);
if(y>=t && y<(t+32))
yyy=yy;
}
if(xxx!=-1 && yyy!=-1)
return ReadRoof(mapx+xxx,mapy+yyy);
return -1;
}
void TL_up()
{
if(key_shifts & KEY_LSHIFT)
mapy-=8;
else
mapy--;
clipmap();
DrawMap(mapx,mapy,s_proj,1,0);
}
void TL_down()
{
if(key_shifts & KEY_LSHIFT)
mapy+=8;
else
mapy++;
clipmap();
DrawMap(mapx,mapy,s_proj,1,0);
}
void TL_left()
{
if(key_shifts & KEY_LSHIFT)
mapx-=8;
else
mapx--;
clipmap();
DrawMap(mapx,mapy,s_proj,1,0);
}
void TL_right()
{
if(key_shifts & KEY_LSHIFT)
mapx+=8;
else
mapx++;
clipmap();
DrawMap(mapx,mapy,s_proj,1,0);
}
void ClearL()
{
for(int cy=0;cy<VSH;cy++)
for(int cx=0;cx<VSW;cx++)
WriteRoof(mapx+cx,mapy+cy,L);
DrawMap(mapx,mapy,s_proj,1,0);
}
void ClearR()
{
for(int cy=0;cy<VSH;cy++)
for(int cx=0;cx<VSW;cx++)
WriteRoof(mapx+cx,mapy+cy,R);
DrawMap(mapx,mapy,s_proj,1,0);
}
void Get_Prefab()
{
for(int cy=0;cy<VSH;cy++)
for(int cx=0;cx<VSW;cx++)
prefab[cx][cy]=ReadRoof(mapx+cx,mapy+cy);
//DrawMap(mapx,mapy,s_proj,l_proj,0);
}
void Put_Prefab()
{
for(int cy=0;cy<VSH;cy++)
for(int cx=0;cx<VSW;cx++)
WriteRoof(mapx+cx,mapy+cy,prefab[cx][cy]);
DrawMap(mapx,mapy,s_proj,1,0);
}
/*
* clipmap - clip the map's coordinates to sensible values
*/
void clipmap()
{
if(mapx<0) mapx=0;
if(mapx>curmap->w-VSW) mapx=curmap->w-VSW;
if(mapy>curmap->h-VSH) mapy=curmap->h-VSH;
if(mapy<0) mapy=0;
}
/*
* GetMapX - Ask the user where on the map they want to be
*/
void GetMapX()
{
mapx=InputIntegerValue(-1,-1,0,curmap->w-VSW,mapx);
DrawMap(mapx,mapy,s_proj,1,0);
}
/*
* GetMapY - Ask the user where on the map they want to be
*/
void GetMapY()
{
mapy=InputIntegerValue(-1,-1,0,curmap->h-VSH,mapy);
DrawMap(mapx,mapy,s_proj,1,0);
}