mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2026-09-06 13:34:36 +02:00
go fmt ./...
This commit is contained in:
@@ -3,68 +3,68 @@ package UI
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"log"
|
||||
"strings"
|
||||
//"encoding/json"
|
||||
"path/filepath"
|
||||
gotime "time"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
"path/filepath"
|
||||
gotime "time"
|
||||
|
||||
"github.com/cuu/gogame/display"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/display"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/time"
|
||||
|
||||
|
||||
"github.com/cuu/gogame/event"
|
||||
|
||||
|
||||
"github.com/clockworkpi/LauncherGoDev/sysgo"
|
||||
)
|
||||
|
||||
//eg: MainScreen
|
||||
type ScreenInterface interface {
|
||||
AppendPage( pg PageInterface )
|
||||
ClearCanvas()
|
||||
CurPage() PageInterface
|
||||
Draw()
|
||||
ExtraName(name string) string
|
||||
FartherPages()
|
||||
Init()
|
||||
IsEmulatorPackage(dirname string ) bool
|
||||
IsExecPackage(dirname string ) bool
|
||||
IsPluginPackage(dirname string ) bool
|
||||
KeyDown(ev *event.Event)
|
||||
OnExitCb()
|
||||
PushCurPage()
|
||||
PushPage( pg PageInterface)
|
||||
RunEXE( cmdpath string)
|
||||
SetCurPage( pg PageInterface)
|
||||
SwapAndShow()
|
||||
AppendPage(pg PageInterface)
|
||||
ClearCanvas()
|
||||
CurPage() PageInterface
|
||||
Draw()
|
||||
ExtraName(name string) string
|
||||
FartherPages()
|
||||
Init()
|
||||
IsEmulatorPackage(dirname string) bool
|
||||
IsExecPackage(dirname string) bool
|
||||
IsPluginPackage(dirname string) bool
|
||||
KeyDown(ev *event.Event)
|
||||
OnExitCb()
|
||||
PushCurPage()
|
||||
PushPage(pg PageInterface)
|
||||
RunEXE(cmdpath string)
|
||||
SetCurPage(pg PageInterface)
|
||||
SwapAndShow()
|
||||
IsWifiConnectedNow()
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
NAME string `json:"NAME"` // plugin name,default could be the same as Plugin Folder's name
|
||||
NAME string `json:"NAME"` // plugin name,default could be the same as Plugin Folder's name
|
||||
SO_FILE string `json:"SO_FILE"`
|
||||
|
||||
}
|
||||
|
||||
type MessageBox struct {
|
||||
Label
|
||||
Parent *MainScreen
|
||||
HWND *sdl.Surface
|
||||
HWND *sdl.Surface
|
||||
}
|
||||
|
||||
func NewMessageBox() *MessageBox {
|
||||
m := &MessageBox{}
|
||||
m.Color = &color.Color{83,83,83,255}
|
||||
|
||||
m.Color = &color.Color{83, 83, 83, 255}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (self *MessageBox) Init( text string, font_obj *ttf.Font, col *color.Color) {
|
||||
func (self *MessageBox) Init(text string, font_obj *ttf.Font, col *color.Color) {
|
||||
if col != nil {
|
||||
self.Color = col
|
||||
}
|
||||
@@ -76,21 +76,21 @@ func (self *MessageBox) Init( text string, font_obj *ttf.Font, col *color.Color)
|
||||
self.Height = 0
|
||||
|
||||
self.CanvasHWND = surface.Surface(self.Parent.Width, self.Parent.Height)
|
||||
self.HWND = self.Parent.CanvasHWND
|
||||
|
||||
self.HWND = self.Parent.CanvasHWND
|
||||
|
||||
}
|
||||
|
||||
func (self *MessageBox) SetText( text string) {
|
||||
func (self *MessageBox) SetText(text string) {
|
||||
self.Text = text
|
||||
}
|
||||
|
||||
func (self *MessageBox) Draw() {
|
||||
self.Width = 0
|
||||
self.Height = 0
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255,255,255,255} )
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255, 255, 255, 255})
|
||||
|
||||
words := strings.Split(self.Text," ")
|
||||
space,_ := font.Size(self.FontObj," ")
|
||||
words := strings.Split(self.Text, " ")
|
||||
space, _ := font.Size(self.FontObj, " ")
|
||||
|
||||
max_width := self.Parent.Width - 40
|
||||
x := 0
|
||||
@@ -99,8 +99,8 @@ func (self *MessageBox) Draw() {
|
||||
row_total_width := 0
|
||||
lines := 0
|
||||
|
||||
for _,word := range words {
|
||||
word_surface := font.Render( self.FontObj, word, true, self.Color,nil)
|
||||
for _, word := range words {
|
||||
word_surface := font.Render(self.FontObj, word, true, self.Color, nil)
|
||||
word_width := int(word_surface.W)
|
||||
word_height := int(word_surface.H)
|
||||
row_total_width += word_width
|
||||
@@ -108,27 +108,27 @@ func (self *MessageBox) Draw() {
|
||||
lines += word_height
|
||||
}
|
||||
|
||||
if (row_total_width + space ) >= max_width {
|
||||
if (row_total_width + space) >= max_width {
|
||||
x = 0
|
||||
y += word_height
|
||||
row_total_width = word_width
|
||||
lines+=word_height
|
||||
lines += word_height
|
||||
}
|
||||
|
||||
dest_rect := rect.Rect(x,y, word_width,word_height)
|
||||
surface.Blit(self.CanvasHWND, word_surface, &dest_rect,nil)
|
||||
word_surface.Free()
|
||||
dest_rect := rect.Rect(x, y, word_width, word_height)
|
||||
surface.Blit(self.CanvasHWND, word_surface, &dest_rect, nil)
|
||||
word_surface.Free()
|
||||
if len(words) == 1 {
|
||||
x+=word_width
|
||||
x += word_width
|
||||
} else {
|
||||
x += word_width+space
|
||||
x += word_width + space
|
||||
}
|
||||
|
||||
|
||||
if x > self.Width {
|
||||
self.Width = x
|
||||
}
|
||||
|
||||
if lines >= self.Parent.Height - 40 {
|
||||
if lines >= self.Parent.Height-40 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -137,31 +137,30 @@ func (self *MessageBox) Draw() {
|
||||
|
||||
padding := 5
|
||||
x = (self.Parent.Width - self.Width) / 2
|
||||
y = (self.Parent.Height - self.Height) /2
|
||||
y = (self.Parent.Height - self.Height) / 2
|
||||
|
||||
rect_ := rect.Rect(x-padding, y-padding, self.Width+padding*2, self.Height+padding*2)
|
||||
|
||||
rect_ := rect.Rect(x-padding,y-padding, self.Width+padding*2, self.Height+padding*2)
|
||||
|
||||
if self.HWND != nil {
|
||||
|
||||
draw.Rect(self.HWND , &color.Color{255,255,255,255},&rect_,0)
|
||||
|
||||
rect__ := draw.MidRect(self.Parent.Width/2, self.Parent.Height/2,self.Width,self.Height,Width,Height)
|
||||
|
||||
dest_rect := rect.Rect(0,0,self.Width,self.Height)
|
||||
|
||||
|
||||
draw.Rect(self.HWND, &color.Color{255, 255, 255, 255}, &rect_, 0)
|
||||
|
||||
rect__ := draw.MidRect(self.Parent.Width/2, self.Parent.Height/2, self.Width, self.Height, Width, Height)
|
||||
|
||||
dest_rect := rect.Rect(0, 0, self.Width, self.Height)
|
||||
|
||||
surface.Blit(self.HWND, self.CanvasHWND, rect__, &dest_rect)
|
||||
|
||||
draw.Rect(self.HWND , &color.Color{0,0,0,255},&rect_,1)
|
||||
|
||||
|
||||
draw.Rect(self.HWND, &color.Color{0, 0, 0, 255}, &rect_, 1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
type MainScreen struct {
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
PageMax int
|
||||
Widget
|
||||
Pages []PageInterface
|
||||
PageMax int
|
||||
PageIndex int
|
||||
|
||||
MyPageStack *PageStack
|
||||
@@ -174,71 +173,68 @@ type MainScreen struct {
|
||||
MsgBoxFont *ttf.Font
|
||||
IconFont *ttf.Font
|
||||
SkinManager *SkinManager
|
||||
|
||||
CounterScreen *CounterScreen
|
||||
Closed bool
|
||||
|
||||
UIPluginList []*UIPlugin
|
||||
|
||||
LastKey string
|
||||
LastKeyDown gotime.Time
|
||||
}
|
||||
|
||||
CounterScreen *CounterScreen
|
||||
Closed bool
|
||||
|
||||
UIPluginList []*UIPlugin
|
||||
|
||||
LastKey string
|
||||
LastKeyDown gotime.Time
|
||||
}
|
||||
|
||||
func NewMainScreen() *MainScreen {
|
||||
m := &MainScreen{}
|
||||
|
||||
m.PosY = TitleBar_BarHeight+1
|
||||
|
||||
m.PosY = TitleBar_BarHeight + 1
|
||||
m.Width = Width
|
||||
m.Height = Height - FootBar_BarHeight - TitleBar_BarHeight - 1
|
||||
m.MyPageStack = NewPageStack()
|
||||
|
||||
|
||||
m.MsgBoxFont = Fonts["veramono20"]
|
||||
m.IconFont = Fonts["varela15"]
|
||||
m.Closed = false
|
||||
m.IconFont = Fonts["varela15"]
|
||||
m.Closed = false
|
||||
return m
|
||||
}
|
||||
|
||||
func (self *MainScreen) Init() {
|
||||
self.CanvasHWND = surface.Surface(self.Width,self.Height)
|
||||
|
||||
self.MsgBox = NewMessageBox()
|
||||
self.CanvasHWND = surface.Surface(self.Width, self.Height)
|
||||
|
||||
self.MsgBox = NewMessageBox()
|
||||
self.MsgBox.Parent = self
|
||||
self.MsgBox.Init(" ", self.MsgBoxFont, &color.Color{83,83,83,255})
|
||||
self.MsgBox.Init(" ", self.MsgBoxFont, &color.Color{83, 83, 83, 255})
|
||||
|
||||
self.SkinManager = NewSkinManager()
|
||||
self.SkinManager.Init()
|
||||
|
||||
self.CounterScreen = NewCounterScreen()
|
||||
self.CounterScreen.HWND = self.HWND
|
||||
self.CounterScreen.Init()
|
||||
|
||||
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
|
||||
|
||||
self.CounterScreen = NewCounterScreen()
|
||||
self.CounterScreen.HWND = self.HWND
|
||||
self.CounterScreen.Init()
|
||||
|
||||
//self.GenList() // load predefined plugin list,ready to be injected ,or ,as a .so for dynamic loading
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
|
||||
self.PageMax = len(self.Pages)
|
||||
|
||||
for i:=0;i< self.PageMax; i++ {
|
||||
for i := 0; i < self.PageMax; i++ {
|
||||
self.Pages[i].SetIndex(i)
|
||||
self.Pages[i].SetCanvasHWND(self.CanvasHWND)
|
||||
self.Pages[i].UpdateIconNumbers() // IconNumbers always == len(Pages[i].Icons)
|
||||
self.Pages[i].SetScreen(self)
|
||||
self.Pages[i].Adjust()
|
||||
|
||||
|
||||
if self.Pages[i].GetIconNumbers() > 1 {
|
||||
self.Pages[i].SetPsIndex(1)
|
||||
self.Pages[i].SetIconIndex( 1 )
|
||||
self.Pages[i].SetIconIndex(1)
|
||||
}
|
||||
}
|
||||
|
||||
self.CurrentPage = self.Pages[ self.PageIndex ]
|
||||
self.CurrentPage = self.Pages[self.PageIndex]
|
||||
self.CurrentPage.SetOnShow(true)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (self *MainScreen) CurPage() PageInterface {
|
||||
return self.CurrentPage
|
||||
}
|
||||
@@ -247,28 +243,28 @@ func (self *MainScreen) PushCurPage() {
|
||||
self.MyPageStack.Push(self.CurrentPage)
|
||||
}
|
||||
|
||||
func (self *MainScreen) SetCurPage( pg PageInterface) {
|
||||
func (self *MainScreen) SetCurPage(pg PageInterface) {
|
||||
self.CurrentPage = pg
|
||||
pg.OnLoadCb()
|
||||
}
|
||||
|
||||
func (self *MainScreen) PushPage( pg PageInterface) {
|
||||
func (self *MainScreen) PushPage(pg PageInterface) {
|
||||
self.PushCurPage()
|
||||
self.SetCurPage(pg)
|
||||
}
|
||||
|
||||
func (self *MainScreen) AppendPage( pg PageInterface ) {
|
||||
self.Pages = append(self.Pages,pg)
|
||||
func (self *MainScreen) AppendPage(pg PageInterface) {
|
||||
self.Pages = append(self.Pages, pg)
|
||||
}
|
||||
|
||||
func (self *MainScreen) ClearCanvas() {
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255,255,255,255} )
|
||||
surface.Fill(self.CanvasHWND, &color.Color{255, 255, 255, 255})
|
||||
}
|
||||
|
||||
func (self *MainScreen) SwapAndShow() {
|
||||
if self.HWND != nil {
|
||||
rect_ := rect.Rect( self.PosX,self.PosY,self.Width,self.Height)
|
||||
surface.Blit(self.HWND,self.CanvasHWND,&rect_, nil)
|
||||
rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
|
||||
surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
|
||||
}
|
||||
|
||||
display.Flip()
|
||||
@@ -276,50 +272,49 @@ func (self *MainScreen) SwapAndShow() {
|
||||
|
||||
func (self *MainScreen) ExtraName(name string) string {
|
||||
|
||||
parts := strings.Split(name,"_")
|
||||
if len(parts) > 1 {
|
||||
parts := strings.Split(name, "_")
|
||||
if len(parts) > 1 {
|
||||
return parts[1]
|
||||
}else if len(parts) == 1 {
|
||||
} else if len(parts) == 1 {
|
||||
return parts[0]
|
||||
}else {
|
||||
} else {
|
||||
return name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ExecPackage is all-in-one folder ,Name.sh,Name.png,etc
|
||||
func (self *MainScreen) IsExecPackage(dirname string ) bool {
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
func (self *MainScreen) IsExecPackage(dirname string) bool {
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
bname := filepath.Base(dirname)
|
||||
bname = self.ExtraName(bname)
|
||||
|
||||
for _,v := range files {
|
||||
if v.Name() == bname+".sh" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
bname := filepath.Base(dirname)
|
||||
bname = self.ExtraName(bname)
|
||||
|
||||
for _, v := range files {
|
||||
if v.Name() == bname+".sh" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsPluginPackage(dirname string ) bool {
|
||||
func (self *MainScreen) IsPluginPackage(dirname string) bool {
|
||||
ret := false
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _,f := range files {
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
//pass
|
||||
}else {
|
||||
if strings.HasSuffix(f.Name(),Plugin_flag) == true {
|
||||
} else {
|
||||
if strings.HasSuffix(f.Name(), Plugin_flag) == true {
|
||||
ret = true
|
||||
break
|
||||
}
|
||||
@@ -329,33 +324,33 @@ func (self *MainScreen) IsPluginPackage(dirname string ) bool {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsEmulatorPackage(dirname string ) bool {
|
||||
func (self *MainScreen) IsEmulatorPackage(dirname string) bool {
|
||||
ret := false
|
||||
files,err := ioutil.ReadDir(dirname)
|
||||
files, err := ioutil.ReadDir(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _,f := range files {
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
//pass
|
||||
}else {
|
||||
if strings.HasSuffix(f.Name(),Emulator_flag) == true {
|
||||
} else {
|
||||
if strings.HasSuffix(f.Name(), Emulator_flag) == true {
|
||||
ret = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *MainScreen) IsWifiConnectedNow() bool {
|
||||
|
||||
cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out)<6 {
|
||||
|
||||
cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
|
||||
out := System(cli)
|
||||
if len(out) < 6 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -363,25 +358,23 @@ func (self *MainScreen) IsWifiConnectedNow() bool {
|
||||
|
||||
func (self *MainScreen) GetWirelessIP() string {
|
||||
|
||||
cli := fmt.Sprintf( "ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'",sysgo.WifiDev)
|
||||
out := SystemTrim(cli)
|
||||
cli := fmt.Sprintf("ip -4 addr show %s | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'", sysgo.WifiDev)
|
||||
out := SystemTrim(cli)
|
||||
|
||||
|
||||
return out
|
||||
return out
|
||||
}
|
||||
|
||||
func (self *MainScreen) RunEXE( cmdpath string) {
|
||||
func (self *MainScreen) RunEXE(cmdpath string) {
|
||||
self.DrawRun()
|
||||
self.SwapAndShow()
|
||||
|
||||
|
||||
time.BlockDelay(1000)
|
||||
|
||||
cmdpath = strings.Trim(cmdpath," ")
|
||||
cmdpath = strings.Trim(cmdpath, " ")
|
||||
cmdpath = CmdClean(cmdpath)
|
||||
|
||||
event.Post(RUNEVT,cmdpath)
|
||||
|
||||
|
||||
event.Post(RUNEVT, cmdpath)
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) OnExitCb() {
|
||||
@@ -399,13 +392,12 @@ func (self *MainScreen) KeyDown(ev *event.Event) {
|
||||
if ev.Data["Key"] == "Space" {
|
||||
self.Draw()
|
||||
self.SwapAndShow()
|
||||
}
|
||||
}
|
||||
|
||||
self.CurrentPage.KeyDown(ev)
|
||||
self.LastKey = ev.Data["Key"]
|
||||
|
||||
}
|
||||
self.LastKey = ev.Data["Key"]
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) DrawRun() {
|
||||
self.MsgBox.SetText("Launching....")
|
||||
@@ -416,14 +408,14 @@ func (self *MainScreen) Draw() {
|
||||
if self.CurrentPage != nil {
|
||||
self.CurrentPage.Draw()
|
||||
}
|
||||
|
||||
|
||||
if self.TitleBar != nil {
|
||||
//every plugin_init should not do any Draw actions since CurrentPage might be nil at that time
|
||||
self.TitleBar.Draw( self.CurrentPage.GetName())
|
||||
//every plugin_init should not do any Draw actions since CurrentPage might be nil at that time
|
||||
self.TitleBar.Draw(self.CurrentPage.GetName())
|
||||
}
|
||||
|
||||
if self.FootBar != nil {
|
||||
self.FootBar.SetLabelTexts( self.CurrentPage.GetFootMsg())
|
||||
self.FootBar.SetLabelTexts(self.CurrentPage.GetFootMsg())
|
||||
self.FootBar.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user