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

180 lines
6.4 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// YMRoomLuckyBigPrizeView.m
// YUMI
//
// Created by YUMI on 2022/6/15.
//
2023-07-14 18:50:55 +08:00
#import "XPRoomLuckyBigPrizeView.h"
///Third
2023-07-06 16:54:13 +08:00
#import <Masonry/Masonry.h>
#import "SVGAParser.h"
#import "SVGA.h"
2023-07-14 18:50:55 +08:00
///Tool
2023-07-06 16:54:13 +08:00
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
2023-07-14 18:50:55 +08:00
///Model
#import "XPGiftBigPrizeModel.h"
///View
#import "XPSVGAPlayer.h"
2023-07-06 16:54:13 +08:00
2023-07-21 14:07:04 +08:00
@interface XPRoomLuckyBigPrizeView ()<SVGAPlayerDelegate>
2023-07-14 18:50:55 +08:00
///
@property (strong, nonatomic) SVGAParser *parser;
2024-01-03 16:58:16 +08:00
@property (nonatomic, strong) XPSVGAPlayer *giftSvgaView;
@property(nonatomic,strong) NetImageView *chestImageView;
@property(nonatomic,strong) NetImageView *giftImageView;
@property(nonatomic,strong) UILabel *contentView;
2023-07-06 16:54:13 +08:00
@end
2023-07-14 18:50:55 +08:00
@implementation XPRoomLuckyBigPrizeView
2023-07-06 16:54:13 +08:00
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
2023-07-14 18:50:55 +08:00
[self initSubViewConstraints];
2023-07-06 16:54:13 +08:00
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
2024-01-03 16:58:16 +08:00
[self addSubview:self.giftSvgaView];
[self addSubview:self.chestImageView];
[self addSubview:self.giftImageView];
[self addSubview:self.contentView];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
2024-01-03 16:58:16 +08:00
[self.giftSvgaView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-07-06 16:54:13 +08:00
make.edges.mas_equalTo(self);
}];
2024-01-03 16:58:16 +08:00
[self.chestImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(9);
make.centerY.equalTo(self);
make.height.width.mas_equalTo(60);
}];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-9);
make.centerY.equalTo(self);
make.height.width.mas_equalTo(60);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self).inset(69);
2024-01-05 17:28:14 +08:00
make.centerY.equalTo(self);
2024-01-03 16:58:16 +08:00
}];
2023-07-06 16:54:13 +08:00
}
#pragma mark - Event Response
- (void)tapRecognizer:(UITapGestureRecognizer *)tap {
2023-07-14 18:50:55 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLuckyBigPrizeView:luckyGiftInfo:)]) {
[self.delegate xPRoomLuckyBigPrizeView:self luckyGiftInfo:self.giftInfo];
2023-07-06 16:54:13 +08:00
}
}
2024-01-03 16:58:16 +08:00
- (void)chestImageViewTapRecognizer:(UITapGestureRecognizer *)tap{
[self tapRecognizer:tap];
}
- (void)giftImageViewTapRecognizer:(UITapGestureRecognizer *)tap{
[self tapRecognizer:tap];
}
2023-07-06 16:54:13 +08:00
#pragma mark - Getters And Setters
2023-07-14 18:50:55 +08:00
- (void)setGiftInfo:(PIBaseAnimationViewModel*)giftInfo {
2023-07-06 16:54:13 +08:00
_giftInfo = giftInfo;
2024-01-03 16:58:16 +08:00
if (_giftInfo) {
2023-10-17 18:30:14 +08:00
NSString * nick = _giftInfo.nick ?: @"";
2024-01-03 16:58:16 +08:00
if (nick.length > 5) {
nick = [nick substringToIndex:5];
}
NSString *goldPrice = _giftInfo.goldPrice ?: @"0";
2023-10-24 19:01:30 +08:00
NSString *giftName = _giftInfo.giftName ?: @"";
NSString *luckyBagName = _giftInfo.luckyBagName ?: @"";
2024-01-03 16:58:16 +08:00
NSString *giftNum = _giftInfo.giftNum ?: @"0";
NSString *mainText = [NSString stringWithFormat:YMLocalizedString(@"XPRoomLuckyBigPrizeView0"),nick,luckyBagName,goldPrice,giftName];
2024-04-24 20:08:24 +08:00
if (isMSRTL()){
mainText = [NSString stringWithFormat:YMLocalizedString(@"XPRoomLuckyBigPrizeView0"),nick,giftName,goldPrice,luckyBagName];
}
2024-01-03 16:58:16 +08:00
if([giftNum integerValue] > 1){
mainText = [NSString stringWithFormat:@"%@ X%@",mainText,giftNum];
}
CGFloat fontSize = 12;
NSDictionary * dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium], NSForegroundColorAttributeName:UIColorFromRGB(0xFFF45E)};
NSDictionary * mainDic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium], NSForegroundColorAttributeName:[UIColor whiteColor]};
2023-07-06 16:54:13 +08:00
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
2024-01-03 16:58:16 +08:00
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:mainText attributes:mainDic]];
2023-10-17 18:30:14 +08:00
2024-01-03 16:58:16 +08:00
[attributedString addAttributes:dic range:[mainText rangeOfString:nick]];
[attributedString addAttributes:dic range:[mainText rangeOfString:luckyBagName]];
[attributedString addAttributes:dic range:[mainText rangeOfString:goldPrice]];
[attributedString addAttributes:dic range:[mainText rangeOfString:giftName]];
if([giftNum integerValue] > 1){
[attributedString addAttributes:dic range:[mainText rangeOfString:giftNum]];
}
_contentView.attributedText = attributedString;
_chestImageView.imageUrl = _giftInfo.luckyBagGiftPic;
_giftImageView.imageUrl = _giftInfo.giftPic;
@kWeakify(self);
2023-10-17 18:30:14 +08:00
2024-01-03 16:58:16 +08:00
[self.parser parseWithNamed:@"pi_room_lucky_gift" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.hidden = NO;
self.giftSvgaView.hidden = NO;
self.giftSvgaView.videoItem = videoItem;
self.giftSvgaView.loops = 10000;
self.giftSvgaView.clearsAfterStop = YES;
[self.giftSvgaView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
2023-10-17 18:30:14 +08:00
2023-07-06 16:54:13 +08:00
}
}
2023-07-21 14:07:04 +08:00
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
2025-04-02 11:04:07 +08:00
2023-07-21 14:07:04 +08:00
}
2024-01-03 16:58:16 +08:00
- (XPSVGAPlayer *)giftSvgaView {
if (!_giftSvgaView) {
_giftSvgaView = [[XPSVGAPlayer alloc]init];
_giftSvgaView.backgroundColor = [UIColor clearColor];
_giftSvgaView.userInteractionEnabled = NO;
_giftSvgaView.delegate = self;
2023-07-06 16:54:13 +08:00
}
2024-01-03 16:58:16 +08:00
return _giftSvgaView;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _parser;
2023-07-06 16:54:13 +08:00
}
2024-01-03 16:58:16 +08:00
- (NetImageView *)chestImageView{
if(!_chestImageView){
_chestImageView = [NetImageView new];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chestImageViewTapRecognizer:)];
_chestImageView.userInteractionEnabled = YES;
[_chestImageView addGestureRecognizer:tap];
}
return _chestImageView;
}
- (NetImageView *)giftImageView{
if(!_giftImageView){
_giftImageView = [NetImageView new];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(giftImageViewTapRecognizer:)];
_giftImageView.userInteractionEnabled = YES;
[_giftImageView addGestureRecognizer:tap];
}
return _giftImageView;
}
- (UILabel *)contentView{
if(!_contentView){
_contentView = [UILabel labelInitWithText:@"" font:kFontMedium(10) textColor:[UIColor whiteColor]];
_contentView.textAlignment = NSTextAlignmentCenter;
_contentView.numberOfLines = 2;
}
return _contentView;
}
2023-07-06 16:54:13 +08:00
@end