2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 * $Source: /cvs/cvsroot/d2x/main/editor/texpage.c,v $
17 * $Date: 2004-12-19 13:54:27 $
19 * Routines for displaying texture pages
21 * $Log: not supported by cvs2svn $
22 * Revision 1.1.1.1 1999/06/14 22:04:32 donut
23 * Import of d1x 1.37 source.
25 * Revision 2.0 1995/02/27 11:34:51 john
26 * Version 2.0! No anonymous unions, Watcom 10.0, with no need
29 * Revision 1.14 1995/01/14 19:18:02 john
30 * First version of object paging.
32 * Revision 1.13 1994/11/27 23:17:15 matt
33 * Made changes for new mprintf calling convention
35 * Revision 1.12 1994/11/23 15:49:00 mike
36 * fix bug in tmapnum == 0 always getting reassigned.
38 * Revision 1.11 1994/11/23 12:17:34 mike
39 * changing texture maps in all mines.
41 * Revision 1.10 1994/11/19 00:04:42 john
42 * Changed some shorts to ints.
44 * Revision 1.9 1994/11/16 17:59:36 john
45 * Fixed bug with writing to canvas before initing it.
47 * Revision 1.8 1994/11/16 13:15:21 matt
48 * Fixed grab bug, and cleaned up code
50 * Revision 1.7 1994/08/05 12:26:37 matt
51 * Fixed overplot problem with texture names
53 * Revision 1.6 1994/04/11 12:01:58 yuan
54 * Fixed resetting to first texture on page annoyance.
56 * Revision 1.5 1994/04/01 11:15:53 yuan
57 * Added objects to objpage. Added buttons for easier tmap scrolling.
58 * Objects are selected fully from objpage and add object menu or pad.
60 * Revision 1.4 1994/03/15 16:33:37 yuan
61 * Fixed bm loader (might have some changes in walls and switches)
63 * Revision 1.3 1993/12/16 17:25:46 john
64 * Moved texture and object selection to texpage and objpage
66 * Revision 1.2 1993/12/16 15:57:39 john
67 * moved texture selection stuff to texpage.c
69 * Revision 1.1 1993/12/16 15:06:56 john
81 static char rcsid[] = "$Id: texpage.c,v 1.1 2004-12-19 13:54:27 btb Exp $";
86 #include "screens.h" // For GAME_SCREEN?????
87 #include "editor.h" // For TMAP_CURBOX??????
88 #include "gr.h" // For canves, font stuff
89 #include "ui.h" // For UI_GADGET stuff
90 #include "textures.h" // For NumTextures
99 #define TMAPS_PER_PAGE 12
101 static UI_GADGET_USERBOX * TmapBox[TMAPS_PER_PAGE];
102 static UI_GADGET_USERBOX * TmapCurrent;
104 int CurrentTmap = 0; // Used globally
105 int CurrentTexture = 0; // Used globally
111 static int TexturePage = 0;
113 static grs_canvas * TmapnameCanvas;
114 static char tmap_filename[13];
116 static void texpage_print_name( char name[13] )
121 for (i=strlen(name);i<12;i++)
125 gr_set_current_canvas( TmapnameCanvas );
126 gr_get_string_size( name, &w, &h, &aw );
127 gr_string( 0, 0, name );
130 static void texpage_display_name( char *format, ... )
134 va_start(ap, format);
135 vsprintf(tmap_filename, format, ap);
138 texpage_print_name(tmap_filename);
141 //Redraw the list of textures, based on TexturePage
142 void texpage_redraw()
146 for (i=0; i<TMAPS_PER_PAGE; i++ )
148 gr_set_current_canvas(TmapBox[i]->canvas);
149 if (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps ) {
150 PIGGY_PAGE_IN( Textures[TmapList[i+TexturePage*TMAPS_PER_PAGE]]);
151 gr_ubitmap(0,0, &GameBitmaps[Textures[TmapList[i+TexturePage*TMAPS_PER_PAGE]].index]);
153 gr_clear_canvas( CGREY );
157 //shows the current texture, updating the window and printing the name, base
159 void texpage_show_current()
161 gr_set_current_canvas(TmapCurrent->canvas);
162 PIGGY_PAGE_IN(Textures[CurrentTexture]);
163 gr_ubitmap(0,0, &GameBitmaps[Textures[CurrentTexture].index]);
164 texpage_display_name( TmapInfo[CurrentTexture].filename );
167 int texpage_goto_first()
174 int texpage_goto_metals()
177 TexturePage=TextureMetals/TMAPS_PER_PAGE;
183 // Goto lights (paste ons)
184 int texpage_goto_lights()
186 TexturePage=TextureLights/TMAPS_PER_PAGE;
191 int texpage_goto_effects()
193 TexturePage=TextureEffects/TMAPS_PER_PAGE;
198 static int texpage_goto_prev()
200 if (TexturePage > 0) {
207 static int texpage_goto_next()
209 if ((TexturePage+1)*TMAPS_PER_PAGE < Num_tmaps ) {
216 //NOTE: this code takes the texture map number, not this index in the
217 //list of available textures. There are different if there are holes in
219 int texpage_grab_current(int n)
223 if ( (n<0) || ( n>= Num_tmaps) ) return 0;
227 for (i=0;i<Num_tmaps;i++)
228 if (TmapList[i] == n) {
232 Assert(i!=Num_tmaps);
234 TexturePage = CurrentTmap / TMAPS_PER_PAGE;
236 if (TexturePage*TMAPS_PER_PAGE < Num_tmaps )
239 texpage_show_current();
245 // INIT TEXTURE STUFF
247 void texpage_init( UI_WINDOW * win )
251 ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 24, 30, 20, "<<", texpage_goto_prev );
252 ui_add_gadget_button( win, TMAPCURBOX_X + 32, TMAPCURBOX_Y - 24, 30, 20, ">>", texpage_goto_next );
254 ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 48, 15, 20, "T", texpage_goto_first );
255 ui_add_gadget_button( win, TMAPCURBOX_X + 17, TMAPCURBOX_Y - 48, 15, 20, "M", texpage_goto_metals );
256 ui_add_gadget_button( win, TMAPCURBOX_X + 34, TMAPCURBOX_Y - 48, 15, 20, "L", texpage_goto_lights );
257 ui_add_gadget_button( win, TMAPCURBOX_X + 51, TMAPCURBOX_Y - 48, 15, 20, "E", texpage_goto_effects );
260 for (i=0;i<TMAPS_PER_PAGE;i++)
261 TmapBox[i] = ui_add_gadget_userbox( win, TMAPBOX_X + (i/3)*(2+TMAPBOX_W), TMAPBOX_Y + (i%3)*(2+TMAPBOX_H), TMAPBOX_W, TMAPBOX_H);
263 TmapCurrent = ui_add_gadget_userbox( win, TMAPCURBOX_X, TMAPCURBOX_Y, 64, 64 );
265 TmapnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, TMAPCURBOX_X , TMAPCURBOX_Y + TMAPBOX_H + 10, 100, 20);
266 gr_set_current_canvas( TmapnameCanvas );
267 gr_set_curfont( ui_small_font );
268 gr_set_fontcolor( CBLACK, CWHITE );
272 // Don't reset the current tmap every time we go back to the editor.
273 // CurrentTmap = TexturePage*TMAPS_PER_PAGE;
274 // CurrentTexture = TmapList[CurrentTmap];
275 texpage_show_current();
281 gr_free_sub_canvas(TmapnameCanvas);
287 #define MAX_REPLACEMENTS 32
289 typedef struct replacement {
293 replacement Replacement_list[MAX_REPLACEMENTS];
294 int Num_replacements=0;
300 for (i=0; i<TMAPS_PER_PAGE; i++ ) {
301 if (TmapBox[i]->b1_clicked && (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps)) {
302 CurrentTmap = i+TexturePage*TMAPS_PER_PAGE;
303 CurrentTexture = TmapList[CurrentTmap];
304 texpage_show_current();
306 if (keyd_pressed[KEY_LSHIFT]) {
307 mprintf((0, "Will replace CurrentTexture (%i) with...(select by pressing Ctrl)\n", CurrentTexture));
308 Replacement_list[Num_replacements].old = CurrentTexture;
311 if (keyd_pressed[KEY_LCTRL]) {
312 mprintf((0, "...Replacement texture for %i is %i\n", Replacement_list[Num_replacements].old, CurrentTexture));
313 Replacement_list[Num_replacements].new = CurrentTexture;
320 void init_replacements(void)
322 Num_replacements = 0;
325 void do_replacements(void)
327 int replnum, segnum, sidenum;
331 for (replnum=0; replnum<Num_replacements; replnum++) {
332 int old_tmap_num, new_tmap_num;
334 old_tmap_num = Replacement_list[replnum].old;
335 new_tmap_num = Replacement_list[replnum].new;
336 Assert(old_tmap_num >= 0);
337 Assert(new_tmap_num >= 0);
339 for (segnum=0; segnum <= Highest_segment_index; segnum++) {
340 segment *segp=&Segments[segnum];
341 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
342 side *sidep=&segp->sides[sidenum];
343 if (sidep->tmap_num == old_tmap_num) {
344 sidep->tmap_num = new_tmap_num;
345 // mprintf((0, "Replacing tmap_num on segment:side = %i:%i\n", segnum, sidenum));
347 if ((sidep->tmap_num2 != 0) && ((sidep->tmap_num2 & 0x3fff) == old_tmap_num)) {
348 if (new_tmap_num == 0) {
349 Int3(); // Error. You have tried to replace a tmap_num2 with
350 // the 0th tmap_num2 which is ILLEGAL!
352 sidep->tmap_num2 = new_tmap_num | (sidep->tmap_num2 & 0xc000);
353 // mprintf((0, "Replacing tmap_num2 on segment:side = %i:%i\n", segnum, sidenum));
362 void do_replacements_all(void)
366 for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
367 load_level(Shareware_level_names[i]);
369 save_level(Shareware_level_names[i]);
372 for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
373 load_level(Registered_level_names[i]);
375 save_level(Registered_level_names[i]);