L1.C 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. #include <stdlib.h>
  53. #include <string.h>
  54. #include <stdio.h>
  55. #include <stdarg.h>
  56. #pragma off (unreferenced)
  57. static char rcsid[] = "$Id: texpage.c 1.13 1994/11/27 23:17:15 matt Exp $";
  58. #pragma on (unreferenced)
  59. #include "inferno.h"
  60. #include "gameseg.h"
  61. #include "screens.h" // For GAME_SCREEN?????
  62. #include "editor.h" // For TMAP_CURBOX??????
  63. #include "gr.h" // For canves, font stuff
  64. #include "ui.h" // For UI_GADGET stuff
  65. #include "textures.h" // For NumTextures
  66. #include "error.h"
  67. #include "key.h"
  68. #include "mono.h"
  69. #include "gamesave.h"
  70. #include "texpage.h"
  71. #define TMAPS_PER_PAGE 12
  72. static UI_GADGET_USERBOX * TmapBox[TMAPS_PER_PAGE];
  73. static UI_GADGET_USERBOX * TmapCurrent;
  74. int CurrentTmap = 0; // Used globally
  75. int CurrentTexture = 0; // Used globally
  76. int TextureLights;
  77. int TextureEffects;
  78. int TextureMetals;
  79. static int TexturePage = 0;
  80. static grs_canvas * TmapnameCanvas;
  81. static char tmap_filename[13];
  82. static void texpage_print_name( char name[13] )
  83. {
  84. int w,h,aw;
  85. int i;
  86. for (i=strlen(name);i<12;i++)
  87. name[i]=' ';
  88. name[i]=0;
  89. gr_set_current_canvas( TmapnameCanvas );
  90. gr_get_string_size( name, &w, &h, &aw );
  91. gr_string( 0, 0, name );
  92. }
  93. static void texpage_display_name( char *format, ... )
  94. {
  95. va_list ap;
  96. va_start(ap, format);
  97. vsprintf(tmap_filename, format, ap);
  98. va_end(ap);
  99. texpage_print_name(tmap_filename);
  100. }
  101. //Redraw the list of textures, based on TexturePage
  102. texpage_redraw()
  103. {
  104. int i;
  105. for (i=0; i<TMAPS_PER_PAGE; i++ )
  106. {
  107. gr_set_current_canvas(TmapBox[i]->canvas);
  108. if (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps )
  109. gr_ubitmap(0,0, Textures[TmapList[i+TexturePage*TMAPS_PER_PAGE]]);
  110. else
  111. gr_clear_canvas( CGREY );
  112. }
  113. }
  114. //shows the current texture, updating the window and printing the name, base
  115. //on CurrentTexture
  116. texpage_show_current()
  117. {
  118. gr_set_current_canvas(TmapCurrent->canvas);
  119. gr_ubitmap(0,0, Textures[CurrentTexture]);
  120. texpage_display_name( TmapInfo[CurrentTexture].filename );
  121. }
  122. int texpage_goto_first()
  123. {
  124. TexturePage=0;
  125. texpage_redraw();
  126. return 1;
  127. }
  128. int texpage_goto_metals()
  129. {
  130. TexturePage=TextureMetals/TMAPS_PER_PAGE;
  131. texpage_redraw();
  132. return 1;
  133. }
  134. // Goto lights (paste ons)
  135. int texpage_goto_lights()
  136. {
  137. TexturePage=TextureLights/TMAPS_PER_PAGE;
  138. texpage_redraw();
  139. return 1;
  140. }
  141. int texpage_goto_effects()
  142. {
  143. TexturePage=TextureEffects/TMAPS_PER_PAGE;
  144. texpage_redraw();
  145. return 1;
  146. }
  147. static int texpage_goto_prev()
  148. {
  149. if (TexturePage > 0) {
  150. TexturePage--;
  151. texpage_redraw();
  152. }
  153. return 1;
  154. }
  155. static int texpage_goto_next()
  156. {
  157. if ((TexturePage+1)*TMAPS_PER_PAGE < Num_tmaps ) {
  158. TexturePage++;
  159. texpage_redraw();
  160. }
  161. return 1;
  162. }
  163. //NOTE: this code takes the texture map number, not this index in the
  164. //list of available textures. There are different if there are holes in
  165. //the list
  166. int texpage_grab_current(int n)
  167. {
  168. int i;
  169. if ( (n<0) || ( n>= Num_tmaps) ) return 0;
  170. CurrentTexture = n;
  171. for (i=0;i<Num_tmaps;i++)
  172. if (TmapList[i] == n) {
  173. CurrentTmap = i;
  174. break;
  175. }
  176. Assert(i!=Num_tmaps);
  177. TexturePage = CurrentTmap / TMAPS_PER_PAGE;
  178. if (TexturePage*TMAPS_PER_PAGE < Num_tmaps )
  179. texpage_redraw();
  180. texpage_show_current();
  181. return 1;
  182. }
  183. // INIT TEXTURE STUFF
  184. void texpage_init( UI_WINDOW * win )
  185. {
  186. int i;
  187. ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 24, 30, 20, "<<", texpage_goto_prev );
  188. ui_add_gadget_button( win, TMAPCURBOX_X + 32, TMAPCURBOX_Y - 24, 30, 20, ">>", texpage_goto_next );
  189. ui_add_gadget_button( win, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 48, 15, 20, "T", texpage_goto_first );
  190. ui_add_gadget_button( win, TMAPCURBOX_X + 17, TMAPCURBOX_Y - 48, 15, 20, "M", texpage_goto_metals );
  191. ui_add_gadget_button( win, TMAPCURBOX_X + 34, TMAPCURBOX_Y - 48, 15, 20, "L", texpage_goto_lights );
  192. ui_add_gadget_button( win, TMAPCURBOX_X + 51, TMAPCURBOX_Y - 48, 15, 20, "E", texpage_goto_effects );
  193. for (i=0;i<TMAPS_PER_PAGE;i++)
  194. 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);
  195. TmapCurrent = ui_add_gadget_userbox( win, TMAPCURBOX_X, TMAPCURBOX_Y, 64, 64 );
  196. TmapnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, TMAPCURBOX_X , TMAPCURBOX_Y + TMAPBOX_H + 10, 100, 20);
  197. gr_set_current_canvas( TmapnameCanvas );
  198. gr_set_curfont( ui_small_font );
  199. gr_set_fontcolor( CBLACK, CWHITE );
  200. texpage_redraw();
  201. // Don't reset the current tmap every time we go back to the editor.
  202. // CurrentTmap = TexturePage*TMAPS_PER_PAGE;
  203. // CurrentTexture = TmapList[CurrentTmap];
  204. texpage_show_current();
  205. }
  206. void texpage_close()
  207. {
  208. gr_free_sub_canvas(TmapnameCanvas);
  209. }
  210. // DO TEXTURE STUFF
  211. #define MAX_REPLACEMENTS 32
  212. typedef struct replacement {
  213. int new, old;
  214. } replacement;
  215. replacement Replacement_list[MAX_REPLACEMENTS];
  216. int Num_replacements=0;
  217. void texpage_do()
  218. {
  219. int i;
  220. for (i=0; i<TMAPS_PER_PAGE; i++ ) {
  221. if (TmapBox[i]->b1_clicked && (i+TexturePage*TMAPS_PER_PAGE < Num_tmaps)) {
  222. CurrentTmap = i+TexturePage*TMAPS_PER_PAGE;
  223. CurrentTexture = TmapList[CurrentTmap];
  224. texpage_show_current();
  225. if (keyd_pressed[KEY_LSHIFT]) {
  226. mprintf((0, "Will replace CurrentTexture (%i) with...(select by pressing Ctrl)\n", CurrentTexture));
  227. Replacement_list[Num_replacements].old = CurrentTexture;
  228. }
  229. if (keyd_pressed[KEY_LCTRL]) {
  230. mprintf((0, "...Replacement texture for %i is %i\n", Replacement_list[Num_replacements].old, CurrentTexture));
  231. Replacement_list[Num_replacements].new = CurrentTexture;
  232. Num_replacements++;
  233. }
  234. }
  235. }
  236. }
  237. void init_replacements(void)
  238. {
  239. Num_replacements = 0;
  240. }
  241. void do_replacements(void)
  242. {
  243. int replnum, segnum, sidenum;
  244. med_compress_mine();
  245. for (replnum=0; replnum<Num_replacements; replnum++) {
  246. int old_tmap_num, new_tmap_num;
  247. old_tmap_num = Replacement_list[replnum].old;
  248. new_tmap_num = Replacement_list[replnum].new;
  249. Assert(old_tmap_num >= 0);
  250. Assert(new_tmap_num >= 0);
  251. for (segnum=0; segnum <= Highest_segment_index; segnum++) {
  252. segment *segp=&Segments[segnum];
  253. for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
  254. side *sidep=&segp->sides[sidenum];
  255. if (sidep->tmap_num == old_tmap_num) {
  256. sidep->tmap_num = new_tmap_num;
  257. // mprintf((0, "Replacing tmap_num on segment:side = %i:%i\n", segnum, sidenum));
  258. }
  259. if ((sidep->tmap_num2 != 0) && ((sidep->tmap_num2 & 0x3fff) == old_tmap_num)) {
  260. if (new_tmap_num == 0) {
  261. Int3(); // Error. You have tried to replace a tmap_num2 with
  262. // the 0th tmap_num2 which is ILLEGAL!
  263. } else {
  264. sidep->tmap_num2 = new_tmap_num | (sidep->tmap_num2 & 0xc000);
  265. // mprintf((0, "Replacing tmap_num2 on segment:side = %i:%i\n", segnum, sidenum));
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. void do_replacements_all(void)
  273. {
  274. int i;
  275. for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
  276. load_level(Shareware_level_names[i]);
  277. do_replacements();
  278. save_level(Shareware_level_names[i]);
  279. }
  280. for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
  281. load_level(Registered_level_names[i]);
  282. do_replacements();
  283. save_level(Registered_level_names[i]);
  284. }
  285. }
  286.