remove ObjType, ObjId, ObjStrength and OL_ constants; use "object" instead of "robot...
[btb/d2x.git] / main / editor / objpage.c
1 /* $Id: objpage.c,v 1.4 2005-03-31 09:38:53 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * object selection stuff.
18  *
19  */
20
21 #ifdef RCS
22 static char rcsid[] = "$Id: objpage.c,v 1.4 2005-03-31 09:38:53 chris Exp $";
23 #endif
24
25 // Num_robot_types -->  N_polygon_models
26 // Cur_robot_type --> Cur_robot_type
27 // Texture[Cur_robot_type]->bitmap  ---> robot_bms[robot_bm_nums[ Cur_robot_type ] ] 
28
29 #ifdef HAVE_CONFIG_H
30 #include "conf.h"
31 #endif
32
33 #include <stdlib.h>
34 #include <stdio.h>
35
36
37 #include "inferno.h"
38 #include "screens.h"                    // For GAME_SCREEN?????
39 #include "editor.h"                     // For TMAP_CURBOX??????
40 #include "gr.h"                         // For canves, font stuff
41 #include "ui.h"                         // For UI_GADGET stuff
42 #include "object.h"                     // For robot_bms
43 #include "mono.h"                               // For debugging
44 #include "error.h"
45
46 #include "objpage.h"
47 #include "bm.h"
48 #include "player.h"
49 #include "piggy.h"
50 #include "cntrlcen.h"
51
52 #define OBJS_PER_PAGE 8
53
54 static UI_GADGET_USERBOX * ObjBox[OBJS_PER_PAGE];
55 static UI_GADGET_USERBOX * ObjCurrent;
56
57 static int ObjectPage = 0;
58
59 //static char Description[8][20] = { "Pig", "Star", "Little\nJosh", "Big\nJosh", "Flying\nPig", "Flying\nStar", 
60 //"Little\nFlying\nJosh", "Big\nFlying\nJosh" };
61
62 //static grs_canvas * ObjnameCanvas;
63 //static char object_filename[13];
64
65 //static void objpage_print_name( char name[13] ) {
66 //       short w,h,aw;
67 //
68 //    gr_set_current_canvas( ObjnameCanvas );
69 //    gr_get_string_size( name, &w, &h, &aw );
70 //    gr_string( 0, 0, name );                    
71 //       //gr_set_fontcolor( CBLACK, CWHITE );
72 //}
73
74 //static void objpage_display_name( char *format, ... ) {
75 //      va_list ap;
76 //
77 //      va_start(ap, format);
78 //   vsprintf(object_filename, format, ap);
79 //      va_end(ap);
80 //
81 //   objpage_print_name(object_filename);
82 //              
83 //}
84
85 #include "vecmat.h"
86 #include "3d.h"
87 #include "polyobj.h"
88 #include "texmap.h"
89
90 #include "hostage.h"
91 #include "powerup.h"
92
93 vms_angvec objpage_view_orient;
94 fix objpage_view_dist;
95
96 //this is bad to have the extern, but this snapshot stuff is special
97 extern int polyobj_lighting;
98
99
100 //canvas set
101 void draw_object_picture(int id, vms_angvec *orient_angles, int type)
102 {
103
104         if (id >= Num_object_subtypes)
105                 return;
106
107         switch (type) {
108
109                 case OBJ_HOSTAGE:
110                         PIGGY_PAGE_IN(Vclip[Hostage_vclip_num[id]].frames[0]);
111                         gr_bitmap(0,0,&GameBitmaps[Vclip[Hostage_vclip_num[id]].frames[0].index]);
112                         break;
113
114                 case OBJ_POWERUP:
115                         if ( Powerup_info[id].vclip_num > -1 )  {
116                                 PIGGY_PAGE_IN(Vclip[Powerup_info[id].vclip_num].frames[0]);
117                                 gr_bitmap(0,0,&GameBitmaps[Vclip[Powerup_info[id].vclip_num].frames[0].index]);
118                         }
119                         break;
120
121                 case OBJ_PLAYER:
122                         draw_model_picture(Player_ship->model_num,orient_angles);               // Draw a poly model below
123                         break;
124
125                 case OBJ_ROBOT:
126                         draw_model_picture(Robot_info[id].model_num,orient_angles);     // Draw a poly model below
127                         break;
128
129                 case OBJ_CNTRLCEN:
130                 case OBJ_CLUTTER:
131                         draw_model_picture(Reactors[id].model_num, orient_angles);
132                         break;
133                 default:
134                         //Int3();       // Invalid type!!!
135                         return;
136         }
137
138 }
139
140 void redraw_current_object()
141 {
142         grs_canvas * cc;
143
144         cc = grd_curcanv;
145         gr_set_current_canvas(ObjCurrent->canvas);
146         draw_object_picture(Cur_object_id, &objpage_view_orient, Cur_object_type);
147         gr_set_current_canvas(cc);
148 }
149
150 void gr_label_box( int i)
151 {
152
153         gr_clear_canvas(BM_XRGB(0,0,0));
154         draw_object_picture(i, &objpage_view_orient, Cur_object_type);
155
156 //      char s[20];
157 //      sprintf( s, " %d ", i );
158 //      gr_clear_canvas( BM_XRGB(0,15,0) );
159 //      gr_set_fontcolor( CWHITE, BM_XRGB(0,15,0) );
160 //      ui_string_centered(  grd_curcanv->cv_bitmap.bm_w/2, grd_curcanv->cv_bitmap.bm_h/2, Description[i] );
161 }
162
163 int objpage_goto_first()
164 {
165         int i;
166
167         ObjectPage=0;
168         for (i=0;  i<OBJS_PER_PAGE; i++ ) {
169                 gr_set_current_canvas(ObjBox[i]->canvas);
170                 if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes ) {
171                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
172                         gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
173                 } else
174                         gr_clear_canvas( CGREY );
175         }
176
177         return 1;
178 }
179
180 int objpage_goto_last()
181 {
182         int i;
183
184         ObjectPage=(Num_object_subtypes)/OBJS_PER_PAGE;
185         for (i=0;  i<OBJS_PER_PAGE; i++ )
186         {
187                 gr_set_current_canvas(ObjBox[i]->canvas);
188                 if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes )
189                 {
190                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
191                         gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
192                 } else {
193                         gr_clear_canvas( CGREY );
194                 }
195         }
196         return 1;
197 }
198
199 static int objpage_goto_prev()
200 {
201         int i;
202         if (ObjectPage > 0) {
203                 ObjectPage--;
204                 for (i=0;  i<OBJS_PER_PAGE; i++ )
205                 {
206                         gr_set_current_canvas(ObjBox[i]->canvas);
207                         if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
208                         {
209                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
210                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
211                         } else {
212                                 gr_clear_canvas( CGREY );
213                         }
214                 }
215         }
216         return 1;
217 }
218
219 static int objpage_goto_next()
220 {
221         int i;
222         if ((ObjectPage+1)*OBJS_PER_PAGE < Num_object_subtypes) {
223                 ObjectPage++;
224                 for (i=0;  i<OBJS_PER_PAGE; i++ )
225                 {
226                         gr_set_current_canvas(ObjBox[i]->canvas);
227                         if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
228                         {
229                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
230                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
231                         } else {
232                                 gr_clear_canvas( CGREY );
233                         }
234                 }
235         }
236         return 1;
237 }
238
239 int objpage_grab_current(int n)
240 {
241         int i;
242
243         if ((n < 0) || (n >= Num_object_subtypes)) return 0;
244         
245         ObjectPage = n / OBJS_PER_PAGE;
246         
247         if (ObjectPage*OBJS_PER_PAGE < Num_object_subtypes) {
248                 for (i=0;  i<OBJS_PER_PAGE; i++ )
249                 {
250                         gr_set_current_canvas(ObjBox[i]->canvas);
251                         if (i + ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
252                         {
253                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
254                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
255                         } else {
256                                 gr_clear_canvas( CGREY );
257                         }
258                 }
259         }
260
261         Cur_object_id = n;
262         gr_set_current_canvas(ObjCurrent->canvas);
263         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
264         gr_label_box(Cur_object_id);
265
266         //objpage_display_name( Texture[Cur_robot_type]->filename );
267         
268         return 1;
269 }
270
271 int objpage_goto_next_object()
272 {
273         // there should be a pop-up menu for this
274         switch (Cur_object_type)
275         {
276                 case OBJ_ROBOT:
277                         Cur_object_type = OBJ_HOSTAGE;
278                         Num_object_subtypes = 1;
279                         break;
280
281                 case OBJ_HOSTAGE:
282                         Cur_object_type = OBJ_PLAYER;
283                         Num_object_subtypes = 1;        // can have anarchy/coop, but this is handled automatically
284                         break;
285
286                 case OBJ_PLAYER:
287                         Cur_object_type = OBJ_POWERUP;
288                         Num_object_subtypes = N_powerup_types;
289                         break;
290
291                 case OBJ_POWERUP:
292                         Cur_object_type = OBJ_CNTRLCEN;
293                         Num_object_subtypes = Num_reactors;
294                         break;
295
296                 case OBJ_CNTRLCEN:
297                 default:
298                         Cur_object_type = OBJ_ROBOT;
299                         Num_object_subtypes = N_robot_types;
300                         break;
301         }
302
303         objpage_grab_current(0);
304
305         return 1;
306
307 }
308
309 #define OBJBOX_X        (TMAPBOX_X)     //location of first one
310 #define OBJBOX_Y        (OBJCURBOX_Y - 24 )
311 #define OBJBOX_W        64
312 #define OBJBOX_H        64
313
314 #define DELTA_ANG 0x800
315
316 int objpage_increase_pitch()
317 {
318         objpage_view_orient.p += DELTA_ANG;
319         redraw_current_object();
320         return 1;
321 }
322
323 int objpage_decrease_pitch()
324 {
325         objpage_view_orient.p -= DELTA_ANG;
326         redraw_current_object();
327         return 1;
328 }
329
330 int objpage_increase_heading()
331 {
332         objpage_view_orient.h += DELTA_ANG;
333         redraw_current_object();
334         return 1;
335 }
336
337 int objpage_decrease_heading()
338 {
339         objpage_view_orient.h -= DELTA_ANG;
340         redraw_current_object();
341         return 1;
342 }
343
344 int objpage_increase_bank()
345 {
346         objpage_view_orient.b += DELTA_ANG;
347         redraw_current_object();
348         return 1;
349 }
350
351 int objpage_decrease_bank()
352 {
353         objpage_view_orient.b -= DELTA_ANG;
354         redraw_current_object();
355         return 1;
356 }
357
358 int objpage_increase_z()
359 {
360         objpage_view_dist -= 0x8000;
361         redraw_current_object();
362         return 1;
363 }
364
365 int objpage_decrease_z()
366 {
367         objpage_view_dist += 0x8000;
368         redraw_current_object();
369         return 1;
370 }
371
372 int objpage_reset_orient()
373 {
374         objpage_view_orient.p = 0;
375         objpage_view_orient.b = 0;
376         objpage_view_orient.h = -0x8000;
377         //objpage_view_dist = DEFAULT_VIEW_DIST;
378         redraw_current_object();
379         return 1;
380 }
381
382
383 // INIT TEXTURE STUFF
384
385 void objpage_init( UI_WINDOW *win )
386 {
387         int i;
388
389         //Num_total_object_types = N_polygon_models + N_hostage_types + N_powerup_types;
390         //Assert (N_polygon_models < MAX_POLYGON_MODELS);
391         //Assert (Num_total_object_types < MAX_OBJTYPE );
392         //Assert (N_hostage_types < MAX_HOSTAGE_TYPES ); 
393         //Assert (N_powerup_types < MAX_POWERUP_TYPES );
394         // Assert (N_robot_types < MAX_ROBOTS);
395
396         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y - 27, 30, 20, "<<", objpage_goto_prev );
397         ui_add_gadget_button( win, OBJCURBOX_X + 32, OBJCURBOX_Y - 27, 30, 20, ">>", objpage_goto_next );
398
399         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y - 54, 30, 20, "B", objpage_goto_first );
400         ui_add_gadget_button( win, OBJCURBOX_X + 32, OBJCURBOX_Y - 54, 30, 20, "E", objpage_goto_last );
401
402         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 62, 22, 13, "P-", objpage_decrease_pitch );
403         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 90, 22, 13, "P+", objpage_increase_pitch );
404         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 90, 22, 13, "B-", objpage_decrease_bank );
405         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 90, 22, 13, "B+", objpage_increase_bank );
406         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 76, 22, 13, "H-", objpage_decrease_heading );
407         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 76, 22, 13, "H+", objpage_increase_heading );
408         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 62, 22, 13, "Z+", objpage_increase_z );
409         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 62, 22, 13, "Z-", objpage_decrease_z );
410         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 76, 22, 13, "R", objpage_reset_orient );
411
412         for (i=0;i<OBJS_PER_PAGE;i++)
413                 ObjBox[i] = ui_add_gadget_userbox( win, OBJBOX_X + (i/2)*(2+OBJBOX_W), OBJBOX_Y + (i%2)*(2+OBJBOX_H), OBJBOX_W, OBJBOX_H);
414
415         ObjCurrent = ui_add_gadget_userbox( win, OBJCURBOX_X, OBJCURBOX_Y-5, 64, 64 );
416
417         objpage_reset_orient();
418
419         for (i=0;  i<OBJS_PER_PAGE; i++ )
420         {
421                 gr_set_current_canvas(ObjBox[i]->canvas);
422                 if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
423                 {
424                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
425                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
426                 } else {
427                         gr_clear_canvas( CGREY );
428                 }
429         }
430
431 // Don't reset robot_type when we return to editor.
432 //      Cur_robot_type = ObjectPage*OBJS_PER_PAGE;
433         gr_set_current_canvas(ObjCurrent->canvas);
434         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
435         gr_label_box(Cur_object_id);
436
437         //ObjnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, OBJCURBOX_X , OBJCURBOX_Y + OBJBOX_H + 10, 100, 20);
438         //gr_set_current_canvas( ObjnameCanvas );
439         //gr_set_curfont( ui_small_font ); 
440    //gr_set_fontcolor( CBLACK, CWHITE );
441         //objpage_display_name( Texture[Cur_robot_type]->filename );
442
443 }
444
445 void objpage_close()
446 {
447         //gr_free_sub_canvas(ObjnameCanvas);
448 }
449
450
451 // DO TEXTURE STUFF
452
453 void objpage_do()
454 {
455         int i;
456
457         for (i=0; i<OBJS_PER_PAGE; i++ )
458         {
459                 if (ObjBox[i]->b1_clicked && (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes))
460                 {
461                         Cur_object_id = i+ObjectPage*OBJS_PER_PAGE;
462                         gr_set_current_canvas(ObjCurrent->canvas);
463                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
464                         gr_label_box(Cur_object_id);
465                         //objpage_display_name( Texture[Cur_robot_type]->filename );
466                 }
467         }
468 }