rom_so_confirm_page.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package Emulator
  2. import (
  3. "fmt"
  4. //"strconv"
  5. "strings"
  6. "path/filepath"
  7. "github.com/clockworkpi/LauncherGoDev/sysgo"
  8. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  9. "github.com/cuu/gogame/event"
  10. )
  11. type RomSoConfirmPage struct {
  12. UI.ConfirmPage
  13. Parent EmulatorPageInterface
  14. DownloadPage *UI.DownloadProcessPage
  15. }
  16. func NewRomSoConfirmPage() *RomSoConfirmPage {
  17. p := &RomSoConfirmPage{}
  18. p.PageIconMargin = 20
  19. p.SelectedIconTopOffset = 20
  20. p.EasingDur = 10
  21. p.Align = UI.ALIGN["SLeft"]
  22. p.ListFont = UI.Fonts["veramono18"]
  23. p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
  24. p.ConfirmText = "Do you want to setup this game engine automatically?"
  25. return p
  26. }
  27. func (self *RomSoConfirmPage) Init() {
  28. self.PosX = self.Index * self.Screen.Width
  29. self.Width = self.Screen.Width
  30. self.Height = self.Screen.Height
  31. self.CanvasHWND = self.Screen.CanvasHWND
  32. li := UI.NewMultiLabel()
  33. li.SetCanvasHWND(self.CanvasHWND)
  34. li.Width = 160
  35. li.Init(self.ConfirmText, self.ListFont, nil)
  36. li.PosX = (self.Width - li.Width) / 2
  37. li.PosY = (self.Height - li.Height) / 2
  38. self.BGPosX = li.PosX - 20
  39. self.BGPosY = li.PosY - 20
  40. self.BGWidth = li.Width + 40
  41. self.BGHeight = li.Height + 40
  42. self.MyList = append(self.MyList, li)
  43. }
  44. func (self *RomSoConfirmPage) SnapMsg(msg string) {
  45. self.MyList[0].SetText(msg)
  46. self.Screen.Refresh()
  47. self.MyList[0].SetText(self.ConfirmText)
  48. }
  49. func (self *RomSoConfirmPage) OnReturnBackCb() {
  50. self.ReturnToUpLevelPage()
  51. self.Screen.Refresh()
  52. }
  53. func (self *RomSoConfirmPage) KeyDown(ev *event.Event) {
  54. if ev.Data["Key"] == UI.CurKeys["Menu"] || ev.Data["Key"] == UI.CurKeys["A"] {
  55. self.ReturnToUpLevelPage()
  56. self.Screen.Refresh()
  57. }
  58. if ev.Data["Key"] == UI.CurKeys["B"] {
  59. bat := UI.CheckBattery()
  60. if bat < 5 && bat >= 0 {
  61. self.SnapMsg("Battery must over 5%")
  62. } else { // -1 or something else,
  63. if self.DownloadPage == nil {
  64. self.DownloadPage = UI.NewDownloadProcessPage()
  65. self.DownloadPage.Screen = self.Screen
  66. self.DownloadPage.Name = "Downloading"
  67. self.DownloadPage.Init()
  68. }
  69. self.Screen.PushPage(self.DownloadPage)
  70. self.Screen.Refresh()
  71. ec := self.Parent.GetEmulatorConfig()
  72. if sysgo.CurKeySet == "PC" {
  73. so_url := ec.SO_URL
  74. so_url = strings.Replace(so_url, "armhf", "x86_64", -1)
  75. fmt.Println(so_url)
  76. self.DownloadPage.StartDownload(so_url, filepath.Dir(ec.ROM_SO))
  77. } else {
  78. so_url := ec.SO_URL
  79. go self.DownloadPage.StartDownload(so_url, filepath.Dir(ec.ROM_SO))
  80. }
  81. }
  82. }
  83. }
  84. func (self *RomSoConfirmPage) Draw() {
  85. self.ClearCanvas()
  86. self.DrawBG()
  87. for _, v := range self.MyList {
  88. v.Draw()
  89. }
  90. }