VulkanShader_1.21.10-0.0.4-alpha.jar
Download file
package net.vulkanmod.config.gui;
import com.mojang.blaze3d.opengl.GlStateManager;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.List;
import net.minecraft.class_11909;
import net.minecraft.class_3532;
import net.minecraft.class_364;
import net.vulkanmod.config.gui.render.GuiRenderer;
import net.vulkanmod.config.gui.widget.OptionWidget;
import net.vulkanmod.config.gui.widget.VAbstractWidget;
import net.vulkanmod.config.option.Option;
import net.vulkanmod.vulkan.util.ColorUtil;
import org.jetbrains.annotations.Nullable;
public class VOptionList extends GuiElement {
private final List<Entry> children = new ObjectArrayList();
boolean scrolling = false;
float scrollAmount = 0.0F;
int itemWidth;
int totalItemHeight;
int itemHeight;
int itemMargin;
int listLength = 0;
Entry focused;
public VOptionList(int x, int y, int width, int height, int itemHeight) {
this.setPosition(x, y, width, height);
this.width = width;
this.height = height;
this.itemWidth = (int)(0.95F * (float)this.width);
this.itemHeight = itemHeight;
this.itemMargin = 3;
this.totalItemHeight = this.itemHeight + this.itemMargin;
}
public void addButton(OptionWidget<?> widget) {
this.addEntry(new Entry(widget, this.itemMargin));
}
public void addAll(OptionBlock[] blocks) {
for(OptionBlock block : blocks) {
int x0 = this.x;
int width = this.itemWidth;
int height = this.itemHeight;
Option<?>[] options = block.options();
for(Option<?> option : options) {
int margin = this.itemMargin;
OptionWidget<?> optionWidget = option.getWidget();
optionWidget.setDimensions(x0, 0, width, height);
this.addEntry(new Entry(optionWidget, margin));
}
this.addEntry(new Entry((OptionWidget)null, 12));
}
}
private void addEntry(Entry entry) {
this.children.add(entry);
this.listLength += entry.getTotalHeight();
}
public void clearEntries() {
this.listLength = 0;
this.children.clear();
}
protected void updateScrollingState(double mouseX, int button) {
this.scrolling = button == 0 && mouseX >= (double)this.getScrollbarPosition() && mouseX < (double)(this.getScrollbarPosition() + 6);
}
protected float getScrollAmount() {
return this.scrollAmount;
}
public void setScrollAmount(double d) {
this.scrollAmount = (float)class_3532.method_15350(d, (double)0.0F, (double)this.getMaxScroll());
}
private int getItemCount() {
return this.children.size();
}
class_364 getFocused() {
return this.focused;
}
void setFocused(Entry focussed) {
this.focused = focussed;
}
public boolean method_25402(class_11909 event, boolean bl) {
this.updateScrollingState(event.comp_4798(), event.method_74245());
if (this.method_25405(event.comp_4798(), event.comp_4799())) {
Entry entry = this.getEntryAtPos(event.comp_4798(), event.comp_4799());
if (entry != null && entry.method_25402(event, bl)) {
this.setFocused(entry);
entry.method_25365(true);
return true;
} else {
return event.method_74245() == 0;
}
} else {
return false;
}
}
public boolean method_25406(class_11909 event) {
if (this.isValidClickButton(event.method_74245())) {
Entry entry = this.getEntryAtPos(event.comp_4798(), event.comp_4799());
if (entry != null && entry.method_25406(event)) {
entry.method_25365(false);
this.setFocused((Entry)null);
return true;
}
}
return false;
}
public boolean method_25403(class_11909 event, double deltaX, double deltaY) {
if (event.method_74245() != 0) {
return false;
} else if (this.getFocused() != null) {
return this.getFocused().method_25403(event, deltaX, deltaY);
} else if (!this.scrolling) {
return false;
} else {
double maxScroll = (double)this.getMaxScroll();
if (event.comp_4799() < (double)this.y) {
this.setScrollAmount((double)0.0F);
} else if (event.comp_4799() > (double)this.getBottom()) {
this.setScrollAmount(maxScroll);
} else if (maxScroll > (double)0.0F) {
double barHeight = (double)this.height * (double)this.height / (double)this.getTotalLength();
double scrollFactor = Math.max((double)1.0F, maxScroll / ((double)this.height - barHeight));
this.setScrollAmount((double)this.getScrollAmount() + deltaY * scrollFactor);
}
return true;
}
}
public boolean method_25401(double mouseX, double mouseY, double xScroll, double yScroll) {
this.setScrollAmount((double)this.getScrollAmount() - yScroll * (double)this.totalItemHeight / (double)2.0F);
return true;
}
public int getMaxScroll() {
return Math.max(0, this.getTotalLength() - this.height);
}
protected int getTotalLength() {
return this.listLength;
}
public int getBottom() {
return this.y + this.height;
}
protected @Nullable Entry getEntryAtPos(double x, double y) {
int x0 = this.x;
if (!(x > (double)this.getScrollbarPosition()) && !(x < (double)x0)) {
for(Entry entry : this.children) {
VAbstractWidget widget = entry.widget;
if (widget != null && y >= (double)widget.y && y <= (double)(widget.y + widget.height)) {
return entry;
}
}
return null;
} else {
return null;
}
}
public void updateState(double mX, double mY) {
if (this.focused == null) {
super.updateState(mX, mY);
}
}
public void renderWidget(int mouseX, int mouseY) {
GuiRenderer.enableScissor(this.x, this.y, this.x + this.width, this.y + this.height);
this.renderList(mouseX, mouseY);
GuiRenderer.disableScissor();
int maxScroll = this.getMaxScroll();
if (maxScroll > 0) {
GlStateManager._enableBlend();
int height = this.getHeight();
int totalLength = this.getTotalLength();
int barHeight = (int)((float)(height * height) / (float)totalLength);
barHeight = class_3532.method_15340(barHeight, 32, height - 8);
int scrollAmount = (int)this.getScrollAmount();
int barY = scrollAmount * (height - barHeight) / maxScroll + this.getY();
barY = Math.max(barY, this.getY());
int scrollbarPosition = this.getScrollbarPosition();
int thickness = 3;
int backgroundColor = ColorUtil.ARGB.pack(0.8F, 0.8F, 0.8F, 0.2F);
GuiRenderer.fill(scrollbarPosition, this.getY(), scrollbarPosition + thickness, this.getY() + height, backgroundColor);
int barColor = ColorUtil.ARGB.pack(0.3F, 0.0F, 0.0F, 0.6F);
GuiRenderer.fill(scrollbarPosition, barY, scrollbarPosition + thickness, barY + barHeight, barColor);
}
}
protected int getScrollbarPosition() {
return this.x + this.itemWidth + 5;
}
public VAbstractWidget getHoveredWidget(double mouseX, double mouseY) {
if (this.focused != null) {
return this.focused.widget;
} else if (!this.method_25405(mouseX, mouseY)) {
return null;
} else {
for(Entry entry : this.children) {
VAbstractWidget widget = entry.widget;
if (widget != null && widget.method_25405(mouseX, mouseY)) {
return widget;
}
}
return null;
}
}
protected void renderList(int mouseX, int mouseY) {
int itemCount = this.getItemCount();
int rowTop = this.y - (int)this.getScrollAmount();
for(int j = 0; j < itemCount; ++j) {
int rowBottom = rowTop + this.itemHeight;
Entry entry = this.getEntry(j);
if (rowBottom >= this.y && rowTop <= this.y + this.height) {
boolean updateState = this.focused == null;
entry.render(rowTop, mouseX, mouseY, updateState);
}
rowTop += entry.getTotalHeight();
}
}
private Entry getEntry(int j) {
return (Entry)this.children.get(j);
}
protected boolean isValidClickButton(int i) {
return i == 0;
}
protected static class Entry implements class_364 {
final VAbstractWidget widget;
final int margin;
private Entry(OptionWidget<?> widget, int margin) {
this.widget = widget;
this.margin = margin;
}
public void render(int y, int mouseX, int mouseY, boolean updateState) {
if (this.widget != null) {
this.widget.y = y;
if (updateState) {
this.widget.updateState((double)mouseX, (double)mouseY);
}
this.widget.render((double)mouseX, (double)mouseY);
}
}
public int getTotalHeight() {
return this.widget != null ? this.widget.height + this.margin : this.margin;
}
public boolean method_25402(class_11909 event, boolean bl) {
return this.widget.method_25402(event, bl);
}
public boolean method_25406(class_11909 event) {
return this.widget.method_25406(event);
}
public boolean method_25403(class_11909 event, double deltaX, double deltaY) {
return this.widget.method_25403(event, deltaX, deltaY);
}
public boolean method_25370() {
return false;
}
public void method_25365(boolean bl) {
this.widget.method_25365(bl);
}
}
}
Download file