123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- //
- // YOUPAILZPKDataView.m
- // TIANYAN
- //
- // Created by CY on 2021/6/1.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZPKDataView.h"
- #import "GGProgressView.h"
- @interface YOUPAILZPKDataView ()
- @property (nonatomic,weak) UIImageView *youpaipimgV1; // 赢家 or 输家
- @property (nonatomic,weak) UIImageView *youpaipimgV2; // 赢家 or 输家
- @property (nonatomic,weak) UIImageView *youpaiptimerBgV; // 倒计时背景
- @property (nonatomic,weak) UIImageView *youpaiptimerFrontImgV;
- @property (nonatomic,weak) UILabel *youpaiptimerL; // 倒计时
-
- @property (nonatomic,weak) GGProgressView *youpaipprogressView; // 进度条
- @property (nonatomic,weak) UILabel *youpaipweL; // 我方
- @property (nonatomic,weak) UILabel *youpaipenemyL; // 对方
- @property (nonatomic,weak) UIImageView *youpaipprogressImgV; // 进度
- @property (nonatomic,assign) NSInteger youpaippkTime; // pk剩余时长
- @property (nonatomic,assign) NSInteger youpaippunishTimer; // 惩罚剩余时长
- @property (nonatomic,strong) NSTimer *youpaiptimer; //计时器
- @end
- @implementation YOUPAILZPKDataView
- - (instancetype)initWithFrame:(CGRect)frame model:(YOUPAILZLiveModel *)model{
- if (self = [super initWithFrame:frame]) {
- _youpaipmodel = model;
- self.hidden = YES;
- self.youpaipisStartPK = NO;
- [self youpaifinitUI];
- self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(youpaifcountDown) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes];
- }
- return self;
- }
- - (void)youpaifinitUI{
- UIImageView *imgV1 = [[UIImageView alloc] init];
- imgV1.hidden = YES;
- [self addSubview:imgV1];
- self.youpaipimgV1 = imgV1;
- [imgV1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.top.offset(-21.0f);
- make.height.offset(48.0f);
- }];
-
- UIImageView *imgV2 = [[UIImageView alloc] init];
- imgV2.hidden = YES;
- [self addSubview:imgV2];
- self.youpaipimgV2 = imgV2;
- [imgV2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(0.0f);
- make.top.offset(-21.0f);
- make.height.offset(48.0f);
- }];
-
- UIImageView *youpaiptimerBgV = [[UIImageView alloc] init];
- youpaiptimerBgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_count_down_border"];
- [self addSubview:youpaiptimerBgV];
- self.youpaiptimerBgV = youpaiptimerBgV;
- [youpaiptimerBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.mas_centerX);
- make.top.offset(9.5f);
- make.size.mas_offset(CGSizeMake(100.0f, 21.0f));
- }];
-
- UIImageView *youpaiptimerFrontImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_L_live_pk_count_down_timer_front_pk"]];
- [youpaiptimerBgV addSubview:youpaiptimerFrontImgV];
- self.youpaiptimerFrontImgV = youpaiptimerFrontImgV;
- [youpaiptimerFrontImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(22.0f);
- make.centerY.equalTo(youpaiptimerBgV);
- make.size.mas_offset(CGSizeMake(21.0f, 17.0f));
- }];
-
- UILabel *youpaiptimerL = [[UILabel alloc] init];
- youpaiptimerL.text = @"00:00";
- youpaiptimerL.font = LCFont(10.0f);
- youpaiptimerL.textColor = [UIColor whiteColor];
- youpaiptimerL.textAlignment = NSTextAlignmentCenter;
- [youpaiptimerBgV addSubview:youpaiptimerL];
- self.youpaiptimerL = youpaiptimerL;
- [youpaiptimerL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaiptimerFrontImgV.mas_right).offset(5.0f);
- make.right.offset(-22.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- GGProgressView *progressView = [[GGProgressView alloc] initWithFrame:CGRectMake(5.0f, 33.0f, self.mj_w - 10.0f, 19.0f)];
- progressView.progress = 0.5f;
- progressView.progressTintColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth, 19.0f) FromColors:@[HexColorFromRGB(0xFC2F55),HexColorFromRGB(0xFF3BDC)] ByGradientType:GradientLeftToRight]];
- progressView.trackTintColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth, 19.0f) FromColors:@[HexColorFromRGB(0x69BCF8),HexColorFromRGB(0x274BE8)] ByGradientType:GradientLeftToRight]];
- progressView.layer.cornerRadius = 2.0f;
- progressView.clipsToBounds = YES;
- [self addSubview:progressView];
- self.youpaipprogressView = progressView;
-
- UILabel *weL = [[UILabel alloc] init];
- weL.text = @"我方 0";
- weL.font = LCFont(12.0f);
- weL.textColor = [UIColor whiteColor];
- [progressView addSubview:weL];
- self.youpaipweL = weL;
- [weL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(7.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- UILabel *youpaipenemyL = [[UILabel alloc] init];
- youpaipenemyL.text = @"0 对方";
- youpaipenemyL.font = LCFont(12.0f);
- youpaipenemyL.textColor = [UIColor whiteColor];
- [progressView addSubview:youpaipenemyL];
- self.youpaipenemyL = youpaipenemyL;
- [youpaipenemyL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-7.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- UIImageView *youpaipprogressImgV = [[UIImageView alloc] initWithFrame:CGRectMake((progressView.mj_w - 19.0f) / 2.0f, -6, 19.0f, 31.0f)];
- youpaipprogressImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_progress"];
- [progressView addSubview:youpaipprogressImgV];
- self.youpaipprogressImgV = youpaipprogressImgV;
- }
- - (void)youpaifreloadWithAttachment:(YOUPAILZLivePKDataAttachment *)attachment{
- self.youpaipattachment = attachment;
- NSInteger currentTime = [attachment.time integerValue];
- NSInteger pkEndTime = [attachment.pk_end_time integerValue];
- NSInteger punishEndTime = [attachment.punish_end_time integerValue];
- self.youpaippkTime = pkEndTime - currentTime;
- if (currentTime > pkEndTime) {
- self.youpaippunishTimer = punishEndTime - currentTime;
- }else{
- self.youpaippunishTimer = punishEndTime - pkEndTime;
- }
-
- NSInteger weNum = 0; // 我方
- NSInteger enemyNum = 0; // 对方
- if ([self.youpaipmodel.youpaipuser_info.youpaipuser_id isEqual:attachment.from_uid]) {
- weNum = [attachment.from_num integerValue];
- enemyNum = [attachment.to_num integerValue];
- }else{
- weNum = [attachment.to_num integerValue];
- enemyNum = [attachment.from_num integerValue];
- }
-
- if (self.youpaippkTime > 0) {
- self.youpaipisStartPK = YES;
- self.youpaiptimerFrontImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_count_down_timer_front_pk"];
- self.youpaiptimerL.text = [NSString stringWithFormat:@"%@",[self youpaiftimeFormatted:self.youpaippkTime]];
- self.youpaipimgV1.hidden = YES;
- self.youpaipimgV2.hidden = YES;
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStatePK);
- }
- if (self.showRePKBlock != nil) {
- self.showRePKBlock(NO);
- }
- if (self.showDrawBlock) {
- self.showDrawBlock(NO);
- }
- }else{
- self.youpaipimgV1.hidden = NO;
- self.youpaipimgV2.hidden = NO;
- if (self.showRePKBlock != nil && self.youpaipisStartPK) {
- self.showRePKBlock(YES);
- }
- }
- if (self.youpaippkTime <= 0 && self.youpaippunishTimer > 0) {
- self.youpaiptimerFrontImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_count_down_timer_front_chenfa"];
- self.youpaiptimerL.text = [NSString stringWithFormat:@"%@",[self youpaiftimeFormatted:self.youpaippunishTimer]];
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStatePunishment);
- }
- if (weNum == enemyNum && self.showDrawBlock) {
- self.showDrawBlock(YES);
- }
- }
- if (self.youpaippkTime <= 0 && self.youpaippunishTimer <= 0) {
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStateEnd);
- }
- if (self.showDrawBlock) {
- self.showDrawBlock(NO);
- }
- self.youpaipattachment = nil;
- self.hidden = YES;
- return;
- }
-
-
- self.youpaipweL.text = [NSString stringWithFormat:@"我方 %@",@(weNum)];
- self.youpaipenemyL.text = [NSString stringWithFormat:@"%@ 对方",@(enemyNum)];
- if (weNum == 0 && enemyNum == 0) {
- self.youpaipprogressView.progress = 0.5f;
- self.youpaipprogressImgV.frame = CGRectMake((self.youpaipprogressView.mj_w - 19.0f) / 2.0f, -6, 19.0f, 31.0f);
- }else{
- CGFloat total = (CGFloat)weNum + (CGFloat)enemyNum;
- CGFloat progress = weNum / total;
- self.youpaipprogressView.progress = progress;
- CGFloat x = self.youpaipprogressView.mj_w * progress - 9.0f;
- self.youpaipprogressImgV.frame = CGRectMake(x, -6, 19.0f, 31.0f);
- }
- if(weNum < enemyNum){
- self.youpaipimgV1.image = [UIImage imageNamed:@"vqu_images_L_live_pk_lose"];
- self.youpaipimgV2.image = [UIImage imageNamed:@"vqu_images_L_live_pk_win"];
- if (self.showDrawBlock) {
- self.showDrawBlock(NO);
- }
- }else if (weNum > enemyNum){
- self.youpaipimgV2.image = [UIImage imageNamed:@"vqu_images_L_live_pk_lose"];
- self.youpaipimgV1.image = [UIImage imageNamed:@"vqu_images_L_live_pk_win"];
- if (self.showDrawBlock) {
- self.showDrawBlock(NO);
- }
- }else{
- self.youpaipimgV1.hidden = YES;
- self.youpaipimgV2.hidden = YES;
-
- }
- }
- - (void)youpaifcountDown{
-
- NSInteger weNum = 0;
- NSInteger enemyNum = 0;
- if ([self.youpaipmodel.youpaipuser_info.youpaipuser_id isEqual:self.youpaipattachment.from_uid]) {
- weNum = [self.youpaipattachment.from_num integerValue];
- enemyNum = [self.youpaipattachment.to_num integerValue];
- }else{
- weNum = [self.youpaipattachment.to_num integerValue];
- enemyNum = [self.youpaipattachment.from_num integerValue];
- }
-
- if (self.youpaippkTime > 0) {
- self.youpaippkTime --;
- self.youpaiptimerFrontImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_count_down_timer_front_pk"];
- self.youpaiptimerL.text = [NSString stringWithFormat:@"%@",[self youpaiftimeFormatted:self.youpaippkTime]];
- self.youpaipimgV1.hidden = YES;
- self.youpaipimgV2.hidden = YES;
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStatePK);
- }
- if (self.showRePKBlock != nil) {
- self.showRePKBlock(NO);
- }
- }else{
- self.youpaipimgV1.hidden = NO;
- self.youpaipimgV2.hidden = NO;
- if (self.showRePKBlock != nil && self.youpaipisStartPK) {
- self.showRePKBlock(YES);
- }
- }
- if (self.youpaippkTime <= 0 && self.youpaippunishTimer > 0) {
- self.youpaippunishTimer --;
- self.youpaiptimerFrontImgV.image = [UIImage imageNamed:@"vqu_images_L_live_pk_count_down_timer_front_chenfa"];
- self.youpaiptimerL.text = [NSString stringWithFormat:@"%@",[self youpaiftimeFormatted:self.youpaippunishTimer]];
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStatePunishment);
- }
-
- if (self.showDrawBlock) {
- if (weNum == enemyNum) {
- self.showDrawBlock(self.youpaipattachment != nil);
- }else{
- self.showDrawBlock(NO);
- }
- }
-
- }
-
- if (self.youpaippkTime <= 0 && self.youpaippunishTimer <= 0) {
- if (self.currentPKStateBlock != nil) {
- self.currentPKStateBlock(LZLivePKStateEnd);
- }
- if (self.showDrawBlock) {
- self.showDrawBlock(NO);
- }
- self.youpaipattachment = nil;
- self.hidden = YES;
- return;
- }
-
-
-
- if(weNum < enemyNum){
- self.youpaipimgV1.image = [UIImage imageNamed:@"vqu_images_L_live_pk_lose"];
- self.youpaipimgV2.image = [UIImage imageNamed:@"vqu_images_L_live_pk_win"];
- }else if (weNum > enemyNum){
- self.youpaipimgV2.image = [UIImage imageNamed:@"vqu_images_L_live_pk_lose"];
- self.youpaipimgV1.image = [UIImage imageNamed:@"vqu_images_L_live_pk_win"];
- }else{
- self.youpaipimgV1.hidden = YES;
- self.youpaipimgV2.hidden = YES;
- }
- }
- - (NSString *)youpaiftimeFormatted:(NSInteger)totalSeconds{
- NSInteger seconds = totalSeconds % 60;
- NSInteger minutes = (totalSeconds / 60);
- return [NSString stringWithFormat:@"%02ld:%02ld", minutes, seconds];
- }
- - (void)dealloc{
- [self youpaifstopTimer];
- }
- - (void)youpaifstopTimer{
- [self.youpaiptimer invalidate];
- self.youpaiptimer = nil;
- }
- @end
|