2015-10-20 13:51:49 +02:00
/*
2016-02-21 16:50:27 +01:00
Copyright ( C ) 2015 - 2016 Parallel Realities
2015-10-20 13:51:49 +02:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
# include "options.h"
static void changeWindowSize ( char * value ) ;
static void changeSoundVolume ( char * value ) ;
static void changeMusicVolume ( char * value ) ;
static void changeFullscreen ( char * value ) ;
static void ok ( void ) ;
2016-03-04 23:11:13 +01:00
static void controlsOK ( void ) ;
static void drawMain ( void ) ;
static void controls ( void ) ;
2015-10-20 13:51:49 +02:00
static void ( * returnFromOptions ) ( void ) ;
2016-03-04 23:11:13 +01:00
static int show ;
2015-10-20 13:51:49 +02:00
void initOptions ( void ( * rtn ) ( void ) )
{
char optionStr [ MAX_NAME_LENGTH ] ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
selectWidget ( " windowSize " , " options " ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
getWidget ( " windowSize " , " options " ) - > onChange = changeWindowSize ;
getWidget ( " soundVolume " , " options " ) - > onChange = changeSoundVolume ;
getWidget ( " musicVolume " , " options " ) - > onChange = changeMusicVolume ;
getWidget ( " fullscreen " , " options " ) - > onChange = changeFullscreen ;
2016-03-04 23:11:13 +01:00
getWidget ( " controls " , " options " ) - > action = controls ;
2015-10-20 13:51:49 +02:00
getWidget ( " ok " , " options " ) - > action = ok ;
2016-03-04 23:11:13 +01:00
getWidget ( " ok " , " controls " ) - > action = controlsOK ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
sprintf ( optionStr , " %d x %d " , app . winWidth , app . winHeight ) ;
setWidgetOption ( " windowSize " , " options " , optionStr ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
sprintf ( optionStr , " %d " , app . soundVolume ) ;
setWidgetOption ( " soundVolume " , " options " , optionStr ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
sprintf ( optionStr , " %d " , app . musicVolume ) ;
setWidgetOption ( " musicVolume " , " options " , optionStr ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
setWidgetOption ( " fullscreen " , " options " , app . fullscreen ? " On " : " Off " ) ;
2016-03-03 19:03:07 +01:00
# if FIXED_RESOLUTION
getWidget ( " windowSize " , " options " ) - > enabled = 0 ;
getWidget ( " fullscreen " , " options " ) - > enabled = 0 ;
# endif
2015-10-20 13:51:49 +02:00
returnFromOptions = rtn ;
2016-03-04 23:11:13 +01:00
show = SHOW_MAIN ;
2015-10-20 13:51:49 +02:00
}
void drawOptions ( void )
2016-03-04 23:11:13 +01:00
{
switch ( show )
{
case SHOW_MAIN :
drawMain ( ) ;
break ;
case SHOW_CONTROLS :
drawControls ( ) ;
break ;
}
}
static void drawMain ( void )
2015-10-20 13:51:49 +02:00
{
SDL_Rect r ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
SDL_SetRenderDrawBlendMode ( app . renderer , SDL_BLENDMODE_BLEND ) ;
SDL_SetRenderDrawColor ( app . renderer , 0 , 0 , 0 , 128 ) ;
SDL_RenderFillRect ( app . renderer , NULL ) ;
SDL_SetRenderDrawBlendMode ( app . renderer , SDL_BLENDMODE_NONE ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
r . w = 500 ;
r . h = 600 ;
r . x = ( SCREEN_WIDTH / 2 ) - r . w / 2 ;
r . y = ( SCREEN_HEIGHT / 2 ) - r . h / 2 ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
SDL_SetRenderDrawColor ( app . renderer , 0 , 0 , 0 , 0 ) ;
SDL_RenderFillRect ( app . renderer , & r ) ;
SDL_SetRenderDrawColor ( app . renderer , 200 , 200 , 200 , 255 ) ;
SDL_RenderDrawRect ( app . renderer , & r ) ;
2016-03-03 19:03:07 +01:00
2016-02-27 20:16:17 +01:00
drawText ( SCREEN_WIDTH / 2 , 70 , 28 , TA_CENTER , colors . white , _ ( " Options " ) ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
SDL_SetRenderDrawColor ( app . renderer , 128 , 128 , 128 , 255 ) ;
SDL_RenderDrawLine ( app . renderer , r . x , 120 , r . x + r . w , 120 ) ;
2016-03-03 19:03:07 +01:00
drawWidgets ( " options " ) ;
2015-10-20 13:51:49 +02:00
limitTextWidth ( r . w - 100 ) ;
2016-03-03 19:03:07 +01:00
# if !FIXED_RESOLUTION
2016-02-27 20:16:17 +01:00
drawText ( SCREEN_WIDTH / 2 , r . y + r . h - 135 , 16 , TA_CENTER , colors . yellow , _ ( " Note: you must restart the game for window size and fullscreen options to take effect. " ) ) ;
2016-03-03 19:03:07 +01:00
# else
drawText ( SCREEN_WIDTH / 2 , r . y + r . h - 135 , 16 , TA_CENTER , colors . yellow , _ ( " Note: this device does not support changing the screen resolution. " ) ) ;
# endif
2015-10-20 13:51:49 +02:00
limitTextWidth ( 0 ) ;
}
2016-03-04 23:11:13 +01:00
static void controls ( void )
{
initControlsDisplay ( ) ;
show = SHOW_CONTROLS ;
}
2015-10-20 13:51:49 +02:00
static void changeWindowSize ( char * value )
{
sscanf ( value , " %d x %d " , & app . winWidth , & app . winHeight ) ;
}
static void changeSoundVolume ( char * value )
{
app . soundVolume = atoi ( value ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
Mix_Volume ( - 1 , app . soundVolume * MIX_MAX_VOLUME / 10 ) ;
}
static void changeMusicVolume ( char * value )
{
app . musicVolume = atoi ( value ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
Mix_VolumeMusic ( app . musicVolume * MIX_MAX_VOLUME / 10 ) ;
}
static void changeFullscreen ( char * value )
{
app . fullscreen = strcmp ( value , " On " ) = = 0 ;
}
static void ok ( void )
{
saveConfig ( ) ;
2016-03-03 19:03:07 +01:00
2015-10-20 13:51:49 +02:00
returnFromOptions ( ) ;
}
2016-03-04 23:11:13 +01:00
static void controlsOK ( void )
{
show = SHOW_MAIN ;
}