music_lib_list_page.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package MusicPlayer
  2. import (
  3. //"fmt"
  4. "path/filepath"
  5. "github.com/cuu/gogame/event"
  6. "github.com/cuu/gogame/rect"
  7. "github.com/cuu/gogame/surface"
  8. "github.com/veandco/go-sdl2/ttf"
  9. "github.com/cuu/gogame/color"
  10. "github.com/clockworkpi/LauncherGoDev/sysgo"
  11. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  12. "github.com/fhs/gompd/v2/mpd"
  13. )
  14. type MusicLibListPage struct {
  15. UI.Page
  16. ListFontObj *ttf.Font
  17. URLColor *color.Color
  18. TextColor *color.Color
  19. Labels map[string]UI.LabelInterface
  20. Icons map[string]UI.IconItemInterface
  21. IP string
  22. MyList []UI.ListItemInterface
  23. MyStack *MusicLibStack
  24. BGwidth int
  25. BGheight int //70
  26. Scroller *UI.ListScroller
  27. Scrolled int
  28. Parent *MusicPlayerPage
  29. }
  30. func NewMusicLibListPage() *MusicLibListPage {
  31. p := &MusicLibListPage{}
  32. p.PageIconMargin = 20
  33. p.SelectedIconTopOffset = 20
  34. p.EasingDur = 10
  35. p.Align = UI.ALIGN["SLeft"]
  36. p.FootMsg = [5]string{"Nav.", "", "Scan","Back","Add to Playlist"}
  37. p.URLColor = UI.MySkinManager.GiveColor("URL")
  38. p.TextColor = UI.MySkinManager.GiveColor("Text")
  39. p.ListFontObj = UI.MyLangManager.TrFont("notosanscjk15")
  40. p.Labels = make(map[string]UI.LabelInterface)
  41. p.Icons = make(map[string]UI.IconItemInterface)
  42. p.BGwidth = 56
  43. p.BGheight = 70
  44. return p
  45. }
  46. func (self *MusicLibListPage) OnLoadCb() {
  47. self.PosY = 0
  48. self.SyncList("/")
  49. }
  50. func (self *MusicLibListPage) SetCoords() {
  51. }
  52. func (self *MusicLibListPage) SyncList(path string) {
  53. conn, err := mpd.Dial("unix", sysgo.MPD_socket)
  54. if err != nil {
  55. log.Fatalln(err)
  56. }
  57. defer conn.Close()
  58. self.MyList = nil
  59. start_x := 0
  60. start_y := 0
  61. hasparent :=0
  62. atts, err := conn.ListInfo(path)
  63. if err != nil {
  64. log.Println(err)
  65. return
  66. }
  67. if self.MyStack.Length() > 0 {
  68. hasparent = 1
  69. li := NewMusicLibListPageListItem()
  70. li.Parent = self
  71. li.PosX = start_x
  72. li.PosY = start_y
  73. li.Width = UI.Width
  74. li.Fonts["normal"] = self.ListFontObj
  75. li.Init("[..]")
  76. li.MyType = UI.ICON_TYPES["DIR"]
  77. self.MyList = append(self.MyList, li)
  78. }
  79. if len(atts) == 0 {
  80. log.Println("no songs")
  81. return
  82. }
  83. for i, m := range atts {
  84. li : NewMusicLibListPageListItem()
  85. li.Parent = self
  86. li.PosX = start_x
  87. li.PosY = start_y + (i+hasparent)*li.Height
  88. li.Width = UI.Width
  89. li.Fonts["normal"] = self.ListFont
  90. li.MyType = UI.ICON_TYPES["FILE"]
  91. init_val := "NoName"
  92. if val, ok := m["directory"] ; ok {
  93. li.MyType = UI.ICON_TYPES["DIR"]
  94. init_val = filepath.Base(m["directory"])
  95. li.Path = m["directory"]
  96. }
  97. if val, ok = m["file"]; ok {
  98. li.MyType = UI.ICON_TYPES["FILE"]
  99. li.Path = m["file"]
  100. val2, ok2 := m["Title"]
  101. if ok2 && len(val2) > 4{
  102. init_val = val2
  103. }else{
  104. init_val = val
  105. }
  106. }
  107. li.Init(init_val)
  108. self.MyList = append(self.MyList, li)
  109. }
  110. }
  111. func (self *MusicLibListPage) Init() {
  112. if self.Screen == nil {
  113. panic("No Screen")
  114. }
  115. if self.Screen.CanvasHWND != nil && self.CanvasHWND == nil {
  116. self.HWND = self.Screen.CanvasHWND
  117. self.CanvasHWND = surface.Surface(self.Screen.Width, self.Screen.Height)
  118. }
  119. self.PosX = self.Index * self.Screen.Width
  120. self.Width = self.Screen.Width
  121. self.Height = self.Screen.Height
  122. ps := UI.NewInfoPageSelector()
  123. ps.Width = UI.Width - 12
  124. ps.PosX = 2
  125. ps.Parent = self
  126. self.Ps = ps
  127. self.PsIndex = 0
  128. bgpng := UI.NewIconItem()
  129. bgpng.ImgSurf = UI.MyIconPool.GetImgSurf("empty")
  130. bgpng.MyType = UI.ICON_TYPES["STAT"]
  131. bgpng.Parent = self
  132. bgpng.AddLabel("Please upload data over Wi-Fi", UI.Fonts["varela22"])
  133. bgpng.SetLabelColor(&color.Color{204, 204, 204, 255})
  134. bgpng.Adjust(0, 0, self.BGwidth, self.BGheight, 0)
  135. self.Icons["bg"] = bgpng
  136. icon_for_list := UI.NewMultiIconItem()
  137. icon_for_list.ImgSurf = UI.MyIconPool.GetImgSurf("sys")
  138. icon_for_list.MyType = UI.ICON_TYPES["STAT"]
  139. icon_for_list.Parent = self
  140. icon_for_list.Adjust(0, 0, 18, 18, 0)
  141. self.Icons["sys"] = icon_for_list
  142. self.Scroller = UI.NewListScroller()
  143. self.Scroller.Parent = self
  144. self.Scroller.PosX = self.Width - 10
  145. self.Scroller.PosY = 2
  146. self.Scroller.Init()
  147. }
  148. func (self *MusicLibListPage) KeyDown(ev *event.Event) {
  149. if ev.Data["Key"] == UI.CurKeys["Left"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  150. self.ReturnToUpLevelPage()
  151. self.Screen.Draw()
  152. self.Screen.SwapAndShow()
  153. }
  154. return
  155. }
  156. func (self *MusicLibListPage) Draw() {
  157. self.ClearCanvas()
  158. if len(self.MyList) == 0 {
  159. self.Icons["bg"].NewCoord(self.Width/2, self.Height/2)
  160. self.Icons["bg"].Draw()
  161. }
  162. if self.HWND != nil {
  163. surface.Fill(self.HWND, UI.MySkinManager.GiveColor("White"))
  164. rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
  165. surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
  166. }
  167. }