option
This commit is contained in:
parent
619c25e53a
commit
25fab39b1e
@ -94,23 +94,23 @@ func (r *Robot) Run() {
|
||||
r.AccountLogin()
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(time.Second * 5)
|
||||
go func() {
|
||||
for {
|
||||
r.printBuilders()
|
||||
<-ticker.C
|
||||
if len(r.builderMap) == 0 {
|
||||
r.printReport(&TestReport{
|
||||
caseTotal: r.caseTotal,
|
||||
caseSuccess: r.caseSuccess,
|
||||
caseError: r.caseError,
|
||||
})
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}()
|
||||
// ticker := time.NewTicker(time.Second * 5)
|
||||
// go func() {
|
||||
// for {
|
||||
// r.printBuilders()
|
||||
// <-ticker.C
|
||||
// if len(r.builderMap) == 0 {
|
||||
// r.printReport(&TestReport{
|
||||
// caseTotal: r.caseTotal,
|
||||
// caseSuccess: r.caseSuccess,
|
||||
// caseError: r.caseError,
|
||||
// })
|
||||
// os.Exit(0)
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
|
||||
select {}
|
||||
// select {}
|
||||
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ func (r *Robot) handleReq() {
|
||||
for len(r.builderMap) > 0 {
|
||||
for _, b := range r.builderMap {
|
||||
if b.enabled && b.req != nil {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
// time.Sleep(time.Millisecond * 500)
|
||||
b.start = time.Now()
|
||||
r.start = time.Now()
|
||||
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
|
||||
|
@ -29,7 +29,7 @@ var (
|
||||
fmt.Printf("%v \n", v)
|
||||
}
|
||||
},
|
||||
enabled: true,
|
||||
// enabled: true,
|
||||
next: func(robot *Robot, rsp proto.Message) {
|
||||
tcs := []*TestCase{}
|
||||
if _, ok := rsp.(*pb.TaskListResp); ok {
|
||||
|
100
cmd/win/core/app.go
Normal file
100
cmd/win/core/app.go
Normal file
@ -0,0 +1,100 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"go_dreamfactory/cmd/win/assets/font"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type MyApp struct {
|
||||
app fyne.App
|
||||
ws *websocket.Conn
|
||||
opts *Options
|
||||
}
|
||||
|
||||
func NewApp() *MyApp {
|
||||
a := app.NewWithID("dreamfactory")
|
||||
a.Settings().SetTheme(&font.MyTheme{})
|
||||
return &MyApp{app: a}
|
||||
}
|
||||
|
||||
func (this *MyApp) Run() {
|
||||
// connect
|
||||
opts := DefaultOpts()
|
||||
ws, _, err := websocket.DefaultDialer.Dial(opts.WsUrl, nil)
|
||||
if err != nil {
|
||||
logrus.Fatalf("websocket conn err:%v", err)
|
||||
}
|
||||
this.ws = ws
|
||||
|
||||
this.ShowLoginWin()
|
||||
this.app.Run()
|
||||
}
|
||||
|
||||
// 登录窗口
|
||||
func (this *MyApp) ShowLoginWin() {
|
||||
accountEntry := widget.NewEntry()
|
||||
accountEntry.TextStyle = fyne.TextStyle{Bold: true}
|
||||
accountEntry.SetPlaceHolder("输入账号")
|
||||
accountEntry.Text = "user7273"
|
||||
// accountEntry.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "username can only contain letters, numbers, '_', and '-'")
|
||||
sidEntry := widget.NewEntry()
|
||||
sidEntry.Text = "0"
|
||||
// password.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "password can only contain letters, numbers, '_', and '-'")
|
||||
|
||||
items := []*widget.FormItem{
|
||||
widget.NewFormItem("账号", accountEntry),
|
||||
widget.NewFormItem("区服", sidEntry),
|
||||
}
|
||||
|
||||
loginWin := fyne.CurrentApp().NewWindow("登录")
|
||||
loginForm := widget.NewForm(items...)
|
||||
loginForm.SubmitText = "登录"
|
||||
loginForm.OnSubmit = func() {
|
||||
if accountEntry.Text != "" {
|
||||
loginWin.Close()
|
||||
|
||||
//
|
||||
// opts := robot.DefaultOpts()
|
||||
// opts.Account = accountEntry.Text
|
||||
// opts.ServerId = cast.ToInt32(sidEntry.Text)
|
||||
// robot.NewRobot(opts).Run()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
loginWin.Resize(fyne.Size{300, 160})
|
||||
loginWin.SetFixedSize(true)
|
||||
loginWin.SetContent(loginForm)
|
||||
loginWin.CenterOnScreen()
|
||||
loginWin.Show()
|
||||
}
|
||||
|
||||
// 主窗口
|
||||
func (this *MyApp) ShowMainWin() {
|
||||
// this.mainWin = this.app.NewWindow("昊天锤")
|
||||
// this.mainWin.Resize(fyne.NewSize(1366, 768))
|
||||
// this.mainWin.CenterOnScreen()
|
||||
// this.mainWin.SetOnClosed(func() {
|
||||
// cnf := dialog.NewConfirm("退出", "确定退出程序吗?", func(b bool) {
|
||||
// if !b {
|
||||
// return
|
||||
// }
|
||||
// }, this.mainWin)
|
||||
// cnf.SetConfirmText("确定")
|
||||
// cnf.SetDismissText("取消")
|
||||
// cnf.Show()
|
||||
// })
|
||||
// top_left := widget.NewMultiLineEntry()
|
||||
// top_right := widget.NewMultiLineEntry()
|
||||
// bottom := widget.NewMultiLineEntry()
|
||||
// top := container.NewHSplit(top_left, top_right)
|
||||
// cont := container.NewVSplit(top, bottom)
|
||||
// this.mainWin.SetContent(cont)
|
||||
// this.mainWin.Show()
|
||||
}
|
27
cmd/win/core/log.go
Normal file
27
cmd/win/core/log.go
Normal file
@ -0,0 +1,27 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
logrus.SetFormatter(&logrus.TextFormatter{})
|
||||
|
||||
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
|
||||
file, err := os.OpenFile("gui.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||
writers := []io.Writer{
|
||||
file,
|
||||
os.Stdout}
|
||||
|
||||
//同时写文件和屏幕
|
||||
fileAndStdoutWriter := io.MultiWriter(writers...)
|
||||
if err == nil {
|
||||
logrus.SetOutput(fileAndStdoutWriter)
|
||||
} else {
|
||||
logrus.Info("failed to log to file.")
|
||||
}
|
||||
}
|
33
cmd/win/core/options.go
Normal file
33
cmd/win/core/options.go
Normal file
@ -0,0 +1,33 @@
|
||||
package core
|
||||
|
||||
type Options struct {
|
||||
WsUrl string //客户端访问网关的ws接口地址
|
||||
RegUrl string //账号注册接口地址
|
||||
Account string //玩家账号
|
||||
Create bool
|
||||
Secretkey string //秘钥串
|
||||
ServerId int32 //区服ID
|
||||
Role bool //是否创角
|
||||
}
|
||||
|
||||
func DefaultOpts() *Options {
|
||||
return &Options{
|
||||
WsUrl: "ws://localhost:7891/gateway",
|
||||
RegUrl: "http://localhost:8000/register",
|
||||
ServerId: 1,
|
||||
}
|
||||
}
|
||||
|
||||
type Option func(*Options)
|
||||
|
||||
func WithWsUrl(addr string) Option {
|
||||
return func(o *Options) {
|
||||
o.WsUrl = addr
|
||||
}
|
||||
}
|
||||
|
||||
func WithAccount(account string) Option {
|
||||
return func(o *Options) {
|
||||
o.Account = account
|
||||
}
|
||||
}
|
10
cmd/win/handle/login.go
Normal file
10
cmd/win/handle/login.go
Normal file
@ -0,0 +1,10 @@
|
||||
package handle
|
||||
|
||||
type Handle struct{
|
||||
|
||||
}
|
||||
|
||||
|
||||
func login() {
|
||||
|
||||
}
|
@ -1,93 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/cmd/robot"
|
||||
"go_dreamfactory/cmd/win/assets/font"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/spf13/cast"
|
||||
"go_dreamfactory/cmd/win/core"
|
||||
)
|
||||
|
||||
type MyApp struct {
|
||||
app fyne.App
|
||||
loginWin fyne.Window
|
||||
mainWin fyne.Window
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := NewApp()
|
||||
app := core.NewApp()
|
||||
app.Run()
|
||||
}
|
||||
|
||||
func NewApp() *MyApp {
|
||||
a := app.NewWithID("dreamfactory")
|
||||
a.Settings().SetTheme(&font.MyTheme{})
|
||||
return &MyApp{app: a}
|
||||
}
|
||||
|
||||
func (this *MyApp) Run() {
|
||||
this.ShowLoginWin()
|
||||
this.app.Run()
|
||||
}
|
||||
|
||||
// 主窗口
|
||||
func (this *MyApp) ShowMainWin() {
|
||||
this.mainWin = this.app.NewWindow("昊天锤")
|
||||
this.mainWin.Resize(fyne.NewSize(1366, 768))
|
||||
this.mainWin.CenterOnScreen()
|
||||
this.mainWin.SetOnClosed(func() {
|
||||
cnf := dialog.NewConfirm("退出", "确定退出程序吗?", func(b bool) {
|
||||
if !b {
|
||||
return
|
||||
}
|
||||
}, this.mainWin)
|
||||
cnf.SetConfirmText("确定")
|
||||
cnf.SetDismissText("取消")
|
||||
cnf.Show()
|
||||
})
|
||||
this.mainWin.Show()
|
||||
}
|
||||
|
||||
// 登录窗口
|
||||
func (this *MyApp) ShowLoginWin() {
|
||||
accountEntry := widget.NewEntry()
|
||||
accountEntry.TextStyle = fyne.TextStyle{Bold: true}
|
||||
accountEntry.SetPlaceHolder("输入账号")
|
||||
|
||||
// accountEntry.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "username can only contain letters, numbers, '_', and '-'")
|
||||
sidEntry := widget.NewEntry()
|
||||
sidEntry.Text = "0"
|
||||
// password.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "password can only contain letters, numbers, '_', and '-'")
|
||||
|
||||
items := []*widget.FormItem{
|
||||
widget.NewFormItem("账号", accountEntry),
|
||||
widget.NewFormItem("区服", sidEntry),
|
||||
}
|
||||
|
||||
w := fyne.CurrentApp().NewWindow("登录")
|
||||
f := widget.NewForm(items...)
|
||||
f.SubmitText = "登录"
|
||||
f.OnSubmit = func() {
|
||||
fmt.Println(accountEntry.Text)
|
||||
if accountEntry.Text != "" {
|
||||
w.Close()
|
||||
this.ShowMainWin()
|
||||
//
|
||||
opts := robot.DefaultOpts()
|
||||
opts.Account = accountEntry.Text
|
||||
opts.ServerId = cast.ToInt32(sidEntry.Text)
|
||||
robot.NewRobot(opts).Run()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
w.Resize(fyne.Size{300, 160})
|
||||
w.SetFixedSize(true)
|
||||
w.SetContent(f)
|
||||
w.CenterOnScreen()
|
||||
w.Show()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user