Files
yuyin_ios/SweetParty/主类/音悦新增/炼仙传说/WL_StakeView.m

531 lines
18 KiB
Mathematica
Raw Normal View History

2025-08-08 11:05:33 +08:00
//
// QY_ZhuanPanView.m
// QiaoYuYueWan
//
// Created by on 2020/10/19.
// Copyright © 2020 QiaoYuYueWan. All rights reserved.
//
#import "WL_StakeView.h"
//#import "AwardModel.h"
#import "BJBoxPoolAlert.h"
#import "BJBoxRankAlert.h"
#import "BJBoxRuleAlert.h"
#import "BJBoxRecordAlert.h"
#import "BJBoxResultAlert.h"
#import "BJBoxAwardModel.h"
#import "BJRoomGiftModel.h"
#import "ZWTimer.h"
#import "WLStakeAlertView.h"
#import "WLStakeModel.h"
#import "WLStakeRecordAlert.h"
#import "WLStakeResultFailureView.h"
#import "WLStakeResultSuccessView.h"
#import "QGVAPWrapView.h"
#import "QGVAPWrapView+download.h"
@interface WL_StakeView ()<SVGAPlayerDelegate, ZWTimerDelegate, HWDMP4PlayDelegate, VAPWrapViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UIImageView *bgImgV;
@property (weak, nonatomic) IBOutlet UILabel *ticketNumLab;
@property (weak, nonatomic) IBOutlet UILabel *unitPriceLabel;
@property (nonatomic, strong) RCMicRoomViewModel *viewModel;
@property(nonatomic, assign) NSInteger boxType;
@property (nonatomic, strong) WLStakeResultSuccessView * successView;
@property (nonatomic, strong) WLStakeResultFailureView * failureView;
@property(nonatomic, strong) NSArray *listModel; /**/
@property(nonatomic, assign) NSInteger coin_value_1;
@property(nonatomic, assign) NSInteger coin_value_2;
@property(nonatomic, assign) NSInteger coin_value_3;
@property (weak, nonatomic) IBOutlet UIButton *jiangchiBtn;
@property (weak, nonatomic) IBOutlet UIButton *rankBtn;
@property (weak, nonatomic) IBOutlet UIButton *guizeBtn;
@property (weak, nonatomic) IBOutlet UIButton *jiluBtn;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn1;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn2;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn3;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn4;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn5;
@property (weak, nonatomic) IBOutlet UIButton *itemBtn6;
@property (weak, nonatomic) IBOutlet UIView *vapBackView1;
@property (weak, nonatomic) IBOutlet UIView *vapBackView2;
@property (weak, nonatomic) IBOutlet UIView *vapBackView3;
@property (weak, nonatomic) IBOutlet UIView *vapBackView4;
@property (weak, nonatomic) IBOutlet UIView *vapBackView5;
@property (weak, nonatomic) IBOutlet UIView *vapBackView6;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel1;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel2;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel3;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel4;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel5;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel6;
@property (weak, nonatomic) IBOutlet UILabel *numLabel1;
@property (weak, nonatomic) IBOutlet UILabel *numLabel2;
@property (weak, nonatomic) IBOutlet UILabel *numLabel3;
@property (weak, nonatomic) IBOutlet UILabel *numLabel4;
@property (weak, nonatomic) IBOutlet UILabel *numLabel5;
@property (weak, nonatomic) IBOutlet UILabel *numLabel6;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel1;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel2;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel3;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel4;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel5;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel6;
@property (weak, nonatomic) IBOutlet UIImageView *selBg1;
@property (weak, nonatomic) IBOutlet UIImageView *selBg3;
@property (weak, nonatomic) IBOutlet UIImageView *selBg4;
@property (weak, nonatomic) IBOutlet UIImageView *selBg5;
@property (weak, nonatomic) IBOutlet UIImageView *selBg6;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (nonatomic, strong) ZWTimer *timer;
@property (nonatomic, assign) NSInteger leftSecond;
@property (nonatomic, assign) NSInteger timerType;//1 2
@property (nonatomic, strong) NSDictionary *resultDict;
@property (nonatomic, strong) NSArray *touruNumArr;
@property (nonatomic, strong) NSArray <UILabel *>*numLabArr;
@property (nonatomic, strong) NSArray <UILabel *>*nameLabArr;
@property (nonatomic, strong) NSArray <UILabel *>*levelLabArr;
@property (nonatomic, strong) NSArray <UIView *>*vapBackViewArr;
@property (nonatomic, strong) NSArray <UIButton *>*itemBtnArr;
@property (nonatomic, strong) NSArray <WLStakeMultipleModel *>*xingqiuDataArray;
@property (nonatomic, strong) NSArray <UIImageView *>*selBgArr;
@property (nonatomic, copy) NSString *unitPrice;
@property (nonatomic, copy) NSString *remainPrice;
@property (weak, nonatomic) IBOutlet UILabel *balanceL; //
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeLabelTop;
@end
@implementation WL_StakeView
+ (WL_StakeView *)initBoxWith:(RCMicRoomViewModel *)model {
WL_StakeView *view = LoadNib(NSStringFromClass(WL_StakeView.class));
view.frame = UIScreen.mainScreen.bounds;
view.backgroundColor = HEXCOLORA(0x000000, 0.3);
view.viewModel = model;
[view initSubView];
return view;
}
- (void)updateModel:(RCMicRoomViewModel *)model {
self.viewModel = model;
[self initSubView];
}
- (void)initSubView {
self.boxType = 777;
//y
self.timeLabelTop.constant = APPW / 375 * 600 / 3;
self.numLabArr = @[_numLabel1, _numLabel2, _numLabel3, _numLabel4, _numLabel5, _numLabel6];
self.nameLabArr = @[_nameLabel1,_nameLabel2,_nameLabel3,_nameLabel4,_nameLabel5,_nameLabel6];
self.levelLabArr = @[_levelLabel1, _levelLabel2, _levelLabel3, _levelLabel4, _levelLabel5, _levelLabel6];
self.itemBtnArr = @[_itemBtn1, _itemBtn2, _itemBtn3, _itemBtn4, _itemBtn5, _itemBtn6];
self.touruNumArr = @[@(0), @(0), @(0), @(0), @(0), @(0)];
// self.selBgArr = @[_selBg4, _selBg1, _selBg5, _selBg3, _selBg6];
// self.vapBackViewArr = @[_vapBackView4, _vapBackView1, _vapBackView5, _vapBackView3, _vapBackView6];
WEAK_SELF
[self.itemBtn1 dg_Tapped:^{
NSNumber *num = self.touruNumArr[0];
[weakSelf onPopChooseNum:1 num:num.integerValue];
}];
[self.itemBtn2 dg_Tapped:^{
NSNumber *num = self.touruNumArr[1];
[weakSelf onPopChooseNum:2 num:num.integerValue];
}];
[self.itemBtn3 dg_Tapped:^{
NSNumber *num = self.touruNumArr[2];
[weakSelf onPopChooseNum:3 num:num.integerValue];
}];
[self.itemBtn4 dg_Tapped:^{
NSNumber *num = self.touruNumArr[3];
[weakSelf onPopChooseNum:4 num:num.integerValue];
}];
[self.itemBtn5 dg_Tapped:^{
NSNumber *num = self.touruNumArr[4];
[weakSelf onPopChooseNum:5 num:num.integerValue];
}];
[self.itemBtn6 dg_Tapped:^{
NSNumber *num = self.touruNumArr[6];
[weakSelf onPopChooseNum:6 num:num.integerValue];
}];
// [self.itemBtn2 dg_Tapped:^{
// NSNumber *num = self.touruNumArr[5];
// [weakSelf onPopChooseNum:6 num:num.integerValue];
// }];
// NSArray *resourceArr = @[@"西路财神", @"北路财神", @"南路财神", @"东路财神", @"中路财神"];
//
// for (int i = 0; i < _vapBackViewArr.count; i++) {
// QGVAPWrapView *vapView = [[QGVAPWrapView alloc] initWithFrame:CGRectZero];
// if (i==4) {
// vapView.frame = CGRectMake(0, 0, 125, 125);
// }else {
// vapView.frame = CGRectMake(0, 0, 85, 85);
// }
// UIView *view = _vapBackViewArr[i];
// vapView.hwd_Delegate = self;
// vapView.contentMode = QGVAPWrapViewContentModeScaleToFill;
// vapView.userInteractionEnabled = YES;
// [view addSubview:vapView];
// NSString *path = [[NSBundle mainBundle] pathForResource:resourceArr[i] ofType:@"mp4"];
// [vapView playHWDMP4:path repeatCount:-1 delegate:self];
// }
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketStart:) name:@"XJTXStartNoti" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketEnd:) name:@"XJTXEndNoti" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketResult:) name:@"XJTXResultNoti" object:nil];
[self fetchData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)fetchData {
NSDictionary *params = @{};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/monster/get_monster_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
WLStakeModel *model = [WLStakeModel mj_objectWithKeyValues:responseDic[@"data"]];
self.unitPrice = model.open_monster_price;
self.remainPrice = model.integral;
self.balanceL.text = [NSString stringWithFormat:@"%@", model.integral];
self.unitPriceLabel.text = [NSString stringWithFormat:@"%@金币/次", model.open_monster_price];
self.xingqiuDataArray = model.multiple_list;
[self onUpdateCommonInfo:model];
[self onUpdateNumUI:model];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onStake:(NSInteger)type num:(NSInteger)num {
NSDictionary *params = @{@"rid":C_string(self.rid),
@"type": @(type),
@"num": @(num)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/monster/open_beat_monster" Loading:YES Hud:NO Success:^(id _Nonnull responseDic) {
WLStakeModel *model = [WLStakeModel mj_objectWithKeyValues:responseDic[@"data"]];
self.balanceL.text = [NSString stringWithFormat:@"%@", model.integral];
[self onUpdateCurrentNumUI:model];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onUpdateCommonInfo:(WLStakeModel *)model {
self.timerType = 1;
self.leftSecond = model.surplus_time;
[self.timer startGCDTimer:1 delegate:self];
}
- (void)onUpdateNumUI:(WLStakeModel *)model {
[self.xingqiuDataArray enumerateObjectsUsingBlock:^(WLStakeMultipleModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self.itemBtnArr enumerateObjectsUsingBlock:^(UIButton * _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.type == idx + 1) {
btn.selected = YES;
}
}];
[self.numLabArr enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.type == idx + 1) {
label.text = [NSString stringWithFormat:@"已投入:%ld", (long)obj.num];
}
}];
[self.nameLabArr enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.type == idx + 1) {
label.text = obj.type_name;
}
}];
[self.levelLabArr enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.type == idx + 1) {
label.text = [NSString stringWithFormat:@"x%@倍", [self formatFloat:obj.multiple]];
}
}];
// [self.selBgArr enumerateObjectsUsingBlock:^(UIImageView * _Nonnull selBg, NSUInteger idx, BOOL * _Nonnull stop) {
// if (obj.type == idx + 1) {
// selBg.hidden = model.num == 0;
// }
//
//// selBg.hidden = obj.type != idx + 1;
// }];
}];
}
- (NSString *)formatFloat:(float)f
{
if (fmodf(f, 1)==0) {//
return [NSString stringWithFormat:@"%.0f",f];
} else if (fmodf(f*10, 1)==0) {//
return [NSString stringWithFormat:@"%.1f",f];
} else {
return [NSString stringWithFormat:@"%.2f",f];
}
}
- (void)onUpdateCurrentNumUI:(WLStakeModel *)model {
[self.itemBtnArr enumerateObjectsUsingBlock:^(UIButton * _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
if (model.type == idx + 1) {
btn.selected = YES;
}
}];
[self.numLabArr enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) {
if (model.type == idx + 1) {
label.text = [NSString stringWithFormat:@"已投入:%ld", (long)model.num];
}
}];
// [self.selBgArr enumerateObjectsUsingBlock:^(UIImageView * _Nonnull selBg, NSUInteger idx, BOOL * _Nonnull stop) {
// if (model.type == idx + 1) {
// selBg.hidden = model.num == 0;
// }
//// selBg.hidden = model.type != idx + 1;
// }];
}
- (void)onSocketStart:(NSNotification *)noti {
[self.failureView remove];
[self.successView remove];
NSDictionary *dataDict = noti.userInfo;
WLStakeModel *model = [WLStakeModel mj_objectWithKeyValues:dataDict];
self.xingqiuDataArray = model.multiple_list;
self.timerType = 1;
self.leftSecond = model.surplus_time;
[self.timer startGCDTimer:1 delegate:self];
self.resultDict = nil;
[self onUpdateCommonInfo:model];
[self onUpdateNumUI:model];
[self.selBgArr enumerateObjectsUsingBlock:^(UIImageView * _Nonnull selBg, NSUInteger idx, BOOL * _Nonnull stop) {
selBg.hidden = YES;
}];
}
- (void)onSocketEnd:(NSNotification *)noti {
NSDictionary *dataDict = noti.userInfo;
NSLog(@"onSocketEnd--%@", dataDict);
WLStakeModel *model = [WLStakeModel mj_objectWithKeyValues:dataDict];
// //0.2
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.resultDict == nil) {
//
if (model.is_finsh == 3) {
self.timeLabel.text = @"未开放";
}
}
});
}
- (void)onSocketResult:(NSNotification *)noti {
NSDictionary *dataDict = noti.userInfo;
NSLog(@"抽奖结果--%@", dataDict);
if (self.resultDict == nil) {
self.resultDict = dataDict;
WLStakeModel *model = [WLStakeModel mj_objectWithKeyValues:dataDict];
if (model.is_win == 1) {
[self.selBgArr enumerateObjectsUsingBlock:^(UIImageView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.hidden = [model.win_type integerValue] != idx + 1;
}];
[self onPopSuccessView:model];
}else {
[self onPopFailureView:model];
}
}
}
- (void)onTimerFired:(ZWTimer *)timer {
self.leftSecond -= 1;
if (self.leftSecond < 0) {
self.leftSecond = 0;
[self.timer stopTimer];
}
if (self.timerType == 1) {
self.timeLabel.text = [NSString stringWithFormat:@"倒计时:%02ld:%02ld", self.leftSecond/60, self.leftSecond%60];
}else if (self.timerType == 2) {
// self.timeLabel.text = [NSString stringWithFormat:@"%@%02lds", MNLOCAL(@"探险中"), self.leftSecond%60];
self.timeLabel.text = @"倒计时:00:00";
}
}
- (void)onPopSuccessView:(WLStakeModel *)model {
[self.successView onPopupWithSize:CGSizeMake(APPW, 403) parent:self model:model];
}
- (void)onPopFailureView:(WLStakeModel *)model {
[self.failureView remove];
[self.failureView onPopupWithSize:CGSizeMake(375, 320) model:model];
}
- (void)onPopChooseNum:(NSInteger)type num:(NSInteger)num {
WLStakeAlertView *view = LoadNib(@"WLStakeAlertView");
view.unitPrice = self.unitPrice;
view.remainPrice = self.remainPrice;
view.type = [NSString stringWithFormat:@"%ld", type];
// [view onPopupWithSize:CGSizeMake(375, 812)];
[view show];
WEAK_SELF
view.onConfirmBlock = ^(NSInteger num) {
[weakSelf onStake:type num:num];
// [weakSelf loadData];
};
}
#pragma mark - public
- (void)showOnView:(nullable UIView *)parent {
if (parent) {
[parent addSubview:self];
}else {
[MainWindow() addSubview:self];
}
}
#pragma mark - 4
- (void)buttonClickMethod:(NSInteger)tag {
switch (tag) {
case 600:{
//
BJBoxRuleAlert *view = [[BJBoxRuleAlert alloc] initWithFrame:UIScreen.mainScreen.bounds];
[view showOnView:UIViewController.currentViewController.view WithType:_boxType];
}break;
case 601:{
BJBoxPoolAlert *view = [[BJBoxPoolAlert alloc] initWithFrame:CGRectZero];
[view showOnView:UIViewController.currentViewController.view WithType:_boxType];
}break;
case 602:{
//
WLStakeRecordAlert *view = [[WLStakeRecordAlert alloc] initWithFrame:CGRectZero];
view.frame = UIScreen.mainScreen.bounds;
[view showOnView:UIViewController.currentViewController.view];
}break;
case 603:{
BJBoxRankAlert *view = [[BJBoxRankAlert alloc] initWithFrame:CGRectZero];
[view showOnView:UIViewController.currentViewController.view roomId:_viewModel.roomInfo.roomId WithType:_boxType];
}break;
default:
break;
}
}
//
- (IBAction)closeMethod:(id)sender {
[self removeFromSuperview];
}
//
- (IBAction)shuomingMethod:(id)sender {
[self buttonClickMethod:600];
}
//
- (IBAction)zhongJiangJiLuMethod:(id)sender {
[self buttonClickMethod:602];
}
//
- (IBAction)shouqiBangMethod:(id)sender {
[self buttonClickMethod:603];
}
//
- (IBAction)benQiJiangChiMethod:(id)sender {
[self buttonClickMethod:601];
}
#pragma mark ====================== ======================
//- (BJBoxResultAlert *)resultView{
// if (!_resultView) {
// _resultView = [[BJBoxResultAlert alloc] initWithFrame:CGRectZero];
// WEAK_SELF
// _resultView.refreshCoinBlock = ^{
// [weakSelf loadData];
// };
// _resultView.tryAgainBlock = ^{
// weakSelf.resultView.hidden = YES;
// //TODO:
//
// };
// }
// return _resultView;
//}
- (WLStakeResultSuccessView *)successView {
if (!_successView) {
_successView = LoadNib(@"WLStakeResultSuccessView");
}
return _successView;
}
- (WLStakeResultFailureView *)failureView {
if (!_failureView) {
_failureView = LoadNib(@"WLStakeResultFailureView");
WEAK_SELF
_failureView.onConfirmBlock = ^() {
//
};
}
return _failureView;
}
- (ZWTimer *)timer {
if (!_timer) {
_timer = [[ZWTimer alloc] init];
}
return _timer;
}
@end