Settings.go 7.8 KB

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