This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JudgeLineSettings.swift
69 lines (67 loc) · 2.98 KB
/
JudgeLineSettings.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Created on Fri Jun 03 2022
*
* Copyright (c) 2022 TianKaiMa
*/
import SwiftUI
struct JudgeLineSettings: View {
@EnvironmentObject private var data: DataStructure
@State private var showAlert = false
var body: some View {
List {
Section(header: Text("Global Operations")) {
Button("New JudgeLine") {
// Automatically append to the end, new judgeLine's id will be the last id + 1
for i in 0 ..< data.listOfJudgeLines.count {
data.listOfJudgeLines[i].id = i
}
data.listOfJudgeLines.append(JudgeLine(id: data.listOfJudgeLines[data.listOfJudgeLines.count - 1].id + 1))
}
Button("Organize JudgeLines") {
// assgin the judgeLine's numbers according to order in memory
for i in 0 ..< data.listOfJudgeLines.count {
data.listOfJudgeLines[i].id = i
}
}
}.textCase(nil)
ForEach($data.listOfJudgeLines, id: \.id) { $_judgeLine in
Section(header: Text("JudgeLine \(String(_judgeLine.id))")) {
HStack {
Text("Description:")
.foregroundColor(.cyan)
TextField("[String]", text: $_judgeLine.description)
}
Button("Edit Notes") {
data.editingJudgeLineNumber = _judgeLine.id
data.windowStatus = .pannelNote
data.rebuildScene()
}
Button("Edit Props") {
data.editingJudgeLineNumber = _judgeLine.id
data.windowStatus = .pannelProp
data.rebuildScene()
}
Button(action: {
if data.listOfJudgeLines.count > 1 {
showAlert = true
}
}) {
HStack {
Image(systemName: "exclamationmark.circle")
Text("Delete this Line")
}
.foregroundColor(Color.red)
}.alert(isPresented: $showAlert) {
Alert(title: Text("Confirm delete?"), message: Text("This would delete everything, with no recovery"), primaryButton: .default(Text("cancel")), secondaryButton: .destructive(Text("Delete"), action: {
data.listOfJudgeLines.removeAll(where: { $0.id == _judgeLine.id })
for i in 0 ..< data.listOfJudgeLines.count {
data.listOfJudgeLines[i].id = i
}
data.editingJudgeLineNumber = 0
}))
}
}.textCase(nil)
}
}
}
}