2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2010-12-24 04:26:24 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
2008-04-06 20:23:28 +00:00
|
|
|
* Routines for displaying texture pages
|
2006-03-20 16:43:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "inferno.h"
|
|
|
|
#include "gameseg.h"
|
|
|
|
#include "screens.h" // For GAME_SCREEN?????
|
|
|
|
#include "editor.h" // For TMAP_CURBOX??????
|
|
|
|
#include "gr.h" // For canves, font stuff
|
|
|
|
#include "ui.h" // For UI_GADGET stuff
|
|
|
|
#include "textures.h" // For NumTextures
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "key.h"
|
|
|
|
#include "gamesave.h"
|
2010-12-24 04:26:24 +00:00
|
|
|
#include "mission.h"
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "texpage.h"
|
|
|
|
#include "piggy.h"
|
|
|
|
|
|
|
|
#define TMAPS_PER_PAGE 12
|
|
|
|
|
|
|
|
static UI_GADGET_USERBOX * TmapBox[TMAPS_PER_PAGE];
|
|
|
|
static UI_GADGET_USERBOX * TmapCurrent;
|
|
|
|
|
|
|
|
int CurrentTexture = 0; // Used globally
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2013-11-17 00:42:28 +00:00
|
|
|
#define DXX_TEXTURE_INITIALIZER(D1, D2) D1
|
2013-03-03 01:03:33 +00:00
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2013-11-17 00:42:28 +00:00
|
|
|
#define DXX_TEXTURE_INITIALIZER(D1, D2) D2
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-17 00:42:28 +00:00
|
|
|
int TextureLights = DXX_TEXTURE_INITIALIZER(263, 275);
|
|
|
|
int TextureEffects = DXX_TEXTURE_INITIALIZER(327, 308);
|
|
|
|
int TextureMetals = DXX_TEXTURE_INITIALIZER(156, 202);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
static int TexturePage = 0;
|
|
|
|
|
2014-09-06 23:55:43 +00:00
|
|
|
static grs_subcanvas_ptr TmapnameCanvas;
|
2014-07-23 02:27:22 +00:00
|
|
|
static void texpage_print_name(d_fname name)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int w,h,aw;
|
2014-07-23 02:27:22 +00:00
|
|
|
name.back() = 0;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
gr_set_current_canvas( TmapnameCanvas );
|
|
|
|
gr_get_string_size( name, &w, &h, &aw );
|
|
|
|
gr_string( 0, 0, name );
|
|
|
|
}
|
|
|
|
|
|
|
|
//Redraw the list of textures, based on TexturePage
|
2013-10-27 22:00:14 +00:00
|
|
|
static void texpage_redraw()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
for (i = 0; i < TMAPS_PER_PAGE; i++)
|
|
|
|
{
|
2006-03-20 16:43:15 +00:00
|
|
|
gr_set_current_canvas(TmapBox[i]->canvas);
|
2010-12-24 04:26:24 +00:00
|
|
|
if (i + TexturePage*TMAPS_PER_PAGE < NumTextures)
|
|
|
|
{
|
|
|
|
PIGGY_PAGE_IN(Textures[i + TexturePage*TMAPS_PER_PAGE]);
|
|
|
|
gr_ubitmap(0, 0, &GameBitmaps[Textures[i + TexturePage*TMAPS_PER_PAGE].index]);
|
2006-03-20 16:43:15 +00:00
|
|
|
} else
|
|
|
|
gr_clear_canvas( CGREY );
|
2010-12-24 04:26:24 +00:00
|
|
|
}
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//shows the current texture, updating the window and printing the name, base
|
|
|
|
//on CurrentTexture
|
2013-10-27 22:00:14 +00:00
|
|
|
static void texpage_show_current()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
gr_set_current_canvas(TmapCurrent->canvas);
|
|
|
|
PIGGY_PAGE_IN(Textures[CurrentTexture]);
|
|
|
|
gr_ubitmap(0,0, &GameBitmaps[Textures[CurrentTexture].index]);
|
2014-07-23 02:27:22 +00:00
|
|
|
texpage_print_name( TmapInfo[CurrentTexture].filename );
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int texpage_goto_first()
|
|
|
|
{
|
|
|
|
TexturePage=0;
|
|
|
|
texpage_redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static int texpage_goto_metals()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
TexturePage=TextureMetals/TMAPS_PER_PAGE;
|
|
|
|
texpage_redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Goto lights (paste ons)
|
2013-10-27 22:00:14 +00:00
|
|
|
static int texpage_goto_lights()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
TexturePage=TextureLights/TMAPS_PER_PAGE;
|
|
|
|
texpage_redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-27 22:00:14 +00:00
|
|
|
static int texpage_goto_effects()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
TexturePage=TextureEffects/TMAPS_PER_PAGE;
|
|
|
|
texpage_redraw();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int texpage_goto_prev()
|
|
|
|
{
|
|
|
|
if (TexturePage > 0) {
|
|
|
|
TexturePage--;
|
|
|
|
texpage_redraw();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int texpage_goto_next()
|
|
|
|
{
|
2010-12-24 04:26:24 +00:00
|
|
|
if ((TexturePage + 1)*TMAPS_PER_PAGE < NumTextures)
|
|
|
|
{
|
2006-03-20 16:43:15 +00:00
|
|
|
TexturePage++;
|
|
|
|
texpage_redraw();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//NOTE: this code takes the texture map number, not this index in the
|
|
|
|
//list of available textures. There are different if there are holes in
|
|
|
|
//the list
|
|
|
|
int texpage_grab_current(int n)
|
|
|
|
{
|
2010-12-24 04:26:24 +00:00
|
|
|
if ((n < 0) || (n >= NumTextures)) return 0;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
CurrentTexture = n;
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
TexturePage = CurrentTexture / TMAPS_PER_PAGE;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
if (TexturePage*TMAPS_PER_PAGE < NumTextures)
|
2006-03-20 16:43:15 +00:00
|
|
|
texpage_redraw();
|
|
|
|
|
|
|
|
texpage_show_current();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// INIT TEXTURE STUFF
|
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
void texpage_init( UI_DIALOG * dlg )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 24, 30, 20, "<<", texpage_goto_prev );
|
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 32, TMAPCURBOX_Y - 24, 30, 20, ">>", texpage_goto_next );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 00, TMAPCURBOX_Y - 48, 15, 20, "T", texpage_goto_first );
|
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 17, TMAPCURBOX_Y - 48, 15, 20, "M", texpage_goto_metals );
|
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 34, TMAPCURBOX_Y - 48, 15, 20, "L", texpage_goto_lights );
|
|
|
|
ui_add_gadget_button( dlg, TMAPCURBOX_X + 51, TMAPCURBOX_Y - 48, 15, 20, "E", texpage_goto_effects );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (i=0;i<TMAPS_PER_PAGE;i++)
|
2011-01-17 14:41:05 +00:00
|
|
|
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);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
TmapCurrent = ui_add_gadget_userbox( dlg, TMAPCURBOX_X, TMAPCURBOX_Y, 64, 64 );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
TmapnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, TMAPCURBOX_X , TMAPCURBOX_Y + TMAPBOX_H + 10, 100, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
void texpage_close()
|
|
|
|
{
|
2014-09-06 23:55:43 +00:00
|
|
|
TmapnameCanvas.reset();
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DO TEXTURE STUFF
|
|
|
|
|
|
|
|
#define MAX_REPLACEMENTS 32
|
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct replacement
|
|
|
|
{
|
2013-10-20 22:34:40 +00:00
|
|
|
int n, old;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
replacement Replacement_list[MAX_REPLACEMENTS];
|
|
|
|
int Num_replacements=0;
|
|
|
|
|
2012-03-18 08:01:53 +00:00
|
|
|
int texpage_do(d_event *event)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-04-09 02:12:58 +00:00
|
|
|
if (event->type == EVENT_UI_DIALOG_DRAW)
|
|
|
|
{
|
|
|
|
gr_set_current_canvas( TmapnameCanvas );
|
2014-07-20 03:48:27 +00:00
|
|
|
gr_set_curfont( ui_small_font.get() );
|
2012-04-09 02:12:58 +00:00
|
|
|
gr_set_fontcolor( CBLACK, CWHITE );
|
|
|
|
|
|
|
|
texpage_redraw();
|
|
|
|
|
|
|
|
gr_set_curfont(editor_font);
|
|
|
|
|
|
|
|
// Don't reset the current tmap every time we go back to the editor.
|
|
|
|
// CurrentTexture = TexturePage*TMAPS_PER_PAGE;
|
|
|
|
texpage_show_current();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
for (i=0; i<TMAPS_PER_PAGE; i++ ) {
|
2012-03-18 08:01:53 +00:00
|
|
|
if (GADGET_PRESSED(TmapBox[i]) && (i + TexturePage*TMAPS_PER_PAGE < NumTextures))
|
2010-12-24 04:26:24 +00:00
|
|
|
{
|
|
|
|
CurrentTexture = i + TexturePage*TMAPS_PER_PAGE;
|
2006-03-20 16:43:15 +00:00
|
|
|
texpage_show_current();
|
|
|
|
|
|
|
|
if (keyd_pressed[KEY_LSHIFT]) {
|
|
|
|
Replacement_list[Num_replacements].old = CurrentTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyd_pressed[KEY_LCTRL]) {
|
2013-10-20 22:34:40 +00:00
|
|
|
Replacement_list[Num_replacements].n = CurrentTexture;
|
2006-03-20 16:43:15 +00:00
|
|
|
Num_replacements++;
|
|
|
|
}
|
2012-03-18 08:01:53 +00:00
|
|
|
|
|
|
|
return 1;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-18 08:01:53 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_replacements(void)
|
|
|
|
{
|
|
|
|
Num_replacements = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_replacements(void)
|
|
|
|
{
|
2013-12-29 04:28:07 +00:00
|
|
|
int replnum, sidenum;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
med_compress_mine();
|
|
|
|
|
|
|
|
for (replnum=0; replnum<Num_replacements; replnum++) {
|
|
|
|
int old_tmap_num, new_tmap_num;
|
|
|
|
|
|
|
|
old_tmap_num = Replacement_list[replnum].old;
|
2013-10-20 22:34:40 +00:00
|
|
|
new_tmap_num = Replacement_list[replnum].n;
|
2006-03-20 16:43:15 +00:00
|
|
|
Assert(old_tmap_num >= 0);
|
|
|
|
Assert(new_tmap_num >= 0);
|
|
|
|
|
2013-12-29 04:28:07 +00:00
|
|
|
for (segnum_t segnum=0; segnum <= Highest_segment_index; segnum++) {
|
2006-03-20 16:43:15 +00:00
|
|
|
segment *segp=&Segments[segnum];
|
|
|
|
for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
|
|
|
|
side *sidep=&segp->sides[sidenum];
|
|
|
|
if (sidep->tmap_num == old_tmap_num) {
|
|
|
|
sidep->tmap_num = new_tmap_num;
|
|
|
|
}
|
|
|
|
if ((sidep->tmap_num2 != 0) && ((sidep->tmap_num2 & 0x3fff) == old_tmap_num)) {
|
|
|
|
if (new_tmap_num == 0) {
|
|
|
|
Int3(); // Error. You have tried to replace a tmap_num2 with
|
|
|
|
// the 0th tmap_num2 which is ILLEGAL!
|
|
|
|
} else {
|
|
|
|
sidep->tmap_num2 = new_tmap_num | (sidep->tmap_num2 & 0xc000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_replacements_all(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
for (i = 0; i < Last_level; i++)
|
|
|
|
{
|
|
|
|
load_level(Level_names[i]);
|
2006-03-20 16:43:15 +00:00
|
|
|
do_replacements();
|
2010-12-24 04:26:24 +00:00
|
|
|
save_level(Level_names[i]);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
for (i = 0; i < -Last_secret_level; i++)
|
|
|
|
{
|
|
|
|
load_level(Secret_level_names[i]);
|
2006-03-20 16:43:15 +00:00
|
|
|
do_replacements();
|
2010-12-24 04:26:24 +00:00
|
|
|
save_level(Secret_level_names[i]);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|