Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ButtonList {
- public int xPos;
- public int yPos;
- public int height;
- public int width;
- public int itemHeight;
- public int itemWidth;
- public int scrollPos = 0;
- public TabButton button;
- public boolean active = false;
- Map<String, ? extends BeepediaPage> list;
- Map<String, BeepediaPage> reducedList = new HashMap<>();
- public ButtonList(int xPos, int yPos, int height, int width, int itemHeight, int itemWidth, TabButton button, Map<String, ? extends BeepediaPage> list) {
- this.xPos = xPos;
- this.yPos = yPos;
- this.height = height;
- this.width = width;
- this.itemHeight = itemHeight;
- this.itemWidth = itemWidth;
- this.list = list;
- this.button = button;
- updateReducedList(null);
- list.forEach((s, b) -> b.listButton.setParent(this));
- }
- public void updateReducedList(String search) {
- reducedList.clear();
- if (search != null && !search.isEmpty() && !search.equals("")) {
- list.forEach((s, b) -> {
- if (s.contains(search.toLowerCase()) || b.getTranslation().toLowerCase().contains(search.toLowerCase())) {
- reducedList.put(s, b);
- }
- });
- } else {
- reducedList = new HashMap<>(list);
- }
- }
- public void updatePos(int newPos) {
- // update position of list
- if (height > reducedList.size() * 20) return;
- scrollPos -= newPos;
- if (scrollPos > 0) scrollPos = 0;
- else if (scrollPos < -(reducedList.size() * 20 - height)) scrollPos = -(reducedList.size() * 20 - height);
- }
- public void updateList() {
- // update each button
- AtomicInteger counter = new AtomicInteger();
- reducedList.forEach((s, b) -> {
- b.updateListPosition(xPos, (yPos + scrollPos + counter.get() * itemHeight));
- counter.getAndIncrement();
- });
- }
- public void setActive(boolean active) {
- this.active = active;
- list.forEach((s, b) -> {
- if (b.listButton != null) b.listButton.visible = active;
- });
- }
- }
- public class ListButton extends TabImageButton {
- private final TextComponent text;
- private final int textX;
- private final int textY;
- private FontRenderer fontRenderer;
- private BeepediaScreen.ButtonList parent = null;
- public ListButton(int xIn, int yIn, int widthIn, int heightIn, int xTexStartIn, int yTexStartIn, int yDiffTextIn, ResourceLocation resourceLocationIn, @NotNull ItemStack displayItem, int itemX, int itemY, TextComponent text, int textX, int textY, IPressable onPressIn) {
- super(xIn, yIn, widthIn, heightIn, xTexStartIn, yTexStartIn, yDiffTextIn, resourceLocationIn, displayItem, itemX, itemY, onPressIn);
- this.text = text;
- this.textX = textX;
- this.textY = textY;
- this.fontRenderer = Minecraft.getInstance().fontRenderer;
- }
- public void setParent(BeepediaScreen.ButtonList parent) {
- this.parent = parent;
- }
- @Override
- public void renderButton(@Nonnull MatrixStack matrix, int p_renderButton_1_, int p_renderButton_2_, float p_renderButton_3_) {
- Minecraft minecraft = Minecraft.getInstance();
- minecraft.getTextureManager().bindTexture(this.resourceLocation);
- RenderSystem.disableDepthTest();
- int i = this.yTexStart;
- if (!this.active) {
- i += yDiffText * 2;
- } else if (this.isHovered()) {
- i += this.yDiffText;
- }
- if (parent != null) {
- double scale = minecraft.getWindow().getGuiScaleFactor();
- GL11.glEnable(GL11.GL_SCISSOR_TEST);
- GL11.glScissor((int) (parent.xPos * scale), (int) (parent.yPos * scale), (int) (parent.width * scale), (int) (parent.height * scale));
- }
- drawTexture(matrix, this.x, this.y, (float) this.xTexStart, (float) i, this.width, this.height, 128, 128);
- fontRenderer.draw(matrix, text, this.x + textX, this.y + textY, Color.parse("white").getRgb());
- if (this.displayItem != null)
- Minecraft.getInstance().getItemRenderer().renderItemAndEffectIntoGUI(this.displayItem, this.x + this.itemX, this.y + this.itemY);
- RenderSystem.enableDepthTest();
- if (parent != null) GL11.glDisable(GL11.GL_SCISSOR_TEST);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment