|
@@ -7,142 +7,35 @@
|
|
|
//
|
|
|
|
|
|
#import "BlackDoorManager.h"
|
|
|
+#import "BlackDoorManager+data.h"
|
|
|
#import <EasyShowView/EasyShowView.h>
|
|
|
|
|
|
-#define KEY_BDM_USERCLICK @"KEY_BDM_USERCLICK"
|
|
|
-#define KEY_BDM_USERCLICK_HEADER @"@BDM*"
|
|
|
-#define KEY_BDM_CLICK_TAG 1234567890
|
|
|
-#define BDM_BUTTON_CLICK_SIZE 90
|
|
|
-#define BDM_BUTTON_SERVER_SIZE_WIDTH 120
|
|
|
-#define BDM_BUTTON_SERVER_SIZE_HEIGHT 50
|
|
|
-#define TIME_INTERVAL_MAX 8
|
|
|
-#define BDM_CLICK_ORDER @"323"
|
|
|
-
|
|
|
-#define BDM_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
|
|
|
-#define BDM_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
|
|
|
-
|
|
|
|
|
|
@implementation BlackDoorManager
|
|
|
|
|
|
-+ (void)addBlackDoor:(UIView*)supperView {
|
|
|
- for (NSInteger i = 1; i <= 4; i++) {
|
|
|
- UIButton* button = [[UIButton alloc] init];
|
|
|
- button.tag = KEY_BDM_CLICK_TAG + i;
|
|
|
- [button setBackgroundColor:[UIColor clearColor]];
|
|
|
- [supperView addSubview:button];
|
|
|
-
|
|
|
- CGFloat x = ((i == 1) || (i == 3))? 0 : (BDM_SCREEN_WIDTH - BDM_BUTTON_CLICK_SIZE);
|
|
|
- CGFloat y = ((i == 1) || (i == 2))? 60 : (BDM_SCREEN_HEIGHT - BDM_BUTTON_CLICK_SIZE) - 40;
|
|
|
- [button setFrame:CGRectMake(x, y, BDM_BUTTON_CLICK_SIZE, BDM_BUTTON_CLICK_SIZE)];
|
|
|
- [button addTarget:self action:@selector(blButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+ [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
|
|
|
+ UIView* view = [self addWhiteView];
|
|
|
+ [self addBackButton:view];
|
|
|
+ [self addCategoryButtons:view];
|
|
|
+ [self addTypeButtons:view];
|
|
|
+ [self addLogButton:view];
|
|
|
}
|
|
|
+ return self;
|
|
|
}
|
|
|
|
|
|
-+ (void)blButtonClick:(UIButton*)button {
|
|
|
- NSInteger index = button.tag % KEY_BDM_CLICK_TAG ;
|
|
|
- NSLog(@"BlackDoorManager: index:%ld", (long)index);
|
|
|
- [self blButtonClickEx:index supperView:[button superview]];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)blButtonClickEx:(NSInteger)index supperView:(UIView*)supperView {
|
|
|
- switch (index) {
|
|
|
- case 1: {
|
|
|
- //清空点击消息
|
|
|
- [self clearUserClickInfo];
|
|
|
-
|
|
|
- NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
|
|
|
- NSString *info = [NSString stringWithFormat:@"%@_%@_",KEY_BDM_USERCLICK_HEADER, @(timestamp)];
|
|
|
- [self setUserClickInfo:info];
|
|
|
- break;
|
|
|
- }
|
|
|
- case 2:
|
|
|
- case 3: {
|
|
|
- //点击信息不全
|
|
|
- NSString* info = [self getUserClickInfo];
|
|
|
- NSArray* array = [info componentsSeparatedByString:@"_"];
|
|
|
- if (array.count < 2) {
|
|
|
- [self showTosatWithMsg:@"请重新点击(跳点)" supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //验证头字串不对
|
|
|
- NSString* header = array[0];
|
|
|
- if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
|
|
|
- [self showTosatWithMsg:@"请重新点击(校验错误)" supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- [self setUserClickInfo:[NSString stringWithFormat:@"%@%@", info, @(index)]];
|
|
|
- break;
|
|
|
- }
|
|
|
- case 4: {
|
|
|
- //点击信息不全
|
|
|
- NSString* info = [self getUserClickInfo];
|
|
|
- NSArray* array = [info componentsSeparatedByString:@"_"];
|
|
|
- if (array.count < 3) {
|
|
|
- [self showTosatWithMsg:@"请重新点击(跳点)" supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //验证头字串不对
|
|
|
- NSString* header = array[0];
|
|
|
- if (![header isEqualToString:KEY_BDM_USERCLICK_HEADER]) {
|
|
|
- [self showTosatWithMsg:@"请重新点击(校验错误)" supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //点击超时
|
|
|
- NSTimeInterval beginTime = [array[1] integerValue];
|
|
|
- NSTimeInterval nowTime = [[NSDate date] timeIntervalSince1970];
|
|
|
- if (nowTime > beginTime && (nowTime - beginTime > TIME_INTERVAL_MAX)) {
|
|
|
- [self showTosatWithMsg:[NSString stringWithFormat:@"请重新点击(%d秒超时)", TIME_INTERVAL_MAX] supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //点击顺序不对
|
|
|
- NSString* order = array[2];
|
|
|
- if (![order isEqualToString:BDM_CLICK_ORDER]) {
|
|
|
- [self showTosatWithMsg:@"请重新点击(顺序不对)" supperView:supperView];
|
|
|
- [self clearUserClickInfo];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //验证通过
|
|
|
- [self showBlackDoorView:supperView];
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)showBlackDoorView:(UIView*)supperView {
|
|
|
- UIView* view = [self showBackground:supperView];
|
|
|
- [self showBackButton:view];
|
|
|
- [self showServerAllButtons:view];
|
|
|
- [self showServerTestDevButtons:view];
|
|
|
- [self showLogButton:view];
|
|
|
-}
|
|
|
-
|
|
|
-+ (UIView*)showBackground:(UIView*)supperView {
|
|
|
- UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, BDM_SCREEN_WIDTH, BDM_SCREEN_HEIGHT)];
|
|
|
- [bgview setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
|
|
|
- [supperView addSubview:bgview];
|
|
|
-
|
|
|
+- (UIView*)addWhiteView {
|
|
|
CGFloat Height = BDM_SCREEN_HEIGHT - 100;
|
|
|
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(20, (BDM_SCREEN_HEIGHT-Height)/2, BDM_SCREEN_WIDTH - 40, Height)];
|
|
|
[view setBackgroundColor:[UIColor whiteColor]];
|
|
|
- [bgview addSubview:view];
|
|
|
+ [self addSubview:view];
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
//关闭
|
|
|
-+ (void)showBackButton:(UIView*)view {
|
|
|
+- (void)addBackButton:(UIView*)view {
|
|
|
UIButton* backBtn = [[UIButton alloc] init];
|
|
|
[backBtn setTitle:@"关闭" forState:UIControlStateNormal];
|
|
|
[backBtn setBackgroundColor:[UIColor redColor]];
|
|
@@ -151,44 +44,26 @@
|
|
|
[view addSubview:backBtn];
|
|
|
}
|
|
|
|
|
|
-+ (void)showServerAllButtons:(UIView*)view {
|
|
|
+- (void)addCategoryButtons:(UIView*)view {
|
|
|
//当前服务器//
|
|
|
- NSInteger serverType = [ServerManager getServerType];
|
|
|
- NSArray* serverNames = [ServerManager getServerNames];
|
|
|
+ NSInteger serverType = [ServerManager getServerCategory];
|
|
|
+ NSArray* serverNames = [ServerManager getServerCategoryNames];
|
|
|
|
|
|
- for (NSInteger i = 0; i <= 2; i++) {
|
|
|
- UIButton* button = [[UIButton alloc] init];
|
|
|
- button.tag = i;
|
|
|
- button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
|
|
|
- [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
- [button addTarget:self action:@selector(serverButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
- [view addSubview:button];
|
|
|
-
|
|
|
- //如果是当前服务器//
|
|
|
- button.alpha = serverType != i ? 1:0.1;
|
|
|
-
|
|
|
- if (i == 0) {
|
|
|
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
- [button setBackgroundColor:[UIColor greenColor]];
|
|
|
- [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 70, 200, 100)];
|
|
|
- }
|
|
|
- else if (i == 1) {
|
|
|
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
- [button setBackgroundColor:[UIColor magentaColor]];
|
|
|
- [button setFrame:CGRectMake(20, 200, 150, 100)];
|
|
|
- }
|
|
|
- else if (i == 2) {
|
|
|
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
- [button setBackgroundColor:[UIColor redColor]];
|
|
|
- [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 200, 150, 100)];
|
|
|
- }
|
|
|
- }
|
|
|
+ UIButton* button = [[UIButton alloc] init];
|
|
|
+ button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
|
|
|
+ [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
+ [view addSubview:button];
|
|
|
+
|
|
|
+ button.alpha = 0.1;
|
|
|
+ [button setTitle:serverNames[serverType] forState:UIControlStateNormal];
|
|
|
+ [button setBackgroundColor:[UIColor greenColor]];
|
|
|
+ [button setFrame:CGRectMake(15, 70, view.frame.size.width-30, 100)];
|
|
|
}
|
|
|
|
|
|
-+ (void)showServerTestDevButtons:(UIView*)view {
|
|
|
+- (void)addTypeButtons:(UIView*)view {
|
|
|
//当前服务器//
|
|
|
NSInteger serverType = [ServerManager getServerType];
|
|
|
- NSArray* serverNames = [ServerManager getServerNames];
|
|
|
+ NSArray* serverNames = [ServerManager getServerTypeNames];
|
|
|
|
|
|
for (NSInteger i = 0; i <= 2; i++) {
|
|
|
UIButton* button = [[UIButton alloc] init];
|
|
@@ -204,23 +79,23 @@
|
|
|
if (i == 0) {
|
|
|
[button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
[button setBackgroundColor:[UIColor greenColor]];
|
|
|
- [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 70, 200, 100)];
|
|
|
+ [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 210, 200, 70)];
|
|
|
}
|
|
|
else if (i == 1) {
|
|
|
[button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
[button setBackgroundColor:[UIColor magentaColor]];
|
|
|
- [button setFrame:CGRectMake(20, 200, 150, 100)];
|
|
|
+ [button setFrame:CGRectMake(20, 300, 150, 70)];
|
|
|
}
|
|
|
else if (i == 2) {
|
|
|
[button setTitle:serverNames[i] forState:UIControlStateNormal];
|
|
|
[button setBackgroundColor:[UIColor redColor]];
|
|
|
- [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 200, 150, 100)];
|
|
|
+ [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 300, 150, 70)];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//log
|
|
|
-+ (void)showLogButton:(UIView*)view {
|
|
|
+- (void)addLogButton:(UIView*)view {
|
|
|
CGFloat height = 100;
|
|
|
UIView* logView = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-height, view.frame.size.width, height)];
|
|
|
[logView setBackgroundColor:[UIColor clearColor]];
|
|
@@ -243,57 +118,20 @@
|
|
|
[logView addSubview:switchBtn];
|
|
|
}
|
|
|
|
|
|
-+ (void)serverButtonClick:(UIButton*)button {
|
|
|
- [EasyTextView showSuccessText:@"切换服务器成功!"];
|
|
|
- [ServerManager setServerType:button.tag];
|
|
|
- [[[button superview] superview] removeFromSuperview];
|
|
|
+- (void)backButtonClick:(id)sender {
|
|
|
+ [self removeFromSuperview];
|
|
|
}
|
|
|
|
|
|
-+ (void)backButtonClick:(UIButton*)button {
|
|
|
- [[[button superview] superview] removeFromSuperview];
|
|
|
+- (void)serverButtonClick:(UIButton*)button {
|
|
|
+ [EasyTextView showSuccessText:@"切换服务器成功!"];
|
|
|
+ [ServerManager setServerType:button.tag];
|
|
|
+ [self removeFromSuperview];
|
|
|
}
|
|
|
|
|
|
-+ (void)clickSwitchButton:(id)sender {
|
|
|
+- (void)clickSwitchButton:(id)sender {
|
|
|
UISwitch* switchBtn = (UISwitch*)sender;
|
|
|
[BlackDoorManager setLogStatus:switchBtn.isOn ? 1 : 0];
|
|
|
[WindowLoggerManager refreshWindowLoggerStatus];
|
|
|
}
|
|
|
|
|
|
-+ (void)setUserClickInfo:(NSString*)info {
|
|
|
- [[NSUserDefaults standardUserDefaults] setObject:info forKey:KEY_BDM_USERCLICK];
|
|
|
- [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)clearUserClickInfo {
|
|
|
- [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_BDM_USERCLICK];
|
|
|
- [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString*)getUserClickInfo {
|
|
|
- return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_BDM_USERCLICK];
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSInteger)getLogStatus {
|
|
|
- NSNumber* type = [[NSUserDefaults standardUserDefaults] objectForKey:@"KEY_LOG_TYPE"];
|
|
|
- if (type) {
|
|
|
- return [type integerValue];
|
|
|
- } else {
|
|
|
- NSInteger value = 0;
|
|
|
- [self setLogStatus:value];
|
|
|
- return value;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)setLogStatus:(NSInteger)type {
|
|
|
- [[NSUserDefaults standardUserDefaults] setObject:@(type) forKey:@"KEY_LOG_TYPE"];
|
|
|
- [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)showTosatWithMsg:(NSString *)strMsg supperView:(UIView*)supperView {
|
|
|
- NSInteger serverType = [ServerManager getServerType];
|
|
|
- if (serverType == 0)
|
|
|
- return;
|
|
|
- [EasyTextView showText:strMsg];
|
|
|
-}
|
|
|
-
|
|
|
@end
|