game_page.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package Pico8
  2. import (
  3. "fmt"
  4. "github.com/cuu/gogame/event"
  5. "github.com/cuu/gogame/rect"
  6. "github.com/cuu/gogame/surface"
  7. "github.com/veandco/go-sdl2/ttf"
  8. "github.com/cuu/gogame/color"
  9. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  10. )
  11. type GamePage struct {
  12. UI.Page
  13. ListFontObj *ttf.Font
  14. URLColor *color.Color
  15. TextColor *color.Color
  16. Labels map[string]UI.LabelInterface
  17. Icons map[string]UI.IconItemInterface
  18. MsgBox *UI.MessageBox
  19. NotFound bool
  20. Pkg *UI.CommercialSoftwarePackage
  21. }
  22. func NewGamePage() *GamePage {
  23. p := &GamePage{}
  24. p.PageIconMargin = 20
  25. p.SelectedIconTopOffset = 20
  26. p.EasingDur = 10
  27. p.Align = UI.ALIGN["SLeft"]
  28. p.FootMsg = [5]string{"Nav.", "", "", "Back", ""}
  29. p.URLColor = UI.MySkinManager.GiveColor("URL")
  30. p.TextColor = UI.MySkinManager.GiveColor("Text")
  31. p.ListFontObj = UI.MyLangManager.TrFont("varela18")
  32. //p.Labels = make(map[string]UI.LabelInterface)
  33. //p.Icons = make(map[string]UI.IconItemInterface)
  34. p.NotFound = true
  35. p.Pkg = UI.NewCommercialSoftwarePackage("/home/cpi/games/PICO-8/pico-8/pico8_dyn","/home/cpi/launchergo/Menu/GameShell/50_Pico8/")
  36. return p
  37. }
  38. func (self *GamePage) OnLoadCb() {
  39. self.PosY = 0
  40. if self.Pkg.IsInstalled() {
  41. self.Pkg.RunSetup()
  42. fmt.Println("Run pico8")
  43. self.MsgBox.SetText("Running Pico8")
  44. self.Screen.RunEXE(self.Pkg.GetRunScript())
  45. }else{
  46. self.MsgBox.SetText("Please purchase the PICO-8 and copy it to the \"~/games/PICO-8\"")
  47. }
  48. fmt.Println("GamePage OnLoadCb")
  49. }
  50. func (self *GamePage) Init() {
  51. if self.Screen == nil {
  52. panic("No Screen")
  53. }
  54. if self.Screen.CanvasHWND != nil && self.CanvasHWND == nil {
  55. self.HWND = self.Screen.CanvasHWND
  56. self.CanvasHWND = surface.Surface(self.Screen.Width, self.Screen.Height)
  57. }
  58. self.PosX = self.Index * self.Screen.Width
  59. self.Width = self.Screen.Width
  60. self.Height = self.Screen.Height
  61. self.MsgBox = UI.NewMessageBox()
  62. self.MsgBox.Parent = self.CanvasHWND
  63. self.MsgBox.Init("Please purchase the PICO-8 and copy it to the \"~/games/PICO-8\"",self.ListFontObj,nil,self.Width,self.Height)
  64. self.Pkg.Init()
  65. }
  66. func (self *GamePage) KeyDown(ev *event.Event) {
  67. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  68. self.ReturnToUpLevelPage()
  69. self.Screen.Refresh()
  70. }
  71. return
  72. }
  73. func (self *GamePage) Draw() {
  74. self.ClearCanvas()
  75. self.MsgBox.Draw()
  76. if self.HWND != nil {
  77. surface.Fill(self.HWND, UI.MySkinManager.GiveColor("white"))
  78. rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
  79. surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
  80. }
  81. }