Exemplo n.º 1
0
 @Override
 public void onDraw(Canvas canvas) {
   for (HUDElement element : elementsLookup.values()) {
     int minX = TeraMath.floorToInt(element.region.minX() * canvas.size().x);
     int minY = TeraMath.floorToInt(element.region.minY() * canvas.size().y);
     int sizeX = TeraMath.floorToInt(element.region.width() * canvas.size().x);
     int sizeY = TeraMath.floorToInt(element.region.height() * canvas.size().y);
     Rect2i region = Rect2i.createFromMinAndSize(minX, minY, sizeX, sizeY);
     canvas.drawWidget(element.widget, region);
   }
 }
Exemplo n.º 2
0
  /**
   * Defines how the fluid container widget is drawn.
   *
   * @param canvas The canvas on which the widget is drawn
   */
  @Override
  public void onDraw(Canvas canvas) {
    TextureRegion texture = getImage();
    if (texture != null) {
      FluidInventoryComponent fluidInventory = entity.getComponent(FluidInventoryComponent.class);
      FluidComponent fluid =
          fluidInventory.fluidSlots.get(slotNo).getComponent(FluidComponent.class);
      float maxVolume = fluidInventory.maximumVolumes.get(slotNo);
      float currentVolume = 0f;
      String fluidType = null;
      FluidRenderer fluidRenderer = null;

      if (fluid != null) {
        currentVolume = fluid.volume;
        fluidType = fluid.fluidType;
        float result = fluid.volume / maxVolume;

        fluidRenderer = fluidRegistry.getFluidRenderer(fluid.fluidType);

        Vector2i size = canvas.size();
        if (minY < maxY) {
          float yPerc = 1f * (minY + result * (maxY - minY)) / texture.getHeight();
          fluidRenderer.renderFluid(
              canvas,
              Rect2i.createFromMinAndSize(minX, minY, maxX, Math.round(yPerc * size.y) - minY));
        } else {
          float yPerc = 1f * (minY - result * (minY - maxY)) / texture.getHeight();
          int y = Math.round(yPerc * size.y);
          fluidRenderer.renderFluid(canvas, Rect2i.createFromMinAndSize(minX, y, maxX, minY - y));
        }
      }

      canvas.drawTexture(texture, canvas.getRegion());

      setTooltipDelay(0);
      String fluidDisplay = fluidType == null ? "Fluid" : fluidRenderer.getFluidName();
      setTooltip(String.format(fluidDisplay + ": %.0f/%.0f", currentVolume, maxVolume));
    }

    canvas.addInteractionRegion(listener);
  }
Exemplo n.º 3
0
 @Override
 public void onDraw(Canvas canvas) {
   if (fillTexture != null) {
     int size = TeraMath.floorToInt(canvas.size().x * getValue());
     int barWidth = fillTexture.getWidth();
     int offset = 0;
     if (time != null && animate) {
       offset = TeraMath.floorToInt(time.getRealTimeInMs() / 10) % barWidth;
     }
     int drawnWidth = 0;
     // Draw Offset
     if (offset != 0) {
       int drawWidth = Math.min(size, offset);
       canvas.drawTextureRaw(
           fillTexture,
           Rect2i.createFromMinAndSize(0, 0, drawWidth, canvas.size().y),
           ScaleMode.STRETCH,
           barWidth - offset,
           0,
           drawWidth,
           canvas.size().y);
       drawnWidth += drawWidth;
     }
     // Draw Remainder
     while (drawnWidth < size) {
       int drawWidth = Math.min(size - drawnWidth, barWidth);
       canvas.drawTextureRaw(
           fillTexture,
           Rect2i.createFromMinAndSize(drawnWidth, 0, drawWidth, canvas.size().y),
           ScaleMode.STRETCH,
           0,
           0,
           drawWidth,
           canvas.size().y);
       drawnWidth += drawWidth;
     }
   }
 }