422 lines
17 KiB
Objective-C
422 lines
17 KiB
Objective-C
//
|
|
// XPNobleCenterMyNobleView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by GreenLand on 2022/1/4.
|
|
//
|
|
|
|
#import "XPNobleCenterMyNobleView.h"
|
|
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+NobleCenter.h"
|
|
#import "UIImage+Utils.h"
|
|
#import "TTPopup.h"
|
|
#import "XPNobleCenterResidueView.h"
|
|
|
|
@interface XPNobleCenterMyNobleView ()
|
|
|
|
///顶部view
|
|
@property (nonatomic, strong) UIView *topView;
|
|
///等级详情
|
|
@property (nonatomic, strong) YYLabel *nobleLabel;
|
|
///时间帮助按钮
|
|
@property (nonatomic, strong) UIButton *timeDescButton;
|
|
///权力值图标
|
|
@property (nonatomic, strong) UIImageView *privilegeIconImage;
|
|
///底层进度条
|
|
@property (nonatomic, strong) UIView *backProgressView;
|
|
///当前进度条
|
|
@property (nonatomic, strong) UIImageView *currentProgressView;
|
|
///进度条圆标
|
|
@property (nonatomic, strong) UIImageView *indicateImageView;
|
|
///保级值箭头
|
|
@property (nonatomic, strong) UIImageView *safeLevelImageView;
|
|
///当前权力值
|
|
@property (nonatomic, strong) UILabel *currentValueLabel;
|
|
///保级权力值
|
|
@property (nonatomic, strong) UILabel *safeValueLabel;
|
|
///升级权力值
|
|
@property (nonatomic, strong) UILabel *upGradeValueLabel;
|
|
///开通贵族
|
|
@property (nonatomic, strong) UILabel *openNobleButton;
|
|
///
|
|
@property (nonatomic,strong) UIImageView *openNobleView;
|
|
@property (nonatomic,strong) UIImageView *openNobleIconView;
|
|
|
|
@end
|
|
|
|
@implementation XPNobleCenterMyNobleView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.backgroundColor = UIColorFromRGB(0x252014);
|
|
[self addSubview:self.topView];
|
|
[self.topView addSubview:self.nobleLabel];
|
|
[self.topView addSubview:self.timeDescButton];
|
|
[self addSubview:self.privilegeIconImage];
|
|
[self addSubview:self.backProgressView];
|
|
[self.backProgressView addSubview:self.currentProgressView];
|
|
[self addSubview:self.indicateImageView];
|
|
[self addSubview:self.safeLevelImageView];
|
|
[self addSubview:self.currentValueLabel];
|
|
[self addSubview:self.safeValueLabel];
|
|
[self addSubview:self.upGradeValueLabel];
|
|
|
|
[self addSubview:self.openNobleView];
|
|
|
|
[self.openNobleView addSubview:self.openNobleIconView];
|
|
[self.openNobleView addSubview:self.openNobleButton];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.leading.trailing.mas_equalTo(0);
|
|
make.height.mas_greaterThanOrEqualTo(36);
|
|
}];
|
|
CGFloat width = KScreenWidth - 29 - 15;
|
|
[self.nobleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(15);
|
|
make.top.bottom.equalTo(self.topView);
|
|
make.width.mas_lessThanOrEqualTo(width);
|
|
}];
|
|
[self.timeDescButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.topView);
|
|
make.leading.mas_equalTo(self.nobleLabel.mas_trailing).mas_offset(3);
|
|
make.width.height.mas_equalTo(14);
|
|
}];
|
|
[self.privilegeIconImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(14);
|
|
make.top.mas_equalTo(self.topView.mas_bottom).mas_offset(24);
|
|
make.width.mas_equalTo(50);
|
|
make.height.mas_equalTo(16);
|
|
}];
|
|
[self.backProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.privilegeIconImage);
|
|
make.leading.mas_equalTo(self.privilegeIconImage.mas_trailing).mas_offset(12);
|
|
make.trailing.mas_equalTo(-14);
|
|
make.height.mas_equalTo(12);
|
|
}];
|
|
[self.currentProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.top.bottom.mas_equalTo(self.backProgressView);
|
|
make.trailing.mas_equalTo(self.indicateImageView.mas_centerX);
|
|
}];
|
|
|
|
[self.indicateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.backProgressView);
|
|
make.width.height.mas_equalTo(18);
|
|
make.centerX.mas_equalTo(self.backProgressView.mas_leading).mas_offset(2);
|
|
}];
|
|
|
|
[self.currentValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.indicateImageView).priorityMedium();
|
|
make.top.mas_equalTo(self.backProgressView.mas_bottom).mas_offset(5);
|
|
make.trailing.mas_lessThanOrEqualTo(-12).priorityHigh();
|
|
}];
|
|
[self.safeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.safeLevelImageView.mas_top).mas_offset(-2);
|
|
make.height.mas_equalTo(10);
|
|
}];
|
|
|
|
[self.safeLevelImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.backProgressView.mas_top).mas_offset(2);
|
|
make.centerX.mas_equalTo(self.safeValueLabel);
|
|
make.width.height.mas_equalTo(8);
|
|
}];
|
|
[self.upGradeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.safeValueLabel);
|
|
make.trailing.mas_equalTo(self.backProgressView);
|
|
}];
|
|
|
|
|
|
[self.openNobleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.bottom.mas_equalTo(-kSafeAreaBottomHeight - 5);
|
|
make.width.mas_equalTo(300);
|
|
make.height.mas_equalTo(44);
|
|
}];
|
|
[self.openNobleButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_lessThanOrEqualTo(258);
|
|
make.centerX.equalTo(self.openNobleView);
|
|
make.top.bottom.equalTo(self.openNobleView);
|
|
}];
|
|
[self.openNobleIconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(20);
|
|
make.centerY.equalTo(self.openNobleView);
|
|
make.trailing.equalTo(self.openNobleButton.mas_leading).mas_offset(-2);
|
|
|
|
}];
|
|
}
|
|
|
|
#pragma mark - private
|
|
- (NSMutableAttributedString *)createNobleStringWithModel:(NobleCenterModel *)model {
|
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
|
|
[string appendAttributedString:[self createAttribute:YMLocalizedString(@"XPNobleCenterMyNobleView0") color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
NSString *levelName = @"";
|
|
NSInteger distanceValue = 0;
|
|
NSString *nextLevelName = @"";
|
|
NSInteger saveScore = 0;
|
|
NSInteger nextSecore = 0;
|
|
BOOL hadNextLevel = YES;//标记
|
|
for (NobleInfo *info in model.vipInfos) {
|
|
if (info.vipLevel == model.currLevel) {
|
|
levelName = info.vipName;
|
|
saveScore = info.levelKeepScore;
|
|
nextSecore = info.levelUpScore;
|
|
distanceValue = info.levelUpScore - model.currScore;
|
|
}
|
|
if (info.vipLevel > model.currLevel && hadNextLevel) {
|
|
hadNextLevel = NO;
|
|
nextLevelName = info.vipName;
|
|
|
|
}
|
|
}
|
|
NSAttributedString *levelStr = [[NSAttributedString alloc] initWithString:levelName attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:[DJDKMIMOMColor hightNobleLightTextColor]}];
|
|
[string appendAttributedString:levelStr];
|
|
if (model.isMaxLevel) {
|
|
[string appendAttributedString:[self createAttribute:YMLocalizedString(@"XPNobleCenterMyNobleView1") color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
} else {
|
|
[string appendAttributedString:[self createAttribute:YMLocalizedString(@"XPNobleCenterMyNobleView2") color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
NSAttributedString *distanceStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%zd", distanceValue] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13], NSForegroundColorAttributeName:[DJDKMIMOMColor hightNobleLightTextColor]}];
|
|
[string appendAttributedString:distanceStr];
|
|
[string appendAttributedString:[self createAttribute:YMLocalizedString(@"XPNobleCenterMyNobleView3") color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
[string appendAttributedString:[self createAttribute:nextLevelName color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
}
|
|
[string appendAttributedString:[self createAttribute:YMLocalizedString(@"XPNobleCenterMyNobleView4") color:[DJDKMIMOMColor normalNobleTextColor]]];
|
|
|
|
NSAttributedString *countTimeStr = [[NSAttributedString alloc] initWithString:[self cacularTimeWithSecond:model.remainSeconds] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13], NSForegroundColorAttributeName:[DJDKMIMOMColor hightNobleLightTextColor]}];
|
|
[string appendAttributedString:countTimeStr];
|
|
|
|
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
|
|
attachment.bounds = CGRectMake(0, 0, 10, 12);
|
|
attachment.image = [UIImage imageNamed:@"noble_indicate_icon"];
|
|
NSAttributedString * starAttribute = [NSMutableAttributedString attributedStringWithAttachment:(NSTextAttachment *)attachment];
|
|
[string appendAttributedString:starAttribute];
|
|
|
|
return string;
|
|
}
|
|
|
|
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color {
|
|
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:color};
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
|
|
return attr;
|
|
}
|
|
|
|
- (NSString *)cacularTimeWithSecond:(long long)second {
|
|
long long minSecond = 60;
|
|
long long hourSecond = minSecond * 60;
|
|
long long daySecond = hourSecond * 24;
|
|
|
|
NSString *day = @"";
|
|
NSString *hour = @"";
|
|
if (second > daySecond) {
|
|
day = [NSString stringWithFormat:@"%lld%@", second / daySecond, YMLocalizedString(@"App_Commont_Day")];
|
|
if (second % daySecond > hourSecond) {
|
|
hour = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView5"), (second % daySecond) / hourSecond];
|
|
return [NSString stringWithFormat:@"%@%@", day, hour];
|
|
}else {
|
|
return day;
|
|
}
|
|
} else if (second > hourSecond) {
|
|
return hour = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView6"), second / hourSecond];
|
|
} else {
|
|
return YMLocalizedString(@"XPNobleCenterMyNobleView7");
|
|
}
|
|
}
|
|
#pragma mark - events
|
|
- (void)onTimeButtonClick:(UIButton *)button {
|
|
XPNobleCenterResidueView *alertView = [[XPNobleCenterResidueView alloc] initWithFrame:CGRectMake(0, 0, 300, 286)];
|
|
TTPopupService * config = [[TTPopupService alloc] init];
|
|
config.shouldDismissOnBackgroundTouch = NO;
|
|
config.contentView = alertView;
|
|
[TTPopup popupWithConfig:config];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setModel:(NobleCenterModel *)model {
|
|
_model = model;
|
|
self.nobleLabel.attributedText = [self createNobleStringWithModel:model];
|
|
NSInteger safeScore = 0;
|
|
NSInteger nextScore = 0;
|
|
for (NobleInfo *info in model.vipInfos) {
|
|
if (info.vipLevel == model.currLevel) {
|
|
safeScore = info.levelKeepScore;
|
|
nextScore = info.levelUpScore;
|
|
}
|
|
}
|
|
self.safeValueLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView8"), safeScore];
|
|
self.upGradeValueLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView9"), nextScore];
|
|
self.currentValueLabel.text = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView10"), model.currScore];
|
|
CGFloat margin = self.backProgressView.frame.size.width * (model.currScore * 1.0 / nextScore);
|
|
[self.indicateImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.backProgressView.mas_leading).mas_offset(margin);
|
|
}];
|
|
CGFloat safeMargin = self.backProgressView.frame.size.width * (safeScore * 1.0 / nextScore);
|
|
[self.safeValueLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.backProgressView.mas_leading).mas_offset(safeMargin);
|
|
}];
|
|
self.upGradeValueLabel.hidden = model.isMaxLevel;
|
|
|
|
}
|
|
- (void)setVipInfo:(NobleInfo *)vipInfo{
|
|
_vipInfo = vipInfo;
|
|
if (_vipInfo.vipLevel > _model.currLevel){
|
|
self.openNobleView.hidden = NO;
|
|
self.openNobleButton.text = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterMyNobleView11"),_rechargeModel.money.floatValue,_vipInfo.vipName];
|
|
}else{
|
|
self.openNobleView.hidden = YES;
|
|
}
|
|
}
|
|
- (void)setIsHiddenPayBtn:(BOOL)isHiddenPayBtn{
|
|
_isHiddenPayBtn = isHiddenPayBtn;
|
|
self.openNobleView.hidden = _isHiddenPayBtn;
|
|
}
|
|
-(void)onOpenNobleButtonClick{
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(payNobleCenterWithModel:vipInfo:)]){
|
|
[self.delegate payNobleCenterWithModel:self.rechargeModel vipInfo:self.vipInfo];
|
|
}
|
|
}
|
|
- (UIView *)topView {
|
|
if (!_topView) {
|
|
_topView = [[UIView alloc] init];
|
|
_topView.backgroundColor = UIColorFromRGB(0x302B20);
|
|
}
|
|
return _topView;
|
|
}
|
|
- (YYLabel *)nobleLabel {
|
|
if (!_nobleLabel) {
|
|
_nobleLabel = [[YYLabel alloc] init];
|
|
_nobleLabel.textAlignment = NSTextAlignmentCenter;
|
|
_nobleLabel.numberOfLines = 0;
|
|
}
|
|
return _nobleLabel;
|
|
}
|
|
|
|
- (UIImageView *)privilegeIconImage {
|
|
if (!_privilegeIconImage) {
|
|
_privilegeIconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noble_privilege_icon"]];
|
|
}
|
|
return _privilegeIconImage;
|
|
}
|
|
|
|
- (UIView *)backProgressView {
|
|
if (!_backProgressView) {
|
|
_backProgressView = [[UIView alloc] init];
|
|
_backProgressView.backgroundColor = UIColorFromRGB(0x443A24);
|
|
_backProgressView.layer.cornerRadius = 6;
|
|
_backProgressView.layer.masksToBounds = YES;
|
|
_backProgressView.layer.borderColor = UIColorFromRGB(0xB49158).CGColor;
|
|
_backProgressView.layer.borderWidth = 0.5;
|
|
}
|
|
return _backProgressView;
|
|
}
|
|
- (UIImageView *)currentProgressView {
|
|
if (!_currentProgressView) {
|
|
_currentProgressView = [[UIImageView alloc] init];
|
|
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xF2B04E),UIColorFromRGB(0xFFE5BA)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(12, 12)];
|
|
_currentProgressView.image = image;
|
|
}
|
|
return _currentProgressView;
|
|
}
|
|
|
|
- (UIImageView *)indicateImageView {
|
|
if (!_indicateImageView) {
|
|
_indicateImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noble_indicate_icon"]];
|
|
}
|
|
return _indicateImageView;
|
|
}
|
|
|
|
- (UIImageView *)safeLevelImageView {
|
|
if (!_safeLevelImageView) {
|
|
_safeLevelImageView = [[UIImageView alloc] init];
|
|
_safeLevelImageView.image = [UIImage imageNamed:@"noble_safe_level_arrow"];
|
|
}
|
|
return _safeLevelImageView;
|
|
}
|
|
|
|
|
|
- (UILabel *)currentValueLabel {
|
|
if (!_currentValueLabel) {
|
|
_currentValueLabel = [[UILabel alloc] init];
|
|
_currentValueLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
// _currentValueLabel.textAlignment = NSTextAlignmentCenter;
|
|
_currentValueLabel.text = @"0";
|
|
_currentValueLabel.textColor = [DJDKMIMOMColor hightNobleLightTextColor];
|
|
}
|
|
return _currentValueLabel;
|
|
}
|
|
|
|
- (UILabel *)safeValueLabel {
|
|
if (!_safeValueLabel) {
|
|
_safeValueLabel = [[UILabel alloc] init];
|
|
_safeValueLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_safeValueLabel.textAlignment = NSTextAlignmentCenter;
|
|
_safeValueLabel.text = @"0";
|
|
_safeValueLabel.textColor = [DJDKMIMOMColor normalNobleTextColor];
|
|
}
|
|
return _safeValueLabel;
|
|
}
|
|
|
|
- (UILabel *)upGradeValueLabel {
|
|
if (!_upGradeValueLabel) {
|
|
_upGradeValueLabel = [[UILabel alloc] init];
|
|
_upGradeValueLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
_upGradeValueLabel.textAlignment = NSTextAlignmentCenter;
|
|
_upGradeValueLabel.text = @"0";
|
|
_upGradeValueLabel.textColor = [DJDKMIMOMColor normalNobleTextColor];
|
|
}
|
|
return _upGradeValueLabel;
|
|
}
|
|
|
|
- (UIButton *)timeDescButton {
|
|
if (!_timeDescButton) {
|
|
_timeDescButton = [[UIButton alloc] init];
|
|
[_timeDescButton setBackgroundImage:[UIImage imageNamed:@"noble_time_help"] forState:UIControlStateNormal];
|
|
[_timeDescButton addTarget:self action:@selector(onTimeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _timeDescButton;
|
|
}
|
|
- (UIImageView *)openNobleView{
|
|
if (!_openNobleView){
|
|
_openNobleView = [UIImageView new];
|
|
_openNobleView.image = kImage(@"noble_open_btn_bg");
|
|
_openNobleView.userInteractionEnabled = YES;
|
|
_openNobleView.hidden = YES;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onOpenNobleButtonClick)];
|
|
[_openNobleView addGestureRecognizer:tap];
|
|
}
|
|
return _openNobleView;
|
|
}
|
|
- (UILabel *)openNobleButton {
|
|
if (!_openNobleButton) {
|
|
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterViewController0"), @"2.99"];
|
|
_openNobleButton = [UILabel new];
|
|
_openNobleButton.text = title;
|
|
_openNobleButton.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
_openNobleButton.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_openNobleButton.numberOfLines = 0;
|
|
_openNobleButton.textAlignment = NSTextAlignmentCenter;
|
|
|
|
}
|
|
return _openNobleButton;
|
|
}
|
|
-(UIImageView *)openNobleIconView{
|
|
if (!_openNobleIconView){
|
|
_openNobleIconView = [UIImageView new];
|
|
_openNobleIconView.image = kImage(@"noble_open_btn");
|
|
}
|
|
return _openNobleIconView;
|
|
}
|
|
|
|
@end
|