更新smithy_trade字段类型

This commit is contained in:
wh_zcy 2023-02-21 16:45:13 +08:00
parent 0be6315357
commit d70cd3a7c6
4 changed files with 103 additions and 37 deletions

View File

@ -7,6 +7,8 @@ import (
"go_dreamfactory/cmd/v2/service/observer"
mytheme "go_dreamfactory/cmd/v2/theme"
"io/ioutil"
"path"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
@ -18,26 +20,31 @@ import (
)
type jsonFileList struct {
selItemId string //选择的文件ID
cacheList common.List
itemList *widget.List
fileTotal int //文件数
selItemId string //选择的文件ID
cachedList common.List
itemList *widget.List
fileTotal int //文件数
//字段
columnList *widget.List
}
func newJsonFileList() *jsonFileList {
return &jsonFileList{
cacheList: common.NewList(""),
cachedList: common.NewList(""),
}
}
type appConfigValid struct {
appAdapter
jsonFileList
jsonFileList *jsonFileList
jsonDirString string //json目录
}
func (a *appConfigValid) LazyInit(pt service.PttService, obs observer.Observer) error {
a.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_VALID, mytheme.ResourceExcelJpg, nil)
a.jsonFileList = *newJsonFileList()
a.jsonFileList = newJsonFileList()
//load conf
storage, _ := os_storage.NewOSStorage()
@ -47,8 +54,8 @@ func (a *appConfigValid) LazyInit(pt service.PttService, obs observer.Observer)
return err
}
if conf.JsonDir!=""{
if conf.JsonDir != "" {
a.jsonDirString = conf.JsonDir
}
content := container.NewMax()
content.Objects = []fyne.CanvasObject{}
@ -72,6 +79,10 @@ func (a *appConfigValid) LazyInit(pt service.PttService, obs observer.Observer)
//配置json路径
jsonDir := widget.NewEntry()
jsonDir.PlaceHolder = "json目录"
jsonDir.OnChanged = func(s string) {
a.jsonFileList.initItem(jsonDir.Text)
a.jsonDirString = jsonDir.Text
}
form := widget.NewForm(
widget.NewFormItem("json目录", container.NewBorder(nil, nil, nil, widget.NewButtonWithIcon("", theme.FolderIcon(), func() {
openFolder(jsonDir)
@ -80,8 +91,27 @@ func (a *appConfigValid) LazyInit(pt service.PttService, obs observer.Observer)
)
jsonDir.SetText(conf.JsonDir)
c := container.NewBorder(form, nil, nil, nil)
confBtn := &widget.Button{Text: "保存配置", Icon: theme.DocumentCreateIcon()}
confBtn.OnTapped = func() {
conf.JsonDir = jsonDir.Text
if err := storage.StoreConfig(conf); err != nil {
logrus.WithField("err", err).Debug("保存配置")
return
}
}
// 创建json文件 List
a.jsonFileList.itemList = a.jsonFileList.createList()
//创建字段
c := container.NewBorder(form,
container.NewHBox(confBtn),
nil, nil,
container.NewGridWithColumns(3,
container.NewVScroll(a.jsonFileList.itemList)))
content.Objects = append(content.Objects, c)
a.tabItem.Content = content
@ -104,19 +134,39 @@ func (f *jsonFileList) initItem(dir string) {
}
for _, file := range files {
if file.IsDir() {
if file.Name() == ".vscode" {
continue
}
fm := common.Item{
Text: file.Name(),
Checked: false,
}
f.cacheList.Items = append(f.cacheList.Items, fm)
// f.selItemIds = append(f.selItemIds, fm.Id)
f.fileTotal++
// logrus.Debugf("%v", fm.Id)
fileSuffix := path.Ext(file.Name())
name := strings.TrimSuffix(file.Name(), fileSuffix)
name = strings.TrimPrefix(name, "game_")
fm := common.Item{
Id: file.Name(),
Text: name,
Checked: false,
}
f.cachedList.Items = append(f.cachedList.Items, fm)
f.fileTotal++
// logrus.Debugf("%v", fm.Id)
}
}
func (f *jsonFileList) createList() *widget.List {
f.itemList = widget.NewList(
func() int {
return len(f.cachedList.Items)
},
func() fyne.CanvasObject {
return widget.NewLabel("Template")
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*widget.Label)
c.Text = f.cachedList.Items[id].Text
c.Refresh()
},
)
f.itemList.OnSelected = func(id widget.ListItemID) {
selId := f.cachedList.Items[id].Id
f.selItemId = selId
return
}
return f.itemList
}

View File

@ -27,9 +27,25 @@ func (s *SmithyView) CreateView(t *model.TestCase) fyne.CanvasObject {
return
}
}
customerBtn := widget.NewButton("顾客", loadCustomer)
btns := container.NewHBox(customerBtn)
//交易
jiaoyi := func() {
if err := service.GetPttService().SendToClient(
t.MainType,
"jiaoyi",
&pb.SmithySellReq{
EquipIds: []string{},
CustomerId: 1,
},
); err != nil {
logrus.Error(err)
return
}
}
customerBtn := widget.NewButton("顾客", loadCustomer)
jiaoyiBtn := widget.NewButton("交易", jiaoyi)
btns := container.NewHBox(customerBtn, jiaoyiBtn)
c := container.NewBorder(btns, nil, nil, nil)
return c
}

View File

@ -150,12 +150,12 @@ func (s *modelTrade) updateCustomer(uid string, customerId int32) error {
}
// 返回概率下的套装
func (s *modelTrade) GetSuitRandom(uid string) string {
func (s *modelTrade) GetSuitRandom(uid string) (suiteId int32) {
//获取玩家所有解锁套装
uex, err := s.module.ModuleUser.GetUserExpand(uid)
if err != nil {
s.module.Errorln(err)
return ""
return
}
var unlockSuiteItems []*WeightItem
for _, v := range uex.SuiteId {
@ -168,7 +168,7 @@ func (s *modelTrade) GetSuitRandom(uid string) string {
ec, suites := s.module.ModuleEquipment.GetActionableSuit(uid)
if ec!=pb.ErrorCode_Success {
s.module.Error("获取玩家已有装备:", log.Field{Key:"code",Value: ec})
return ""
return
}
var ownerSuiteItems []*WeightItem
for _, v := range suites {
@ -182,9 +182,9 @@ func (s *modelTrade) GetSuitRandom(uid string) string {
// 设置权重
wr := newWeightedRandom(merge)
if c := wr.pick(); c != nil {
return c.Id.(string)
return c.Id.(int32)
}
return ""
return
}
// 交易

View File

@ -184,9 +184,9 @@ type CustomerInfo struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
CustomerId int32 `protobuf:"varint,1,opt,name=customerId,proto3" json:"customerId"` //顾客ID
SuitId string `protobuf:"bytes,2,opt,name=suitId,proto3" json:"suitId"` //套装ID 随机套装
EquipCount int32 `protobuf:"varint,3,opt,name=equipCount,proto3" json:"equipCount"` //装备数量
CustomerId int32 `protobuf:"varint,1,opt,name=customerId,proto3" json:"customerId"` //顾客ID
SuitId int32 `protobuf:"varint,2,opt,name=suitId,proto3" json:"suitId"` //套装ID 随机套装
EquipCount int32 `protobuf:"varint,3,opt,name=equipCount,proto3" json:"equipCount"` //装备数量
}
func (x *CustomerInfo) Reset() {
@ -228,11 +228,11 @@ func (x *CustomerInfo) GetCustomerId() int32 {
return 0
}
func (x *CustomerInfo) GetSuitId() string {
func (x *CustomerInfo) GetSuitId() int32 {
if x != nil {
return x.SuitId
}
return ""
return 0
}
func (x *CustomerInfo) GetEquipCount() int32 {
@ -773,7 +773,7 @@ var file_smithy_smithy_db_proto_rawDesc = []byte{
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x75,
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a,
0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x75,
0x69, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x75, 0x69, 0x74,
0x69, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x75, 0x69, 0x74,
0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x71, 0x75, 0x69, 0x70, 0x43, 0x6f, 0x75, 0x6e, 0x74,
0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x65, 0x71, 0x75, 0x69, 0x70, 0x43, 0x6f, 0x75,
0x6e, 0x74, 0x22, 0x9b, 0x01, 0x0a, 0x0a, 0x44, 0x42, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65,