Settings.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. package Settings
  2. import (
  3. "github.com/veandco/go-sdl2/ttf"
  4. "path/filepath"
  5. // "github.com/cuu/gogame/surface"
  6. "github.com/cuu/gogame/event"
  7. "github.com/cuu/gogame/rect"
  8. "github.com/cuu/gogame/color"
  9. "github.com/cuu/gogame/draw"
  10. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  11. //child packages
  12. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/About"
  13. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Sound"
  14. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Brightness"
  15. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Wifi"
  16. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Bluetooth"
  17. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/LauncherPy"
  18. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Update"
  19. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Storage"
  20. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Languages"
  21. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOFF"
  22. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/PowerOptions"
  23. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Airplane"
  24. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/ButtonsLayout"
  25. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/TimeZone"
  26. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/Lima"
  27. "github.com/clockworkpi/LauncherGoDev/Menu/GameShell/10_Settings/GateWay"
  28. )
  29. type SettingsPageSelector struct {
  30. UI.PageSelector
  31. BackgroundColor *color.Color
  32. }
  33. func NewSettingsPageSelector() *SettingsPageSelector{
  34. s := &SettingsPageSelector{}
  35. s.BackgroundColor = &color.Color{131,199,219,255}
  36. s.Width = UI.Width
  37. return s
  38. }
  39. func (self *SettingsPageSelector) Draw() {
  40. idx := self.Parent.GetPsIndex()
  41. mylist := self.Parent.GetMyList()
  42. if idx < len( mylist) {
  43. _,y_ := mylist[idx].Coord()
  44. _,h_ := mylist[idx].Size()
  45. x := 2
  46. y := y_+1
  47. h := h_-3
  48. self.PosX = x
  49. self.PosY = y
  50. self.Height = h
  51. rect_ := rect.Rect(x,y,self.Width-4,h)
  52. canvas_ := self.Parent.GetCanvasHWND()
  53. draw.AARoundRect(canvas_, &rect_,self.BackgroundColor,4,0,self.BackgroundColor)
  54. }
  55. }
  56. //##############################################//
  57. type SettingsPage struct {
  58. UI.Page
  59. AList map[string]map[string]string
  60. ListFontObj *ttf.Font
  61. Scrolled int
  62. BGwidth int
  63. BGheight int
  64. DrawOnce bool
  65. Scroller *UI.ListScroller
  66. Icons map[string]UI.IconItemInterface
  67. MyPath string
  68. }
  69. func NewSettingsPage() *SettingsPage {
  70. p := &SettingsPage{}
  71. p.FootMsg = [5]string{"Nav","","","Back","Enter"}
  72. p.ListFontObj = UI.Fonts["varela15"]
  73. p.MyPath = "Menu/GameShell/10_Settings"
  74. return p
  75. }
  76. func (self *SettingsPage) GenList() []*UI.UIPlugin {
  77. alist := []*UI.UIPlugin{
  78. &UI.UIPlugin{UI.PluginPackage,"", "Airplane", "Airplane Mode", &Airplane.APIOBJ},
  79. &UI.UIPlugin{UI.PluginPackage,"", "PowerOptions", "Power Options", &PowerOptions.APIOBJ},
  80. &UI.UIPlugin{UI.PluginPackage,"", "Wifi", "Wi-Fi", &Wifi.APIOBJ},
  81. &UI.UIPlugin{UI.PluginPackage,"", "Bluetooth", "Bluetooth", &Bluetooth.APIOBJ},
  82. &UI.UIPlugin{UI.PluginPackage,"", "Sound", "Sound Volume" , &Sound.APIOBJ},
  83. &UI.UIPlugin{UI.PluginPackage,"", "Brightness", "BackLight Brightness", &Brightness.APIOBJ},
  84. &UI.UIPlugin{UI.PluginPackage,"", "Storage", "", &Storage.APIOBJ},
  85. &UI.UIPlugin{UI.PluginPackage,"", "TimeZone", "Timezone", &TimeZone.APIOBJ},
  86. &UI.UIPlugin{UI.PluginPackage,"", "Languages", "Languages", &Languages.APIOBJ},
  87. &UI.UIPlugin{UI.PluginPackage,"", "Update", "Update LauncherGo", &Update.APIOBJ},
  88. &UI.UIPlugin{UI.PluginPackage,"", "About", "About", &About.APIOBJ},
  89. &UI.UIPlugin{UI.PluginPackage,"", "PowerOFF", "Power off", &PowerOFF.APIOBJ},
  90. &UI.UIPlugin{UI.PluginPackage,"", "ButtonsLayout", "Buttons Layout", &ButtonsLayout.APIOBJ},
  91. &UI.UIPlugin{UI.PluginPackage,"", "LauncherPy", "Switch to Launcher", &LauncherPy.APIOBJ},
  92. &UI.UIPlugin{UI.PluginPackage,"", "Lima", "GPU Driver Switch", &Lima.APIOBJ},
  93. &UI.UIPlugin{UI.PluginPackage,"", "GateWay", "Network gateway switch", &GateWay.APIOBJ},
  94. }
  95. return alist
  96. }
  97. func (self *SettingsPage) Init() {
  98. if self.Screen != nil {
  99. self.PosX = self.Index * self.Screen.Width
  100. self.Width = self.Screen.Width
  101. self.Height = self.Screen.Height
  102. self.CanvasHWND = self.Screen.CanvasHWND
  103. ps := NewSettingsPageSelector()
  104. ps.Parent = self
  105. self.Ps = ps
  106. self.PsIndex = 0
  107. start_x := 0
  108. start_y := 0
  109. alist := self.GenList()
  110. for i,v := range alist{
  111. li := UI.NewListItem()
  112. li.Parent = self
  113. li.PosX = start_x
  114. li.PosY = start_y + i*li.Height
  115. li.Width = UI.Width
  116. li.Fonts["normal"] = self.ListFontObj
  117. if v.LabelText != "" {
  118. li.Init(v.LabelText)
  119. }else{
  120. li.Init(v.FolderName)
  121. }
  122. if v.SoFile!= "" && UI.FileExists( filepath.Join(self.MyPath,v.FolderName,v.SoFile )) {
  123. pi,err := UI.LoadPlugin(filepath.Join(self.MyPath,v.FolderName,v.SoFile ))
  124. UI.Assert(err)
  125. li.LinkObj = UI.InitPlugin(pi,self.Screen)
  126. self.MyList = append(self.MyList,li)
  127. }else {
  128. if v.EmbInterface != nil {
  129. v.EmbInterface.Init(self.Screen)
  130. li.LinkObj = v.EmbInterface
  131. self.MyList = append(self.MyList,li)
  132. }
  133. }
  134. }
  135. self.Scroller = UI.NewListScroller()
  136. self.Scroller.Parent = self
  137. self.Scroller.PosX = self.Width - 10
  138. self.Scroller.PosY = 2
  139. self.Scroller.Init()
  140. }
  141. }
  142. func (self *SettingsPage) ScrollUp() {
  143. if len(self.MyList) == 0 {
  144. return
  145. }
  146. self.PsIndex -= 1
  147. if self.PsIndex < 0 {
  148. self.PsIndex = 0
  149. }
  150. cur_li := self.MyList[self.PsIndex]
  151. x,y := cur_li.Coord()
  152. if y < 0 {
  153. for i:=0;i<len(self.MyList);i++ {
  154. _,h := self.MyList[i].Size()
  155. x,y = self.MyList[i].Coord()
  156. self.MyList[i].NewCoord(x, y+h)
  157. }
  158. }
  159. }
  160. func (self *SettingsPage) ScrollDown() {
  161. if len(self.MyList) == 0 {
  162. return
  163. }
  164. self.PsIndex += 1
  165. if self.PsIndex >= len(self.MyList) {
  166. self.PsIndex = len(self.MyList) - 1
  167. }
  168. cur_li := self.MyList[self.PsIndex]
  169. x,y := cur_li.Coord()
  170. _,h := cur_li.Size()
  171. if y + h > self.Height {
  172. for i:=0;i<len(self.MyList);i++ {
  173. _,h = self.MyList[i].Size()
  174. x,y = self.MyList[i].Coord()
  175. self.MyList[i].NewCoord(x, y - h)
  176. }
  177. }
  178. }
  179. func (self *SettingsPage) Click() {
  180. if len(self.MyList) == 0 {
  181. return
  182. }
  183. cur_li := self.MyList[self.PsIndex]
  184. lk_obj := cur_li.GetLinkObj()
  185. if lk_obj != nil {
  186. lk_obj.Run(self.Screen)
  187. }
  188. }
  189. func (self *SettingsPage) KeyDown( ev *event.Event) {
  190. if ev.Data["Key"] == UI.CurKeys["A"] || ev.Data["Key"] == UI.CurKeys["Menu"] {
  191. self.ReturnToUpLevelPage()
  192. self.Screen.Draw()
  193. self.Screen.SwapAndShow()
  194. }
  195. if ev.Data["Key"] == UI.CurKeys["Up"] {
  196. self.ScrollUp()
  197. self.Screen.Draw()
  198. self.Screen.SwapAndShow()
  199. }
  200. if ev.Data["Key"] == UI.CurKeys["Down"] {
  201. self.ScrollDown()
  202. self.Screen.Draw()
  203. self.Screen.SwapAndShow()
  204. }
  205. if ev.Data["Key"] == UI.CurKeys["Enter"] {
  206. self.Click()
  207. }
  208. }
  209. func (self *SettingsPage) Draw() {
  210. self.ClearCanvas()
  211. if len(self.MyList) == 0 {
  212. return
  213. }
  214. _,h_ := self.MyList[0].Size()
  215. if len(self.MyList) * h_ > self.Height {
  216. _,ph_ := self.Ps.Size()
  217. self.Ps.NewSize(self.Width - 11, ph_)
  218. self.Ps.Draw()
  219. for _,v := range self.MyList {
  220. v.Draw()
  221. }
  222. self.Scroller.UpdateSize(len(self.MyList)*h_,self.PsIndex*h_)
  223. self.Scroller.Draw()
  224. }else {
  225. _,ph_ := self.Ps.Size()
  226. self.Ps.NewSize(self.Width,ph_)
  227. self.Ps.Draw()
  228. for _,v := range self.MyList {
  229. v.Draw()
  230. }
  231. }
  232. }
  233. /******************************************************************************/
  234. type SettingsPlugin struct {
  235. UI.Plugin
  236. Page UI.PageInterface
  237. }
  238. func (self *SettingsPlugin) Init( main_screen *UI.MainScreen ) {
  239. self.Page = NewSettingsPage()
  240. self.Page.SetScreen( main_screen)
  241. self.Page.SetName("Settings")
  242. self.Page.Init()
  243. }
  244. func (self *SettingsPlugin) Run( main_screen *UI.MainScreen ) {
  245. if main_screen != nil {
  246. main_screen.PushPage(self.Page)
  247. main_screen.Draw()
  248. main_screen.SwapAndShow()
  249. }
  250. }
  251. var APIOBJ SettingsPlugin