Settings.go 7.8 KB

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