Skip to content

Commit

Permalink
Save window mode and background to configuration too
Browse files Browse the repository at this point in the history
  • Loading branch information
kazzmir committed Aug 22, 2006
1 parent 207cb3f commit f36b737
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
40 changes: 40 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Configuration::Configuration(){
internalSetLeftKey( Keyboard::LEFT );
internalSetRightKey( Keyboard::RIGHT );
internalSetShootKey( Keyboard::SPACE );
internalSetWindowMode( false );
internalSetBackground( true );

loadConfiguration();
}
Expand Down Expand Up @@ -63,6 +65,10 @@ void Configuration::loadConfiguration(){
internalSetRightKey( key );
} else if ( name == "shoot" ){
internalSetShootKey( key );
} else if ( name == "window" ){
internalSetWindowMode( key );
} else if ( name == "background" ){
internalSetBackground( key );
} else {
cout << "Ignoring line " << buf << endl;
}
Expand Down Expand Up @@ -91,6 +97,14 @@ std::string Configuration::getShootKeyName(){
return Keyboard::keyToString( getShootKey() );
}

bool Configuration::getWindowMode(){
return getInstance()->internalGetWindowMode();
}

bool Configuration::getBackground(){
return getInstance()->internalGetBackground();
}

int Configuration::getForwardKey(){
return getInstance()->internalGetForwardKey();
}
Expand Down Expand Up @@ -131,6 +145,14 @@ int Configuration::internalGetShootKey() const {
return keyShoot;
}

bool Configuration::internalGetWindowMode() const {
return windowMode;
}

bool Configuration::internalGetBackground() const {
return background;
}

void Configuration::setForwardKey( int k ){
getInstance()->internalSetForwardKey( k );
}
Expand All @@ -151,6 +173,14 @@ void Configuration::setShootKey( int k ){
getInstance()->internalSetShootKey( k );
}

void Configuration::setWindowMode( bool b ){
getInstance()->internalSetWindowMode( b );
}

void Configuration::setBackground( bool b ){
getInstance()->internalSetBackground( b );
}

void Configuration::internalSetForwardKey( const int k ){
keyForward = k;
}
Expand All @@ -171,6 +201,14 @@ void Configuration::internalSetShootKey( const int k ){
keyShoot = k;
}

void Configuration::internalSetWindowMode( const bool b ){
windowMode = b;
}

void Configuration::internalSetBackground( const bool b ){
background = b;
}

void Configuration::saveConfiguration(){

ofstream config( getConfigFile().c_str() );
Expand All @@ -183,6 +221,8 @@ void Configuration::saveConfiguration(){
config << "left = " << getLeftKey() << endl;
config << "right = " << getRightKey() << endl;
config << "shoot = " << getShootKey() << endl;
config << "window = " << getWindowMode() << endl;
config << "background = " << getBackground() << endl;
config.close();

delete instance;
Expand Down
10 changes: 10 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ class Configuration{
static int getLeftKey();
static int getRightKey();
static int getShootKey();
static bool getWindowMode();
static bool getBackground();

static void setForwardKey( int k );
static void setBackwardKey( int k );
static void setLeftKey( int k );
static void setRightKey( int k );
static void setShootKey( int k );
static void setWindowMode( bool b );
static void setBackground( bool b );

static void saveConfiguration();

Expand All @@ -38,18 +42,24 @@ class Configuration{
int internalGetLeftKey() const;
int internalGetRightKey() const;
int internalGetShootKey() const;
bool internalGetWindowMode() const;
bool internalGetBackground() const;

void internalSetForwardKey( const int k );
void internalSetBackwardKey( const int k );
void internalSetLeftKey( const int k );
void internalSetRightKey( const int k );
void internalSetShootKey( const int k );
void internalSetWindowMode( const bool k );
void internalSetBackground( const bool k );

int keyForward;
int keyBackward;
int keyLeft;
int keyRight;
int keyShoot;
bool windowMode;
bool background;
};

#endif
33 changes: 15 additions & 18 deletions src/raptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ static const int CHANGE_KEY_RIGHT = 23;
static const int CHANGE_KEY_SHOOT = 24;

static Font * normalFont = NULL;
static int windowMode = 0;
static bool background = true;

extern void init( int GFX, int GAME_SPEED );


void credits() {
cout << "Exiting normally.. " << endl;
cout << "-------" << endl;
Expand Down Expand Up @@ -346,17 +343,17 @@ int intro_screen( int & frames, SpaceObject ** player, DATAFILE * sound ){
option_menu.addMenu( "Change Keys", normalFont, true, INIT_CHANGE_KEYS, &changeKeyMenu, select_smp );

RField * fullscreenField;
if ( windowMode ){
if ( Configuration::getWindowMode() ){
fullscreenField = option_menu.addMenu( "Fullscreen on", normalFont, true,INIT_SCREEN,&option_menu,select_smp);
} else {
fullscreenField = option_menu.addMenu( "Fullscreen off", normalFont, true,INIT_SCREEN,&option_menu,select_smp);
}

RField * backgroundField;
if ( background ){
backgroundField = option_menu.addMenu( "Background on", normalFont, true, INIT_BACK, &option_menu, select_smp );
if ( Configuration::getBackground() ){
backgroundField = option_menu.addMenu( "Background off", normalFont, true, INIT_BACK, &option_menu, select_smp );
} else {
backgroundField = option_menu.addMenu( "Background off", normalFont, true, INIT_BACK, &option_menu, select_smp);
backgroundField = option_menu.addMenu( "Background on", normalFont, true, INIT_BACK, &option_menu, select_smp);
}
option_menu.addMenu( "Sound", normalFont, true, 800, &sound_menu, select_smp );
option_menu.addMenu( "Return to Menu", normalFont, true,800,NULL,select_smp);
Expand Down Expand Up @@ -527,8 +524,8 @@ int intro_screen( int & frames, SpaceObject ** player, DATAFILE * sound ){
break;
}
case INIT_SCREEN : {
windowMode = !windowMode;
if ( windowMode ) {
Configuration::setWindowMode( ! Configuration::getWindowMode() );
if ( Configuration::getWindowMode() ) {
Bitmap::setGfxModeWindowed( GRAPHICS_X, GRAPHICS_Y );
string str( "Fullscreen off" );
fullscreenField->set( &str );
Expand All @@ -540,14 +537,14 @@ int intro_screen( int & frames, SpaceObject ** player, DATAFILE * sound ){
break;
}
case INIT_BACK : {
background = ! background;
if ( background ){
Configuration::setBackground( ! Configuration::getBackground() );
if ( Configuration::getBackground() ){
// option_menu.replace( 5, "Background ON", &menuFont, true, INIT_BACK, &option_menu, select_smp );
string str( "Background On" );
string str( "Background Off" );
backgroundField->set( &str );
} else {
// option_menu.replace( 5, "Background off", &menuFont, true, INIT_BACK, &option_menu, select_smp );
string str( "Background Off" );
string str( "Background On" );
backgroundField->set( &str );
}
break;
Expand Down Expand Up @@ -788,7 +785,7 @@ void playLevel( PlayerObject * const player ){
Drawer draw;
Logic logic;
LevelCreator level( file_level, player );
draw.setDrawLand(background);
draw.setDrawLand( Configuration::getBackground() );

/* stop loading screen */
endLoadingScreen();
Expand Down Expand Up @@ -920,9 +917,9 @@ int rafkill( int argc, char ** argv ) {
return 0;
}
if ( strcmp( argv[q], "-w" ) == 0 ){
windowMode = 1;
Configuration::setWindowMode( true );
} else if ( strcmp( argv[q], "-l" ) == 0 ){
background = false;
Configuration::setBackground( false );
} else if ( strlen( argv[q] ) > 2 ){
if ( argv[q][1] == 'g' ){
gameSpeed = atoi( &argv[q][2] );
Expand All @@ -935,8 +932,8 @@ int rafkill( int argc, char ** argv ) {
}

cout << "Running game at " << gameSpeed << endl;
cout << "Using mode " << windowMode << endl;
init( windowMode, gameSpeed );
cout << "Using window mode " << Configuration::getWindowMode() << endl;
init( Configuration::getWindowMode(), gameSpeed );
cout << "OS " << Util::getOS() << endl;

Util::loadGlobals();
Expand Down

0 comments on commit f36b737

Please sign in to comment.