ui cleanup

This commit is contained in:
Rory Hinnen
2026-09-07 11:15:18 -05:00
parent 025b006194
commit 2c10c7c093
+152 -129
View File
@@ -76,35 +76,37 @@ struct MainView: View {
//MARK: State Views
@ViewBuilder func armourCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) {
Spacer()
VStack {
Text("Armour")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addPenetration()
})
Text(
(current.armourPenetration > 0 ?
"+" : "") +
String(current.armourPenetration))
Text("▼")
.gesture(TapGesture() .onEnded {
current.losePenetration()
})
VStack {
HStack(alignment: .top) {
Spacer()
VStack {
Text("Armour")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addPenetration()
})
Text(
(current.armourPenetration > 0 ?
"+" : "") +
String(current.armourPenetration))
Text("▼")
.gesture(TapGesture() .onEnded {
current.losePenetration()
})
}
.font(.system(size: controlSize))
Text("Penetration")
}
.font(.system(size: controlSize))
Text("Penetration")
Spacer()
VStack {
Text("Invulnerable")
Toggle("", isOn: $current.invulnerable).labelsHidden()
.padding()
}
Spacer()
}
Spacer()
VStack{
Text("Invulnerable")
Toggle("", isOn: $current.invulnerable).labelsHidden()
.padding()
}
Spacer()
VStack {
HStack {
Text("Reroll")
Picker("", selection: $current.saveRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in
@@ -112,76 +114,75 @@ struct MainView: View {
}
}
.pickerStyle(.segmented)
.frame(width: 180)
Button("🎲") {
current.applyReroll()
}
.disabled(current.saveRerollMode == .none || current.saveHasRerolled)
.padding()
.font(.system(size: controlSize))
}
Spacer()
.padding(.horizontal)
}
.padding()
}
@ViewBuilder func woundCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) {
Spacer()
VStack {
Text("Attack")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addStrength()
})
Text(String(current.strength))
Text("▼")
.gesture(TapGesture() .onEnded {
current.loseStrength()
})
}.font(.system(size: controlSize))
Text("Strength")
VStack {
HStack(alignment: .top) {
Spacer()
VStack {
Text("Attack")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addStrength()
})
Text(String(current.strength))
Text("▼")
.gesture(TapGesture() .onEnded {
current.loseStrength()
})
}.font(.system(size: controlSize))
Text("Strength")
}
Spacer()
VStack {
Text("Toughness")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addToughness()
})
Text(String(current.toughness))
Text("▼")
.gesture(TapGesture() .onEnded {
current.loseToughness()
})
}.font(.system(size: controlSize))
Text(" ")
}
Spacer()
VStack {
Text("Wound")
.multilineTextAlignment(.center)
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.woundModifier = current.woundModifier.add()
})
Text(
(current.woundModifier.rawValue > 0 ?
"+" : "") +
String(current.woundModifier.rawValue))
Text("▼")
.gesture(TapGesture() .onEnded {
current.woundModifier = current.woundModifier.remove()
})
}.font(.system(size: controlSize))
Text("Modifier")
}
Spacer()
}
Spacer()
VStack {
Text("Toughness")
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.addToughness()
})
Text(String(current.toughness))
Text("▼")
.gesture(TapGesture() .onEnded {
current.loseToughness()
})
}.font(.system(size: controlSize))
Text(" ")
}
Spacer()
VStack {
Text("Wound")
.multilineTextAlignment(.center)
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.woundModifier = current.woundModifier.add()
})
Text(
(current.woundModifier.rawValue > 0 ?
"+" : "") +
String(current.woundModifier.rawValue))
Text("▼")
.gesture(TapGesture() .onEnded {
current.woundModifier = current.woundModifier.remove()
})
}.font(.system(size: controlSize))
Text("Modifier")
}
Spacer()
VStack {
HStack {
Text("Reroll")
Picker("", selection: $current.woundRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in
@@ -189,40 +190,40 @@ struct MainView: View {
}
}
.pickerStyle(.segmented)
.frame(width: 180)
Button("🎲") {
current.applyReroll()
}
.disabled(current.woundRerollMode == .none || current.woundHasRerolled)
.padding()
.font(.system(size: controlSize))
}
Spacer()
}.padding()
.padding(.horizontal)
}
.padding()
}
@ViewBuilder func hitCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) {
Group {
VStack {
HStack(alignment: .top) {
Spacer()
VStack {
Text("Hit")
.multilineTextAlignment(.center)
Group {
Text("▲")
.gesture(TapGesture() .onEnded {
current.modifier = current.modifier.add()
})
Text( (current.modifier.rawValue > 0 ?
"+" : "") +
String(current.modifier.rawValue))
Text("▼")
.gesture(TapGesture() .onEnded {
current.modifier = current.modifier.remove()
})
Text("▲")
.gesture(TapGesture() .onEnded {
current.modifier = current.modifier.add()
})
Text((current.modifier.rawValue > 0 ? "+" : "") +
String(current.modifier.rawValue))
Text("▼")
.gesture(TapGesture() .onEnded {
current.modifier = current.modifier.remove()
})
}
.font(.system(size: controlSize))
Text("Modifier")
}
Spacer()
VStack {
Text("Blow Up")
VStack {
@@ -239,26 +240,26 @@ struct MainView: View {
}
.padding()
.font(.system(size: controlSize))
}
VStack {
Text("Reroll")
Picker("", selection: $current.hitRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in
Text(mode.label).tag(mode)
}
}
.pickerStyle(.segmented)
.frame(width: 180)
Button("🎲") {
current.applyReroll()
}
.disabled(current.hitRerollMode == .none || current.hitHasRerolled)
.padding()
.font(.system(size: controlSize))
}
Spacer()
}
}.padding()
HStack {
Text("Reroll")
Picker("", selection: $current.hitRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in
Text(mode.label).tag(mode)
}
}
.pickerStyle(.segmented)
Button("🎲") {
current.applyReroll()
}
.disabled(current.hitRerollMode == .none || current.hitHasRerolled)
.font(.system(size: controlSize))
}
.padding(.horizontal)
}
.padding()
}
//MARK: die views
@@ -272,6 +273,7 @@ struct MainView: View {
Text(String(current.dice.value(which: whichDie)))
.foregroundColor(current.state == .armour ?
displayColorArmorText : displayColorHit)
.frame(minWidth: 44, alignment: .trailing)
Image(systemName: "die.face." + String(whichDie.rawValue) + ".fill")
.foregroundColor(current.state == .armour ?
displayColorArmor : displayColorHit)
@@ -326,8 +328,18 @@ struct MainView: View {
VStack{
HStack {
VStack {
Button(action: {showFillView.toggle()}) {
buttons(color: blue, label: "Pool", value: current.total)
Button(action: { showFillView.toggle() }) {
VStack(spacing: 2) {
Text("Dice Pool")
.font(.caption)
Text(String(current.total))
.font(.system(size: 28, weight: .black))
}
.padding(.horizontal, 20)
.padding(.vertical, 8)
.background(Color(blue).opacity(0.35))
.clipShape(RoundedRectangle(cornerRadius: 10))
.foregroundColor(.primary)
}
.sheet(isPresented: $showFillView,
onDismiss: { current.resetPool() }) {
@@ -337,11 +349,9 @@ struct MainView: View {
.padding(20)
}
}
Spacer()
Button(action: current.incrementState) {
buttons(color: red, label: current.state.text(), value: current.result)
}
}.padding(.leading, padSize)
Spacer()
diePool().padding(.trailing, padSize)
@@ -366,9 +376,22 @@ struct MainView: View {
.sheet(isPresented: $sheet.isShowing, content: sheetContent)}
}
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView()
.environmentObject(Roll())
}
#Preview("Hit") {
MainView().environmentObject(Roll())
}
#Preview("Wound") {
MainView().environmentObject({
let r = Roll()
r.state = .wound
return r
}())
}
#Preview("Armour") {
MainView().environmentObject({
let r = Roll()
r.state = .armour
return r
}())
}