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