Files
peko-ios/YuMi/Modules/YMRoom/View/SendGiftView/View/PIGiftInfoSegmentedView.m
eggmanQQQ fb30106c63 -- 客户端“我的装扮”入口
-- 礼物面板 API 调试
-- 礼物面板调整
2024-08-02 21:09:02 +08:00

475 lines
18 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PIGiftInfoSegmentedView.m
// YuMi
//
// Created by duoban on 2023/11/9.
//
#import "PIGiftInfoSegmentedView.h"
#import <JXCategoryView/JXCategoryView.h>
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
#import <JXCategoryView/JXCategoryListContainerView.h>
#import "ThemeColor+SendGift.h"
#import "XPGiftInfoView.h"
@interface PIGiftInfoSegmentedView()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate,XPGiftInfoViewDelegate,XPGiftInfoViewDelegate>
///分页标题
@property (nonatomic, strong) NSArray<NSString *> *pi_titles;
///导航条背景
@property (nonatomic,strong) UIImageView *segmentBgView;
///分页控件
@property (nonatomic, strong) JXCategoryTitleView *titleView;
///分页lineView
@property (nonatomic, strong) JXCategoryListContainerView *pi_containerView;
/////背包总价值
//@property (nonatomic,strong) UILabel *totalValueLabel;
///背包礼物
@property (nonatomic,strong) UIButton *packGiftButton;
///背包礼物面板
@property(nonatomic,strong) XPGiftInfoView *packGiftView;
///礼物数据
@property(nonatomic,strong) NSMutableArray *giftList;
///最后一次选中的礼物
@property (nonatomic,strong) GiftInfoModel *lastSelectGift;
///当前展示的数据的类型
@property (nonatomic,assign) GiftSegmentType segmentType;
///普通
@property (nonatomic,strong)XPGiftInfoView *normalVC;
///幸运
@property (nonatomic,strong)XPGiftInfoView *luckyVC;
///周星
@property (nonatomic,strong)XPGiftInfoView *weekStarVC;
///VIP
@property (nonatomic,strong)XPGiftInfoView *nobleVC;
///人气
@property (nonatomic,strong)XPGiftInfoView *anchorVC;
@property (nonatomic, strong) UIActivityIndicatorView *loadingView;
@end
@implementation PIGiftInfoSegmentedView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
self.segmentType = GiftSegmentType_Normal;
[self installUI];
[self installConstraints];
[self showLoading];
}
return self;
}
- (void)showLoading {
if (!_loadingView) {
_loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_loadingView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_loadingView];
[NSLayoutConstraint activateConstraints:@[
[_loadingView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[_loadingView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor]
]];
}
[self.loadingView startAnimating];
self.loadingView.hidden = NO;
}
- (void)hideLoading {
if (_loadingView) {
[self.loadingView stopAnimating];
self.loadingView.hidden = YES;
}
}
-(void)installUI{
[self addSubview:self.segmentBgView];
[self addSubview:self.titleView];
[self addSubview:self.pi_containerView];
[self addSubview:self.packGiftButton];
[self addSubview:self.packGiftView];
}
-(void)installConstraints{
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(44+108 * 2 + 10 + 10 + 15);
}];
[self.segmentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.equalTo(self);
make.height.mas_equalTo(44);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.equalTo(self);
make.height.mas_equalTo(34);
make.width.mas_equalTo(kGetScaleWidth(200));
}];
[self.packGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-15);
make.centerY.mas_equalTo(self.titleView);
make.size.mas_equalTo(CGSizeMake(14, 14));
}];
[self.pi_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self);
make.top.equalTo(self.titleView.mas_bottom).mas_offset(kGetScaleWidth(0));
}];
[self.packGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.pi_containerView);
}];
}
#pragma mark - JXCategoryViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.pi_titles.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
XPGiftInfoView *vc = [self getListVC:index];
if(vc.segmentType == GiftSegmentType_Noble){
vc.curUserNobleLevel = self.curUserNobleLevel;
}
vc.usingPlaceType = self.usingPlaceType;
vc.normalOriginArray = [self.giftList xpSafeObjectAtIndex:index];
return vc;
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
if (self.usingPlaceType == SendGiftType_User) {
self.titleView.titleColor = [DJDKMIMOMColor secondTextColor];
self.titleView.titleSelectedColor = [DJDKMIMOMColor mainTextColor];
[self.packGiftButton setTitleColor:[DJDKMIMOMColor secondTextColor] forState:UIControlStateNormal];
}else {
[self.packGiftButton setTitleColor:[DJDKMIMOMColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
self.titleView.titleColor = [DJDKMIMOMColor giftSegmentNormalTitleColor];
self.titleView.titleSelectedColor = [DJDKMIMOMColor giftSegmentSelectTitleColor];
}
[self.titleView reloadData];
self.pi_containerView.hidden = NO;
self.packGiftView.hidden = YES;
// self.totalValueLabel.hidden = YES;
XPGiftInfoView *vc = [self getListVC:index];
self.segmentType = vc.segmentType;
if(self.delegate && [self.delegate respondsToSelector:@selector(pIGiftInfoSegmentedView:didClickSegment:)]){
[self.delegate pIGiftInfoSegmentedView:self didClickSegment:self.segmentType];
}
if(self.segmentType == GiftSegmentType_WeekStar){
if(self.delegate && [self.delegate respondsToSelector:@selector(pIGiftInfoSegmentedView:didClickItem:type:)]){
[self.delegate pIGiftInfoSegmentedView:self didClickItem:vc.lastSelectGift type:self.segmentType];
}
}
}
-(XPGiftInfoView *)getListVC:(NSInteger)index{
if(self.usingPlaceType == SendGiftType_User){
return [@[self.normalVC,self.weekStarVC,self.nobleVC] xpSafeObjectAtIndex:index];
}
if(self.roomType == RoomType_Anchor){
return [@[self.normalVC,self.luckyVC,self.weekStarVC,self.nobleVC,self.anchorVC] xpSafeObjectAtIndex:index];
}
return [@[self.normalVC,self.luckyVC,self.weekStarVC,self.nobleVC] xpSafeObjectAtIndex:index];
}
-(NSInteger)getIndex{
if(self.usingPlaceType == SendGiftType_User){
if(self.segmentType == GiftSegmentType_Normal){
return 0;
}else if (self.segmentType == GiftSegmentType_WeekStar){
return 1;
}else{
return 2;
}
}
if(self.roomType == RoomType_Anchor){
NSString *index = [@[@"0",@"1",@"2",@"3",@"4"] xpSafeObjectAtIndex:self.segmentType];
return index.integerValue;
}
NSString *index = [@[@"0",@"1",@"2",@"3"] xpSafeObjectAtIndex:self.segmentType];
return index.integerValue;
}
-(void)didClickGiftSegmentAction:(UIButton *)sender{
if (self.usingPlaceType == SendGiftType_User) {
[self.packGiftButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
self.titleView.titleColor = [DJDKMIMOMColor secondTextColor];
self.titleView.titleSelectedColor = [DJDKMIMOMColor secondTextColor];
}else {
[self.packGiftButton setTitleColor:[DJDKMIMOMColor giftSegmentSelectTitleColor] forState:UIControlStateNormal];
self.titleView.titleColor = [DJDKMIMOMColor giftSegmentNormalTitleColor];
self.titleView.titleSelectedColor = [DJDKMIMOMColor giftSegmentNormalTitleColor];
}
[self.titleView reloadData];
self.packGiftView.hidden = NO;
self.pi_containerView.hidden = YES;
self.segmentType = GiftSegmentType_Pack;
if(self.delegate && [self.delegate respondsToSelector:@selector(pIGiftInfoSegmentedView:didClickSegment:)]){
[self.delegate pIGiftInfoSegmentedView:self didClickSegment:self.segmentType];
}
}
/**
将数量格式化为字符串 万之后用xx.xxW显示并保留小数点2位最多显示9999W+
@param number 数值
@return 格式化后的字符串
*/
- (NSString *)countFormatCoinStr:(NSInteger)number {
NSString *numStr = [NSString stringWithFormat:@"%li", number];
NSInteger num = number;
if (num > 99990000) {
numStr = @"99990k+";
} else if (num >= 10000) {
CGFloat numF = num / 1000.0;
numStr = [NSString stringWithFormat:@"%.0fk+", numF];
}
return numStr;
}
- (void)setTagsArray:(NSArray<GiftPanelTabModel *> *)tagsArray {
[self hideLoading];
_tagsArray = tagsArray;
NSMutableArray *tempTitles = @[].mutableCopy;
NSMutableArray *tempGifts = @[].mutableCopy;
for (GiftPanelTabModel *tab in tagsArray) {
// 聊天界面不显示 幸运/个播 礼物
if (self.usingPlaceType == SendGiftType_User && ([tab.key isEqualToString:@"luckyBagGift"] || [tab.key isEqualToString:@"superLuckyGift"] || [tab.key isEqualToString:@"singlePopularGift"])) {
continue;
}
if (isMSRTL()) {
[tempTitles addObject:tab.nameMap.ar];
} else if (isMSEN()) {
[tempTitles addObject:tab.nameMap.en];
} else {
[tempTitles addObject:tab.nameMap.zh];
}
[tempGifts addObject:tab.gifts ? tab.gifts : @[]];
}
self.pi_titles = tempTitles.copy;
self.titleView.titles = self.pi_titles;
self.giftList = tempGifts;
[self.titleView reloadData];
// @kWeakify(self);
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// @kStrongify(self);
[self.pi_containerView reloadData];
// });
}
- (void)setNormalOriginArray:(NSArray *)normalOriginArray {
[self hideLoading];
_normalOriginArray = normalOriginArray;
// __block NSMutableArray * normalArray = [NSMutableArray array];
// __block NSMutableArray * luckyArray = [NSMutableArray array];
// __block NSMutableArray * weekStarArray = [NSMutableArray array];
// __block NSMutableArray * nobleArray = [NSMutableArray array];
// __block NSMutableArray * anchorArray = [NSMutableArray array];
// [self.normalOriginArray enumerateObjectsUsingBlock:^(GiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// if (obj.giftType == GiftType_Lucky || obj.giftType == GiftType_super) {
// [luckyArray addObject:obj];
// } else if(obj.giftType == GiftType_Game) {
// [normalArray addObject:obj];
// } else if (obj.giftType == GiftType_Noble) {
// [nobleArray addObject:obj];
// } else if (obj.giftType == GiftType_WeekStar) {
// [weekStarArray addObject:obj];
// }else if(obj.giftType == GiftType_Anchor){
// [anchorArray addObject:obj];
// }
// }];
// if (self.usingPlaceType == SendGiftType_User) {
// _giftList = [[NSMutableArray alloc]initWithArray:@[normalArray, weekStarArray, nobleArray]];
// }else{
// _giftList = [[NSMutableArray alloc]initWithArray:@[normalArray, luckyArray, weekStarArray, nobleArray, anchorArray]];
// }
// @kWeakify(self);
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// @kStrongify(self);
// [self.pi_containerView reloadData];
// });
}
-(void)setPackOriginArray:(NSArray *)packOriginArray{
_packOriginArray = packOriginArray;
self.packGiftView.packOriginArray = packOriginArray;
}
-(void)setFreeModel:(XPFreeGiftModel *)freeModel{
_freeModel = freeModel;
self.packGiftView.freeModel = freeModel;
}
- (void)setIsDelFreeGift:(BOOL)isDelFreeGift{
_isDelFreeGift = isDelFreeGift;
self.packGiftView.isDelFreeGift = _isDelFreeGift;
}
-(void)setRoomType:(RoomType)roomType{
_roomType = roomType;
// if(_roomType == RoomType_Anchor){
// self.pi_titles = @[YMLocalizedString(@"XPGiftInfoView2"),
// YMLocalizedString(@"XPGiftInfoView3"),
// YMLocalizedString(@"XPGiftInfoView4"),
// YMLocalizedString(@"XPGiftInfoView9"),
// YMLocalizedString(@"XPGiftInfoView8")];
//
// self.titleView.titles = self.pi_titles;
//
// [self.titleView reloadData];
// }
}
- (void)setUsingPlaceType:(SendGiftType)usingPlaceType {
_usingPlaceType = usingPlaceType;
self.packGiftView.usingPlaceType = _usingPlaceType;
if (_usingPlaceType == SendGiftType_User) {
// self.pi_titles = @[YMLocalizedString(@"XPGiftInfoView2"),
// YMLocalizedString(@"XPGiftInfoView4"),
// YMLocalizedString(@"XPGiftInfoView9")];
// self.titleView.titles = self.pi_titles;
// [self.titleView reloadData];
self.titleView.titleColor = [DJDKMIMOMColor secondTextColor];
self.titleView.titleSelectedColor = [DJDKMIMOMColor mainTextColor];
self.segmentBgView.hidden = NO;
[self.packGiftButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateSelected];
[self.packGiftButton setTitleColor:[DJDKMIMOMColor secondTextColor] forState:UIControlStateNormal];
}
}
///送背包礼物更新数据源
- (void)updatePackSource:(GiftReceiveInfoModel *)giftReceiveInfo numberUser:(NSInteger)numberUser{
[self.packGiftView updatePackSource:giftReceiveInfo numberUser:numberUser];
}
#pragma mark- XPGiftInfoViewDelegate
///点击了某个item
- (void)xPGiftInfoView:(XPGiftInfoView *)view didClickItem:(GiftInfoModel *)info type:(GiftSegmentType)type{
if(self.delegate && [self.delegate respondsToSelector:@selector(pIGiftInfoSegmentedView:didClickItem:type:)]){
[self.delegate pIGiftInfoSegmentedView:self didClickItem:info type:type];
}
}
#pragma mark - 懒加载
- (GiftInfoModel *)lastSelectGift{
if(_segmentType == GiftSegmentType_Pack){
return _packGiftView.lastSelectGift;
}
XPGiftInfoView *vc = [self getListVC:[self getIndex]];
return vc.lastSelectGift;
}
- (NSArray<NSString *> *)pi_titles{
if(!_pi_titles){
// _pi_titles = @[YMLocalizedString(@"XPGiftInfoView2"),YMLocalizedString(@"XPGiftInfoView3"),YMLocalizedString(@"XPGiftInfoView4"),YMLocalizedString(@"XPGiftInfoView9")];
_pi_titles = @[];
}
return _pi_titles;
}
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.pi_titles;
_titleView.backgroundColor = [UIColor clearColor];
_titleView.titleColor = [DJDKMIMOMColor giftSegmentNormalTitleColor];
_titleView.titleSelectedColor = [DJDKMIMOMColor giftSegmentSelectTitleColor];
_titleView.titleFont = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_titleView.titleSelectedFont = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.defaultSelectedIndex = 0;
_titleView.cellSpacing = 0;
_titleView.cellWidthIncrement = 5;
// _titleView.cellWidth = 30;
_titleView.listContainer = self.pi_containerView;
}
return _titleView;
}
- (JXCategoryListContainerView *)pi_containerView {
if (!_pi_containerView) {
_pi_containerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_pi_containerView.defaultSelectedIndex = 0;
_pi_containerView.scrollView.tag = 1009;
_pi_containerView.scrollView.scrollEnabled = NO;
}
return _pi_containerView;
}
- (UIButton *)packGiftButton {
if (!_packGiftButton) {
_packGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_packGiftButton setBackgroundImage:[UIImage imageNamed:@"gift_bag_icon"] forState:UIControlStateNormal];
_packGiftButton.tag = GiftSegmentType_Pack;
[_packGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
[_packGiftButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _packGiftButton;
}
- (XPGiftInfoView *)packGiftView{
if(!_packGiftView){
_packGiftView = [[XPGiftInfoView alloc]initWithFrame:CGRectZero];
_packGiftView.segmentType = GiftSegmentType_Pack;
_packGiftView.delegate = self;
_packGiftView.hidden = YES;
}
return _packGiftView;
}
- (UIImageView *)segmentBgView {
if (!_segmentBgView) {
_segmentBgView = [[UIImageView alloc] init];
_segmentBgView.userInteractionEnabled = YES;
_segmentBgView.contentMode = UIViewContentModeScaleAspectFill;
_segmentBgView.image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor colorWithHexString:@"#E5FFFF"], [DJDKMIMOMColor colorWithHexString:@"#FFFFFF"]] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(KScreenWidth, 44)];
_segmentBgView.hidden = YES;
}
return _segmentBgView;
}
- (XPGiftInfoView *)normalVC{
if(!_normalVC){
_normalVC = [[XPGiftInfoView alloc]init];
_normalVC.delegate = self;
_normalVC.segmentType = GiftSegmentType_Normal;
}
return _normalVC;;
}
- (XPGiftInfoView *)luckyVC{
if(!_luckyVC){
XPGiftInfoView *luckyVC = [[XPGiftInfoView alloc]init];
luckyVC.delegate = self;
luckyVC.segmentType = GiftSegmentType_Lucky;
_luckyVC = luckyVC;
}
return _luckyVC;
}
- (XPGiftInfoView *)weekStarVC{
if(!_weekStarVC){
XPGiftInfoView *weekStarVC = [[XPGiftInfoView alloc]init];
weekStarVC.delegate = self;
weekStarVC.segmentType = GiftSegmentType_WeekStar;
_weekStarVC = weekStarVC;
}
return _weekStarVC;
}
- (XPGiftInfoView *)nobleVC{
if(!_nobleVC){
XPGiftInfoView *nobleVC = [[XPGiftInfoView alloc]init];
nobleVC.delegate = self;
nobleVC.segmentType = GiftSegmentType_Noble;
_nobleVC = nobleVC;
}
return _nobleVC;
}
-(XPGiftInfoView *)anchorVC{
if(!_anchorVC){
XPGiftInfoView *anchorVC = [[XPGiftInfoView alloc]init];
anchorVC.delegate = self;
anchorVC.segmentType = GiftSegmentType_Anchor;
_anchorVC = anchorVC;
}
return _anchorVC;;
}
@end