932ff8176a66f9fab0b15d0df29b62a6443586d8
[btb/d2x.git] / main / editor / objpage.c
1 /* $Id: objpage.c,v 1.3 2004-12-19 15:21:11 btb 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.3 2004-12-19 15:21:11 btb 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
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 //      Type is optional.  If you pass -1, type is determined, else type is used, and id is not xlated through ObjId.
102 void draw_robot_picture(int id, vms_angvec *orient_angles, int type)
103 {
104
105         if (id >= Num_total_object_types)
106                 return;
107
108         if ( type == -1 )       {
109                 type = ObjType[id];             // Find the object type, given an object id.
110                 id = ObjId[id]; // Translate to sub-id.
111         }
112
113         switch (type) {
114
115                 case OL_HOSTAGE:
116                         PIGGY_PAGE_IN(Vclip[Hostage_vclip_num[id]].frames[0]);
117                         gr_bitmap(0,0,&GameBitmaps[Vclip[Hostage_vclip_num[id]].frames[0].index]);
118                         break;
119
120                 case OL_POWERUP:
121                         if ( Powerup_info[id].vclip_num > -1 )  {
122                                 PIGGY_PAGE_IN(Vclip[Powerup_info[id].vclip_num].frames[0]);
123                                 gr_bitmap(0,0,&GameBitmaps[Vclip[Powerup_info[id].vclip_num].frames[0].index]);
124                         }
125                         break;
126
127                 case OL_PLAYER:
128                         draw_model_picture(Player_ship->model_num,orient_angles);               // Draw a poly model below
129                         break;
130
131                 case OL_ROBOT:
132                         draw_model_picture(Robot_info[id].model_num,orient_angles);     // Draw a poly model below
133                         break;
134
135                 case OL_CONTROL_CENTER:
136                 case OL_CLUTTER:
137                         draw_model_picture(id,orient_angles);
138                         break;
139                 default:
140                         //Int3();       // Invalid type!!!
141                         return;
142         }
143
144 }
145
146 void redraw_current_object()
147 {
148         grs_canvas * cc;
149
150         cc = grd_curcanv;
151         gr_set_current_canvas(ObjCurrent->canvas);
152         draw_robot_picture(Cur_robot_type,&objpage_view_orient, -1);
153         gr_set_current_canvas(cc);
154 }
155
156 void gr_label_box( int i)
157 {
158
159         gr_clear_canvas(BM_XRGB(0,0,0));
160         draw_robot_picture(i,&objpage_view_orient, -1);
161
162 //      char s[20];
163 //      sprintf( s, " %d ", i );
164 //      gr_clear_canvas( BM_XRGB(0,15,0) );
165 //      gr_set_fontcolor( CWHITE, BM_XRGB(0,15,0) );
166 //      ui_string_centered(  grd_curcanv->cv_bitmap.bm_w/2, grd_curcanv->cv_bitmap.bm_h/2, Description[i] );
167 }
168
169 int objpage_goto_first()
170 {
171         int i;
172
173         ObjectPage=0;
174         for (i=0;  i<OBJS_PER_PAGE; i++ ) {
175                 gr_set_current_canvas(ObjBox[i]->canvas);
176                 if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types ) {
177                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
178                         gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
179                 } else
180                         gr_clear_canvas( CGREY );
181         }
182
183         return 1;
184 }
185
186 int objpage_goto_last()
187 {
188         int i;
189
190         ObjectPage=(Num_total_object_types)/OBJS_PER_PAGE;
191         for (i=0;  i<OBJS_PER_PAGE; i++ )
192         {
193                 gr_set_current_canvas(ObjBox[i]->canvas);
194                 if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types )
195                 {
196                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
197                         gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
198                 } else {
199                         gr_clear_canvas( CGREY );
200                 }
201         }
202         return 1;
203 }
204
205 static int objpage_goto_prev()
206 {
207         int i;
208         if (ObjectPage > 0) {
209                 ObjectPage--;
210                 for (i=0;  i<OBJS_PER_PAGE; i++ )
211                 {
212                         gr_set_current_canvas(ObjBox[i]->canvas);
213                         if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types)
214                         {
215                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
216                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
217                         } else {
218                                 gr_clear_canvas( CGREY );
219                         }
220                 }
221         }
222         return 1;
223 }
224
225 static int objpage_goto_next()
226 {
227         int i;
228         if ((ObjectPage+1)*OBJS_PER_PAGE < Num_total_object_types) {
229                 ObjectPage++;
230                 for (i=0;  i<OBJS_PER_PAGE; i++ )
231                 {
232                         gr_set_current_canvas(ObjBox[i]->canvas);
233                         if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types)
234                         {
235                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
236                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
237                         } else {
238                                 gr_clear_canvas( CGREY );
239                         }
240                 }
241         }
242         return 1;
243 }
244
245 int objpage_grab_current(int n)
246 {
247         int i;
248
249         if ( (n<0) || ( n>= Num_total_object_types) ) return 0;
250         
251         ObjectPage = n / OBJS_PER_PAGE;
252         
253         if (ObjectPage*OBJS_PER_PAGE < Num_total_object_types) {
254                 for (i=0;  i<OBJS_PER_PAGE; i++ )
255                 {
256                         gr_set_current_canvas(ObjBox[i]->canvas);
257                         if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types)
258                         {
259                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
260                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
261                         } else {
262                                 gr_clear_canvas( CGREY );
263                         }
264                 }
265         }
266
267         Cur_robot_type = n;
268         gr_set_current_canvas(ObjCurrent->canvas);
269         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
270         gr_label_box(Cur_robot_type);
271
272         //objpage_display_name( Texture[Cur_robot_type]->filename );
273         
274         return 1;
275 }
276
277 int objpage_goto_next_object()
278 {
279         int n;
280
281         n = Cur_robot_type++;
282         if (n >= Num_total_object_types) n = 0;
283
284         objpage_grab_current(n);
285
286         return 1;
287
288 }
289
290 #define OBJBOX_X        (TMAPBOX_X)     //location of first one
291 #define OBJBOX_Y        (OBJCURBOX_Y - 24 )
292 #define OBJBOX_W        64
293 #define OBJBOX_H        64
294
295 #define DELTA_ANG 0x800
296
297 int objpage_increase_pitch()
298 {
299         objpage_view_orient.p += DELTA_ANG;
300         redraw_current_object();
301         return 1;
302 }
303
304 int objpage_decrease_pitch()
305 {
306         objpage_view_orient.p -= DELTA_ANG;
307         redraw_current_object();
308         return 1;
309 }
310
311 int objpage_increase_heading()
312 {
313         objpage_view_orient.h += DELTA_ANG;
314         redraw_current_object();
315         return 1;
316 }
317
318 int objpage_decrease_heading()
319 {
320         objpage_view_orient.h -= DELTA_ANG;
321         redraw_current_object();
322         return 1;
323 }
324
325 int objpage_increase_bank()
326 {
327         objpage_view_orient.b += DELTA_ANG;
328         redraw_current_object();
329         return 1;
330 }
331
332 int objpage_decrease_bank()
333 {
334         objpage_view_orient.b -= DELTA_ANG;
335         redraw_current_object();
336         return 1;
337 }
338
339 int objpage_increase_z()
340 {
341         objpage_view_dist -= 0x8000;
342         redraw_current_object();
343         return 1;
344 }
345
346 int objpage_decrease_z()
347 {
348         objpage_view_dist += 0x8000;
349         redraw_current_object();
350         return 1;
351 }
352
353 int objpage_reset_orient()
354 {
355         objpage_view_orient.p = 0;
356         objpage_view_orient.b = 0;
357         objpage_view_orient.h = -0x8000;
358         //objpage_view_dist = DEFAULT_VIEW_DIST;
359         redraw_current_object();
360         return 1;
361 }
362
363
364 // INIT TEXTURE STUFF
365
366 void objpage_init( UI_WINDOW *win )
367 {
368         int i;
369
370         //Num_total_object_types = N_polygon_models + N_hostage_types + N_powerup_types;
371         //Assert (N_polygon_models < MAX_POLYGON_MODELS);
372         //Assert (Num_total_object_types < MAX_OBJTYPE );
373         //Assert (N_hostage_types < MAX_HOSTAGE_TYPES ); 
374         //Assert (N_powerup_types < MAX_POWERUP_TYPES );
375         // Assert (N_robot_types < MAX_ROBOTS);
376
377         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y - 27, 30, 20, "<<", objpage_goto_prev );
378         ui_add_gadget_button( win, OBJCURBOX_X + 32, OBJCURBOX_Y - 27, 30, 20, ">>", objpage_goto_next );
379
380         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y - 54, 30, 20, "B", objpage_goto_first );
381         ui_add_gadget_button( win, OBJCURBOX_X + 32, OBJCURBOX_Y - 54, 30, 20, "E", objpage_goto_last );
382
383         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 62, 22, 13, "P-", objpage_decrease_pitch );
384         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 90, 22, 13, "P+", objpage_increase_pitch );
385         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 90, 22, 13, "B-", objpage_decrease_bank );
386         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 90, 22, 13, "B+", objpage_increase_bank );
387         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 76, 22, 13, "H-", objpage_decrease_heading );
388         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 76, 22, 13, "H+", objpage_increase_heading );
389         ui_add_gadget_button( win, OBJCURBOX_X + 00, OBJCURBOX_Y + 62, 22, 13, "Z+", objpage_increase_z );
390         ui_add_gadget_button( win, OBJCURBOX_X + 50, OBJCURBOX_Y + 62, 22, 13, "Z-", objpage_decrease_z );
391         ui_add_gadget_button( win, OBJCURBOX_X + 25, OBJCURBOX_Y + 76, 22, 13, "R", objpage_reset_orient );
392
393         for (i=0;i<OBJS_PER_PAGE;i++)
394                 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);
395
396         ObjCurrent = ui_add_gadget_userbox( win, OBJCURBOX_X, OBJCURBOX_Y-5, 64, 64 );
397
398         objpage_reset_orient();
399
400         for (i=0;  i<OBJS_PER_PAGE; i++ )
401         {
402                 gr_set_current_canvas(ObjBox[i]->canvas);
403                 if (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types)
404                 {
405                                 //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
406                                 gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
407                 } else {
408                         gr_clear_canvas( CGREY );
409                 }
410         }
411
412 // Don't reset robot_type when we return to editor.
413 //      Cur_robot_type = ObjectPage*OBJS_PER_PAGE;
414         gr_set_current_canvas(ObjCurrent->canvas);
415         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
416         gr_label_box(Cur_robot_type);
417
418         //ObjnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, OBJCURBOX_X , OBJCURBOX_Y + OBJBOX_H + 10, 100, 20);
419         //gr_set_current_canvas( ObjnameCanvas );
420         //gr_set_curfont( ui_small_font ); 
421    //gr_set_fontcolor( CBLACK, CWHITE );
422         //objpage_display_name( Texture[Cur_robot_type]->filename );
423
424 }
425
426 void objpage_close()
427 {
428         //gr_free_sub_canvas(ObjnameCanvas);
429 }
430
431
432 // DO TEXTURE STUFF
433
434 void objpage_do()
435 {
436         int i;
437
438         for (i=0; i<OBJS_PER_PAGE; i++ )
439         {
440                 if (ObjBox[i]->b1_clicked && (i+ObjectPage*OBJS_PER_PAGE < Num_total_object_types))
441                 {
442                         Cur_robot_type = i+ObjectPage*OBJS_PER_PAGE;
443                         gr_set_current_canvas(ObjCurrent->canvas);
444                         //gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
445                         gr_label_box(Cur_robot_type);
446                         //objpage_display_name( Texture[Cur_robot_type]->filename );
447                 }
448         }
449 }