Class ElementHandlerBase<T extends ElementBase>

java.lang.Object
org.rusherhack.client.api.ui.ElementHandlerBase<T>
All Implemented Interfaces:
Globals, IRenderable2D, org.rusherhack.core.interfaces.IClickable, org.rusherhack.core.interfaces.IDraggable, org.rusherhack.core.interfaces.IHoverable, org.rusherhack.core.interfaces.IScrollable, org.rusherhack.core.interfaces.ITickable, org.rusherhack.core.interfaces.ITypeable, org.rusherhack.core.serialize.ISerializable<com.google.gson.JsonElement>, org.rusherhack.core.serialize.JsonSerializable
Direct Known Subclasses:
HudHandlerBase, PanelHandlerBase, WindowHandlerBase

public abstract class ElementHandlerBase<T extends ElementBase> extends Object implements Globals, IRenderable2D, org.rusherhack.core.interfaces.IDraggable, org.rusherhack.core.interfaces.IScrollable, org.rusherhack.core.interfaces.ITypeable, org.rusherhack.core.interfaces.ITickable, org.rusherhack.core.serialize.JsonSerializable
A handler for managing multiple elements on screen.
  • Field Details

    • positionsInitialized

      public boolean positionsInitialized
      Flag variable used because positions are first set when the ui is first opened.

      Afterwards, the positions are saved to the config and will load from there.

  • Constructor Details

    • ElementHandlerBase

      public ElementHandlerBase(boolean scaledWithMinecraftGui)
      Parameters:
      scaledWithMinecraftGui - sets whether elements should be scaled with the minecraft gui
  • Method Details

    • getElements

      public abstract List<T> getElements()
      Returns:
      elements to be handled by this handler
    • getElement

      public Optional<T> getElement(String name)
      Finds an element given it's name
      Parameters:
      name - name of the element
      Returns:
      the element with the name or null if not found
    • initialize

      public abstract void initialize()
      Initialize all of the elements
    • setDefaultPositions

      public abstract void setDefaultPositions()
      Sets the default positions of the elements
    • moveElementToTop

      public abstract void moveElementToTop(T element)
      Moves the element to the top
      Parameters:
      element - element to move to the top
    • render

      public void render(RenderContext context, double mouseX, double mouseY)
      Specified by:
      render in interface IRenderable2D
    • renderElements

      public void renderElements(RenderContext renderContext, double mouseX, double mouseY)
    • tick

      public void tick()
      Specified by:
      tick in interface org.rusherhack.core.interfaces.ITickable
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Specified by:
      mouseClicked in interface org.rusherhack.core.interfaces.IClickable
    • mouseReleased

      public void mouseReleased(double mouseX, double mouseY, int button)
      Specified by:
      mouseReleased in interface org.rusherhack.core.interfaces.IClickable
    • mouseMoved

      public void mouseMoved(double mouseX, double mouseY)
      Specified by:
      mouseMoved in interface org.rusherhack.core.interfaces.IDraggable
    • mouseScrolled

      public boolean mouseScrolled(double mouseX, double mouseY, double delta)
      Specified by:
      mouseScrolled in interface org.rusherhack.core.interfaces.IScrollable
    • charTyped

      public boolean charTyped(char character)
      Specified by:
      charTyped in interface org.rusherhack.core.interfaces.ITypeable
    • keyTyped

      public boolean keyTyped(int key, int scanCode, int modifiers)
      Specified by:
      keyTyped in interface org.rusherhack.core.interfaces.ITypeable
    • isHovered

      public boolean isHovered(double mouseX, double mouseY)
      Specified by:
      isHovered in interface org.rusherhack.core.interfaces.IHoverable
    • consumeMouseClick

      protected boolean consumeMouseClick(double mouseX, double mouseY, int button)
    • consumeElementMouseClick

      protected boolean consumeElementMouseClick(T element, double mouseX, double mouseY, int button)
    • consumeMouseRelease

      protected void consumeMouseRelease(double mouseX, double mouseY, int button)
    • consumeElementMouseRelease

      protected boolean consumeElementMouseRelease(T element, double mouseX, double mouseY, int button)
    • consumeMouseMove

      protected void consumeMouseMove(double mouseX, double mouseY)
    • consumeElementMouseMove

      protected boolean consumeElementMouseMove(T element, double mouseX, double mouseY)
    • consumeMouseScroll

      protected boolean consumeMouseScroll(double mouseX, double mouseY, double delta)
    • consumeElementMouseScroll

      protected boolean consumeElementMouseScroll(T element, double mouseX, double mouseY, double delta)
    • consumeElementCharTyped

      protected boolean consumeElementCharTyped(T element, char character)
    • consumeElementKeyTyped

      protected boolean consumeElementKeyTyped(T element, int key, int scanCode, int modifiers)
    • getScale

      public float getScale()
    • isEnabled

      protected boolean isEnabled(T element)
      Checks if an element should have events sent to it
      Parameters:
      element - element to check
      Returns:
    • isElementHovered

      public boolean isElementHovered(T element, double mouseX, double mouseY)
      Checks if an element is hovered. Can be overridden to change the hover behavior.
      Parameters:
      element - the element
      mouseX - the x-coordinate of the mouse
      mouseY - the y-coordinate of the mouse
      Returns:
      true if the window is hovered
    • serialize

      public com.google.gson.JsonElement serialize()
      Specified by:
      serialize in interface org.rusherhack.core.serialize.ISerializable<T extends ElementBase>
    • deserialize

      public boolean deserialize(com.google.gson.JsonElement obj)
      Specified by:
      deserialize in interface org.rusherhack.core.serialize.ISerializable<T extends ElementBase>
    • shouldSerialize

      public boolean shouldSerialize(boolean autosave)
      Specified by:
      shouldSerialize in interface org.rusherhack.core.serialize.ISerializable<T extends ElementBase>