all features implemented
This commit is contained in:
@@ -0,0 +1,509 @@
|
||||
//
|
||||
// PortraitView.swift
|
||||
// Bunch O' Dice
|
||||
//
|
||||
// Created by Rory Hinnen on 22/6/18.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MainView: View {
|
||||
|
||||
enum MenuView: Int {
|
||||
case history, add, settings
|
||||
|
||||
func icon() -> Image {
|
||||
switch self {
|
||||
case .history:
|
||||
return(Image(systemName: "folder"))
|
||||
case .settings:
|
||||
return(Image(systemName: "square.and.pencil"))
|
||||
case .add:
|
||||
return(Image(systemName: "folder.badge.plus"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func myCircle() -> some View {
|
||||
Circle()
|
||||
.fill(Color.gray)
|
||||
.blur(radius: 2.0)
|
||||
.frame(width: controlSize*2.5, height: controlSize*2.5, alignment: .center)
|
||||
}
|
||||
|
||||
@ViewBuilder private func stateView() -> some View {
|
||||
switch current.state {
|
||||
case .wound:
|
||||
woundCalculator(controlSize: controlSize)
|
||||
case .armour:
|
||||
armourCalculator(controlSize: controlSize)
|
||||
default:
|
||||
hitCalculator(controlSize: controlSize)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func sheetContent() -> some View {
|
||||
switch sheet.state {
|
||||
case .settings:
|
||||
SettingsView(isShowing: $sheet.isShowing)
|
||||
case .history:
|
||||
HistoryView(isShowing: $sheet.isShowing)
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func buttons(color: CGColor, label: String, value: Int) -> some View {
|
||||
let frameSize = 120.0
|
||||
let fontSize = 35.0
|
||||
let blurSize = 5.0
|
||||
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color(color))
|
||||
.frame(width: frameSize, height: frameSize)
|
||||
.blur(radius: blurSize)
|
||||
VStack{
|
||||
Text(String(value))
|
||||
.fontWeight(.black)
|
||||
Text(label)
|
||||
.font(.system(size: 20))
|
||||
}
|
||||
}
|
||||
.foregroundColor(.primary)
|
||||
.font(.system(size: fontSize))
|
||||
}
|
||||
|
||||
//MARK: State Views
|
||||
@ViewBuilder func armourCalculator(controlSize: Double) -> some View {
|
||||
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")
|
||||
}
|
||||
Spacer()
|
||||
VStack {
|
||||
Text("Invulnerable")
|
||||
Toggle("", isOn: $current.invulnerable).labelsHidden()
|
||||
.padding()
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Text("Reroll")
|
||||
Picker("", selection: $current.saveRerollMode) {
|
||||
ForEach(RerollMode.allCases, id: \.self) { mode in
|
||||
Text(mode.label).tag(mode)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Button("🎲") {
|
||||
current.applyReroll()
|
||||
}
|
||||
.disabled(current.saveRerollMode == .none || current.saveHasRerolled)
|
||||
.font(.system(size: controlSize))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
if current.mortalWoundsTotal > 0 {
|
||||
HStack {
|
||||
Text("Mortal wounds: \(current.mortalWoundsTotal) (bypassed saves)")
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.orange)
|
||||
Spacer()
|
||||
}
|
||||
.font(.system(size: 18))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
@ViewBuilder func woundCalculator(controlSize: Double) -> some View {
|
||||
VStack {
|
||||
if current.autoWoundsCarried > 0 {
|
||||
HStack {
|
||||
Text("Auto-wounds carried: \(current.autoWoundsCarried) (skip wound roll)")
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.orange)
|
||||
Spacer()
|
||||
}
|
||||
.font(.system(size: 18))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
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()
|
||||
}
|
||||
HStack {
|
||||
Text("Reroll")
|
||||
Picker("", selection: $current.woundRerollMode) {
|
||||
ForEach(RerollMode.allCases, id: \.self) { mode in
|
||||
Text(mode.label).tag(mode)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Button("🎲") {
|
||||
current.applyReroll()
|
||||
}
|
||||
.disabled(current.woundRerollMode == .none || current.woundHasRerolled)
|
||||
.font(.system(size: controlSize))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
VStack(spacing: 8) {
|
||||
HStack {
|
||||
Toggle("Devastating Wounds", isOn: $current.devastatingWounds)
|
||||
}
|
||||
if current.devastatingWounds {
|
||||
HStack {
|
||||
Text("Mortals (6s): \(current.critWoundCount)")
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.orange)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.font(.system(size: 18))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
@ViewBuilder func hitCalculator(controlSize: Double) -> some View {
|
||||
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()
|
||||
})
|
||||
}
|
||||
.font(.system(size: controlSize))
|
||||
Text("Modifier")
|
||||
}
|
||||
.disabled(current.torrent || current.psychic)
|
||||
.opacity((current.torrent || current.psychic) ? 0.4 : 1.0)
|
||||
Spacer()
|
||||
VStack {
|
||||
Text("Blow Up")
|
||||
VStack {
|
||||
Button(action: { current.applyBlowup(face: .six) }) {
|
||||
Image(systemName: "die.face.6")
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
Button(action: { current.applyBlowup(face: .five) }) {
|
||||
Image(systemName: "die.face.5")
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.font(.system(size: controlSize))
|
||||
}
|
||||
.disabled(current.blowupUsed || current.torrent)
|
||||
.opacity((current.blowupUsed || current.torrent) ? 0.4 : 1.0)
|
||||
Spacer()
|
||||
}
|
||||
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)
|
||||
.disabled(current.torrent)
|
||||
.opacity(current.torrent ? 0.4 : 1.0)
|
||||
HStack {
|
||||
Toggle("Torrent", isOn: $current.torrent)
|
||||
Spacer()
|
||||
Toggle("Psychic", isOn: $current.psychic)
|
||||
.disabled(current.torrent)
|
||||
.opacity(current.torrent ? 0.4 : 1.0)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
VStack(spacing: 8) {
|
||||
HStack {
|
||||
Toggle("Lethal Hits", isOn: $current.lethalHits)
|
||||
Spacer()
|
||||
Toggle("Sust. Hits", isOn: $current.sustainedHits)
|
||||
}
|
||||
if current.sustainedHits {
|
||||
HStack {
|
||||
Text("X:")
|
||||
Spacer()
|
||||
Text("▲")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.sustainedHitsX < 6 { current.sustainedHitsX += 1 }
|
||||
})
|
||||
Text(String(current.sustainedHitsX))
|
||||
.frame(minWidth: 30, alignment: .center)
|
||||
Text("▼")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.sustainedHitsX > 1 { current.sustainedHitsX -= 1 }
|
||||
})
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Toggle("Anti-X", isOn: $current.antiX)
|
||||
if current.antiX {
|
||||
Spacer()
|
||||
Text("▲")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.antiXThreshold < 6 { current.antiXThreshold += 1 }
|
||||
})
|
||||
Text("\(current.antiXThreshold)+")
|
||||
.frame(minWidth: 34, alignment: .center)
|
||||
Text("▼")
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.antiXThreshold > 2 { current.antiXThreshold -= 1 }
|
||||
})
|
||||
}
|
||||
}
|
||||
if current.lethalHits || current.sustainedHits || current.antiX {
|
||||
HStack {
|
||||
if current.lethalHits || current.sustainedHits {
|
||||
Text("Crits (6s): \(current.critHitCount)")
|
||||
.fontWeight(.semibold)
|
||||
}
|
||||
Spacer()
|
||||
if current.antiX {
|
||||
Text("Anti-X (\(current.antiXThreshold)+): \(current.antiXCount)")
|
||||
.fontWeight(.semibold)
|
||||
}
|
||||
}
|
||||
.foregroundColor(.orange)
|
||||
}
|
||||
}
|
||||
.font(.system(size: 18))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
//MARK: die views
|
||||
@ViewBuilder func die(whichDie: Dice.DiceType) -> some View {
|
||||
let size = 22.0
|
||||
let displayColorHit = (whichDie.rawValue >= current.cutoff.rawValue) ? Color.red : Color.primary
|
||||
let displayColorArmor = (whichDie.rawValue <= current.cutoff.rawValue) ? Color.red : Color.primary
|
||||
let displayColorArmorText = (whichDie.rawValue < current.cutoff.rawValue) ? Color.red : Color.primary
|
||||
|
||||
VStack(spacing: 2) {
|
||||
Text(String(current.dice.value(which: whichDie)))
|
||||
.foregroundColor(current.state == .armour ?
|
||||
displayColorArmorText : displayColorHit)
|
||||
.frame(minWidth: 30, alignment: .center)
|
||||
Image(systemName: "die.face." + String(whichDie.rawValue) + ".fill")
|
||||
.foregroundColor(current.state == .armour ?
|
||||
displayColorArmor : displayColorHit)
|
||||
}
|
||||
.font(.system(size: size))
|
||||
.padding(4)
|
||||
.frame(maxWidth: .infinity)
|
||||
.gesture(TapGesture().onEnded {
|
||||
if current.state == .hit {
|
||||
if whichDie.rawValue != 1 {
|
||||
current.hitCutoff = whichDie }
|
||||
} else if current.state == .armour {
|
||||
current.armourSave = Int(whichDie.rawValue)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ViewBuilder func diePool() -> some View {
|
||||
HStack(spacing: 0) {
|
||||
ForEach(Dice.DiceType.allCases, id: \.rawValue) { i in
|
||||
die(whichDie: i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: Var declarations
|
||||
@EnvironmentObject var current: Roll
|
||||
@ObservedObject var sheet = SettingsSheet()
|
||||
@State var showFillView = false
|
||||
|
||||
let padSize = 60.0
|
||||
let controlSize = 30.0
|
||||
let red = CGColor(red: 1.0, green: 0.3, blue: 0.3, alpha: 1.0)
|
||||
let blue = CGColor(red: 0.3, green: 0.3, blue: 1.0, alpha: 1.0)
|
||||
|
||||
var body: some View {
|
||||
VStack{
|
||||
HStack{
|
||||
Button(action: {current.state = .hit}) {
|
||||
ZStack{
|
||||
if current.state == .hit {myCircle()}
|
||||
Text(RollState.hit.print())}}
|
||||
Button(action: {current.state = .wound}) {
|
||||
ZStack{
|
||||
if current.state == .wound {myCircle()}
|
||||
Text(RollState.wound.print())}}
|
||||
Button(action: {current.state = .armour}) {
|
||||
ZStack{
|
||||
if current.state == .armour {myCircle()}
|
||||
Text(RollState.armour.print())}}
|
||||
}.font(.system(size: 60))
|
||||
VStack(spacing: 12) {
|
||||
HStack(spacing: 12) {
|
||||
Button(action: { showFillView.toggle() }) {
|
||||
VStack(spacing: 4) {
|
||||
Text("Dice Pool")
|
||||
.font(.caption)
|
||||
Text(String(current.total))
|
||||
.font(.system(size: 28, weight: .black))
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundColor(.black)
|
||||
}
|
||||
.sheet(isPresented: $showFillView,
|
||||
onDismiss: { current.resetPool() }) {
|
||||
VStack {
|
||||
AddToPool()
|
||||
Button("Accept", action: {showFillView.toggle()})
|
||||
.padding(20)
|
||||
}
|
||||
}
|
||||
Button(action: current.incrementState) {
|
||||
VStack(spacing: 4) {
|
||||
Text(current.state.text())
|
||||
.font(.caption)
|
||||
Text(String(current.result))
|
||||
.font(.system(size: 28, weight: .black))
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundColor(.black)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(Color.black)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 14))
|
||||
diePool()
|
||||
stateView()
|
||||
}.padding()
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .bottomBar) {
|
||||
HStack {
|
||||
Button(action: {self.sheet.state = .history}) {
|
||||
MenuView.history.icon()}
|
||||
Button(action: {current.history.insert(Event(total: current.result, pool: current.dice, state: current.state), at: 0)}) {
|
||||
MenuView.add.icon()}
|
||||
Button(action: {self.sheet.state = .settings}) {
|
||||
MenuView.settings.icon()}
|
||||
}
|
||||
.font(.system(size: controlSize))
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $sheet.isShowing, content: sheetContent)}
|
||||
}
|
||||
|
||||
#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
|
||||
}())
|
||||
}
|
||||
Reference in New Issue
Block a user