194 lines
8.2 KiB
Objective-C
194 lines
8.2 KiB
Objective-C
//
|
|
// XPTreasureFairyGiftView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by XY on 2023/3/1.
|
|
//
|
|
|
|
#import "XPTreasureFairyGiftView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <SVGA.h>
|
|
#import "XPSVGAPlayer.h"
|
|
#import "ThemeColor+Room.h"
|
|
#import "TreasureFailryMessageModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
|
|
@interface XPTreasureFairyGiftView()
|
|
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
///夺宝特效
|
|
@property (nonatomic,strong) XPSVGAPlayer *treasureView;
|
|
///背景图
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///容器
|
|
@property (nonatomic,strong) UIView *titleView;
|
|
///显示文本内容
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
|
|
@end
|
|
|
|
@implementation XPTreasureFairyGiftView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.treasureView];
|
|
[self addSubview:self.backImageView];
|
|
[self.backImageView addSubview:self.titleView];
|
|
|
|
[self.titleView addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.treasureView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.backImageView).inset(20);
|
|
make.height.mas_equalTo(28);
|
|
make.top.mas_equalTo(self.backImageView).offset(23);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.titleView);
|
|
make.centerY.mas_equalTo(self.titleView);
|
|
}];
|
|
}
|
|
|
|
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color fontSize:(CGFloat)fonSize {
|
|
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
|
|
return attr;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setTreasureInfo:(NSDictionary *)treasureInfo {
|
|
if (treasureInfo) {
|
|
TreasureFailryMessageModel * giftInfo = [TreasureFailryMessageModel modelWithDictionary:treasureInfo];
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
CGFloat fontSize = self.isMaxLargeGift ? 22 : 13;
|
|
// CGFloat fontSize = 13;
|
|
if (self.isDrawGift) {
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView0") color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
NSString * nick = giftInfo.nick;
|
|
if (nick.length > 6) {
|
|
nick = [nick substringToIndex:6];
|
|
}
|
|
[attribute appendAttributedString:[self createAttribute:nick color:[DJDKMIMOMColor colorWithHexString:@"#EC4613"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView1") color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.rewardName color:[DJDKMIMOMColor colorWithHexString:@"#EC4613"] fontSize:fontSize]];
|
|
if (giftInfo.rewardNum > 1) {
|
|
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@" X%ld", giftInfo.rewardNum] color:[DJDKMIMOMColor colorWithHexString:@"#EC4613"] fontSize:fontSize]];
|
|
}
|
|
}else{
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView2") color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.nick color:[DJDKMIMOMColor colorWithHexString:@"#EC4613"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView3") color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
NSString *level = @"";
|
|
if (giftInfo.rewardLevel == 1) {
|
|
level = YMLocalizedString(@"XPTreasureFairyGiftView4");
|
|
}else if (giftInfo.rewardLevel == 2) {
|
|
level = YMLocalizedString(@"XPTreasureFairyGiftView5");
|
|
}else if (giftInfo.rewardLevel == 3) {
|
|
level = YMLocalizedString(@"XPTreasureFairyGiftView6");
|
|
}
|
|
[attribute appendAttributedString:[self createAttribute:level color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView7") color:[DJDKMIMOMColor colorWithHexString:@"#8C4700"] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@"%ld",giftInfo.rewardShowValue] color:[DJDKMIMOMColor colorWithHexString:@"#F1390A"] fontSize:fontSize]];
|
|
|
|
if ([giftInfo.rewardType isEqualToString:@"gift"]) {
|
|
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPTreasureFairyGiftView8") color:[DJDKMIMOMColor colorWithHexString:@"#F1390A"] fontSize:fontSize]];
|
|
}else{
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.rewardUnit color:[DJDKMIMOMColor colorWithHexString:@"#F1390A"] fontSize:fontSize]];
|
|
}
|
|
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.rewardName color:[DJDKMIMOMColor colorWithHexString:@"#F1390A"] fontSize:fontSize]];
|
|
}
|
|
|
|
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
|
|
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
|
|
paragraphStyle.lineSpacing = 0.0f;//行间距
|
|
paragraphStyle.alignment = NSTextAlignmentCenter;
|
|
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
|
[attribute addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attribute.length)];
|
|
[self.treasureView setAttributedText:attribute forKey:@"touming_text_name"];
|
|
if (self.isMaxLargeGift) {
|
|
self.backImageView.hidden = YES;
|
|
self.treasureView.hidden = NO;
|
|
@kWeakify(self);
|
|
[self.parser parseWithNamed:@"pi_treasure_fairy_gift_bg" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.treasureView.loops = 1;
|
|
self.treasureView.clearsAfterStop = NO;
|
|
self.treasureView.videoItem = videoItem;
|
|
|
|
[self.treasureView startAnimation];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
} else {
|
|
self.backImageView.hidden = NO;
|
|
self.treasureView.hidden = YES;
|
|
self.titleLabel.attributedText = attribute;
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
}
|
|
}
|
|
|
|
- (XPSVGAPlayer *)treasureView {
|
|
if (!_treasureView) {
|
|
_treasureView = [[XPSVGAPlayer alloc]init];
|
|
_treasureView.backgroundColor = [UIColor clearColor];
|
|
_treasureView.userInteractionEnabled = NO;
|
|
}
|
|
return _treasureView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
|
|
- (UIView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[UIView alloc] init];
|
|
_titleView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"room_treaseure_fairy_normal_gift_bg"];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.numberOfLines = 2;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
@end
|