// // ViewControllerScreen.m // FMC Planner 2 // // Created by Kilian Hofmann on 20.03.16. // Copyright © 2016 Kilian Hofmann. All rights reserved. // #import "ViewController.h" #import "ViewControllerScreen.h" @implementation ViewControllerScreen NavDataParser *parser = nil; #pragma mark - View management and navigation - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Init Start Page [self clearScreen]; _Header.text = @"START"; _Scratchpad.text = @""; _numRoutePage = 1; // ADJUST BASED ON SAVE _maxNumRoutePages = 1; // Tap gesture shit for (UILabel *label in _LSK) { label.adjustsFontSizeToFitWidth = YES; UITapGestureRecognizer *reg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(enterLSK:)]; reg.numberOfTapsRequired = 1; reg.numberOfTouchesRequired = 1; [label addGestureRecognizer:reg]; } parser = _main.navDataParser; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:YES]; [self loadScreen:@"MENU" withOptions:nil]; } - (void)viewDidLayoutSubviews { _FrameHeight.constant = self.view.frame.size.height / 14.5; // Size and LineBreak _Header.font = [SharedDeclerations findAdaptiveFontForUILabelSize:_Header.frame.size withMinimumSize:5 withMod:0.7]; _Header.adjustsFontSizeToFitWidth = YES; _Scratchpad.font = [SharedDeclerations findAdaptiveFontForUILabelSize:_Scratchpad.frame.size withMinimumSize:5 withMod:0.7]; _Scratchpad.adjustsFontSizeToFitWidth = YES; for (UILabel *label in _LSK) { label.font = [SharedDeclerations findAdaptiveFontForUILabelSize:_Header.frame.size withMinimumSize:5 withMod:0.6]; } } #pragma mark - LSK action - (void)enterLSK:(UITapGestureRecognizer *)tapReg { if ([_Scratchpad.text isEqualToString:INVALID] || [_Scratchpad.text isEqualToString:NOTREADY]) { // DO NOTHING AS OF YET } else if ([_Scratchpad.text isEqualToString:@"DELETE"]) { ((UILabel *)tapReg.view).text = @""; _Scratchpad.text = @""; } else if ([_Header.text isEqualToString:@"MENU"]) { if ([((UILabel *)tapReg.view) .restorationIdentifier isEqualToString:@"LSKR1"]) { if ([((UILabel *)tapReg.view).text isEqualToString:@""]) { _main.firstLoad = true; } else if (!([((UILabel *)tapReg.view) .text isEqualToString:_Scratchpad.text])) { _main.firstLoad = true; } _main.backupCoRte = ((UILabel *)tapReg.view).text; ((UILabel *)tapReg.view).text = _Scratchpad.text; _Scratchpad.text = @""; } else if ([((UILabel *)tapReg.view) .restorationIdentifier isEqualToString:@"LSKR4"]) { [_main saveToFile:_main.save]; _main.save = [[NSMutableDictionary alloc] init]; [self clearScreen]; NSArray *optional = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LSKs" ofType:@"plist"]] valueForKey:_Header.text]; for (UILabel *label in _LSK) { for (int i = 0; i < optional.count; i++) { if (label.tag == i && [label.text isEqualToString:@""]) { label.text = optional[i]; if (!([optional[i] isEqualToString:@""])) { label.userInteractionEnabled = YES; } } } } } else if ([((UILabel *)tapReg.view) .restorationIdentifier isEqualToString:@"LSKR5"]) { // TODO: Export to PMDG route format } else if ([((UILabel *)tapReg.view) .restorationIdentifier isEqualToString:@"LSKR6"]) { UINavigationController *sm = [self.storyboard instantiateViewControllerWithIdentifier:@"ServiceMenu"]; ((ViewControllerServiceMenu *)(sm.childViewControllers).firstObject) .main = _main; [self presentViewController:sm animated:YES completion:nil]; } else { ((UILabel *)tapReg.view).text = _Scratchpad.text; _Scratchpad.text = @""; } } else if ([[_Header.text substringToIndex:3] isEqualToString:@"ROU"]) { #warning TEST BED for NOW if (parser.parserReady) { NSArray *finds = [parser findWaypoint:_Scratchpad.text]; if (finds.count != 0) { ((UILabel *)tapReg.view).text = _Scratchpad.text; _Scratchpad.text = @""; } else { _Scratchpad.text = INVALID; } } else { _Scratchpad.text = NOTREADY; } if ([((UILabel *)tapReg.view) .restorationIdentifier isEqualToString:@"LSKR6"] && _numRoutePage == _maxNumRoutePages) { _maxNumRoutePages += 1; NSRange indexSlash = [_Header.text rangeOfString:@"/"]; _Header.text = [_Header.text stringByReplacingCharactersInRange:NSMakeRange( indexSlash.location, _Header.text.length - indexSlash.location) withString: [NSString stringWithFormat: @"/%lu", (unsigned long) _maxNumRoutePages]]; } } else { ((UILabel *)tapReg.view).text = _Scratchpad.text; _Scratchpad.text = @""; } (_main.save)[[NSString stringWithFormat:@"%@@%@", _Header.text, ((UILabel *)tapReg.view).restorationIdentifier]] = ((UILabel *)tapReg.view).text; [_main saveToFile:_main.save]; } #pragma mark - Screen actions - (void)clearScreen { for (UILabel *label in _LSK) { label.text = @""; } } - (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options { [self clearScreen]; _Header.text = screenName; NSArray *screen = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:screenName ofType:@"plist"]]; for (UILabel *label in _Desc) { for (int j = 0; j < screen.count; j++) { if ((label.restorationIdentifier).intValue == j) { label.text = screen[j]; } if (![screen[j] isEqualToString:@""] || [_Header.text isEqualToString:@"ROUTE"]) { for (UILabel *lsk in _LSK) { if (lsk.tag == j) { lsk.userInteractionEnabled = YES; } } } } } for (NSString *opt in options) { if ([opt isEqualToString:FMCNEXTRTEPAGE]) { _numRoutePage += 1; } else if ([opt isEqualToString:FMCFIRSTRTEPAGE]) { _numRoutePage = 1; } _Header.text = [_Header.text stringByAppendingString: [NSString stringWithFormat:@" %lu/%lu", (unsigned long)_numRoutePage, (unsigned long)_maxNumRoutePages]]; } [self loadDataToScreen]; NSArray *optional = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LSKs" ofType:@"plist"]] valueForKey:_Header.text]; for (UILabel *label in _LSK) { for (int i = 0; i < optional.count; i++) { if (label.tag == i && [label.text isEqualToString:@""]) { label.text = optional[i]; if (!([optional[i] isEqualToString:@""])) { label.userInteractionEnabled = YES; } } } } } - (void)loadDataToScreen { for (NSString *ident in _main.save) { NSRange range = [ident rangeOfString:@"@"]; if ([[ident substringToIndex:range.location] isEqualToString:_Header.text]) { for (UILabel *label in _LSK) { if ([label.restorationIdentifier isEqualToString:[ident substringFromIndex:range.location + 1]]) { label.text = [_main.save valueForKey:ident]; } } } NSArray *optional = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LSKs" ofType:@"plist"]] valueForKey:_Header.text]; for (UILabel *label in _LSK) { for (int i = 0; i < optional.count; i++) { if (label.tag == i && [label.text isEqualToString:@""]) { label.text = optional[i]; if (!([optional[i] isEqualToString:@""])) { label.userInteractionEnabled = YES; } } } } } } @end