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

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