mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 07:58:51 +01:00
then titlebar and footbar
This commit is contained in:
parent
b06a60ec38
commit
d4e83803d8
@ -7,7 +7,7 @@ import (
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/font"
|
||||
"../sysgo"
|
||||
"../../sysgo"
|
||||
)
|
||||
|
||||
var Fonts map[string]*ttf.Font
|
||||
|
||||
@ -9,6 +9,8 @@ import (
|
||||
"github.com/cuu/gogame/display"
|
||||
"github.com/cuu/gogame/surface"
|
||||
"github.com/cuu/gogame/color"
|
||||
"github.com/cuu/gogame/time"
|
||||
"github.com/cuu/gogame/event"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -146,6 +148,8 @@ func NewMainScreen() *MainScreen {
|
||||
m.Height = Height - FootBar_BarHeight - TitleBar_BarHeight - 1
|
||||
m.MyPageStack = NewPageStack()
|
||||
|
||||
m.MsgBoxFont = Fonts["veramono20"]
|
||||
m.IconFont = Fonts["varela15"]
|
||||
}
|
||||
|
||||
func (self *MainScreen) Init() {
|
||||
@ -157,6 +161,8 @@ func (self *MainScreen) Init() {
|
||||
|
||||
self.SkinManager = NewSkinManager()
|
||||
self.SkinManager.Init()
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) FartherPages() { // right after ReadTheDirIntoPages
|
||||
@ -271,4 +277,138 @@ func (self *MainScreen) IsEmulatorPackage(dirname string ) bool {
|
||||
|
||||
func (self *MainScreen) ReadTheDirIntoPages(_dir string, pglevel int, cur_page PageInterface) {
|
||||
|
||||
if FileExists(_dir) == false && IsDirectory(_dir) == false {
|
||||
return
|
||||
}
|
||||
|
||||
files,err := ioutil.ReadDir(_dir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _,f := range files { // already sorted
|
||||
if IsDirectory( _dir +"/"+f.Name()) {
|
||||
if pglevel == 0 {
|
||||
page := NewPage()
|
||||
page.Name = self.ExtraName(f.Name())
|
||||
self.Pages = append(self.Pages, page)
|
||||
self.ReadTheDirIntoPages(_dir+"/"+f.Name(),pglevel+1, self.Pages[ len(self.Pages) - 1] )
|
||||
}else{ // on cur_page now
|
||||
i2:= self.ExtraName(f.Name())
|
||||
iconitem := NewIconItem()
|
||||
iconitem.AddLabel(i2,self.IconFont)
|
||||
if FileExists( SkinMap(_dir+"/"+i2+".png")) {
|
||||
iconitem.ImageName = SkinMap(_dir+"/"+i2+".png")
|
||||
}else {
|
||||
untitled := NewUntitledIcon()
|
||||
untitled.Init()
|
||||
if len(i2) > 1 {
|
||||
untitled.SetWords(i2[0],i2[1])
|
||||
}else if len(i2) == 1 {
|
||||
untitled.SetWords(i2[0],i2[0])
|
||||
}else {
|
||||
untitled.SetWords("G","s")
|
||||
}
|
||||
iconitem.ImgSurf = untitled.Surface()
|
||||
iconitem.ImageName = ""
|
||||
}
|
||||
|
||||
if self.IsPluginPackage(_dir+"/"+f.Name()) {
|
||||
iconitem.MyType = ICON_TYPES["FUNC"]
|
||||
iconitem.CmdPath = f.Name()
|
||||
cur_page.AppendIcon(iconitem)
|
||||
//Init it
|
||||
}else {
|
||||
iconitem.MyType = ICON_TYPES["DIR"]
|
||||
linkpage := NewPage()
|
||||
linkpage.Name = i2
|
||||
iconitem.LinkPage = linkpage
|
||||
cur_page.AppendIcon(iconitem)
|
||||
self.ReadTheDirIntoPages(_dir+"/"+f.Name(),pglevel+1, iconitem.LinkPage)
|
||||
}
|
||||
|
||||
}
|
||||
} else if IsAFile(_dir+"/"+f.Name()) && (pglevel > 0) {
|
||||
if strings.HasSuffix(strings.ToLower(f.Name()),IconExt) {
|
||||
i2 := self.ExtraName(f.Name())
|
||||
iconitem = NewIconItem()
|
||||
iconitem.CmdPath = _dir+"/"+f.Name()
|
||||
MakeExecutable( iconitem.CmdPath )
|
||||
iconitem.MyType = ICON_TYPES["EXE"]
|
||||
if FileExists( SkinMap( _dir+"/"+ ReplaceSuffix(i2,"png"))) {
|
||||
iconitem.ImageName = SkinMap( _dir+"/"+ ReplaceSuffix(i2,"png"))
|
||||
}else {
|
||||
untitled:= NewUntitledIcon()
|
||||
untitled.Init()
|
||||
if len(i2) > 1 {
|
||||
untitled.SetWords(i2[0],i2[1])
|
||||
}else if len(i2) == 1 {
|
||||
untitled.SetWords(i2[0],i2[0])
|
||||
}else {
|
||||
untitled.SetWords("G","s")
|
||||
}
|
||||
iconitem.ImgSurf = untitled.Surface()
|
||||
iconitem.ImageName = ""
|
||||
}
|
||||
|
||||
iconitem.AddLabel(strings.Split(i2,".")[0], self.IconFont)
|
||||
iconfont.LinkPage = nil
|
||||
cur_page.AppendIcon(iconitem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (self *MainScreen) RunEXE( cmdpath string) {
|
||||
self.DrawRun()
|
||||
self.SwapAndShow()
|
||||
|
||||
time.Delay(1000)
|
||||
|
||||
cmdpath = strings.Trim(cmdpath," ")
|
||||
|
||||
cmdpath = CmdClean(cmdpath)
|
||||
|
||||
event.Post(event.RUNEVT,cmdpath)
|
||||
|
||||
}
|
||||
|
||||
func (self *MainScreen) OnExitCb() {
|
||||
self.CurrentPage.OnExitCb()
|
||||
}
|
||||
|
||||
func (self *MainScreen) KeyDown(ev *event.Event) {
|
||||
|
||||
if ev.Data["Key"] == "T" {
|
||||
self.DrawRun()
|
||||
self.SwapAndShow()
|
||||
return
|
||||
}
|
||||
|
||||
if ev.Data["Key"] == "Space" {
|
||||
self.Draw()
|
||||
self.SwapAndShow()
|
||||
}
|
||||
|
||||
self.CurrentPage.KeyDown(ev)
|
||||
}
|
||||
|
||||
|
||||
func (self *MainScreen) DrawRun() {
|
||||
self.MsgBox.SetText("Launching....")
|
||||
self.MsgBox.Draw()
|
||||
}
|
||||
|
||||
func (self *MainScreen) Draw() {
|
||||
self.CurrentPage.Draw()
|
||||
if self.TitleBar != nil {
|
||||
self.TitleBar.Draw( self.CurrentPage.GetName())
|
||||
}
|
||||
|
||||
if self.FootBar != nil {
|
||||
self.FootBar.SetLabelTexts( self.CurrentPage.GetFootMsg())
|
||||
self.FootBar.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +158,9 @@ type PageInterface interface {
|
||||
// UpdateIconNumbers
|
||||
// GetIconNumbers
|
||||
// SetOnShow
|
||||
|
||||
|
||||
// AppendIcon
|
||||
// GetName()
|
||||
// GetFootMsg
|
||||
|
||||
}
|
||||
|
||||
@ -764,6 +765,10 @@ func (self *Page) ClearCanvas() {
|
||||
surface.Fill(self.CanvasHWND, self.Screen.SkinManager.GiveColor("White"))
|
||||
}
|
||||
|
||||
func (self *Page) AppendIcon( it interface{} ) {
|
||||
self.Icons = append(self.Icons, it)
|
||||
}
|
||||
|
||||
func (self *Page) ClearIcons() {
|
||||
for i:=0;i<self.IconNumbers; i++ {
|
||||
self.Icons[i].Clear()
|
||||
@ -830,6 +835,7 @@ func (self *Page) KeyDown( ev *event.Event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (self *Page) OnLoadCb() {
|
||||
|
||||
}
|
||||
@ -838,6 +844,10 @@ func (self *Page) OnReturnBackCb() {
|
||||
|
||||
}
|
||||
|
||||
func (self *Page) OnExitCb() {
|
||||
|
||||
}
|
||||
|
||||
func (self *Page) Draw() {
|
||||
self.ClearCanvas()
|
||||
self.DrawIcons()
|
||||
|
||||
@ -1,16 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"../../UI"
|
||||
"../../../UI"
|
||||
)
|
||||
|
||||
|
||||
type HelloWorldPlugin struct {
|
||||
UI.Plugin
|
||||
|
||||
type HelloWorldPage struct {
|
||||
UI.Page
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type HelloWorldPlugin struct {
|
||||
UI.Plugin
|
||||
}
|
||||
|
||||
|
||||
func (self *HelloWorldPlugin) Init( main_screen *UI.MainScreen ) {
|
||||
|
||||
}
|
||||
|
||||
func (self *HelloWorldPlugin) Run( main_screen *UI.MainScreen ) {
|
||||
|
||||
}
|
||||
|
||||
var APIOBJ HelloWorldPlugin
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/cuu/gogame/color"
|
||||
|
||||
"../sysgo"
|
||||
"../../sysgo"
|
||||
)
|
||||
|
||||
type SkinManager struct {
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/itchyny/volume-go"
|
||||
|
||||
"../sysgo"
|
||||
"../../sysgo"
|
||||
)
|
||||
|
||||
|
||||
|
||||
72
sysgo/UI/untitled_icon.go
Normal file
72
sysgo/UI/untitled_icon.go
Normal file
@ -0,0 +1,72 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/color"
|
||||
)
|
||||
|
||||
|
||||
type UntitledIcon struct {
|
||||
|
||||
PosX int
|
||||
PosY int
|
||||
Width int
|
||||
Height int
|
||||
Words [2]string
|
||||
FontObj *ttf.Font
|
||||
BG *sdl.Surface
|
||||
Color *color.Color
|
||||
BlankPng string
|
||||
Text *sdl.Surface
|
||||
}
|
||||
|
||||
func NewUntitledIcon() *UntitledIcon {
|
||||
u := &UntitledIcon{}
|
||||
u.Width = 80
|
||||
u.Height = 80
|
||||
u.Words = [2]string{"G","s"}
|
||||
|
||||
u.FontObj = Fonts["varela40"]
|
||||
|
||||
u.Color = &color.Color{83,83,83,255}
|
||||
|
||||
u.BlankPng = SkinMap("gameshell/blank.png")
|
||||
}
|
||||
|
||||
func (self *UntitledIcon) Init() {
|
||||
self.BG = image.Load(self.BlankPng)
|
||||
)
|
||||
|
||||
func (self *UntitledIcon) SetWords( TwoWords ...string) {
|
||||
if len(TwoWords) == 1 {
|
||||
self.Words[0] = strings.ToUpper(TwoWords[0])
|
||||
}
|
||||
if len(TwoWords) == 2 {
|
||||
self.Words[0] = strings.ToUpper( TwoWords[0])
|
||||
self.Words[1] = strings.ToLower( TwoWords[1] )
|
||||
|
||||
self.Text = font.Render(self.FontObj, strings.Join(self.Words,""),true,self.Color, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *UntitledIcon) Draw() {
|
||||
if self.BG != nil {
|
||||
w_ := self.Text.W
|
||||
h_ := self.Text.H
|
||||
|
||||
surface.Blit(self.BG,self.Text,draw.MidRect(self.Width/2, self.Height/2,w_,h_, self.Width, self.Height),nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *UntitledIcon) Surface() *sdl.Surface {
|
||||
self.Draw()
|
||||
return self.BG
|
||||
}
|
||||
|
||||
|
||||
|
||||
71
sysgo/UI/util_funcs.go
Normal file
71
sysgo/UI/util_funcs.go
Normal file
@ -0,0 +1,71 @@
|
||||
package UI
|
||||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/cuu/gogame/display"
|
||||
|
||||
)
|
||||
|
||||
func CmdClean(cmdpath string) string {
|
||||
spchars := "\\`$();|{}&'\"*?<>[]!^~-#\n\r "
|
||||
for _,v:= range spchars {
|
||||
cmdpath = strings.Replace(cmdpath,string(v),"\\"+string(v),-1)
|
||||
}
|
||||
return cmdpath
|
||||
}
|
||||
|
||||
func FileExists(name string) bool {
|
||||
if _, err := os.Stat(name ); err == nil {
|
||||
return true
|
||||
}else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func IsDirectory(path string) bool {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}else {
|
||||
return fileInfo.IsDir()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func IsAFile(path string) bool {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}else {
|
||||
return fileInfo.Mode().IsRegular()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func MakeExecutable(path string) {
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
log.Fatalf("os.Stat %s failed", path)
|
||||
return
|
||||
}
|
||||
mode := fileInfo.Mode()
|
||||
mode |= (mode & 0444) >> 2
|
||||
os.Chmod(path,mode)
|
||||
}
|
||||
|
||||
func ReplaceSuffix(orig_file_str string, new_ext string) string {
|
||||
orig_ext := filepath.Ext(orig_file_str)
|
||||
if orig_ext!= "" {
|
||||
las_pos := strings.LastIndex(orig_file_str,".")
|
||||
return orig_file_str[0:las_pos]+"."+new_ext
|
||||
}
|
||||
return orig_file_str // failed just return back where it came
|
||||
}
|
||||
|
||||
func SwapAndShow() {
|
||||
display.Flip()
|
||||
}
|
||||
15
test.go
15
test.go
@ -14,7 +14,8 @@ import (
|
||||
"github.com/cuu/gogame/rect"
|
||||
"github.com/cuu/gogame/draw"
|
||||
"github.com/cuu/gogame/image"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/font"
|
||||
"github.com/cuu/gogame/time"
|
||||
)
|
||||
|
||||
func run() int {
|
||||
@ -90,7 +91,10 @@ func run() int {
|
||||
running = false
|
||||
break
|
||||
}
|
||||
|
||||
if ev.Type == event.USEREVENT {
|
||||
|
||||
fmt.Println(ev.Data["Msg"])
|
||||
}
|
||||
if ev.Type == event.KEYDOWN {
|
||||
fmt.Println(ev)
|
||||
if ev.Data["Key"] == "Q" {
|
||||
@ -99,6 +103,12 @@ func run() int {
|
||||
if ev.Data["Key"] == "Escape" {
|
||||
return 0
|
||||
}
|
||||
if ev.Data["Key"] == "T" {
|
||||
time.Delay(1000)
|
||||
}
|
||||
if ev.Data["Key"] == "P" {
|
||||
event.Post(event.RUNEVT,"GODEBUG=cgocheck=0 sucks") // just id and string, simpify the stuff
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,6 +119,7 @@ func main() {
|
||||
var exitcode int
|
||||
|
||||
os.Setenv("SDL_VIDEO_CENTERED","1")
|
||||
os.Setenv("GODEBUG", "cgocheck=0")
|
||||
|
||||
sdl.Main(func() {
|
||||
exitcode = run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user