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