Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * |
||
22 | * Routines for displaying texture pages |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | #include <stdlib.h> |
||
27 | #include <string.h> |
||
28 | #include <stdio.h> |
||
29 | #include <stdarg.h> |
||
30 | |||
31 | #include "inferno.h" |
||
32 | #include "gameseg.h" |
||
33 | #include "screens.h" // For GAME_SCREEN????? |
||
34 | #include "editor.h" // For TMAP_CURBOX?????? |
||
35 | #include "gr.h" // For canves, font stuff |
||
36 | #include "ui.h" // For UI_GADGET stuff |
||
37 | #include "textures.h" // For NumTextures |
||
38 | #include "dxxerror.h" |
||
39 | #include "key.h" |
||
40 | #include "event.h" |
||
41 | #include "gamesave.h" |
||
42 | #include "mission.h" |
||
43 | |||
44 | #include "texpage.h" |
||
45 | #include "piggy.h" |
||
46 | |||
47 | #include "compiler-range_for.h" |
||
48 | |||
49 | constexpr std::integral_constant<unsigned, 12> TMAPS_PER_PAGE{}; |
||
50 | |||
51 | static std::array<std::unique_ptr<UI_GADGET_USERBOX>, TMAPS_PER_PAGE> TmapBox; |
||
52 | static std::unique_ptr<UI_GADGET_USERBOX> TmapCurrent; |
||
53 | |||
54 | int CurrentTexture = 0; // Used globally |
||
55 | |||
56 | #if defined(DXX_BUILD_DESCENT_I) |
||
57 | #define DXX_TEXTURE_INITIALIZER(D1, D2) D1 |
||
58 | #elif defined(DXX_BUILD_DESCENT_II) |
||
59 | #define DXX_TEXTURE_INITIALIZER(D1, D2) D2 |
||
60 | #endif |
||
61 | |||
62 | int TextureLights = DXX_TEXTURE_INITIALIZER(263, 275); |
||
63 | int TextureEffects = DXX_TEXTURE_INITIALIZER(327, 308); |
||
64 | int TextureMetals = DXX_TEXTURE_INITIALIZER(156, 202); |
||
65 | |||
66 | namespace { |
||
67 | |||
68 | class texture_dialog |
||
69 | { |
||
70 | public: |
||
71 | std::unique_ptr<UI_GADGET_BUTTON> prev_texture, next_texture, first_texture, metal_texture, light_texture, effects_texture; |
||
72 | }; |
||
73 | |||
74 | } |
||
75 | |||
76 | static texture_dialog texpage_dialog; |
||
77 | |||
78 | static int TexturePage = 0; |
||
79 | |||
80 | static grs_subcanvas_ptr TmapnameCanvas; |
||
81 | static void texpage_print_name(d_fname name) |
||
82 | { |
||
83 | name.back() = 0; |
||
84 | |||
85 | gr_set_current_canvas( TmapnameCanvas ); |
||
86 | gr_string(*grd_curcanv, *grd_curcanv->cv_font, 0, 0, name); |
||
87 | } |
||
88 | |||
89 | //Redraw the list of textures, based on TexturePage |
||
90 | static void texpage_redraw() |
||
91 | { |
||
92 | for (int i = 0; i < TMAPS_PER_PAGE; i++) |
||
93 | { |
||
94 | gr_set_current_canvas(TmapBox[i]->canvas); |
||
95 | if (i + TexturePage*TMAPS_PER_PAGE < NumTextures) |
||
96 | { |
||
97 | PIGGY_PAGE_IN(Textures[i + TexturePage*TMAPS_PER_PAGE]); |
||
98 | gr_ubitmap(*grd_curcanv, GameBitmaps[Textures[i + TexturePage*TMAPS_PER_PAGE].index]); |
||
99 | } else |
||
100 | gr_clear_canvas(*grd_curcanv, CGREY); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | //shows the current texture, updating the window and printing the name, base |
||
105 | //on CurrentTexture |
||
106 | static void texpage_show_current() |
||
107 | { |
||
108 | auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
||
109 | gr_set_current_canvas(TmapCurrent->canvas); |
||
110 | PIGGY_PAGE_IN(Textures[CurrentTexture]); |
||
111 | gr_ubitmap(*grd_curcanv, GameBitmaps[Textures[CurrentTexture].index]); |
||
112 | texpage_print_name( TmapInfo[CurrentTexture].filename ); |
||
113 | } |
||
114 | |||
115 | int texpage_goto_first() |
||
116 | { |
||
117 | TexturePage=0; |
||
118 | texpage_redraw(); |
||
119 | return 1; |
||
120 | } |
||
121 | |||
122 | static int texpage_goto_metals() |
||
123 | { |
||
124 | |||
125 | TexturePage=TextureMetals/TMAPS_PER_PAGE; |
||
126 | texpage_redraw(); |
||
127 | return 1; |
||
128 | } |
||
129 | |||
130 | |||
131 | // Goto lights (paste ons) |
||
132 | static int texpage_goto_lights() |
||
133 | { |
||
134 | TexturePage=TextureLights/TMAPS_PER_PAGE; |
||
135 | texpage_redraw(); |
||
136 | return 1; |
||
137 | } |
||
138 | |||
139 | static int texpage_goto_effects() |
||
140 | { |
||
141 | TexturePage=TextureEffects/TMAPS_PER_PAGE; |
||
142 | texpage_redraw(); |
||
143 | return 1; |
||
144 | } |
||
145 | |||
146 | static int texpage_goto_prev() |
||
147 | { |
||
148 | if (TexturePage > 0) { |
||
149 | TexturePage--; |
||
150 | texpage_redraw(); |
||
151 | } |
||
152 | return 1; |
||
153 | } |
||
154 | |||
155 | static int texpage_goto_next() |
||
156 | { |
||
157 | if ((TexturePage + 1)*TMAPS_PER_PAGE < NumTextures) |
||
158 | { |
||
159 | TexturePage++; |
||
160 | texpage_redraw(); |
||
161 | } |
||
162 | return 1; |
||
163 | } |
||
164 | |||
165 | //NOTE: this code takes the texture map number, not this index in the |
||
166 | //list of available textures. There are different if there are holes in |
||
167 | //the list |
||
168 | int texpage_grab_current(int n) |
||
169 | { |
||
170 | if ((n < 0) || (n >= NumTextures)) return 0; |
||
171 | |||
172 | CurrentTexture = n; |
||
173 | |||
174 | TexturePage = CurrentTexture / TMAPS_PER_PAGE; |
||
175 | |||
176 | if (TexturePage*TMAPS_PER_PAGE < NumTextures) |
||
177 | texpage_redraw(); |
||
178 | |||
179 | texpage_show_current(); |
||
180 | |||
181 | return 1; |
||
182 | } |
||
183 | |||
184 | |||
185 | // INIT TEXTURE STUFF |
||
186 | |||
187 | void texpage_init( UI_DIALOG * dlg ) |
||
188 | { |
||
189 | auto &t = texpage_dialog; |
||
190 | t.prev_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 24, 30, 20, "<<", texpage_goto_prev ); |
||
191 | t.next_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 32, TMAPCURBOX_Y - 24, 30, 20, ">>", texpage_goto_next ); |
||
192 | |||
193 | t.first_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 48, 15, 20, "T", texpage_goto_first ); |
||
194 | t.metal_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 17, TMAPCURBOX_Y - 48, 15, 20, "M", texpage_goto_metals ); |
||
195 | t.light_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 34, TMAPCURBOX_Y - 48, 15, 20, "L", texpage_goto_lights ); |
||
196 | t.effects_texture = ui_add_gadget_button( dlg, TMAPCURBOX_X + 51, TMAPCURBOX_Y - 48, 15, 20, "E", texpage_goto_effects ); |
||
197 | |||
198 | for (int i=0;i<TMAPS_PER_PAGE;i++) |
||
199 | TmapBox[i] = ui_add_gadget_userbox( dlg, TMAPBOX_X + (i/3)*(2+TMAPBOX_W), TMAPBOX_Y + (i%3)*(2+TMAPBOX_H), TMAPBOX_W, TMAPBOX_H); |
||
200 | |||
201 | TmapCurrent = ui_add_gadget_userbox( dlg, TMAPCURBOX_X, TMAPCURBOX_Y, 64, 64 ); |
||
202 | |||
203 | TmapnameCanvas = gr_create_sub_canvas(grd_curscreen->sc_canvas, TMAPCURBOX_X , TMAPCURBOX_Y + TMAPBOX_H + 10, 100, 20); |
||
204 | } |
||
205 | |||
206 | void texpage_close() |
||
207 | { |
||
208 | TmapnameCanvas.reset(); |
||
209 | } |
||
210 | |||
211 | |||
212 | // DO TEXTURE STUFF |
||
213 | |||
214 | #define MAX_REPLACEMENTS 32 |
||
215 | |||
216 | struct replacement |
||
217 | { |
||
218 | int n, old; |
||
219 | }; |
||
220 | |||
221 | int Num_replacements=0; |
||
222 | static std::array<replacement, MAX_REPLACEMENTS> Replacement_list; |
||
223 | |||
224 | int texpage_do(const d_event &event) |
||
225 | { |
||
226 | if (event.type == EVENT_UI_DIALOG_DRAW) |
||
227 | { |
||
228 | gr_set_current_canvas( TmapnameCanvas ); |
||
229 | gr_set_curfont(*grd_curcanv, ui_small_font.get()); |
||
230 | gr_set_fontcolor(*grd_curcanv, CBLACK, CWHITE); |
||
231 | |||
232 | texpage_redraw(); |
||
233 | |||
234 | // Don't reset the current tmap every time we go back to the editor. |
||
235 | // CurrentTexture = TexturePage*TMAPS_PER_PAGE; |
||
236 | texpage_show_current(); |
||
237 | |||
238 | return 1; |
||
239 | } |
||
240 | |||
241 | for (int i=0; i<TMAPS_PER_PAGE; i++ ) { |
||
242 | if (GADGET_PRESSED(TmapBox[i].get()) && (i + TexturePage*TMAPS_PER_PAGE < NumTextures)) |
||
243 | { |
||
244 | CurrentTexture = i + TexturePage*TMAPS_PER_PAGE; |
||
245 | texpage_show_current(); |
||
246 | |||
247 | if (keyd_pressed[KEY_LSHIFT]) { |
||
248 | Replacement_list[Num_replacements].old = CurrentTexture; |
||
249 | } |
||
250 | |||
251 | if (keyd_pressed[KEY_LCTRL]) { |
||
252 | Replacement_list[Num_replacements].n = CurrentTexture; |
||
253 | Num_replacements++; |
||
254 | } |
||
255 | |||
256 | return 1; |
||
257 | } |
||
258 | } |
||
259 | |||
260 | return 0; |
||
261 | } |
||
262 | |||
263 | void init_replacements(void) |
||
264 | { |
||
265 | Num_replacements = 0; |
||
266 | } |
||
267 | |||
268 | void do_replacements(void) |
||
269 | { |
||
270 | med_compress_mine(); |
||
271 | |||
272 | for (int replnum=0; replnum<Num_replacements; replnum++) { |
||
273 | int old_tmap_num, new_tmap_num; |
||
274 | |||
275 | old_tmap_num = Replacement_list[replnum].old; |
||
276 | new_tmap_num = Replacement_list[replnum].n; |
||
277 | Assert(old_tmap_num >= 0); |
||
278 | Assert(new_tmap_num >= 0); |
||
279 | |||
280 | range_for (unique_segment &segp, vmsegptr) |
||
281 | { |
||
282 | range_for (auto &sidep, segp.sides) |
||
283 | { |
||
284 | if (sidep.tmap_num == old_tmap_num) { |
||
285 | sidep.tmap_num = new_tmap_num; |
||
286 | } |
||
287 | if ((sidep.tmap_num2 != 0) && ((sidep.tmap_num2 & 0x3fff) == old_tmap_num)) { |
||
288 | if (new_tmap_num == 0) { |
||
289 | Int3(); // Error. You have tried to replace a tmap_num2 with |
||
290 | // the 0th tmap_num2 which is ILLEGAL! |
||
291 | } else { |
||
292 | sidep.tmap_num2 = new_tmap_num | (sidep.tmap_num2 & 0xc000); |
||
293 | } |
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | |||
299 | } |
||
300 | |||
301 | void do_replacements_all(void) |
||
302 | { |
||
303 | for (int i = 0; i < Last_level; i++) |
||
304 | { |
||
305 | load_level( |
||
306 | #if defined(DXX_BUILD_DESCENT_II) |
||
307 | LevelSharedSegmentState.DestructibleLights, |
||
308 | #endif |
||
309 | Level_names[i]); |
||
310 | do_replacements(); |
||
311 | save_level( |
||
312 | #if defined(DXX_BUILD_DESCENT_II) |
||
313 | LevelSharedSegmentState.DestructibleLights, |
||
314 | #endif |
||
315 | Level_names[i]); |
||
316 | } |
||
317 | |||
318 | for (int i = 0; i < -Last_secret_level; i++) |
||
319 | { |
||
320 | load_level( |
||
321 | #if defined(DXX_BUILD_DESCENT_II) |
||
322 | LevelSharedSegmentState.DestructibleLights, |
||
323 | #endif |
||
324 | Secret_level_names[i]); |
||
325 | do_replacements(); |
||
326 | save_level( |
||
327 | #if defined(DXX_BUILD_DESCENT_II) |
||
328 | LevelSharedSegmentState.DestructibleLights, |
||
329 | #endif |
||
330 | Secret_level_names[i]); |
||
331 | } |
||
332 | |||
333 | } |
||
334 |