Files
yuyin_ios/SweetParty/主类/RCMic/Room/Box/规则说明/BJBoxRuleAlert.m
2025-08-08 11:05:33 +08:00

232 lines
8.0 KiB
Objective-C
Executable File

//
// ShuoMingView.m
// miliao
//
// Created by 翟三美 on 2020/8/14.
// Copyright © 2020 miliao. All rights reserved.
//
#import "BJBoxRuleAlert.h"
#import <WebKit/WebKit.h>
@interface BJBoxRuleAlert ()
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) UILabel *ruleLabel;
@property (nonatomic, strong) UILabel *xiaohaoLab;
@property (nonatomic, strong) UILabel *chanchuLab;
@property (nonatomic, strong) UILabel *biliLab;
@property (nonatomic, assign) NSInteger poolType;
@property (nonatomic, assign) CGFloat mainW;
@property (nonatomic, assign) CGFloat mainH;
@property (nonatomic, assign) CGFloat contentX;
@property (nonatomic, assign) CGFloat contentTop;
@property (nonatomic, assign) CGFloat contentBottom;
@property (nonatomic, copy) NSString *bgImgName;
@property (nonatomic, strong) WKWebView*webView;
@end
@implementation BJBoxRuleAlert
- (instancetype)initWithFrame:(CGRect)frame {
if ([super initWithFrame:frame]) {
self.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
[ControlCreator createButton:self rect:self.bounds text:@"" font:nil color:nil backguoundColor:UIColor.clearColor imageName:nil target:self action:@selector(backAction)];
}
return self;
}
- (void)initMainView {
if (_mainView) {
return;
}
UIColor *color;
if (self.poolType == 4 || self.poolType == 5 || self.poolType == 6) {
color = HEXCOLOR(0xFFFFFF);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}else if (self.poolType == 21){
color = HEXCOLOR(0x752400);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}else {
color = HEXCOLOR(0xFFFFFF);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}
_mainView.backgroundColor = UIColor.clearColor;
[self addSubview:_mainView];
[ControlCreator createImageView:_mainView rect:_mainView.bounds imageName:self.bgImgName backguoundColor:nil];
// NSInteger startY = _contentTop;
//
// _xiaohaoLab = [ControlCreator createLabel:_mainView rect:CGRectMake(_contentX, startY, 150, 14) text:@"" font:YBFont(13) color:color backguoundColor:nil align:NSTextAlignmentLeft lines:0];
//
// _chanchuLab = [ControlCreator createLabel:_mainView rect:CGRectMake(_contentX, _xiaohaoLab.bottom+10, 150, 14) text:@"" font:YBFont(13) color:color backguoundColor:nil align:NSTextAlignmentLeft lines:0];
//
// _biliLab = [ControlCreator createLabel:_mainView rect:CGRectMake(_contentX+150, startY, 150, 14) text:@"" font:YBFont(13) color:color backguoundColor:nil align:NSTextAlignmentLeft lines:0];
//
_ruleLabel = [ControlCreator createLabel:_mainView rect:CGRectMake(_contentX, self.contentTop, _mainView.width-_contentX*2, _mainH-(_chanchuLab.bottom+10)-_contentBottom) text:@"" font:YBFont(13) color:color backguoundColor:nil align:NSTextAlignmentLeft lines:0];
// _chanchuLab.hidden = _xiaohaoLab.hidden = _biliLab.hidden = YES;
// _ruleLabel.frame = CGRectMake(_contentX, startY, _mainView.width-_contentX*2, _mainH-startY-_contentBottom);
// [self getPoolTodayInfo];
// [self setupWebview];
}
- (void)backAction {
[self removeFromSuperview];
}
- (void)showOnView:(UIView *)parent WithType:(NSInteger)type {
self.poolType = type;
if (type == 4 || type == 5 || type == 6) {
CGFloat x = 0;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/375*500;
self.mainW = w;
self.mainH = h;
self.contentX = 30;
self.contentTop = 90;
self.contentBottom = 40;
self.bgImgName = @"zhuan_bg_rule";
}else if (type == 21) {
CGFloat x = 0;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/375*531;
self.mainW = w;
self.mainH = h;
self.contentX = 15;
self.contentTop = 100;
self.contentBottom = 24;
self.bgImgName = @"sec_zhuan_bg_rule";
}else if (type == 100) {
CGFloat x = 12;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/350*465;
self.mainW = w;
self.mainH = h;
self.contentX = 22;
self.contentTop = 100;
self.contentBottom = 25;
self.bgImgName = @"zxy_rule_bg";
}else if(type == 777){
CGFloat x = 0;
CGFloat w = ScreenWidth - x*2;
CGFloat h = w/375*580;
self.mainW = w;
self.mainH = h;
self.contentX = 30;
self.contentTop = 115;
self.contentBottom = 50;
self.bgImgName = @"stake_bg_rule";
}else {
CGFloat x = 0;
CGFloat w = ScreenWidth - x*2;
CGFloat h = w/375*480;
self.mainW = w;
self.mainH = h;
self.contentX = 15;
self.contentTop = 80;
self.contentBottom = 50;
self.bgImgName = @"bg_explore_rule";
}
[self initMainView];
[self getExplanation];
//动画前
[parent addSubview:self];
}
- (void)getExplanation {
NSDictionary *dict = @{@"type":[NSString stringWithFormat:@"%ld",self.poolType]};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
NSString *urlStr = @"/api/box/get_box_note";
if (self.poolType == 100) {
urlStr = @"/api/Sprite/get_monster_note";
}
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:urlStr parameters:paras response:^(RCMicHTTPResult *result) {
[SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSString.class]) {
self.ruleLabel.text = result.content;
[self.ruleLabel sizeToFit];
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
}
}];
}
- (void)getPoolTodayInfo {
NSDictionary *params = @{@"type":@(self.poolType)};
[RCMicHTTP postWithURLString:@"/api/box/get_user_box_count" parameters:params response:^(RCMicHTTPResult *result) {
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSDictionary.class]) {
self.xiaohaoLab.text = NSStringFormat(@"今日消耗:%d", [result.content safeIntForKey:@"out_amount"]);
self.chanchuLab.text = NSStringFormat(@"今日产出:%d", [result.content safeIntForKey:@"in_amount"]);
self.biliLab.text = NSStringFormat(@"产出比例:%@", [result.content safeStringForKey:@"rate"]);
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}
}];
}
- (void)setupWebview
{
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.userContentController = [[WKUserContentController alloc] init];
configuration.preferences = [[WKPreferences alloc] init];
configuration.preferences.minimumFontSize = 10;
configuration.preferences.javaScriptEnabled = YES;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, APPW, APPH) configuration:configuration];
_webView.backgroundColor = kClearColor;
_webView.scrollView.backgroundColor = kClearColor;
[_webView setValue:@NO forKey:@"WKCompositingView"];
[_webView setValue:[NSNumber numberWithBool:YES] forKey:@"drawsTransparentBackground"];
[self.mainView addSubview:_webView];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:[VERSION_HTTPS_SERVER stringByAppendingString:@"index.php/index/index/page_show?id=%d"],self.poolType+25]];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
[_webView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(30);
make.right.mas_equalTo(-30);
make.top.mas_equalTo(90);
make.bottom.mas_equalTo(-40);
}];
}
@end