首次提交
This commit is contained in:
197
SweetParty/主类/音悦新增/炼仙传说/WLStakeAlertView.m
Normal file
197
SweetParty/主类/音悦新增/炼仙传说/WLStakeAlertView.m
Normal file
@@ -0,0 +1,197 @@
|
||||
//
|
||||
// WLStakeAlertView.m
|
||||
// romantic
|
||||
//
|
||||
// Created by Xmac on 2024/4/16.
|
||||
// Copyright © 2024 romantic. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WLStakeAlertView.h"
|
||||
#import "TFPopup.h"
|
||||
#import "WLStakeItem.h"
|
||||
|
||||
@interface WLStakeAlertView ()<UICollectionViewDelegate, UICollectionViewDataSource>
|
||||
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *subBtn;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *addBtn;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
|
||||
@property (weak, nonatomic) IBOutlet UITextField *numTF;
|
||||
@property (nonatomic, strong) NSMutableArray *dataArr;
|
||||
@property (nonatomic, assign) NSInteger selectIndex;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *unitPriceLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
|
||||
@property (weak, nonatomic) IBOutlet UIView *blcakView;
|
||||
|
||||
|
||||
@end
|
||||
@implementation WLStakeAlertView
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[super awakeFromNib];
|
||||
|
||||
[self.numTF addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
[self initConfig];
|
||||
[self setupUI];
|
||||
|
||||
WEAK_SELF
|
||||
[self.blcakView dg_Tapped:^{
|
||||
[weakSelf dismiss];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)initConfig {
|
||||
self.selectIndex = -1;
|
||||
self.dataArr = @[@"1",@"10", @"20", @"30", @"50", @"100"].mutableCopy;
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||
CGFloat itemW = (APPW-90-30)/3.0 - 1.0;
|
||||
CGFloat itemH = 32;
|
||||
flowLayout.itemSize = CGSizeMake(itemW, itemH);
|
||||
flowLayout.minimumLineSpacing = 10;
|
||||
flowLayout.minimumInteritemSpacing = 15;
|
||||
flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
||||
|
||||
// flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
|
||||
_collectionView.collectionViewLayout = flowLayout;
|
||||
_collectionView.backgroundColor = UIColor.clearColor;
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.showsHorizontalScrollIndicator = NO;
|
||||
|
||||
[_collectionView registerNib:[UINib nibWithNibName:@"WLStakeItem" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"WLStakeItem"];
|
||||
}
|
||||
|
||||
- (void)textFieldChanged:(UITextField*)textField {
|
||||
[self calculateNum];
|
||||
}
|
||||
|
||||
- (void)calculateNum {
|
||||
self.priceLabel.text = [NSString stringWithFormat:@"金币%ld/%@", self.numTF.text.integerValue * self.unitPrice.integerValue, self.remainPrice];
|
||||
}
|
||||
|
||||
- (IBAction)onSub:(id)sender {
|
||||
NSInteger num = [self.numTF.text integerValue];
|
||||
if (num <= 1) {
|
||||
return;
|
||||
}
|
||||
num -= 1;
|
||||
self.numTF.text = [NSString stringWithFormat:@"%ld", num];
|
||||
[self calculateNum];
|
||||
}
|
||||
|
||||
- (IBAction)onAdd:(id)sender {
|
||||
NSInteger num = [self.numTF.text integerValue];
|
||||
num += 1;
|
||||
self.numTF.text = [NSString stringWithFormat:@"%ld", num];
|
||||
[self calculateNum];
|
||||
}
|
||||
|
||||
- (IBAction)onCancel:(id)sender {
|
||||
[self tf_hide];
|
||||
}
|
||||
|
||||
- (IBAction)onConfirm:(id)sender {
|
||||
if (self.onConfirmBlock) {
|
||||
self.onConfirmBlock([self.numTF.text integerValue]);
|
||||
}
|
||||
[self tf_remove];
|
||||
}
|
||||
|
||||
- (void)onPopupWithSize:(CGSize)size {
|
||||
self.frame = CGRectMake(0, 0, size.width, size.height);
|
||||
TFPopupParam *param = [[TFPopupParam alloc] init];
|
||||
[self tf_showNormal:KEYWINDOW popupParam:param];
|
||||
}
|
||||
|
||||
- (void)dismiss {
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)show {
|
||||
self.frame = [UIScreen mainScreen].bounds;
|
||||
[MainWindow() addSubview:self];
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return self.dataArr.count;
|
||||
|
||||
}
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
WLStakeItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WLStakeItem" forIndexPath:indexPath];
|
||||
cell.titleLabel.text = [NSString stringWithFormat:@"%@",self.dataArr[indexPath.row]];
|
||||
if(self.selectIndex == indexPath.row){
|
||||
// cell.backImageView.backgroundColor = HEXCOLOR(0xFFA50A);
|
||||
// cell.backImageView.layer.borderWidth = 1;
|
||||
// cell.backImageView.layer.borderColor = HEXCOLOR(0x333333).CGColor;
|
||||
cell.backImageView.image = ImageNamed(@"stake_item_sel");
|
||||
// cell.titleLabel.textColor = kWhiteColor;
|
||||
}else{
|
||||
// cell.backImageView.backgroundColor = kClearColor;
|
||||
// cell.backImageView.layer.borderWidth = 1;
|
||||
// cell.backImageView.layer.borderColor = HEXCOLOR(0x333333).CGColor;
|
||||
cell.backImageView.image = ImageNamed(@"stake_item_nor");
|
||||
// cell.titleLabel.textColor = HEXCOLOR(0x333333);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSString *num = self.dataArr[indexPath.row];
|
||||
self.selectIndex = indexPath.row;
|
||||
self.numTF.text = num;
|
||||
[self calculateNum];
|
||||
[self.collectionView reloadData];
|
||||
|
||||
}
|
||||
|
||||
- (void)setType:(NSString *)type {
|
||||
_type = type;
|
||||
if ([_type isEqualToString:@"1"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_1");
|
||||
_nameLabel.text = @"天魔城";
|
||||
} else if ([_type isEqualToString:@"2"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_2");
|
||||
_nameLabel.text = @"天悲谷";
|
||||
} else if ([_type isEqualToString:@"3"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_3");
|
||||
_nameLabel.text = @"九煞山";
|
||||
} else if ([_type isEqualToString:@"4"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_4");
|
||||
_nameLabel.text = @"昊天府";
|
||||
} else if ([_type isEqualToString:@"5"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_5");
|
||||
_nameLabel.text = @"凌云殿";
|
||||
} else if ([_type isEqualToString:@"6"]) {
|
||||
_iconImageView.image = ImageNamed(@"stake_name_6");
|
||||
_nameLabel.text = @"半月宫";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setUnitPrice:(NSString *)unitPrice {
|
||||
_unitPrice = unitPrice;
|
||||
self.unitPriceLabel.text = [NSString stringWithFormat:@"%@金币/次", _unitPrice];
|
||||
}
|
||||
|
||||
- (void)setRemainPrice:(NSString *)remainPrice {
|
||||
_remainPrice = remainPrice;
|
||||
[self calculateNum];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user