Settings.go 6.5 KB

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