// // XPMineGameMateOrderView.m // YuMi // // Created by P on 2024/7/9. // #import "XPMineGameMateOrderView.h" #import "XPIAPRechargeViewController.h" #import "XCCurrentVCStackManager.h" #import "XPMineGamePartnerInfoModel.h" #import "Api.h" #import "WalletInfoModel.h" @interface XPMineGameMateOrderView () @property (nonatomic, assign) NSInteger round; @property (nonatomic, assign) NSInteger currentCoin; @property (nonatomic, strong) UIImageView *bgImageView; @property (nonatomic, strong) NetImageView *logoImageView; @property (nonatomic, strong) UIButton *reduceButton; @property (nonatomic, strong) UILabel *numberLabel; @property (nonatomic, strong) UIButton *increaseButton; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *balanceLabel; @property (nonatomic, strong) UIButton *payButton; @property (nonatomic, strong) UIButton *rechargeButton; @end @implementation XPMineGameMateOrderView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.round = 1; [self setup]; [self getCoin]; } return self; } - (void)getCoin { NSString * uid = [AccountInfoStorage instance].getUid; NSString * ticket = [AccountInfoStorage instance].getTicket; @kWeakify(self); [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200) { @kStrongify(self); WalletInfoModel * model = [WalletInfoModel modelWithDictionary:data.data]; self.currentCoin = model.diamonds.integerValue; self.balanceLabel.text = @(self.currentCoin).stringValue; [self updateBalanceContent]; } } uid:uid ticket:ticket]; } - (void)setInfoModel:(XPMineGamePartnerInfoModel *)infoModel { _infoModel = infoModel; self.round = MAX(1, _infoModel.inning); self.logoImageView.imageUrl = infoModel.pic; self.numberLabel.text = @(self.round).stringValue; [self updatePriceContent]; } - (void)updatePriceContent { self.priceLabel.text = @(self.infoModel.price * self.round).stringValue; } - (void)updateBalanceContent { NSTextAttachment *coinAttachment = [[NSTextAttachment alloc] init]; coinAttachment.image = kImage(@"moli_money_icon"); coinAttachment.bounds = CGRectMake(2, -0.5, 10, 10); NSAttributedString *coin = [NSAttributedString attributedStringWithAttachment:coinAttachment]; NSAttributedString *price = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@:%ld ", YMLocalizedString(@"GameOrderContent_21"),(long)self.currentCoin] attributes:@{ NSFontAttributeName: self.balanceLabel.font, NSForegroundColorAttributeName: self.balanceLabel.textColor }]; NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:coin]; [mutableAttributedString insertAttributedString:price atIndex:0]; self.balanceLabel.attributedText = mutableAttributedString.copy; } - (void)setup { UIView *maskBG = [[UIView alloc] initWithFrame:self.bounds]; maskBG.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; [self addSubview:maskBG]; [self addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(KScreenWidth - 38*2, 280)); make.center.mas_equalTo(self); }]; UIImageView *closeImage = [[UIImageView alloc] initWithImage:kImage(@"noble_time_close")]; closeImage.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapCloseButton:)]; [closeImage addGestureRecognizer:tap]; [self addSubview:closeImage]; [closeImage mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(26, 26)); make.bottom.mas_equalTo(self.bgImageView.mas_top); make.leading.mas_equalTo(self.bgImageView.mas_trailing); }]; UILabel *titleLabel = [UILabel labelInitWithText:YMLocalizedString(@"GameOrderContent_5") font:kFontBold(20) textColor:UIColorFromRGB(0x563c1f)]; titleLabel.clipsToBounds = NO; [self addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.bgImageView).offset(24); make.centerX.mas_equalTo(self.bgImageView); make.height.mas_equalTo(20); }]; [self addSubview:self.logoImageView]; [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(titleLabel.mas_bottom).offset(17.5); make.centerX.mas_equalTo(self.bgImageView); make.size.mas_equalTo(CGSizeMake(KScreenWidth - 38*4, 95)); }]; UILabel *subTitleLabel_1 = [UILabel labelInitWithText:YMLocalizedString(@"GameOrderContent_19") font:kFontMedium(14) textColor:UIColorFromRGB(0x3f3c33)]; UILabel *subTitleLabel_2 = [UILabel labelInitWithText:YMLocalizedString(@"GameOrderContent_7") font:kFontMedium(14) textColor:UIColorFromRGB(0x3f3c33)]; UIStackView *subTitleStack = [[UIStackView alloc] init]; subTitleStack.axis = UILayoutConstraintAxisVertical; subTitleStack.alignment = UIStackViewAlignmentTop; subTitleStack.distribution = UIStackViewDistributionEqualSpacing; subTitleStack.spacing = 10; [subTitleStack addArrangedSubview:subTitleLabel_1]; [subTitleStack addArrangedSubview:subTitleLabel_2]; [self addSubview:subTitleStack]; [subTitleStack mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(19); make.leading.mas_equalTo(self.logoImageView); }]; [self addSubview:self.increaseButton]; [self.increaseButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(15); make.size.mas_equalTo(CGSizeMake(23, 23)); make.trailing.mas_equalTo(self.logoImageView); }]; [self addSubview:self.numberLabel]; [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.increaseButton); make.trailing.mas_equalTo(self.increaseButton.mas_leading).offset(-12.5); }]; [self addSubview:self.reduceButton]; [self.reduceButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(15); make.size.mas_equalTo(CGSizeMake(23, 23)); make.trailing.mas_equalTo(self.numberLabel.mas_leading).offset(-12.5); }]; UIStackView *priceStack = [[UIStackView alloc] init]; priceStack.spacing = 1; priceStack.distribution = UIStackViewDistributionFill; priceStack.alignment = UIStackViewAlignmentCenter; UIImageView *coinIcon = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")]; coinIcon.frame = CGRectMake(0, 0, 12, 12); [priceStack addArrangedSubview:self.priceLabel]; [priceStack addArrangedSubview:coinIcon]; [self addSubview:priceStack]; [priceStack mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.numberLabel); make.top.mas_equalTo(self.increaseButton.mas_bottom).offset(12); }]; UIImageView *line = [[UIImageView alloc] initWithImage:kImage(@"mine_game_order_line")]; [self addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.mas_equalTo(self.logoImageView); make.height.mas_equalTo(0.5); make.bottom.mas_equalTo(self.bgImageView).offset(-46); make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(15); }]; [self addSubview:self.balanceLabel]; [self.balanceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(line.mas_bottom).offset(15); make.leading.mas_equalTo(self.logoImageView); }]; [self addSubview:self.rechargeButton]; [self addSubview:self.payButton]; [self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.balanceLabel); make.leading.mas_equalTo(self.balanceLabel.mas_trailing).offset(8.5); }]; [self.payButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.balanceLabel); make.size.mas_equalTo(CGSizeMake(65, 26)); make.trailing.mas_equalTo(self.logoImageView); }]; } - (IBAction)didTapReduceButton:(id)sender { self.round--; if (self.round<1) { self.round = 1; } self.reduceButton.enabled = self.round >= 1; self.numberLabel.text = @(self.round).stringValue; [self updatePriceContent]; } - (IBAction)didTapIncreaseButton:(id)sender { self.round ++; self.numberLabel.text = @(self.round).stringValue; self.reduceButton.enabled = self.round >= 1; [self updatePriceContent]; } - (IBAction)didTapRechargeButton:(id)sender { XPIAPRechargeViewController *vc = [[XPIAPRechargeViewController alloc] init]; [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:vc animated:YES]; } - (IBAction)didTapPayButton:(id)sender { if (self.payForGame) { self.payForGame(self.round); } } - (IBAction)didTapCloseButton:(id)sender { [self removeFromSuperview]; } #pragma mark - - (UIImageView *)bgImageView { if (!_bgImageView) { _bgImageView = [[UIImageView alloc] initWithImage:[kImage(@"mine_game_order_bg") ms_SetImageForRTL]]; _bgImageView.contentMode = UIViewContentModeScaleAspectFill; } return _bgImageView; } - (NetImageView *)logoImageView { if (!_logoImageView) { NetImageConfig * config = [[NetImageConfig alloc] init]; config.placeHolder = [UIImageConstant defaultBannerPlaceholder]; _logoImageView = [[NetImageView alloc] initWithConfig:config]; _logoImageView.contentMode = UIViewContentModeScaleAspectFill; _logoImageView.layer.masksToBounds = YES; _logoImageView.layer.cornerRadius = 8; _logoImageView.layer.borderWidth = 2; _logoImageView.layer.borderColor = UIColorFromRGB(0xf09540).CGColor; _logoImageView.backgroundColor = [UIColor systemTealColor]; } return _logoImageView; } - (UIButton *)reduceButton { if (!_reduceButton) { _reduceButton = [UIButton buttonWithType:UIButtonTypeCustom]; _reduceButton.enabled = NO; [_reduceButton addTarget:self action:@selector(didTapReduceButton:) forControlEvents:UIControlEventTouchUpInside]; [_reduceButton setImage:kImage(@"mine_game_order_reduce_icon") forState:UIControlStateNormal]; [_reduceButton setImage:kImage(@"mine_game_order_reduce_icon_disable") forState:UIControlStateDisabled]; [_reduceButton enlargeTouchArea:UIEdgeInsetsMake(10, 10, 10, 10)]; } return _reduceButton; } - (UIButton *)increaseButton { if (!_increaseButton) { _increaseButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_increaseButton addTarget:self action:@selector(didTapIncreaseButton:) forControlEvents:UIControlEventTouchUpInside]; [_increaseButton setImage:kImage(@"mine_game_order_increase_icon") forState:UIControlStateNormal]; [_reduceButton enlargeTouchArea:UIEdgeInsetsMake(10, 10, 10, 10)]; } return _increaseButton; } - (UILabel *)numberLabel { if (!_numberLabel) { _numberLabel = [UILabel labelInitWithText:@"1" font:kFontMedium(13) textColor:UIColorFromRGB(0x471606)]; } return _numberLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [UILabel labelInitWithText:@"0" font:kFontMedium(13) textColor:UIColorFromRGB(0x471606)]; [_priceLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; [_priceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _priceLabel; } - (UILabel *)balanceLabel { if (!_balanceLabel) { _balanceLabel = [UILabel labelInitWithText:YMLocalizedString(@"GameOrderContent_21") font:kFontMedium(12) textColor:UIColorFromRGB(0x471606)]; } return _balanceLabel; } - (UIButton *)rechargeButton { if (!_rechargeButton) { _rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_rechargeButton setTitle:[NSString stringWithFormat:@"%@ >", YMLocalizedString(@"XPGiftBarView1")] forState:UIControlStateNormal]; [_rechargeButton.titleLabel setFont:kFontMedium(12)]; [_rechargeButton setTitleColor:UIColorFromRGB(0xff433a) forState:UIControlStateNormal]; [_rechargeButton addTarget:self action:@selector(didTapRechargeButton:) forControlEvents:UIControlEventTouchUpInside]; _rechargeButton.titleLabel.adjustsFontSizeToFitWidth = YES; _rechargeButton.titleLabel.minimumScaleFactor = 0.5; // 最小缩放比例 } return _rechargeButton; } - (UIButton *)payButton { if (!_payButton) { _payButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_payButton setTitle:YMLocalizedString(@"GameOrderContent_22") forState:UIControlStateNormal]; UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x57e193),UIColorFromRGB(0x14d2a6)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(65, 26)]; [_payButton setBackgroundImage:image forState:UIControlStateNormal]; [_payButton.titleLabel setFont:kFontMedium(13)]; [_payButton addTarget:self action:@selector(didTapPayButton:) forControlEvents:UIControlEventTouchUpInside]; _payButton.layer.cornerRadius = 13; _payButton.layer.masksToBounds = YES; } return _payButton; } @end