thecodewarrior

Untitled

Sep 8th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. class GuiBookLayoutEditor(val book: Book) : GuiBase(0, 0) {
  2.  
  3. var selected: GuiComponent<*>? = null
  4.  
  5. companion object {
  6. val TEX = Texture(ResourceLocation("librarianlib:textures/gui/editorUI.png"))
  7. }
  8.  
  9. var bookWidth = 100
  10. set(value) {
  11. field = value
  12. mainComponent.size = mainComponent.size.setX(value.toDouble())
  13. }
  14. var bookHeight = 150
  15. set(value) {
  16. field = value
  17. mainComponent.size = mainComponent.size.setY(value.toDouble())
  18. }
  19.  
  20. val mainComponent = ComponentVoid(0,0, bookWidth, bookHeight)
  21. val sidebarList = ComponentRect(0, 0, 100, 0)
  22. val sidebarInfo = ComponentRect(0, 0, 100, 0)
  23. val sprites = ComponentVoid(0, 0, 0, 0)
  24.  
  25. init {
  26.  
  27. val center = ComponentCenterAlign(0,0,true,true)
  28. center.add(mainComponent)
  29. DrawBorderMixin(mainComponent).color.setValue(Color.MAGENTA)
  30.  
  31. sidebarList.color.setValue(Color.LIGHT_GRAY)
  32. sidebarInfo.color.setValue(Color.LIGHT_GRAY)
  33. fullscreenComponents.BUS.hook(GuiComponent.SetSizeEvent::class.java) {
  34. resize(it.size)
  35. }
  36.  
  37. components.add(center)
  38. fullscreenComponents.add(sidebarList)
  39. fullscreenComponents.add(sidebarInfo)
  40.  
  41. val pos = ComponentText(1, 1, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP)
  42. val size = ComponentText(1, 10, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP)
  43.  
  44. pos.text.func {
  45. val sel = selected
  46. if(sel == null)
  47. "(N/A, N/A)"
  48. else
  49. "(${sel.pos.xi}, ${sel.pos.yi})"
  50. }
  51.  
  52. size.text.func {
  53. val sel = selected
  54. if(sel == null)
  55. "N/A x N/A"
  56. else
  57. "${sel.size.xi} x ${sel.size.yi}"
  58. }
  59.  
  60. sidebarInfo.add(pos)
  61. sidebarInfo.add(size)
  62.  
  63. sprites.calculateOwnHover = false
  64. components.add(sprites)
  65.  
  66. val componentsbg = ComponentVoid(-1000, -1000, 1000, 1000)
  67. componentsbg.zIndex = -1000
  68. componentsbg.BUS.hook(GuiComponent.MouseDownEvent::class.java) {
  69. if(componentsbg.mouseOver) selected = null
  70. }
  71. sprites.add(componentsbg)
  72.  
  73. val rect = createRect()
  74. createRect()
  75. createRect()
  76. createRect()
  77. createRect()
  78. createRect()
  79. createRect()
  80. createRect()
  81.  
  82. selected = rect
  83.  
  84.  
  85. }
  86.  
  87. fun createRect(): GuiComponent<*> {
  88. val rect = ComponentRect(0, 0, 25, 25)
  89. val color = Color(ThreadLocalRandom.current().nextInt(0, 255), ThreadLocalRandom.current().nextInt(0, 255), ThreadLocalRandom.current().nextInt(0, 255))
  90. rect.color.func { color }
  91. ResizableMixin(rect, 8, false)
  92. DragMixin(rect, { it })
  93.  
  94. rect.BUS.hook(GuiComponent.MouseDownEvent::class.java) { if(rect.mouseOver) selected = rect }
  95.  
  96. sprites.add(rect)
  97. return rect
  98. }
  99.  
  100. fun resize(size: Vec2d) {
  101. sidebarInfo.size = sidebarInfo.size.setY(size.y)
  102.  
  103. sidebarList.size = sidebarList.size.setY(size.y)
  104. sidebarList.pos = sidebarList.pos.setX(size.x - sidebarList.size.x)
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment