diff --git a/Brokenithm-iOS.xcodeproj/project.pbxproj b/Brokenithm-iOS.xcodeproj/project.pbxproj index 2a5a583..780d35f 100644 --- a/Brokenithm-iOS.xcodeproj/project.pbxproj +++ b/Brokenithm-iOS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1961EB742507451600C79BF8 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 1961EB732507451600C79BF8 /* Settings.bundle */; }; 1968E72624086C2200784829 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1968E72524086C2200784829 /* AppDelegate.m */; }; 1968E72924086C2200784829 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1968E72824086C2200784829 /* ViewController.m */; }; 1968E72C24086C2200784829 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1968E72A24086C2200784829 /* Main.storyboard */; }; @@ -21,6 +22,7 @@ /* Begin PBXFileReference section */ 1277586B240D1432002C27EE /* MainApp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MainApp.h; sourceTree = ""; }; + 1961EB732507451600C79BF8 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; 1968E72124086C2200784829 /* Brokenithm-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Brokenithm-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1968E72424086C2200784829 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 1968E72524086C2200784829 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -84,6 +86,7 @@ 19F40719240CFCFF00D7F506 /* MainApp.m */, 1968E72724086C2200784829 /* ViewController.h */, 1968E72824086C2200784829 /* ViewController.m */, + 1961EB732507451600C79BF8 /* Settings.bundle */, 1968E72A24086C2200784829 /* Main.storyboard */, 1968E72D24086C2B00784829 /* Assets.xcassets */, 1968E73224086C2B00784829 /* Info.plist */, @@ -170,6 +173,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1961EB742507451600C79BF8 /* Settings.bundle in Resources */, 1968E72E24086C2B00784829 /* Assets.xcassets in Resources */, 19F40723240FE2B800D7F506 /* zh.lproj in Resources */, 1968E72C24086C2200784829 /* Main.storyboard in Resources */, @@ -349,7 +353,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = K9CP5766XY; INFOPLIST_FILE = "Brokenithm-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -373,7 +377,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = K9CP5766XY; INFOPLIST_FILE = "Brokenithm-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/Brokenithm-iOS/Settings.bundle/Root.plist b/Brokenithm-iOS/Settings.bundle/Root.plist new file mode 100644 index 0000000..8e3475c --- /dev/null +++ b/Brokenithm-iOS/Settings.bundle/Root.plist @@ -0,0 +1,63 @@ + + + + + StringsTable + Root + PreferenceSpecifiers + + + Type + PSToggleSwitchSpecifier + Title + Enable Air Input + Key + enableAir + DefaultValue + + + + Type + PSToggleSwitchSpecifier + Title + Auto Pop Menu + Key + autoPopMenu + DefaultValue + + + + Type + PSToggleSwitchSpecifier + Title + Invert Air Input Layout + Key + invertAir + DefaultValue + + + + Type + PSTitleValueSpecifier + DefaultValue + + Title + Hold duration to open side menu + Key + menuDurationTitle + + + Type + PSSliderSpecifier + Key + menuDuration + MinimumValue + 0.5 + DefaultValue + 1 + MaximumValue + 2 + + + + diff --git a/Brokenithm-iOS/Settings.bundle/en.lproj/Root.strings b/Brokenithm-iOS/Settings.bundle/en.lproj/Root.strings new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Brokenithm-iOS/Settings.bundle/en.lproj/Root.strings @@ -0,0 +1 @@ + diff --git a/Brokenithm-iOS/Settings.bundle/zh.lproj/Root.strings b/Brokenithm-iOS/Settings.bundle/zh.lproj/Root.strings new file mode 100644 index 0000000..17a661c Binary files /dev/null and b/Brokenithm-iOS/Settings.bundle/zh.lproj/Root.strings differ diff --git a/Brokenithm-iOS/SocketDelegate.m b/Brokenithm-iOS/SocketDelegate.m index 4e0d1ba..b47546a 100644 --- a/Brokenithm-iOS/SocketDelegate.m +++ b/Brokenithm-iOS/SocketDelegate.m @@ -96,6 +96,7 @@ [server disconnect]; } - (void)becomeActive { + [self.parentVc becomeActive]; server.IPv4Enabled = YES; server.IPv6Enabled = YES; [self acceptConnection]; diff --git a/Brokenithm-iOS/ViewController.h b/Brokenithm-iOS/ViewController.h index cab851f..24980d6 100644 --- a/Brokenithm-iOS/ViewController.h +++ b/Brokenithm-iOS/ViewController.h @@ -29,8 +29,10 @@ UILabel *openCloseBtn; UISwitch *enableAirToggle; BOOL airEnabled; - UISwitch *autoPopToggle; BOOL autoPopMenu; + BOOL invertAir; + NSNumber *menuHoldDuration; + UILongPressGestureRecognizer *openCloseHold; } @property UIView *airIOView; @property UIView *sliderIOView; @@ -40,6 +42,7 @@ -(void)connected; -(void)disconnected; -(void)becomeInactive; +-(void)becomeActive; @end diff --git a/Brokenithm-iOS/ViewController.m b/Brokenithm-iOS/ViewController.m index 5ec76ed..63f01f0 100644 --- a/Brokenithm-iOS/ViewController.m +++ b/Brokenithm-iOS/ViewController.m @@ -22,7 +22,12 @@ - (void)viewDidLoad { [super viewDidLoad]; pendingHideStatus = NO; - [NSUserDefaults.standardUserDefaults registerDefaults:@{@"enableAir":@YES, @"autoPopMenu":@YES}]; + [NSUserDefaults.standardUserDefaults registerDefaults:@{ + @"enableAir": @YES, + @"autoPopMenu": @YES, + @"invertAir": @NO, + @"menuDuration": @1.0 + }]; funcViewOn = YES; openCloseEventOnce = NO; @@ -40,9 +45,8 @@ CGRect screenSize = [UIScreen mainScreen].bounds; screenWidth = screenSize.size.width; screenHeight = screenSize.size.height; - float offsetY = 0, sliderHeight = screenHeight; - self.airIOView = [[UIView alloc] initWithFrame:CGRectMake(0, offsetY, screenWidth, screenHeight*0.4)]; - offsetY += screenHeight*0.4; + float sliderHeight = screenHeight; + self.airIOView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight*0.4)]; self.sliderIOView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, sliderHeight)]; self.airIOView.backgroundColor = [UIColor blackColor]; self.airIOView.layer.borderWidth = 1.0f; @@ -83,7 +87,7 @@ openCloseBtn.text = @"◀"; openCloseBtn.font = [UIFont systemFontOfSize:30]; UITapGestureRecognizer *openCloseTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeFunc)]; - UILongPressGestureRecognizer *openCloseHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(openOrCloseFunc)]; + openCloseHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(openOrCloseFunc)]; openCloseHold.minimumPressDuration = 1; [openCloseBtnBorder addGestureRecognizer:openCloseTap]; [openCloseBtnBorder addGestureRecognizer:openCloseHold]; @@ -106,7 +110,7 @@ } UIView *enableAir; UILabel *enableAirLabel; - enableAir = [[UIView alloc] initWithFrame:CGRectMake(0, 240, 200, 60)]; + enableAir = [[UIView alloc] initWithFrame:CGRectMake(0, offset, 200, 60)]; enableAir.backgroundColor = [UIColor blackColor]; enableAir.layer.borderColor = [UIColor whiteColor].CGColor; enableAir.layer.borderWidth = 1.0; @@ -118,31 +122,20 @@ enableAirLabel.text = [[NSBundle mainBundle] localizedStringForKey:@"Enable Air Input" value:@"" table:nil]; [enableAir addSubview:enableAirLabel]; enableAirToggle = [[UISwitch alloc] initWithFrame:CGRectMake(135, 13, 50, 27)]; - BOOL pref = [NSUserDefaults.standardUserDefaults boolForKey:@"enableAir"]; - [enableAirToggle setOn:pref animated:NO]; - [enableAirToggle addTarget:self action:@selector(enableAirChanged) forControlEvents:UIControlEventValueChanged]; - [self updateAirEnabled:pref]; [enableAir addSubview:enableAirToggle]; + offset += 60; - UIView *autoPop; - UILabel *autoPopLabel; - autoPop = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 200, 60)]; - autoPop.backgroundColor = [UIColor blackColor]; - autoPop.layer.borderColor = [UIColor whiteColor].CGColor; - autoPop.layer.borderWidth = 1.0; - [functionBtnView addSubview:autoPop]; - autoPopLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 130, 60)]; - autoPopLabel.textAlignment = NSTextAlignmentRight; - autoPopLabel.textColor = [UIColor whiteColor]; - autoPopLabel.numberOfLines = 1; - autoPopLabel.text = [[NSBundle mainBundle] localizedStringForKey:@"Auto Pop Menu" value:@"" table:nil]; - [autoPop addSubview:autoPopLabel]; - autoPopToggle = [[UISwitch alloc] initWithFrame:CGRectMake(135, 13, 50, 27)]; - pref = [NSUserDefaults.standardUserDefaults boolForKey:@"autoPopMenu"]; - [autoPopToggle setOn:pref animated:NO]; - [autoPopToggle addTarget:self action:@selector(autoPopChanged) forControlEvents:UIControlEventValueChanged]; - autoPopMenu = pref; - [autoPop addSubview:autoPopToggle]; + FunctionButton *moreBtn = [[FunctionButton alloc] initAtY:offset]; + offset += 60; + moreBtn.name = @"more_setting_button"; + moreBtn.text = [[NSBundle mainBundle] localizedStringForKey:@"More..." value:@"" table:nil]; + moreBtn.userInteractionEnabled = YES; + UITapGestureRecognizer *moreBtnTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jumpToSetting)]; + [moreBtn addGestureRecognizer:moreBtnTap]; + [functionBtnView addSubview:moreBtn]; + + [self loadPrefs]; + [enableAirToggle addTarget:self action:@selector(enableAirChanged) forControlEvents:UIControlEventValueChanged]; } } @@ -193,6 +186,24 @@ NSLog(@"server created"); } +-(void)loadPrefs { + // enable air + BOOL pref = [NSUserDefaults.standardUserDefaults boolForKey:@"enableAir"]; + [enableAirToggle setOn:pref animated:NO]; + [self updateAirEnabled:pref]; + + // auto pop + autoPopMenu = [NSUserDefaults.standardUserDefaults boolForKey:@"autoPopMenu"]; + + // invert air + pref = [NSUserDefaults.standardUserDefaults boolForKey:@"invertAir"]; + [self updateAirInverted:pref]; + + // hold duration + menuHoldDuration = [NSUserDefaults.standardUserDefaults valueForKey:@"menuDuration"]; + openCloseHold.minimumPressDuration = [menuHoldDuration floatValue]; +} + -(void)updateLed:(NSData*)rgbData { if (rgbData.length != 32*3) return; NSMutableArray *colorArr = [NSMutableArray arrayWithCapacity:33]; @@ -225,10 +236,14 @@ airEnabled = enable; } --(void)autoPopChanged{ - BOOL pref = autoPopToggle.on; - [NSUserDefaults.standardUserDefaults setBool:pref forKey:@"autoPopMenu"]; - autoPopMenu = pref; +-(void)updateAirInverted:(BOOL)invert { + if (invertAir != invert) { + CGRect screenSize = [UIScreen mainScreen].bounds; + screenWidth = screenSize.size.width; + screenHeight = screenSize.size.height; + self.airIOView.frame = CGRectMake(0, invert ? screenHeight * 0.6 : 0, screenWidth, screenHeight * 0.4); + invertAir = invert; + } } -(void)openOrCloseFunc { @@ -262,6 +277,9 @@ [self sendIoBuf:&buf]; } } +-(void)jumpToSetting { + [UIApplication.sharedApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; +} -(BOOL)prefersStatusBarHidden { return kCFCoreFoundationVersionNumber < 1443.00; } -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures { return UIRectEdgeAll; } @@ -317,8 +335,17 @@ } CGPoint point = [touch locationInView:nil]; float pointX = screenWidth - point.x, pointY = point.y; - if (airEnabled && pointY < airHeight) { - int idx = pointY / airIOHeight; + BOOL inAirRange = airEnabled && ( + (invertAir && pointY > screenHeight - airHeight) || + (!invertAir && pointY < airHeight) + ); + if (inAirRange) { + int idx; + if (invertAir) { + idx = (screenHeight - pointY) / airIOHeight; + } else { + idx = pointY / airIOHeight; + } uint8_t airIdx[] = {4,5,2,3,0,1}; buf.air[airIdx[idx]] = 1; } else { @@ -380,5 +407,8 @@ struct ioBuf buf = {0}; [self sendIoBuf:&buf]; } +-(void)becomeActive { + [self loadPrefs]; +} @end diff --git a/Brokenithm-iOS/zh.lproj/Localizable.strings b/Brokenithm-iOS/zh.lproj/Localizable.strings index 348733e..776e856 100755 --- a/Brokenithm-iOS/zh.lproj/Localizable.strings +++ b/Brokenithm-iOS/zh.lproj/Localizable.strings @@ -4,5 +4,5 @@ "Enable Air Input" = "启用Air输入"; "Insert Coin" = "投币"; "Read Card" = "刷卡"; - "Auto Pop Menu" = "自动弹出菜单"; + "More..." = "更多设置…"; }