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 //MARK: State Views
@ViewBuilder func armourCalculator(controlSize: Double) -> some View { @ViewBuilder func armourCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) { VStack {
Spacer() HStack(alignment: .top) {
VStack { Spacer()
Text("Armour") VStack {
Group { Text("Armour")
Text("▲") Group {
.gesture(TapGesture() .onEnded { Text("▲")
current.addPenetration() .gesture(TapGesture() .onEnded {
}) current.addPenetration()
Text( })
(current.armourPenetration > 0 ? Text(
"+" : "") + (current.armourPenetration > 0 ?
String(current.armourPenetration)) "+" : "") +
Text("▼") String(current.armourPenetration))
.gesture(TapGesture() .onEnded { Text("▼")
current.losePenetration() .gesture(TapGesture() .onEnded {
}) current.losePenetration()
})
}
.font(.system(size: controlSize))
Text("Penetration")
} }
.font(.system(size: controlSize)) Spacer()
Text("Penetration") VStack {
Text("Invulnerable")
Toggle("", isOn: $current.invulnerable).labelsHidden()
.padding()
}
Spacer()
} }
Spacer() HStack {
VStack{
Text("Invulnerable")
Toggle("", isOn: $current.invulnerable).labelsHidden()
.padding()
}
Spacer()
VStack {
Text("Reroll") Text("Reroll")
Picker("", selection: $current.saveRerollMode) { Picker("", selection: $current.saveRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in ForEach(RerollMode.allCases, id: \.self) { mode in
@@ -112,76 +114,75 @@ struct MainView: View {
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)
.frame(width: 180)
Button("🎲") { Button("🎲") {
current.applyReroll() current.applyReroll()
} }
.disabled(current.saveRerollMode == .none || current.saveHasRerolled) .disabled(current.saveRerollMode == .none || current.saveHasRerolled)
.padding()
.font(.system(size: controlSize)) .font(.system(size: controlSize))
} }
Spacer() .padding(.horizontal)
} }
.padding() .padding()
} }
@ViewBuilder func woundCalculator(controlSize: Double) -> some View { @ViewBuilder func woundCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) { VStack {
Spacer() HStack(alignment: .top) {
VStack { Spacer()
Text("Attack") VStack {
Group { Text("Attack")
Text("▲") Group {
.gesture(TapGesture() .onEnded { Text("▲")
current.addStrength() .gesture(TapGesture() .onEnded {
}) current.addStrength()
Text(String(current.strength)) })
Text("▼") Text(String(current.strength))
.gesture(TapGesture() .onEnded { Text("▼")
current.loseStrength() .gesture(TapGesture() .onEnded {
}) current.loseStrength()
}.font(.system(size: controlSize)) })
Text("Strength") }.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()
} }
HStack {
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 {
Text("Reroll") Text("Reroll")
Picker("", selection: $current.woundRerollMode) { Picker("", selection: $current.woundRerollMode) {
ForEach(RerollMode.allCases, id: \.self) { mode in ForEach(RerollMode.allCases, id: \.self) { mode in
@@ -189,40 +190,40 @@ struct MainView: View {
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)
.frame(width: 180)
Button("🎲") { Button("🎲") {
current.applyReroll() current.applyReroll()
} }
.disabled(current.woundRerollMode == .none || current.woundHasRerolled) .disabled(current.woundRerollMode == .none || current.woundHasRerolled)
.padding()
.font(.system(size: controlSize)) .font(.system(size: controlSize))
} }
Spacer() .padding(.horizontal)
}.padding() }
.padding()
} }
@ViewBuilder func hitCalculator(controlSize: Double) -> some View { @ViewBuilder func hitCalculator(controlSize: Double) -> some View {
HStack(alignment: .top) { VStack {
Group { HStack(alignment: .top) {
Spacer()
VStack { VStack {
Text("Hit") Text("Hit")
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
Group { Group {
Text("▲") Text("▲")
.gesture(TapGesture() .onEnded { .gesture(TapGesture() .onEnded {
current.modifier = current.modifier.add() current.modifier = current.modifier.add()
}) })
Text( (current.modifier.rawValue > 0 ? Text((current.modifier.rawValue > 0 ? "+" : "") +
"+" : "") + String(current.modifier.rawValue))
String(current.modifier.rawValue)) Text("▼")
Text("▼") .gesture(TapGesture() .onEnded {
.gesture(TapGesture() .onEnded { current.modifier = current.modifier.remove()
current.modifier = current.modifier.remove() })
})
} }
.font(.system(size: controlSize)) .font(.system(size: controlSize))
Text("Modifier") Text("Modifier")
} }
Spacer()
VStack { VStack {
Text("Blow Up") Text("Blow Up")
VStack { VStack {
@@ -239,26 +240,26 @@ struct MainView: View {
} }
.padding() .padding()
.font(.system(size: controlSize)) .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 //MARK: die views
@@ -272,6 +273,7 @@ struct MainView: View {
Text(String(current.dice.value(which: whichDie))) Text(String(current.dice.value(which: whichDie)))
.foregroundColor(current.state == .armour ? .foregroundColor(current.state == .armour ?
displayColorArmorText : displayColorHit) displayColorArmorText : displayColorHit)
.frame(minWidth: 44, alignment: .trailing)
Image(systemName: "die.face." + String(whichDie.rawValue) + ".fill") Image(systemName: "die.face." + String(whichDie.rawValue) + ".fill")
.foregroundColor(current.state == .armour ? .foregroundColor(current.state == .armour ?
displayColorArmor : displayColorHit) displayColorArmor : displayColorHit)
@@ -326,8 +328,18 @@ struct MainView: View {
VStack{ VStack{
HStack { HStack {
VStack { VStack {
Button(action: {showFillView.toggle()}) { Button(action: { showFillView.toggle() }) {
buttons(color: blue, label: "Pool", value: current.total) 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, .sheet(isPresented: $showFillView,
onDismiss: { current.resetPool() }) { onDismiss: { current.resetPool() }) {
@@ -337,11 +349,9 @@ struct MainView: View {
.padding(20) .padding(20)
} }
} }
Spacer()
Button(action: current.incrementState) { Button(action: current.incrementState) {
buttons(color: red, label: current.state.text(), value: current.result) buttons(color: red, label: current.state.text(), value: current.result)
} }
}.padding(.leading, padSize) }.padding(.leading, padSize)
Spacer() Spacer()
diePool().padding(.trailing, padSize) diePool().padding(.trailing, padSize)
@@ -366,9 +376,22 @@ struct MainView: View {
.sheet(isPresented: $sheet.isShowing, content: sheetContent)} .sheet(isPresented: $sheet.isShowing, content: sheetContent)}
} }
struct MainView_Previews: PreviewProvider { #Preview("Hit") {
static var previews: some View { MainView().environmentObject(Roll())
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
}())
} }