761 lines
28 KiB
Objective-C
761 lines
28 KiB
Objective-C
//
|
|
// XPCandyTreeViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/9.
|
|
//
|
|
|
|
#import "XPCandyTreeViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <SVGA.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
///Tool
|
|
|
|
#import "TTPopup.h"
|
|
|
|
///Model
|
|
#import "RoomInfoModel.h"
|
|
#import "AttachmentModel.h"
|
|
#import "CandyTreeInfoModel.h"
|
|
#import "CandyTreeResultModel.h"
|
|
#import "UserInfoModel.h"
|
|
///View
|
|
#import "XPRoomHalfWebView.h"
|
|
#import "XPCandyTreeMoreView.h"
|
|
#import "XPCandyRankContainerView.h"
|
|
#import "XPCandyTreeGiftView.h"
|
|
#import "XPMineUserInfoViewController.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
#import "XPCandyTreeInsufficientBalanceView.h"
|
|
#import "XPWebViewController.h"
|
|
///P
|
|
#import "XPCandyTreePresenter.h"
|
|
#import "XPCandyTreeProtocol.h"
|
|
#import "Api+Room.h"
|
|
#define KitemHeight (20 + 5)
|
|
|
|
UIKIT_EXTERN NSString * const kRoomReceivedCandyNotificationKey;
|
|
@interface XPCandyTreeViewController ()<XPCandyTreeInsufficientBalanceViewDelegate,UITextFieldDelegate,XPCandyRankContainerViewDelegate,XPCandyTreeProtocol, NIMSystemNotificationManagerDelegate>
|
|
///上面点击的view
|
|
@property (nonatomic,strong) UIView *topTapView;
|
|
///下面点击的view
|
|
@property (nonatomic,strong) UIView *bottomTapView;
|
|
///大的容器
|
|
@property (nonatomic,strong) UIView * contentView;
|
|
|
|
///中间内容的容器
|
|
@property (nonatomic,strong) UIImageView * backView;
|
|
///排行榜的
|
|
@property (nonatomic,strong) UIStackView *rankStackView;
|
|
///排行榜
|
|
@property (nonatomic,strong) UIImageView * rankImageView;
|
|
|
|
///获得糖果
|
|
@property (nonatomic,strong) UIImageView *moreImageView;
|
|
|
|
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
///糖果树魔天輪
|
|
@property (nonatomic,strong) UIImageView *candyTreeView;
|
|
///送礼物的特效
|
|
@property (nonatomic,strong) SVGAImageView *candyTreeLightView;
|
|
///糖果树开启特效
|
|
@property (nonatomic,strong) SVGAImageView *candyTreeOpenView;
|
|
///光
|
|
@property (nonatomic,strong) SVGAImageView *candyTreeTransView;
|
|
|
|
///选择个数的背景
|
|
@property (nonatomic,strong) UIImageView *pickBackImageView;
|
|
|
|
///加
|
|
@property (nonatomic,strong) UIButton *addButton;
|
|
///输入的个数
|
|
@property (nonatomic,strong) UITextField *textFiled;
|
|
///减
|
|
@property (nonatomic,strong) UIButton *subtractButton;
|
|
///摘糖果
|
|
@property (nonatomic,strong) UIButton *pickButton;
|
|
///摘糖果
|
|
@property (nonatomic,strong) UILabel *pickLabel;
|
|
///动画的容器
|
|
@property (nonatomic,strong) UIView * animationView;
|
|
///摘糖果的个数
|
|
@property (nonatomic,assign) NSInteger numberCandy;
|
|
///糖果的信息
|
|
@property (nonatomic,strong) CandyTreeInfoModel *candyInfo;
|
|
///host代理
|
|
@property (nonatomic,weak) id<RoomHostDelegate>hostDelegate;
|
|
///是否正在采摘
|
|
@property (nonatomic,assign) BOOL isPicking;
|
|
|
|
|
|
@end
|
|
|
|
@implementation XPCandyTreeViewController
|
|
|
|
- (void)dealloc {
|
|
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
|
|
[[NSNotificationCenter defaultCenter]postNotificationName:kRoomReceivedCandyNotificationKey object:nil userInfo:@{@"isHidden":@(YES)}];
|
|
}
|
|
|
|
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
|
|
if (self = [super init]) {
|
|
self.hostDelegate = delegate;
|
|
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (XPCandyTreePresenter *)createPresenter {
|
|
return [[XPCandyTreePresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
self.numberCandy = 1;
|
|
[self.presenter getCandyTreeInfo];
|
|
[self getRoomInfo];
|
|
}
|
|
-(void)getRoomInfo{
|
|
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
RoomInfoModel *roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
|
self.pickLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPCandyTreeViewController0"),roomInfo.findLoveDrawSwitchVo.price];
|
|
} uid:@(self.hostDelegate.getRoomInfo.uid).stringValue intoUid:[AccountInfoStorage instance].getUid];
|
|
}
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
[self.view endEditing:YES];
|
|
}
|
|
#pragma mark -XPCandyRankContainerViewDelegate
|
|
- (void)didClickHeadHandle:(NSInteger)uid{
|
|
[TTPopup dismiss];
|
|
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
|
|
userInfoVC.uid = uid;
|
|
[self.hostDelegate.getCurrentNav pushViewController:userInfoVC animated:YES];
|
|
|
|
|
|
|
|
}
|
|
#pragma mark - XPCandyTreeProtocol
|
|
- (void)getCandyTreeInfoSuccess:(CandyTreeInfoModel *)info {
|
|
[self hideHUD];
|
|
self.candyInfo = info;
|
|
|
|
}
|
|
|
|
- (void)pickCandyFail {
|
|
[self hideHUD];
|
|
self.isPicking = NO;
|
|
}
|
|
-(void)pickCandyPay{
|
|
[self hideHUD];
|
|
self.isPicking = NO;
|
|
XPCandyTreeInsufficientBalanceView *balanceView = [[XPCandyTreeInsufficientBalanceView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
|
|
balanceView.delegate = self;
|
|
[self.view addSubview:balanceView];
|
|
}
|
|
- (void)pickCandySuccess:(NSArray<CandyTreeGiftInfoModel *> *)result {
|
|
[self hideHUD];
|
|
self.isPicking = NO;
|
|
[result enumerateObjectsUsingBlock:^(CandyTreeGiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.level > 2) {
|
|
///取消所有的延迟加载的方法
|
|
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
|
|
XPCandyTreeGiftView * newAnimaView = [[XPCandyTreeGiftView alloc] init];
|
|
newAnimaView.giftInfo = obj;
|
|
NSString * giftTitle = [NSString stringWithFormat:@"%@ x %d", obj.rewardName, obj.num];
|
|
CGFloat widht = [giftTitle boundingRectWithSize:CGSizeMake(200, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} context:nil].size.width + 10;
|
|
newAnimaView.frame = CGRectMake(0, 4 * (KitemHeight), widht + 12, KitemHeight);
|
|
[self.animationView addSubview:newAnimaView];
|
|
|
|
if (self.animationView.subviews.count > 5) {
|
|
[self.animationView.subviews.firstObject removeFromSuperview];
|
|
}
|
|
for (int i=0; i < self.animationView.subviews.count; i++) {
|
|
XPCandyTreeGiftView * view = [self.animationView.subviews safeObjectAtIndex1:i];
|
|
NSInteger offsetY= (self.animationView.subviews.count - i) * KitemHeight;
|
|
[UIView animateWithDuration:0.1 animations:^{
|
|
CGRect rect = view.frame;
|
|
rect.origin.y = KitemHeight * 5 - offsetY;
|
|
view.frame = rect;
|
|
} completion:^(BOOL finished) {
|
|
if (i == (self.animationView.subviews.count -1)) {
|
|
[self.animationView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
[self performSelector:@selector(giftViewRemoveFromSuperView:) withObject:obj afterDelay:3];
|
|
}];
|
|
}
|
|
}];
|
|
}
|
|
|
|
|
|
}
|
|
}];
|
|
@kWeakify(self);
|
|
NSString * lightName = [NSString stringWithFormat:@"https://image.hfighting.com/candyTree_light.svga"];
|
|
|
|
NSString *baseFileName = @"/GiftSvga";
|
|
NSString *filePath = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:baseFileName] stringByAppendingPathComponent:lightName];
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
if ([fileManager fileExistsAtPath:filePath]){
|
|
NSData *data=[NSData dataWithContentsOfFile:filePath options:0 error:NULL];
|
|
[self.parser parseWithData:data cacheKey:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
if (videoItem != nil) {
|
|
self.candyTreeLightView.loops = 1;
|
|
self.candyTreeLightView.clearsAfterStop = YES;
|
|
self.candyTreeLightView.videoItem = videoItem;
|
|
[self.candyTreeLightView startAnimation];
|
|
}
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
|
|
|
|
}else{
|
|
[self.parser parseWithURL:[NSURL URLWithString:lightName] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.candyTreeLightView.loops = 1;
|
|
self.candyTreeLightView.clearsAfterStop = YES;
|
|
self.candyTreeLightView.videoItem = videoItem;
|
|
[self.candyTreeLightView startAnimation];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
};
|
|
|
|
|
|
|
|
NSString * openName = [NSString stringWithFormat:@"https://image.hfighting.com/candyTree_open.svga"];
|
|
NSString *openFilePath = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:baseFileName] stringByAppendingPathComponent:openName];
|
|
if ([fileManager fileExistsAtPath:openFilePath]){
|
|
NSData *data=[NSData dataWithContentsOfFile:openFilePath options:0 error:NULL];
|
|
[self.parser parseWithData:data cacheKey:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
if (videoItem != nil) {
|
|
self.candyTreeOpenView.loops = 1;
|
|
self.candyTreeOpenView.clearsAfterStop = YES;
|
|
self.candyTreeOpenView.videoItem = videoItem;
|
|
[self.candyTreeOpenView startAnimation];
|
|
}
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
|
|
|
|
}else{
|
|
[self.parser parseWithURL:[NSURL URLWithString:lightName] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.candyTreeOpenView.loops = 1;
|
|
self.candyTreeOpenView.clearsAfterStop = YES;
|
|
self.candyTreeOpenView.videoItem = videoItem;
|
|
[self.candyTreeOpenView startAnimation];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
};
|
|
|
|
NSString * transformName = [NSString stringWithFormat:@"https://image.hfighting.com/candyTree_transform.svga"];
|
|
NSString *transformFilePath = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:baseFileName] stringByAppendingPathComponent:transformName];
|
|
if ([fileManager fileExistsAtPath:transformFilePath]){
|
|
NSData *data=[NSData dataWithContentsOfFile:transformFilePath options:0 error:NULL];
|
|
[self.parser parseWithData:data cacheKey:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
if (videoItem != nil) {
|
|
self.candyTreeTransView.loops = 1;
|
|
self.candyTreeTransView.clearsAfterStop = YES;
|
|
self.candyTreeTransView.videoItem = videoItem;
|
|
[self.candyTreeTransView startAnimation];
|
|
}
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
|
|
|
|
}else{
|
|
[self.parser parseWithURL:[NSURL URLWithString:lightName] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.candyTreeTransView.loops = 1;
|
|
self.candyTreeTransView.clearsAfterStop = YES;
|
|
self.candyTreeTransView.videoItem = videoItem;
|
|
[self.candyTreeTransView startAnimation];
|
|
self.candyTreeTransView.backgroundColor = [UIColor redColor];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
};
|
|
|
|
}
|
|
|
|
#pragma mark - NIMSystemNotificationManagerDelegate
|
|
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
|
|
if (notification.receiverType == NIMSessionTypeP2P) {
|
|
AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content];
|
|
if (attachment.first == CustomMessageType_Account && attachment.second == Custom_Message_Sub_Account_Changed){
|
|
if (attachment.second == Custom_Message_Sub_Account_Changed) {
|
|
[self.presenter getCandyTreeInfo];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[[NSNotificationCenter defaultCenter]postNotificationName:kRoomReceivedCandyNotificationKey object:nil userInfo:@{@"isHidden":@(NO)}];
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
[self.view addSubview:self.topTapView];
|
|
[self.view addSubview:self.contentView];
|
|
[self.view addSubview:self.bottomTapView];
|
|
|
|
[self.contentView addSubview:self.backView];
|
|
|
|
|
|
[self.backView addSubview:self.rankStackView];
|
|
[self.backView addSubview:self.moreImageView];
|
|
[self.backView addSubview:self.candyTreeView];
|
|
[self.backView addSubview:self.candyTreeLightView];
|
|
[self.backView addSubview:self.candyTreeOpenView];
|
|
|
|
[self.backView addSubview:self.pickBackImageView];
|
|
|
|
[self.backView addSubview:self.pickButton];
|
|
[self.pickButton addSubview:self.pickLabel];
|
|
[self.backView addSubview:self.candyTreeTransView];
|
|
[self.backView addSubview:self.animationView];
|
|
|
|
[self.backView addSubview:self.subtractButton];
|
|
[self.backView addSubview:self.textFiled];
|
|
[self.backView addSubview:self.addButton];
|
|
|
|
|
|
|
|
[self.rankStackView addArrangedSubview:self.rankImageView];
|
|
|
|
|
|
// @kWeakify(self);
|
|
// [self.parser parseWithNamed:@"candyTree" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
// @kStrongify(self);
|
|
// self.candyTreeView.loops = INT_MAX;
|
|
// self.candyTreeView.clearsAfterStop = NO;
|
|
// self.candyTreeView.videoItem = videoItem;
|
|
// [self.candyTreeView startAnimation];
|
|
// } failureBlock:^(NSError * _Nonnull error) {
|
|
//
|
|
// }];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.topTapView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.leading.trailing.mas_equalTo(self.view);
|
|
make.bottom.mas_equalTo(self.contentView.mas_top);
|
|
}];
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.view).inset(45);
|
|
make.centerY.mas_equalTo(self.view);
|
|
make.bottom.mas_equalTo(self.backView.mas_bottom);
|
|
}];
|
|
|
|
[self.bottomTapView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.contentView.mas_bottom);
|
|
make.bottom.mas_equalTo(self.view);
|
|
}];
|
|
|
|
|
|
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(285);
|
|
make.height.mas_equalTo(434);
|
|
make.centerX.mas_equalTo(self.contentView);
|
|
make.top.mas_equalTo(self.contentView).offset(0);
|
|
}];
|
|
|
|
[self.rankStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.backView).offset(45);
|
|
make.leading.mas_equalTo(self.backView).offset(9);
|
|
make.height.mas_equalTo(37);
|
|
make.width.mas_equalTo(36);
|
|
}];
|
|
|
|
|
|
|
|
|
|
[self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(30, 30));
|
|
make.top.mas_equalTo(44);
|
|
make.trailing.mas_equalTo(self.backView).offset(-12);
|
|
}];
|
|
|
|
|
|
|
|
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.backView).offset(63);
|
|
make.centerX.mas_equalTo(self.backView);
|
|
make.size.mas_equalTo(CGSizeMake(285, 363));
|
|
}];
|
|
|
|
[self.candyTreeLightView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.candyTreeView);
|
|
}];
|
|
|
|
[self.candyTreeOpenView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.candyTreeView);
|
|
}];
|
|
|
|
|
|
|
|
[self.pickBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(150, 29));
|
|
make.centerX.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(340);
|
|
}];
|
|
|
|
|
|
[self.subtractButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(self.pickBackImageView.mas_leading).mas_offset(5);;
|
|
make.top.equalTo(self.pickBackImageView.mas_top).mas_offset(2.25);
|
|
make.width.mas_equalTo(40);
|
|
make.height.mas_equalTo(21);
|
|
}];
|
|
|
|
[self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.top.height.equalTo(self.subtractButton);
|
|
make.trailing.equalTo(self.pickBackImageView.mas_trailing).mas_offset(-5);;
|
|
}];
|
|
[self.textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.height.equalTo(self.subtractButton);
|
|
make.width.mas_equalTo(62);
|
|
make.leading.equalTo(self.subtractButton.mas_trailing);
|
|
|
|
}];
|
|
[self.pickButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(121, 45));
|
|
make.centerX.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(367);
|
|
}];
|
|
[self.pickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(20);
|
|
make.centerX.equalTo(self.pickButton);
|
|
make.left.right.equalTo(self.pickButton);
|
|
}];
|
|
CGFloat kscale = (CGFloat)350 / (CGFloat)755;
|
|
[self.candyTreeTransView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.candyTreeView);
|
|
make.bottom.trailing.mas_equalTo(self.view);
|
|
make.width.mas_equalTo(self.candyTreeTransView.mas_height).multipliedBy(kscale);
|
|
}];
|
|
|
|
[self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.backView).offset(7);
|
|
make.bottom.mas_equalTo(self.backView).offset(-106);
|
|
make.width.mas_equalTo(150);
|
|
make.height.mas_equalTo(KitemHeight * 5);
|
|
}];
|
|
}
|
|
|
|
- (void)giftViewRemoveFromSuperView:(UIView *)view {
|
|
[view removeFromSuperview];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)moreTapRecognizer:(UITapGestureRecognizer *)tap {
|
|
UserInfoModel * userInfo = self.hostDelegate.getUserInfo;
|
|
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
|
|
XPCandyTreeMoreView * moreView = [[XPCandyTreeMoreView alloc] init];
|
|
moreView.sendMessageSwitchLevel = roomInfo.findLoveDrawSwitchVo.sendMsgLevel;
|
|
moreView.showMessageSwitch = userInfo.userLevelVo.experLevelSeq >= roomInfo.findLoveDrawSwitchVo.sendMsgLevel;
|
|
[TTPopup popupView:moreView style:TTPopupStyleActionSheet];
|
|
}
|
|
|
|
- (void)rankTapRecognizer:(UITapGestureRecognizer *)tap {
|
|
XPCandyRankContainerView * rankView = [[XPCandyRankContainerView alloc] init];
|
|
rankView.delegate = self;
|
|
[TTPopup popupView:rankView style:TTPopupStyleActionSheet];
|
|
}
|
|
|
|
- (void)addButtonAction:(UIButton *)sender {
|
|
self.numberCandy += 1;
|
|
self.textFiled.text = [NSString stringWithFormat:@"%ld", self.numberCandy];
|
|
|
|
}
|
|
|
|
- (void)subtractButtonAction:(UIButton *)sender {
|
|
if (self.numberCandy <= 1) return;
|
|
self.numberCandy -= 1;
|
|
self.textFiled.text = [NSString stringWithFormat:@"%ld", self.numberCandy];
|
|
|
|
}
|
|
#pragma mark -XPCandyTreeInsufficientBalanceViewDelegate
|
|
- (void)payBalanceAction{
|
|
XPWebViewController * webVC =[[XPWebViewController alloc] init];
|
|
webVC.url = [NSString stringWithFormat:URLWithType(kThirdPartyPay),@"4",[YYUtility deviceID]];
|
|
webVC.isPush = YES;
|
|
@kWeakify(self)
|
|
webVC.CloseWebViewBlock = ^(BOOL result){
|
|
@kStrongify(self)
|
|
[self.presenter getCandyTreeInfo];
|
|
};
|
|
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
|
}
|
|
- (void)pickButtonAction:(UIButton *)sender {
|
|
if (self.numberCandy <= 0) {
|
|
[self showErrorToast:YMLocalizedString(@"XPCandyTreeViewController2")];
|
|
return;
|
|
}
|
|
if (self.isPicking) return;
|
|
self.isPicking = YES;
|
|
///摘
|
|
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
|
|
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
NSString * candyNumber = [NSString stringWithFormat:@"%ld", self.numberCandy];
|
|
BOOL showMessageSwitch = self.hostDelegate.getUserInfo.userLevelVo.experLevelSeq >= roomInfo.findLoveDrawSwitchVo.sendMsgLevel;
|
|
[self.presenter pickCandy:candyNumber roomUid:roomUid isSendMessage:showMessageSwitch];
|
|
|
|
}
|
|
|
|
- (void)dismissTapRecognizer:(UITapGestureRecognizer *)tap {
|
|
[[NSNotificationCenter defaultCenter]postNotificationName:kRoomReceivedCandyNotificationKey object:nil userInfo:@{@"isHidden":@(YES)}];
|
|
[self.view removeFromSuperview];
|
|
}
|
|
#pragma mark -UITextFieldDelegate
|
|
- (void)textFieldDidChanged:(UITextField *)textField {
|
|
if (textField.text.integerValue > 200) {
|
|
textField.text = @"200";
|
|
[self showErrorToast:YMLocalizedString(@"XPCandyTreeViewController5")];
|
|
}
|
|
self.numberCandy = textField.text.intValue;
|
|
|
|
}
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField{
|
|
if(textField.text.length <= 0){
|
|
textField.text = @"1";
|
|
}
|
|
|
|
}
|
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
|
return [self validateNumber:string];
|
|
}
|
|
|
|
- (BOOL)validateNumber:(NSString*)number {
|
|
BOOL res = YES;
|
|
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
|
|
int i = 0;
|
|
while (i < number.length) {
|
|
NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
|
|
NSRange range = [string rangeOfCharacterFromSet:tmpSet];
|
|
if (range.length == 0) {
|
|
res = NO;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
return res;
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (void)setIsPicking:(BOOL)isPicking {
|
|
_isPicking = isPicking;
|
|
self.pickButton.enabled = !_isPicking;
|
|
}
|
|
|
|
- (UIView *)topTapView {
|
|
if (!_topTapView) {
|
|
_topTapView = [[UIView alloc] init];
|
|
_topTapView.backgroundColor = [UIColor clearColor];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissTapRecognizer:)];
|
|
[_topTapView addGestureRecognizer:tap];
|
|
}
|
|
return _topTapView;
|
|
}
|
|
- (UIView *)bottomTapView {
|
|
if (!_bottomTapView) {
|
|
_bottomTapView = [[UIView alloc] init];
|
|
_bottomTapView.backgroundColor = [UIColor clearColor];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissTapRecognizer:)];
|
|
[_bottomTapView addGestureRecognizer:tap];
|
|
}
|
|
return _bottomTapView;
|
|
}
|
|
|
|
- (UIView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[UIView alloc] init];
|
|
_contentView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _contentView;
|
|
}
|
|
|
|
|
|
|
|
- (UIImageView *)backView {
|
|
if (!_backView) {
|
|
_backView = [[UIImageView alloc] init];
|
|
_backView.userInteractionEnabled = YES;
|
|
_backView.image = [UIImage imageNamed:@"room_candy_tree_back"];
|
|
|
|
}
|
|
return _backView;
|
|
}
|
|
|
|
- (UIStackView *)rankStackView {
|
|
if (!_rankStackView) {
|
|
_rankStackView = [[UIStackView alloc] init];
|
|
_rankStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_rankStackView.distribution = UIStackViewDistributionFill;
|
|
_rankStackView.alignment = UIStackViewAlignmentCenter;
|
|
_rankStackView.spacing = 0;
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rankTapRecognizer:)];
|
|
[_rankStackView addGestureRecognizer:tap];
|
|
}
|
|
return _rankStackView;
|
|
}
|
|
|
|
- (UIImageView *)rankImageView {
|
|
if (!_rankImageView) {
|
|
_rankImageView = [[UIImageView alloc] init];
|
|
_rankImageView.userInteractionEnabled = YES;
|
|
_rankImageView.image = [UIImage imageNamed:@"room_candy_tree_rank"];
|
|
}
|
|
return _rankImageView;
|
|
}
|
|
|
|
|
|
|
|
- (UIImageView *)moreImageView {
|
|
if (!_moreImageView) {
|
|
_moreImageView = [[UIImageView alloc] init];
|
|
_moreImageView.userInteractionEnabled = YES;
|
|
_moreImageView.image = [UIImage imageNamed:@"room_candy_tree_more"];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreTapRecognizer:)];
|
|
[_moreImageView addGestureRecognizer:tap];
|
|
}
|
|
return _moreImageView;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (UIImageView *)candyTreeView {
|
|
if (!_candyTreeView) {
|
|
_candyTreeView = [[UIImageView alloc]init];
|
|
_candyTreeView.backgroundColor = [UIColor clearColor];
|
|
_candyTreeView.userInteractionEnabled = NO;
|
|
_candyTreeView.image = [UIImage imageNamed:@"room_candy_tree_bg"];
|
|
}
|
|
return _candyTreeView;
|
|
}
|
|
|
|
- (SVGAImageView *)candyTreeLightView {
|
|
if (!_candyTreeLightView) {
|
|
_candyTreeLightView = [[SVGAImageView alloc]init];
|
|
_candyTreeLightView.backgroundColor = [UIColor clearColor];
|
|
_candyTreeLightView.userInteractionEnabled = NO;
|
|
}
|
|
return _candyTreeLightView;
|
|
}
|
|
|
|
- (SVGAImageView *)candyTreeOpenView {
|
|
if (!_candyTreeOpenView) {
|
|
_candyTreeOpenView = [[SVGAImageView alloc]init];
|
|
_candyTreeOpenView.backgroundColor = [UIColor clearColor];
|
|
_candyTreeOpenView.userInteractionEnabled = NO;
|
|
}
|
|
return _candyTreeOpenView;
|
|
}
|
|
|
|
- (SVGAImageView *)candyTreeTransView {
|
|
if (!_candyTreeTransView) {
|
|
_candyTreeTransView = [[SVGAImageView alloc]init];
|
|
_candyTreeTransView.backgroundColor = [UIColor clearColor];
|
|
_candyTreeTransView.userInteractionEnabled = NO;
|
|
}
|
|
return _candyTreeTransView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
|
|
|
|
- (UIImageView *)pickBackImageView {
|
|
if (!_pickBackImageView) {
|
|
_pickBackImageView = [[UIImageView alloc] init];
|
|
_pickBackImageView.userInteractionEnabled = YES;
|
|
_pickBackImageView.image = [UIImage imageNamed:@"room_candy_tree_pick_bg"];
|
|
}
|
|
return _pickBackImageView;
|
|
}
|
|
|
|
|
|
|
|
- (UIButton *)addButton {
|
|
if (!_addButton) {
|
|
_addButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_addButton setImage:[UIImage imageNamed:@"room_candy_tree_add"] forState:UIControlStateNormal];
|
|
[_addButton setImage:[UIImage imageNamed:@"room_candy_tree_add"] forState:UIControlStateSelected];
|
|
[_addButton addTarget:self action:@selector(addButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_addButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
|
}
|
|
return _addButton;
|
|
}
|
|
|
|
- (UIButton *)subtractButton {
|
|
if (!_subtractButton) {
|
|
_subtractButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_subtractButton setImage:[UIImage imageNamed:@"room_candy_tree_subtract"] forState:UIControlStateNormal];
|
|
[_subtractButton setImage:[UIImage imageNamed:@"room_candy_tree_subtract"] forState:UIControlStateSelected];
|
|
[_subtractButton addTarget:self action:@selector(subtractButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_subtractButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
|
|
}
|
|
return _subtractButton;
|
|
}
|
|
|
|
- (UITextField *)textFiled {
|
|
if (!_textFiled) {
|
|
_textFiled = [[UITextField alloc] init];
|
|
_textFiled.tintColor = [UIColor whiteColor];
|
|
_textFiled.textColor = [UIColor whiteColor];
|
|
_textFiled.backgroundColor = [UIColor clearColor];
|
|
_textFiled.textAlignment = NSTextAlignmentCenter;
|
|
_textFiled.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
|
|
_textFiled.text = @"1";
|
|
_textFiled.delegate = self;
|
|
[_textFiled addTarget:self action:@selector(textFieldDidChanged:) forControlEvents:UIControlEventEditingChanged];
|
|
_textFiled.keyboardType = UIKeyboardTypeNumberPad;
|
|
}
|
|
return _textFiled;
|
|
}
|
|
|
|
- (UIButton *)pickButton {
|
|
if (!_pickButton) {
|
|
_pickButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_pickButton setImage:[UIImage imageNamed:@"room_candy_tree_pick_normal"] forState:UIControlStateNormal];
|
|
[_pickButton setImage:[UIImage imageNamed:@"room_candy_tree_pick_normal"] forState:UIControlStateDisabled];
|
|
[_pickButton addTarget:self action:@selector(pickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _pickButton;
|
|
}
|
|
- (UILabel *)pickLabel{
|
|
if(!_pickLabel){
|
|
_pickLabel = [UILabel labelInitWithText:@"" font:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium] textColor:UIColorFromRGB(0xDF7604)];
|
|
_pickLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _pickLabel;
|
|
}
|
|
- (UIView *)animationView {
|
|
if (!_animationView) {
|
|
_animationView = [[UIView alloc] init];
|
|
_animationView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _animationView;
|
|
}
|
|
|
|
|
|
@end
|