Code:
char pic_name[80];
void SetupHangarMenu(int NationOrd, Menu ** menu, int Special, InputInfo *input)
{
if (!Special)
{
get_hangar_picname(pic_name);
strcpy(menu_over_pic,pic_name);
sprintf(message,"hangar%s.mnu",pilot_pre[NationOrd]);
*menu = load_menu(message , pic_name);
readpictopal(Windows[DISPLAY_PAGE], pic_name, MyPal);
SetHangarAnimations();
SetAnimDrawPage((*menu)->Window);
}
else
{
get_special_hangar_picname(pic_name);
strcpy(menu_over_pic,pic_name);
if (is_campaign_mission())
{
if (NationOrd==0)
sprintf(message,"outsidgr.mnu");
else
sprintf(message,"outsiduk.mnu");
}
else
{
sprintf(message,"hangar%s.mnu",pilot_pre[NationOrd]);
}
*menu=load_menu(message, pic_name);
readpictopal(Windows[DISPLAY_PAGE],pic_name,MyPal);
}
InitInputInfo(input, menu_stuff, DoAnimationStuff, &screen_hot_spots[0], screen_hot_count, 0);
if (!Special)
DoAnimationStuff(input);
// turn off view plane
offit_screen_hot(5);
if( GameSetup.GameType != GS_SINGLE_MISSION )
{
// mission parameter option is only for single mission
offit_screen_hot(3);
}
}
int hangar_menu(void)
{
Menu *menu;
InputInfo input;
int done, selection, quit;
// HotSpot *hs;
UWORD save_wf;
BOOL Special = use_special_hanger();
save_wf=window_flags;
window_flags&=~WF_IGNOREBACK_BUILD;
NationOrd = GetNationOrd(player_nation);
// if (NationOrd > 1) NationOrd = 1;
FadeOutMusic();
quit = done = FALSE;
fade_flag = DO_NOTHING;
SetupHangarMenu(NationOrd, &menu, Special, &input);
state_screen_hots(TRUE,4);
sync_display_pages();
fade_in();
while (!done)
{
if (fade_flag == FADE_BACKPIC)
{
cursor.Status &= CURSOR_OFF;
show_pic( pic_name, FADE_IN_ONLY );
fade_flag = DO_NOTHING;
}
selection = get_input( &input );
switch ( selection )
{
case 2:
remove_menu(menu);
if (!Special)
WipeAnimations();
hangar_chalkboard();
if (!Special)
SetHangarAnimations();
ClearBuffer(NULL);
restore_menu(menu);
state_screen_hots(FALSE,4);
fade_flag = FADE_BACKPIC;
window_flags = save_wf;
break;
case 3:
if (GameSetup.GameType == GS_SINGLE_MISSION)
{
// remove_menu(menu);
delete_menu(menu);
screen_hot_count = 0;
clear_bytes(&screen_hot_spots[0], MAX_SCREEN_HOTSPOTS * sizeof(HotSpot));
if (!use_special_hanger())
WipeAnimations();
SingleSetup();
save_last_mission();
if (!use_special_hanger())
SetHangarAnimations();
// ClearBuffer(NULL);
NationOrd = GetNationOrd(player_nation);
SetupHangarMenu(NationOrd, &menu, use_special_hanger(), &input);
menu->Status |= RENDER_MENU;
// state_screen_hots(FALSE,4);
fade_flag = FADE_BACKPIC;
window_flags = save_wf;
}
break;
case 6:
case 7:
case KBD_ALT_F:
done = TRUE;
break;
case 1:
case ABORT:
done = TRUE;
quit = TRUE;
break;
}
}
fade_out();
if (!Special)
WipeAnimations();
fade_flag = FADE_BACKPIC;
clear_screen_hot_spots();
delete_menu(menu);
ClearBuffer(NULL);
return(!quit);
}
void offit_screen_hot(UWORD ReturnCode)
{
HotSpot *hs;
for ( hs = screen_hot_spots; hs < &screen_hot_spots[screen_hot_count]; hs++ )
{
if ( (hs->Status & HS_ACTIVE) && hs->ReturnCode==ReturnCode)
{
if (hs->Text)
{
GmFree(hs->Text);
hs->Text = NULL;
}
hs->Status &= ~HS_ACTIVE;
return;
}
}
}
Plane *get_hngr_plane_picname(char *pic_name) // cj this calls the profile view of the cockpit image....not used
{
sprintf(pic_name, "plane%02d.mpc", player_plane_type);
return (current_plane);
}
void get_hangar_picname(char *pic_name)
{
sprintf(pic_name, "hngr%02d.mpc", player_plane_type);
}
void get_special_hangar_picname(char *pic_name)
{
sprintf(pic_name, "outsid%02d.mpc", player_plane_type);
}
Code:
#include "xvars.h"
static PALETTEENTRY MenuColors[12];
static int menu_pal_loaded;
void readpicnopal( Window *window, char *filename)
{
readpictopal( window, filename, NULL);
}
void readpaltopal( char *filename, PALETTEENTRY *palette)
{
PicHeader hdr;
int fd;
if ((fd = Copen(filename, O_RDONLY|O_BINARY)) == -1)
clean_exit(ERR_PIC_NOT_FOUND, "Pic not Found %s!\n", filename);
ReadPicHeader(fd, &hdr, palette);
close(fd);
return;
}
void readpictopal( Window *window, char *filename, PALETTEENTRY *palette )
{
int fd;
if (!window)
clean_exit(757,"Error calling readpictopal %s\n", filename);
if ((fd = Copen(filename, O_RDONLY|O_BINARY)) == -1)
clean_exit(ERR_PIC_NOT_FOUND, "Pic not Found %s!\n", filename);
LZWUnCompress(fd, window, palette);
close(fd);
return;
}
void readpictopal16( Window *window, char *filename, PALETTEENTRY *palette )
{
int fd;
if (!window)
clean_exit(757,"Error calling readpictopal16 %s\n", filename);
if ((fd = Copen(filename, O_RDONLY|O_BINARY)) == -1)
clean_exit(ERR_PIC_NOT_FOUND, "Pic not Found %s!\n", filename);
if ( window != NULL ) {
// alloc temporary storage
Window *win;
win = AllocWindow(window->Width,window->Height);
LZWUnCompress(fd, win, palette);
// make 16 bit palette here
Make16BitReferencedPalette(palette);
// copy bytes to original window, through 16bit index palette
Copy8BitTo16BitWithPalette(win->Buffer,(short*)window->Buffer,palette,window->Width,window->Height,window->Pitch);
// we're done (hopefully)
GmFree(win);
}
close(fd);
return;
}
LPDIRECTDRAWSURFACE CreateDDSurfaceFromPict( char *filename, PALETTEENTRY *palette )
{
Window *win;
PicHeader hdr;
void *ptr;
int fd;
int w,h;
LPDIRECTDRAWSURFACE ddsurf;
DDSURFACEDESC ddsd;
// open file
if ((fd = Copen(filename, O_RDONLY|O_BINARY)) == -1)
clean_exit(ERR_PIC_NOT_FOUND, "Pic not Found %s!\n", filename);
// read file header to get size
ReadPicHeader(fd, &hdr, palette);
w = hdr.Width;
h = hdr.Height;
// seek back to beginning of file
lseek(fd, 0L, SEEK_SET);
// create surface of the right size
ddsurf = ddAllocSurface(w,h);
// check to see if we're 8 bit or 16 bit
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsurf->lpVtbl->GetSurfaceDesc(ddsurf,&ddsd);
// alloc temporary storage
win = AllocWindow(w,h);
LZWUnCompress(fd, win, palette);
// lock surface
ptr = (void *)ddLock(ddsurf);
// load based on size
if ( ddsd.ddpfPixelFormat.dwRGBBitCount == 16 ) {
// make 16 bit palette here
Make16BitReferencedPalette(palette);
// copy bytes to original window, through 16bit index palette
Copy8BitTo16BitWithPalette(win->Buffer,ptr,palette,w,h,ddsd.lPitch);
} else {
// copy bytes directly
memcpy(ptr,win->Buffer,w*h);
}
// unlock surface
ddUnlock(ddsurf,ptr);
// we're done (hopefully)
GmFree(win->Buffer);
GmFree(win);
// close the file
close(fd);
return ddsurf;
}
size_t readpicheader(char *filename, PicHeader *hdr, PALETTEENTRY *palette)
{
int fd;
size_t amount_read;
if ( (fd = Copen(filename, O_RDONLY|O_BINARY)) == -1)
clean_exit(ERR_PIC_NOT_FOUND, "Pic not Found %s!\n", filename);
amount_read = ReadPicHeader(fd, hdr, palette);
close(fd);
return(amount_read);
}
size_t ReadPicHeader(int file_handle, PicHeader *hdr, PALETTEENTRY *palette)
{
size_t read_size;
ColorTriplet rgb[256], *rgb_entry;
PALETTEENTRY *pal_entry;
int i;
if( (read_size = read(file_handle, hdr, sizeof(PicHeader))) == sizeof(PicHeader))
{
if (hdr->Status & PIC_PAL_DEFINED)
{
if (palette)
{
//
// The disk image palette is RGB (3 bytes), but our palette in memory is RGBx (dword)
//
read_size += read(file_handle, &rgb[0], 256*3); // read disk image of palette.
if(!(hdr->Status & PIC_8_BIT_PAL)) // if this is a 6 bit pallette make it a
{ // 8 bit pal for windows.
rgb_entry = &rgb[0];
pal_entry = palette;
for (i=0; i<256; i++, pal_entry++, rgb_entry++)
{
pal_entry->peRed = rgb_entry->Red << 2;
pal_entry->peGreen = rgb_entry->Green << 2;
pal_entry->peBlue = rgb_entry->Blue << 2;
pal_entry->peFlags = 0;
// RJH debug
// dprintf("RPH : %d : in <%3d,%3d,%3d> out <%3d,%3d,%3d> \n",i,rgb_entry->Red,rgb_entry->Green,rgb_entry->Blue,pal_entry->peRed,pal_entry->peGreen,pal_entry->peBlue);
}
}
else
{
CopyTripletPal2Pal(&rgb[0], palette, 256);
}
if (menu_pal_loaded)
CopyPal2Pal(MenuColors, palette, 12);
}
else
lseek(file_handle, 256*3, SEEK_CUR); // skip over the pallette
}
}
return (read_size);
}
void LoadMenuColors(void)
{
PALETTEENTRY temp[256];
menu_pal_loaded = FALSE;
readpaltopal( "menu.pal", temp);
CopyPal2Pal(temp, MenuColors, 12);
menu_pal_loaded = TRUE;
}
void UnloadMenuColors( void )
{
menu_pal_loaded = FALSE;
}