Skip to content

Commit

Permalink
Fixes controls issues with scripted pause
Browse files Browse the repository at this point in the history
Moves the pause/resume code from pollFlightControls and pollDockedControls into a new method of PlayerEntity(Controls) and have the Global pauseGame method use this, so that pause from script is like pause from user button press.
  • Loading branch information
jobi-wan committed Nov 4, 2017
1 parent 8d5277d commit 0c90938
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 75 deletions.
1 change: 1 addition & 0 deletions src/Core/Entities/PlayerEntity.h
Expand Up @@ -747,6 +747,7 @@ typedef enum
- (void) completeSetUp;
- (void) completeSetUpAndSetTarget:(BOOL)setTarget;
- (void) startUpComplete;
- (BOOL) pauseControl;

- (NSString *) commanderName;
- (void) setCommanderName:(NSString *)value;
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Entities/PlayerEntity.m
Expand Up @@ -2200,6 +2200,17 @@ - (void) startUpComplete
}


- (BOOL) pauseControl
{
if ([[UNIVERSE gameController] isGamePaused])
return NO;

[self handleButtonPause];

return YES;
}


- (BOOL) setUpShipFromDictionary:(NSDictionary *)shipDict
{
DESTROY(compassTarget);
Expand Down
1 change: 1 addition & 0 deletions src/Core/Entities/PlayerEntityControls.h
Expand Up @@ -33,6 +33,7 @@ MA 02110-1301, USA.

- (void) pollControls:(double)delta_t;
- (BOOL) handleGUIUpDownArrowKeys;
- (void) handleButtonPause;
- (void) clearPlanetSearchString;
- (void) targetNewSystem:(int) direction;
- (void) switchToMainView;
Expand Down
160 changes: 88 additions & 72 deletions src/Core/Entities/PlayerEntityControls.m
Expand Up @@ -491,6 +491,90 @@ - (BOOL) handleGUIUpDownArrowKeys
}


- (void) handleButtonPause
{
GameController *gameController = [UNIVERSE gameController];
MyOpenGLView *gameView = [UNIVERSE gameView];
BOOL paused = [gameController isGamePaused];

if ([self status] == STATUS_DOCKED)
{
if (paused) // resume
{
script_time = saved_script_time;
[gameView allowStringInput:NO];
if ([UNIVERSE pauseMessageVisible])
{
[UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
}
[[UNIVERSE gui] setForegroundTextureKey:@"docked_overlay"];
[gameController setGamePaused:NO];
}
else // pause
{
saved_script_time = script_time;
[[UNIVERSE messageGUI] clear];
[UNIVERSE pauseGame]; // 'paused' handler
}
}
else // flight
{
if (paused) // resume
{
script_time = saved_script_time;
// Reset to correct GUI screen, if we are unpausing from one.
// Don't set gui_screen here, use setGuis - they also switch backgrounds.
// No gui switching events will be triggered while still paused.
switch (saved_gui_screen)
{
case GUI_SCREEN_STATUS:
[self setGuiToStatusScreen];
break;
case GUI_SCREEN_LONG_RANGE_CHART:
[self setGuiToLongRangeChartScreen];
break;
case GUI_SCREEN_SHORT_RANGE_CHART:
[self setGuiToShortRangeChartScreen];
break;
case GUI_SCREEN_MANIFEST:
[self setGuiToManifestScreen];
break;
case GUI_SCREEN_MARKET:
[self setGuiToMarketScreen];
break;
case GUI_SCREEN_MARKETINFO:
[self setGuiToMarketInfoScreen];
break;
case GUI_SCREEN_SYSTEM_DATA:
// Do not reset planet rotation if we are already in the system info screen!
if (gui_screen != GUI_SCREEN_SYSTEM_DATA)
[self setGuiToSystemDataScreen];
break;
default:
gui_screen = saved_gui_screen; // make sure we're back to the right screen
break;
}
[gameView allowStringInput:NO];
[UNIVERSE clearPreviousMessage];
[UNIVERSE setViewDirection:saved_view_direction];
currentWeaponFacing = saved_weapon_facing;
// make sure the light comes from the right direction after resuming from pause!
if (saved_gui_screen == GUI_SCREEN_SYSTEM_DATA) [UNIVERSE setMainLightPosition:_sysInfoLight];
[[UNIVERSE gui] setForegroundTextureKey:@"overlay"];
[gameController setGamePaused:NO];
}
else // pause
{
saved_view_direction = [UNIVERSE viewDirection];
saved_script_time = script_time;
saved_gui_screen = gui_screen;
saved_weapon_facing = currentWeaponFacing;
[UNIVERSE pauseGame]; // pause handler
}
}
}


- (void) targetNewSystem:(int) direction whileTyping:(BOOL) whileTyping
{
target_system_id = [[UNIVERSE gui] targetNextFoundSystem:direction];
Expand Down Expand Up @@ -1592,60 +1676,9 @@ - (void) pollFlightControls:(double)delta_t
{
if (!pause_pressed)
{
if (paused)
{
script_time = saved_script_time;
// Reset to correct GUI screen, if we are unpausing from one.
// Don't set gui_screen here, use setGuis - they also switch backgrounds.
// No gui switching events will be triggered while still paused.
switch (saved_gui_screen)
{
case GUI_SCREEN_STATUS:
[self setGuiToStatusScreen];
break;
case GUI_SCREEN_LONG_RANGE_CHART:
[self setGuiToLongRangeChartScreen];
break;
case GUI_SCREEN_SHORT_RANGE_CHART:
[self setGuiToShortRangeChartScreen];
break;
case GUI_SCREEN_MANIFEST:
[self setGuiToManifestScreen];
break;
case GUI_SCREEN_MARKET:
[self setGuiToMarketScreen];
break;
case GUI_SCREEN_MARKETINFO:
[self setGuiToMarketInfoScreen];
break;
case GUI_SCREEN_SYSTEM_DATA:
// Do not reset planet rotation if we are already in the system info screen!
if (gui_screen != GUI_SCREEN_SYSTEM_DATA)
[self setGuiToSystemDataScreen];
break;
default:
gui_screen = saved_gui_screen; // make sure we're back to the right screen
break;
}
[gameView allowStringInput:NO];
[UNIVERSE clearPreviousMessage];
[UNIVERSE setViewDirection:saved_view_direction];
currentWeaponFacing = saved_weapon_facing;
// make sure the light comes from the right direction after resuming from pause!
if (saved_gui_screen == GUI_SCREEN_SYSTEM_DATA) [UNIVERSE setMainLightPosition:_sysInfoLight];
[[UNIVERSE gui] setForegroundTextureKey:@"overlay"];
[[UNIVERSE gameController] setGamePaused:NO];
}
else
{
saved_view_direction = [UNIVERSE viewDirection];
saved_script_time = script_time;
saved_gui_screen = gui_screen;
saved_weapon_facing = currentWeaponFacing;
[UNIVERSE pauseGame]; // pause handler
}
[self handleButtonPause];
pause_pressed = YES;
}
pause_pressed = YES;
}
else
{
Expand Down Expand Up @@ -4225,26 +4258,9 @@ - (void) pollDockedControls:(double)delta_t
{
if (!pause_pressed)
{
if ([gameController isGamePaused])
{
script_time = saved_script_time;
[gameView allowStringInput:NO];
if ([UNIVERSE pauseMessageVisible])
{
[UNIVERSE clearPreviousMessage]; // remove the 'paused' message.
}
[[UNIVERSE gui] setForegroundTextureKey:@"docked_overlay"];
[gameController setGamePaused:NO];
}
else
{
saved_script_time = script_time;
[[UNIVERSE messageGUI] clear];

[UNIVERSE pauseGame]; // 'paused' handler
}
[self handleButtonPause];
pause_pressed = YES;
}
pause_pressed = YES;
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Scripting/OOJSGlobal.m
Expand Up @@ -597,13 +597,12 @@ static JSBool GlobalPauseGame(JSContext *context, uintN argc, jsval *vp)
{
OOGUIScreenID guiScreen = [player guiScreen];

if (guiScreen != GUI_SCREEN_LONG_RANGE_CHART &&
if (guiScreen != GUI_SCREEN_LONG_RANGE_CHART &&
guiScreen != GUI_SCREEN_MISSION &&
guiScreen != GUI_SCREEN_REPORT &&
guiScreen != GUI_SCREEN_SAVE)
{
[UNIVERSE pauseGame];
result = YES;
result = [player pauseControl];
}
}

Expand Down

0 comments on commit 0c90938

Please sign in to comment.