71 lines
2.2 KiB
Java
71 lines
2.2 KiB
Java
package com.mojang.realmsclient.gui;
|
|
|
|
import java.util.List;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.gui.components.AbstractSelectionList;
|
|
import net.minecraft.client.gui.components.ObjectSelectionList;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public abstract class RowButton {
|
|
public final int width;
|
|
public final int height;
|
|
public final int xOffset;
|
|
public final int yOffset;
|
|
|
|
public RowButton(int width, int height, int xOffset, int yOffset) {
|
|
this.width = width;
|
|
this.height = height;
|
|
this.xOffset = xOffset;
|
|
this.yOffset = yOffset;
|
|
}
|
|
|
|
public void drawForRowAt(GuiGraphics guiGraphics, int x, int y, int mouseX, int mouseY) {
|
|
int i = x + this.xOffset;
|
|
int j = y + this.yOffset;
|
|
boolean bl = mouseX >= i && mouseX <= i + this.width && mouseY >= j && mouseY <= j + this.height;
|
|
this.draw(guiGraphics, i, j, bl);
|
|
}
|
|
|
|
protected abstract void draw(GuiGraphics guiGraphics, int x, int y, boolean showTooltip);
|
|
|
|
public int getRight() {
|
|
return this.xOffset + this.width;
|
|
}
|
|
|
|
public int getBottom() {
|
|
return this.yOffset + this.height;
|
|
}
|
|
|
|
public abstract void onClick(int index);
|
|
|
|
public static void drawButtonsInRow(
|
|
GuiGraphics guiGraphics, List<RowButton> rowButtons, AbstractSelectionList<?> pendingInvitations, int x, int y, int mouseX, int mouseY
|
|
) {
|
|
for (RowButton rowButton : rowButtons) {
|
|
if (pendingInvitations.getRowWidth() > rowButton.getRight()) {
|
|
rowButton.drawForRowAt(guiGraphics, x, y, mouseX, mouseY);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void rowButtonMouseClicked(
|
|
AbstractSelectionList<?> pendingInvitations, ObjectSelectionList.Entry<?> entry, List<RowButton> rowButtons, int button, double mouseX, double mouseY
|
|
) {
|
|
int i = pendingInvitations.children().indexOf(entry);
|
|
if (i > -1) {
|
|
pendingInvitations.setSelectedIndex(i);
|
|
int j = pendingInvitations.getRowLeft();
|
|
int k = pendingInvitations.getRowTop(i);
|
|
int l = (int)(mouseX - j);
|
|
int m = (int)(mouseY - k);
|
|
|
|
for (RowButton rowButton : rowButtons) {
|
|
if (l >= rowButton.xOffset && l <= rowButton.getRight() && m >= rowButton.yOffset && m <= rowButton.getBottom()) {
|
|
rowButton.onClick(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|