Files
peko-ios/YuMi/Modules/YMRoom/View/AcrossRoomPK/View/SubViews/XPAcrossRoomPKPanelView.m

1041 lines
39 KiB
Objective-C

//
// YMAcrpssRoomPKPanelView.m
// YUMI
//
// Created by YUMI on 2022/1/11.
//
#import "XPAcrossRoomPKPanelView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NetImageView.h"
#import "YUMIMacroUitls.h"
#import "UIImage+Utils.h"
#import "UIButton+EnlargeTouchArea.h"
#import "Timestamp.h"
#import "NSArray+Safe.h"
///Model
#import "UserInfoModel.h"
#import "AcrossRoomPKPanelModel.h"
///View
#import "XPAcrossRoomPKPanelUserView.h"
static CGFloat MaxHeight = 285.5;
static CGFloat MiniHeight = 130.5;
@interface XPAcrossRoomPKPanelView ()
///背景
@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) UIImageView *backgroundImageView_small;
#pragma mark - 规则的view
///帮助按钮
@property (nonatomic, strong) UIButton *helpButton;
///规则背景
@property (nonatomic, strong) UIImageView *ruleBgImageView;
///规则
@property (nonatomic, strong) SZTextView *ruleTextView;
///显示倒计时
@property (nonatomic, strong) UILabel *timeLabel;
///最大的容器
@property (nonatomic,strong) UIStackView *stackView;
#pragma mark - 队伍的view
///队伍的容器
@property (nonatomic,strong) UIView * teamContainerView;
///红队厅名
@property (nonatomic, strong) UILabel *redTitleLabel;
/// 红队头像
@property (nonatomic, strong) NetImageView *redAvatarImageView;
/// 助攻
@property (nonatomic, strong) UIButton *assistButton;
///蓝队厅名
@property (nonatomic, strong) UILabel *blueTitleLabel;
/// 蓝队头像
@property (nonatomic, strong) NetImageView *blueAvatarImageView;
/// 去围观
@property (nonatomic, strong) UIButton *onLookButton;
#pragma mark -进度条内容
///PK最外面的容器
@property (nonatomic, strong) UIView *progressView;
///红方的进度图片
@property (nonatomic, strong) UIImageView *redCountImageView;
///红方的礼物值
@property (nonatomic, strong) UILabel *redCountLabel;
///动画管理类
@property (strong, nonatomic) SVGAParser *parser;
///中间进度的动画
//@property (nonatomic, strong) SVGAImageView *svgDisplayView;
@property (nonatomic, strong) UIImageView *fireImageView;
///蓝方的进度图片
@property (nonatomic, strong) UIImageView *blueCountImageView;
///蓝方的礼物值
@property (nonatomic, strong) UILabel *blueCountLabel;
#pragma mark - 展开更多
///展开
@property (nonatomic,strong) UIButton *foldButton;
#pragma mark - 队伍的队友的view
///
@property (nonatomic,strong) UIStackView *userStackView;
///贡献的容器
@property (nonatomic,strong) UIStackView *contributeStackView;
///红方的贡献用户容器
@property (nonatomic,strong) UIStackView *redContributeStackView;
///蓝方的贡献用户容器
@property (nonatomic,strong) UIStackView *blueContributeStackView;
///魅力的容器
@property (nonatomic,strong) UIStackView *charmStackView;
///红方的魅力用户容器
@property (nonatomic,strong) UIStackView *redCharmStackView;
///蓝方的魅力用户容器
@property (nonatomic,strong) UIStackView *blueCharmStackView;
///倒计时
@property (strong, nonatomic) dispatch_source_t timer;
@property (nonatomic, assign) CGPoint centerCenter;
@end
@implementation XPAcrossRoomPKPanelView
#pragma mark - life cycle
- (void)dealloc {
NSLog(@"销毁了");
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:CGRectMake(0, 0, kGetScaleWidth(310), kGetScaleWidth(MaxHeight))]) {
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(changeLocation:)];
// 这里的delaysTouchesBegan属性很明显就是对touchBegin方法是否进行延迟,
// YES表示延迟,即在系统未识别出来手势为什么手势时先不要调用touchesBegan 方法;
// NO表示不延迟,即在系统未识别出来手势为什么手势时会先调用touchesBegan 方法;
pan.delaysTouchesBegan = YES;
[self addGestureRecognizer:pan];
}
return self;
}
- (void)startInitUI {
[self initSubViews];
[self initSubViewConstraints];
for (id view in self.ruleTextView.subviews) {
if ([view isKindOfClass:[UITextView class]]){
UITextView *textView = view;
textView.textAlignment = NSTextAlignmentLeft;
break;
}
}
}
#pragma mark - Public Method
- (void)resetAcrossPKViewData {
if (self.timer) {
dispatch_source_cancel(self.timer);
self.timer = nil;
}
self.pkPanelInfo = nil;
}
#pragma mark - Private Method
- (void)setupBackground {
if (self.backgroundImageView.superview) {
return;
}
[self addSubview:self.backgroundImageView];
[self addSubview:self.backgroundImageView_small];
UIImageView *topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pk_background_top"]];
topImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:topImageView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.backgroundImageView_small mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self);
make.height.mas_equalTo(kGetScaleWidth(MiniHeight));
}];
[topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.centerY.mas_equalTo(self.mas_top).offset(7);
make.width.mas_equalTo(180);
make.height.mas_equalTo(32);
}];
UIView *pkTimeContent = [[UIView alloc] init];
[self addSubview:pkTimeContent];
[pkTimeContent mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(topImageView);
}];
UIImageView *pkMarkIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pk_mark_icon"]];
[pkTimeContent addSubview:pkMarkIcon];
[pkTimeContent addSubview:self.timeLabel];
[pkMarkIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.leading.mas_equalTo(pkTimeContent);
make.size.mas_equalTo(CGSizeMake(30, 13));
}];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(pkTimeContent);
make.leading.mas_equalTo(pkMarkIcon.mas_trailing).offset(4);
make.trailing.mas_equalTo(pkTimeContent);
}];
[self addSubview:self.helpButton];
[self.helpButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-14);
make.top.mas_equalTo(12);
make.width.height.mas_equalTo(16);
}];
}
- (void)setupBattleArea {
[self addSubview:self.stackView];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.backgroundImageView).offset(34);
make.leading.trailing.mas_equalTo(self);
make.height.mas_equalTo(88);
}];
[self.stackView addArrangedSubview:self.teamContainerView];
[self.teamContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.top.leading.trailing.mas_equalTo(self.stackView);
}];
[self.teamContainerView addSubview:self.redTitleLabel];
[self.teamContainerView addSubview:self.blueTitleLabel];
[self.redTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(10);
make.top.mas_equalTo(self.teamContainerView);
}];
[self.blueTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.teamContainerView);
make.trailing.mas_equalTo(-10);
}];
UIImageView *vsMark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pk_vs_icon"]];
[self.teamContainerView addSubview:vsMark];
[vsMark mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.teamContainerView);
make.top.mas_equalTo(self.redTitleLabel.mas_bottom).offset(4.5);
make.size.mas_equalTo(CGSizeMake(40, 20));
}];
[self.teamContainerView addSubview:self.redAvatarImageView];
[self.teamContainerView addSubview:self.blueAvatarImageView];
[self.redAvatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(10);
make.width.height.mas_equalTo(44);
make.top.mas_equalTo(self.redTitleLabel.mas_bottom).offset(12);
}];
[self.blueAvatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-10);
make.width.height.mas_equalTo(44);
make.top.mas_equalTo(self.blueTitleLabel.mas_bottom).offset(12);
}];
// [self.teamContainerView insertSubview:self.progressView belowSubview:self.redAvatarImageView];
[self.teamContainerView addSubview:self.progressView];
[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.redAvatarImageView.mas_trailing).offset(-2);
make.trailing.mas_equalTo(self.blueAvatarImageView.mas_leading).offset(2);
make.height.mas_equalTo(15);
make.centerY.mas_equalTo(self.redAvatarImageView);
}];
[self.teamContainerView insertSubview:self.assistButton belowSubview:self.redAvatarImageView];
[self.teamContainerView insertSubview:self.onLookButton belowSubview:self.blueAvatarImageView];
[self.assistButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.redAvatarImageView.mas_trailing).offset(-16);
make.bottom.mas_equalTo(self.progressView.mas_top);
make.width.mas_equalTo(70);
make.height.mas_equalTo(14);
}];
[self.onLookButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.blueAvatarImageView.mas_leading).offset(16);
make.bottom.mas_equalTo(self.progressView.mas_top);
make.width.mas_equalTo(70);
make.height.mas_equalTo(14);
}];
[self.progressView addSubview:self.redCountImageView];
[self.progressView addSubview:self.blueCountImageView];
[self.progressView addSubview:self.redCountLabel];
[self.progressView addSubview:self.blueCountLabel];
[self.progressView addSubview:self.fireImageView];
[self.fireImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.progressView).offset(0);
make.centerY.mas_equalTo(self.progressView);
make.height.mas_equalTo(35);
make.width.mas_equalTo(24);
}];
[self.redCountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.progressView);
}];
[self.blueCountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.trailing.mas_equalTo(0);
make.leading.mas_equalTo(self.fireImageView.mas_centerX);
}];
[self.redCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.progressView).offset(2);
make.bottom.mas_equalTo(self.redAvatarImageView);
}];
[self.blueCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.progressView).offset(-2);
make.bottom.mas_equalTo(self.blueAvatarImageView);
}];
[self addSubview:self.foldButton];
[self.foldButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(self).offset(124);
make.size.mas_equalTo(CGSizeMake(18, 10));
}];
}
- (void)setupInteractiveArea {
[self addSubview:self.userStackView];
[self.userStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.stackView.mas_bottom).offset(28);
// make.bottom.mas_equalTo(self).offset(-24);
make.leading.trailing.mas_equalTo(self);
}];
UIImageView *charmTitleMark = [[UIImageView alloc] initWithImage:[UIImage getLanguageImage:@"pk_top_charms_mark"]];
charmTitleMark.contentMode = UIViewContentModeScaleAspectFill ;
[self.userStackView addArrangedSubview:charmTitleMark];
[charmTitleMark mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(145, 16));
}];
[self.userStackView addArrangedSubview:self.charmStackView];
[self.charmStackView addArrangedSubview:self.redCharmStackView];
[self.charmStackView addArrangedSubview:self.blueCharmStackView];
[self.charmStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(32);
make.leading.mas_equalTo(16);
make.trailing.mas_equalTo(-16);
}];
[self.redCharmStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.blueCharmStackView);
}];
UIImageView *moneyTitleMark = [[UIImageView alloc] initWithImage:[UIImage getLanguageImage:@"pk_top_momey_mark"]];
moneyTitleMark.contentMode = UIViewContentModeScaleAspectFill;
[self.userStackView addArrangedSubview:moneyTitleMark];
[moneyTitleMark mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(145, 16));
}];
[self.userStackView addArrangedSubview:self.contributeStackView];
[self.contributeStackView addArrangedSubview:self.redContributeStackView];
[self.contributeStackView addArrangedSubview:self.blueContributeStackView];
[self.contributeStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(32);
make.leading.mas_equalTo(16);
make.trailing.mas_equalTo(-16);
}];
[self.redContributeStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.blueContributeStackView);
}];
[self initUserSubViews];
}
- (void)setupRules {
[self addSubview:self.ruleBgImageView];
[self.ruleBgImageView addSubview:self.ruleTextView];
[self.ruleTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.ruleBgImageView).insets(UIEdgeInsetsMake(4, 4, 4, 4));
}];
[self.ruleBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-8);
make.top.mas_equalTo(30);
make.width.lessThanOrEqualTo(@210);
make.width.equalTo(self.ruleTextView.mas_width).offset(20).priorityLow();
make.height.equalTo(self.ruleTextView.mas_height).offset(20);
}];
}
- (void)initSubViews {
[self setupBackground];
[self setupBattleArea];
[self setupInteractiveArea];
[self setupRules];
// NSString * anatomiser1Name = [NSString stringWithFormat:@"%@/crossRoomPk_progress.svga", API_Image_URL];
// [self.parser parseWithURL:[NSURL URLWithString:anatomiser1Name] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// self.svgDisplayView.loops = INT_MAX;
// self.svgDisplayView.clearsAfterStop = NO;
// self.svgDisplayView.videoItem = videoItem;
// [self.svgDisplayView startAnimation];
// } failureBlock:^(NSError * _Nonnull error) {
//
// }];
}
- (void)initUserSubViews {
// TODO: 换图
for (int i = 0; i < 3; i++) {
XPAcrossRoomPKPanelUserView * userView = [[XPAcrossRoomPKPanelUserView alloc] init];
userView.tag = (1000 + i);
userView.type = AcrossRoomPKPanelUserType_Red_Charm;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUserRecognizer:)];
[userView addGestureRecognizer:tap];
[self.redCharmStackView addArrangedSubview:userView];
}
for (int i = 0; i < 3; i++) {
XPAcrossRoomPKPanelUserView * userView = [[XPAcrossRoomPKPanelUserView alloc] init];
userView.tag = (1000 + i);
userView.type = AcrossRoomPKPanelUserType_Blue_Charm;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUserRecognizer:)];
[userView addGestureRecognizer:tap];
[self.blueCharmStackView addArrangedSubview:userView];
}
for (int i = 0; i < 3; i++) {
XPAcrossRoomPKPanelUserView * userView = [[XPAcrossRoomPKPanelUserView alloc] init];
userView.tag = (1000 + i);
userView.type = AcrossRoomPKPanelUserType_Red_Contribute;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUserRecognizer:)];
[userView addGestureRecognizer:tap];
[self.redContributeStackView addArrangedSubview:userView];
}
for (int i = 0; i < 3; i++) {
XPAcrossRoomPKPanelUserView * userView = [[XPAcrossRoomPKPanelUserView alloc] init];
userView.tag = (1000 + i);
userView.type = AcrossRoomPKPanelUserType_Blue_Contribute;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUserRecognizer:)];
[userView addGestureRecognizer:tap];
[self.blueContributeStackView addArrangedSubview:userView];
}
}
- (void)initSubViewConstraints {
}
#pragma mark - 倒计时
- (void)openCountdownWithTime:(long)time {
__block long tempTime = time; //倒计时时间
if (self.timer == nil) {
@kWeakify(self);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.timer,dispatch_walltime(NULL, 0), 1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(self.timer, ^{
@kStrongify(self);
if(tempTime <= 0){ //倒计时结束,关闭
dispatch_source_cancel(self.timer);
self.timer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
self.timeLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
self.timeLabel.text = YMLocalizedString(@"XPAcrossRoomPKPanelView0");
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
//设置按钮显示读秒效果
[self acrossRoomPKCutdownOpen:tempTime];
});
tempTime--;
}
});
dispatch_resume(self.timer);
}
}
///房间pk, 倒计时回调
- (void)acrossRoomPKCutdownOpen:(NSInteger)time {
NSInteger minute = time / 60;
NSInteger second = (time % 60);
NSInteger hour = time/3600;
NSString *timeStr;
if (hour > 0) {
minute = minute % 60;
timeStr = [NSString stringWithFormat:@"%02zd:%02zd:%02zd", hour, minute, second];
} else {
timeStr = [NSString stringWithFormat:@"%02zd:%02zd", minute, second];
}
self.timeLabel.text = timeStr;
if (time <= 30) {
self.timeLabel.textColor = UIColorFromRGB(0xFFF17D);
} else {
self.timeLabel.textColor = UIColorFromRGB(0xFEFEFE);
}
}
#pragma mark - Event Response
- (void)foldButtonAction:(UIButton *)sender {
sender.selected = !sender.selected;
CGRect newFrame = self.frame;
if (sender.isSelected) {
self.userStackView.hidden = NO;
self.backgroundImageView.hidden = NO;
self.backgroundImageView_small.hidden = YES;
newFrame.size.height = kGetScaleWidth(MaxHeight);
self.foldButton.transform = CGAffineTransformIdentity;
} else {
self.userStackView.hidden = YES;
self.backgroundImageView.hidden = YES;
self.backgroundImageView_small.hidden = NO;
newFrame.size.height = kGetScaleWidth(MiniHeight);
self.foldButton.transform = CGAffineTransformMakeRotation(M_PI);
}
self.frame = newFrame;
[self layoutIfNeeded];
}
- (void)helpButtonAction:(UIButton *)sender {
sender.selected = !sender.selected;
self.ruleBgImageView.hidden = !sender.selected;
}
- (void)tapRedAvatarRecognizer:(UITapGestureRecognizer *)ges {
if (self.delegate && [self.delegate respondsToSelector:@selector(XPAcrossRoomPKPanelView:showUserCard:)]) {
[self.delegate XPAcrossRoomPKPanelView:self
showUserCard:self.pkPanelInfo.cUid];
}
}
- (void)tapBlueAvatarRecognizer:(UITapGestureRecognizer *)ges {
if (self.delegate && [self.delegate respondsToSelector:@selector(XPAcrossRoomPKPanelView:showUserCard:)]) {
[self.delegate XPAcrossRoomPKPanelView:self
showUserCard:self.pkPanelInfo.aUid];
}
}
- (void)assistButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(XPAcrossRoomPKPanelView:sendGiftToUser:)]) {
[self.delegate XPAcrossRoomPKPanelView:self
sendGiftToUser:self.pkPanelInfo.cUid];
}
}
- (void)onlookButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(XPAcrossRoomPKPanelView:onLookRoom:)]) {
[self.delegate XPAcrossRoomPKPanelView:self
onLookRoom:self.pkPanelInfo.aUid];
}
}
- (void)tapUserRecognizer:(UITapGestureRecognizer *)tap {
XPAcrossRoomPKPanelUserView * userView= (XPAcrossRoomPKPanelUserView *)tap.view;
if (userView.panelInfo && userView.panelInfo.uid.length > 0 && self.delegate && [self.delegate respondsToSelector:@selector(XPAcrossRoomPKPanelView:showUserCard:)]) {
[self.delegate XPAcrossRoomPKPanelView:self showUserCard:userView.panelInfo.uid];
}
}
- (void)changeLocation:(UIPanGestureRecognizer*)p {
// 就是悬浮小球底下的那个的window,就是APPdelegete里面的那个window属性
// 获取正在显示的那个界面的Window,http://www.jianshu.com/p/d23763e60e94
UIWindow *appWindow = [UIApplication sharedApplication].delegate.window;
CGPoint panPoint = [p locationInView:appWindow];
if (p.state == UIGestureRecognizerStateBegan) {
// self.alpha = 1;
} else if(p.state == UIGestureRecognizerStateChanged) {
self.center = CGPointMake(panPoint.x, panPoint.y);
} else if(p.state == UIGestureRecognizerStateEnded
|| p.state == UIGestureRecognizerStateCancelled) {
// self.alpha = 1;
CGFloat touchWidth = self.frame.size.width;
CGFloat touchHeight = self.frame.size.height;
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
// fabs 是取绝对值的意思
CGFloat left = fabs(panPoint.x);
CGFloat right = fabs(screenWidth - left);
CGFloat top = fabs(panPoint.y);
CGFloat bottom = fabs(screenHeight - top);
CGFloat minSpace = 0;
minSpace = MIN(MIN(MIN(top, left), bottom), right);
CGPoint newCenter;
CGFloat targetY = 0;
//校正Y
if (panPoint.y < 15 + touchHeight / 2.0) {
targetY = 15 + touchHeight / 2.0;
}else if (panPoint.y > (screenHeight - touchHeight / 2.0 - 15)) {
targetY = screenHeight - touchHeight / 2.0 - 15;
}else{
targetY = panPoint.y;
}
if (minSpace == left) {
newCenter = CGPointMake(15+touchWidth/2.0, targetY);
}else if (minSpace == right) {
newCenter = CGPointMake(screenWidth - touchWidth/2.0 - 15, targetY);
}else if (minSpace == top) {
newCenter = CGPointMake(panPoint.x, touchWidth / 3);
}else {
newCenter = CGPointMake(panPoint.x, screenHeight - touchWidth / 3);
}
self.centerCenter = newCenter;
[UIView animateWithDuration:0.25 animations:^{
if ((newCenter.y + self.frame.size.height / 2) > (KScreenHeight - kSafeAreaBottomHeight - 44)) {
self.center = CGPointMake(newCenter.x, KScreenHeight - self.frame.size.height / 2 - kSafeAreaBottomHeight - 44);
}else {
self.center = newCenter;
}
}];
}
}
#pragma mark - getters and setters
- (void)setPkPanelInfo:(AcrossRoomPKPanelModel *)pkPanelInfo {
_pkPanelInfo = pkPanelInfo;
if (_pkPanelInfo) {
@kWeakify(self);
[Timestamp getInternetDateWithSuccess:^(NSTimeInterval timeInterval) {
@kStrongify(self);
timeInterval = timeInterval * 1000;
long aTime = (pkPanelInfo.endTime - timeInterval) / 1000;
[self openCountdownWithTime:aTime];
} failure:^(NSError * _Nonnull error) {
@kStrongify(self);
NSDate *datenow = [NSDate date];//现在时间
long time2 = (long)([datenow timeIntervalSince1970]*1000);
long aTime = (pkPanelInfo.endTime - time2) / 1000;
[self openCountdownWithTime:aTime];
}];
if (_pkPanelInfo.cTitle.length > 7) {
_pkPanelInfo.cTitle = [NSString stringWithFormat:@"%@…", [_pkPanelInfo.cTitle substringToIndex:7]];
}
if (_pkPanelInfo.aTitle.length > 7) {
_pkPanelInfo.aTitle = [NSString stringWithFormat:@"%@…", [_pkPanelInfo.aTitle substringToIndex:7]];
}
self.redTitleLabel.text = _pkPanelInfo.cTitle;
self.redAvatarImageView.imageUrl = _pkPanelInfo.cAvatar;
self.redCountLabel.text = [NSString stringWithFormat:@"%lld", _pkPanelInfo.cAmount];
self.blueTitleLabel.text = _pkPanelInfo.aTitle;
self.blueAvatarImageView.imageUrl = _pkPanelInfo.aAvatar;
self.blueCountLabel.text = [NSString stringWithFormat:@"%lld", _pkPanelInfo.aAmount];
for (int i = 0; i<_pkPanelInfo.csRank.count; i++) {
AcrossRoomPkRankModel * rankModel = [_pkPanelInfo.csRank xpSafeObjectAtIndex:i];
if (i >= self.redContributeStackView.subviews.count) {
break;
}
XPAcrossRoomPKPanelUserView *userView = self.redContributeStackView.subviews[i];
userView.panelInfo = rankModel;
}
for (int i = 0; i<_pkPanelInfo.crRank.count; i++) {
AcrossRoomPkRankModel * rankModel = [_pkPanelInfo.crRank xpSafeObjectAtIndex:i];
if (i >= self.redCharmStackView.subviews.count) {
break;
}
XPAcrossRoomPKPanelUserView *userView = self.redCharmStackView.subviews[i];
userView.panelInfo = rankModel;
}
for (int i = 0; i<_pkPanelInfo.asRank.count; i++) {
AcrossRoomPkRankModel * rankModel = [_pkPanelInfo.asRank xpSafeObjectAtIndex:i];
if (i >= self.blueContributeStackView.subviews.count) {
break;
}
XPAcrossRoomPKPanelUserView *userView = self.blueContributeStackView.subviews[i];
userView.panelInfo = rankModel;
}
for (int i = 0; i<_pkPanelInfo.arRank.count; i++) {
AcrossRoomPkRankModel * rankModel = [_pkPanelInfo.arRank xpSafeObjectAtIndex:i];
if (i >= self.blueCharmStackView.subviews.count) {
break;
}
XPAcrossRoomPKPanelUserView *userView = self.blueCharmStackView.subviews[i];
userView.panelInfo = rankModel;
}
// 0.5 = centerX
if (_pkPanelInfo.aPercent > 1) {
_pkPanelInfo.aPercent = 1;
}
CGFloat progress = 1 - _pkPanelInfo.aPercent;
CGFloat width = CGRectGetWidth(self.progressView.bounds);
CGFloat centerX = progress * width;
[UIView animateWithDuration:0.1 animations:^{
[self.fireImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.progressView).offset(centerX - width / 2);
}];
[self layoutIfNeeded];
}];
} else {
self.redTitleLabel.text = @"";
self.redAvatarImageView.image = nil;
self.redCountLabel.text = @"0";
self.blueTitleLabel.text = @"";
self.blueAvatarImageView.image = nil;
self.blueCountLabel.text = @"0";
for (int i = 0; i<self.redContributeStackView.subviews.count; i++) {
XPAcrossRoomPKPanelUserView *userView = self.redContributeStackView.subviews[i];
userView.panelInfo = nil;
}
for (int i = 0; i<self.redCharmStackView.subviews.count; i++) {
XPAcrossRoomPKPanelUserView *userView = self.redCharmStackView.subviews[i];
userView.panelInfo = nil;
}
for (int i = 0; i<self.blueContributeStackView.subviews.count; i++) {
XPAcrossRoomPKPanelUserView *userView = self.blueContributeStackView.subviews[i];
userView.panelInfo = nil;
}
for (int i = 0; i<self.blueCharmStackView.subviews.count; i++) {
XPAcrossRoomPKPanelUserView *userView = self.blueCharmStackView.subviews[i];
userView.panelInfo = nil;
}
CGFloat width = 174;
[self.blueCountImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(width * 0.5);
}];
}
}
- (UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];
_backgroundImageView.image = [UIImage imageNamed:@"room_across_pk_panel_bg"];
_backgroundImageView.userInteractionEnabled = YES;
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _backgroundImageView;
}
- (UIImageView *)backgroundImageView_small {
if (!_backgroundImageView_small) {
_backgroundImageView_small = [[UIImageView alloc] init];
_backgroundImageView_small.image = [UIImage imageNamed:@"room_across_pk_panel_small_bg"];
_backgroundImageView_small.userInteractionEnabled = YES;
_backgroundImageView_small.contentMode = UIViewContentModeScaleAspectFit;
_backgroundImageView_small.hidden = YES;
}
return _backgroundImageView_small;
}
- (UIButton *)helpButton {
if (!_helpButton) {
_helpButton = [[UIButton alloc] init];
[_helpButton setImage:[UIImage imageNamed:@"room_across_pk_panel_help"] forState:UIControlStateNormal];
[_helpButton addTarget:self action:@selector(helpButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_helpButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _helpButton;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
if (@available(iOS 13.0, *)) {
_timeLabel.font = [UIFont monospacedSystemFontOfSize:16 weight:UIFontWeightBold];
} else {
_timeLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
}
_timeLabel.textColor = UIColorFromRGB(0xFEFEFE);
_timeLabel.text = @"00:00";
}
return _timeLabel;
}
- (UIImageView *)ruleBgImageView {
if (!_ruleBgImageView) {
_ruleBgImageView = [[UIImageView alloc] init];
_ruleBgImageView.layer.cornerRadius = 11;
_ruleBgImageView.clipsToBounds = YES;
_ruleBgImageView.backgroundColor = UIColorRGBAlpha(0x140B24, 0.8);
_ruleBgImageView.hidden = YES;
}
return _ruleBgImageView;
}
- (SZTextView *)ruleTextView {
if (!_ruleTextView) {
_ruleTextView = [[SZTextView alloc] init];
_ruleTextView.backgroundColor = [UIColor clearColor];
_ruleTextView.textColor = [UIColor whiteColor];
_ruleTextView.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
_ruleTextView.scrollEnabled = NO;
_ruleTextView.text = YMLocalizedString(@"XPAcrossRoomPKPanelView1");
}
return _ruleTextView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.backgroundColor = [UIColor clearColor];
_stackView.axis = UILayoutConstraintAxisVertical;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 10;
}
return _stackView;
}
- (UIView *)teamContainerView {
if (!_teamContainerView) {
_teamContainerView = [[UIView alloc] init];
_teamContainerView.backgroundColor = [UIColor clearColor];
}
return _teamContainerView;
}
- (UIView *)progressView {
if (!_progressView) {
_progressView = [[UIView alloc] init];
}
return _progressView;
}
- (UIImageView *)redCountImageView {
if (!_redCountImageView) {
_redCountImageView = [[UIImageView alloc] init];
_redCountImageView.image = [[UIImage imageNamed:@"pk_progress_red"]
resizableImageWithCapInsets:UIEdgeInsetsZero
resizingMode:UIImageResizingModeTile];
}
return _redCountImageView;
}
- (UILabel *)redCountLabel {
if (!_redCountLabel) {
_redCountLabel = [[UILabel alloc] init];
_redCountLabel.font = [UIFont boldSystemFontOfSize:12];
_redCountLabel.textColor = [UIColor whiteColor];
_redCountLabel.text = @"0";
_redCountLabel.textAlignment = NSTextAlignmentLeft;
}
return _redCountLabel;
}
- (UIImageView *)blueCountImageView {
if (!_blueCountImageView) {
_blueCountImageView = [[UIImageView alloc] init];
_blueCountImageView.image = [[UIImage imageNamed:@"pk_progress_blue"]
resizableImageWithCapInsets:UIEdgeInsetsZero
resizingMode:UIImageResizingModeTile];
}
return _blueCountImageView;
}
- (UILabel *)blueCountLabel {
if (!_blueCountLabel) {
_blueCountLabel = [[UILabel alloc] init];
_blueCountLabel.font = [UIFont boldSystemFontOfSize:12];
_blueCountLabel.textColor = [UIColor whiteColor];
_blueCountLabel.text = @"0";
_blueCountLabel.textAlignment = NSTextAlignmentRight;
}
return _blueCountLabel;
}
- (UILabel *)redTitleLabel {
if (!_redTitleLabel) {
_redTitleLabel = [[UILabel alloc] init];
_redTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
_redTitleLabel.textColor = [UIColor whiteColor];
}
return _redTitleLabel;
}
- (NetImageView *)redAvatarImageView {
if (!_redAvatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_redAvatarImageView = [[NetImageView alloc] initWithConfig:config];
_redAvatarImageView.layer.masksToBounds = YES;
_redAvatarImageView.layer.cornerRadius = 22;
_redAvatarImageView.layer.borderWidth = 1;
_redAvatarImageView.userInteractionEnabled = YES;
_redAvatarImageView.layer.borderColor = UIColorFromRGB(0xFF6574).CGColor;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRedAvatarRecognizer:)];
[_redAvatarImageView addGestureRecognizer:tap];
}
return _redAvatarImageView;
}
- (UILabel *)blueTitleLabel {
if (!_blueTitleLabel) {
_blueTitleLabel = [[UILabel alloc] init];
_blueTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
_blueTitleLabel.textColor = [UIColor whiteColor];
_blueTitleLabel.textAlignment = NSTextAlignmentRight;
}
return _blueTitleLabel;
}
- (NetImageView *)blueAvatarImageView {
if (!_blueAvatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_blueAvatarImageView = [[NetImageView alloc] initWithConfig:config];
_blueAvatarImageView.layer.masksToBounds = YES;
_blueAvatarImageView.layer.cornerRadius = 22;
_blueAvatarImageView.layer.borderWidth = 1;
_blueAvatarImageView.layer.borderColor = UIColorFromRGB(0x45C0FF).CGColor;
_blueAvatarImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBlueAvatarRecognizer:)];
[_blueAvatarImageView addGestureRecognizer:tap];
}
return _blueAvatarImageView;
}
- (UIButton *)assistButton {
if (!_assistButton) {
_assistButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_assistButton setBackgroundImage:kImage(@"pk_name_bg_red") forState:UIControlStateNormal];
[_assistButton setTitle:YMLocalizedString(@"XPAcrossRoomPKPanelView2") forState:UIControlStateNormal];
_assistButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
[_assistButton setTitleColor:UIColorFromRGB(0xFFFABD) forState:UIControlStateNormal];
[_assistButton addTarget:self action:@selector(assistButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _assistButton;
}
- (UIButton *)onLookButton {
if (!_onLookButton) {
_onLookButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_onLookButton setBackgroundImage:kImage(@"pk_name_bg_blue") forState:UIControlStateNormal];
[_onLookButton setTitle:YMLocalizedString(@"XPAcrossRoomPKPanelView3") forState:UIControlStateNormal];
_onLookButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
[_onLookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_onLookButton addTarget:self action:@selector(onlookButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _onLookButton;
}
- (UIButton *)foldButton {
if (!_foldButton) {
_foldButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_foldButton setImage:[UIImage imageNamed:@"room_across_pk_panel_fold"] forState:UIControlStateNormal];
[_foldButton addTarget:self action:@selector(foldButtonAction:) forControlEvents:UIControlEventTouchUpInside];
_foldButton.selected = YES;
[_foldButton setEnlargeEdgeWithTop:5 right:10 bottom:10 left:10];
}
return _foldButton;
}
- (UIStackView *)userStackView {
if (!_userStackView) {
_userStackView = [[UIStackView alloc] init];
_userStackView.backgroundColor = [UIColor clearColor];
_userStackView.axis = UILayoutConstraintAxisVertical;
_userStackView.distribution = UIStackViewDistributionFill;
_userStackView.alignment = UIStackViewAlignmentCenter;
_userStackView.spacing = 8;
}
return _userStackView;
}
- (UIStackView *)charmStackView {
if (!_charmStackView) {
_charmStackView = [[UIStackView alloc] init];
_charmStackView.axis = UILayoutConstraintAxisHorizontal;
_charmStackView.distribution = UIStackViewDistributionFill;
_charmStackView.alignment = UIStackViewAlignmentCenter;
_charmStackView.spacing = 36;
}
return _charmStackView;
}
- (UIStackView *)redCharmStackView {
if (!_redCharmStackView) {
_redCharmStackView = [[UIStackView alloc] init];
_redCharmStackView.axis = UILayoutConstraintAxisHorizontal;
_redCharmStackView.distribution = UIStackViewDistributionEqualSpacing;
_redCharmStackView.alignment = UIStackViewAlignmentFill;
_redCharmStackView.spacing = 14;
}
return _redCharmStackView;
}
- (UIStackView *)blueCharmStackView {
if (!_blueCharmStackView) {
_blueCharmStackView = [[UIStackView alloc] init];
_blueCharmStackView.axis = UILayoutConstraintAxisHorizontal;
_blueCharmStackView.distribution = UIStackViewDistributionEqualSpacing;
_blueCharmStackView.alignment = UIStackViewAlignmentFill;
_blueCharmStackView.spacing = 14;
}
return _blueCharmStackView;
}
- (UIStackView *)contributeStackView {
if (!_contributeStackView) {
_contributeStackView = [[UIStackView alloc] init];
_contributeStackView.axis = UILayoutConstraintAxisHorizontal;
_contributeStackView.distribution = UIStackViewDistributionFill;
_contributeStackView.alignment = UIStackViewAlignmentCenter;
_contributeStackView.spacing = 36;
}
return _contributeStackView;
}
- (UIStackView *)redContributeStackView {
if (!_redContributeStackView) {
_redContributeStackView = [[UIStackView alloc] init];
_redContributeStackView.axis = UILayoutConstraintAxisHorizontal;
_redContributeStackView.distribution = UIStackViewDistributionEqualSpacing;
_redContributeStackView.alignment = UIStackViewAlignmentFill;
_redContributeStackView.spacing = 14;
}
return _redContributeStackView;
}
- (UIStackView *)blueContributeStackView {
if (!_blueContributeStackView) {
_blueContributeStackView = [[UIStackView alloc] init];
_blueContributeStackView.axis = UILayoutConstraintAxisHorizontal;
_blueContributeStackView.distribution = UIStackViewDistributionEqualSpacing;
_blueContributeStackView.alignment = UIStackViewAlignmentFill;
_blueContributeStackView.spacing = 14;
}
return _blueContributeStackView;
}
//- (SVGAImageView *)svgDisplayView {
// if (_svgDisplayView == nil) {
// _svgDisplayView = [[SVGAImageView alloc]init];
// _svgDisplayView.contentMode = UIViewContentModeScaleToFill;
// _svgDisplayView.userInteractionEnabled = NO;
// _svgDisplayView.backgroundColor = [UIColor clearColor];
// }
// return _svgDisplayView;
//}
- (UIImageView *)fireImageView {
if (!_fireImageView) {
_fireImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pk_progress_fire_icon"]];
_fireImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _fireImageView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
@end