Files
yinmeng-ios/xplan-ios/Main/ModuleKit/FaceView/View/Cell/XCGameRoomFaceContainerCell.m
2022-03-10 18:55:18 +08:00

153 lines
5.5 KiB
Objective-C

//
// XCGameRoomFaceContainerCell.m
// XChat
//
// Created by 卫明何 on 2017/12/12.
// Copyright © 2017年 XC. All rights reserved.
//
#import "XCGameRoomFaceContainerCell.h"
#import "XCGameRoomFaceCell.h"
#import <Masonry/Masonry.h>
#import "XPFaceParser.h"
#import "NSArray+Lookin.h"
#import "TTPopup.h"
@interface XCGameRoomFaceContainerCell()
<UICollectionViewDelegate,
UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout
>
//@property (nonatomic, strong) UserInfo *userInfo;
@property (nonatomic, strong) NSIndexPath *currentIndexPath;
@end
@implementation XCGameRoomFaceContainerCell
- (void)awakeFromNib {
[super awakeFromNib];
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initView];
[self initConstrations];
}
return self;
}
- (void)initView {
[self.collectionView registerClass:[XCGameRoomFaceCell class] forCellWithReuseIdentifier:@"XCGameRoomFaceCell"];
[self.contentView addSubview:self.collectionView];
}
- (void)initConstrations {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView.mas_top);
make.leading.mas_equalTo(self.contentView.mas_leading);
make.trailing.mas_equalTo(self.contentView.mas_trailing);
make.bottom.mas_equalTo(self.contentView.mas_bottom);
}];
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.currentIndexPath = indexPath;
FaceConfigInfo *info = [self.faceInfos lookin_safeObjectAtIndex:indexPath.row];
if (self.curUserNobleLevel < info.faceVipInfo.vipLevel) {
[TTPopup dismiss];
NSString *message = [NSString stringWithFormat:@"尚未达到发送%@所需贵族等级,所需贵族等级:%@", info.name, info.faceVipInfo.vipName];
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
} cancelHandler:^{
}];
return;
}
if (![[XPFaceParser shareParser] getShowingFace]) {
if (self.delegate && [self.delegate respondsToSelector:@selector(onSelectFace:)]) {
[self.delegate onSelectFace:info];
}
}
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.faceInfos.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XCGameRoomFaceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"XCGameRoomFaceCell" forIndexPath:indexPath];
[self configureCell:cell forItemAtIndexPath:indexPath];
return cell;
}
- (void)configureCell:(XCGameRoomFaceCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
FaceConfigInfo *info = self.faceInfos[indexPath.row];
//读取图片
UIImage *face = [[XPFaceParser shareParser] findFaceIconImageById:info.id];
[cell.faceImageView setImage:face];
[cell.faceName setText:info.name];
if (info.faceVipInfo) {///贵族表情
cell.lockImageView.hidden = self.curUserNobleLevel >= info.faceVipInfo.vipLevel;
cell.nobleTagImageView.hidden = NO;
cell.nobleTagImageView.imageUrl = info.faceVipInfo.vipIcon;
} else {
cell.lockImageView.hidden = YES;
cell.nobleTagImageView.hidden = YES;
}
cell.lockImageView.hidden = self.curUserNobleLevel >= info.faceVipInfo.vipLevel;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake((self.frame.size.width - 20) / 5, self.frame.size.height / 3);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0.01;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0.01;
}
- (void)setFaceInfos:(NSMutableArray<FaceConfigInfo *> *)faceInfos{
_faceInfos = faceInfos;
[self.collectionView reloadData];
}
- (void)setCurUserNobleLevel:(NSInteger)curUserNobleLevel {
_curUserNobleLevel = curUserNobleLevel;
[self.collectionView reloadData];
}
#pragma mark - RoomQueueCoreClient
- (void)onMicroQueueUpdate:(NSMutableDictionary *)micQueue{
// [[GetCore(UserCore) getUserInfoByRac:GetCore(AuthCore).getUid.userIDValue refresh:NO] subscribeNext:^(id x) {
// self.userInfo = (UserInfo *)x;
// }];
}
#pragma mark - Getter & Setter
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flow];
_collectionView.scrollEnabled = NO;
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = [UIColor clearColor];
}
return _collectionView;
}
@end