-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCofigUI.go
255 lines (224 loc) · 7.88 KB
/
CofigUI.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"image/color"
"strconv"
)
func MakeConfigUI(Windows fyne.Window, Config RunConfig) *fyne.Container {
Windows.SetTitle("配置页面")
IdCodeInput := widget.NewEntry()
IdCodeInput.Text = Config.IdCode
IdCodeInput.SetPlaceHolder("个人身份码")
OpenFanfan := widget.NewButton("打开饭饭获取身份码", func() {
err := AgreeOpenUrl("https://play-live.bilibili.com/")
if err != nil {
return
}
})
LineKeyInput := widget.NewEntry()
if Config.LineKey == "" {
LineKeyInput.Text = "排队"
} else {
LineKeyInput.Text = Config.LineKey
}
LineKeyInput.SetPlaceHolder("请输入排队关键词")
GiftJoinLine := widget.NewCheck("当有用户赠送大于设定值的礼物时自动加入队列", func(b bool) {})
GiftJoinLine.Checked = Config.AutoJoinGiftLine
GiftPriceDisplaySwitch := widget.NewCheck("是否显示礼物价格", func(b bool) {})
GiftPriceDisplaySwitch.Checked = Config.GiftPriceDisplay
IsOnlyGiftSwitch := widget.NewCheck("是否开启 <!->仅限<-!> 付费用户排队(舰长/礼物)", func(status bool) {
})
IsOnlyGiftSwitch.OnChanged = func(status bool) {
if status {
dialog.ShowConfirm("警告", "开启后只有舰长和送礼物的用户才能加入队列", func(b bool) {
IsOnlyGiftSwitch.SetChecked(status)
}, Windows)
}
}
IsOnlyGiftSwitch.Checked = Config.IsOnlyGift
Guard := canvas.NewText("舰长", color.RGBA{R: 255, G: 255, B: 255, A: 255})
if !Config.GuardPrintColor.IsEmpty() {
Guard.Color = Config.GuardPrintColor.ToRGBA()
}
Gift := canvas.NewText("礼物用户", color.RGBA{R: 255, G: 255, B: 255, A: 255})
if !Config.GuardPrintColor.IsEmpty() {
Gift.Color = Config.GiftPrintColor.ToRGBA()
}
Normal := canvas.NewText("普通用户", color.RGBA{R: 255, G: 255, B: 255, A: 255})
if !Config.CommonPrintColor.IsEmpty() {
Normal.Color = Config.CommonPrintColor.ToRGBA()
}
DmDisplayColor := canvas.NewText("弹幕", color.RGBA{R: 255, G: 255, B: 255, A: 255})
if !Config.DmDisplayColor.IsEmpty() {
DmDisplayColor.Color = Config.DmDisplayColor.ToRGBA()
}
TransparentBackgroundCheck := widget.NewCheck("开启排队展示无背景色 UI", func(b bool) {
})
TransparentBackgroundCheck.Checked = Config.TransparentBackground
SelectLineColor := container.NewVBox(
widget.NewLabel("请选择队列显示颜色\n当然,您可以在配置文件中自定义"),
Guard,
MakeSelectColor(Guard),
Gift,
MakeSelectColor(Gift),
Normal,
MakeSelectColor(Normal),
)
GiftPriceInput := widget.NewEntry()
GiftPriceInput.SetPlaceHolder("加入队列的礼物价格门槛(RMB)")
if Config.GiftLinePrice > 0 {
GiftPriceInput.Text = strconv.FormatFloat(Config.GiftLinePrice, 'f', -1, 64)
}
DisplayQueSize := widget.NewCheck("显示当前队列长度", func(b bool) {})
DisplayQueSize.Checked = Config.CurrentQueueSizeDisplay
EnableMusicServer := widget.NewCheck("启用音乐服务器[已半废弃]", func(b bool) {})
EnableMusicServer.Checked = Config.EnableMusicServer
EnableDmDisplayNoSleep := widget.NewCheck("弹幕页面显示不休眠(移动端实验性)", func(b bool) {})
EnableDmDisplayNoSleep.Checked = Config.DmDisplayNoSleep
AutoScrollLine := widget.NewCheck("队列自动滚动展示", func(b bool) {})
AutoScrollLine.Checked = Config.AutoScrollLine
//滚动间隔
ScrollIntervalInput := widget.NewEntry()
ScrollIntervalInput.SetPlaceHolder("滚动间隔(秒)")
if Config.ScrollInterval > 0 {
ScrollIntervalInput.Text = strconv.Itoa(Config.ScrollInterval / 2)
}
LineMaxLengthInput := widget.NewEntry()
LineMaxLengthInput.SetPlaceHolder("队列最大容量")
if Config.MaxLineCount > 0 {
LineMaxLengthInput.Text = strconv.Itoa(Config.MaxLineCount)
}
StartButton := widget.NewButton("保存配置并开始", func() {
GiftLinePriceFloat64, err := strconv.ParseFloat(GiftPriceInput.Text, 10)
LineMaxLengthInt, err := strconv.Atoi(LineMaxLengthInput.Text)
ScrollIntervalInt, err := strconv.Atoi(ScrollIntervalInput.Text)
switch {
case len(IdCodeInput.Text) == 0:
dialog.ShowError(DisplayError{Message: "房间号不能为空"}, Windows)
return
case GiftJoinLine.Checked && GiftLinePriceFloat64 <= 0:
dialog.ShowError(DisplayError{Message: "礼物价格应该大于0"}, Windows)
return
case LineMaxLengthInt <= 0:
dialog.ShowError(DisplayError{Message: "队列最大容量应该大于0"}, Windows)
return
}
if LineKeyInput.Text == "" {
LineKeyInput.Text = "排队"
}
SaveConfig := RunConfig{
IdCode: IdCodeInput.Text,
GuardPrintColor: ToLineColor(Guard.Color),
GiftPriceDisplay: GiftPriceDisplaySwitch.Checked,
GiftPrintColor: ToLineColor(Gift.Color),
GiftLinePrice: GiftLinePriceFloat64,
CommonPrintColor: ToLineColor(Normal.Color),
DmDisplayColor: ToLineColor(DmDisplayColor.Color),
LineKey: LineKeyInput.Text,
IsOnlyGift: IsOnlyGiftSwitch.Checked,
AutoJoinGiftLine: GiftJoinLine.Checked,
TransparentBackground: TransparentBackgroundCheck.Checked,
MaxLineCount: LineMaxLengthInt,
CurrentQueueSizeDisplay: DisplayQueSize.Checked,
EnableMusicServer: EnableMusicServer.Checked,
DmDisplayNoSleep: EnableDmDisplayNoSleep.Checked,
ScrollInterval: ScrollIntervalInt * 2,
AutoScrollLine: AutoScrollLine.Checked,
}
KeyWordMatchMap = make(map[string]bool)
KeyWordMatchInit(SaveConfig.LineKey)
if err != nil {
dialog.ShowError(err, Windows)
} else {
globalConfiguration = SaveConfig
SetConfig(SaveConfig)
dialog.ShowInformation("保存成功", "配置已保存,如果涉及身份码修改,请重启", Windows)
Restart()
}
})
return container.NewVBox(
IdCodeInput,
OpenFanfan,
LineKeyInput,
IsOnlyGiftSwitch,
GiftPriceDisplaySwitch,
TransparentBackgroundCheck,
SelectLineColor,
GiftJoinLine,
GiftPriceInput,
DisplayQueSize,
EnableMusicServer,
EnableDmDisplayNoSleep,
LineMaxLengthInput,
AutoScrollLine,
ScrollIntervalInput,
StartButton,
)
}
func MakeSelectColor(text *canvas.Text) *fyne.Container {
return container.NewHBox(
widget.NewButton("暗蓝", func() {
text.Color = color.RGBA{R: 6, G: 68, B: 255, A: 255}
text.Refresh()
}),
widget.NewButton("深绿", func() {
text.Color = color.RGBA{R: 18, G: 146, B: 14, A: 255}
text.Refresh()
}),
widget.NewButton("淡蓝", func() {
text.Color = color.RGBA{R: 58, G: 150, B: 221, A: 255}
text.Refresh()
}),
widget.NewButton("红色", func() {
text.Color = color.RGBA{R: 255, G: 26, B: 45, A: 255}
text.Refresh()
}),
widget.NewButton("暗紫", func() {
text.Color = color.RGBA{R: 187, G: 31, B: 211, A: 255}
text.Refresh()
}),
widget.NewButton("暗棕", func() {
text.Color = color.RGBA{R: 193, G: 156, B: 0, A: 255}
text.Refresh()
}),
widget.NewButton("蓝色", func() {
text.Color = color.RGBA{R: 59, G: 120, B: 255, A: 255}
text.Refresh()
}),
widget.NewButton("绿色", func() {
text.Color = color.RGBA{R: 22, G: 198, B: 12, A: 255}
text.Refresh()
}),
widget.NewButton("亮蓝", func() {
text.Color = color.RGBA{R: 100, G: 221, B: 221, A: 255}
text.Refresh()
}),
widget.NewButton("大红", func() {
text.Color = color.RGBA{R: 231, G: 72, B: 86, A: 255}
text.Refresh()
}),
widget.NewButton("紫色", func() {
text.Color = color.RGBA{R: 180, G: 0, B: 158, A: 255}
text.Refresh()
}),
widget.NewButton("黄色", func() {
text.Color = color.RGBA{R: 249, G: 241, B: 165, A: 255}
text.Refresh()
}),
widget.NewButton("自定义选择", func() {
MakeColorPicker(text)
}),
)
}
func MakeColorPicker(text *canvas.Text) {
ColorPicker := dialog.NewColorPicker("颜色选择", "", func(c color.Color) {
text.Color = c
text.Refresh()
}, MainWindows)
ColorPicker.Advanced = true
ColorPicker.Show()
}