airplane_page.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.Draw()
  105. self.Screen.SwapAndShow()
  106. }
  107. UI.System("sudo rfkill unblock all")
  108. self.Screen.TitleBar.InAirPlaneMode = false
  109. } else {
  110. data := self.EasingData(0, 43)
  111. for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 { // reverse data
  112. data[i], data[j] = data[j], data[i]
  113. }
  114. for _, v := range data {
  115. self.airwire_y += v
  116. self.dialog_index = 3
  117. time.BlockDelay(40)
  118. self.Screen.Draw()
  119. self.Screen.SwapAndShow()
  120. }
  121. UI.System("sudo rfkill block all")
  122. self.Screen.TitleBar.InAirPlaneMode = true
  123. }
  124. }
  125. func (self *AirplanePage) ToggleMode() {
  126. }
  127. func (self *AirplanePage) UnBlockAll() {
  128. self.Screen.MsgBox.SetText("TurningOn")
  129. self.Screen.MsgBox.Draw()
  130. UI.System("sudo rfkill unblock all")
  131. self.Screen.TitleBar.InAirPlaneMode = false
  132. }
  133. func (self *AirplanePage) OnLoadCb() {
  134. self.Scrolled = 0
  135. self.PosY = 0
  136. //self.DrawOnce = false
  137. out := UI.System("sudo rfkill list | grep yes | cut -d \" \" -f3")
  138. if strings.Contains(out, "yes") {
  139. self.Screen.TitleBar.InAirPlaneMode = true
  140. self.airwire_y = 50 + 43
  141. self.dialog_index = 1
  142. } else {
  143. self.dialog_index = 0
  144. self.airwire_y = 50
  145. self.Screen.TitleBar.InAirPlaneMode = false
  146. }
  147. }
  148. func (self *AirplanePage) KeyDown(ev *event.Event) {
  149. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  150. self.ReturnToUpLevelPage()
  151. self.Screen.Draw()
  152. self.Screen.SwapAndShow()
  153. }
  154. if ev.Data["Key"] == UI.CurKeys["B"] {
  155. self.ToggleModeAni()
  156. }
  157. if ev.Data["Key"] == UI.CurKeys["X"] {
  158. self.UnBlockAll()
  159. self.Screen.SwapAndShow()
  160. time.BlockDelay(1000)
  161. self.Screen.Draw()
  162. self.Screen.SwapAndShow()
  163. }
  164. }
  165. func (self *AirplanePage) Draw() {
  166. self.ClearCanvas()
  167. self.Icons["DialogBoxs"].NewCoord(145, 23)
  168. self.Icons["airwire"].NewCoord(80, self.airwire_y)
  169. self.Icons["DialogBoxs"].SetIconIndex(self.dialog_index)
  170. self.Icons["DialogBoxs"].DrawTopLeft()
  171. self.Icons["airwire"].Draw()
  172. self.Icons["GS"].NewCoord(98, 118)
  173. self.Icons["GS"].Draw()
  174. if self.HWND != nil {
  175. surface.Fill(self.HWND, &color.Color{255, 255, 255, 255})
  176. rect_ := rect.Rect(self.PosX, self.PosY, self.Width, self.Height)
  177. surface.Blit(self.HWND, self.CanvasHWND, &rect_, nil)
  178. }
  179. }