// // QXDressSubViewController.m // QXLive // // Created by 启星 on 2025/5/16. // #import "QXDressSubViewController.h" #import "QXDressCell.h" #import "QXMineNetwork.h" #import "QXSeatHeaderView.h" #import "QXGiftPlayerManager.h" @interface QXDressSubViewController () @property (nonatomic,strong)QXSeatHeaderView *headerImageView; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)UIButton *commitBtn; @property (nonatomic,assign)NSInteger selectedIndex; @property (nonatomic,strong)QXEffectContentView *fullEffectView; @end @implementation QXDressSubViewController -(UIView *)listView{ return self.view; } -(void)listWillAppear{ [self getData]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)initSubViews{ self.bgImageHidden = YES; self.selectedIndex = -1; if (self.model.id.intValue == 1) { // 头像 [self.view addSubview:self.headerImageView]; self.collectionView.frame = CGRectMake(0, self.headerImageView.bottom+25, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44-self.headerImageView.bottom-25); }else{ self.collectionView.frame = CGRectMake(0, 12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44); } [self.view addSubview:self.collectionView]; [self.view addSubview:self.commitBtn]; [self.view addSubview:self.fullEffectView]; } -(void)getData{ MJWeakSelf [QXMineNetwork userDressListWithType:self.model.id successBlock:^(NSArray * _Nonnull list) { [weakSelf.dataArray removeAllObjects]; [weakSelf.dataArray addObjectsFromArray:list]; if (list.count > 0 ) { QXUserDressModel *model = [[QXUserDressModel alloc] init]; model.title = QXText(@"无"); model.udid = @"-1"; [weakSelf.dataArray insertObject:model atIndex:0]; } [weakSelf.collectionView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXDressCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXDressCell" forIndexPath:indexPath]; cell.model = self.dataArray[indexPath.row]; if (indexPath.row == self.selectedIndex) { cell.selecteBtn.selected = YES; }else{ cell.selecteBtn.selected = NO; } return cell; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ int width = (SCREEN_WIDTH-15*2-22*2-1)/3; return CGSizeMake(width, width/100*120); } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == self.selectedIndex) { return; } QXUserDressModel *model = self.dataArray[indexPath.row]; self.selectedIndex = indexPath.row; [collectionView reloadData]; // MJWeakSelf if ([self.model.id isEqualToString:@"2"]) { self.fullEffectView.hidden = NO; [self.fullEffectView previewEffectWith:model.play_image]; } [self.headerImageView setHeadIcon:[QXGlobal shareGlobal].loginModel.avatar dress:model.play_image]; } -(void)commitAction{ QXUserDressModel *model = self.dataArray[self.selectedIndex]; BOOL isCancel = NO; if ([model.udid isEqualToString:@"-1"]) { isCancel = YES; }else{ isCancel = NO; } MJWeakSelf [QXMineNetwork setUserDressIsCancel:isCancel udid:model.udid type:self.model.id successBlock:^(NSDictionary * _Nonnull dict) { if (weakSelf.model.id.intValue == 1) { [QXGlobal shareGlobal].loginModel.dress = model.play_image; [[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel]; } showToast(@"设置成功"); } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } -(UIButton *)commitBtn{ if (!_commitBtn) { _commitBtn = [[UIButton alloc] init]; _commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.view.height-NavContentHeight-44-kSafeAreaBottom-42-10, SCREEN_WIDTH-38*2, 42)]; [_commitBtn setTitle:QXText(@"确认装扮") forState:(UIControlStateNormal)]; [_commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; [_commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; [_commitBtn addRoundedCornersWithRadius:21]; _commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; _commitBtn.needEventInterval = 0.3; _commitBtn.backgroundColor = QXConfig.themeColor; } return _commitBtn; } -(UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 22; layout.minimumInteritemSpacing = 22; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.headerImageView.bottom+12+12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerNib:[UINib nibWithNibName:@"QXDressCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXDressCell"]; } return _collectionView; } -(QXSeatHeaderView *)headerImageView{ if (!_headerImageView) { _headerImageView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-104)/2, 24, 104, 104)]; [_headerImageView setHeadIcon:[QXGlobal shareGlobal].loginModel.avatar dress:[QXGlobal shareGlobal].loginModel.dress]; } return _headerImageView; } - (QXEffectContentView *)fullEffectView { if (!_fullEffectView) { _fullEffectView = [[QXEffectContentView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _fullEffectView.queue = dispatch_queue_create("qx_room_full_preview_message.com", NULL); _fullEffectView.hidden = YES; } return _fullEffectView; } @end