Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Component[+A <: Component[A]] extends Publisher {
- this: A =>
- def init(channel: Publisher, context: Context): Unit = {
- listenTo(channel)
- this.context = context
- }
- def update(mousePos: Point): Unit
- def dispose(): Unit = {
- if (context != null)
- deafTo(context)
- }
- def bounds: Rectangle = {
- if (_bounds == null || _bounds.width != width || _bounds.height != height || _bounds.start != position)
- _bounds = Rectangle(position, width, height)
- _bounds
- }
- def screenBounds: Rectangle = {
- if (_screenBounds == null || _screenBounds.width != width || _screenBounds.height != height || _screenBounds.start != screen)
- _screenBounds = Rectangle(screen, width, height)
- _screenBounds
- }
- def x = position.x
- def y = position.y
- def width = size.width
- def height = size.height
- def hovered(mousePosition: Point) = screenBounds contains mousePosition
- def skin: Skin = Skin(this)
- def defaultSkin: Skin
- lazy val mc: Minecraft = FMLClientHandler.instance.getClient
- val utils = GuiUtils
- var position = Point(0, 0)
- var screen = Point(0, 0)
- var size = Size(0, 0)
- var context: Context = _
- var enabled: Boolean = true
- var visible: Boolean = true
- var parent: Panel = _
- var name: String = _
- var tooltip: String = _
- var identifier: String = getClass.getSimpleName
- private var _bounds: Rectangle = Rectangle(position, width, height)
- private var _screenBounds: Rectangle = Rectangle(screen, width, height)
- object Skin {
- private var defaults = HashMap.empty[String, Skin]
- private var activeSkins = HashMap.empty[String, Skin]
- def apply[C <: Component[C]](comp: Component[C]): Skin = {
- if (!activeSkins.contains(comp.identifier))
- if (defaults.contains(comp.identifier)) {
- activeSkins += comp.identifier -> defaults(comp.identifier)
- } else {
- defaults += comp.identifier -> comp.defaultSkin.asInstanceOf[Skin]
- activeSkins += comp.identifier -> comp.defaultSkin.asInstanceOf[Skin]
- }
- activeSkins(comp.identifier)
- }
- def load(): Unit = {
- }
- def setDefault(id: String, skin: Skin): Unit = {
- defaults += id -> skin
- }
- def set(id: String, skin: Skin): Unit = {
- activeSkins += id -> skin
- }
- }
- trait Skin {
- val utils = GuiUtils
- protected def drawBackground(mousePos: Point, component: A): Unit = {
- if (background != null) {
- background.size = component.size
- background.draw(mousePos, component.screen)
- }
- }
- protected def drawForeground(mousePos: Point, component: A): Unit
- def draw(mousePos: Point, component: A): Unit = {
- drawBackground(mousePos, component)
- drawForeground(mousePos, component)
- }
- var background: Drawable = null
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement