252 lines
7.8 KiB
Objective-C
252 lines
7.8 KiB
Objective-C
//
|
|
// ZXYBoxView.m
|
|
// SweetParty
|
|
//
|
|
// Created by MAC on 2024/5/6.
|
|
//
|
|
|
|
#import "ZXYBoxView.h"
|
|
#import "ZWTimer.h"
|
|
#import "ZXYBoxModel.h"
|
|
#import "ZXYChooseNumView.h"
|
|
#import "ZXYBuyView.h"
|
|
#import "ZXYResultView.h"
|
|
#import "DDCaiMyRecordAlert.h"
|
|
#import "BJBoxRuleAlert.h"
|
|
#import "BJBoxPoolAlert.h"
|
|
#import "ZXYRankView.h"
|
|
|
|
@interface ZXYBoxView () <ZWTimerDelegate>
|
|
|
|
@property (weak, nonatomic) IBOutlet UIImageView *touchImgV;
|
|
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
|
|
@property (weak, nonatomic) IBOutlet UILabel *ticketLab;
|
|
@property (weak, nonatomic) IBOutlet UIImageView *timeBgImgV;
|
|
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
|
|
@property (weak, nonatomic) IBOutlet UIView *yueqiView_1;
|
|
@property (weak, nonatomic) IBOutlet UIView *yueqiView_2;
|
|
@property (weak, nonatomic) IBOutlet UIView *yueqiView_3;
|
|
@property (weak, nonatomic) IBOutlet UIView *yueqiView_4;
|
|
@property (weak, nonatomic) IBOutlet UIView *yueqiView_5;
|
|
@property (weak, nonatomic) IBOutlet UILabel *numLab_1;
|
|
@property (weak, nonatomic) IBOutlet UILabel *numLab_2;
|
|
@property (weak, nonatomic) IBOutlet UILabel *numLab_3;
|
|
@property (weak, nonatomic) IBOutlet UILabel *numLab_4;
|
|
@property (weak, nonatomic) IBOutlet UILabel *numLab_5;
|
|
|
|
@property (nonatomic, strong) NSArray *currentLabArr;
|
|
|
|
@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) ZXYResultView *resultView;
|
|
|
|
@property (nonatomic, assign) BOOL isSecondLoad;
|
|
|
|
@end
|
|
|
|
@implementation ZXYBoxView
|
|
|
|
- (void)dealloc {
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
|
|
self.currentLabArr = @[_numLab_1, _numLab_2, _numLab_3, _numLab_4, _numLab_5];
|
|
|
|
[self createUI];
|
|
|
|
[self fetchData];
|
|
}
|
|
|
|
- (void)createUI {
|
|
WEAK_SELF
|
|
[self.touchImgV dg_Tapped:^{
|
|
[weakSelf removeFromSuperview];
|
|
}];
|
|
|
|
//中奖类型 1吉他2小提琴3古筝4架子鼓5钢琴
|
|
[self.yueqiView_1 dg_Tapped:^{
|
|
[weakSelf onPopChooseNum:1];
|
|
}];
|
|
[self.yueqiView_2 dg_Tapped:^{
|
|
[weakSelf onPopChooseNum:2];
|
|
}];
|
|
[self.yueqiView_3 dg_Tapped:^{
|
|
[weakSelf onPopChooseNum:3];
|
|
}];
|
|
[self.yueqiView_4 dg_Tapped:^{
|
|
[weakSelf onPopChooseNum:4];
|
|
}];
|
|
[self.yueqiView_5 dg_Tapped:^{
|
|
[weakSelf onPopChooseNum:5];
|
|
}];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketStart:) name:@"ZXYStartNoti" object:nil];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketEnd:) name:@"ZXYEndNoti" object:nil];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSocketResult:) name:@"ZXYResultNoti" object:nil];
|
|
}
|
|
|
|
- (void)onSocketStart:(NSNotification *)noti {
|
|
NSDictionary *dataDict = noti.userInfo;
|
|
ZXYBoxModel *model = [ZXYBoxModel mj_objectWithKeyValues:dataDict];
|
|
self.timerType = 1;
|
|
self.leftSecond = model.surplus_time;
|
|
[self.timer startGCDTimer:1 delegate:self];
|
|
|
|
//重置当前架数
|
|
for (UILabel *currentLab in self.currentLabArr) {
|
|
currentLab.text = @"0";
|
|
}
|
|
self.resultDict = nil;
|
|
self.timeBgImgV.image = ImageNamed(@"zxy_time_bg");
|
|
}
|
|
|
|
- (void)onSocketEnd:(NSNotification *)noti {
|
|
NSDictionary *dataDict = noti.userInfo;
|
|
ZXYBoxModel *model = [ZXYBoxModel 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) {
|
|
[self onFeichuanAnimate:1 model:model];
|
|
}
|
|
});
|
|
}
|
|
|
|
- (void)onSocketResult:(NSNotification *)noti {
|
|
NSDictionary *dataDict = noti.userInfo;
|
|
NSLog(@"抽奖结果--%@", dataDict);
|
|
self.resultDict = dataDict;
|
|
ZXYBoxModel *model = [ZXYBoxModel mj_objectWithKeyValues:dataDict];
|
|
if (model.is_win == 1) {
|
|
[self onFeichuanAnimate:2 model:model];
|
|
}else {
|
|
[self onFeichuanAnimate:3 model:model];
|
|
}
|
|
//更新门票余额
|
|
self.ticketLab.text = model.airship;
|
|
}
|
|
|
|
- (void)onFeichuanAnimate:(NSInteger)type model:(ZXYBoxModel *)model {
|
|
//探险中,飞机动画后弹出结果页
|
|
self.timerType = 2;
|
|
self.leftSecond = 10;
|
|
[self.timer startGCDTimer:1 delegate:self];
|
|
|
|
[self addSubview:self.resultView];
|
|
[self.resultView onShowWith:type model:model];
|
|
}
|
|
|
|
- (void)onPopChooseNum:(NSInteger)type {
|
|
ZXYChooseNumView *view = LoadNib(@"ZXYChooseNumView");
|
|
view.frame = [UIScreen mainScreen].bounds;
|
|
[self addSubview:view];
|
|
[view onUpdateWith:type rid:self.rid];
|
|
view.onConfirmBlock = ^() {
|
|
[self fetchData];
|
|
};
|
|
}
|
|
|
|
//打开宝箱请求信息
|
|
- (void)fetchData {
|
|
NSDictionary *params = @{};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/Sprite/get_monster_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
|
|
ZXYBoxModel *model = [ZXYBoxModel mj_objectWithKeyValues:responseDic[@"data"]];
|
|
[self onUpdateCommonInfo:model];
|
|
[self onUpdateNumUI:model];
|
|
|
|
self.isSecondLoad = YES;
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)onUpdateCommonInfo:(ZXYBoxModel *)model {
|
|
self.moneyLab.text = [NSString stringWithFormat:@"%ld", [model.integral integerValue]];
|
|
self.ticketLab.text = model.airship;
|
|
|
|
if (self.isSecondLoad == NO) {
|
|
self.timerType = 1;
|
|
self.leftSecond = model.surplus_time;
|
|
[self.timer startGCDTimer:1 delegate:self];
|
|
}
|
|
}
|
|
|
|
- (void)onUpdateNumUI:(ZXYBoxModel *)model {
|
|
for (NSInteger i = 0; i < model.multiple_list.count; i++) {
|
|
NSDictionary *dict = model.multiple_list[i];
|
|
UILabel *currentLab = self.currentLabArr[i];
|
|
currentLab.text = [dict safeStringForKey:@"num"];
|
|
}
|
|
}
|
|
|
|
- (void)onTimerFired:(ZWTimer *)timer {
|
|
self.leftSecond -= 1;
|
|
if (self.leftSecond < 0) {
|
|
self.leftSecond = 0;
|
|
[self.timer stopTimer];
|
|
}
|
|
// if (self.timerType == 1) {
|
|
self.timeLab.text = [NSString stringWithFormat:@"%02ld:%02ld", self.leftSecond/60, self.leftSecond%60];
|
|
// }else if (self.timerType == 2) {
|
|
// self.timeLab.text = [NSString stringWithFormat:@"弹奏中%02lds", self.leftSecond%60];
|
|
// }
|
|
if (self.leftSecond <= 5) {
|
|
self.timeBgImgV.image = ImageNamed(@"zxy_time_bg_2");
|
|
}
|
|
}
|
|
|
|
- (ZWTimer *)timer {
|
|
if (!_timer) {
|
|
_timer = [[ZWTimer alloc] init];
|
|
}
|
|
return _timer;
|
|
}
|
|
|
|
- (IBAction)onBuyTicket:(id)sender {
|
|
ZXYBuyView *view = LoadNib(@"ZXYBuyView");
|
|
view.frame = [UIScreen mainScreen].bounds;
|
|
[self addSubview:view];
|
|
view.rid = self.rid;
|
|
view.onBuySuccessBlock = ^(NSString * _Nonnull integral, NSString * _Nonnull airship) {
|
|
self.moneyLab.text = [NSString stringWithFormat:@"%ld", [integral integerValue]];
|
|
self.ticketLab.text = airship;
|
|
};
|
|
}
|
|
|
|
- (IBAction)onPool:(id)sender {
|
|
BJBoxPoolAlert *view = [[BJBoxPoolAlert alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
[view showOnView:self WithType:100];
|
|
}
|
|
|
|
- (IBAction)onRule:(id)sender {
|
|
BJBoxRuleAlert *view = [[BJBoxRuleAlert alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
[view showOnView:self WithType:100];
|
|
}
|
|
|
|
- (IBAction)onRecord:(id)sender {
|
|
DDCaiMyRecordAlert *view = [[DDCaiMyRecordAlert alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
[view showOnView:self];
|
|
}
|
|
|
|
- (IBAction)onRank:(id)sender {
|
|
ZXYRankView *view = [[ZXYRankView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
[view showOnView:self];
|
|
}
|
|
|
|
- (ZXYResultView *)resultView {
|
|
if (!_resultView) {
|
|
_resultView = LoadNib(@"ZXYResultView");
|
|
_resultView.frame = [UIScreen mainScreen].bounds;
|
|
}
|
|
return _resultView;
|
|
}
|
|
|
|
@end
|