//
|
// GamesPayView.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/9/15.
|
//
|
|
import UIKit
|
import JQTools
|
|
class GamesPayView: UIView,JQNibView{
|
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var label_price: UILabel!
|
@IBOutlet weak var label_coin: UILabel!
|
@IBOutlet weak var label_integral: UILabel!
|
|
private var price:Double = 0
|
private var coin:Int?
|
private var integral:Int?
|
private var needPay:(()->Void)!
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
label_coin.isHidden = true
|
label_integral.isHidden = true
|
label_price.isHidden = true
|
view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
|
alpha = 0
|
layoutIfNeeded()
|
}
|
|
static func show(price:Double,coin:Int?,integral:Int? = nil,needPay: @escaping ()->Void){
|
let gamesPayView = GamesPayView.jq_loadNibView()
|
gamesPayView.frame = sceneDelegate?.window?.frame ?? .zero
|
gamesPayView.price = price
|
gamesPayView.coin = coin
|
gamesPayView.integral = integral
|
gamesPayView.needPay = needPay
|
|
if price != 0 && price != 0{
|
gamesPayView.label_price.isHidden = false
|
gamesPayView.label_price.attributedText = AttributedStringbuilder.build().add(string: "游玩价格:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: price.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
|
}
|
|
|
if coin != nil && coin != 0{
|
gamesPayView.label_coin.isHidden = false
|
gamesPayView.label_coin.attributedText = AttributedStringbuilder.build().add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: "\(coin!)币", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
|
}
|
|
if integral != nil && integral != 0{
|
gamesPayView.label_integral.isHidden = false
|
gamesPayView.label_integral.attributedText = AttributedStringbuilder.build().add(string: "积分:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: "\(integral!)", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
|
}
|
|
|
sceneDelegate?.window?.addSubview(gamesPayView)
|
UIView.animate(withDuration: 0.5) {
|
gamesPayView.view_container.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
gamesPayView.alpha = 1
|
} completion: { _ in
|
|
}
|
}
|
|
@IBAction func payAction(_ sender: UIButton) {
|
needPay()
|
cancel()
|
}
|
|
@IBAction func closeAction(_ sender: UIButton) {
|
cancel()
|
}
|
|
private func cancel(){
|
UIView.animate(withDuration: 0.5) {
|
self.view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
}
|