Files
peko-ios/YuMi/Modules/YMRoom/View/Custom Background/CustomRoomBGContentViewController.m
2024-10-31 19:24:04 +08:00

513 lines
19 KiB
Objective-C

//
// CustomRoomBGContentViewController.m
// YuMi
//
// Created by P on 2024/10/29.
//
#import "CustomRoomBGContentViewController.h"
#import "SVGA.h"
#import "CustomRoomBGCell.h"
#import "CustomRoomBGPresenter.h"
@interface CustomRoomBGContentViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) UIView *bottomAreaBackGround;
@property (nonatomic, strong) UIView *emptyStateView;
@property (nonatomic, strong) UIButton *freeButton;
@property (nonatomic, strong) UIButton *payButton;
@property (nonatomic, strong) UIButton *customButton;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIView *previewMask;
@property (nonatomic, strong) UIImageView *previewFrontImageView;
@property (nonatomic, strong) NetImageView *previewBackImageView;
@property (nonatomic, strong) SVGAImageView *previewBackSvgaView;
@property (nonatomic, strong) UIView *previewBottomBackground;
@property (nonatomic, strong) UILabel *previewTipsContentLabel;
@property (nonatomic, strong) UIButton *previewActionButton;
@property (nonatomic, strong) UIButton *cancelPreviewButton;
@end
@implementation CustomRoomBGContentViewController
- (CustomRoomBGPresenter *)createPresenter {
return [[CustomRoomBGPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
[self didSelectedButton:self.freeButton];
}
- (void)setupUI {
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
[self setupBackgroundContent];
[self setupTopButtons];
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(50);
make.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(180 + 32 + 22));
}];
}
- (void)setupBackgroundContent {
[self.view addSubview:[self bottomAreaBackGround]];
UIButton *b = [self dismissButton];
[self.view addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.bottomAreaBackGround.mas_top).offset(-16);
}];
[self.view addSubview:self.emptyStateView];
[self.emptyStateView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(72);
make.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(26 + 110);
}];
}
- (void)setupTopButtons {
self.freeButton = [self bgCategoryButton:101];
self.payButton = [self bgCategoryButton:102];
self.customButton = [self bgCategoryButton:103];
[self.view addSubview:self.freeButton];
[self.freeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(10);
make.leading.mas_equalTo(15);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
[self.view addSubview:self.payButton];
[self.payButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.freeButton);
make.leading.mas_equalTo(self.freeButton.mas_trailing).offset(25);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
[self.view addSubview:self.customButton];
[self.customButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.freeButton);
make.leading.mas_equalTo(self.payButton.mas_trailing).offset(25);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
UIButton *helpButton = [self helpButton];
[self.view addSubview:helpButton];
[helpButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.freeButton);
make.trailing.mas_equalTo(self.view).offset(-15);
make.size.mas_equalTo(CGSizeMake(22, 22));
}];
UIButton *createButton = [self createCustomButton];
[self.view addSubview:createButton];
[createButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.freeButton);
make.trailing.mas_equalTo(helpButton.mas_leading).offset(-5);
make.size.mas_equalTo(CGSizeMake(82, 22));
}];
}
#pragma mark -
- (void)updateDataSource:(NSInteger)tag {
switch (tag) {
case 101:
break;
default:
break;
}
}
- (void)displayPreviewArea {
UIView *view = [self previewMask];
[self.view addSubview:view];
[self.view addSubview:self.previewBottomBackground];
[self.previewBottomBackground addSubview:self.previewTipsContentLabel];
[self.previewTipsContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.previewBottomBackground).offset(47);
make.leading.trailing.mas_equalTo(self.previewBottomBackground).inset(15);
}];
UIImageView *gold = [self goldIcon];
[self.previewBottomBackground addSubview:gold];
[gold mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.previewBottomBackground).offset(103);
make.leading.mas_equalTo(self.previewBottomBackground).offset(15);
make.size.mas_equalTo(CGSizeMake(26, 26));
}];
UILabel *pricePerDay = [self pricePerDayLabel];
[self.previewBottomBackground addSubview:pricePerDay];
[pricePerDay mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(gold);
make.leading.mas_equalTo(gold.mas_trailing).offset(4);
}];
[self.previewBottomBackground addSubview:self.previewActionButton];
[self.previewActionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(gold);
make.trailing.mas_equalTo(self.previewBottomBackground).offset(15);
make.size.mas_equalTo(CGSizeMake(120, 38));
}];
[self.view addSubview:self.previewFrontImageView];
[self.previewFrontImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.previewBottomBackground.mas_top).offset(-16);
make.top.mas_equalTo(100);
make.leading.trailing.mas_equalTo(self.view).inset(64);
}];
[self.view insertSubview:self.previewBackImageView belowSubview:self.previewFrontImageView];
[self.previewBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.previewFrontImageView);
}];
[self.view insertSubview:self.previewBackSvgaView belowSubview:self.previewFrontImageView];
[self.previewBackSvgaView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.previewFrontImageView);
}];
SVGAParser *_parser = [SVGAParser new];
@kWeakify(self);
[_parser parseWithNamed:@"Combo_Boom"
inBundle:nil
completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
// self.svgaVideoEntity = videoItem;
self.previewBackSvgaView.loops = 0;
// self.previewBackSvgaView.clearsAfterStop = NO;
self.previewBackSvgaView.videoItem = videoItem;
[self.previewBackSvgaView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
NSLog(@"%@", error);
}];
}
#pragma mark -
- (void)didTapEmptySpace {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didSelectedButton:(UIButton *)button {
self.freeButton.selected = NO;
self.payButton.selected = NO;
self.customButton.selected = NO;
button.selected = YES;
[self updateDataSource:button.tag];
}
- (void)didTapCreate {
}
- (void)didTapHelp {
}
- (void)didTapActionButton {
}
- (void)didTapCancelPreview {
}
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomRoomBGCell *cell = [CustomRoomBGCell reuseFrom:collectionView atIndexPath:indexPath];
@kWeakify(self);
[cell setHandleTapPlayButton:^(id _Nonnull obj) {
@kStrongify(self);
[self displayPreviewArea];
}];
return cell;
}
#pragma mark -
- (UIButton *)dismissButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setBackgroundColor:[UIColor clearColor]];
[b addTarget:self action:@selector(didTapEmptySpace) forControlEvents:UIControlEventTouchUpInside];
return b;
}
- (UIView *)bottomAreaBackGround {
if (!_bottomAreaBackGround) {
CGFloat height = kGetScaleWidth(323) + kSafeAreaBottomHeight;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenHeight - height, KScreenWidth, height)];
v.userInteractionEnabled = YES;
v.backgroundColor = [UIColor blackColor];
v.layer.cornerRadius = 16;
v.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
v.layer.masksToBounds = YES;
_bottomAreaBackGround = v;
}
return _bottomAreaBackGround;
}
- (UIButton *)bgCategoryButton:(NSInteger)tag {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.tag = tag;
// 设置普通状态字体
UIFont *normalFont = kFontRegular(15);
NSDictionary *normalAttributes = @{NSFontAttributeName: normalFont,
NSForegroundColorAttributeName: [UIColor colorWithWhite:1 alpha:0.6]};
NSAttributedString *normalTitle = [[NSAttributedString alloc] initWithString:[self titleForTag:tag]
attributes:normalAttributes];
[b setAttributedTitle:normalTitle forState:UIControlStateNormal];
// 设置选中状态字体
UIFont *selectedFont = kFontMedium(15);
NSDictionary *selectedAttributes = @{NSFontAttributeName: selectedFont,
NSForegroundColorAttributeName: [UIColor whiteColor]};
NSAttributedString *selectedTitle = [[NSAttributedString alloc] initWithString:[self titleForTag:tag]
attributes:selectedAttributes];
[b setAttributedTitle:selectedTitle forState:UIControlStateSelected];
[b addTarget:self
action:@selector(didSelectedButton:)
forControlEvents:UIControlEventTouchUpInside];
[b setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
[b setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
return b;
}
- (UIButton *)createCustomButton {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 82, 22);
[button setTitle:YMLocalizedString(@"1.0.18_4") forState:UIControlStateNormal];
[button.titleLabel setFont:kFontRegular(12)];
button.layer.cornerRadius = 11; // 设置圆角
button.clipsToBounds = YES; // 使圆角生效
// 创建渐变图层
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)UIColorFromRGB(0xE29030).CGColor,
(__bridge id)UIColorFromRGB(0xFCC074).CGColor];
gradientLayer.startPoint = CGPointMake(0.5, 0.0); // 顶部中央
gradientLayer.endPoint = CGPointMake(0.5, 1.0); // 底部中央
gradientLayer.frame = button.bounds; // 设置渐变图层大小
// 将渐变图层添加到按钮图层
[button.layer insertSublayer:gradientLayer atIndex:0];
[button addTarget:self
action:@selector(didTapCreate)
forControlEvents:UIControlEventTouchUpInside];
return button;
}
- (UIButton *)helpButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:kImage(@"custom_bg_help") forState:UIControlStateNormal];
[b addTarget:self
action:@selector(didTapHelp)
forControlEvents:UIControlEventTouchUpInside];
return b;
}
- (UIView *)emptyStateView {
if (!_emptyStateView) {
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 26 + 110)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImageConstant defaultEmptyPlaceholder_UFO]];
[v addSubview:imageView];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.mas_equalTo(v);
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(110), kGetScaleWidth(110)));
}];
UILabel *messageLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_5")
font:kFontRegular(14)
textColor:[UIColor colorWithWhite:1 alpha:0.4]];
messageLabel.textAlignment = NSTextAlignmentCenter;
[v addSubview:messageLabel];
[messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(v).inset(52);
make.top.mas_equalTo(imageView.mas_bottom).offset(6);
make.height.mas_equalTo(22);
}];
_emptyStateView = v;
}
return _emptyStateView;
}
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(kGetScaleWidth(135), kGetScaleWidth(180 + 32 + 22));
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 10;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.showsHorizontalScrollIndicator = NO;
[CustomRoomBGCell registerTo:_collectionView];
}
return _collectionView;
}
- (UIView *)previewMask {
UIView *v = [[UIView alloc] initWithFrame:self.view.bounds];
v.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
return v;
}
- (UIView *)previewBottomBackground {
if (!_previewBottomBackground) {
CGFloat height = kGetScaleWidth(174) + kSafeAreaBottomHeight;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenHeight - height, KScreenWidth, height)];
v.userInteractionEnabled = YES;
v.backgroundColor = [UIColor blackColor];
v.layer.cornerRadius = 16;
v.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
v.layer.masksToBounds = YES;
UILabel *tipsTitleLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_11")
font:kFontMedium(15)
textColor:[UIColor whiteColor]];
tipsTitleLabel.textAlignment = NSTextAlignmentCenter;
[v addSubview:tipsTitleLabel];
[tipsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(v).offset(13);
make.centerX.mas_equalTo(v);
}];
UIButton *b = [self cancelPreviewButton];
[v addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.top.mas_equalTo(15);
make.size.mas_equalTo(22);
}];
_previewBottomBackground = v;
}
return _previewBottomBackground;
}
- (NetImageView *)previewBackImageView {
if (!_previewBackImageView) {
_previewBackImageView = [[NetImageView alloc] init];
_previewBackImageView.layer.cornerRadius = 14;
_previewBackImageView.layer.masksToBounds = YES;
// _previewBackImageView.imageUrl = @"https://wx1.moyu.im/mw600/008ElFOcly1hv5oqfnpxtj30z07czx1k.jpg";
}
return _previewBackImageView;
}
- (SVGAImageView *)previewBackSvgaView {
if (!_previewBackSvgaView) {
_previewBackSvgaView = [[SVGAImageView alloc] init];
_previewBackSvgaView.layer.cornerRadius = 14;
_previewBackSvgaView.layer.masksToBounds = YES;
_previewBackSvgaView.autoPlay = YES;
}
return _previewBackSvgaView;
}
- (UIImageView *)previewFrontImageView {
if (!_previewFrontImageView) {
_previewFrontImageView = [[UIImageView alloc] initWithImage:kImage(@"custom_bg_preview")];
_previewFrontImageView.layer.cornerRadius = 14;
_previewFrontImageView.layer.masksToBounds = YES;
_previewFrontImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _previewFrontImageView;
}
- (UILabel *)previewTipsContentLabel {
if (!_previewTipsContentLabel) {
_previewTipsContentLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_12")
font:kFontMedium(15)
textColor:[UIColor colorWithWhite:1 alpha:0.6]];
_previewTipsContentLabel.numberOfLines = 0;
_previewTipsContentLabel.textAlignment = NSTextAlignmentCenter;
}
return _previewTipsContentLabel;
}
- (UIImageView *)goldIcon {
UIImageView *gold = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
return gold;
}
- (UILabel *)pricePerDayLabel {
UILabel *label = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_14")
font:kFontMedium(16)
textColor:UIColorFromRGB(0xFF8C03)];
return label;
}
- (UIButton *)previewActionButton {
if (!_previewActionButton) {
_previewActionButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_previewActionButton setTitle:YMLocalizedString(@"1.0.18_15")
forState:UIControlStateNormal];
_previewActionButton.layer.cornerRadius = 11;
_previewActionButton.layer.masksToBounds = YES;
[_previewActionButton addTarget:self
action:@selector(didTapActionButton)
forControlEvents:UIControlEventTouchUpInside];
}
return _previewActionButton;
}
- (UIButton *)cancelPreviewButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:kImage(@"common_nav_back_white") forState:UIControlStateNormal];
[b addTarget:self action:@selector(didTapCancelPreview) forControlEvents:UIControlEventTouchUpInside];
return b;
}
#pragma mark -
- (NSString *)titleForTag:(NSInteger)tag {
NSString *title = @"";
switch (tag) {
case 101:
title = YMLocalizedString(@"1.0.18_1");
break;
case 102:
title = YMLocalizedString(@"1.0.18_2");
break;
case 103:
title = YMLocalizedString(@"1.0.18_3");
break;
default:
break;
}
return title;
}
@end