Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomCandyGiftView.m

153 lines
5.6 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
2023-07-18 18:26:10 +08:00
// XPRoomCandyGiftView.m
// xplan-ios
2023-07-14 18:50:55 +08:00
//
2023-07-18 18:26:10 +08:00
// Created by on 2021/12/10.
2023-07-14 18:50:55 +08:00
//
#import "XPRoomCandyGiftView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
#import "ThemeColor+Room.h"
#import "CandyTreeResultModel.h"
#import "NSObject+MJExtension.h"
2023-07-18 18:26:10 +08:00
2023-07-14 18:50:55 +08:00
@interface XPRoomCandyGiftView ()
///
@property (strong, nonatomic) SVGAParser *parser;
///
2023-07-18 18:26:10 +08:00
@property (nonatomic,strong) SVGAImageView *candyTreeView;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,strong) UIImageView *backImageView;
///
@property (nonatomic,strong) UILabel *titleLabel;
@end
@implementation XPRoomCandyGiftView
- (instancetype)initWithFrame:(CGRect)frame {
2023-07-18 18:26:10 +08:00
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
2023-07-14 18:50:55 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
2023-07-18 18:26:10 +08:00
[self addSubview:self.candyTreeView];
[self addSubview:self.backImageView];
[self addSubview:self.titleLabel];
2023-07-14 18:50:55 +08:00
}
- (void)initSubViewConstraints {
2023-07-18 18:26:10 +08:00
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.mas_equalTo(self);
make.height.mas_equalTo(kGetScaleWidth(55));
}];
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.mas_equalTo(self.candyTreeView);
make.height.mas_equalTo(kGetScaleWidth(55));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.backImageView);
make.leading.mas_equalTo(kGetScaleWidth(84));
make.trailing.mas_equalTo(-kGetScaleWidth(70.5));
2023-07-18 18:26:10 +08:00
}];
2023-07-14 18:50:55 +08:00
}
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color fontSize:(CGFloat)fonSize {
2023-07-18 18:26:10 +08:00
if(text.length == 0)return nil;
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
return attr;
2023-07-14 18:50:55 +08:00
}
#pragma mark - Getters And Setters
- (void)setCandyInfo:(NSDictionary *)candyInfo {
2023-07-18 18:26:10 +08:00
if (candyInfo) {
CandyTreeGiftInfoModel * giftInfo = [CandyTreeGiftInfoModel modelWithDictionary:candyInfo];
2023-09-27 14:57:55 +08:00
if(giftInfo.nick.length > 8){
giftInfo.nick = [NSString stringWithFormat:@"%@...",[giftInfo.nick substringToIndex:8]];
2023-07-18 18:26:10 +08:00
}
2024-04-19 17:26:43 +08:00
NSString *text = [NSString stringWithFormat:YMLocalizedString(@"XPRoomCandyGiftView0"),giftInfo.nick,giftInfo.prizeName,[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]];
CGFloat fontSize = self.isMaxLargeGift ? 12 : 12;
2024-04-19 17:26:43 +08:00
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithAttributedString:[self createAttribute:text color:[UIColor whiteColor] fontSize:fontSize]];
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:UIColorFromRGB(0xFFE44E)} range:[text rangeOfString:giftInfo.nick]];
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:UIColorFromRGB(0xFFE44E)} range:[text rangeOfString:giftInfo.prizeName]];
2023-07-18 18:26:10 +08:00
if (giftInfo.prizeNum > 1) {
2024-04-19 17:26:43 +08:00
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:[UIColor whiteColor]} range:[text rangeOfString:[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]]];
2023-07-18 18:26:10 +08:00
}
self.titleLabel.attributedText = attribute;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
2023-07-18 18:26:10 +08:00
if (self.isMaxLargeGift) {
2024-04-24 20:08:24 +08:00
// self.backImageView.hidden = YES;
// self.candyTreeView.hidden = NO;
// @kWeakify(self);
//
// [self.parser parseWithNamed:@"pi_room_game_fine_love" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// @kStrongify(self);
// self.candyTreeView.loops = 2;
// self.candyTreeView.clearsAfterStop = NO;
// self.candyTreeView.videoItem = videoItem;
// [self.candyTreeView startAnimation];
//
// } failureBlock:^(NSError * _Nonnull error) {
//
// }];
self.backImageView.image = [kImage(@"room_candytree_large_big_gift_bg") ms_SetImageForRTL];
self.backImageView.hidden = NO;
self.candyTreeView.hidden = YES;
2023-07-18 18:26:10 +08:00
} else {
self.backImageView.hidden = NO;
self.candyTreeView.hidden = YES;
2024-04-24 20:08:24 +08:00
self.backImageView.image = [kImage(@"room_candytree_large_gift_bg") ms_SetImageForRTL];
2023-07-18 18:26:10 +08:00
}
}
2023-07-14 18:50:55 +08:00
}
2023-07-18 18:26:10 +08:00
- (SVGAImageView *)candyTreeView {
if (!_candyTreeView) {
_candyTreeView = [[SVGAImageView alloc]init];
_candyTreeView.backgroundColor = [UIColor clearColor];
_candyTreeView.userInteractionEnabled = NO;
}
return _candyTreeView;
2023-07-14 18:50:55 +08:00
}
- (SVGAParser *)parser {
2023-07-18 18:26:10 +08:00
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
2023-07-14 18:50:55 +08:00
}
- (UIImageView *)backImageView {
2023-07-18 18:26:10 +08:00
if (!_backImageView) {
_backImageView = [[UIImageView alloc] init];
_backImageView.userInteractionEnabled = YES;
_backImageView.image = [UIImage imageNamed:@"room_candytree_large_gift_bg"];
}
return _backImageView;
2023-07-14 18:50:55 +08:00
}
- (UILabel *)titleLabel {
2023-07-18 18:26:10 +08:00
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.numberOfLines = 2;
2023-07-18 18:26:10 +08:00
}
return _titleLabel;
2023-07-14 18:50:55 +08:00
}
@end