-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
183 lines (178 loc) · 5.41 KB
/
main.go
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/lxn/win"
"os"
"path/filepath"
"sort"
"syscall"
)
const hkSplitMakerDir = "hk-split-maker/src/asset/hollowknight/"
func getSystemMetrics(nIndex int) int {
ret, _, _ := syscall.NewLazyDLL(`User32.dll`).NewProc(`GetSystemMetrics`).Call(uintptr(nIndex))
return int(ret)
}
var mainWindow *walk.MainWindow
var splitLinesViewContainer *walk.Composite
var splitLinesView *walk.Composite
var categoriesComboBox *walk.ComboBox
var startTriggerCheckBox *walk.CheckBox
var startTriggerComboBox *walk.ComboBox
var saveTimeCheckBox *walk.CheckBox
func main() {
initCategories()
if err := initSplitsFile(true); err != nil {
walk.MsgBox(nil, "错误", "内部错误", walk.MsgBoxIconError)
return
}
screenX, screenY := getSystemMetrics(0), getSystemMetrics(1)
width, height := 720, 960
err := MainWindow{
OnDropFiles: func(f []string) {
if len(f) > 0 {
file := f[0]
if filepath.Ext(file) != ".lss" {
return
}
buf, err := os.ReadFile(file)
if err != nil {
walk.MsgBox(mainWindow, "内部错误", err.Error(), walk.MsgBoxIconError)
return
}
loadSplitFile(buf)
}
},
AssignTo: &mainWindow,
Title: "计时器生成器",
Bounds: Rectangle{X: (screenX - width) / 2, Y: (screenY - height) / 2, Width: width, Height: height},
Layout: VBox{},
Children: []Widget{
Composite{
MaxSize: Size{Height: 20},
Layout: HBox{},
Children: []Widget{
TextLabel{TextAlignment: AlignHFarVCenter, Text: "你可以"},
PushButton{Text: "打开已有的lss文件", OnClicked: onClickLoadSplitFile},
TextLabel{TextAlignment: AlignHFarVCenter, Text: "或者把文件拖拽进来,也可以使用现有模板"},
ComboBox{
AssignTo: &categoriesComboBox,
Model: func() []string {
var keys []string
for key := range categoriesCache {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}(),
OnCurrentIndexChanged: onSelectCategory,
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
TextLabel{
TextAlignment: AlignHFarVCenter,
Text: "还有一些其他玩家友情提供的",
},
GetUserDefinedComboBox(),
TextLabel{
TextAlignment: AlignHFarVCenter,
Text: "Auto Splitter Version: 3.1.14.0",
},
PushButton{
Text: "更新LiveSplit",
OnClicked: fixLiveSplit,
},
},
},
ScrollView{
HorizontalFixed: true,
Layout: VBox{},
Children: []Widget{
Composite{
MaxSize: Size{Width: 0, Height: 25},
Layout: HBox{},
Children: []Widget{
CheckBox{
AssignTo: &startTriggerCheckBox,
Text: "自动开始",
ToolTipText: "对于全关的速通和万神殿某一门的速通,不要勾选",
OnClicked: func() {
startTriggerComboBox.SetEnabled(startTriggerCheckBox.Checked())
},
},
ComboBox{
AssignTo: &startTriggerComboBox,
Model: &splitIdModel{},
Enabled: false,
Editable: true,
Value: splitDescriptions[0],
OnTextChanged: func() {
onSearchSplitId(true, &lineData{splitId: startTriggerComboBox})
},
},
},
},
Composite{
AssignTo: &splitLinesViewContainer,
Layout: Flow{},
Children: []Widget{
Composite{
AssignTo: &splitLinesView,
Alignment: AlignHCenterVNear,
Layout: VBox{},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
LineEdit{AssignTo: &finalLine.name, Text: "空洞骑士", ToolTipText: "片段名"},
ComboBox{AssignTo: &finalLine.splitId, Visible: false, Editable: true, Model: splitDescriptions, MaxSize: Size{Width: 200}, Value: splitDescriptions[0]},
ComboBox{AssignTo: &finalLine.splitId2, Editable: true, Model: []string{"空洞骑士", "辐光", "无上辐光"}, MaxSize: Size{Width: 200}, Value: "空洞骑士"},
CheckBox{AssignTo: &finalLine.endTrigger, Checked: true, Text: "以游戏结束停止计时", ToolTipText: "如果是以游戏结束或者万神殿某一门结束停止计时,不要勾选",
OnCheckedChanged: func() {
finalLine.splitId.SetVisible(!finalLine.endTrigger.Checked())
finalLine.splitId2.SetVisible(finalLine.endTrigger.Checked())
},
},
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
CheckBox{AssignTo: &saveTimeCheckBox, Text: "保留原lss文件中的时间数据", Enabled: false},
PushButton{Text: "另存为", OnClicked: saveSplitsFile},
PushButton{
MaxSize: Size{Width: 100},
Alignment: AlignHFarVCenter,
Text: "帮助",
OnClicked: func() {
walk.MsgBox(mainWindow, "帮助", readme, walk.MsgBoxIconInformation)
},
}, PushButton{
MaxSize: Size{Width: 100},
Alignment: AlignHFarVCenter,
Text: "FAQ",
OnClicked: func() {
walk.MsgBox(mainWindow, "FAQ", faq, walk.MsgBoxIconInformation)
},
},
},
},
},
}.Create()
addLine(true)
if err != nil {
walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxIconError)
return
}
hWnd := mainWindow.Handle()
currStyle := win.GetWindowLong(hWnd, win.GWL_STYLE)
win.SetWindowLong(hWnd, win.GWL_STYLE, currStyle & ^win.WS_SIZEBOX)
mainWindow.Run()
}