// // ViewControllerScreen.m // FMC Planner 2 // // Created by Kilian Hofmann on 20.03.16. // Copyright © 2016 Kilian Hofmann. All rights reserved. // #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 = @""; } _Scratchpad.text = @""; _Header.text = @""; } - (void)enterLSK:(UITapGestureRecognizer *)tapReg { if ([_Scratchpad.text isEqualToString:@"DELETE"]) { ((UILabel *)tapReg.view).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: @"/%u", _maxNumRoutePages]]; } _Scratchpad.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 (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:@" %u/%u", _numRoutePage, _maxNumRoutePages]]; } } @end