VulkanShader_1.21.10-0.0.4-alpha.jar

Download file
    package net.vulkanmod.config.gui.widget;

import net.minecraft.class_11231;
import net.minecraft.class_2561;
import net.minecraft.class_310;
import net.minecraft.class_327;
import net.vulkanmod.config.gui.render.GuiRenderer;
import net.vulkanmod.config.option.CyclingOption;
import net.vulkanmod.render.shader.CustomRenderPipelines;
import net.vulkanmod.vulkan.util.ColorUtil;

public class CyclingOptionWidget extends OptionWidget<CyclingOption<?>> {
   private final Button leftButton;
   private final Button rightButton;
   private boolean focused;

   public CyclingOptionWidget(CyclingOption<?> option, class_2561 name) {
      super(option, name);
      this.leftButton = new Button(CyclingOptionWidget.Button.Direction.LEFT);
      this.rightButton = new Button(CyclingOptionWidget.Button.Direction.RIGHT);
   }

   public void setDimensions(int x, int y, int width, int height) {
      super.setDimensions(x, y, width, height);
      this.leftButton.setDimensions(this.controlX, 16);
      this.rightButton.setDimensions(this.controlX + this.controlWidth - 16, 16);
   }

   protected int getYImage(boolean hovered) {
      return 0;
   }

   public void renderControls(double mouseX, double mouseY) {
      this.renderBars();
      this.leftButton.setStatus(((CyclingOption)this.option).index() > 0);
      this.rightButton.setStatus(((CyclingOption)this.option).index() < ((CyclingOption)this.option).getValues().length - 1);
      int color = this.active ? -1 : -6250336;
      class_327 textRenderer = class_310.method_1551().field_1772;
      int x = this.controlX + this.controlWidth / 2;
      int y = this.y + (this.height - 9) / 2;
      GuiRenderer.drawCenteredString(textRenderer, this.getDisplayedValue(), x, y, color);
      this.leftButton.renderButton(mouseX, mouseY);
      this.rightButton.renderButton(mouseX, mouseY);
   }

   public void renderBars() {
      int count = ((CyclingOption)this.option).getValues().length;
      int current = ((CyclingOption)this.option).index();
      int margin = 30;
      int padding = 4;
      int barWidth = (this.controlWidth - 2 * margin - padding * count) / count;
      int color = ColorUtil.ARGB.pack(1.0F, 1.0F, 1.0F, 0.4F);
      int activeColor = ColorUtil.ARGB.pack(1.0F, 1.0F, 1.0F, 1.0F);
      if (barWidth > 0) {
         for(int i = 0; i < count; ++i) {
            int x0 = this.controlX + margin + i * (barWidth + padding);
            int y0 = this.y + this.height - 5;
            int c = i == current ? activeColor : color;
            GuiRenderer.fill(x0, y0, x0 + barWidth, (int)((float)y0 + 1.5F), c);
         }

      }
   }

   public void setActive(boolean active) {
      this.active = active;
      Button var10000 = this.leftButton;
      var10000.active &= active;
      var10000 = this.rightButton;
      var10000.active &= active;
   }

   public void onClick(double mouseX, double mouseY) {
      if (this.leftButton.isHovered(mouseX, mouseY)) {
         ((CyclingOption)this.option).prevValue();
      } else if (this.rightButton.isHovered(mouseX, mouseY)) {
         ((CyclingOption)this.option).nextValue();
      }

   }

   public void onRelease(double mouseX, double mouseY) {
   }

   protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
   }

   public void method_25365(boolean bl) {
      this.focused = bl;
   }

   public boolean method_25370() {
      return this.focused;
   }

   class Button {
      final int ACTIVE_COLOR = ColorUtil.ARGB.pack(1.0F, 1.0F, 1.0F, 0.8F);
      final int HOVERED_COLOR = ColorUtil.ARGB.pack(1.0F, 1.0F, 1.0F, 1.0F);
      final int INACTIVE_COLOR = ColorUtil.ARGB.pack(0.3F, 0.3F, 0.3F, 0.8F);
      int x;
      int width;
      boolean active = true;
      Direction direction;

      Button(Direction direction) {
         this.direction = direction;
      }

      public void setDimensions(int x, int width) {
         this.x = x;
         this.width = width;
      }

      boolean isHovered(double mouseX, double mouseY) {
         return mouseX >= (double)this.x && mouseX <= (double)(this.x + this.width) && mouseY >= (double)CyclingOptionWidget.this.y && mouseY <= (double)(CyclingOptionWidget.this.y + CyclingOptionWidget.this.height);
      }

      void setStatus(boolean status) {
         this.active = status;
      }

      void renderButton(double mouseX, double mouseY) {
         float f = this.isHovered(mouseX, mouseY) && this.active ? 5.0F : 4.5F;
         int color;
         if (this.isHovered(mouseX, mouseY) && this.active) {
            color = this.HOVERED_COLOR;
         } else if (this.active) {
            color = this.ACTIVE_COLOR;
         } else {
            color = this.INACTIVE_COLOR;
         }

         float w = f - 1.0F;
         float yC = (float)CyclingOptionWidget.this.y + (float)CyclingOptionWidget.this.height * 0.5F;
         float xC = (float)this.x + (float)this.width * 0.5F;
         float[][] vertices;
         if (this.direction == CyclingOptionWidget.Button.Direction.LEFT) {
            vertices = new float[][]{{xC - w, yC}, {xC + w, yC + f}, {xC + w, yC - f}};
         } else {
            vertices = new float[][]{{xC + w, yC}, {xC - w, yC - f}, {xC - w, yC + f}};
         }

         GuiRenderer.submitPolygon(CustomRenderPipelines.GUI_TRIANGLES, class_11231.method_70899(), vertices, color);
      }

      static enum Direction {
         LEFT,
         RIGHT;

         // $FF: synthetic method
         private static Direction[] $values() {
            return new Direction[]{LEFT, RIGHT};
         }
      }
   }
}
    
Download file