ware_house_list_item.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package Warehouse
  2. import (
  3. "github.com/veandco/go-sdl2/ttf"
  4. "github.com/cuu/gogame/draw"
  5. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  6. )
  7. //GameStoreListItem in py
  8. type WareHouseListItem struct {
  9. UI.InfoPageListItem
  10. Type string
  11. Value map[string]string
  12. Parent *WareHouse
  13. }
  14. func NewWareHouseListItem() *WareHouseListItem {
  15. p := &WareHouseListItem{}
  16. p.Height = UI.DefaultInfoPageListItemHeight
  17. p.Labels = make(map[string]UI.LabelInterface)
  18. p.Icons = make(map[string]UI.IconItemInterface)
  19. p.Fonts = make(map[string]*ttf.Font)
  20. return p
  21. }
  22. func (self *WareHouseListItem) Init( text string) {
  23. l := UI.NewLabel()
  24. l.CanvasHWND = self.Parent.GetCanvasHWND()
  25. l.PosX = 10
  26. l.Init(text,self.Fonts["normal"],nil)
  27. self.Labels["text"] = l
  28. add_icon := UI.NewIconItem()
  29. add_icon.ImgSurf = UI.MyIconPool.GetImgSurf("add")
  30. add_icon.Parent = self.Parent
  31. add_icon.Init(0,0,UI.MyIconPool.Width("add"),UI.MyIconPool.Height("add"),0)
  32. ware_icon := UI.NewIconItem()
  33. ware_icon.ImgSurf = UI.MyIconPool.GetImgSurf("ware")
  34. ware_icon.Parent = self.Parent
  35. ware_icon.Init(0,0,UI.MyIconPool.Width("ware"),UI.MyIconPool.Height("ware"),0)
  36. app_icon := UI.NewIconItem()
  37. app_icon.ImgSurf = UI.MyIconPool.GetImgSurf("app")
  38. app_icon.Parent = self.Parent
  39. app_icon.Init(0,0,UI.MyIconPool.Width("app"),UI.MyIconPool.Height("app"),0)
  40. appdling_icon := UI.NewIconItem()
  41. appdling_icon.ImgSurf = UI.MyIconPool.GetImgSurf("appdling")
  42. appdling_icon.Parent = self.Parent
  43. appdling_icon.Init(0,0,UI.MyIconPool.Width("appdling"),UI.MyIconPool.Height("appdling"),0)
  44. blackheart_icon := UI.NewIconItem()
  45. blackheart_icon.ImgSurf = UI.MyIconPool.GetImgSurf("blackheart")
  46. blackheart_icon.Parent = self.Parent
  47. blackheart_icon.Init(0,0,UI.MyIconPool.Width("blackheart"),UI.MyIconPool.Height("blackheart"),0)
  48. self.Icons["add"] = add_icon
  49. self.Icons["ware"] = ware_icon
  50. self.Icons["app"] = app_icon
  51. self.Icons["appdling"] = appdling_icon
  52. self.Icons["blackheart"] = blackheart_icon
  53. }
  54. func (self *WareHouseListItem) Draw() {
  55. if self.ReadOnly == true {
  56. self.Labels["text"].SetColor( UI.MySkinManager.GiveColor("ReadOnlyText"))
  57. } else {
  58. self.Labels["text"].SetColor( UI.MySkinManager.GiveColor("Text"))
  59. }
  60. padding := 17
  61. if self.Type == "" {
  62. padding = 0
  63. }
  64. if self.Type == "source" || self.Type == "dir" {
  65. _,h := self.Icons["ware"].Size()
  66. self.Icons["ware"].NewCoord(4,(self.Height - h)/2)
  67. self.Icons["ware"].DrawTopLeft()
  68. }
  69. if self.Type == "launcher" || self.Type == "pico8" || self.Type == "tic80" {
  70. _icon := "app"
  71. if self.ReadOnly == true {
  72. _icon = "appdling"
  73. }
  74. _,h := self.Icons[_icon].Size()
  75. self.Icons[_icon].NewCoord(4,(self.Height - h )/2)
  76. self.Icons[_icon].DrawTopLeft()
  77. }
  78. if self.Type == "add_house" {
  79. _,h := self.Icons["add"].Size()
  80. self.Icons["add"].NewCoord(4,(self.Height - h)/2)
  81. self.Icons["add"].DrawTopLeft()
  82. }
  83. x,_ := self.Labels["text"].Coord()
  84. _,h := self.Labels["text"].Size()
  85. self.Labels["text"].NewCoord(x + self.PosX + padding, self.PosY + (self.Height-h)/2)
  86. self.Labels["text"].Draw()
  87. x,y := self.Labels["text"].Coord()
  88. self.Labels["text"].NewCoord( x - self.PosX - padding, y)
  89. if _, ok := self.Labels["Small"]; ok {
  90. x, _ = self.Labels["Small"].Coord()
  91. w, h := self.Labels["Small"].Size()
  92. self.Labels["Small"].NewCoord(self.Width-w-5, self.PosY+(self.Height-h)/2)
  93. self.Labels["Small"].Draw()
  94. }
  95. canvas_ := self.Parent.GetCanvasHWND()
  96. draw.Line(canvas_,UI.MySkinManager.GiveColor("Line"),
  97. self.PosX,self.PosY + self.Height -1,
  98. self.PosX+self.Width,self.PosY+self.Height-1,
  99. 1)
  100. }