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

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