// // MessageContentGameView.m // xplan-ios // // Created by duoban on 2023/8/22. // #import "MessageContentGameView.h" #import "UserGameInfoVo.h" @interface MessageContentGameView() ///背景图片 @property(nonatomic,strong) NetImageView *bgImageView; ///开黑邀请 @property(nonatomic,strong) UILabel *titleView; ///副标题 @property(nonatomic,strong) UILabel *subTitleView; ///游戏背景 @property(nonatomic,strong) UIView *gameBgView; ///游戏logo @property(nonatomic,strong) NetImageView *gameIcomView; ///游戏名 @property(nonatomic,strong) UILabel *gameNameView; ///游戏局数 @property(nonatomic,strong) UILabel *gameNumView; @property(nonatomic,strong) NIMMessage *msg; @end @implementation MessageContentGameView + (CGFloat)measureHeight:(NIMMessage *)message { return (CONTENT_PADDING_V_TOTAL + kGetScaleWidth(136)); } - (void)initSubViews { [super initSubViews]; [self addSubview:self.backView]; [self.backView addSubview:self.bgImageView]; [self.bgImageView addSubview:self.titleView]; [self.bgImageView addSubview:self.subTitleView]; [self.bgImageView addSubview:self.gameBgView]; [self.gameBgView addSubview:self.gameIcomView]; [self.gameBgView addSubview:self.gameNameView]; [self.gameBgView addSubview:self.gameNumView]; } - (void)initSubViewConstraints { [super initSubViewConstraints]; [self.backView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(239), kGetScaleWidth(136))); }]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(kGetScaleWidth(239)); make.height.mas_equalTo(kGetScaleWidth(136)); make.top.leading.mas_equalTo(self.backView); }]; [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(kGetScaleWidth(16)); make.top.mas_equalTo(kGetScaleWidth(12)); make.height.mas_equalTo(kGetScaleWidth(22)); }]; [self.subTitleView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(kGetScaleWidth(16)); make.top.equalTo(self.titleView.mas_bottom).mas_offset(kGetScaleWidth(1)); make.height.mas_equalTo(kGetScaleWidth(17)); }]; [self.gameBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(kGetScaleWidth(10)); make.top.equalTo(self.subTitleView.mas_bottom).mas_offset(kGetScaleWidth(6)); make.width.mas_equalTo(kGetScaleWidth(219)); make.height.mas_equalTo(kGetScaleWidth(68)); }]; [self.gameIcomView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.width.mas_equalTo(kGetScaleWidth(44)); make.leading.mas_equalTo(kGetScaleWidth(16)); make.top.mas_equalTo(kGetScaleWidth(12)); }]; [self.gameNameView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(kGetScaleWidth(12)); make.leading.mas_equalTo(kGetScaleWidth(70)); make.height.mas_equalTo(kGetScaleWidth(22)); }]; [self.gameNumView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.gameNameView.mas_bottom).mas_offset(kGetScaleWidth(2)); make.leading.mas_equalTo(kGetScaleWidth(70)); make.height.mas_equalTo(kGetScaleWidth(20)); }]; } - (void)render:(NIMMessage *)message { self.msg = message; NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; AttachmentModel * attach = obj.attachment; UserGameInfoVo *gameInfo = [UserGameInfoVo modelWithDictionary:attach.data]; _gameIcomView.imageUrl = gameInfo.gameLogo; _gameNameView.text = gameInfo.gameName; _gameNumView.text = [NSString stringWithFormat:@"%@ 局",gameInfo.inning]; } -(void)checkGameAction{ if(self.delegate && [self.delegate respondsToSelector:@selector(checkGameListInfo:)]){ [self.delegate checkGameListInfo:self.msg]; } } - (NetImageView *)bgImageView{ if(!_bgImageView){ _bgImageView = [NetImageView new]; _bgImageView.image = kImage(@"message_session_game_Invite_bg"); _bgImageView.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checkGameAction)]; [_bgImageView addGestureRecognizer:tap]; } return _bgImageView; } - (UILabel *)titleView{ if(!_titleView){ _titleView = [UILabel labelInitWithText:@"开黑邀请" font:kFontMedium(16) textColor:[UIColor whiteColor]]; } return _titleView; } -(UILabel *)subTitleView{ if(!_subTitleView){ _subTitleView = [UILabel labelInitWithText:@"和我一起玩游戏吧~" font:kFontRegular(12) textColor:UIColorFromRGB(0xCED1DB)]; } return _subTitleView; } - (UIView *)gameBgView{ if(!_gameBgView){ _gameBgView = [UIView new]; _gameBgView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.1]; _gameBgView.layer.cornerRadius = kGetScaleWidth(6); _gameBgView.layer.masksToBounds = YES; } return _gameBgView; } - (NetImageView *)gameIcomView{ if(!_gameIcomView){ NetImageConfig *config = [[NetImageConfig alloc]init]; config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder]; _gameIcomView = [[NetImageView alloc]initWithConfig:config]; _gameIcomView.userInteractionEnabled = YES; } return _gameIcomView; } - (UILabel *)gameNameView{ if(!_gameNameView){ _gameNameView = [UILabel labelInitWithText:@"" font:kFontMedium(16) textColor:[UIColor whiteColor]]; } return _gameNameView; } - (UILabel *)gameNumView{ if(!_gameNumView){ _gameNumView = [UILabel labelInitWithText:@"" font:kFontRegular(14) textColor:[UIColor colorWithWhite:1 alpha:0.8]]; } return _gameNumView; } @end