Add fixes for menu from xash3d repo.

This commit is contained in:
nekonomicon 2016-04-24 13:36:11 +05:00 committed by Alibek Omarov
parent 9d256c15f1
commit b0d8e59c65
3 changed files with 47 additions and 82 deletions

View File

@ -102,43 +102,25 @@ const char *MenuButtons[PC_BUTTONCOUNT] =
"Spectate games" "Spectate games"
}; };
#pragma pack(push,1) typedef struct bmp_s
typedef struct
{ {
char magic[2]; //char magic[2]; //Useless.
unsigned int filesz; unsigned int filesz;
unsigned short creator1; unsigned short creator1;
unsigned short creator2; unsigned short creator2;
unsigned int bmp_offset; unsigned int bmp_offset;
} bmphdr_t; unsigned int biSize;
#pragma pack(pop) unsigned int biWidth;
unsigned int biHeight;
#ifndef _WIN32 unsigned short biPlanes;
struct BITMAPFILEHEADER unsigned short biBitCount;
{ unsigned int biCompression;
WORD bfType; unsigned int biSizeImage;
DWORD bfSize; unsigned int biXPelsPerMeter;
WORD bfReserved1; unsigned int biYPelsPerMeter;
WORD bfReserved2; unsigned int biClrUsed;
DWORD bfOffBits; unsigned int biClrImportant;
}; }bmp_t;
struct BITMAPINFOHEADER
{
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
};
#endif
/* /*
================= =================
@ -158,58 +140,48 @@ void UI_LoadBmpButtons( void )
return; return;
} }
BITMAPINFOHEADER *pInfoHdr; bmp_t bhdr;
bmphdr_t *pHdr; memcpy( &bhdr, &bmp_buffer[sizeof( short )], sizeof( bmp_t ));
int pallete_sz = bhdr.bmp_offset - sizeof( bmp_t ) - sizeof( short );
pInfoHdr =(BITMAPINFOHEADER *)&bmp_buffer[sizeof(bmphdr_t)]; uiStatic.buttons_height = ( bhdr.biBitCount == 4 ) ? 80 : 78; // bugstompers issues
pHdr = (bmphdr_t*)bmp_buffer; uiStatic.buttons_width = bhdr.biWidth - 3; // make some offset
BITMAPINFOHEADER CuttedDibHdr; int stride = bhdr.biWidth * bhdr.biBitCount / 8;
bmphdr_t CuttedHdr;
memcpy( &CuttedHdr, pHdr, sizeof( bmphdr_t ));
memcpy( &CuttedDibHdr, pInfoHdr, pInfoHdr->biSize );
int pallete_sz = pHdr->bmp_offset - sizeof( bmphdr_t ) - pInfoHdr->biSize;
uiStatic.buttons_height = ( pInfoHdr->biBitCount == 4 ) ? 80 : 78; // bugstompers issues
uiStatic.buttons_width = pInfoHdr->biWidth - 3; // make some offset
int stride = (pInfoHdr->biWidth * pInfoHdr->biBitCount / 8);
int cutted_img_sz = ((stride + 3 ) & ~3) * uiStatic.buttons_height; int cutted_img_sz = ((stride + 3 ) & ~3) * uiStatic.buttons_height;
int CuttedBmpSize = sizeof( bmphdr_t ) + pInfoHdr->biSize + pallete_sz + cutted_img_sz; int CuttedBmpSize = sizeof( bmp_t ) + sizeof( short ) + pallete_sz + cutted_img_sz;
byte *img_data = &bmp_buffer[bmp_len_holder-cutted_img_sz]; byte *img_data = &bmp_buffer[bmp_len_holder-cutted_img_sz];
if ( pInfoHdr->biBitCount <= 8 ) if ( bhdr.biBitCount <= 8 )
{ {
byte* palette=&bmp_buffer[sizeof( bmphdr_t ) + pInfoHdr->biSize]; byte* palette=&bmp_buffer[sizeof( bmp_t ) + sizeof( short )];
byte* firstpixel_col=&palette[img_data[0]*4]; byte* firstpixel_col=&palette[img_data[0]*4];
firstpixel_col[0]=firstpixel_col[1]=firstpixel_col[2]=0; firstpixel_col[0]=firstpixel_col[1]=firstpixel_col[2]=0;
} }
CuttedDibHdr.biHeight = 78; //uiStatic.buttons_height; // determine buttons count by image height...
CuttedHdr.filesz = CuttedBmpSize; // int pic_count = ( pInfoHdr->biHeight == 5538 ) ? PC_BUTTONCOUNT : PC_BUTTONCOUNT - 2;
CuttedDibHdr.biSizeImage = CuttedBmpSize - CuttedHdr.bmp_offset; int pic_count = ( bhdr.biHeight / 78 );
bhdr.biHeight = 78; //uiStatic.buttons_height;
bhdr.filesz = CuttedBmpSize;
bhdr.biSizeImage = CuttedBmpSize - bhdr.bmp_offset;
char fname[256]; char fname[256];
byte *raw_img_buff = (byte *)MALLOC( sizeof( bmphdr_t ) + pInfoHdr->biSize + pallete_sz + cutted_img_sz ); byte *raw_img_buff = (byte *)MALLOC( sizeof( bmp_t ) + sizeof( short ) + pallete_sz + cutted_img_sz );
// determine buttons count by image height...
// int pic_count = ( pInfoHdr->biHeight == 5538 ) ? PC_BUTTONCOUNT : PC_BUTTONCOUNT - 2;
int pic_count = ( pInfoHdr->biHeight / 78 );
for( int i = 0; i < pic_count; i++ ) for( int i = 0; i < pic_count; i++ )
{ {
int offset = sizeof( short );
sprintf( fname, "#btns_%d.bmp", i ); sprintf( fname, "#btns_%d.bmp", i );
int offset = 0; memcpy( raw_img_buff, bmp_buffer, offset);
memcpy( &raw_img_buff[offset], &CuttedHdr, sizeof( bmphdr_t ));
offset += sizeof( bmphdr_t ); memcpy( &raw_img_buff[offset], &bhdr, sizeof( bmp_t ));
offset += sizeof( bmp_t );
memcpy( &raw_img_buff[offset], &CuttedDibHdr, CuttedDibHdr.biSize ); if( bhdr.biBitCount <= 8 )
offset += CuttedDibHdr.biSize;
if( CuttedDibHdr.biBitCount <= 8 )
{ {
memcpy( &raw_img_buff[offset], &bmp_buffer[offset], pallete_sz ); memcpy( &raw_img_buff[offset], &bmp_buffer[offset], pallete_sz );
offset += pallete_sz; offset += pallete_sz;
@ -217,7 +189,7 @@ void UI_LoadBmpButtons( void )
memcpy( &raw_img_buff[offset], img_data, cutted_img_sz ); memcpy( &raw_img_buff[offset], img_data, cutted_img_sz );
// upload image into viedo memory // upload image into video memory
uiStatic.buttonsPics[i] = PIC_Load( fname, raw_img_buff, CuttedBmpSize ); uiStatic.buttonsPics[i] = PIC_Load( fname, raw_img_buff, CuttedBmpSize );
img_data -= cutted_img_sz; img_data -= cutted_img_sz;

View File

@ -94,6 +94,9 @@ static void UI_CreateGame_Begin( void )
if( CVAR_GET_FLOAT( "host_serverstate" ) && CVAR_GET_FLOAT( "maxplayers" ) == 1 ) if( CVAR_GET_FLOAT( "host_serverstate" ) && CVAR_GET_FLOAT( "maxplayers" ) == 1 )
HOST_ENDGAME( "end of the game" ); HOST_ENDGAME( "end of the game" );
if( atoi( uiCreateGame.maxClients.buffer ) > 32 )
strcpy( uiCreateGame.maxClients.buffer, "32" );
CVAR_SET_FLOAT( "deathmatch", 1.0f ); // start deathmatch as default CVAR_SET_FLOAT( "deathmatch", 1.0f ); // start deathmatch as default
CVAR_SET_FLOAT( "maxplayers", atoi( uiCreateGame.maxClients.buffer )); CVAR_SET_FLOAT( "maxplayers", atoi( uiCreateGame.maxClients.buffer ));
CVAR_SET_STRING( "hostname", uiCreateGame.hostName.buffer ); CVAR_SET_STRING( "hostname", uiCreateGame.hostName.buffer );
@ -386,7 +389,7 @@ static void UI_CreateGame_Init( void )
uiCreateGame.maxClients.generic.y = 360; uiCreateGame.maxClients.generic.y = 360;
uiCreateGame.maxClients.generic.width = 205; uiCreateGame.maxClients.generic.width = 205;
uiCreateGame.maxClients.generic.height = 32; uiCreateGame.maxClients.generic.height = 32;
uiCreateGame.maxClients.maxLength = 3; uiCreateGame.maxClients.maxLength = 2;
if( CVAR_GET_FLOAT( "maxplayers" ) <= 1 ) if( CVAR_GET_FLOAT( "maxplayers" ) <= 1 )
strcpy( uiCreateGame.maxClients.buffer, "8" ); strcpy( uiCreateGame.maxClients.buffer, "8" );

View File

@ -104,16 +104,6 @@ static void UI_FileDialog_Callback( void *self, int event )
{ {
menuCommon_s *item = (menuCommon_s *)self; menuCommon_s *item = (menuCommon_s *)self;
switch( item->id )
{/*
// checkboxes
case ID_XXX
if( event == QM_PRESSED )
((menuCheckBox_s *)self)->focusPic = UI_CHECKBOX_PRESSED;
else ((menuCheckBox_s *)self)->focusPic = UI_CHECKBOX_FOCUS;
break;*/
}
if( event == QM_CHANGED ) if( event == QM_CHANGED )
{ {
switch( item->id ) switch( item->id )