Oolite
Loading...
Searching...
No Matches
PlayerEntity(LoadSave) Category Reference

#include <PlayerEntityLoadSave.h>

Instance Methods

(BOOL) - loadPlayer
(void) - savePlayer
(void) - quicksavePlayer
(void) - autosavePlayer
(void) - setGuiToScenarioScreen:
(void) - addScenarioModel:
(void) - showScenarioDetails
(BOOL) - startScenario
(NSString *) - commanderSelector
(void) - saveCommanderInputHandler
(void) - overwriteCommanderInputHandler
(BOOL) - loadPlayerFromFile:asNew:

Detailed Description

Definition at line 50 of file PlayerEntityLoadSave.h.

Method Documentation

◆ addScenarioModel:

- (void) addScenarioModel: (NSString*) shipKey

Extends class PlayerEntity.

Definition at line 215 of file PlayerEntityLoadSave.m.

215 :(NSString*)shipKey
216{
217 [self showShipModelWithKey:shipKey shipData:nil personality:0 factorX:1.2 factorY:0.8 factorZ:6.4 inContext:@"scenario"];
218}

References PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:.

Here is the call graph for this function:

◆ autosavePlayer

- (void) autosavePlayer

Extends class PlayerEntity.

Definition at line 93 of file PlayerEntityLoadSave.m.

94{
95 NSString* tmp_path = nil;
96 NSString* tmp_name = nil;
97 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
98
99 tmp_name = [self lastsaveName];
100 tmp_path = save_path;
101
102 [self doScriptEvent:OOJSID("playerWillSaveGame") withArgument:@"AUTO_SAVE"];
103
104 NSString* saveName = [self lastsaveName];
105 NSString* autosaveSuffix = DESC(@"autosave-commander-suffix");
106
107 if (![saveName hasSuffix:autosaveSuffix]) {
108 saveName = [saveName stringByAppendingString:autosaveSuffix];
109 }
110 NSString* savePath = [dir stringByAppendingPathComponent:[saveName stringByAppendingString:@".oolite-save"]];
111
112 [self setLastsaveName:saveName];
113
114 @try {
115 [self writePlayerToPath:savePath];
116 }
117 @catch (id exception) {
118 // Suppress exceptions silently. Warning the user about failed autosaves would be pretty unhelpful.
119 }
120
121 if (tmp_path != nil) {
122 [save_path autorelease];
123 save_path = [tmp_path copy];
124 }
125 [self setLastsaveName:tmp_name];
126}
return nil
#define DESC(key)
Definition Universe.h:832

References autosavePlayer, DESC, ShipEntity::doScriptEvent:withArgument:, PlayerEntity::lastsaveName, nil, PlayerEntity::setLastsaveName:, and PlayerEntity::writePlayerToPath:.

Referenced by autosavePlayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commanderSelector

- (NSString *) commanderSelector

Extends class PlayerEntity.

Definition at line 282 of file PlayerEntityLoadSave.m.

283{
284 MyOpenGLView* gameView = [UNIVERSE gameView];
285 GuiDisplayGen* gui = [UNIVERSE gui];
286 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
287 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
288
289 int idx;
290 if ([self handleGUIUpDownArrowKeys]) {
291 int guiSelectedRow = [gui selectedRow];
292 idx = (guiSelectedRow - STARTROW) + (currentPage * NUMROWS);
293 if (guiSelectedRow != MOREROW && guiSelectedRow != BACKROW && guiSelectedRow != EXITROW) {
294 [self showCommanderShip:idx];
295 } else {
296 [UNIVERSE removeDemoShips];
297 [gui setText:@"" forRow:CDRDESCROW align:GUI_ALIGN_LEFT];
298 [gui setText:@"" forRow:CDRDESCROW + 1 align:GUI_ALIGN_LEFT];
299 [gui setText:@"" forRow:CDRDESCROW + 2 align:GUI_ALIGN_LEFT];
300 }
301
302 } else {
303 idx = ([gui selectedRow] - STARTROW) + (currentPage * NUMROWS);
304 }
305
306 // handle page <-- and page --> keys
307 if (([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up] || joyButtonState[BUTTON_GUILEFT] || joyButtonState[BUTTON_GUIPAGEUP]) && [[gui keyForRow:BACKROW] isEqual:GUI_KEY_OK]) {
308 currentPage--;
309 [self playMenuPagePrevious];
310 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
311 [gameView suppressKeysUntilKeyUp];
312 }
313 if (([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down] || joyButtonState[BUTTON_GUIRIGHT] || joyButtonState[BUTTON_GUIPAGEDOWN]) && [[gui keyForRow:MOREROW] isEqual:GUI_KEY_OK]) {
314 currentPage++;
315 [self playMenuPageNext];
316 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
317 [gameView suppressKeysUntilKeyUp];
318 }
319
320 // Enter pressed - find the commander name underneath.
321 // ignore Ctrl for the moment - we check for it explicitly later
322 if ([self checkKeyPress:n_key_gui_select ignore_ctrl:YES] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) {
323 NSDictionary* cdr;
324 switch ([gui selectedRow]) {
325 case EXITROW:
326 if ([self status] == STATUS_START_GAME) {
327 [self setGuiToIntroFirstGo:YES];
328 return nil;
329 }
330 break;
331 case BACKROW:
332 currentPage--;
333 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
334 [gameView suppressKeysUntilKeyUp];
335 break;
336 case MOREROW:
337 currentPage++;
338 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
339 [gameView suppressKeysUntilKeyUp];
340 break;
341 default:
342 cdr = [cdrDetailArray objectAtIndex:idx];
343 if ([cdr oo_boolForKey:@"isSavedGame"])
344 return [cdr oo_stringForKey:@"saved_game_path"];
345 else {
346 if ([gameView isCommandModifierKeyDown] || [gameView isDown:gvMouseDoubleClick]) {
347 // change directory to the selected path
348 NSString* newDir = [cdr oo_stringForKey:@"saved_game_path"];
349 [[UNIVERSE gameController] setPlayerFileDirectory:newDir];
350 dir = newDir;
351 currentPage = 0;
352 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
353 [gameView suppressKeysUntilKeyUp];
354 }
355 }
356 }
357 }
358
359 if ([gameView isDown:27]) // escape key
360 {
361 [self setGuiToStatusScreen];
362 }
363 return nil;
364}
#define GUI_KEY_OK
@ gvMouseDoubleClick
@ BUTTON_GUILEFT
@ BUTTON_GUISELECT
@ BUTTON_GUIRIGHT
@ BUTTON_GUIPAGEDOWN
@ BUTTON_GUIPAGEUP
#define EXITROW
#define MOREROW
#define NUMROWS
#define STARTROW
#define BACKROW
void setText:forRow:align:(NSString *str,[forRow] OOGUIRow row,[align] OOGUIAlignment alignment)
OOGUIRow selectedRow
const BOOL * getAllButtonStates()

References BACKROW, BUTTON_GUILEFT, BUTTON_GUIPAGEDOWN, BUTTON_GUIPAGEUP, BUTTON_GUIRIGHT, BUTTON_GUISELECT, commanderSelector, EXITROW, OOJoystickManager::getAllButtonStates, GUI_KEY_OK, gvMouseDoubleClick, PlayerEntity::lsCommanders:directory:pageNumber:highlightName:, MOREROW, nil, NUMROWS, PlayerEntity::playMenuPageNext, PlayerEntity::playMenuPagePrevious, GuiDisplayGen::selectedRow, PlayerEntity::setGuiToIntroFirstGo:, PlayerEntity::setGuiToStatusScreen, GuiDisplayGen::setText:forRow:align:, OOJoystickManager::sharedStickHandler, PlayerEntity::showCommanderShip:, STARTROW, and MyOpenGLView::suppressKeysUntilKeyUp.

Referenced by commanderSelector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPlayer

- (BOOL) loadPlayer

Extends class PlayerEntity.

Definition at line 80 of file PlayerEntityLoadSave.m.

81{
82 BOOL OK = YES;
83
84 [self setGuiToLoadCommanderScreen];
85 return OK;
86}

References loadPlayer, and PlayerEntity::setGuiToLoadCommanderScreen.

Referenced by loadPlayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPlayerFromFile:asNew:

- (BOOL) loadPlayerFromFile: (NSString*) fileToOpen
asNew: (BOOL) asNew 

Extends class PlayerEntity.

Definition at line 485 of file PlayerEntityLoadSave.m.

485 :(NSString*)fileToOpen asNew:(BOOL)asNew
486{
487 /* TODO: it would probably be better to load by creating a new
488 PlayerEntity, verifying that's OK, then replacing the global player.
489
490 Actually, it'd be better to separate PlayerEntity into OOPlayer and
491 OOPlayerShipEntity. And then move most of OOPlayerShipEntity into
492 ShipEntity, and make NPC ships behave more like player ships.
493 -- Ahruman
494 */
495
496 BOOL loadedOK = YES;
497 NSDictionary* fileDic = nil;
498 NSString* fail_reason = nil;
499
500 if (fileToOpen == nil) {
501 fail_reason = DESC(@"loadfailed-no-file-specified");
502 loadedOK = NO;
503 }
504
505 if (loadedOK) {
506 OOLog(@"load.progress", @"%@", @"Reading file");
507 fileDic = OODictionaryFromFile(fileToOpen);
508 if (fileDic == nil) {
509 fail_reason = DESC(@"loadfailed-could-not-load-file");
510 loadedOK = NO;
511 }
512 }
513
514 if (loadedOK) {
515 OOLog(@"load.progress", @"%@", @"Restricting scenario");
516 NSString* scenarioRestrict = [fileDic oo_stringForKey:@"scenario_restriction" defaultValue:nil];
517 if (scenarioRestrict == nil) {
518 // older save game - use the 'strict' key instead
519 BOOL strict = [fileDic oo_boolForKey:@"strict" defaultValue:NO];
520 if (strict) {
521 scenarioRestrict = SCENARIO_OXP_DEFINITION_NONE;
522 } else {
523 scenarioRestrict = SCENARIO_OXP_DEFINITION_ALL;
524 }
525 }
526
527 if (![UNIVERSE setUseAddOns:scenarioRestrict fromSaveGame:YES forceReinit:YES]) {
528 fail_reason = DESC(@"loadfailed-saved-game-failed-to-load");
529 loadedOK = NO;
530 }
531 }
532
533 if (loadedOK) {
534 OOLog(@"load.progress", @"%@", @"Creating player ship");
535 // Check that player ship exists
536 NSString* shipKey = nil;
537 NSDictionary* shipDict = nil;
538
539 shipKey = [fileDic oo_stringForKey:@"ship_desc"];
540 shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
541
542 if (shipDict == nil) {
543 loadedOK = NO;
544 if (shipKey != nil)
545 fail_reason = [NSString stringWithFormat:DESC(@"loadfailed-could-not-find-ship-type-@-please-reinstall-the-appropriate-OXP"), shipKey];
546 else
547 fail_reason = DESC(@"loadfailed-invalid-saved-game-no-ship-specified");
548 }
549 }
550
551 if (loadedOK) {
552 OOLog(@"load.progress", @"%@", @"Initialising player entity");
553 if (![self setUpAndConfirmOK:YES saveGame:YES]) {
554 fail_reason = DESC(@"loadfailed-could-not-reset-javascript");
555 loadedOK = NO;
556 }
557 }
558
559 if (loadedOK) {
560 OOLog(@"load.progress", @"%@", @"Loading commander data");
561 if (![self setCommanderDataFromDictionary:fileDic]) {
562 // this could still be a reset js issue, if switching from strict / unrestricted
563 // TODO: use "could not reset js message" if that's the case.
564 fail_reason = DESC(@"loadfailed-could-not-set-up-player-ship");
565 loadedOK = NO;
566 }
567 }
568
569 if (loadedOK) {
570 OOLog(@"load.progress", @"%@", @"Recording save path");
571 if (!asNew) {
572 [save_path autorelease];
573 save_path = [fileToOpen retain];
574
575 [[[UNIVERSE gameView] gameController] setPlayerFileToLoad:fileToOpen];
576 [[[UNIVERSE gameView] gameController] setPlayerFileDirectory:fileToOpen];
577 }
578 } else {
579 OOLog(@"load.failed", @"***** Failed to load saved game \"%@\": %@", [fileToOpen lastPathComponent], fail_reason ? fail_reason : (NSString*)@"unknown error");
580 [[UNIVERSE gameController] setPlayerFileToLoad:nil];
581 [UNIVERSE handleGameOver];
582 [UNIVERSE clearPreviousMessage];
583 [UNIVERSE addMessage:DESC(@"loadfailed-saved-game-failed-to-load") forCount:9.0];
584 if (fail_reason != nil)
585 [UNIVERSE addMessage:fail_reason forCount:9.0];
586 return NO;
587 }
588
589 OOLog(@"load.progress", @"%@", @"Creating system");
590 [UNIVERSE setTimeAccelerationFactor:TIME_ACCELERATION_FACTOR_DEFAULT];
591 [UNIVERSE setSystemTo:system_id];
592 [UNIVERSE removeAllEntitiesExceptPlayer];
593 [UNIVERSE setGalaxyTo:galaxy_number andReinit:YES]; // set overridden planet names on long range map
594 [UNIVERSE setUpSpace];
595 [UNIVERSE setAutoSaveNow:NO];
596
597 OOLog(@"load.progress", @"%@", @"Resetting player flight variables");
598 [self setDockedAtMainStation];
599 StationEntity* dockedStation = [self dockedStation];
600
601 [UNIVERSE enterGUIViewModeWithMouseInteraction:NO];
602
603 if (dockedStation) {
604 position = [dockedStation position];
605 [self setOrientation:kIdentityQuaternion];
606 v_forward = vector_forward_from_quaternion(orientation);
607 v_right = vector_right_from_quaternion(orientation);
608 v_up = vector_up_from_quaternion(orientation);
609 }
610
611 flightRoll = 0.0;
612 flightPitch = 0.0;
613 flightYaw = 0.0;
614 flightSpeed = 0.0;
615
616 [self setEntityPersonalityInt:PersonalityForCommanderDict(fileDic)];
617
618 OOLog(@"load.progress", @"%@", @"Loading system market");
619 // dockedStation is always the main station at this point;
620 // "localMarket" save key always refers to the main station (system) market
621 NSArray* market = [fileDic oo_arrayForKey:@"localMarket"];
622 if (market != nil) {
623 [dockedStation setLocalMarket:market];
624 } else {
625 [dockedStation initialiseLocalMarket];
626 }
627
628 [self calculateCurrentCargo];
629
630 OOLog(@"load.progress", @"%@", @"Setting scenario key");
631 // set scenario key if the scenario allows saving and has one
632 NSString* scenario = [fileDic oo_stringForKey:@"scenario_key" defaultValue:nil];
633 DESTROY(scenarioKey);
634 if (scenario != nil) {
635 scenarioKey = [scenario retain];
636 }
637
638 OOLog(@"load.progress", @"%@", @"Starting JS engine");
639 // Remember the savegame target, run js startUp.
640 [self completeSetUpAndSetTarget:NO];
641 // run initial system population
642 OOLog(@"load.progress", @"%@", @"Populating initial system");
643 [UNIVERSE populateNormalSpace];
644
645 // might as well start off with a collected JS environment
647
648 // read saved position vector and primary role, check for an
649 // appropriate station at those coordinates, if found, switch
650 // docked station to that one.
651 HPVector dockedPos = [fileDic oo_hpvectorForKey:@"docked_station_position"];
652 NSString* dockedRole = [fileDic oo_stringForKey:@"docked_station_role" defaultValue:@""];
653 StationEntity* saveStation = [UNIVERSE stationWithRole:dockedRole andPosition:dockedPos];
654 if (saveStation != nil && [saveStation allowsSaving]) {
655 [self setDockedStation:saveStation];
656 position = [saveStation position];
657 }
658 // and initialise markets for the secondary stations
659 [UNIVERSE loadStationMarkets:[fileDic oo_arrayForKey:@"station_markets"]];
660
661 OOLog(@"load.progress", @"%@", @"Completing JS startup");
662 [self startUpComplete];
663
664 // if the file was specified in the command line at startup, DO NOT suppress the keys!
665 if ([[UNIVERSE gameController] finishedLaunching])
666 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
667 if (asNew) {
668 gui_screen = GUI_SCREEN_NEWGAME;
669 } else {
670 gui_screen = GUI_SCREEN_LOAD; // force evaluation of new gui screen on startup
671 }
672 [self setGuiToStatusScreen];
673 if (loadedOK)
674 [self doWorldEventUntilMissionScreen:OOJSID("missionScreenOpportunity")]; // trigger missionScreenOpportunity immediately after loading
675 OOLog(@"load.progress", @"%@", @"Loading complete");
676 return loadedOK;
677}
#define DESTROY(x)
struct HPVector HPVector
#define OOLog(class, format,...)
Definition OOLogging.h:84
NSDictionary * OODictionaryFromFile(NSString *path)
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
#define SCENARIO_OXP_DEFINITION_NONE
#define SCENARIO_OXP_DEFINITION_ALL
#define UNIVERSE
Definition Universe.h:827
HPVector position
Definition Entity.m:576
OOJavaScriptEngine * sharedEngine()
void garbageCollectionOpportunity:(BOOL force)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)

References PlayerEntity::calculateCurrentCargo, PlayerEntity::completeSetUpAndSetTarget:, DESC, DESTROY, PlayerEntity::dockedStation, PlayerEntity::doWorldEventUntilMissionScreen:, OOJavaScriptEngine::garbageCollectionOpportunity:, StationEntity::initialiseLocalMarket, nil, OODictionaryFromFile(), OOLog, Entity::position, SCENARIO_OXP_DEFINITION_ALL, SCENARIO_OXP_DEFINITION_NONE, PlayerEntity::setDockedAtMainStation, PlayerEntity::setDockedStation:, ShipEntity::setEntityPersonalityInt:, PlayerEntity::setGuiToStatusScreen, StationEntity::setLocalMarket:, Entity::setOrientation:, OOJavaScriptEngine::sharedEngine, OOShipRegistry::sharedRegistry, OOShipRegistry::shipInfoForKey:, PlayerEntity::startUpComplete, UNIVERSE, vector_forward_from_quaternion(), vector_right_from_quaternion(), and vector_up_from_quaternion().

Here is the call graph for this function:

◆ overwriteCommanderInputHandler

- (void) overwriteCommanderInputHandler

Extends class PlayerEntity.

Definition at line 453 of file PlayerEntityLoadSave.m.

454{
455 MyOpenGLView* gameView = [UNIVERSE gameView];
456 GuiDisplayGen* gui = [UNIVERSE gui];
457 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
458
459 [self handleGUIUpDownArrowKeys];
460
461 // Translation issue: we can't confidently use raw Y and N ascii as shortcuts. It's better to use the load-previous-commander keys.
462 id valueYes = [[[UNIVERSE descriptions] oo_stringForKey:@"load-previous-commander-yes" defaultValue:@"y"] lowercaseString];
463 id valueNo = [[[UNIVERSE descriptions] oo_stringForKey:@"load-previous-commander-no" defaultValue:@"n"] lowercaseString];
464 unsigned char cYes, cNo;
465
466 cYes = [valueYes characterAtIndex:0] & 0x00ff; // Use lower byte of unichar.
467 cNo = [valueNo characterAtIndex:0] & 0x00ff; // Use lower byte of unichar.
468
469 if ((([self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && ([gui selectedRow] == SAVE_OVERWRITE_YES_ROW)) || [gameView isDown:cYes] || [gameView isDown:cYes - 32]) {
470 pollControls = YES;
471 [self nativeSavePlayer:commanderNameString];
472 [self playSaveOverwriteYes];
473 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
474 [self setGuiToStatusScreen];
475 }
476
477 if ((([self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && ([gui selectedRow] == SAVE_OVERWRITE_NO_ROW)) || [gameView isDown:27] || [gameView isDown:cNo] || [gameView isDown:cNo - 32]) {
478 // esc or NO was pressed - get out of here
479 pollControls = YES;
480 [self playSaveOverwriteNo];
481 [self setGuiToSaveCommanderScreen:@""];
482 }
483}
#define SAVE_OVERWRITE_NO_ROW
#define SAVE_OVERWRITE_YES_ROW

References BUTTON_GUISELECT, OOJoystickManager::getAllButtonStates, PlayerEntity::handleGUIUpDownArrowKeys, PlayerEntity::nativeSavePlayer:, overwriteCommanderInputHandler, PlayerEntity::playSaveOverwriteNo, PlayerEntity::playSaveOverwriteYes, SAVE_OVERWRITE_NO_ROW, SAVE_OVERWRITE_YES_ROW, PlayerEntity::setGuiToSaveCommanderScreen:, PlayerEntity::setGuiToStatusScreen, and OOJoystickManager::sharedStickHandler.

Referenced by overwriteCommanderInputHandler.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quicksavePlayer

- (void) quicksavePlayer

Extends class PlayerEntity.

Definition at line 128 of file PlayerEntityLoadSave.m.

129{
130 MyOpenGLView* gameView = [UNIVERSE gameView];
131 NSString* path = nil;
132
133 path = save_path;
134 if (!path)
135 path = [[gameView gameController] playerFileToLoad];
136 if (!path) {
137 OOLog(@"quickSave.failed.noName", @"%@", @"ERROR no file name returned by [[gameView gameController] playerFileToLoad]");
138 [NSException raise:@"OoliteGameNotSavedException"
139 format:@"ERROR no file name returned by [[gameView gameController] playerFileToLoad]"];
140 }
141
142 [self doScriptEvent:OOJSID("playerWillSaveGame") withArgument:@"QUICK_SAVE"];
143
144 [self writePlayerToPath:path];
145 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
146 [self setGuiToStatusScreen];
147}
NSString * playerFileToLoad
GameController * gameController

References ShipEntity::doScriptEvent:withArgument:, MyOpenGLView::gameController, nil, OOLog, GameController::playerFileToLoad, quicksavePlayer, PlayerEntity::setGuiToStatusScreen, and PlayerEntity::writePlayerToPath:.

Referenced by quicksavePlayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveCommanderInputHandler

- (void) saveCommanderInputHandler

Extends class PlayerEntity.

Definition at line 366 of file PlayerEntityLoadSave.m.

367{
368 MyOpenGLView* gameView = [UNIVERSE gameView];
369 GuiDisplayGen* gui = [UNIVERSE gui];
370 NSString* dir = [[UNIVERSE gameController] playerFileDirectory];
371 const BOOL* joyButtonState = [[OOJoystickManager sharedStickHandler] getAllButtonStates];
372
373 if ([self handleGUIUpDownArrowKeys]) {
374 int guiSelectedRow = [gui selectedRow];
375 int idx = (guiSelectedRow - STARTROW) + (currentPage * NUMROWS);
376 if (guiSelectedRow != MOREROW && guiSelectedRow != BACKROW) {
377 [self showCommanderShip:idx];
378 if ([(NSDictionary*)[cdrDetailArray objectAtIndex:idx] oo_boolForKey:@"isSavedGame"]) // don't show things that aren't saved games
379 commanderNameString = [[cdrDetailArray oo_dictionaryAtIndex:idx] oo_stringForKey:@"player_save_name" defaultValue:[[cdrDetailArray oo_dictionaryAtIndex:idx] oo_stringForKey:@"player_name"]];
380 else
381 commanderNameString = [gameView typedString];
382 } else {
383 [UNIVERSE removeDemoShips];
384 [gui setText:@"" forRow:CDRDESCROW align:GUI_ALIGN_LEFT];
385 [gui setText:@"" forRow:CDRDESCROW + 1 align:GUI_ALIGN_LEFT];
386 [gui setText:@"" forRow:CDRDESCROW + 2 align:GUI_ALIGN_LEFT];
387 }
388 } else {
389 commanderNameString = [gameView typedString];
390 }
391
392 [gameView setTypedString:commanderNameString];
393
394 [gui setText:
395 [NSString stringWithFormat:DESC(@"savescreen-commander-name-@"), commanderNameString]
396 forRow:INPUTROW];
397 [gui setColor:[OOColor cyanColor] forRow:INPUTROW];
398
399 // handle page <-- and page --> keys, and on-screen buttons
400 if (((([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == BACKROW) || ([self checkKeyPress:n_key_gui_arrow_left] || [self checkKeyPress:n_key_gui_page_up]))
401 && [[gui keyForRow:BACKROW] isEqual:GUI_KEY_OK]) {
402 currentPage--;
403 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
404 [gameView suppressKeysUntilKeyUp];
405 }
406 //
407 if (((([gameView isDown:gvMouseDoubleClick] || [self checkKeyPress:n_key_gui_select] || joyButtonState[BUTTON_GUISELECT]) && [gui selectedRow] == MOREROW) || ([self checkKeyPress:n_key_gui_arrow_right] || [self checkKeyPress:n_key_gui_page_down]))
408 && [[gui keyForRow:MOREROW] isEqual:GUI_KEY_OK]) {
409 currentPage++;
410 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
411 [gameView suppressKeysUntilKeyUp];
412 }
413
414 // ignore Ctrl if pressed together with Enter for the moment - we check for it explicitly immediately after
415 if (([self checkKeyPress:n_key_gui_select ignore_ctrl:YES] || [gameView isDown:gvMouseDoubleClick] || joyButtonState[BUTTON_GUISELECT]) && [commanderNameString length]) {
416 if ([gameView isCommandModifierKeyDown] || [gameView isDown:gvMouseDoubleClick]) {
417 int guiSelectedRow = [gui selectedRow];
418 int idx = (guiSelectedRow - STARTROW) + (currentPage * NUMROWS);
419 NSDictionary* cdr = [cdrDetailArray objectAtIndex:idx];
420
421 if (![cdr oo_boolForKey:@"isSavedGame"]) // don't open saved games
422 {
423 // change directory to the selected path
424 NSString* newDir = [cdr oo_stringForKey:@"saved_game_path"];
425 [[UNIVERSE gameController] setPlayerFileDirectory:newDir];
426 dir = newDir;
427 currentPage = 0;
428 [self lsCommanders:gui directory:dir pageNumber:currentPage highlightName:nil];
429 [gameView suppressKeysUntilKeyUp];
430 }
431 } else {
432 pollControls = YES;
433 if ([self existingNativeSave:commanderNameString]) {
434 [gameView suppressKeysUntilKeyUp];
435 [self setGuiToOverwriteScreen:commanderNameString];
436 } else {
437 [self nativeSavePlayer:commanderNameString];
438 [[UNIVERSE gameView] suppressKeysUntilKeyUp];
439 [self setGuiToStatusScreen];
440 }
441 }
442 }
443
444 if ([gameView isDown:27]) // escape key
445 {
446 // get out of here
447 pollControls = YES;
448 [[UNIVERSE gameView] resetTypedString];
449 [self setGuiToStatusScreen];
450 }
451}
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
void setTypedString:(NSString *value)
NSMutableString * typedString
OOColor * cyanColor()
Definition OOColor.m:274

References BACKROW, BUTTON_GUISELECT, OOColor::cyanColor, OOJoystickManager::getAllButtonStates, GUI_KEY_OK, gvMouseDoubleClick, PlayerEntity::lsCommanders:directory:pageNumber:highlightName:, MOREROW, PlayerEntity::nativeSavePlayer:, NUMROWS, saveCommanderInputHandler, GuiDisplayGen::selectedRow, GuiDisplayGen::setColor:forRow:, PlayerEntity::setGuiToOverwriteScreen:, PlayerEntity::setGuiToStatusScreen, GuiDisplayGen::setText:forRow:, GuiDisplayGen::setText:forRow:align:, MyOpenGLView::setTypedString:, OOJoystickManager::sharedStickHandler, PlayerEntity::showCommanderShip:, STARTROW, MyOpenGLView::suppressKeysUntilKeyUp, and MyOpenGLView::typedString.

Referenced by saveCommanderInputHandler.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ savePlayer

- (void) savePlayer

Extends class PlayerEntity.

Definition at line 88 of file PlayerEntityLoadSave.m.

89{
90 [self setGuiToSaveCommanderScreen:[self lastsaveName]];
91}

References PlayerEntity::lastsaveName, savePlayer, and PlayerEntity::setGuiToSaveCommanderScreen:.

Referenced by savePlayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGuiToScenarioScreen:

- (void) setGuiToScenarioScreen: (int) page

Extends class PlayerEntity.

Definition at line 149 of file PlayerEntityLoadSave.m.

149 :(int)page
150{
151 NSArray* scenarios = [UNIVERSE scenarios];
152 [UNIVERSE removeDemoShips];
153 // GUI stuff
154 {
155 GuiDisplayGen* gui = [UNIVERSE gui];
157 OOGUIRow row = start_row;
158 BOOL guiChanged = (gui_screen != GUI_SCREEN_NEWGAME);
159
160 [gui clearAndKeepBackground:!guiChanged];
161 [gui setTitle:DESC(@"oolite-newgame-title")];
162
163 OOGUITabSettings tab_stops;
164 tab_stops[0] = 0;
165 tab_stops[1] = -480;
166 [gui setTabStops:tab_stops];
167
168 unsigned n_rows = GUI_MAX_ROWS_SCENARIOS;
169 NSUInteger i, count = [scenarios count];
170
171 NSDictionary* scenario = nil;
172
173 [gui setArray:[NSArray arrayWithObjects:DESC(@"oolite-scenario-exit"), @" <----- ", nil] forRow:start_row - 2];
174 [gui setColor:[OOColor redColor] forRow:start_row - 2];
175 [gui setKey:@"exit" forRow:start_row - 2];
176
177 if (page > 0) {
178 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil] forRow:start_row - 1];
179 [gui setColor:[OOColor greenColor] forRow:start_row - 1];
180 [gui setKey:[NSString stringWithFormat:@"__page:%i", page - 1] forRow:start_row - 1];
181 }
182
183 [self setShowDemoShips:NO];
184
185 for (i = page * n_rows; i < count && row < start_row + n_rows; i++) {
186 scenario = [[UNIVERSE scenarios] objectAtIndex:i];
187 NSString* scenarioName = [NSString stringWithFormat:@" %@ ", [scenario oo_stringForKey:@"name"]];
188 [gui setText:OOExpand(scenarioName) forRow:row];
189 [gui setKey:[NSString stringWithFormat:@"Scenario:%zu", i] forRow:row];
190 ++row;
191 }
192
193 if ((page + 1) * n_rows < count) {
194 [gui setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil] forRow:row];
195 [gui setColor:[OOColor greenColor] forRow:row];
196 [gui setKey:[NSString stringWithFormat:@"__page:%i", page + 1] forRow:row];
197 ++row;
198 }
199
200 gui_screen = GUI_SCREEN_NEWGAME;
201
202 [gui setSelectableRange:NSMakeRange(start_row - 2, 3 + row - start_row)];
203 [gui setSelectedRow:start_row];
204 [self showScenarioDetails];
205
206 if (guiChanged) {
207 [gui setBackgroundTextureKey:@"newgame"];
208 [gui setForegroundTextureKey:@"newgame_overlay"];
209 }
210 }
211
212 [UNIVERSE enterGUIViewModeWithMouseInteraction:YES];
213}
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
NSInteger OOGUIRow
unsigned count
@ GUI_ROW_SCENARIOS_START
@ GUI_MAX_ROWS_SCENARIOS
BOOL setBackgroundTextureKey:(NSString *key)
BOOL setSelectedRow:(OOGUIRow row)
BOOL setForegroundTextureKey:(NSString *key)
void clearAndKeepBackground:(BOOL keepBackground)
void setSelectableRange:(NSRange range)
void setTitle:(NSString *str)
void setTabStops:(OOGUITabSettings stops)
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
OOColor * redColor()
Definition OOColor.m:259
OOColor * greenColor()
Definition OOColor.m:264
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References GuiDisplayGen::clearAndKeepBackground:, count, OOColor::greenColor, GUI_MAX_ROWS_SCENARIOS, GUI_ROW_SCENARIOS_START, nil, OOColor::redColor, GuiDisplayGen::setArray:forRow:, GuiDisplayGen::setBackgroundTextureKey:, GuiDisplayGen::setColor:forRow:, GuiDisplayGen::setForegroundTextureKey:, GuiDisplayGen::setKey:forRow:, GuiDisplayGen::setSelectableRange:, GuiDisplayGen::setSelectedRow:, PlayerEntity::setShowDemoShips:, GuiDisplayGen::setTabStops:, GuiDisplayGen::setText:forRow:, GuiDisplayGen::setTitle:, and PlayerEntity::showScenarioDetails.

Here is the call graph for this function:

◆ showScenarioDetails

- (void) showScenarioDetails

Extends class PlayerEntity.

Definition at line 220 of file PlayerEntityLoadSave.m.

221{
222 GuiDisplayGen* gui = [UNIVERSE gui];
223 NSString* key = [gui selectedRowKey];
224 [UNIVERSE removeDemoShips];
225
226 if ([key hasPrefix:@"Scenario"]) {
227 int item = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
228 NSDictionary* scenario = [[UNIVERSE scenarios] objectAtIndex:item];
229 [self setShowDemoShips:NO];
230 for (NSUInteger i = GUI_ROW_SCENARIOS_DETAIL; i <= 27; i++) {
231 [gui setText:@"" forRow:i];
232 }
233 if (scenario) {
234 [gui addLongText:OOExpand([scenario oo_stringForKey:@"description"]) startingAtRow:GUI_ROW_SCENARIOS_DETAIL align:GUI_ALIGN_LEFT];
235 NSString* shipKey = [scenario oo_stringForKey:@"model"];
236 if (shipKey != nil) {
237 [self addScenarioModel:shipKey];
238 [self setShowDemoShips:YES];
239 }
240 }
241 }
242}
@ GUI_ROW_SCENARIOS_DETAIL
OOGUIRow addLongText:startingAtRow:align:(NSString *str,[startingAtRow] OOGUIRow row,[align] OOGUIAlignment alignment)
NSString * selectedRowKey()

References GuiDisplayGen::addLongText:startingAtRow:align:, PlayerEntity::addScenarioModel:, GUI_ROW_SCENARIOS_DETAIL, nil, GuiDisplayGen::selectedRowKey, PlayerEntity::setShowDemoShips:, GuiDisplayGen::setText:forRow:, and showScenarioDetails.

Referenced by showScenarioDetails.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startScenario

- (BOOL) startScenario

Extends class PlayerEntity.

Definition at line 244 of file PlayerEntityLoadSave.m.

245{
246 GuiDisplayGen* gui = [UNIVERSE gui];
247 NSString* key = [gui selectedRowKey];
248
249 if ([key isEqualToString:@"exit"]) {
250 // intended to return to main menu
251 return NO;
252 }
253 if ([key hasPrefix:@"__page"]) {
254 int page = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
255 [self setGuiToScenarioScreen:page];
256 return YES;
257 }
258 int selection = [[key componentsSeparatedByString:@":"] oo_intAtIndex:1];
259
260 NSDictionary* scenario = [[UNIVERSE scenarios] objectAtIndex:selection];
261 NSString* file = [scenario oo_stringForKey:@"file" defaultValue:nil];
262 if (file == nil) {
263 OOLog(@"scenario.init.error", @"%@", @"No file entry found for scenario");
264 return NO;
265 }
266 NSString* path = [ResourceManager pathForFileNamed:file inFolder:@"Scenarios"];
267 if (path == nil) {
268 OOLog(@"scenario.init.error", @"Game file not found for scenario %@", file);
269 return NO;
270 }
271 BOOL result = [self loadPlayerFromFile:path asNew:YES];
272 if (!result) {
273 return NO;
274 }
275 [scenarioKey release];
276 scenarioKey = [[scenario oo_stringForKey:@"scenario" defaultValue:nil] retain];
277
278 // don't drop the save game directory in
279 return YES;
280}
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References PlayerEntity::loadPlayerFromFile:asNew:, nil, OOLog, ResourceManager::pathForFileNamed:inFolder:, GuiDisplayGen::selectedRowKey, PlayerEntity::setGuiToScenarioScreen:, and startScenario.

Referenced by startScenario.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this category was generated from the following files: