confirm_page.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package UI
  2. import (
  3. //"fmt"
  4. "github.com/veandco/go-sdl2/ttf"
  5. // "github.com/cuu/gogame/surface"
  6. "github.com/cuu/gogame/color"
  7. "github.com/cuu/gogame/event"
  8. "github.com/cuu/gogame/rect"
  9. // "github.com/cuu/gogame/font"
  10. "github.com/cuu/gogame/draw"
  11. )
  12. type ListPageSelector struct {
  13. PageSelector
  14. BackgroundColor *color.Color
  15. Parent *ConfirmPage
  16. }
  17. func NewListPageSelector() *ListPageSelector {
  18. p := &ListPageSelector{}
  19. p.Width = Width
  20. p.BackgroundColor = &color.Color{131, 199, 219, 255}
  21. return p
  22. }
  23. func (self *ListPageSelector) Draw() {
  24. idx := self.Parent.GetPsIndex()
  25. mylist := self.Parent.MyList
  26. if idx > (len(mylist) - 1) {
  27. idx = len(mylist)
  28. if idx > 0 {
  29. idx -= 1
  30. } else if idx == 0 {
  31. return
  32. }
  33. }
  34. x, y := mylist[idx].Coord()
  35. _, h := mylist[idx].Size()
  36. self.PosX = x
  37. self.PosY = y
  38. self.Height = h - 3
  39. canvas_ := self.Parent.GetCanvasHWND()
  40. rect_ := rect.Rect(self.PosX, self.PosY, self.Width-4, self.Height)
  41. draw.AARoundRect(canvas_, &rect_, self.BackgroundColor, 4, 0, self.BackgroundColor)
  42. }
  43. type ConfirmPage struct {
  44. Page
  45. ListFont *ttf.Font
  46. FileName string
  47. TrashDir string
  48. ConfirmText string
  49. BGPosX int
  50. BGPosY int
  51. BGWidth int
  52. BGHeight int
  53. Icons map[string]IconItemInterface
  54. MyList []LabelInterface
  55. }
  56. func NewConfirmPage() *ConfirmPage {
  57. p := &ConfirmPage{}
  58. p.ListFont = MyLangManager.TrFont("veramono20")
  59. p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
  60. p.ConfirmText = "Confirm?"
  61. return p
  62. }
  63. func (self *ConfirmPage) Reset() {
  64. self.MyList[0].SetText(self.ConfirmText)
  65. x, y := self.MyList[0].Coord()
  66. w, h := self.MyList[0].Size()
  67. self.MyList[0].NewCoord((self.Width-w)/2, (self.Height-h)/2)
  68. x, y = self.MyList[0].Coord()
  69. self.BGPosX = x - 10
  70. self.BGPosY = y - 10
  71. self.BGWidth = w + 20
  72. self.BGHeight = h + 20
  73. }
  74. func (self *ConfirmPage) SnapMsg(msg string) {
  75. self.MyList[0].SetText(msg)
  76. x, y := self.MyList[0].Coord()
  77. w, h := self.MyList[0].Size()
  78. self.MyList[0].NewCoord((self.Width-w)/2, (self.Height-h)/2)
  79. x, y = self.MyList[0].Coord()
  80. self.BGPosX = x - 10
  81. self.BGPosY = y - 10
  82. self.BGWidth = w + 20
  83. self.BGHeight = h + 20
  84. }
  85. func (self *ConfirmPage) Init() {
  86. if self.Screen != nil {
  87. self.PosX = self.Index * self.Screen.Width
  88. self.Width = self.Screen.Width
  89. self.Height = self.Screen.Height
  90. self.CanvasHWND = self.Screen.CanvasHWND
  91. ps := NewListPageSelector()
  92. ps.Parent = self
  93. self.Ps = ps
  94. self.PsIndex = 0
  95. li := NewLabel()
  96. li.SetCanvasHWND(self.CanvasHWND)
  97. li.Init(self.ConfirmText, self.ListFont, nil)
  98. li.PosX = (self.Width - li.Width) / 2
  99. li.PosY = (self.Height - li.Height) / 2
  100. self.BGPosX = li.PosX - 10
  101. self.BGPosY = li.PosY - 10
  102. self.BGWidth = li.Width + 20
  103. self.BGHeight = li.Height + 20
  104. self.MyList = append(self.MyList, li)
  105. }
  106. }
  107. func (self *ConfirmPage) KeyDown(ev *event.Event) {
  108. if ev.Data["Key"] == CurKeys["A"] || ev.Data["Key"] == CurKeys["Menu"] {
  109. self.ReturnToUpLevelPage()
  110. self.Screen.Draw()
  111. self.Screen.SwapAndShow()
  112. }
  113. }
  114. func (self *ConfirmPage) DrawBG() {
  115. rect_ := rect.Rect(self.BGPosX, self.BGPosY, self.BGWidth, self.BGHeight)
  116. draw.Rect(self.CanvasHWND, &color.Color{255, 255, 255, 255}, &rect_, 0) // SkinManager().GiveColor('White')
  117. draw.Rect(self.CanvasHWND, &color.Color{83, 83, 83, 255}, &rect_, 1) //SkinManager().GiveColor('Text')
  118. }
  119. func (self *ConfirmPage) Draw() {
  120. self.DrawBG()
  121. for _, v := range self.MyList {
  122. v.Draw()
  123. }
  124. self.Reset()
  125. }