From f960df14244e44430e4e023a4866c03345f333e0 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sun, 7 Feb 2021 12:43:23 -0800 Subject: [PATCH] Makes armor type a picker instead of a string. --- iOS/MonsterCards.xcodeproj/project.pbxproj | 4 +++ iOS/MonsterCards/Views/EditMonster.swift | 11 +++--- .../Views/MCArmorTypePicker.swift | 36 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 iOS/MonsterCards/Views/MCArmorTypePicker.swift diff --git a/iOS/MonsterCards.xcodeproj/project.pbxproj b/iOS/MonsterCards.xcodeproj/project.pbxproj index 270b3bf..cb18033 100644 --- a/iOS/MonsterCards.xcodeproj/project.pbxproj +++ b/iOS/MonsterCards.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ E2570FFF25B1AE180055B23B /* Library.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2570FFE25B1AE180055B23B /* Library.swift */; }; E257100425B1AF4A0055B23B /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = E257100325B1AF4A0055B23B /* SearchBar.swift */; }; E257100925B1B2480055B23B /* MonsterDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = E257100825B1B2470055B23B /* MonsterDetail.swift */; }; + E26CDA2B25CFB38E00E3F50D /* MCArmorTypePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26CDA2A25CFB38E00E3F50D /* MCArmorTypePicker.swift */; }; E2B5285925B3028700AAA69E /* EditMonster.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2B5285825B3028700AAA69E /* EditMonster.swift */; }; E2BD702C25B3A8D70058ED69 /* MCTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2BD702B25B3A8D70058ED69 /* MCTextField.swift */; }; E2BD703125B3BBB90058ED69 /* MCStepperField.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2BD703025B3BBB90058ED69 /* MCStepperField.swift */; }; @@ -75,6 +76,7 @@ E2570FFE25B1AE180055B23B /* Library.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Library.swift; sourceTree = ""; }; E257100325B1AF4A0055B23B /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; E257100825B1B2470055B23B /* MonsterDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonsterDetail.swift; sourceTree = ""; }; + E26CDA2A25CFB38E00E3F50D /* MCArmorTypePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCArmorTypePicker.swift; sourceTree = ""; }; E2B5285825B3028700AAA69E /* EditMonster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditMonster.swift; sourceTree = ""; }; E2BD702B25B3A8D70058ED69 /* MCTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCTextField.swift; sourceTree = ""; }; E2BD703025B3BBB90058ED69 /* MCStepperField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCStepperField.swift; sourceTree = ""; }; @@ -183,6 +185,7 @@ E2BD702B25B3A8D70058ED69 /* MCTextField.swift */, E2BD703025B3BBB90058ED69 /* MCStepperField.swift */, E210B83925B42D980083EAC5 /* MCProficiencyPicker.swift */, + E26CDA2A25CFB38E00E3F50D /* MCArmorTypePicker.swift */, ); path = Views; sourceTree = ""; @@ -353,6 +356,7 @@ E210B83025B426570083EAC5 /* ProficiencyType.swift in Sources */, E2BD702C25B3A8D70058ED69 /* MCTextField.swift in Sources */, E210B83F25B42DAB0083EAC5 /* MCAdvantagePicker.swift in Sources */, + E26CDA2B25CFB38E00E3F50D /* MCArmorTypePicker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iOS/MonsterCards/Views/EditMonster.swift b/iOS/MonsterCards/Views/EditMonster.swift index 3f0dc72..92f6c90 100644 --- a/iOS/MonsterCards/Views/EditMonster.swift +++ b/iOS/MonsterCards/Views/EditMonster.swift @@ -23,7 +23,7 @@ struct EditMonster: View { @State private var monsterHitDice: Int64 = 0 @State private var monsterHasCustomHP: Bool = false @State private var monsterCustomHP: String = "" - @State private var monsterArmorType: String = "" + @State private var monsterArmorType: ArmorType = ArmorType.none @State private var monsterHasShield: Bool = false @State private var monsterNaturalArmorBonus: Int64 = 0 @State private var monsterCustomArmor: String = "" @@ -103,9 +103,8 @@ struct EditMonster: View { .textCase(nil) Section(header: Text("Armor")) { - // Armor Type select bound to monster.armorType? - // TODO: this should be a select/dropdown - MCTextField( + // Armor Type select bound to monster.armorTypeEnum + MCArmorTypePicker( label: "Armor Type", value: $monsterArmorType) @@ -306,7 +305,7 @@ struct EditMonster: View { monsterHitDice = monster.hitDice monsterHasCustomHP = monster.hasCustomHP monsterCustomHP = monster.customHP ?? "" - monsterArmorType = monster.armorType ?? "" + monsterArmorType = monster.armorTypeEnum monsterHasShield = monster.hasShield monsterNaturalArmorBonus = monster.naturalArmorBonus monsterCustomArmor = monster.customArmor ?? "" @@ -347,7 +346,7 @@ struct EditMonster: View { monster.hitDice = monsterHitDice monster.hasCustomHP = monsterHasCustomHP monster.customHP = monsterCustomHP - monster.armorType = monsterArmorType + monster.armorType = monsterArmorType.rawValue monster.hasShield = monsterHasShield monster.naturalArmorBonus = monsterNaturalArmorBonus monster.customArmor = monsterCustomArmor diff --git a/iOS/MonsterCards/Views/MCArmorTypePicker.swift b/iOS/MonsterCards/Views/MCArmorTypePicker.swift new file mode 100644 index 0000000..a59b6df --- /dev/null +++ b/iOS/MonsterCards/Views/MCArmorTypePicker.swift @@ -0,0 +1,36 @@ +// +// MCArmorTypePicker.swift +// MonsterCards +// +// Created by Tom Hicks on 2/6/21. +// + +import SwiftUI + +struct MCArmorTypePicker: View { + var label: String = "" + var value: Binding + + var body: some View { + VStack(alignment: .leading) { + Text(label) + .font(.caption2) + Picker( + selection: value, + label: Text(value.wrappedValue.displayName)) { + ForEach(ArmorType.allCases) {armorType in + Text(armorType.displayName).tag(armorType) + } + } + .pickerStyle(MenuPickerStyle()) + } + } +} + +struct MCArmorTypePicker_Previews: PreviewProvider { + static var previews: some View { + MCArmorTypePicker( + value: .constant(ArmorType.none) + ) + } +}