86 lines
2.6 KiB
Go
86 lines
2.6 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/cmd/v2/lib/common"
|
|
"go_dreamfactory/cmd/v2/service"
|
|
"go_dreamfactory/cmd/v2/service/observer"
|
|
"time"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/data/binding"
|
|
"fyne.io/fyne/v2/layout"
|
|
"fyne.io/fyne/v2/widget"
|
|
"github.com/atotto/clipboard"
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
type toyUserInfo struct {
|
|
toyAdapter
|
|
|
|
dataList *widget.List
|
|
titleLabel *widget.Label
|
|
|
|
userInfo *service.UserInfo
|
|
|
|
data binding.ExternalStringList
|
|
obs observer.Observer
|
|
copyBtn *widget.Button
|
|
}
|
|
|
|
func (this *toyUserInfo) Init(obs observer.Observer) error {
|
|
this.obs = obs
|
|
this.titleLabel = widget.NewLabel(common.USERINFO_TITLE)
|
|
this.data = binding.BindStringList(&[]string{})
|
|
this.copyBtn = widget.NewButton(common.USERINFO_BTN_COPY, func() {
|
|
if this.userInfo != nil && this.userInfo.DbUser != nil {
|
|
_ = clipboard.WriteAll(this.userInfo.DbUser.Uid)
|
|
|
|
}
|
|
})
|
|
this.copyBtn.Disable()
|
|
|
|
this.dataList = widget.NewListWithData(this.data,
|
|
func() fyne.CanvasObject {
|
|
return widget.NewLabel("template")
|
|
},
|
|
func(i binding.DataItem, o fyne.CanvasObject) {
|
|
o.(*widget.Label).Bind(i.(binding.String))
|
|
},
|
|
)
|
|
|
|
this.widget = widget.NewCard("", "",
|
|
container.NewBorder(container.NewHBox(this.titleLabel, layout.NewSpacer(), this.copyBtn),
|
|
nil, nil, nil, container.NewVScroll(this.dataList)))
|
|
this.widget.Resize(fyne.NewSize(ToyWidth, 600))
|
|
|
|
this.Run()
|
|
return nil
|
|
}
|
|
|
|
func (this *toyUserInfo) Run() {
|
|
this.obs.AddListener(observer.EVENT_USERINFO, observer.Listener{
|
|
OnNotify: func(d interface{}, args ...interface{}) {
|
|
time.Sleep(time.Millisecond * 50)
|
|
_ = this.data.Set([]string{})
|
|
if this.copyBtn.Disabled() {
|
|
this.copyBtn.Enable()
|
|
}
|
|
this.userInfo = d.(*service.UserInfo)
|
|
if this.userInfo == nil {
|
|
return
|
|
}
|
|
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_UID, this.userInfo.DbUser.Uid))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_ACC, this.userInfo.DbUser.Binduid))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_NAME, this.userInfo.DbUser.Name))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_AVATAR, cast.ToString(this.userInfo.DbUser.Avatar)))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_VIP, cast.ToString(this.userInfo.DbUser.Vip)))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_LV, cast.ToString(this.userInfo.DbUser.Lv)))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_GOLD, cast.ToString(this.userInfo.DbUser.Gold)))
|
|
_ = this.data.Append(fmt.Sprintf("%-3s\t: %s", common.USERINFO_EXP, cast.ToString(this.userInfo.DbUser.Exp)))
|
|
},
|
|
})
|
|
}
|