diff --git a/Menu/GameShell/21_Warehouse/ware_house_page.go b/Menu/GameShell/21_Warehouse/ware_house_page.go index 2d23b24..2122b34 100644 --- a/Menu/GameShell/21_Warehouse/ware_house_page.go +++ b/Menu/GameShell/21_Warehouse/ware_house_page.go @@ -398,14 +398,17 @@ func (self *WareHouse) Init() { self.rpcSecret, gotime.Second, AppNotifier{Parent:self}) - if err != nil { + if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) - } + } + self.rpcc = rpcc self.Downloader = grab.NewClient() self.Downloading = make(chan bool,1) + self.Screen.HookExitCb(self) + } } @@ -768,7 +771,6 @@ func (self *WareHouse) OnKbdReturnBackCb() { } func (self *WareHouse) OnExitCb() { - self.SetDownloading(false) self.rpcc.Close() diff --git a/Menu/GameShell/97_MusicPlayer/list_page_selector.go b/Menu/GameShell/97_MusicPlayer/list_page_selector.go new file mode 100644 index 0000000..da00978 --- /dev/null +++ b/Menu/GameShell/97_MusicPlayer/list_page_selector.go @@ -0,0 +1,54 @@ +package MusicPlayer + +import ( + "fmt" +// "path/filepath" + +// "github.com/cuu/gogame/event" + "github.com/cuu/gogame/draw" + "github.com/cuu/gogame/rect" +// "github.com/cuu/gogame/surface" +// "github.com/veandco/go-sdl2/ttf" + + "github.com/cuu/gogame/color" + +// "github.com/clockworkpi/LauncherGoDev/sysgo" + "github.com/clockworkpi/LauncherGoDev/sysgo/UI" + + +) + +type ListPageSelector struct { + UI.InfoPageSelector +} + +func NewListPageSelector() *ListPageSelector { + + p := &ListPageSelector{} + + p.Width = UI.Width + p.BackgroundColor = &color.Color{131, 199, 219, 255} //SkinManager().GiveColor('Front') + + return p + +} + +func (self *ListPageSelector) Draw() { + + idx := self.Parent.GetPsIndex() + mylist := self.Parent.GetMyList() + fmt.Println(idx) + if idx < len(mylist) { + x, y := mylist[idx].Coord() + _, h := mylist[idx].Size() + + self.PosX = x + 2 + self.PosY = y + 1 + self.Height = h - 3 + + canvas_ := self.Parent.GetCanvasHWND() + rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height) + + draw.AARoundRect(canvas_, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor) + } +} diff --git a/Menu/GameShell/97_MusicPlayer/music_lib_list_page.go b/Menu/GameShell/97_MusicPlayer/music_lib_list_page.go index 6955dd8..8672e97 100644 --- a/Menu/GameShell/97_MusicPlayer/music_lib_list_page.go +++ b/Menu/GameShell/97_MusicPlayer/music_lib_list_page.go @@ -2,6 +2,7 @@ package MusicPlayer import ( //"fmt" + "log" "path/filepath" "github.com/cuu/gogame/event" @@ -11,11 +12,11 @@ import ( "github.com/cuu/gogame/color" - "github.com/clockworkpi/LauncherGoDev/sysgo" +// "github.com/clockworkpi/LauncherGoDev/sysgo" "github.com/clockworkpi/LauncherGoDev/sysgo/UI" - "github.com/fhs/gompd/v2/mpd" - +// "github.com/fhs/gompd/v2/mpd" + ) type MusicLibListPage struct { @@ -28,14 +29,15 @@ type MusicLibListPage struct { IP string - MyList []UI.ListItemInterface - MyStack *MusicLibStack + //MyList []UI.ListItemInterface + MyStack *UI.FolderStack BGwidth int BGheight int //70 Scroller *UI.ListScroller Scrolled int + + Parent *MusicPlayerPage// also use the MpdClient from - Parent *MusicPlayerPage } func NewMusicLibListPage() *MusicLibListPage { @@ -74,12 +76,7 @@ func (self *MusicLibListPage) SetCoords() { } func (self *MusicLibListPage) SyncList(path string) { - conn, err := mpd.Dial("unix", sysgo.MPD_socket) - if err != nil { - log.Fatalln(err) - } - - defer conn.Close() + conn := self.Parent.MpdClient self.MyList = nil @@ -113,25 +110,25 @@ func (self *MusicLibListPage) SyncList(path string) { for i, m := range atts { - li : NewMusicLibListPageListItem() + li := NewMusicLibListPageListItem() li.Parent = self li.PosX = start_x li.PosY = start_y + (i+hasparent)*li.Height li.Width = UI.Width - li.Fonts["normal"] = self.ListFont + li.Fonts["normal"] = self.ListFontObj li.MyType = UI.ICON_TYPES["FILE"] init_val := "NoName" if val, ok := m["directory"] ; ok { li.MyType = UI.ICON_TYPES["DIR"] - init_val = filepath.Base(m["directory"]) - li.Path = m["directory"] + init_val = filepath.Base(val) + li.Path = val } - if val, ok = m["file"]; ok { + if val, ok := m["file"]; ok { li.MyType = UI.ICON_TYPES["FILE"] - li.Path = m["file"] + li.Path = val val2, ok2 := m["Title"] if ok2 && len(val2) > 4{ @@ -162,7 +159,9 @@ func (self *MusicLibListPage) Init() { self.Width = self.Screen.Width self.Height = self.Screen.Height - ps := UI.NewInfoPageSelector() + ps := NewListPageSelector() + ps.Parent = self + ps.Width = UI.Width - 12 ps.PosX = 2 ps.Parent = self @@ -195,15 +194,67 @@ func (self *MusicLibListPage) Init() { self.Scroller.PosY = 2 self.Scroller.Init() + self.MyStack = UI.NewFolderStack() + self.MyStack.SetRootPath("/") + +} + +func (self *MusicLibListPage) Click() { + self.RefreshPsIndex() + + if len(self.MyList) == 0 { + return + } + + cur_li := self.MyList[self.PsIndex].(*MusicLibListPageListItem) + + if cur_li.MyType == UI.ICON_TYPES["DIR"] { + if cur_li.Path == "[..]" { + self.MyStack.Pop() + self.SyncList( self.MyStack.Last() ) + self.PsIndex = 0 + } else { + self.MyStack.Push( cur_li.Path ) + self.SyncList( self.MyStack.Last() ) + self.PsIndex = 0 + } + } + + if cur_li.MyType == UI.ICON_TYPES["FILE"] { + //addfile(cur_li.Path) + //PlayListPage.SyncList() + //print("add" , cur_li._Path) + } + + self.Screen.Draw() + self.Screen.SwapAndShow() + } func (self *MusicLibListPage) KeyDown(ev *event.Event) { + if ev.Data["Key"] == UI.CurKeys["Left"] || ev.Data["Key"] == UI.CurKeys["Menu"] { self.ReturnToUpLevelPage() self.Screen.Draw() self.Screen.SwapAndShow() } + + if ev.Data["Key"] == UI.CurKeys["Up"] { + + self.ScrollUp() + self.Screen.Draw() + self.Screen.SwapAndShow() + } + + if ev.Data["Key"] == UI.CurKeys["Down"] { + + self.ScrollDown() + self.Screen.Draw() + self.Screen.SwapAndShow() + } + + return } @@ -213,6 +264,37 @@ func (self *MusicLibListPage) Draw() { if len(self.MyList) == 0 { self.Icons["bg"].NewCoord(self.Width/2, self.Height/2) self.Icons["bg"].Draw() + }else { + if len(self.MyList)*UI.DefaultInfoPageListItemHeight > self.Height { + self.Ps.(*ListPageSelector).Width = self.Width - 11 + self.Ps.Draw() + + for _, v := range self.MyList { + if v.(*MusicLibListPageListItem).PosY > self.Height+self.Height/2 { + break + } + + if v.(*MusicLibListPageListItem).PosY < 0 { + continue + } + + v.Draw() + } + + } else{ + self.Ps.(*ListPageSelector).Width = self.Width + self.Ps.Draw() + for _, v := range self.MyList { + if v.(*MusicLibListPageListItem).PosY > self.Height+self.Height/2 { + break + } + + if v.(*MusicLibListPageListItem).PosY < 0 { + continue + } + v.Draw() + } + } } if self.HWND != nil { diff --git a/Menu/GameShell/97_MusicPlayer/music_lib_list_page_list_item.go b/Menu/GameShell/97_MusicPlayer/music_lib_list_page_list_item.go index 75ae9b7..3c6cc50 100644 --- a/Menu/GameShell/97_MusicPlayer/music_lib_list_page_list_item.go +++ b/Menu/GameShell/97_MusicPlayer/music_lib_list_page_list_item.go @@ -1,23 +1,23 @@ package MusicPlayer import ( - "fmt" +// "fmt" //"io/ioutil" //"path/filepath" "github.com/veandco/go-sdl2/ttf" - "runtime" - "strconv" - "strings" +// "runtime" +// "strconv" +// "strings" //"github.com/mitchellh/go-homedir" - "github.com/clockworkpi/LauncherGoDev/sysgo" + /// "github.com/clockworkpi/LauncherGoDev/sysgo" "github.com/clockworkpi/LauncherGoDev/sysgo/UI" "github.com/cuu/gogame/color" "github.com/cuu/gogame/draw" - "github.com/cuu/gogame/event" - "github.com/cuu/gogame/rect" - "github.com/cuu/gogame/surface" - "github.com/cuu/gogame/time" +// "github.com/cuu/gogame/event" +// "github.com/cuu/gogame/rect" +// "github.com/cuu/gogame/surface" +// "github.com/cuu/gogame/time" ) type MusicLibListPageListItem struct { @@ -25,7 +25,7 @@ type MusicLibListPageListItem struct { Active bool Value string - MyType string + MyType int Path string } diff --git a/Menu/GameShell/97_MusicPlayer/music_player_page.go b/Menu/GameShell/97_MusicPlayer/music_player_page.go index ef31bd1..d3be9a2 100644 --- a/Menu/GameShell/97_MusicPlayer/music_player_page.go +++ b/Menu/GameShell/97_MusicPlayer/music_player_page.go @@ -1,16 +1,18 @@ package MusicPlayer import ( - //"fmt" - + "fmt" + "log" "github.com/cuu/gogame/event" "github.com/cuu/gogame/rect" "github.com/cuu/gogame/surface" "github.com/veandco/go-sdl2/ttf" "github.com/cuu/gogame/color" - + "github.com/clockworkpi/LauncherGoDev/sysgo" "github.com/clockworkpi/LauncherGoDev/sysgo/UI" + + "github.com/fhs/gompd/v2/mpd" ) type MusicPlayerPage struct { @@ -23,15 +25,16 @@ type MusicPlayerPage struct { IP string - MyMusicLibListPage *MusicLibListPage + MyMusicLibListPage *MusicLibListPage //also use the MpdClient *mpd.Client - MyList []UI.ListItemInterface - MyStack *MusicLibStack + //MyList []UI.ListItemInterface + MyStack *UI.FolderStack BGwidth int BGheight int //70 Scroller *UI.ListScroller Scrolled int + MpdClient *mpd.Client } func NewMusicPlayerPage() *MusicPlayerPage { @@ -62,6 +65,24 @@ func NewMusicPlayerPage() *MusicPlayerPage { func (self *MusicPlayerPage) OnLoadCb() { self.PosY = 0 + + if self.MpdClient == nil { + conn, err := mpd.Dial("unix", sysgo.MPD_socket) + if err != nil { + log.Fatalln(err) + } + self.MpdClient = conn + + fmt.Println("Start mpd client") + } +} + +func (self *MusicPlayerPage) OnPopUpCb() { + if self.MpdClient != nil { + self.MpdClient.Close() + self.MpdClient = nil + fmt.Println("Close mpd client") + } } func (self *MusicPlayerPage) SetCoords() { @@ -124,6 +145,9 @@ func (self *MusicPlayerPage) Init() { self.MyMusicLibListPage.Name = "Music Library" self.MyMusicLibListPage.Parent = self self.MyMusicLibListPage.Init() + + self.MyStack = UI.NewFolderStack() + self.MyStack.SetRootPath("/") } func (self *MusicPlayerPage) KeyDown(ev *event.Event) { diff --git a/Menu/GameShell/97_MusicPlayer/music_player_page_list_item.go b/Menu/GameShell/97_MusicPlayer/music_player_page_list_item.go index 51417b8..5a6b3f5 100644 --- a/Menu/GameShell/97_MusicPlayer/music_player_page_list_item.go +++ b/Menu/GameShell/97_MusicPlayer/music_player_page_list_item.go @@ -1,23 +1,23 @@ package MusicPlayer import ( - "fmt" + //"fmt" //"io/ioutil" //"path/filepath" "github.com/veandco/go-sdl2/ttf" - "runtime" - "strconv" - "strings" + //"runtime" + //"strconv" + //"strings" //"github.com/mitchellh/go-homedir" - "github.com/clockworkpi/LauncherGoDev/sysgo" + //"github.com/clockworkpi/LauncherGoDev/sysgo" "github.com/clockworkpi/LauncherGoDev/sysgo/UI" "github.com/cuu/gogame/color" "github.com/cuu/gogame/draw" - "github.com/cuu/gogame/event" - "github.com/cuu/gogame/rect" - "github.com/cuu/gogame/surface" - "github.com/cuu/gogame/time" + //"github.com/cuu/gogame/event" + //"github.com/cuu/gogame/rect" + //"github.com/cuu/gogame/surface" + //"github.com/cuu/gogame/time" ) type MusicPlayPageListItem struct { @@ -25,7 +25,7 @@ type MusicPlayPageListItem struct { Active bool Value string - MyType string + MyType int Path string } @@ -49,8 +49,8 @@ func (self *MusicPlayPageListItem) Draw() { self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2) if self.Active == true { - self.Parent.(*MusicPlayPage).Icons["sys"].NewCoord(self.Parent.(*MusicPlayPage).Width-30, self.PosY+5) - self.Parent.(*MusicPlayPage).Icons["sys"].Draw() + self.Parent.(*MusicPlayerPage).Icons["sys"].NewCoord(self.Parent.(*MusicPlayerPage).Width-30, self.PosY+5) + self.Parent.(*MusicPlayerPage).Icons["sys"].Draw() } self.Labels["Text"].SetBold(self.Active) diff --git a/Menu/GameShell/97_MusicPlayer/plugin_init.go b/Menu/GameShell/97_MusicPlayer/plugin_init.go index 286f5ff..a574610 100644 --- a/Menu/GameShell/97_MusicPlayer/plugin_init.go +++ b/Menu/GameShell/97_MusicPlayer/plugin_init.go @@ -11,18 +11,23 @@ import ( */ "github.com/clockworkpi/LauncherGoDev/sysgo/UI" //"github.com/clockworkpi/LauncherGoDev/sysgo/DBUS" + "github.com/fhs/gompd/v2/mpd" + ) /******************************************************************************/ type MusicPlayerPlugin struct { UI.Plugin MusicPlayerPage *MusicPlayerPage + MpdClient *mpd.Client } func (self *MusicPlayerPlugin) Init(main_screen *UI.MainScreen) { self.MusicPlayerPage = NewMusicPlayerPage() self.MusicPlayerPage.SetScreen(main_screen) self.MusicPlayerPage.SetName("Music Player") + self.MpdClient = nil + self.MusicPlayerPage.MpdClient = self.MpdClient self.MusicPlayerPage.Init() } diff --git a/go.mod b/go.mod index 7b9bdc2..ab1894c 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( ) require ( + github.com/fhs/gompd/v2 v2.3.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/moutend/go-wca v0.2.0 // indirect diff --git a/go.sum b/go.sum index 51b7ed5..f968a0c 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/fhs/gompd/v2 v2.3.0 h1:wuruUjmOODRlJhrYx73rJnzS7vTSXSU7pWmZtM3VPE0= +github.com/fhs/gompd/v2 v2.3.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4= github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= diff --git a/sysgo/UI/download_process_page.go b/sysgo/UI/download_process_page.go index b868b1a..22269ef 100644 --- a/sysgo/UI/download_process_page.go +++ b/sysgo/UI/download_process_page.go @@ -32,7 +32,7 @@ type DownloadProcessPage struct { URLColor *color.Color TextColor *color.Color - TheTicker *gotime.Ticker + //TheTicker *gotime.Ticker Downloader *grab.Client resp *grab.Response @@ -95,9 +95,9 @@ func (self *DownloadProcessPage) Init() { func (self *DownloadProcessPage) OnExitCb() { //Stop Ticker and the Grab - if self.TheTicker != nil { - self.TheTicker.Stop() - } + //if self.TheTicker != nil { + // self.TheTicker.Stop() + //} } diff --git a/sysgo/UI/main_screen.go b/sysgo/UI/main_screen.go index 466a4f4..66e4bc7 100644 --- a/sysgo/UI/main_screen.go +++ b/sysgo/UI/main_screen.go @@ -38,6 +38,7 @@ type ScreenInterface interface { IsPluginPackage(dirname string) bool KeyDown(ev *event.Event) OnExitCb() + HookExitCb() PushCurPage() PushPage(pg PageInterface) RunEXE(cmdpath string) @@ -160,10 +161,13 @@ func (self *MessageBox) Draw() { type MainScreen struct { Widget Pages []PageInterface + Child []PageInterface + PageMax int PageIndex int MyPageStack *PageStack + CurrentPage PageInterface CanvasHWND *sdl.Surface HWND *sdl.Surface @@ -181,6 +185,7 @@ type MainScreen struct { LastKey string LastKeyDown gotime.Time + } func NewMainScreen() *MainScreen { @@ -377,8 +382,16 @@ func (self *MainScreen) RunEXE(cmdpath string) { } +func (self *MainScreen) HookExitCb( page PageInterface) { + self.Child = append(self.Child,page) +} + func (self *MainScreen) OnExitCb() { - self.CurrentPage.OnExitCb() + PageLen := len(self.Child) + + for i := 0; i < PageLen; i++ { + self.Child[i].OnExitCb() + } } func (self *MainScreen) KeyDown(ev *event.Event) { diff --git a/sysgo/UI/page.go b/sysgo/UI/page.go index 6e530e5..eca8c27 100644 --- a/sysgo/UI/page.go +++ b/sysgo/UI/page.go @@ -5,7 +5,7 @@ import ( // "math" //"reflect" - "sync" +// "sync" "github.com/veandco/go-sdl2/sdl" @@ -19,54 +19,6 @@ import ( "github.com/cuu/gogame/transform" ) -type element struct { - data interface{} - next *element -} - -type PageStack struct { - lock *sync.Mutex - head *element - Size int -} - -func (stk *PageStack) Push(data interface{}) { - stk.lock.Lock() - - element := new(element) - element.data = data - temp := stk.head - element.next = temp - stk.head = element - stk.Size++ - - stk.lock.Unlock() -} - -func (stk *PageStack) Pop() interface{} { - if stk.head == nil { - return nil - } - stk.lock.Lock() - r := stk.head.data - stk.head = stk.head.next - stk.Size-- - - stk.lock.Unlock() - - return r -} - -func (stk *PageStack) Length() int { - return stk.Size -} - -func NewPageStack() *PageStack { - stk := new(PageStack) - stk.lock = &sync.Mutex{} - return stk -} - type PageSelectorInterface interface { Init(x, y, w, h, alpha int) Adjust(x, y, w, h, alpha int) @@ -208,6 +160,7 @@ type PageInterface interface { OnReturnBackCb() OnKbdReturnBackCb() OnExitCb() + OnPopUpCb() // IconClick() ResetPageSelector() @@ -806,13 +759,15 @@ func (self *Page) IconClick() { } func (self *Page) ReturnToUpLevelPage() { + + self.Screen.CurrentPage.OnPopUpCb() + pop_page := self.Screen.MyPageStack.Pop() if pop_page != nil { page_ := pop_page.(PageInterface) page_.Draw() self.Screen.CurrentPage = page_ self.Screen.CurrentPage.OnReturnBackCb() - } else { if self.Screen.MyPageStack.Length() == 0 { if len(self.Screen.Pages) > 0 { @@ -824,6 +779,7 @@ func (self *Page) ReturnToUpLevelPage() { } } } + } func (self *Page) ClearCanvas() { @@ -919,9 +875,12 @@ func (self *Page) OnReturnBackCb() { } func (self *Page) OnExitCb() { - + //MainScreen will call every page's OnExitCb when launchego ready to exit(0) +} +func (self *Page) OnPopUpCb(){ + //happend when page switching + //use self.Screen.Current.OnPopUpCb to call the current custom Page's OnPopUpCb ,not this empty one } - func (self *Page) Draw() { self.ClearCanvas() self.DrawIcons() diff --git a/Menu/GameShell/97_MusicPlayer/music_lib_stack.go b/sysgo/UI/page_stack.go similarity index 50% rename from Menu/GameShell/97_MusicPlayer/music_lib_stack.go rename to sysgo/UI/page_stack.go index 32743bd..8f69aa2 100644 --- a/Menu/GameShell/97_MusicPlayer/music_lib_stack.go +++ b/sysgo/UI/page_stack.go @@ -1,21 +1,21 @@ -package MusicPlayer +package UI import ( "sync" ) type element struct { - data interface{} - next *element + data interface{} + next *element } -type MusicLibStack struct { - lock *sync.Mutex - head *element - Size int +type PageStack struct { + lock *sync.Mutex + head *element + Size int } -func (stk *MusicLibStack) Push(data interface{}) { +func (stk *PageStack) Push(data interface{}) { stk.lock.Lock() element := new(element) @@ -28,7 +28,7 @@ func (stk *MusicLibStack) Push(data interface{}) { stk.lock.Unlock() } -func (stk *MusicLibStack) Pop() interface{} { +func (stk *PageStack) Pop() interface{} { if stk.head == nil { return nil } @@ -42,23 +42,21 @@ func (stk *MusicLibStack) Pop() interface{} { return r } -func (stk *MusicLibStack) Length() int { +func (stk *PageStack) Length() int { return stk.Size } -func (stk *MusicLibStack) Last() string { - idx := stk.Length() -1 +func (stk *PageStack) Last() interface{} { + idx := stk.Length() - 1 if idx < 0 { - return "/" + return nil } else { - return stk.head.data.(string) + return stk.head.data } } -func NewMusicLibStack() *MusicLibStack { - stk := new(MusicLibStack) +func NewPageStack() *PageStack { + stk := new(PageStack) stk.lock = &sync.Mutex{} return stk } - -