@ -935,74 +935,76 @@ void ShowPatchesSelection()
AllocateWindowDesc ( & _patches_selection_desc ) ;
}
struct GRFFile * _sel_grffile ;
enum {
NEwGRF_WND_PROC_OFFSET_TOP_WIDGET = 14 ,
NEWGRF_WND_PROC_ROWSIZE = 14
} ;
static void NewgrfWndProc ( Window * w , WindowEvent * e )
{
uint i = 0 ;
switch ( e - > event ) {
switch ( e - > event ) {
case WE_PAINT : {
int x , y = 15 ;
struct GRFFile * c = _first_grffile ;
int x , y = NEwGRF_WND_PROC_OFFSET_TOP_WIDGET ;
uint16 i = 0 ;
struct GRFFile * c = _first_grffile ;
DrawWindowWidgets ( w ) ;
if ( _first_grffile = = NULL ) { // no grf sets installed
if ( _first_grffile = = NULL ) { // no grf sets installed
DrawStringMultiCenter ( 140 , 240 , STR_NEWGRF_NO_FILES_INSTALLED , 250 ) ;
break ;
}
// draw list of all grf files
while ( c ! = NULL ) {
if ( i > = w - > vscroll . pos ) { // draw files according to scrollbar position
if ( _sel_grffile = = c ) GfxFillRect ( 2 , y - 1 , 267 , y + 12 , 10 ) ; // show highlighted item with a different background
DrawSprite ( SPRITE_PALETTE ( 0x2EB | 0x30b8000 ) , 5 , y + 2 ) ;
DoDrawString ( c - > filename , 25 , y + 2 , 0x10 ) ; // will be grf name later
y + = 15 ;
while ( c ! = NULL ) {
if ( i > = w - > vscroll . pos ) { // draw files according to scrollbar position
DrawSprite ( SPRITE_PALETTE ( 0x2EB | 0x30b8000 ) , 5 , y + 3 ) ;
// give highlighted item other colour
// XXX - will be grf name later
DoDrawString ( c - > filename , 25 , y + 2 , ( _sel_grffile = = c ) ? 0xC : 0x10 ) ;
y + = NEWGRF_WND_PROC_ROWSIZE ;
}
c = c - > next ;
if ( + + i > = 12 + w - > vscroll . pos ) break ; // stop after displaying 12 items
c = c - > next ;
if ( + + i = = w - > vscroll . cap + w - > vscroll . pos ) break ; // stop after displaying 12 items
}
// DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name
if ( _sel_grffile = = NULL ) { // no grf file selected yet
DrawStringMultiCenter ( 140 , 2 40 , STR_NEWGRF_TIP , 250 ) ;
if ( _sel_grffile = = NULL ) { // no grf file selected yet
DrawStringMultiCenter ( 140 , 2 29 , STR_NEWGRF_TIP , 250 ) ;
} else {
// draw filename
x = DrawString ( 5 , 210 , STR_NEWGRF_FILENAME , 0 ) ;
DoDrawString ( _sel_grffile - > filename , x + 2 , 210 , 0x01 ) ;
x = DrawString ( 5 , 199 , STR_NEWGRF_FILENAME , 0 ) ;
DoDrawString ( _sel_grffile - > filename , x + 2 , 199 , 0x01 ) ;
// draw grf id
x = DrawString ( 5 , 2 2 0, STR_NEWGRF_GRF_ID , 0 ) ;
x = DrawString ( 5 , 2 09 , STR_NEWGRF_GRF_ID , 0 ) ;
SET_DPARAM16 ( 0 , _sel_grffile - > grfid ) ;
DrawString ( x + 2 , 2 2 0, STR_7024 , 0x01 ) ;
DrawString ( x + 2 , 2 09 , STR_7024 , 0x01 ) ;
}
} break ;
} break ;
case WE_CLICK :
switch ( e - > click . widget ) {
case 2 : { // select a grf file
int y ;
int y = ( e - > click . pt . y - NEwGRF_WND_PROC_OFFSET_TOP_WIDGET ) / NEWGRF_WND_PROC_ROWSIZE ;
y = e - > click . pt . y - 16 ;
if ( y < 0 ) return ;
if ( y > = w - > vscroll . cap ) { return ; } // click out of bounds
y + = w - > vscroll . pos ;
y = ( y / 15 ) + w - > vscroll . pos ; // calc selected item
if ( y > = _grffile_count ) return ;
_sel_grffile = _first_grffile ;
while ( y ) {
_sel_grffile = _sel_grffile - > next ;
y - - ;
}
// get selected grf-file
while ( y - - ! = 0 ) _sel_grffile = _sel_grffile - > next ;
SetWindowDirty ( w ) ;
} break ;
case 9 :
} break ;
case 9 : /* Cancel button */
DeleteWindowById ( WC_GAME_OPTIONS , 0 ) ;
break ;
} break ;
@ -1029,22 +1031,22 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
static const Widget _newgrf_widgets [ ] = {
{ WWT_CLOSEBOX , 14 , 0 , 10 , 0 , 13 , STR_00C5 , STR_018B_CLOSE_WINDOW } ,
{ WWT_CAPTION , 14 , 11 , 279 , 0 , 13 , STR_NEWGRF_SETINGS_CAPTION , STR_018C_WINDOW_TITLE_DRAG_THIS } ,
{ WWT_MATRIX , 14 , 0 , 268 , 14 , 1 93, 0xC01 , STR_NEWGRF_TIP } ,
{ WWT_PANEL , 14 , 0 , 279 , 1 94, 332 , 0x0 , STR_NULL } ,
{ WWT_MATRIX , 14 , 0 , 268 , 14 , 1 82, 0xC01 , /*small rows*/ STR_NEWGRF_TIP } ,
{ WWT_PANEL , 14 , 0 , 279 , 1 83, 321 , 0x0 , STR_NULL } ,
{ WWT_SCROLLBAR , 14 , 269 , 279 , 14 , 1 93 , 0x0 , STR_0190_SCROLL_BAR_SCROLLS_LIST } ,
{ WWT_SCROLLBAR , 14 , 269 , 279 , 14 , 1 82 , 0x0 , STR_0190_SCROLL_BAR_SCROLLS_LIST } ,
{ WWT_CLOSEBOX , 14 , 147 , 158 , 300, 311 , STR_0188 , STR_NULL } ,
{ WWT_CLOSEBOX , 14 , 159 , 170 , 300, 311 , STR_0189 , STR_NULL } ,
{ WWT_CLOSEBOX , 14 , 175 , 274 , 300, 311 , STR_NEWGRF_SET_PARAMETERS , STR_NULL } ,
{ WWT_CLOSEBOX , 14 , 147 , 158 , 289, 300 , STR_0188 , STR_NULL } ,
{ WWT_CLOSEBOX , 14 , 159 , 170 , 289, 300 , STR_0189 , STR_NULL } ,
{ WWT_CLOSEBOX , 14 , 175 , 274 , 289, 300 , STR_NEWGRF_SET_PARAMETERS , STR_NULL } ,
{ WWT_CLOSEBOX , 3 , 5 , 138 , 3 17, 328 , STR_NEWGRF_APPLY_CHANGES , STR_NULL } ,
{ WWT_CLOSEBOX , 3 , 142 , 274 , 3 17, 328 , STR_012E_CANCEL , STR_NULL } ,
{ WWT_CLOSEBOX , 3 , 5 , 138 , 3 06, 317 , STR_NEWGRF_APPLY_CHANGES , STR_NULL } ,
{ WWT_CLOSEBOX , 3 , 142 , 274 , 3 06, 317 , STR_012E_CANCEL , STR_NULL } ,
{ WIDGETS_END } ,
} ;
static const WindowDesc _newgrf_desc = {
WDP_CENTER , WDP_CENTER , 280 , 3 33 ,
WDP_CENTER , WDP_CENTER , 280 , 3 22 ,
WC_GAME_OPTIONS , 0 ,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET ,
_newgrf_widgets ,
@ -1059,11 +1061,11 @@ void ShowNewgrf()
{ // little helper function to calculate _grffile_count
// should be REMOVED once _grffile_count is calculated at loading
_grffile_count = 0 ;
struct GRFFile * c = _first _grffile;
while ( c ! = NULL ) {
struct GRFFile * c = _first_grffile ;
_grffile_count = 0 ;
while ( c ! = NULL ) {
_grffile_count + + ;
c = c - > next ;
c = c - > next ;
}
}