home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / texpage.c < prev    next >
Text File  |  1998-06-08  |  9KB  |  365 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/texpage.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:34:51 $
  6.  * 
  7.  * Routines for displaying texture pages
  8.  * 
  9.  * $Log: texpage.c $
  10.  * Revision 2.0  1995/02/27  11:34:51  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.14  1995/01/14  19:18:02  john
  15.  * First version of object paging.
  16.  * 
  17.  * Revision 1.13  1994/11/27  23:17:15  matt
  18.  * Made changes for new mprintf calling convention
  19.  * 
  20.  * Revision 1.12  1994/11/23  15:49:00  mike
  21.  * fix bug in tmapnum == 0 always getting reassigned.
  22.  * 
  23.  * Revision 1.11  1994/11/23  12:17:34  mike
  24.  * changing texture maps in all mines.
  25.  * 
  26.  * Revision 1.10  1994/11/19  00:04:42  john
  27.  * Changed some shorts to ints.
  28.  * 
  29.  * Revision 1.9  1994/11/16  17:59:36  john
  30.  * Fixed bug with writing to canvas before initing it.
  31.  * 
  32.  * Revision 1.8  1994/11/16  13:15:21  matt
  33.  * Fixed grab bug, and cleaned up code
  34.  * 
  35.  * Revision 1.7  1994/08/05  12:26:37  matt
  36.  * Fixed overplot problem with texture names
  37.  * 
  38.  * Revision 1.6  1994/04/11  12:01:58  yuan
  39.  * Fixed resetting to first texture on page annoyance.
  40.  * 
  41.  * Revision 1.5  1994/04/01  11:15:53  yuan
  42.  * Added objects to objpage. Added buttons for easier tmap scrolling.
  43.  * Objects are selected fully from objpage and add object menu or pad.
  44.  * 
  45.  * Revision 1.4  1994/03/15  16:33:37  yuan
  46.  * Fixed bm loader (might have some changes in walls and switches)
  47.  * 
  48.  * Revision 1.3  1993/12/16  17:25:46  john
  49.  * Moved texture and object selection to texpage and objpage
  50.  * 
  51.  * Revision 1.2  1993/12/16  15:57:39  john
  52.  * moved texture selection stuff to texpage.c
  53.  * 
  54.  * Revision 1.1  1993/12/16  15:06:56  john
  55.  * Initial revision
  56.  * 
  57.  * 
  58.  */
  59.  
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <stdio.h>
  63. #include <stdarg.h>
  64.  
  65. #pragma off (unreferenced)
  66. static char rcsid[] = "$Id: texpage.c 2.0 1995/02/27 11:34:51 john Exp $";
  67. #pragma on (unreferenced)
  68.  
  69. #include "inferno.h"
  70. #include "gameseg.h"
  71. #include "screens.h"            // For GAME_SCREEN?????
  72. #include "editor.h"            // For TMAP_CURBOX??????
  73. #include "gr.h"                // For canves, font stuff
  74. #include "ui.h"                // For UI_GADGET stuff
  75. #include "textures.h"        // For NumTextures
  76. #include "error.h"
  77. #include "key.h"
  78. #include "mono.h"
  79. #include "gamesave.h"
  80.  
  81. #include "texpage.h"
  82. #include "piggy.h"
  83.  
  84. #define TMAPS_PER_PAGE 12
  85.  
  86. static UI_GADGET_USERBOX * TmapBox[TMAPS_PER_PAGE];
  87. static UI_GADGET_USERBOX * TmapCurrent;
  88.  
  89. int CurrentTmap = 0;        // Used globally
  90. int CurrentTexture = 0;        // Used globally
  91.  
  92. int TextureLights;
  93. int TextureEffects;
  94. int TextureMetals;
  95.  
  96. static int TexturePage = 0;
  97.  
  98. static grs_canvas * TmapnameCanvas;
  99. static char tmap_filename[13];
  100.  
  101. static void texpage_print_name( char name[13] ) 
  102. {
  103.      int w,h,aw;
  104.     int i;
  105.  
  106.     for (i=strlen(name);i<12;i++)
  107.         name[i]=' ';
  108.     name[i]=0;
  109.     
  110.     gr_set_current_canvas( TmapnameCanvas );
  111.     gr_get_string_size( name, &w, &h, &aw );
  112.     gr_string( 0, 0, name );              
  113. }
  114.  
  115. static void texpage_display_name( char *format, ... ) 
  116. {
  117.     va_list ap;
  118.  
  119.     va_start(ap, format);
  120.    vsprintf(tmap_filename, format, ap);
  121.     va_end(ap);
  122.  
  123.    texpage_print_name(tmap_filename);
  124. }
  125.  
  126. //Redraw the list of textures, based on TexturePage
  127. texpage_redraw()
  128. {
  129.     int i;
  130.  
  131.     for (i=0;  i<TMAPS_PER_PAGE; i++ )
  132.         {
  133.         gr_set_current_canvas(TmapBox[i]->canvas);
  134.         if (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps )    {
  135.             PIGGY_PAGE_IN( Textures[TmapList[i+TexturePage*TMAPS_PER_PAGE]]);
  136.             gr_ubitmap(0,0, &GameBitmaps[Textures[TmapList[i+TexturePage*TMAPS_PER_PAGE]].index]);
  137.         } else 
  138.             gr_clear_canvas( CGREY );
  139.         }
  140. }
  141.  
  142. //shows the current texture, updating the window and printing the name, base
  143. //on CurrentTexture
  144. texpage_show_current()
  145. {
  146.     gr_set_current_canvas(TmapCurrent->canvas);
  147.     PIGGY_PAGE_IN(Textures[CurrentTexture]);
  148.     gr_ubitmap(0,0, &GameBitmaps[Textures[CurrentTexture].index]);
  149.     texpage_display_name( TmapInfo[CurrentTexture].filename );
  150. }
  151.  
  152. int texpage_goto_first()
  153. {
  154.     TexturePage=0;
  155.     texpage_redraw();
  156.     return 1;
  157. }
  158.  
  159. int texpage_goto_metals()
  160. {
  161.  
  162.     TexturePage=TextureMetals/TMAPS_PER_PAGE;
  163.     texpage_redraw();
  164.     return 1;
  165. }
  166.  
  167.  
  168. // Goto lights (paste ons)
  169. int texpage_goto_lights()
  170. {
  171.     TexturePage=TextureLights/TMAPS_PER_PAGE;
  172.     texpage_redraw();
  173.     return 1;
  174. }
  175.  
  176. int texpage_goto_effects()
  177. {
  178.     TexturePage=TextureEffects/TMAPS_PER_PAGE;
  179.     texpage_redraw();
  180.     return 1;
  181. }
  182.  
  183. static int texpage_goto_prev()
  184. {
  185.     if (TexturePage > 0) {
  186.         TexturePage--;
  187.         texpage_redraw();
  188.     }
  189.     return 1;
  190. }
  191.  
  192. static int texpage_goto_next()
  193. {
  194.     if ((TexturePage+1)*TMAPS_PER_PAGE < Num_tmaps ) {
  195.         TexturePage++;
  196.         texpage_redraw();
  197.     }
  198.     return 1;
  199. }
  200.  
  201. //NOTE:  this code takes the texture map number, not this index in the
  202. //list of available textures.  There are different if there are holes in
  203. //the list
  204. int texpage_grab_current(int n)
  205. {
  206.     int i;
  207.  
  208.     if ( (n<0) || ( n>= Num_tmaps) ) return 0;
  209.  
  210.     CurrentTexture = n;
  211.  
  212.     for (i=0;i<Num_tmaps;i++)
  213.         if (TmapList[i] == n) {
  214.             CurrentTmap = i;
  215.             break;
  216.         }
  217.     Assert(i!=Num_tmaps);
  218.     
  219.     TexturePage = CurrentTmap / TMAPS_PER_PAGE;
  220.     
  221.     if (TexturePage*TMAPS_PER_PAGE < Num_tmaps )
  222.         texpage_redraw();
  223.  
  224.     texpage_show_current();
  225.     
  226.     return 1;
  227. }
  228.  
  229.  
  230. // INIT TEXTURE STUFF
  231.  
  232. void texpage_init( UI_WINDOW * win )
  233. {
  234.     int i;
  235.  
  236.     ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 24, 30, 20, "<<", texpage_goto_prev );
  237.     ui_add_gadget_button( win, TMAPCURBOX_X + 32, TMAPCURBOX_Y - 24, 30, 20, ">>", texpage_goto_next );
  238.  
  239.     ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 48, 15, 20, "T", texpage_goto_first );
  240.     ui_add_gadget_button( win, TMAPCURBOX_X + 17, TMAPCURBOX_Y - 48, 15, 20, "M", texpage_goto_metals );
  241.     ui_add_gadget_button( win, TMAPCURBOX_X + 34, TMAPCURBOX_Y - 48, 15, 20, "L", texpage_goto_lights );
  242.     ui_add_gadget_button( win, TMAPCURBOX_X + 51, TMAPCURBOX_Y - 48, 15, 20, "E", texpage_goto_effects );
  243.     
  244.  
  245.     for (i=0;i<TMAPS_PER_PAGE;i++)
  246.         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);
  247.  
  248.     TmapCurrent = ui_add_gadget_userbox( win, TMAPCURBOX_X, TMAPCURBOX_Y, 64, 64 );
  249.  
  250.     TmapnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, TMAPCURBOX_X , TMAPCURBOX_Y + TMAPBOX_H + 10, 100, 20);
  251.     gr_set_current_canvas( TmapnameCanvas );
  252.     gr_set_curfont( ui_small_font ); 
  253.    gr_set_fontcolor( CBLACK, CWHITE );
  254.  
  255.     texpage_redraw();
  256.  
  257. // Don't reset the current tmap every time we go back to the editor.
  258. //    CurrentTmap = TexturePage*TMAPS_PER_PAGE;
  259. //    CurrentTexture = TmapList[CurrentTmap];
  260.     texpage_show_current();
  261.  
  262. }
  263.  
  264. void texpage_close()
  265. {
  266.     gr_free_sub_canvas(TmapnameCanvas);
  267. }
  268.  
  269.  
  270. // DO TEXTURE STUFF
  271.  
  272. #define    MAX_REPLACEMENTS    32
  273.  
  274. typedef struct replacement {
  275.     int    new, old;
  276. } replacement;
  277.  
  278. replacement Replacement_list[MAX_REPLACEMENTS];
  279. int    Num_replacements=0;
  280.  
  281. void texpage_do()
  282. {
  283.     int i;
  284.  
  285.     for (i=0; i<TMAPS_PER_PAGE; i++ ) {
  286.         if (TmapBox[i]->b1_clicked && (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps)) {
  287.             CurrentTmap = i+TexturePage*TMAPS_PER_PAGE;
  288.             CurrentTexture = TmapList[CurrentTmap];
  289.             texpage_show_current();
  290.  
  291.             if (keyd_pressed[KEY_LSHIFT]) {
  292.                 mprintf((0, "Will replace CurrentTexture (%i) with...(select by pressing Ctrl)\n", CurrentTexture));
  293.                 Replacement_list[Num_replacements].old = CurrentTexture;
  294.             }
  295.  
  296.             if (keyd_pressed[KEY_LCTRL]) {
  297.                 mprintf((0, "...Replacement texture for %i is %i\n", Replacement_list[Num_replacements].old, CurrentTexture));
  298.                 Replacement_list[Num_replacements].new = CurrentTexture;
  299.                 Num_replacements++;
  300.             }
  301.         }
  302.     }
  303. }
  304.  
  305. void init_replacements(void)
  306. {
  307.     Num_replacements = 0;
  308. }
  309.  
  310. void do_replacements(void)
  311. {
  312.     int    replnum, segnum, sidenum;
  313.  
  314.     med_compress_mine();
  315.  
  316.     for (replnum=0; replnum<Num_replacements; replnum++) {
  317.         int    old_tmap_num, new_tmap_num;
  318.  
  319.         old_tmap_num = Replacement_list[replnum].old;
  320.         new_tmap_num = Replacement_list[replnum].new;
  321.         Assert(old_tmap_num >= 0);
  322.         Assert(new_tmap_num >= 0);
  323.  
  324.         for (segnum=0; segnum <= Highest_segment_index; segnum++) {
  325.             segment    *segp=&Segments[segnum];
  326.             for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
  327.                 side    *sidep=&segp->sides[sidenum];
  328.                 if (sidep->tmap_num == old_tmap_num) {
  329.                     sidep->tmap_num = new_tmap_num;
  330.                     // mprintf((0, "Replacing tmap_num on segment:side = %i:%i\n", segnum, sidenum));
  331.                 }
  332.                 if ((sidep->tmap_num2 != 0) && ((sidep->tmap_num2 & 0x3fff) == old_tmap_num)) {
  333.                     if (new_tmap_num == 0) {
  334.                         Int3();    //    Error.  You have tried to replace a tmap_num2 with 
  335.                                     //    the 0th tmap_num2 which is ILLEGAL!
  336.                     } else {
  337.                         sidep->tmap_num2 = new_tmap_num | (sidep->tmap_num2 & 0xc000);
  338.                         // mprintf((0, "Replacing tmap_num2 on segment:side = %i:%i\n", segnum, sidenum));
  339.                     }
  340.                 }
  341.             }
  342.         }
  343.     }
  344.  
  345. }
  346.  
  347. void do_replacements_all(void)
  348. {
  349.     int    i;
  350.  
  351.     for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
  352.         load_level(Shareware_level_names[i]);
  353.         do_replacements();
  354.         save_level(Shareware_level_names[i]);
  355.     }
  356.  
  357.     for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
  358.         load_level(Registered_level_names[i]);
  359.         do_replacements();
  360.         save_level(Registered_level_names[i]);
  361.     }
  362.  
  363. }
  364.  
  365.