airplane_page.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package Airplane
  2. import (
  3. //"fmt"
  4. //"io/ioutil"
  5. //"path/filepath"
  6. "strings"
  7. "github.com/veandco/go-sdl2/ttf"
  8. //"github.com/cuu/gogame/draw"
  9. "github.com/cuu/gogame/color"
  10. "github.com/cuu/gogame/event"
  11. "github.com/cuu/gogame/rect"
  12. "github.com/cuu/gogame/surface"
  13. "github.com/cuu/gogame/time"
  14. //"github.com/clockworkpi/LauncherGoDev/sysgo"
  15. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  16. )
  17. type AirplanePage struct {
  18. UI.Page
  19. ListFontObj *ttf.Font
  20. BGwidth int
  21. BGheight int
  22. Scrolled int
  23. Scroller *UI.ListScroller
  24. airwire_y int //0
  25. dialog_index int //0
  26. Icons map[string]UI.IconItemInterface
  27. }
  28. func NewAirplanePage() *AirplanePage {
  29. p := &AirplanePage{}
  30. p.PageIconMargin = 20
  31. p.SelectedIconTopOffset = 20
  32. p.EasingDur = 10
  33. p.Align = UI.ALIGN["SLeft"]
  34. p.ListFontObj = UI.MyLangManager.TrFont("varela13")
  35. p.FootMsg = [5]string{"Nav", "Rescue", "", "Back", "Toggle"}
  36. p.BGwidth = UI.Width
  37. p.BGheight = UI.Height - 24 - 20
  38. p.Icons = make(map[string]UI.IconItemInterface)
  39. return p
  40. }
  41. func (self *AirplanePage) GenList() {
  42. self.MyList = nil
  43. }
  44. func (self *AirplanePage) Init() {
  45. if self.Screen != nil {
  46. if self.Screen.CanvasHWND != nil && self.CanvasHWND == nil {
  47. self.HWND = self.Screen.CanvasHWND
  48. self.CanvasHWND = surface.Surface(self.Screen.Width, self.Screen.Height)
  49. }
  50. }
  51. self.PosX = self.Index * self.Screen.Width
  52. self.Width = self.Screen.Width
  53. self.Height = self.Screen.Height
  54. airwire := UI.NewIconItem()
  55. airwire.ImgSurf = UI.MyIconPool.GetImgSurf("airwire")
  56. airwire.MyType = UI.ICON_TYPES["STAT"]
  57. airwire.Parent = self
  58. airwire.Adjust(0, 0, 5, 43, 0)
  59. self.Icons["airwire"] = airwire
  60. GS := UI.NewIconItem()
  61. GS.ImgSurf = UI.MyIconPool.GetImgSurf("GS")
  62. GS.MyType = UI.ICON_TYPES["STAT"]
  63. GS.Parent = self
  64. GS.Adjust(0, 0, 72, 95, 0)
  65. self.Icons["GS"] = GS
  66. DialogBoxs := UI.NewMultiIconItem()
  67. DialogBoxs.ImgSurf = UI.MyIconPool.GetImgSurf("DialogBoxs")
  68. DialogBoxs.MyType = UI.ICON_TYPES["STAT"]
  69. DialogBoxs.Parent = self
  70. DialogBoxs.IconWidth = 134
  71. DialogBoxs.IconHeight = 93
  72. DialogBoxs.Adjust(0, 0, 134, 372, 0)
  73. self.Icons["DialogBoxs"] = DialogBoxs
  74. self.GenList()
  75. self.Scroller = UI.NewListScroller()
  76. self.Scroller.Parent = self
  77. self.Scroller.PosX = self.Width - 10
  78. self.Scroller.PosY = 2
  79. self.Scroller.Init()
  80. self.Scroller.SetCanvasHWND(self.HWND)
  81. }
  82. func (self *AirplanePage) ScrollUp() {
  83. dis := 10
  84. if self.PosY < 0 {
  85. self.PosY += dis
  86. self.Scrolled += dis
  87. }
  88. }
  89. func (self *AirplanePage) ScrollDown() {
  90. dis := 10
  91. if UI.Abs(self.Scrolled) < (self.BGheight-self.Height)/2+0 {
  92. self.PosY -= dis
  93. self.Scrolled -= dis
  94. }
  95. }
  96. func (self *AirplanePage) ToggleModeAni() {
  97. out := UI.System("sudo rfkill list | grep yes | cut -d \" \" -f3")
  98. if strings.Contains(out, "yes") {
  99. data := self.EasingData(0, 43)
  100. for _, v := range data {
  101. self.airwire_y -= v
  102. self.dialog_index = 2
  103. time.BlockDelay(40)
  104. self.Screen.Refresh()
  105. }
  106. UI.System("sudo rfkill unblock all")
  107. self.Screen.TitleBar.InAirPlaneMode = false
  108. } else {
  109. data := self.EasingData(0, 43)
  110. for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 { // reverse data
  111. data[i], data[j] = data[j], data[i]
  112. }
  113. for _, v := range data {
  114. self.airwire_y += v
  115. self.dialog_index = 3
  116. time.BlockDelay(40)
  117. self.Screen.Refresh()
  118. }
  119. UI.System("sudo rfkill block all")
  120. self.Screen.TitleBar.InAirPlaneMode = true
  121. }
  122. }
  123. func (self *AirplanePage) ToggleMode() {
  124. }
  125. func (self *AirplanePage) UnBlockAll() {
  126. self.Screen.MsgBox.SetText("TurningOn")
  127. self.Screen.MsgBox.Draw()
  128. UI.System("sudo rfkill unblock all")
  129. self.Screen.TitleBar.InAirPlaneMode = false
  130. }
  131. func (self *AirplanePage) OnLoadCb() {
  132. self.Scrolled = 0
  133. self.PosY = 0
  134. //self.DrawOnce = false
  135. out := UI.System("sudo rfkill list | grep yes | cut -d \" \" -f3")
  136. if strings.Contains(out, "yes") {
  137. self.Screen.TitleBar.InAirPlaneMode = true
  138. self.airwire_y = 50 + 43
  139. self.dialog_index = 1
  140. } else {
  141. self.dialog_index = 0
  142. self.airwire_y = 50
  143. self.Screen.TitleBar.InAirPlaneMode = false
  144. }
  145. }
  146. func (self *AirplanePage) KeyDown(ev *event.Event) {
  147. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  148. self.ReturnToUpLevelPage()
  149. self.Screen.Refresh()
  150. }
  151. if ev.Data["Key"] == UI.CurKeys["B"] {
  152. self.ToggleModeAni()
  153. }
  154. if ev.Data["Key"] == UI.CurKeys["X"] {
  155. self.UnBlockAll()
  156. self.Screen.SwapAndShow()
  157. time.BlockDelay(1000)
  158. self.Screen.Refresh()
  159. }
  160. }
  161. func (self *AirplanePage) Draw() {
  162. self.ClearCanvas()
  163. self.Icons["DialogBoxs"].NewCoord(145, 23)
  164. self.Icons["airwire"].NewCoord(80, self.airwire_y)
  165. self.Icons["DialogBoxs"].SetIconIndex(self.dialog_index)
  166. self.Icons["DialogBoxs"].DrawTopLeft()
  167. self.Icons["airwire"].Draw()
  168. self.Icons["GS"].NewCoord(98, 118)
  169. self.Icons["GS"].Draw()
  170. if self.HWND != nil {
  171. surface.Fill(self.HWND, &color.Color{255, 255, 255, 255})
  172. rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
  173. surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
  174. }
  175. }