diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index b0a99711..ed525513 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -845,6 +845,7 @@ E8E20BE828169BDC0033B688 /* XPMineLoginPasswordPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E20BE728169BDC0033B688 /* XPMineLoginPasswordPresenter.m */; }; E8E20BEC2816A5B90033B688 /* XPMineBlackListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E20BEB2816A5B90033B688 /* XPMineBlackListViewController.m */; }; E8E20BEF2816A5FC0033B688 /* XPMineBlackListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E20BEE2816A5FC0033B688 /* XPMineBlackListTableViewCell.m */; }; + E8E21A9B28B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E21A9A28B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.m */; }; E8E5E18B27C332EE00F457D8 /* XPHomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E5E18A27C332EE00F457D8 /* XPHomeViewController.m */; }; E8E5E18E27C3331E00F457D8 /* XPHomeRecommendViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E5E18D27C3331E00F457D8 /* XPHomeRecommendViewController.m */; }; E8E5E19127C369F000F457D8 /* XPHomeRecommendListView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8E5E19027C369F000F457D8 /* XPHomeRecommendListView.m */; }; @@ -2619,6 +2620,8 @@ E8E20BEB2816A5B90033B688 /* XPMineBlackListViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineBlackListViewController.m; sourceTree = ""; }; E8E20BED2816A5FC0033B688 /* XPMineBlackListTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineBlackListTableViewCell.h; sourceTree = ""; }; E8E20BEE2816A5FC0033B688 /* XPMineBlackListTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineBlackListTableViewCell.m; sourceTree = ""; }; + E8E21A9928B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPRoomGraffitiGiftAnimationView.h; sourceTree = ""; }; + E8E21A9A28B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPRoomGraffitiGiftAnimationView.m; sourceTree = ""; }; E8E5E18927C332EE00F457D8 /* XPHomeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPHomeViewController.h; sourceTree = ""; }; E8E5E18A27C332EE00F457D8 /* XPHomeViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPHomeViewController.m; sourceTree = ""; }; E8E5E18C27C3331E00F457D8 /* XPHomeRecommendViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPHomeRecommendViewController.h; sourceTree = ""; }; @@ -4968,6 +4971,8 @@ E8998D7F28597B0300C68558 /* XPRoomLuckyBigPrizeView.m */, E838D99E275E1BF60079E0B5 /* XPRoomAnimationView.h */, E838D99F275E1BF60079E0B5 /* XPRoomAnimationView.m */, + E8E21A9928B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.h */, + E8E21A9A28B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.m */, 9BC9DAED27E33B3F009EE409 /* XPRoomGiftAnimationParser.h */, 9BC9DAEE27E33B3F009EE409 /* XPRoomGiftAnimationParser.m */, ); @@ -8119,6 +8124,7 @@ 9BE9F10227FEE5C200667200 /* XPAnchorFansTaskDetailModel.m in Sources */, E8E0DAE6285C280E00566A2F /* XPSessionFindNewAlertView.m in Sources */, E86596542701A55500846EBD /* StatisticsServiceHelper.m in Sources */, + E8E21A9B28B4BD92008F7C9D /* XPRoomGraffitiGiftAnimationView.m in Sources */, E8E70D8C26F2F5A500F03460 /* XPMineHeadItemCollectionViewCell.m in Sources */, E883E82E28153BDF0000005D /* XPGuildAnchorIncomeSectionView.m in Sources */, 9B17F71827BD150600440843 /* SVGAParserManager.m in Sources */, diff --git a/xplan-ios/Main/IM/Model/AttachmentModel.h b/xplan-ios/Main/IM/Model/AttachmentModel.h index 9d47513c..41535e87 100644 --- a/xplan-ios/Main/IM/Model/AttachmentModel.h +++ b/xplan-ios/Main/IM/Model/AttachmentModel.h @@ -86,6 +86,8 @@ typedef NS_ENUM(NSUInteger, CustomMessageType) { CustomMessageType_Task_Complete = 92, ///礼物合成 CustomMessageType_Gift_Compound = 93, + ///涂鸦礼物 + CustomMessageType_Graffiti_Gift = 94, }; @@ -458,6 +460,12 @@ typedef NS_ENUM(NSUInteger, CustomMessageGiftCompound) { Custom_Message_Sub_Gift_Compound = 931, }; +///first = CustomMessageType_Graffiti_Gift +typedef NS_ENUM(NSUInteger, CustomMessageGraffitiGift) { + ///涂鸦礼物 + Custom_Message_Sub_Graffiti_Gift = 941, +}; + @interface AttachmentModel : NSObject @property (nonatomic,assign) int first; @property (nonatomic,assign) int second; diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/Model/GiftInfoModel.h b/xplan-ios/Main/ModuleKit/SendGiftView/Model/GiftInfoModel.h index 3630ac71..7e2bad2f 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/Model/GiftInfoModel.h +++ b/xplan-ios/Main/ModuleKit/SendGiftView/Model/GiftInfoModel.h @@ -17,6 +17,7 @@ typedef NS_ENUM(NSUInteger, GiftType) { GiftType_LuckyPool = 5, //福袋奖池礼物 GiftType_Noble = 7, // 贵族礼物 GiftType_WeekStar = 8, //周星礼物 + GiftType_Graffiti = 10, //涂鸦礼物 }; //礼物类型 diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/Presenter/XPGiftPresenter.m b/xplan-ios/Main/ModuleKit/SendGiftView/Presenter/XPGiftPresenter.m index 96124243..73725e44 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/Presenter/XPGiftPresenter.m +++ b/xplan-ios/Main/ModuleKit/SendGiftView/Presenter/XPGiftPresenter.m @@ -62,12 +62,14 @@ NSArray *luckyPoolGift = [GiftInfoModel modelsWithArray:data.data[@"luckyPoolGift"]];// 福袋奖池礼物 NSArray *normalGift = [GiftInfoModel modelsWithArray:data.data[@"normalGift"]]; // 普通面板礼物 NSArray *weekStarGift = [GiftInfoModel modelsWithArray:data.data[@"weekStarGift"]]; // 周星礼物 + NSArray *drawGift = [GiftInfoModel modelsWithArray:data.data[@"drawGift"]]; // 涂鸦礼物 NSMutableArray *info = [NSMutableArray array]; NSMutableArray *totalInfo = [NSMutableArray array]; [info addObjectsFromArray:luckyBagGift]; [info addObjectsFromArray:vipGift]; [info addObjectsFromArray:normalGift]; [info addObjectsFromArray:weekStarGift]; + [info addObjectsFromArray:drawGift]; [totalInfo addObjectsFromArray:info]; [totalInfo addObjectsFromArray:luckyPoolGift]; ///把礼物信息保存一下 diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m index b1c8f76b..32254892 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m +++ b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m @@ -23,7 +23,8 @@ #import "XPWeekStarInfoView.h" @interface XPGiftInfoView () -/// +///滚动的容器 +@property (nonatomic,strong) UIScrollView *scrollView; @property (nonatomic,strong) UIStackView *segmentStackView; ///普通礼物 @property (nonatomic,strong) UIButton *normalGiftButton; @@ -131,8 +132,10 @@ #pragma mark - Private Method - (void)initSubViews { - [self addSubview:self.segmentStackView]; + [self addSubview:self.scrollView]; [self addSubview:self.giftStackView]; + + [self.scrollView addSubview:self.segmentStackView]; ///分段控制 [self.segmentStackView addArrangedSubview:self.normalGiftButton]; [self.segmentStackView addArrangedSubview:self.luckyGiftButton]; @@ -154,9 +157,12 @@ [self mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(30 + 108 * 2 + 10 + 10 + 15); }]; - - - [self.segmentStackView mas_makeConstraints:^(MASConstraintMaker *make) { + + [self.segmentStackView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.bottom.leading.trailing.height.mas_equalTo(self.scrollView); + }]; + + [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self).inset(15); make.top.mas_equalTo(self); make.height.mas_equalTo(30); @@ -394,6 +400,10 @@ if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickSegment:)]) { [self.delegate xPGiftInfoView:self didClickSegment:_segmentType]; } + + if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickItem:type:)]) { + [self.delegate xPGiftInfoView:self didClickItem:self.lastSelectGift type:_segmentType]; + } } - (void)setNormalOriginArray:(NSArray *)normalOriginArray { @@ -402,6 +412,7 @@ NSMutableArray * normaleArray = [NSMutableArray array]; NSMutableArray * nobleArray = [NSMutableArray array]; NSMutableArray * weekStarArray = [NSMutableArray array]; + NSMutableArray * graffiti = [NSMutableArray array]; [_normalOriginArray enumerateObjectsUsingBlock:^(GiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.giftType == GiftType_Lucky) { [luckyArray addObject:obj]; @@ -411,13 +422,15 @@ [nobleArray addObject:obj]; } else if (obj.giftType == GiftType_WeekStar) { [weekStarArray addObject:obj]; - } + } else if (obj.giftType == GiftType_Graffiti) { + [graffiti addObject:obj]; +} }]; self.giftArray = normaleArray; self.giftLuckyArray = luckyArray; self.giftNobleArray = nobleArray; self.giftWeekStarArray = weekStarArray; - self.giftGraffitiArray = luckyArray; + self.giftGraffitiArray = graffiti; if (self.defaultSelectGiftId.length) { for (GiftInfoModel *gift in self.normalOriginArray) { if (gift.giftId == [self.defaultSelectGiftId integerValue]) { @@ -469,6 +482,7 @@ _usingplaceType = usingplaceType; if (_usingplaceType == SendGiftType_User) { self.luckyGiftButton.hidden = YES; + self.graffitiButton.hidden = YES; } } @@ -669,5 +683,14 @@ return _datasource; } +- (UIScrollView *)scrollView { + if (!_scrollView) { + _scrollView = [[UIScrollView alloc] init]; + _scrollView.backgroundColor = [UIColor clearColor]; + _scrollView.showsHorizontalScrollIndicator = NO; + } + return _scrollView; +} + @end diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.h b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.h index 7ac12fe2..87f994f8 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.h +++ b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.h @@ -8,9 +8,24 @@ #import NS_ASSUME_NONNULL_BEGIN +@class XPGraffitiGiftView; +@protocol XPGraffitiGiftViewDelegate +///点击切换 +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickChange:(UILabel *)sender; +///点击了关闭 +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickClose:(UIButton *)sender; +///绘画完成了 +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didDrawCompletion:(NSArray *)pointArray; +@end @interface XPGraffitiGiftView : UIView @property (nonatomic,strong) UIImage *image; +///代理 +@property (nonatomic,weak) id delegate; +///价格 +@property (nonatomic,assign) double price; +///动画的数据 +@property (nonatomic,strong) NSArray *animationArray; @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.m b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.m index f9a11620..ca37bf1d 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.m +++ b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.m @@ -11,10 +11,14 @@ ///Tool #import "ThemeColor.h" #import "XPMacro.h" +#import "XCHUDTool.h" +#import "XPHomeGradientLabel.h" @interface XPGraffitiGiftView () ///回话的内容 @property (nonatomic,strong) UIView * contentView; +///绘画的view +@property (nonatomic,strong) UIView * drawView; ///类型 @property (nonatomic,strong) UIStackView *tipsStackView; ///✋🏻 @@ -28,23 +32,27 @@ ///类型 @property (nonatomic,strong) UIStackView *toolStackView; ///切换 -@property (nonatomic,strong) UIButton *changeButton; +@property (nonatomic,strong) XPHomeGradientLabel *changeButton; ///撤销 @property (nonatomic,strong) UIButton *repealButton; ///删除 @property (nonatomic,strong) UIButton *deleteButton; ///关闭 @property (nonatomic,strong) UIButton *closeButton; - +///手指滑动的point @property (nonatomic,assign) CGPoint panPoint; -/// +///开始的point @property (nonatomic,assign) CGPoint beginPoint; -/// +///两个涂鸦的间距 @property (nonatomic,assign) CGFloat step; /// -@property (nonatomic,strong) NSMutableArray *datasource; -/// @property (nonatomic,assign) int index; +///是否展示超过最大值的 +@property (nonatomic,assign) BOOL isShowMaxToast; +@property (nonatomic,strong) NSMutableArray *viewsArray; +@property (nonatomic,strong) NSMutableArray *indexArray; +@property (nonatomic,strong) NSMutableArray *> *pointArray; + @end @implementation XPGraffitiGiftView @@ -60,12 +68,15 @@ #pragma mark - Private Method - (void)initSubViews { - self.step = 20; + self.isShowMaxToast = YES; + self.step = 10; UIPanGestureRecognizer * panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [self addGestureRecognizer:panGes]; self.backgroundColor = [UIColor clearColor]; [self addSubview:self.contentView]; + [self.contentView addSubview:self.tipsStackView]; + [self.contentView addSubview:self.drawView]; [self.contentView addSubview:self.toolView]; [self.tipsStackView addArrangedSubview:self.handImageView]; @@ -98,6 +109,11 @@ make.width.mas_equalTo(KScreenWidth); }]; + [self.drawView mas_makeConstraints:^(MASConstraintMaker *make) { + make.top.mas_equalTo(self.contentView).offset(kSafeAreaTopHeight); + make.left.right.mas_equalTo(self.contentView); + make.bottom.mas_equalTo(self.toolView.mas_top); + }]; [self.handImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(78, 93)); @@ -142,12 +158,23 @@ UITouch *touch = touches.anyObject; CGPoint point = [touch locationInView:self.contentView]; self.beginPoint = point; - NSLog(@"beginPoint:X:%.2f, Y:%.2f", point.x, point.y); } - (void)panAction:(UIPanGestureRecognizer *)tap { + if (self.pointArray.count >= 300) { + if (self.isShowMaxToast) { + [XCHUDTool showErrorWithMessage:@"最多只能画300个呦"]; + self.isShowMaxToast = YES; + } + return; + } + + if (tap.state == UIGestureRecognizerStateBegan) { + [self.indexArray addObject:[NSNumber numberWithInteger:self.viewsArray.count]]; + } else if(tap.state == UIGestureRecognizerStateEnded) { + self.isShowMaxToast = YES; + } CGPoint point = [tap translationInView:self.contentView]; - NSLog(@"panAction:X:%.2f, Y:%.2f", point.x, point.y); CGFloat dx = [self myAbs:point.x - self.panPoint.x]; CGFloat dy = [self myAbs:point.y - self.panPoint.y]; CGPoint drawPoint = CGPointMake(self.beginPoint.x + point.x , self.beginPoint.y + point.y); @@ -171,24 +198,63 @@ imageView.layer.masksToBounds = YES; imageView.image = self.image; imageView.frame = CGRectMake(point.x, point.y, 20, 20); - [self.contentView addSubview:imageView]; + [self.drawView addSubview:imageView]; + [self.viewsArray addObject:imageView]; + [self.pointArray addObject:@[@([self changeWidthDraw:point.x]), @([self changeHeightDraw:point.y])]]; + [self cratePriceAttribute]; + if (self.pointArray.count > 10 && self.delegate && [self.delegate respondsToSelector:@selector(xPGraffitiGiftView:didDrawCompletion:)]) { + [self.delegate xPGraffitiGiftView:self didDrawCompletion:self.pointArray]; + } } -#pragma mark - Event Response -- (void)changeButtonAction:(UIButton *)sender { +- (NSInteger)changeWidthDraw:(CGFloat)number { + return number / KScreenWidth * 1000; +} +- (NSInteger)changeHeightDraw:(CGFloat)number { + return number / KScreenHeight * 1000; +} +#pragma mark - Event Response +- (void)changeButtonAction{ + if (self.delegate && [self.delegate respondsToSelector:@selector(xPGraffitiGiftView:didClickChange:)]) { + [self.delegate xPGraffitiGiftView:self didClickChange:self.changeButton]; + } } - (void)repealButtonAction:(UIButton *)sender { - + NSInteger index = [self.indexArray lastObject].integerValue; + if (index < self.viewsArray.count) { + NSArray * array = [self.viewsArray subarrayWithRange:NSMakeRange(index, self.viewsArray.count - index)]; + NSArray * array2 = [self.pointArray subarrayWithRange:NSMakeRange(index, self.pointArray.count - index)]; + [self.pointArray removeObjectsInArray:array2]; + [self.viewsArray removeObjectsInArray:array]; + if (array.count) { + [array makeObjectsPerformSelector:@selector(removeFromSuperview)]; + } + [self.indexArray removeLastObject]; + } } - (void)deleteButtonAction:(UIButton *)sender { - + [self.viewsArray makeObjectsPerformSelector:@selector(removeFromSuperview)]; + [self.pointArray removeAllObjects]; + [self.indexArray removeAllObjects]; } - (void)closeButtonAction:(UIButton *)sender { + if (self.delegate && [self.delegate respondsToSelector:@selector(xPGraffitiGiftView:didClickClose:)]) { + [self.delegate xPGraffitiGiftView:self didClickClose:sender]; + } +} +- (void)cratePriceAttribute { + NSString * count = [NSString stringWithFormat:@"%ld", self.viewsArray.count]; + NSString * price = [NSString stringWithFormat:@"%.0f", self.viewsArray.count * self.price]; + NSString * title = [NSString stringWithFormat:@"已画%@个,需花费%@钻石", count, price]; + NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:[UIColor whiteColor]}]; + [attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor appMainColor] range:[title rangeOfString:count]]; + [attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor appMainColor] range:[title rangeOfString:price]]; + self.titleLabel.attributedText = attribute; } #pragma mark - Getters And Setters @@ -200,6 +266,14 @@ return _contentView; } +- (UIView *)drawView { + if (!_drawView) { + _drawView = [[UIView alloc] init]; + _drawView.backgroundColor = [UIColor clearColor]; + } + return _drawView; +} + - (UIStackView *)tipsStackView { if (!_tipsStackView) { _tipsStackView = [[UIStackView alloc] init]; @@ -262,13 +336,15 @@ return _toolStackView; } -- (UIButton *)changeButton { +- (XPHomeGradientLabel *)changeButton { if (!_changeButton) { - _changeButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_changeButton setTitle:@"切换涂鸦" forState:UIControlStateNormal]; - [_changeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - _changeButton.titleLabel.font = [UIFont systemFontOfSize:12]; - [_changeButton addTarget:self action:@selector(changeButtonAction:) forControlEvents:UIControlEventTouchUpInside]; + _changeButton = [[XPHomeGradientLabel alloc] init]; + _changeButton.font = [UIFont systemFontOfSize:12]; + _changeButton.gradientColor = @[(id)UIColorFromRGB(0x33ECFF).CGColor, (id)UIColorFromRGB(0x57CF99).CGColor]; + _changeButton.text = @"切换涂鸦"; + _changeButton.userInteractionEnabled = YES; + UITapGestureRecognizer * tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeButtonAction)]; + [_changeButton addGestureRecognizer:tap]; } return _changeButton; } @@ -303,5 +379,25 @@ return _closeButton; } +- (NSMutableArray *)indexArray { + if (!_indexArray) { + _indexArray = [NSMutableArray array]; + } + return _indexArray; +} + +- (NSMutableArray *)pointArray { + if (!_pointArray) { + _pointArray = [NSMutableArray array]; + } + return _pointArray; +} + +- (NSMutableArray *)viewsArray { + if (!_viewsArray) { + _viewsArray = [NSMutableArray array]; + } + return _viewsArray; +} @end diff --git a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPSendGiftView.m b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPSendGiftView.m index 01962b3a..1f9b2857 100644 --- a/xplan-ios/Main/ModuleKit/SendGiftView/View/XPSendGiftView.m +++ b/xplan-ios/Main/ModuleKit/SendGiftView/View/XPSendGiftView.m @@ -40,7 +40,7 @@ #import "XPFirstRechargeViewController.h" #import "XPNobleCenterViewController.h" -@interface XPSendGiftView ()< XPGiftBarViewDelegate, XPGiftProtocol, XPGiftInfoViewDelegate> +@interface XPSendGiftView ()< XPGiftBarViewDelegate, XPGiftProtocol, XPGiftInfoViewDelegate, XPGraffitiGiftViewDelegate> ///顶部的区域 @property (nonatomic,strong) UIView * topView; ///内容区域 @@ -66,6 +66,10 @@ ///背包礼物的重试次数 @property (nonatomic,assign) int packGiftRetryCount; @property (nonatomic,strong) NSArray *userArray; +///涂鸦礼物的坐标 +@property (nonatomic,strong) NSArray *graffitiPoint; +///选择了滑块的类型 +@property (nonatomic,assign) GiftSegmentType segmentType; @end @implementation XPSendGiftView @@ -130,6 +134,19 @@ } #pragma mark - Send Custom Message +- (void)sendGraffitiGiftMessage { + if (self.segmentType == GiftSegmentType_Graffiti && self.graffitiPoint.count > 0) { + AttachmentModel * attachment = [[AttachmentModel alloc] init]; + attachment.first = CustomMessageType_Graffiti_Gift; + attachment.second = Custom_Message_Sub_Graffiti_Gift; + NSMutableDictionary * dic = [NSMutableDictionary dictionary]; + [dic setValue:@(self.giftInfoView.lastSelectGift.giftId) forKey:@"giftId"]; + [dic setValue:self.graffitiPoint forKey:@"drawFixedArray"]; + attachment.data = dic; + [self sendCustomMessage:attachment]; + } +} + - (void)sendCustomMessage:(GiftReceiveInfoModel *)receiveModel oringinDic:(NSDictionary *)originDic { NSDictionary * dict = originDic; if (receiveModel.roomSendGiftType == RoomSendGiftType_AllMic) { // 全麦 @@ -381,6 +398,7 @@ } - (void)xPGiftInfoView:(XPGiftInfoView *)view didClickSegment:(GiftSegmentType)type { + self.segmentType = type; self.giftBarView.type = type; } @@ -403,6 +421,7 @@ if (type == GiftSegmentType_Graffiti) { self.giftInfoView.hidden = YES; self.graffitiView.hidden = NO; + self.graffitiView.price = info.goldPrice; [[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:info.giftUrl] options:SDWebImageProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { if (error == nil && image) { self.graffitiView.image = image; @@ -413,6 +432,25 @@ } } +#pragma mark - XPGraffitiGiftViewDelegate +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickClose:(UIButton *)sender { + [UIView animateWithDuration:0.2 animations:^{ + self.graffitiView.hidden = YES; + self.giftInfoView.hidden = NO; + }]; +} + +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickChange:(UIButton *)sender { + [UIView animateWithDuration:0.2 animations:^{ + self.graffitiView.hidden = YES; + self.giftInfoView.hidden = NO; + }]; +} + +- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didDrawCompletion:(NSArray *)pointArray { + self.graffitiPoint = pointArray; +} + #pragma mark - XPGiftProtocol - (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo { self.giftBarView.isShowFirstRecharge = userInfo.isFirstCharge; @@ -459,6 +497,13 @@ [self.presenter getUserWallInfo]; } [self sendCustomMessage:receiveInfo oringinDic:originDic]; + ///发送涂鸦礼物消息 + [self sendGraffitiGiftMessage]; + if (self.segmentType == GiftSegmentType_Graffiti) { + NSString * title = [NSString stringWithFormat:@"发送涂鸦礼物:%@成功",self.giftInfoView.lastSelectGift.giftName]; + [self showSuccessToast:title]; + [self dismissViewControllerAnimated:YES completion:nil]; + } } ///送礼物失败 @@ -573,6 +618,7 @@ if (!_graffitiView) { _graffitiView = [[XPGraffitiGiftView alloc] init]; _graffitiView.hidden = YES; + _graffitiView.delegate = self; } return _graffitiView; } diff --git a/xplan-ios/Main/Room/View/AnimationView/XPRoomAnimationView.m b/xplan-ios/Main/Room/View/AnimationView/XPRoomAnimationView.m index 50f50321..31eb869c 100644 --- a/xplan-ios/Main/Room/View/AnimationView/XPRoomAnimationView.m +++ b/xplan-ios/Main/Room/View/AnimationView/XPRoomAnimationView.m @@ -14,6 +14,7 @@ #import "QGVAPConfigModel.h" #import "UIView+VAP.h" #import +#import ///Tool #import "XPGiftStorage.h" #import "XPMacro.h" @@ -53,8 +54,9 @@ #import "XPRoomLuckyBigPrizeView.h" #import "XPRoomGiftCompoundView.h" #import "XPSailingAnimationView.h" +#import "XPRoomGraffitiGiftAnimationView.h" -@interface XPRoomAnimationView () +@interface XPRoomAnimationView () ///展示的不同层级 ///最底层的 @property (nonatomic,strong) XPRoomAnimationHitView * lowLevelView; @@ -124,6 +126,8 @@ @property (nonatomic, strong) NSMutableArray *acrossRoomPKQueue; #pragma mark - 航海 @property (nonatomic, strong) NSMutableArray *sailingQueue; +#pragma mark - 涂鸦礼物 +@property (nonatomic, strong) NSMutableArray *graffitiGiftQueue; ///幸运礼物动画是否在播放 @property (nonatomic,assign) BOOL isLuckyGiftAnimation; @end @@ -277,6 +281,8 @@ [self receiveGiftCompound:attachment]; } else if(attachment.first == CustomMessageType_Room_Sailing) { [self receiveRoomSailing:attachment]; + } else if(attachment.first == CustomMessageType_Graffiti_Gift) {///涂鸦礼物 + [self receiveRoomGraffitiGift:attachment]; } } } @@ -298,6 +304,57 @@ [self userEnterRoom:content ext:extModel]; } } + +#pragma mark - 涂鸦礼物动画 +- (void)receiveRoomGraffitiGift:(AttachmentModel *)attacment { + if (self.graffitiGiftQueue.count == 0) { + [self startGraffitiGiftAnimation:attacment]; + } + [self.graffitiGiftQueue addObject:attacment]; +} + +- (void)startGraffitiGiftAnimation:(AttachmentModel *)model { + NSDictionary * dic = model.data; + NSNumber * giftId = dic[@"giftId"]; + GiftInfoModel * giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:giftId.stringValue]; + NSArray * array = dic[@"drawFixedArray"]; + if (giftInfo.giftUrl.length > 0 && array.count > 0) { + [[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:giftInfo.giftUrl] options:SDWebImageProgressiveLoad progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) { + if (error == nil && image) { + XPRoomGraffitiGiftAnimationView *graffitiView = [[XPRoomGraffitiGiftAnimationView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; + graffitiView.giftImage = image; + graffitiView.delegate = self; + graffitiView.model = model; + graffitiView.pointArray = array; + [graffitiView beginDrawAnimation]; + [self.highLevleView addSubview:graffitiView]; + } else { + [self.graffitiGiftQueue removeObject:model]; + if (self.graffitiGiftQueue.count > 0) { + [self startGraffitiGiftAnimation:self.graffitiGiftQueue.firstObject]; + } + } + }]; + } else { + [self.graffitiGiftQueue removeObject:model]; + if (self.graffitiGiftQueue.count > 0) { + [self startGraffitiGiftAnimation:self.graffitiGiftQueue.firstObject]; + } + } +} + + + +- (void)xPRoomGraffitiGiftAnimationViewCompletion:(XPRoomGraffitiGiftAnimationView *)view attachment:(nonnull AttachmentModel *)attachment{ + [view removeFromSuperview]; + if ([self.graffitiGiftQueue containsObject:attachment]) { + [self.graffitiGiftQueue removeObject:attachment]; + } + if (self.graffitiGiftQueue.count > 0) { + [self startGraffitiGiftAnimation:self.graffitiGiftQueue.firstObject]; + } +} + #pragma mark - 跨房PK横幅动画 - (void)acrossRoomPKBannerAnimation:(AttachmentModel *)attacment { AcrossRoomPKPrizeModel * prizeModel = [AcrossRoomPKPrizeModel modelWithJSON:attacment.data]; @@ -1822,5 +1879,12 @@ return _sailingQueue; } +- (NSMutableArray *)graffitiGiftQueue { + if (!_graffitiGiftQueue) { + _graffitiGiftQueue = [NSMutableArray array]; + } + return _graffitiGiftQueue; +} + @end diff --git a/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.h b/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.h new file mode 100644 index 00000000..51269214 --- /dev/null +++ b/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.h @@ -0,0 +1,31 @@ +// +// XPRoomGraffitiGiftAnimationView.h +// xplan-ios +// +// Created by 冯硕 on 2022/8/23. +// + +#import + +NS_ASSUME_NONNULL_BEGIN +@class XPRoomGraffitiGiftAnimationView, AttachmentModel; +@protocol XPRoomGraffitiGiftAnimationViewDelegate + +///动画完成 +- (void)xPRoomGraffitiGiftAnimationViewCompletion:(XPRoomGraffitiGiftAnimationView *)view attachment:(AttachmentModel *)attachment; + +@end + +@interface XPRoomGraffitiGiftAnimationView : UIView +@property (nonatomic,strong) UIImage *giftImage; +///代理 +@property (nonatomic,weak) id delegate; +@property (nonatomic,strong) NSArray *pointArray; +@property (nonatomic,strong) AttachmentModel *model; +///开始涂鸦动画 +- (void)beginDrawAnimation; +///结束涂鸦动画 +- (void)endDrawAnimation; +@end + +NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.m b/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.m new file mode 100644 index 00000000..95bd5d45 --- /dev/null +++ b/xplan-ios/Main/Room/View/AnimationView/XPRoomGraffitiGiftAnimationView.m @@ -0,0 +1,82 @@ +// +// XPRoomGraffitiGiftAnimationView.m +// xplan-ios +// +// Created by 冯硕 on 2022/8/23. +// + +#import "XPRoomGraffitiGiftAnimationView.h" +#import "XPWeakTimer.h" +#import "XPMacro.h" + +@interface XPRoomGraffitiGiftAnimationView () +@property (nonatomic,strong) NSTimer *timer; +@property (nonatomic,assign) int index; +///数据 +@property (nonatomic,strong) NSMutableArray *datasource; +@end + +@implementation XPRoomGraffitiGiftAnimationView + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + self.timer = [XPWeakTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(dramGraffitiAnimationView) userInfo:@"" repeats:YES]; + } + return self; +} + +- (void)beginDrawAnimation { + self.index = 0; + for (int i = 0; i < self.pointArray.count; i++) { + NSArray * pointArray = self.pointArray[i]; + NSNumber * first = [pointArray firstObject]; + NSNumber * second = [pointArray lastObject]; + CGFloat x = first.floatValue / 1000.0 * KScreenWidth; + CGFloat y = second.floatValue / 1000.0 * KScreenHeight; + if (x <= 0 || x >= KScreenWidth || y <= 0 || y >= KScreenHeight) { + continue; + } + CGPoint point = CGPointMake(x, y); + [self.datasource addObject:[NSValue valueWithCGPoint:point]]; + } + self.timer.fireDate = NSDate.distantPast; +} + +- (void)endDrawAnimation { + self.timer.fireDate = NSDate.distantFuture; + [self.datasource removeAllObjects]; + self.index = 0; +} + + +- (void)dramGraffitiAnimationView { + if (self.index > (self.datasource.count -1)) { + self.timer.fireDate = NSDate.distantFuture; + [self.datasource removeAllObjects]; + self.index = 0; + [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; + if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomGraffitiGiftAnimationViewCompletion:attachment:)]) { + [self.delegate xPRoomGraffitiGiftAnimationViewCompletion:self attachment:self.model]; + } + return; + } + NSValue * valeu= [self.datasource objectAtIndex:self.index]; + CGPoint point = valeu.CGPointValue; + UIImageView * imageView = [[UIImageView alloc] init]; + imageView.layer.masksToBounds = YES; + imageView.contentMode = UIViewContentModeScaleAspectFill; + imageView.image = self.giftImage; + imageView.frame = CGRectMake(point.x, point.y, 20, 20); + [self addSubview:imageView]; + self.index++; +} + +- (NSMutableArray *)datasource { + if (!_datasource) { + _datasource = [NSMutableArray array]; + } + return _datasource; +} + +@end diff --git a/xplan-ios/Main/Room/View/XPRoomViewController.m b/xplan-ios/Main/Room/View/XPRoomViewController.m index ec4dba4f..9a7ae856 100644 --- a/xplan-ios/Main/Room/View/XPRoomViewController.m +++ b/xplan-ios/Main/Room/View/XPRoomViewController.m @@ -618,6 +618,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出 if (!self.menuContainerView.superview) { [self.view addSubview:self.menuContainerView]; } + [self.view bringSubviewToFront:self.animationView]; [self updateViewConstraintsOnAnchorRoom]; [self changeStageViewOnAnchorRoom]; @@ -893,6 +894,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出 [self.anchorScrollView addSubview:self.roomHeaderView]; [self.anchorScrollView addSubview:self.functionView]; [self.anchorScrollView addSubview:self.menuContainerView]; + [self.view bringSubviewToFront:self.animationView]; [self updateViewConstraintsOnAnchorRoom]; [self changeStageViewOnAnchorRoom]; @@ -1481,6 +1483,7 @@ NSString * const kHadQuitOtherRoomKey = @"kHadQuitOtherRoomKey";//是否退出 if (!self.menuContainerView.superview) { [self.view addSubview:self.menuContainerView]; } + [self.view bringSubviewToFront:self.animationView]; [self updateViewConstraintsOnAnchorRoom]; [self changeStageViewOnAnchorRoom];