Emulator bug fix

This commit is contained in:
cuu 2018-12-12 14:34:46 +08:00
parent 8746a98d3b
commit ced5ed5440
5 changed files with 123 additions and 51 deletions

View File

@ -104,11 +104,14 @@ func ReadTheDirIntoPages(self *UI.MainScreen, _dir string, pglevel int, cur_page
//Init it
}else if self.IsEmulatorPackage(_dir+"/"+f.Name()) {
a_c := Emulator.ActionConfig{}
a_c.FILETYPE="file"
a_c.TITLE = "Game"
dat, err := ioutil.ReadFile(_dir+"/"+f.Name()+"/" +UI.Emulator_flag)
UI.ShowErr(err)
err = json.Unmarshal(dat, &a_c)
if err == nil {
if err == nil {
//fmt.Println(a_c)
if UI.FileExists(filepath.Join(_dir,f.Name(),"retroarch-local.cfg")) {
a_c.RETRO_CONFIG = UI.CmdClean( filepath.Join(_dir,f.Name(),"retroarch-local.cfg") )
fmt.Println("a local retroarch cfg: ",a_c.RETRO_CONFIG)

View File

@ -26,7 +26,7 @@ type FavListPage struct {
RomSoConfirmDownloadPage *RomSoConfirmPage
MyList []*EmulatorListItem
MyList []UI.ListItemInterface
BGwidth int
BGheight int //70
Scroller *UI.ListScroller
@ -99,8 +99,8 @@ func (self *FavListPage) GeneratePathList(path string) ([]map[string]string,erro
pieces := strings.Split(bname,".")
if len(pieces) > 1 {
pieces_ext := strings.ToLower( pieces[len(pieces)-1])
for _,v := range self.EmulatorConfig.EXT {
if pieces_ext == v {
for _,u := range self.EmulatorConfig.EXT {
if pieces_ext == u {
dirmap["file"] = v
ret = append(ret,dirmap)
break
@ -240,10 +240,12 @@ func (self *FavListPage) ScrollUp() {
}
cur_li := self.MyList[self.PsIndex]
x,y := cur_li.Coord()
_,h := cur_li.Size()
if cur_li.PosY < 0 {
if y < 0 {
for i,_ := range self.MyList{
self.MyList[i].PosY += self.MyList[i].Height
self.MyList[i].NewCoord(x, y + h)
}
self.Scrolled +=1
@ -262,10 +264,11 @@ func (self *FavListPage) ScrollDown(){
}
cur_li := self.MyList[self.PsIndex]
if cur_li.PosY + cur_li.Height > self.Height {
x,y := cur_li.Coord()
_,h := cur_li.Size()
if y + h > self.Height {
for i,_ := range self.MyList{
self.MyList[i].PosY -= self.MyList[i].Height
self.MyList[i].NewCoord(x,y-h)
}
self.Scrolled -=1
}
@ -280,16 +283,21 @@ func (self *FavListPage) SyncScroll() {
if self.PsIndex < len(self.MyList) {
cur_li := self.MyList[self.PsIndex]
x,y := cur_li.Coord()
_,h := cur_li.Size()
if self.Scrolled > 0 {
if cur_li.PosY < 0 {
if y < 0 {
for i,_ := range self.MyList{
self.MyList[i].PosY += self.Scrolled*self.MyList[i].Height
_,h = self.MyList[i].Size()
self.MyList[i].NewCoord(x, y + self.Scrolled*h)
}
}
}else if self.Scrolled < 0 {
if cur_li.PosY + cur_li.Height > self.Height {
if y + h > self.Height {
for i,_ := range self.MyList {
self.MyList[i].PosY += self.Scrolled*self.MyList[i].Height
_,h = self.MyList[i].Size()
self.MyList[i].NewCoord(x,y + self.Scrolled*h)
}
}
}
@ -312,28 +320,28 @@ func (self *FavListPage) Click() {
cur_li := self.MyList[self.PsIndex]
if cur_li.MyType == UI.ICON_TYPES["DIR"] {
if cur_li.Path == "[..]" {
if cur_li.(*EmulatorListItem).MyType == UI.ICON_TYPES["DIR"] {
if cur_li.(*EmulatorListItem).Path == "[..]" {
self.MyStack.Pop()
self.SyncList(self.MyStack.Last())
self.PsIndex = 0
}else{
self.MyStack.Push(self.MyList[self.PsIndex].Path)
self.MyStack.Push(self.MyList[self.PsIndex].(*EmulatorListItem).Path)
self.SyncList(self.MyStack.Last())
self.PsIndex = 0
}
}
if cur_li.MyType == UI.ICON_TYPES["FILE"] {
if cur_li.(*EmulatorListItem).MyType == UI.ICON_TYPES["FILE"] {
self.Screen.MsgBox.SetText("Launching")
self.Screen.MsgBox.Draw()
self.Screen.SwapAndShow()
path := ""
if self.EmulatorConfig.FILETYPE == "dir" {
path = filepath.Join(cur_li.Path,self.EmulatorConfig.EXT[0])
path = filepath.Join(cur_li.(*EmulatorListItem).Path,self.EmulatorConfig.EXT[0])
}else{
path = cur_li.Path
path = cur_li.(*EmulatorListItem).Path
}
fmt.Println("Run ",path)
@ -449,9 +457,9 @@ func (self *FavListPage) KeyDown(ev *event.Event) {
}
cur_li := self.MyList[self.PsIndex]
if cur_li.IsFile() {
uid := UI.GetUid(cur_li.Path)
os.Chown(cur_li.Path,uid ,uid)
if cur_li.(*EmulatorListItem).IsFile() {
uid := UI.GetUid(cur_li.(*EmulatorListItem).Path)
os.Chown(cur_li.(*EmulatorListItem).Path,uid ,uid)
self.Screen.MsgBox.SetText("Deleting")
self.Screen.MsgBox.Draw()
self.Screen.SwapAndShow()
@ -478,11 +486,12 @@ func (self *FavListPage) Draw() {
for _,v := range self.MyList {
if v.PosY > self.Height + self.Height/2 {
_, y := v.Coord()
if y > self.Height + self.Height/2 {
break
}
if v.PosY < 0 {
if y < 0 {
continue
}

View File

@ -95,6 +95,10 @@ func (self *HierListItem) IsDir() bool {
func (self *HierListItem) Init(text string) {
l := UI.NewLabel()
l.PosX = 20
if self.Parent == nil {
fmt.Println("Parent nil")
return
}
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
if self.IsDir() == true || self.IsFile() == true {
@ -178,10 +182,47 @@ func NewEmulatorListItem() *EmulatorListItem {
p.MyType = UI.ICON_TYPES["EXE"]
p.Height = 32
p.Width = 0
p.Width = 0
return p
}
func (self *EmulatorListItem) Init(text string) {
l := UI.NewLabel()
l.PosX = 20
l.SetCanvasHWND(self.Parent.GetCanvasHWND())
if self.IsDir() == true || self.IsFile() == true {
self.Path = text
}
label_text := filepath.Base(text)
ext:= filepath.Ext(text)
if ext != "" {
alias_file := strings.Replace(text,ext,"",-1) + ".alias"
if UI.FileExists(alias_file) == true {
b, err := ioutil.ReadFile(alias_file)
if err != nil {
fmt.Print(err)
}else {
label_text = string(b)
}
}
}
if self.IsDir() == true {
l.Init(label_text, self.Fonts["normal"],nil)
}else {
l.Init(label_text,self.Fonts["normal"],nil)
}
self.Labels["Text"] = l
}
func (self *EmulatorListItem) Draw() {
x,y := self.Labels["Text"].Coord()
_,h := self.Labels["Text"].Size()

View File

@ -26,7 +26,7 @@ type RomListPage struct {
RomSoConfirmDownloadPage *RomSoConfirmPage
MyList []*EmulatorListItem
MyList []UI.ListItemInterface
BGwidth int
BGheight int //70
Scroller *UI.ListScroller
@ -57,6 +57,10 @@ func NewRomListPage() *RomListPage {
return p
}
func (self *RomListPage) GetMyList() []UI.ListItemInterface {
return self.MyList
}
func (self *RomListPage) GetMapIcons() map[string]UI.IconItemInterface {
return self.Icons
}
@ -98,6 +102,7 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
}
bname := filepath.Base(v)
if len(bname) > 1 {
is_excluded := false
for _,exclude_pattern := range self.EmulatorConfig.EXCLUDE {
@ -111,10 +116,11 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
if is_excluded == false {
pieces := strings.Split(bname,".")
if len(pieces) > 1 {
pieces_ext := strings.ToLower( pieces[len(pieces)-1])
for _,v := range self.EmulatorConfig.EXT {
if pieces_ext == v {
for _,u := range self.EmulatorConfig.EXT {
if pieces_ext == u {
dirmap["file"] = v
ret = append(ret,dirmap)
break
@ -133,7 +139,7 @@ func (self *RomListPage) GeneratePathList(path string) ([]map[string]string,erro
func (self *RomListPage) SyncList( path string ) {
alist,err := self.GeneratePathList(path)
//fmt.Println(alist)
if err != nil {
fmt.Println(err)
return
@ -165,6 +171,7 @@ func (self *RomListPage) SyncList( path string ) {
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"]
@ -265,10 +272,11 @@ func (self *RomListPage) ScrollUp() {
}
cur_li := self.MyList[self.PsIndex]
if cur_li.PosY < 0 {
x,y := cur_li.Coord()
_,h := cur_li.Size()
if y < 0 {
for i,_ := range self.MyList{
self.MyList[i].PosY += self.MyList[i].Height
self.MyList[i].NewCoord(x,y + h)
}
self.Scrolled +=1
@ -287,10 +295,12 @@ func (self *RomListPage) ScrollDown(){
}
cur_li := self.MyList[self.PsIndex]
x,y := cur_li.Coord()
_,h := cur_li.Size()
if cur_li.PosY + cur_li.Height > self.Height {
if y+ h > self.Height {
for i,_ := range self.MyList{
self.MyList[i].PosY -= self.MyList[i].Height
self.MyList[i].NewCoord(x,y - h)
}
self.Scrolled -=1
}
@ -305,16 +315,21 @@ func (self *RomListPage) SyncScroll() {
if self.PsIndex < len(self.MyList) {
cur_li := self.MyList[self.PsIndex]
x, y := cur_li.Coord()
_, h := cur_li.Size()
if self.Scrolled > 0 {
if cur_li.PosY < 0 {
if y < 0 {
for i,_ := range self.MyList{
self.MyList[i].PosY += self.Scrolled*self.MyList[i].Height
_, h = self.MyList[i].Size()
self.MyList[i].NewCoord(x, y + self.Scrolled*h)
}
}
}else if self.Scrolled < 0 {
if cur_li.PosY + cur_li.Height > self.Height{
if y + h > self.Height{
for i,_ := range self.MyList{
self.MyList[i].PosY += self.Scrolled*self.MyList[i].Height
_, h = self.MyList[i].Size()
self.MyList[i].NewCoord(x, y + self.Scrolled*h)
}
}
}
@ -336,28 +351,28 @@ func (self *RomListPage) Click() {
cur_li := self.MyList[self.PsIndex]
if cur_li.MyType == UI.ICON_TYPES["DIR"] {
if cur_li.Path == "[..]"{
if cur_li.(*EmulatorListItem).MyType == UI.ICON_TYPES["DIR"] {
if cur_li.(*EmulatorListItem).Path == "[..]"{
self.MyStack.Pop()
self.SyncList(self.MyStack.Last())
self.PsIndex = 0
}else{
self.MyStack.Push(self.MyList[self.PsIndex].Path)
self.MyStack.Push(self.MyList[self.PsIndex].(*EmulatorListItem).Path)
self.SyncList(self.MyStack.Last())
self.PsIndex = 0
}
}
if cur_li.MyType == UI.ICON_TYPES["FILE"] {
if cur_li.(*EmulatorListItem).MyType == UI.ICON_TYPES["FILE"] {
self.Screen.MsgBox.SetText("Launching")
self.Screen.MsgBox.Draw()
self.Screen.SwapAndShow()
path := ""
if self.EmulatorConfig.FILETYPE == "dir" {
path = filepath.Join(cur_li.Path,self.EmulatorConfig.EXT[0])
path = filepath.Join(cur_li.(*EmulatorListItem).Path,self.EmulatorConfig.EXT[0])
}else{
path = cur_li.Path
path = cur_li.(*EmulatorListItem).Path
}
fmt.Println("Run ",path)
@ -401,6 +416,7 @@ func (self *RomListPage) Click() {
}
func (self *RomListPage) ReScan() {
fmt.Println("RomListPage ReScan ",self.EmulatorConfig.ROM)
if self.MyStack.Length() == 0 {
self.SyncList(self.EmulatorConfig.ROM)
}else{
@ -470,8 +486,8 @@ func (self *RomListPage) KeyDown(ev *event.Event) {
cur_li := self.MyList[self.PsIndex]
if cur_li.IsFile() {
cmd := exec.Command("chgrp", FavGname, UI.CmdClean(cur_li.Path))
if cur_li.(*EmulatorListItem).IsFile() {
cmd := exec.Command("chgrp", FavGname, UI.CmdClean(cur_li.(*EmulatorListItem).Path))
err := cmd.Run()
if err != nil {
fmt.Println(err)
@ -500,8 +516,8 @@ func (self *RomListPage) KeyDown(ev *event.Event) {
}
cur_li := self.MyList[self.PsIndex]
if cur_li.IsFile() {
self.Leader.DeleteConfirmPage.SetFileName(cur_li.Path)
if cur_li.(*EmulatorListItem).IsFile() {
self.Leader.DeleteConfirmPage.SetFileName(cur_li.(*EmulatorListItem).Path)
self.Leader.DeleteConfirmPage.SetTrashDir(filepath.Join(self.EmulatorConfig.ROM,"/.Trash") )
self.Screen.PushCurPage()
@ -527,11 +543,12 @@ func (self *RomListPage) Draw() {
for _,v := range self.MyList {
if v.PosY > self.Height + self.Height/2 {
_,y := v.Coord()
if y > self.Height + self.Height/2 {
break
}
if v.PosY < 0 {
if y < 0 {
continue
}

View File

@ -1,6 +1,7 @@
package UI
import (
//"fmt"
// "github.com/veandco/go-sdl2/ttf"
// "github.com/cuu/gogame/surface"
@ -33,11 +34,12 @@ func (self *InfoPageSelector) AnimateDraw(x2, y2 int) {
func (self *InfoPageSelector) Draw() {
idx := self.Parent.GetPsIndex()
mylist := self.Parent.GetMyList()
if idx < len(mylist) {
_,y := mylist[idx].Coord()
_,h := mylist[idx].Size()
self.PosY = y+1
self.Height = h-3