|
|
@@ -44,6 +44,7 @@ extension LNSkillFieldPriceEditView {
|
|
|
let panel = LNSkillPriceEditPanel()
|
|
|
panel.titleLabel.text = field.fieldName
|
|
|
panel.inputField.text = (field.value as? Double)?.toDisplay
|
|
|
+ panel.limit = field.validate.numLimit
|
|
|
panel.handler = { [weak self] price in
|
|
|
guard let self else { return }
|
|
|
curValueLabel.text = price.toDisplay
|
|
|
@@ -83,9 +84,10 @@ extension LNSkillFieldPriceEditView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-private class LNSkillPriceEditPanel: LNPopupView {
|
|
|
+private class LNSkillPriceEditPanel: LNPopupView, UITextFieldDelegate {
|
|
|
let titleLabel = UILabel()
|
|
|
let inputField = UITextField()
|
|
|
+ var limit: LNSkillFieldValidateNumLimit?
|
|
|
private let confirmButton = UIButton()
|
|
|
|
|
|
var handler: ((Double) -> Void)?
|
|
|
@@ -131,6 +133,7 @@ private class LNSkillPriceEditPanel: LNPopupView {
|
|
|
inputField.textColor = .text_5
|
|
|
inputField.placeholder = .init(key: "B00097")
|
|
|
inputField.keyboardType = .decimalPad
|
|
|
+ inputField.delegate = self
|
|
|
inputField.addAction(UIAction(handler: { [weak self] _ in
|
|
|
guard let self else { return }
|
|
|
let inputAvailable = if let text = inputField.text, Double(text) != nil {
|
|
|
@@ -169,6 +172,12 @@ private class LNSkillPriceEditPanel: LNPopupView {
|
|
|
confirmButton.backgroundColor = .fill_4
|
|
|
confirmButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
guard let self else { return }
|
|
|
+ let text = inputField.text ?? "0"
|
|
|
+ let value = Double(text) ?? 0
|
|
|
+ if let limit, value < limit.min || value > limit.max {
|
|
|
+ showToast(.init(key: "B00102", limit.min.toDisplay, limit.max.toDisplay))
|
|
|
+ return
|
|
|
+ }
|
|
|
dismiss()
|
|
|
handler?(Double(inputField.text ?? "0") ?? 0)
|
|
|
}), for: .touchUpInside)
|
|
|
@@ -184,4 +193,38 @@ private class LNSkillPriceEditPanel: LNPopupView {
|
|
|
required init?(coder: NSCoder) {
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
}
|
|
|
+
|
|
|
+ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
|
|
+ guard let limit else { return true }
|
|
|
+ let currentText = textField.text ?? ""
|
|
|
+
|
|
|
+ guard let range = Range(range, in: currentText) else { return false }
|
|
|
+ let newText = currentText.replacingCharacters(in: range, with: string)
|
|
|
+ if newText.isEmpty {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if newText.starts(with: "00") {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ if newText.filter({ $0 == "." }).count > 2 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let value = Double(newText) else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ if value > limit.max {
|
|
|
+ showToast(.init(key: "B00102", limit.min.toDisplay, limit.max.toDisplay))
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
|
|
+ textField.resignFirstResponder()
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|