// // XPSessionMessageGameCell.m // xplan-ios // // Created by duoban on 2023/8/22. // #import "XPSessionMessageGameCell.h" #import "XPSessionMessageHeadView.h" @interface XPSessionMessageGameCell () ///背景 @property(nonatomic,strong) NetImageView *bgImageView; ///游戏logo @property(nonatomic,strong) NetImageView *iconView; ///游戏名 @property(nonatomic,strong) UILabel *titleView; ///段位背景 @property(nonatomic,strong) UIView *tierBgView; ///段位 @property(nonatomic,strong) UILabel *tierView; ///抖音次数 @property(nonatomic,strong) UILabel *numView; ///价格 @property(nonatomic,strong) UILabel *priceView; ///支付 @property(nonatomic,strong) NetImageView *payBtn; @property(nonatomic,strong) UIButton *payTitleBnt; ///跟随进房卡片 @property (nonatomic, strong) XPSessionMessageHeadView *followInRoomView; @end @implementation XPSessionMessageGameCell -(instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ [self installUI]; [self installConstraints]; } return self; } -(void)installUI{ self.backgroundColor = [UIColor clearColor]; self.contentView.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:self.bgImageView]; [self.contentView addSubview:self.followInRoomView]; [self.bgImageView addSubview:self.iconView]; [self.bgImageView addSubview:self.titleView]; [self.bgImageView addSubview:self.tierBgView]; [self.tierBgView addSubview:self.tierView]; [self.bgImageView addSubview:self.numView]; [self.bgImageView addSubview:self.priceView]; [self.bgImageView addSubview:self.payBtn]; [self.bgImageView addSubview:self.payTitleBnt]; } -(void)installConstraints{ [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kGetScaleWidth(0)); make.bottom.mas_equalTo(-kGetScaleWidth(0)); make.leading.trailing.equalTo(self.contentView).inset(kGetScaleWidth(16)); }]; [self.followInRoomView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.contentView); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(kGetScaleWidth(48)); make.top.mas_equalTo(kGetScaleWidth(14)); make.leading.mas_equalTo(kGetScaleWidth(18)); }]; [self.priceView mas_makeConstraints:^(MASConstraintMaker *make) { make.trailing.mas_equalTo(-kGetScaleWidth(18)); make.height.mas_equalTo(kGetScaleWidth(21)); make.width.mas_greaterThanOrEqualTo(10); make.top.mas_equalTo(kGetScaleWidth(11)); }]; [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.iconView.mas_trailing).mas_offset(kGetScaleWidth(10)); make.top.mas_equalTo(kGetScaleWidth(15)); make.height.mas_equalTo(kGetScaleWidth(22)); }]; [self.tierBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(kGetScaleWidth(16)); make.width.mas_equalTo(kGetScaleWidth(52)); make.centerY.equalTo(self.titleView); make.leading.equalTo(self.titleView.mas_trailing).mas_offset(kGetScaleWidth(4)); make.trailing.equalTo(self.priceView.mas_leading).mas_offset(-kGetScaleWidth(2)); }]; [self.tierView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.equalTo(self.tierBgView).inset(kGetScaleWidth(6)); make.centerY.equalTo(self.tierBgView); }]; [self.numView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleView.mas_bottom).mas_offset(kGetScaleWidth(3)); make.height.mas_equalTo(kGetScaleWidth(21)); make.leading.equalTo(self.iconView.mas_trailing).mas_offset(kGetScaleWidth(10)); }]; [self.payBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(kGetScaleWidth(72)); make.height.mas_equalTo(kGetScaleWidth(28)); make.trailing.mas_equalTo(-kGetScaleWidth(18)); make.top.mas_equalTo(kGetScaleWidth(36)); }]; [self.payTitleBnt mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(kGetScaleWidth(72)); make.height.mas_equalTo(kGetScaleWidth(28)); make.trailing.mas_equalTo(-kGetScaleWidth(18)); make.top.mas_equalTo(kGetScaleWidth(36)); }]; } #pragma mark - XPSessionMessageHeadViewDelegate - (void)onAvatarClick:(NSInteger)uid{ if(self.delegate && [self.delegate respondsToSelector:@selector(xpSessionMessageGameCell:onAvatarClick:)]){ [self.delegate xpSessionMessageGameCell:self onAvatarClick:uid]; } } - (void)onFollowInRoom:(NSString *)roomUid{ if(self.delegate && [self.delegate respondsToSelector:@selector(xpSessionMessageGameCell:onFollowInRoom:)]){ [self.delegate xpSessionMessageGameCell:self onFollowInRoom:roomUid]; } } -(void)payAtion{ if(self.delegate && [self.delegate respondsToSelector:@selector(xpSessionMessageGameCell:onPlaceOrder:)]){ [self.delegate xpSessionMessageGameCell:self onPlaceOrder:@""]; } } -(void)setUserInfo:(UserInfoModel *)userInfo{ _userInfo = userInfo; self.followInRoomView.userInfo = _userInfo; self.followInRoomView.hidden = NO; self.bgImageView.hidden = YES; } - (void)setGameInfo:(UserGameInfoVo *)gameInfo{ _gameInfo = gameInfo; self.followInRoomView.hidden = YES; self.bgImageView.hidden = NO; _iconView.imageUrl = _gameInfo.logo; _payBtn.imageUrl = _gameInfo.btnBg; [_payTitleBnt setTitleColor:UIColorFromRGB(0xBBBCBD) forState:UIControlStateNormal]; self.tierView.textColor = UIColorFromRGB(0xBBBCBD); self.tierBgView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];; [_bgImageView loadImageWithUrl:_gameInfo.background completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) { self.tierView.textColor = [ThemeColor colorWithHexString:gameInfo.tagRgb]; self.tierBgView.backgroundColor = [ThemeColor colorWithHexString:gameInfo.tagBg]; self.bgImageView.image = image; [self.payTitleBnt setTitleColor:[ThemeColor colorWithHexString:gameInfo.btnRgb] forState:UIControlStateNormal]; }]; _tierView.text = _gameInfo.tier; CGFloat width = [UILabel getWidthWithText:_gameInfo.tier height:kGetScaleWidth(16) font:_tierView.font]+kGetScaleWidth(14); if(width > kGetScaleWidth(72)){ width = kGetScaleWidth(72); } [_tierBgView mas_remakeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(kGetScaleWidth(16)); make.width.mas_equalTo(width); make.centerY.equalTo(self.titleView); make.leading.equalTo(self.titleView.mas_trailing).mas_offset(kGetScaleWidth(4)); }]; _tierBgView.hidden = _gameInfo.tier.length == 0; if(_gameInfo.gameName.length > 6){ _gameInfo.gameName = [NSString stringWithFormat:@"%@...",[_gameInfo.gameName substringToIndex:6]]; } _titleView.text = _gameInfo.gameName; NSMutableAttributedString *gameNameAtt = [[NSMutableAttributedString alloc]initWithString:_gameInfo.gameName attributes:@{NSFontAttributeName:kFontMedium(16),NSForegroundColorAttributeName:[UIColor whiteColor]}]; NSString *gameName = @""; if(_gameInfo.gameName.length > 5 ){ gameName = [_gameInfo.gameName substringWithRange:NSMakeRange(4, _gameInfo.gameName.length-4)]; [gameNameAtt addAttributes:@{NSFontAttributeName:kFontMedium(12),NSForegroundColorAttributeName:[UIColor whiteColor]} range:[_gameInfo.gameName rangeOfString:gameName]]; _titleView.attributedText = gameNameAtt; }else{ _titleView.attributedText = gameNameAtt; } NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ 钻/局",_gameInfo.price] attributes:@{NSFontAttributeName:kFontMedium(16),NSForegroundColorAttributeName:[UIColor whiteColor]}]; [textAtt addAttributes:@{NSFontAttributeName:kFontRegular(10),NSForegroundColorAttributeName:[UIColor colorWithWhite:1 alpha:0.8]} range:[textAtt.string rangeOfString:@"钻/局"]]; UIImage *iconImage = kImage(@"mine_game_diamond"); NSTextAttachment * attachment = [[NSTextAttachment alloc] init]; attachment.bounds = CGRectMake(0, roundf(_priceView.font.capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);; attachment.image = iconImage; [textAtt insertAttributedString:[NSMutableAttributedString attributedStringWithAttachment:attachment] atIndex:0]; _priceView.textAlignment = NSTextAlignmentRight; _priceView.attributedText = textAtt; _gameInfo.finishNum = _gameInfo.finishNum ?: @"0"; NSMutableAttributedString *numAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"接单 %@ 次>",_gameInfo.finishNum] attributes:@{NSFontAttributeName:kFontRegular(12),NSForegroundColorAttributeName:[UIColor whiteColor]}]; [numAtt addAttributes:@{NSFontAttributeName:kFontMedium(16),NSForegroundColorAttributeName:UIColorFromRGB(0xFFDA24)} range:[numAtt.string rangeOfString:_gameInfo.finishNum]]; _numView.attributedText = numAtt; } -(void)jumToChooseGameVC{ if(self.delegate && [self.delegate respondsToSelector:@selector(xpSessionMessageGameCell:chooseGame:)]){ [self.delegate xpSessionMessageGameCell:self chooseGame:@""]; } } #pragma mark - 懒加载 - (NetImageView *)bgImageView{ if(!_bgImageView){ NetImageConfig *config = [[NetImageConfig alloc]init]; config.placeHolder = kImage(@"mine_user_game_cell_bg"); _bgImageView = [[NetImageView alloc]initWithConfig:config]; _bgImageView.layer.cornerRadius = kGetScaleWidth(12); _bgImageView.layer.masksToBounds = YES; _bgImageView.userInteractionEnabled = YES; } return _bgImageView; } -(NetImageView *)iconView{ if(!_iconView){ NetImageConfig *config = [NetImageConfig new]; config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder]; _iconView = [[NetImageView alloc]initWithConfig:config]; } return _iconView; } - (UILabel *)titleView{ if(!_titleView){ _titleView = [UILabel labelInitWithText:@"" font:kFontMedium(16) textColor:[UIColor whiteColor]]; } return _titleView; } - (UIView *)tierBgView{ if(!_tierBgView){ _tierBgView = [UIView new]; _tierBgView.backgroundColor = UIColorFromRGB(0xFFF8ED); _tierBgView.layer.cornerRadius = kGetScaleWidth(16)/2; _tierBgView.layer.masksToBounds = YES; } return _tierBgView; } - (UILabel *)tierView{ if(!_tierView){ _tierView = [UILabel labelInitWithText:@"" font:kFontRegular(10) textColor:UIColorFromRGB(0x764108)]; _tierView.textAlignment = NSTextAlignmentCenter; } return _tierView; } - (UILabel *)priceView{ if(!_priceView){ _priceView = [UILabel new]; } return _priceView; } - (NetImageView *)payBtn{ if(!_payBtn){ NetImageConfig *config = [[NetImageConfig alloc]init]; config.placeHolder = kImage(@"mine_user_game_cell_pay_bg"); _payBtn = [[NetImageView alloc]initWithConfig:config]; _payBtn.userInteractionEnabled = YES; } return _payBtn; } - (UIButton *)payTitleBnt{ if(!_payTitleBnt){ UIButton *payTitleBnt = [[UIButton alloc]init]; [payTitleBnt setTitleColor:UIColorFromRGB(0xBBBCBD) forState:UIControlStateNormal]; [payTitleBnt setTitle:@"下单" forState:UIControlStateNormal]; payTitleBnt.titleLabel.font = kFontMedium(12); [payTitleBnt addTarget:self action:@selector(payAtion) forControlEvents:UIControlEventTouchUpInside]; _payTitleBnt = payTitleBnt; } return _payTitleBnt; } - (UILabel *)numView{ if(!_numView){ _numView = [UILabel new]; _numView.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jumToChooseGameVC)]; [_numView addGestureRecognizer:tap]; } return _numView; } - (XPSessionMessageHeadView *)followInRoomView { if (!_followInRoomView) { _followInRoomView = [[XPSessionMessageHeadView alloc] init]; _followInRoomView.delegate = self; _followInRoomView.hidden = YES; } return _followInRoomView; } @end