add TimeZone selection in settings

This commit is contained in:
cuu
2018-12-24 14:18:32 +08:00
parent af6e325bb3
commit fe210d5561
13 changed files with 772 additions and 180 deletions

View File

@@ -21,7 +21,7 @@ type FavListPage struct {
UI.Page
Icons map[string]UI.IconItemInterface
ListFont *ttf.Font
MyStack *EmuStack
MyStack *UI.FolderStack
EmulatorConfig *ActionConfig
RomSoConfirmDownloadPage *RomSoConfirmPage
@@ -48,7 +48,7 @@ func NewFavListPage() *FavListPage {
p.Icons=make(map[string]UI.IconItemInterface)
p.ListFont = UI.Fonts["notosanscjk15"]
p.MyStack = NewEmuStack()
p.MyStack = UI.NewFolderStack()
p.BGwidth = 75
p.BGheight = 73
@@ -194,10 +194,10 @@ func (self *FavListPage) Init() {
self.Ps = ps
self.PsIndex = 0
self.MyStack.SetRootPath(self.EmulatorConfig.ROM)
self.SyncList( self.EmulatorConfig.ROM )
self.MyStack.EmulatorConfig = self.EmulatorConfig
icon_for_list := UI.NewMultiIconItem()
icon_for_list.ImgSurf = UI.MyIconPool.GetImgSurf("sys")
icon_for_list.MyType = UI.ICON_TYPES["STAT"]
@@ -492,7 +492,7 @@ func (self *FavListPage) Draw() {
self.Icons["bg"].Draw()
}else{
_,h := self.Ps.Size()
if len(self.MyList) * HierListItemDefaultHeight > self.Height {
if len(self.MyList) * UI.HierListItemDefaultHeight > self.Height {
self.Ps.NewSize(self.Width - 10, h)
self.Ps.Draw()
@@ -511,7 +511,8 @@ func (self *FavListPage) Draw() {
v.Draw()
}
self.Scroller.UpdateSize( len(self.MyList)*HierListItemDefaultHeight, self.PsIndex*HierListItemDefaultHeight)
self.Scroller.UpdateSize( len(self.MyList)*UI.HierListItemDefaultHeight,
self.PsIndex*UI.HierListItemDefaultHeight)
self.Scroller.Draw()

View File

@@ -8,8 +8,8 @@ import (
"github.com/veandco/go-sdl2/ttf"
//"github.com/veandco/go-sdl2/sdl"
"github.com/cuu/gogame/surface"
"github.com/cuu/gogame/rect"
//"github.com/cuu/gogame/surface"
//"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/color"
"github.com/cuu/gogame/draw"
@@ -24,153 +24,8 @@ type EmulatorPageInterface interface {
}
type ListItemIcon struct {
UI.IconItem
}
func NewListItemIcon() *ListItemIcon {
p := &ListItemIcon{}
p.MyType = UI.ICON_TYPES["EXE"]
p.Align = UI.ALIGN["VCenter"]
p.Width = 18
p.Height = 18
return p
}
func (self *ListItemIcon) Draw() {
_,h := self.Parent.Size()
rect_ := rect.Rect(self.PosX,self.PosY+(h-self.Height)/2,self.Width,self.Height)
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf,&rect_,nil)
}
/// [..] [.]
type HierListItem struct {
UI.ListItem
MyType int
Path string
Active bool
Playing bool
}
var HierListItemDefaultHeight = 32
func NewHierListItem() *HierListItem {
p := &HierListItem{}
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"]
p.Height = HierListItemDefaultHeight
p.Width = 0
return p
}
func (self *HierListItem) IsFile() bool {
if self.MyType == UI.ICON_TYPES["FILE"] {
return true
}
return false
}
func (self *HierListItem) IsDir() bool {
if self.MyType == UI.ICON_TYPES["DIR"] {
return true
}
return false
}
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 {
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 *HierListItem) Draw() {
x,y := self.Labels["Text"].Coord()
_,h := self.Labels["Text"].Size()
if self.Path != "[..]" {
self.Labels["Text"].NewCoord(23,y)
}else {
self.Labels["Text"].NewCoord(3,y)
}
x,y = self.Labels["Text"].Coord()
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height-h)/2)
self.Labels["Text"].Draw()
/*
w,h := self.Parent.Icons["sys"].Size()
if self.IsDir() == true && self.Path != "[..]" {
self.Parent.Icons["sys"].IconIndex = 0
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
self.Parent.Icons["sys"].Draw()
}
if self.IsFile() == true {
self.Parent.Icons["sys"].IconIndex = 1
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
self.Parent.Icons["sys"].Draw()
}
*/
draw.Line(self.Parent.GetCanvasHWND(),&color.Color{169,169,169,255},
self.PosX,self.PosY+self.Height-1,self.PosX+self.Width,self.PosY+self.Height-1,1)
}
type EmulatorListItem struct {
HierListItem
UI.HierListItem
Parent EmulatorPageInterface
}

View File

@@ -21,7 +21,7 @@ type RomListPage struct {
UI.Page
Icons map[string]UI.IconItemInterface
ListFont *ttf.Font
MyStack *EmuStack
MyStack *UI.FolderStack
EmulatorConfig *ActionConfig
RomSoConfirmDownloadPage *RomSoConfirmPage
@@ -49,7 +49,7 @@ func NewRomListPage() *RomListPage {
p.Icons=make(map[string]UI.IconItemInterface)
p.ListFont = UI.Fonts["notosanscjk15"]
p.MyStack = NewEmuStack()
p.MyStack = UI.NewFolderStack()
p.BGwidth = 56
p.BGheight = 70
@@ -211,6 +211,8 @@ func (self *RomListPage) Init() {
self.Ps = ps
self.PsIndex = 0
self.MyStack.SetRootPath(self.EmulatorConfig.ROM)
self.SyncList( self.EmulatorConfig.ROM )
err := os.MkdirAll( self.EmulatorConfig.ROM+"/.Trash", 0700)
@@ -222,9 +224,7 @@ func (self *RomListPage) Init() {
if err != nil {
panic(err)
}
self.MyStack.EmulatorConfig = self.EmulatorConfig
icon_for_list := UI.NewMultiIconItem()
icon_for_list.ImgSurf = UI.MyIconPool.GetImgSurf("sys")
icon_for_list.MyType = UI.ICON_TYPES["STAT"]
@@ -543,7 +543,7 @@ func (self *RomListPage) Draw() {
self.Icons["bg"].Draw()
}else{
_,h := self.Ps.Size()
if len(self.MyList) * HierListItemDefaultHeight > self.Height {
if len(self.MyList) * UI.HierListItemDefaultHeight > self.Height {
self.Ps.NewSize(self.Width - 10,h)
self.Ps.Draw()
@@ -555,7 +555,8 @@ func (self *RomListPage) Draw() {
v.Draw()
}
self.Scroller.UpdateSize( len(self.MyList)*HierListItemDefaultHeight, self.PsIndex*HierListItemDefaultHeight)
self.Scroller.UpdateSize( len(self.MyList)*UI.HierListItemDefaultHeight,
self.PsIndex*UI.HierListItemDefaultHeight)
self.Scroller.Draw()
}else {

View File

@@ -91,4 +91,8 @@ func init() {
MyLangManager.Init()
}
if MySkinManager == nil {
MySkinManager = NewSkinManager()
MySkinManager.Init()
}
}

View File

@@ -1,24 +1,18 @@
package Emulator
package UI
import (
"sync"
//"github.com/cuu/LauncherGoDev/sysgo/UI"
)
type element struct {
data interface{}
next *element
}
type EmuStack struct {
type FolderStack struct {
lock *sync.Mutex
head *element
Size int
EmulatorConfig *ActionConfig
RootPath string
}
func (stk *EmuStack) Push(data interface{}) {
func (stk *FolderStack) Push(data interface{}) {
stk.lock.Lock()
element := new(element)
@@ -31,7 +25,7 @@ func (stk *EmuStack) Push(data interface{}) {
stk.lock.Unlock()
}
func (stk *EmuStack) Pop() interface{} {
func (stk *FolderStack) Pop() interface{} {
if stk.head == nil {
return nil
}
@@ -45,21 +39,25 @@ func (stk *EmuStack) Pop() interface{} {
return r
}
func (stk *EmuStack) Length() int {
func (stk *FolderStack) SetRootPath(path string) {
stk.RootPath = path
}
func (stk *FolderStack) Length() int {
return stk.Size
}
func (stk *EmuStack) Last() string {
func (stk *FolderStack) Last() string {
idx := stk.Length() -1
if idx < 0 {
return stk.EmulatorConfig.ROM
return stk.RootPath
}else {
return stk.head.data.(string)
}
}
func NewEmuStack() *EmuStack {
stk := new(EmuStack)
func NewFolderStack() *FolderStack {
stk := new(FolderStack)
stk.lock = &sync.Mutex{}
return stk
}

161
sysgo/UI/hier_list_item.go Normal file
View File

@@ -0,0 +1,161 @@
package UI
import(
"fmt"
"path/filepath"
"strings"
"io/ioutil"
"github.com/veandco/go-sdl2/ttf"
"github.com/cuu/gogame/rect"
"github.com/cuu/gogame/surface"
"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/color"
)
type ListItemIcon struct {
IconItem
}
func NewListItemIcon() *ListItemIcon {
p := &ListItemIcon{}
p.MyType = ICON_TYPES["EXE"]
p.Align = ALIGN["VCenter"]
p.Width = 18
p.Height = 18
return p
}
func (self *ListItemIcon) Draw() {
_,h := self.Parent.Size()
rect_ := rect.Rect(self.PosX,self.PosY+(h-self.Height)/2,self.Width,self.Height)
surface.Blit(self.Parent.GetCanvasHWND(), self.ImgSurf,&rect_,nil)
}
/// [..] [.]
type HierListItem struct {
ListItem
MyType int
Path string
Active bool
Playing bool
}
var HierListItemDefaultHeight = 32
func NewHierListItem() *HierListItem {
p := &HierListItem{}
p.Labels = make(map[string]LabelInterface)
p.Icons = make( map[string]IconItemInterface)
p.Fonts = make(map[string]*ttf.Font)
p.MyType = ICON_TYPES["EXE"]
p.Height = HierListItemDefaultHeight
p.Width = 0
return p
}
func (self *HierListItem) IsFile() bool {
if self.MyType == ICON_TYPES["FILE"] {
return true
}
return false
}
func (self *HierListItem) IsDir() bool {
if self.MyType == ICON_TYPES["DIR"] {
return true
}
return false
}
func (self *HierListItem) Init(text string) {
l := 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 {
self.Path = text
}
label_text := filepath.Base(text)
ext:= filepath.Ext(text)
if ext != "" {
alias_file := strings.Replace(text,ext,"",-1) + ".alias"
if 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 *HierListItem) Draw() {
x,y := self.Labels["Text"].Coord()
_,h := self.Labels["Text"].Size()
if self.Path != "[..]" {
self.Labels["Text"].NewCoord(23,y)
}else {
self.Labels["Text"].NewCoord(3,y)
}
x,y = self.Labels["Text"].Coord()
self.Labels["Text"].NewCoord(x, self.PosY + (self.Height-h)/2)
self.Labels["Text"].Draw()
/*
w,h := self.Parent.Icons["sys"].Size()
if self.IsDir() == true && self.Path != "[..]" {
self.Parent.Icons["sys"].IconIndex = 0
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
self.Parent.Icons["sys"].Draw()
}
if self.IsFile() == true {
self.Parent.Icons["sys"].IconIndex = 1
self.Parent.Icons["sys"].NewCoord(self.PosX+12,self.PosY+(self.Height-h)/2+h/2)
self.Parent.Icons["sys"].Draw()
}
*/
draw.Line(self.Parent.GetCanvasHWND(),&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

@@ -1065,3 +1065,65 @@ func (self *Page) ScrollDown() {
// self.Scrolled -=1
}
}
func (self *Page) FastScrollUp(step int) {
if len(self.MyList) == 0 {
return
}
if step < 1 {
step = 1
}
tmp := self.PsIndex
self.PsIndex -=step
if self.PsIndex < 0 {
self.PsIndex = 0
}
dy := tmp - self.PsIndex
cur_li := self.MyList[self.PsIndex]
x,y := cur_li.Coord()
_,h := cur_li.Size()
if y < 0 {
for i,_ := range self.MyList{
x,y = self.MyList[i].Coord()
_, h = self.MyList[i].Size()
self.MyList[i].NewCoord(x,y + h*dy)
}
//self.Scrolled +=1
}
}
func (self *Page) FastScrollDown(step int) {
if len(self.MyList) == 0 {
return
}
if step < 1 {
step =1
}
tmp := self.PsIndex
self.PsIndex +=step
if self.PsIndex >= len(self.MyList) {
self.PsIndex = len(self.MyList) - 1
}
dy := self.PsIndex - tmp
cur_li := self.MyList[self.PsIndex]
x,y := cur_li.Coord()
_,h := cur_li.Size()
if y+ h > self.Height {
for i,_ := range self.MyList{
x,y = self.MyList[i].Coord()
_, h = self.MyList[i].Size()
self.MyList[i].NewCoord(x,y - h*dy)
}
// self.Scrolled -=1
}
}

View File

@@ -59,6 +59,8 @@ func (self *SkinManager) Init() {
self.Colors["Line"] = &color.Color{169,169,169,255}
self.Colors["TitleBg"] = &color.Color{228,228,228,255}
self.Colors["Active"] = &color.Color{175,90,0,255}
self.Colors["Disabled"] = &color.Color{204,204,204,255}
self.Colors["White"] = &color.Color{255,255,255,255}
self.Colors["Black"] = &color.Color{0,0,0,255}
@@ -97,3 +99,4 @@ func (self *SkinManager) GiveColor(name string) *color.Color {
}
}
var MySkinManager *SkinManager