try to add list_item for music_lib_list_page and music_player_page

This commit is contained in:
cuu 2023-01-15 12:25:57 +00:00
parent 5b5cb5e39f
commit 8075ac6290
3 changed files with 230 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package MusicPlayer
import (
//"fmt"
"path/filepath"
"github.com/cuu/gogame/event"
"github.com/cuu/gogame/rect"
@ -10,7 +11,11 @@ import (
"github.com/cuu/gogame/color"
"github.com/clockworkpi/LauncherGoDev/sysgo"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/fhs/gompd/v2/mpd"
)
type MusicLibListPage struct {
@ -61,12 +66,90 @@ func NewMusicLibListPage() *MusicLibListPage {
func (self *MusicLibListPage) OnLoadCb() {
self.PosY = 0
self.SyncList("/")
}
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()
self.MyList = nil
start_x := 0
start_y := 0
hasparent :=0
atts, err := conn.ListInfo(path)
if err != nil {
log.Println(err)
return
}
if self.MyStack.Length() > 0 {
hasparent = 1
li := NewMusicLibListPageListItem()
li.Parent = self
li.PosX = start_x
li.PosY = start_y
li.Width = UI.Width
li.Fonts["normal"] = self.ListFontObj
li.Init("[..]")
li.MyType = UI.ICON_TYPES["DIR"]
self.MyList = append(self.MyList, li)
}
if len(atts) == 0 {
log.Println("no songs")
return
}
for i, m := range atts {
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.MyType = UI.ICON_TYPES["FILE"]
init_val := "NoName"
val, ok := m["directory"]
if ok {
li.MyType = UI.ICON_TYPES["DIR"]
init_val = filepath.Base(m["directory"])
li.Path = m["directory"]
}
val, ok = m["file"]
if ok {
li.MyType = UI.ICON_TYPES["FILE"]
li.Path = m["file"]
val2, ok2 := m["Title"]
if ok2 && len(val2) > 4{
init_val = val2
}else{
init_val = val
}
}
li.Init(init_val)
self.MyList = append(self.MyList, li)
}
}
func (self *MusicLibListPage) Init() {
if self.Screen == nil {
panic("No Screen")

View File

@ -0,0 +1,73 @@
package MusicPlayer
import (
"fmt"
//"io/ioutil"
//"path/filepath"
"github.com/veandco/go-sdl2/ttf"
"runtime"
"strconv"
"strings"
//"github.com/mitchellh/go-homedir"
"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"
)
type MusicLibListPageListItem struct {
UI.InfoPageListItem
Active bool
Value string
MyType string
Path string
}
func NewMusicLibListPageListItem() *MusicLibListPageListItem {
p := &MusicLibListPageListItem{}
p.Height = UI.DefaultInfoPageListItemHeight
p.ReadOnly = false
p.Labels = make(map[string]UI.LabelInterface)
p.Icons = make(map[string]UI.IconItemInterface)
p.Fonts = make(map[string]*ttf.Font)
p.MyType = UI.ICON_TYPES["EXE"]
return p
}
func (self *MusicLibListPageListItem) Draw() {
x, _ := self.Labels["Text"].Coord()
w, h := self.Labels["Text"].Size()
self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
if self.Active == true {
self.Parent.(*MusicLibListPage).Icons["sys"].NewCoord(self.Parent.(*MusicLibListPage).Width-30, self.PosY+5)
self.Parent.(*MusicLibListPage).Icons["sys"].Draw()
}
self.Labels["Text"].SetBold(self.Active)
self.Labels["Text"].Draw()
if _, ok := self.Labels["Small"]; ok {
x, _ = self.Labels["Small"].Coord()
w, h = self.Labels["Small"].Size()
self.Labels["Small"].NewCoord(self.Width-w-10, self.PosY+(self.Height-h)/2)
self.Labels["Small"].Draw()
}
canvas_ := self.Parent.GetCanvasHWND()
draw.Line(canvas_, &color.Color{169, 169, 169, 255},
self.PosX, self.PosY+self.Height-1,
self.PosX+self.Width, self.PosY+self.Height-1, 1)
}

View File

@ -0,0 +1,73 @@
package MusicPlayer
import (
"fmt"
//"io/ioutil"
//"path/filepath"
"github.com/veandco/go-sdl2/ttf"
"runtime"
"strconv"
"strings"
//"github.com/mitchellh/go-homedir"
"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"
)
type MusicPlayPageListItem struct {
UI.InfoPageListItem
Active bool
Value string
MyType string
Path string
}
func NewMusicPlayPageListItem() *MusicPlayPageListItem {
p := &MusicPlayPageListItem{}
p.Height = UI.DefaultInfoPageListItemHeight
p.ReadOnly = false
p.Labels = make(map[string]UI.LabelInterface)
p.Icons = make(map[string]UI.IconItemInterface)
p.Fonts = make(map[string]*ttf.Font)
p.MyType = UI.ICON_TYPES["EXE"]
return p
}
func (self *MusicPlayPageListItem) Draw() {
x, _ := self.Labels["Text"].Coord()
w, h := self.Labels["Text"].Size()
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.Labels["Text"].SetBold(self.Active)
self.Labels["Text"].Draw()
if _, ok := self.Labels["Small"]; ok {
x, _ = self.Labels["Small"].Coord()
w, h = self.Labels["Small"].Size()
self.Labels["Small"].NewCoord(self.Width-w-10, self.PosY+(self.Height-h)/2)
self.Labels["Small"].Draw()
}
canvas_ := self.Parent.GetCanvasHWND()
draw.Line(canvas_, &color.Color{169, 169, 169, 255},
self.PosX, self.PosY+self.Height-1,
self.PosX+self.Width, self.PosY+self.Height-1, 1)
}