// // 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 - (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]; } } - (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]; } } - (void)clearScreen { for (UILabel *label in _LSK) { label.text = @""; } } - (void)enterLSK:(UITapGestureRecognizer *)tapReg { if ([_Scratchpad.text isEqualToString:@"DELETE"]) { ((UILabel *)tapReg.view).text = @""; } else 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; } else { ((UILabel *)tapReg.view).text = _Scratchpad.text; } 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]]; } [_main.save setObject:((UILabel *)tapReg.view).text forKey:[NSString stringWithFormat:@"%@@%@", _Header.text, ((UILabel *)tapReg.view) .restorationIdentifier]]; _Scratchpad.text = @""; [_main saveToFile:_main.save]; } - (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options { [self clearScreen]; _Header.text = screenName; NSArray *screen = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:screenName ofType:@"plist"]]; for (int i = 0; i < _Desc.count; i++) { ((UILabel *)_Desc[i]).text = [NSString stringWithFormat:@"%@\n", screen[i]]; if (![screen[i] isEqualToString:@""] || [_Header.text isEqualToString:@"ROUTE"]) { ((UILabel *)_LSK[i]).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]; } - (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]; } } } } } @end