Skip to content

Commit

Permalink
修复&更新: 修复中文乱码问题; 更新大区下拉框选项以及主界面的组件重构
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikyanite committed Jul 30, 2023
1 parent d2f39c4 commit d9e039b
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 38 deletions.
28 changes: 4 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,36 @@ module hidden-record-assistant

go 1.19

require fyne.io/fyne/v2 v2.3.5
require (
fyne.io/fyne/v2 v2.3.5
golang.org/x/net v0.12.0
)

require (
fyne.io/systray v1.10.1-0.20230602210930-b6a2d6ca2a7b // indirect
github.com/bytedance/sonic v1.10.0-rc2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v0.1.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/go-text/typesetting v0.0.0-20230405155246-bf9c697c6e16 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/goki/freetype v0.0.0-20220119013949-7a161fd3728c // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76 // indirect
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/image v0.3.0 // indirect
golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
3 changes: 2 additions & 1 deletion service/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package query

import (
"encoding/json"
"hidden-record-assistant/model"
"io"
"net/http"
)

func SendQuery(dq, name string) (res Result, err error) {
func SendQuery(dq, name string) (res model.Result, err error) {
formData := NewQueryForm(dq, name)
resp, err := http.PostForm("http://www.sslol.top/api/lol.php?act=cx", formData)
if err != nil {
Expand Down
146 changes: 133 additions & 13 deletions view/main.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,150 @@
package view

import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/validation"
theme2 "fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"hidden-record-assistant/view/theme"
"sort"
"strings"
)

type DqSlice []string

func (m DqSlice) Len() int {
return len(m)
}

func (m DqSlice) Less(i, j int) bool {
return DqMap[m[i]] < DqMap[m[j]]
}

func (m DqSlice) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}

var (
DqMap = map[string]int{
"艾欧尼亚": 1, "比尔吉沃特": 2, "祖安": 3, "诺克萨斯": 4, "班德尔城": 5, "德玛西亚": 6, "皮尔特沃夫": 7,
"战争学院": 8, "弗雷尔卓德": 9, "巨神峰": 10, "雷瑟守备": 11, "裁决之地": 13, "黑色玫瑰": 14, "暗影岛": 15,
"恕瑞玛": 16, "钢铁烈阳": 17, "水晶之痕": 18, "均衡教派": 19, "扭曲丛林": 20, "影流": 22, "守望之海": 23,
"征服之海": 24, "卡拉曼达": 25, "巨龙之巢": 26, "皮城警备": 27, "男爵领域": 30, "峡谷之巅": 31,
}
DqNames DqSlice
DqNum int
)

func init() {
for k, _ := range DqMap {
DqNames = append(DqNames, k)
}
sort.Sort(DqNames)
}

func Show() {
a := app.New()
a.Settings().SetTheme(&theme.MyTheme{})
w := a.NewWindow("LOL隐藏战绩查询小助手")
w.Resize(fyne.NewSize(400, 300))

hello := container.NewBorder(nil, nil, nil,
container.NewBorder(nil, nil,
widget.NewLabel("大区: "), widget.NewSelect([]string{"艾欧尼亚", "德玛西亚"}, func(s string) {}),
),
)
w.SetContent(container.NewBorder(
hello,
widget.NewButton("Submit", func() {
w.SetContent(container.NewVBox(widget.NewLabel("TODO PAGE...")))
}),
nil, nil,
widget.NewEntry(),
))
w.SetContent(mainPage(w))

w.ShowAndRun()
}

func mainPage(w fyne.Window) fyne.CanvasObject {
input := widget.NewMultiLineEntry()
examplePlayerNames := "玩家1加入了房间\n" +
"玩家2加入了房间\n" +
"..."
input.SetPlaceHolder(examplePlayerNames)
input.Validator = validation.NewRegexp(`^(?:.*加入了房间\n)*.*加入了房间[\n]*$`, "请按照'xxx加入了房间'的格式输入")

var form *widget.Form
selector := widget.NewSelect(
DqNames,
func(s string) {
DqNum = DqMap[s]
},
)
selector.SetSelectedIndex(0)

form = &widget.Form{
Items: []*widget.FormItem{
{Text: "输入房间文本", Widget: input},
{
Text: "大区",
Widget: selector,
},
},
OnSubmit: func() {
// 先进入到查询过度界面
w.SetContent(loadingPage(w))

// 开始查询
str := strings.Split(input.Text, "\n")
bound := len(str)
if bound != 0 && str[bound-1] == "" {
bound--
}

completeChan := make(chan struct{}, bound)
for i := 0; i < bound; i++ {
go func(i int) {
defer func() {
// 出错也算完成
completeChan <- struct{}{}
if r := recover(); r != nil {

}
}()
playerName := ""
_, err := fmt.Sscanf(str[i], "%s加入了房间", &playerName)
if err != nil {
// TODO 提示错误
return
}

//TODO 接下来是需要把res插入到查询界面中用于显示
//res, err := query.SendQuery(playerName, strconv.Itoa(DqNum))
//if err != nil {
// // TODO 提示错误
// return
//}

}(i)
}

// 等待所有查询完成, 然后返回处理好的查询界面
for i := 0; i < bound; i++ {
<-completeChan
}
w.SetContent(queryPage(w))
},
OnCancel: func() {

},
}
return form
}

func loadingPage(w fyne.Window) fyne.CanvasObject {
return container.NewVBox(
widget.NewLabel("正在查询中..."),
)
}

func queryPage(w fyne.Window) fyne.CanvasObject {
// TODO 设计查询结果界面
return container.NewVBox(
widget.NewLabel(fmt.Sprintf("大区: %d", DqNum)),
widget.NewButtonWithIcon("返回", theme2.NavigateBackIcon(), func() {
DqNum = 1 // 因为默认是艾欧尼亚
w.SetContent(mainPage(w))
}),
)
}
Binary file added view/theme/font/NotoSansSC-Regular.ttf
Binary file not shown.
34 changes: 34 additions & 0 deletions view/theme/theme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package theme

import (
_ "embed"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"image/color"
)

var (
//go:embed font/NotoSansSC-Regular.ttf
FontBi []byte
)

type MyTheme struct{}

func (m *MyTheme) Font(fyne.TextStyle) fyne.Resource {
return &fyne.StaticResource{
StaticName: "NotoSansSC-Regular.ttf",
StaticContent: FontBi,
}
}

func (*MyTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
return theme.DefaultTheme().Color(n, v)
}

func (*MyTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(n)
}

func (*MyTheme) Size(n fyne.ThemeSizeName) float32 {
return theme.DefaultTheme().Size(n)
}

0 comments on commit d9e039b

Please sign in to comment.