mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 16:08:52 +01:00
add infinitely scroll up down in RomListPage
This commit is contained in:
parent
cbb49f5f78
commit
8a205de3ca
2
main.go
2
main.go
@ -437,7 +437,7 @@ func run() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main_screen.KeyDown(ev)
|
main_screen.KeyDown(ev)
|
||||||
|
main_screen.LastKeyDown = everytime_keydown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,11 +31,18 @@ type MyEmulator struct { // as leader of RomListPage and FavListPage, it's a Plu
|
|||||||
FavPage *FavListPage
|
FavPage *FavListPage
|
||||||
DeleteConfirmPage *UI.DeleteConfirmPage
|
DeleteConfirmPage *UI.DeleteConfirmPage
|
||||||
EmulatorConfig *ActionConfig
|
EmulatorConfig *ActionConfig
|
||||||
|
|
||||||
|
SpeedMax int
|
||||||
|
SpeedTimeInter int
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMyEmulator() *MyEmulator{
|
func NewMyEmulator() *MyEmulator{
|
||||||
p := &MyEmulator{}
|
p := &MyEmulator{}
|
||||||
|
|
||||||
|
p.SpeedMax = 5
|
||||||
|
p.SpeedTimeInter = 300
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"errors"
|
"errors"
|
||||||
|
gotime "time"
|
||||||
"github.com/veandco/go-sdl2/ttf"
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
"github.com/cuu/gogame/event"
|
"github.com/cuu/gogame/event"
|
||||||
@ -53,6 +53,8 @@ func NewFavListPage() *FavListPage {
|
|||||||
p.BGwidth = 75
|
p.BGwidth = 75
|
||||||
p.BGheight = 73
|
p.BGheight = 73
|
||||||
|
|
||||||
|
p.ScrollStep = 1
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,6 +436,22 @@ func (self *FavListPage) OnLoadCb() {
|
|||||||
self.Screen.SwapAndShow()
|
self.Screen.SwapAndShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *FavListPage) SpeedScroll(thekey string ) {
|
||||||
|
if self.Screen.LastKey == thekey {
|
||||||
|
self.ScrollStep += 1
|
||||||
|
if self.ScrollStep >= self.Leader.SpeedMax {
|
||||||
|
self.ScrollStep = self.Leader.SpeedMax
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.ScrollStep = 1
|
||||||
|
}
|
||||||
|
cur_time := gotime.Now()
|
||||||
|
|
||||||
|
if cur_time.Sub(self.Screen.LastKeyDown) > gotime.Duration(self.Leader.SpeedTimeInter)*gotime.Millisecond {
|
||||||
|
self.ScrollStep = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *FavListPage) KeyDown(ev *event.Event) {
|
func (self *FavListPage) KeyDown(ev *event.Event) {
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["Left"] {
|
if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["Left"] {
|
||||||
@ -443,12 +461,14 @@ func (self *FavListPage) KeyDown(ev *event.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Up"]{
|
if ev.Data["Key"] == UI.CurKeys["Up"]{
|
||||||
|
self.SpeedScroll(ev.Data["Key"])
|
||||||
self.ScrollUp()
|
self.ScrollUp()
|
||||||
self.Screen.Draw()
|
self.Screen.Draw()
|
||||||
self.Screen.SwapAndShow()
|
self.Screen.SwapAndShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Down"] {
|
if ev.Data["Key"] == UI.CurKeys["Down"] {
|
||||||
|
self.SpeedScroll(ev.Data["Key"])
|
||||||
self.ScrollDown()
|
self.ScrollDown()
|
||||||
self.Screen.Draw()
|
self.Screen.Draw()
|
||||||
self.Screen.SwapAndShow()
|
self.Screen.SwapAndShow()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"errors"
|
"errors"
|
||||||
|
gotime "time"
|
||||||
"github.com/veandco/go-sdl2/ttf"
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
"github.com/cuu/gogame/time"
|
"github.com/cuu/gogame/time"
|
||||||
"github.com/cuu/gogame/color"
|
"github.com/cuu/gogame/color"
|
||||||
@ -54,6 +54,7 @@ func NewRomListPage() *RomListPage {
|
|||||||
p.BGwidth = 56
|
p.BGwidth = 56
|
||||||
p.BGheight = 70
|
p.BGheight = 70
|
||||||
|
|
||||||
|
p.ScrollStep = 1
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,24 +264,27 @@ func (self *RomListPage) ScrollUp() {
|
|||||||
if len(self.MyList) == 0 {
|
if len(self.MyList) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
tmp := self.PsIndex
|
||||||
self.PsIndex -=1
|
self.PsIndex -=self.ScrollStep
|
||||||
|
dy := 0
|
||||||
|
|
||||||
if self.PsIndex < 0 {
|
if self.PsIndex < 0 {
|
||||||
self.PsIndex = 0
|
self.PsIndex = len(self.MyList) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dy = tmp - self.PsIndex
|
||||||
|
|
||||||
cur_li := self.MyList[self.PsIndex]
|
cur_li := self.MyList[self.PsIndex]
|
||||||
x,y := cur_li.Coord()
|
x,y := cur_li.Coord()
|
||||||
_,h := cur_li.Size()
|
_,h := cur_li.Size()
|
||||||
if y < 0 {
|
{
|
||||||
for i,_ := range self.MyList{
|
for i,_ := range self.MyList{
|
||||||
x,y = self.MyList[i].Coord()
|
x,y = self.MyList[i].Coord()
|
||||||
_, h = self.MyList[i].Size()
|
_, h = self.MyList[i].Size()
|
||||||
self.MyList[i].NewCoord(x,y + h)
|
self.MyList[i].NewCoord(x,y + h*dy)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Scrolled +=1
|
self.Scrolled +=dy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,23 +293,26 @@ func (self *RomListPage) ScrollDown(){
|
|||||||
if len(self.MyList) == 0 {
|
if len(self.MyList) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.PsIndex +=1
|
tmp := self.PsIndex
|
||||||
|
self.PsIndex +=self.ScrollStep
|
||||||
|
|
||||||
if self.PsIndex >= len(self.MyList) {
|
if self.PsIndex >= len(self.MyList) {
|
||||||
self.PsIndex = len(self.MyList) - 1
|
self.PsIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dy := self.PsIndex - tmp
|
||||||
|
|
||||||
cur_li := self.MyList[self.PsIndex]
|
cur_li := self.MyList[self.PsIndex]
|
||||||
x,y := cur_li.Coord()
|
x,y := cur_li.Coord()
|
||||||
_,h := cur_li.Size()
|
_,h := cur_li.Size()
|
||||||
|
|
||||||
if y+ h > self.Height {
|
{
|
||||||
for i,_ := range self.MyList{
|
for i,_ := range self.MyList{
|
||||||
x,y = self.MyList[i].Coord()
|
x,y = self.MyList[i].Coord()
|
||||||
_, h = self.MyList[i].Size()
|
_, h = self.MyList[i].Size()
|
||||||
self.MyList[i].NewCoord(x,y - h)
|
self.MyList[i].NewCoord(x,y - h*dy)
|
||||||
}
|
}
|
||||||
self.Scrolled -=1
|
self.Scrolled -=dy
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -428,19 +435,8 @@ func (self *RomListPage) ReScan() {
|
|||||||
self.SyncList(self.MyStack.Last())
|
self.SyncList(self.MyStack.Last())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.PsIndex = 0 //sync PsIndex
|
||||||
idx := self.PsIndex
|
self.Scrolled = 0
|
||||||
|
|
||||||
if idx > len(self.MyList) - 1 {
|
|
||||||
idx = len(self.MyList)
|
|
||||||
if idx > 0 {
|
|
||||||
idx -= 1
|
|
||||||
}else if idx == 0 {
|
|
||||||
//nothing in MyList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.PsIndex = idx //sync PsIndex
|
|
||||||
|
|
||||||
self.SyncScroll()
|
self.SyncScroll()
|
||||||
}
|
}
|
||||||
@ -453,6 +449,22 @@ func (self *RomListPage) OnReturnBackCb() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (self *RomListPage) SpeedScroll(thekey string ) {
|
||||||
|
if self.Screen.LastKey == thekey {
|
||||||
|
self.ScrollStep += 1
|
||||||
|
if self.ScrollStep >= self.Leader.SpeedMax {
|
||||||
|
self.ScrollStep = self.Leader.SpeedMax
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.ScrollStep = 1
|
||||||
|
}
|
||||||
|
cur_time := gotime.Now()
|
||||||
|
|
||||||
|
if cur_time.Sub(self.Screen.LastKeyDown) > gotime.Duration(self.Leader.SpeedTimeInter)*gotime.Millisecond {
|
||||||
|
self.ScrollStep = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *RomListPage) KeyDown(ev *event.Event) {
|
func (self *RomListPage) KeyDown(ev *event.Event) {
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Menu"]{
|
if ev.Data["Key"] == UI.CurKeys["Menu"]{
|
||||||
@ -469,12 +481,14 @@ func (self *RomListPage) KeyDown(ev *event.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Up"]{
|
if ev.Data["Key"] == UI.CurKeys["Up"]{
|
||||||
|
self.SpeedScroll(ev.Data["Key"])
|
||||||
self.ScrollUp()
|
self.ScrollUp()
|
||||||
self.Screen.Draw()
|
self.Screen.Draw()
|
||||||
self.Screen.SwapAndShow()
|
self.Screen.SwapAndShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev.Data["Key"] == UI.CurKeys["Down"] {
|
if ev.Data["Key"] == UI.CurKeys["Down"] {
|
||||||
|
self.SpeedScroll(ev.Data["Key"])
|
||||||
self.ScrollDown()
|
self.ScrollDown()
|
||||||
self.Screen.Draw()
|
self.Screen.Draw()
|
||||||
self.Screen.SwapAndShow()
|
self.Screen.SwapAndShow()
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
//"encoding/json"
|
//"encoding/json"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
gotime "time"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
"github.com/veandco/go-sdl2/ttf"
|
"github.com/veandco/go-sdl2/ttf"
|
||||||
|
|
||||||
@ -179,6 +179,9 @@ type MainScreen struct {
|
|||||||
Closed bool
|
Closed bool
|
||||||
|
|
||||||
UIPluginList []*UIPlugin
|
UIPluginList []*UIPlugin
|
||||||
|
|
||||||
|
LastKey string
|
||||||
|
LastKeyDown gotime.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -382,6 +385,8 @@ func (self *MainScreen) KeyDown(ev *event.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.CurrentPage.KeyDown(ev)
|
self.CurrentPage.KeyDown(ev)
|
||||||
|
self.LastKey = ev.Data["Key"]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -252,6 +252,7 @@ type Page struct {
|
|||||||
|
|
||||||
SelectedIconTopOffset int
|
SelectedIconTopOffset int
|
||||||
EasingDur int
|
EasingDur int
|
||||||
|
ScrollStep int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPage() *Page {
|
func NewPage() *Page {
|
||||||
@ -261,7 +262,7 @@ func NewPage() *Page {
|
|||||||
p.EasingDur = 10
|
p.EasingDur = 10
|
||||||
|
|
||||||
p.Align = ALIGN["SLeft"]
|
p.Align = ALIGN["SLeft"]
|
||||||
|
p.ScrollStep = 1
|
||||||
p.FootMsg = [5]string{"Nav.","","","","Enter"}
|
p.FootMsg = [5]string{"Nav.","","","","Enter"}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user