show world download list
This commit is contained in:
parent
2761cf094c
commit
e13856a4ff
|
@ -331,6 +331,9 @@ func (w *worldsHandler) SaveAndReset() {
|
||||||
img = w.mapUI.ToImage()
|
img = w.mapUI.ToImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folder := fmt.Sprintf("worlds/%s/%s", w.serverState.Name, worldStateCopy.Name)
|
||||||
|
filename := folder + ".mcworld"
|
||||||
|
|
||||||
w.serverState.worldCounter += 1
|
w.serverState.worldCounter += 1
|
||||||
w.Reset()
|
w.Reset()
|
||||||
w.wg.Add(1)
|
w.wg.Add(1)
|
||||||
|
@ -338,12 +341,14 @@ func (w *worldsHandler) SaveAndReset() {
|
||||||
defer w.wg.Done()
|
defer w.wg.Done()
|
||||||
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": worldStateCopy.Name, "Count": len(worldStateCopy.chunks)}))
|
logrus.Infof(locale.Loc("saving_world", locale.Strmap{"Name": worldStateCopy.Name, "Count": len(worldStateCopy.chunks)}))
|
||||||
w.gui.Message(messages.SavingWorld{
|
w.gui.Message(messages.SavingWorld{
|
||||||
Name: w.worldState.Name,
|
World: &messages.SavedWorld{
|
||||||
Chunks: len(w.worldState.chunks),
|
Name: worldStateCopy.Name,
|
||||||
|
Path: filename,
|
||||||
|
Chunks: len(worldStateCopy.chunks),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// open world
|
// open world
|
||||||
folder := fmt.Sprintf("worlds/%s/%s", w.serverState.Name, worldStateCopy.Name)
|
|
||||||
os.RemoveAll(folder)
|
os.RemoveAll(folder)
|
||||||
os.MkdirAll(folder, 0o777)
|
os.MkdirAll(folder, 0o777)
|
||||||
provider, err := worldStateCopy.Save(folder)
|
provider, err := worldStateCopy.Save(folder)
|
||||||
|
@ -469,7 +474,6 @@ func (w *worldsHandler) SaveAndReset() {
|
||||||
w.AddPacks(folder)
|
w.AddPacks(folder)
|
||||||
|
|
||||||
// zip it
|
// zip it
|
||||||
filename := folder + ".mcworld"
|
|
||||||
err = utils.ZipFolder(filename, folder)
|
err = utils.ZipFolder(filename, folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
|
@ -563,6 +567,9 @@ func (w *worldsHandler) AddPacks(folder string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worldsHandler) OnConnect(err error) bool {
|
func (w *worldsHandler) OnConnect(err error) bool {
|
||||||
|
w.gui.Message(messages.SetWorldName{
|
||||||
|
WorldName: w.worldState.Name,
|
||||||
|
})
|
||||||
w.gui.Message(messages.SetUIState(messages.UIStateMain))
|
w.gui.Message(messages.SetUIState(messages.UIStateMain))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -111,7 +111,7 @@ func drawPackEntry(gtx C, th *material.Theme, entry *packEntry, button *widget.C
|
||||||
size = utils.SizeofFmt(float32(entry.Size))
|
size = utils.SizeofFmt(float32(entry.Size))
|
||||||
} else {
|
} else {
|
||||||
size = fmt.Sprintf("%s / %s %.02f%%",
|
size = fmt.Sprintf("%s / %s %.02f%%",
|
||||||
utils.SizeofFmt(float32(entry.Size)),
|
utils.SizeofFmt(float32(entry.Loaded)),
|
||||||
utils.SizeofFmt(float32(entry.Size)),
|
utils.SizeofFmt(float32(entry.Size)),
|
||||||
float32(entry.Loaded)/float32(entry.Size)*100,
|
float32(entry.Loaded)/float32(entry.Size)*100,
|
||||||
)
|
)
|
||||||
|
@ -206,6 +206,8 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
|
|
||||||
return margin.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
return margin.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||||
switch p.State {
|
switch p.State {
|
||||||
|
case messages.UIStateConnecting:
|
||||||
|
return layout.Center.Layout(gtx, material.Label(th, 100, "Connecting").Layout)
|
||||||
case messages.UIStateMain:
|
case messages.UIStateMain:
|
||||||
return p.layoutFinished(gtx, th)
|
return p.layoutFinished(gtx, th)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package worlds
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
|
@ -29,7 +28,7 @@ type Page struct {
|
||||||
worldName string
|
worldName string
|
||||||
|
|
||||||
worldsList widget.List
|
worldsList widget.List
|
||||||
worlds []messages.SavingWorld
|
worlds []*messages.SavedWorld
|
||||||
l sync.Mutex
|
l sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +61,19 @@ func (p *Page) NavItem() component.NavItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func displayWorldEntry(gtx C, th *material.Theme, entry *messages.SavedWorld) D {
|
||||||
|
return layout.UniformInset(5).Layout(gtx, func(gtx C) D {
|
||||||
|
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||||
|
layout.Rigid(material.Label(th, th.TextSize, entry.Name).Layout),
|
||||||
|
layout.Rigid(material.Label(th, th.TextSize, fmt.Sprintf("%d Chunks", entry.Chunks)).Layout),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Page) Layout(gtx C, th *material.Theme) D {
|
func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
margin := layout.Inset{
|
margin := layout.Inset{
|
||||||
Top: unit.Dp(25),
|
Top: unit.Dp(25),
|
||||||
|
@ -70,46 +82,42 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||||
Left: unit.Dp(35),
|
Left: unit.Dp(35),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch p.State {
|
margin.Layout(gtx, func(gtx C) D {
|
||||||
case messages.UIStateConnect:
|
switch p.State {
|
||||||
// display login page
|
case messages.UIStateConnect:
|
||||||
return margin.Layout(gtx, material.Label(th, 100, "connect Client").Layout)
|
// display login page
|
||||||
case messages.UIStateConnecting:
|
return layout.Center.Layout(gtx, material.Label(th, 100, "connect Client").Layout)
|
||||||
// display connecting to server
|
case messages.UIStateConnecting:
|
||||||
return margin.Layout(gtx, material.Label(th, 100, "Connecting").Layout)
|
return layout.Center.Layout(gtx, material.Label(th, 100, "Connecting").Layout)
|
||||||
case messages.UIStateMain:
|
case messages.UIStateMain:
|
||||||
// show the main ui
|
// show the main ui
|
||||||
return layout.Flex{
|
return layout.Flex{
|
||||||
Axis: layout.Vertical,
|
Axis: layout.Vertical,
|
||||||
}.Layout(gtx,
|
}.Layout(gtx,
|
||||||
layout.Flexed(1, func(gtx C) D {
|
//layout.Rigid(material.Label(th, th.TextSize, p.worldName).Layout),
|
||||||
return layout.Center.Layout(gtx, p.worldMap.Layout)
|
layout.Flexed(1, func(gtx C) D {
|
||||||
}),
|
return layout.Center.Layout(gtx, p.worldMap.Layout)
|
||||||
)
|
}),
|
||||||
case messages.UIStateFinished:
|
)
|
||||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
case messages.UIStateFinished:
|
||||||
layout.Rigid(func(gtx C) D {
|
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||||
return layout.UniformInset(20).
|
layout.Rigid(func(gtx C) D {
|
||||||
Layout(gtx, material.Label(th, 20, "Worlds Saved").Layout)
|
return layout.UniformInset(15).
|
||||||
}),
|
Layout(gtx, material.Label(th, 20, "Worlds Saved").Layout)
|
||||||
layout.Flexed(1, func(gtx C) D {
|
}),
|
||||||
p.l.Lock()
|
layout.Flexed(1, func(gtx C) D {
|
||||||
defer p.l.Unlock()
|
p.l.Lock()
|
||||||
return material.List(th, &p.worldsList).Layout(gtx, len(p.worlds), func(gtx C, index int) D {
|
defer p.l.Unlock()
|
||||||
entry := p.worlds[len(p.worlds)-index-1]
|
return material.List(th, &p.worldsList).Layout(gtx, len(p.worlds), func(gtx C, index int) D {
|
||||||
return layout.UniformInset(25).Layout(gtx, func(gtx C) D {
|
entry := p.worlds[len(p.worlds)-index-1]
|
||||||
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
|
return displayWorldEntry(gtx, th, entry)
|
||||||
layout.Rigid(material.Label(th, th.TextSize, entry.Name).Layout),
|
|
||||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
|
||||||
return layout.Dimensions{Size: image.Pt(20, 20)}
|
|
||||||
}),
|
|
||||||
layout.Rigid(material.Label(th, th.TextSize, fmt.Sprintf("%d chunks", entry.Chunks)).Layout),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
}),
|
||||||
}),
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
return D{}
|
||||||
|
})
|
||||||
|
|
||||||
return layout.Dimensions{}
|
return layout.Dimensions{}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +148,7 @@ func (u *Page) Handler(data any) messages.MessageResponse {
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
case messages.SavingWorld:
|
case messages.SavingWorld:
|
||||||
u.l.Lock()
|
u.l.Lock()
|
||||||
u.worlds = append(u.worlds, m)
|
u.worlds = append(u.worlds, m.World)
|
||||||
u.l.Unlock()
|
u.l.Unlock()
|
||||||
u.Router.Invalidate()
|
u.Router.Invalidate()
|
||||||
r.Ok = true
|
r.Ok = true
|
||||||
|
|
|
@ -63,8 +63,14 @@ type NewSkin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SavingWorld struct {
|
type SavingWorld struct {
|
||||||
|
World *SavedWorld
|
||||||
|
}
|
||||||
|
|
||||||
|
type SavedWorld struct {
|
||||||
Name string
|
Name string
|
||||||
|
Path string
|
||||||
Chunks int
|
Chunks int
|
||||||
|
Image image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
type CanShowImages struct{}
|
type CanShowImages struct{}
|
||||||
|
|
Loading…
Reference in New Issue