354 lines
12 KiB
Objective-C
354 lines
12 KiB
Objective-C
//
|
|
// XPHomeLittleGameTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/3/24.
|
|
//
|
|
|
|
#import "XPHomeLittleGameTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "NetImageView.h"
|
|
#import "XPMacro.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "HomeLittleGameRoomModel.h"
|
|
|
|
@interface XPHomeLittleGameTableViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///边框
|
|
@property (nonatomic,strong) UIImageView *coverImageView;
|
|
///内容
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///房间标题
|
|
@property (nonatomic,strong) UILabel *roomTitleLabel;
|
|
///游戏名字
|
|
@property (nonatomic,strong) UILabel *gamenameLabel;
|
|
///分割线
|
|
@property (nonatomic,strong) UIView * gameLineView;
|
|
///游戏状态
|
|
@property (nonatomic,strong) UILabel *stateLabel;
|
|
///进房
|
|
@property (nonatomic,strong) UIButton *enterButton;
|
|
///房间在线人数
|
|
@property (nonatomic,strong) UIView *micContainerView;
|
|
///第一个
|
|
@property (nonatomic,strong) NetImageView *firstImageView;
|
|
///第二个
|
|
@property (nonatomic,strong) NetImageView *secondImageView;
|
|
///第三个
|
|
@property (nonatomic,strong) NetImageView *thirdImageView;
|
|
///第四个
|
|
@property (nonatomic,strong) NetImageView *fourImageView;
|
|
///第五个
|
|
@property (nonatomic,strong) NetImageView *fifImageView;
|
|
///用户的数组
|
|
@property (nonatomic,strong) NSArray *micUserArray;
|
|
@end
|
|
|
|
|
|
@implementation XPHomeLittleGameTableViewCell
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[self.contentView addSubview:self.backImageView];
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.coverImageView];
|
|
|
|
[self.backImageView addSubview:self.roomTitleLabel];
|
|
[self.backImageView addSubview:self.gamenameLabel];
|
|
[self.backImageView addSubview:self.gameLineView];
|
|
[self.backImageView addSubview:self.stateLabel];
|
|
[self.backImageView addSubview:self.micContainerView];
|
|
[self.backImageView addSubview:self.enterButton];
|
|
|
|
[self.micContainerView addSubview:self.fifImageView];
|
|
[self.micContainerView addSubview:self.fourImageView];
|
|
[self.micContainerView addSubview:self.thirdImageView];
|
|
[self.micContainerView addSubview:self.secondImageView];
|
|
[self.micContainerView addSubview:self.firstImageView];
|
|
self.micUserArray = @[self.firstImageView, self.secondImageView, self.thirdImageView, self.fourImageView, self.fifImageView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(74, 74));
|
|
make.centerY.mas_equalTo(self.backImageView).offset(-2);
|
|
make.left.mas_equalTo(self.contentView).offset(15);
|
|
}];
|
|
|
|
[self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.avatarImageView);
|
|
}];
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.avatarImageView).offset(26);
|
|
make.right.mas_equalTo(self.contentView).offset(-15);
|
|
make.height.mas_equalTo(98);
|
|
make.centerX.mas_equalTo(self.contentView).offset(-10);
|
|
}];
|
|
|
|
[self.roomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.backImageView).offset(56);
|
|
make.top.mas_equalTo(self.backImageView).offset(15);
|
|
}];
|
|
[self.gamenameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.roomTitleLabel);
|
|
make.top.mas_equalTo(self.roomTitleLabel.mas_bottom).offset(4);
|
|
}];
|
|
|
|
[self.gameLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.gamenameLabel.mas_right).offset(4);
|
|
make.centerY.mas_equalTo(self.gamenameLabel);
|
|
make.size.mas_equalTo(CGSizeMake(1, 9));
|
|
}];
|
|
|
|
[self.stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.gamenameLabel);
|
|
make.left.mas_equalTo(self.gameLineView.mas_right).offset(4);
|
|
}];
|
|
|
|
[self.enterButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(65, 24));
|
|
make.right.mas_equalTo(self.backImageView).offset(-15);
|
|
make.top.mas_equalTo(self.backImageView).offset(56);
|
|
}];
|
|
|
|
[self.micContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.backImageView).offset(-13);
|
|
make.height.mas_equalTo(16);
|
|
make.top.mas_equalTo(self.gamenameLabel.mas_bottom).offset(10);
|
|
make.left.mas_equalTo(self.fifImageView.mas_left).offset(-5);
|
|
}];
|
|
|
|
[self.firstImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(16, 16));
|
|
make.right.mas_equalTo(self.micContainerView);
|
|
make.centerY.mas_equalTo(self.micContainerView);
|
|
}];
|
|
|
|
[self.secondImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.centerY.mas_equalTo(self.firstImageView);
|
|
make.right.mas_equalTo(self.firstImageView.mas_left).offset(2);
|
|
}];
|
|
|
|
[self.thirdImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.centerY.mas_equalTo(self.firstImageView);
|
|
make.right.mas_equalTo(self.secondImageView.mas_left).offset(2);
|
|
}];
|
|
|
|
[self.fourImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.centerY.mas_equalTo(self.firstImageView);
|
|
make.right.mas_equalTo(self.thirdImageView.mas_left).offset(2);
|
|
}];
|
|
|
|
[self.fifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.centerY.mas_equalTo(self.firstImageView);
|
|
make.right.mas_equalTo(self.fourImageView.mas_left).offset(2);
|
|
}];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (void)setGameInfo:(HomeLittleGameRoomModel *)gameInfo {
|
|
_gameInfo = gameInfo;
|
|
if (_gameInfo) {
|
|
self.roomTitleLabel.text = _gameInfo.title;
|
|
self.avatarImageView.imageUrl = _gameInfo.avatar;
|
|
self.gamenameLabel.text = _gameInfo.mgName;
|
|
self.stateLabel.text = _gameInfo.state == 1 ? @"游戏中" : @"等待中";
|
|
if (_gameInfo.micUsers.count > 0) {
|
|
self.micContainerView.hidden = NO;
|
|
for (NSInteger i = 0; i < self.micUserArray.count; i++) {
|
|
NetImageView * imageView = [self.micUserArray objectAtIndex:i];
|
|
if (i< _gameInfo.micUsers.count) {
|
|
HomeLittleGameMicUserModel * micUserInfo = [_gameInfo.micUsers objectAtIndex:i];
|
|
imageView.imageUrl = micUserInfo.avatar;
|
|
imageView.hidden = NO;
|
|
} else {
|
|
imageView.hidden = YES;
|
|
}
|
|
}
|
|
} else {
|
|
self.micContainerView.hidden = YES;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 8;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UIImageView *)coverImageView {
|
|
if (!_coverImageView) {
|
|
_coverImageView = [[UIImageView alloc] init];
|
|
_coverImageView.userInteractionEnabled = YES;
|
|
_coverImageView.image = [UIImage imageNamed:@"home_party_little_game_cover"];
|
|
}
|
|
return _coverImageView;
|
|
}
|
|
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"home_party_little_game_content_bg"];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (UILabel *)roomTitleLabel {
|
|
if (!_roomTitleLabel) {
|
|
_roomTitleLabel = [[UILabel alloc] init];
|
|
_roomTitleLabel.font = [UIFont systemFontOfSize:14];
|
|
_roomTitleLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _roomTitleLabel;
|
|
}
|
|
|
|
- (UILabel *)gamenameLabel {
|
|
if (!_gamenameLabel) {
|
|
_gamenameLabel = [[UILabel alloc] init];
|
|
_gamenameLabel.font = [UIFont systemFontOfSize:10];
|
|
}
|
|
return _gamenameLabel;
|
|
}
|
|
|
|
- (UIView *)gameLineView {
|
|
if (!_gameLineView) {
|
|
_gameLineView = [[UIView alloc] init];
|
|
_gameLineView.backgroundColor = UIColorFromRGB(0xD8D8D8);
|
|
}
|
|
return _gameLineView;
|
|
}
|
|
|
|
- (UILabel *)stateLabel {
|
|
if (!_stateLabel) {
|
|
_stateLabel = [[UILabel alloc] init];
|
|
_stateLabel.font = [UIFont systemFontOfSize:10];
|
|
_stateLabel.textColor = [ThemeColor secondTextColor];
|
|
}
|
|
return _stateLabel;
|
|
}
|
|
|
|
|
|
- (UIButton *)enterButton {
|
|
if (!_enterButton) {
|
|
_enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_enterButton setTitle:@"进房" forState:UIControlStateNormal];
|
|
[_enterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_enterButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[_enterButton setImage:[UIImage imageNamed:@"home_party_little_game_enter"] forState:UIControlStateNormal];
|
|
[_enterButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xAF7CFF), UIColorFromRGB(0x5D57FD)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
_enterButton.layer.masksToBounds = YES;
|
|
_enterButton.layer.cornerRadius = 12;
|
|
_enterButton.userInteractionEnabled = NO;
|
|
}
|
|
return _enterButton;
|
|
}
|
|
|
|
- (UIView *)micContainerView {
|
|
if (!_micContainerView) {
|
|
_micContainerView = [[UIView alloc] init];
|
|
_micContainerView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _micContainerView;
|
|
}
|
|
|
|
- (NetImageView *)firstImageView {
|
|
if (!_firstImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_firstImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_firstImageView.layer.masksToBounds = YES;
|
|
_firstImageView.layer.cornerRadius = 8;
|
|
_firstImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_firstImageView.layer.borderWidth = 1;
|
|
_firstImageView.backgroundColor= [UIColor redColor];
|
|
}
|
|
return _firstImageView;
|
|
}
|
|
|
|
- (NetImageView *)secondImageView {
|
|
if (!_secondImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_secondImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_secondImageView.layer.masksToBounds = YES;
|
|
_secondImageView.layer.cornerRadius = 8;
|
|
_secondImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_secondImageView.layer.borderWidth = 1;
|
|
_secondImageView.backgroundColor= [UIColor yellowColor];
|
|
}
|
|
return _secondImageView;
|
|
}
|
|
|
|
- (NetImageView *)thirdImageView {
|
|
if (!_thirdImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_thirdImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_thirdImageView.layer.masksToBounds = YES;
|
|
_thirdImageView.layer.cornerRadius = 8;
|
|
_thirdImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_thirdImageView.layer.borderWidth = 1;
|
|
_thirdImageView.backgroundColor= [UIColor blueColor];
|
|
}
|
|
return _thirdImageView;
|
|
}
|
|
|
|
- (NetImageView *)fourImageView {
|
|
if (!_fourImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_fourImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_fourImageView.layer.masksToBounds = YES;
|
|
_fourImageView.layer.cornerRadius = 8;
|
|
_fourImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_fourImageView.layer.borderWidth = 1;
|
|
}
|
|
return _fourImageView;
|
|
}
|
|
|
|
|
|
- (NetImageView *)fifImageView {
|
|
if (!_fifImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_fifImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_fifImageView.layer.masksToBounds = YES;
|
|
_fifImageView.layer.cornerRadius = 8;
|
|
_fifImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_fifImageView.layer.borderWidth = 1;
|
|
}
|
|
return _fifImageView;
|
|
}
|
|
|
|
@end
|