use of net.minecraft.client.gui.components.events.GuiEventListener in project BuildingGadgets by Direwolf20-MC.
the class ModeRadialMenu method render.
@Override
public void render(PoseStack matrices, int mx, int my, float partialTicks) {
float stime = 5F;
float fract = Math.min(stime, this.timeIn + partialTicks) / stime;
int x = this.width / 2;
int y = this.height / 2;
int radiusMin = 26;
int radiusMax = 60;
double dist = new Vec3(x, y, 0).distanceTo(new Vec3(mx, my, 0));
boolean inRange = false;
if (this.segments != 0) {
inRange = dist > radiusMin && dist < radiusMax;
for (GuiEventListener button : children()) {
if (button instanceof PositionedIconActionable) {
((PositionedIconActionable) button).setFaded(inRange);
}
}
}
// This triggers the animation on creation
matrices.pushPose();
matrices.translate((1 - fract) * x, (1 - fract) * y, 0);
matrices.scale(fract, fract, fract);
super.render(matrices, mx, my, partialTicks);
matrices.popPose();
if (this.segments == 0) {
return;
}
float angle = mouseAngle(x, y, mx, my);
float totalDeg = 0;
float degPer = 360F / this.segments;
List<NameDisplayData> nameData = new ArrayList<>();
ItemStack tool = this.getGadget();
if (tool.isEmpty()) {
return;
}
this.slotSelected = -1;
List<ResourceLocation> signs;
int modeIndex;
if (tool.getItem() instanceof GadgetBuilding) {
modeIndex = GadgetBuilding.getToolMode(tool).ordinal();
signs = Arrays.stream(BuildingModes.values()).map(e -> new ResourceLocation(Reference.MODID, e.getIcon())).collect(Collectors.toList());
} else if (tool.getItem() instanceof GadgetExchanger) {
modeIndex = GadgetExchanger.getToolMode(tool).ordinal();
signs = Arrays.stream(ExchangingModes.values()).map(e -> new ResourceLocation(Reference.MODID, e.getIcon())).collect(Collectors.toList());
} else {
modeIndex = GadgetCopyPaste.getToolMode(tool).ordinal();
signs = signsCopyPaste;
}
boolean shouldCenter = (this.segments + 2) % 4 == 0;
int indexBottom = this.segments / 4;
int indexTop = indexBottom + this.segments / 2;
for (int seg = 0; seg < this.segments; seg++) {
boolean mouseInSector = this.isCursorInSlice(angle, totalDeg, degPer, inRange);
float radius = Math.max(0F, Math.min((this.timeIn + partialTicks - seg * 6F / this.segments) * 40F, radiusMax));
float gs = 0.25F;
if (seg % 2 == 0) {
gs += 0.1F;
}
float r = gs;
float g = gs + (seg == modeIndex ? 1F : 0.0F);
float b = gs;
float a = 0.4F;
if (mouseInSector) {
this.slotSelected = seg;
r = g = b = 1F;
}
MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource();
VertexConsumer buffer = bufferSource.getBuffer(OurRenderTypes.TRIANGLE_STRIP);
for (float i = degPer; i >= 0; i--) {
float rad = (float) ((i + totalDeg) / 180F * Math.PI);
float xp = (float) (x + Math.cos(rad) * radius);
float yp = (float) (y + Math.sin(rad) * radius);
if ((int) i == (int) (degPer / 2))
nameData.add(new NameDisplayData((int) xp, (int) yp, mouseInSector, shouldCenter && (seg == indexBottom || seg == indexTop)));
Matrix4f pose = matrices.last().pose();
buffer.vertex(pose, (float) (x + Math.cos(rad) * radius / 2.3F), (float) (y + Math.sin(rad) * radius / 2.3F), 0).color(r, g, b, a).endVertex();
buffer.vertex(xp, yp, 0).color(r, g, b, a).endVertex();
}
bufferSource.endBatch(OurRenderTypes.TRIANGLE_STRIP);
totalDeg += degPer;
}
// This is the naming logic for the text that pops up
for (int i = 0; i < nameData.size(); i++) {
matrices.pushPose();
NameDisplayData data = nameData.get(i);
int xp = data.getX();
int yp = data.getY();
String name;
if (tool.getItem() instanceof GadgetBuilding) {
name = ForgeI18n.getPattern(BuildingModes.values()[i].getTranslationKey());
} else if (tool.getItem() instanceof GadgetExchanger) {
name = ForgeI18n.getPattern(ExchangingModes.values()[i].getTranslationKey());
} else {
name = GadgetCopyPaste.ToolMode.values()[i].getTranslation().format();
}
int xsp = xp - 4;
int ysp = yp;
int width = font.width(name);
if (xsp < x) {
xsp -= width - 8;
}
if (ysp < y) {
ysp -= 9;
}
Color color = i == modeIndex ? Color.GREEN : Color.WHITE;
if (data.isSelected())
font.drawShadow(matrices, name, xsp + (data.isCentralized() ? width / 2f - 4 : 0), ysp, color.getRGB());
double mod = 0.7;
int xdp = (int) ((xp - x) * mod + x);
int ydp = (int) ((yp - y) * mod + y);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, 1);
RenderSystem.setShaderTexture(0, signs.get(i));
blit(matrices, xdp - 8, ydp - 8, 0, 0, 16, 16, 16, 16);
matrices.popPose();
}
float s = 1.8F * fract;
PoseStack stack = RenderSystem.getModelViewStack();
stack.pushPose();
stack.scale(s, s, s);
matrices.popPose();
stack.translate(x / s - (tool.getItem() instanceof GadgetCopyPaste ? 8 : 8.5), y / s - 8, 0);
this.itemRenderer.renderAndDecorateItem(tool, 0, 0);
stack.popPose();
}
use of net.minecraft.client.gui.components.events.GuiEventListener in project BuildingGadgets by Direwolf20-MC.
the class ModeRadialMenu method updateButtons.
private void updateButtons(ItemStack tool) {
int posRight = 0;
int posLeft = 0;
int dim = 24;
int padding = 10;
boolean isDestruction = tool.getItem() instanceof GadgetDestruction;
ScreenPosition right = isDestruction ? ScreenPosition.BOTTOM : ScreenPosition.RIGHT;
for (GuiEventListener widget : children()) {
if (!(widget instanceof PositionedIconActionable))
continue;
PositionedIconActionable button = (PositionedIconActionable) widget;
if (!button.visible) {
continue;
}
int offset;
boolean isRight = button.position == right;
if (isRight) {
posRight += dim + padding;
offset = 70;
} else {
posLeft += dim + padding;
offset = -70 - dim;
}
button.setWidth(dim);
button.setHeight(dim);
if (isDestruction)
button.y = height / 2 + (isRight ? 10 : -button.getHeight() - 10);
else
button.x = width / 2 + offset;
}
posRight = resetPos(tool, padding, posRight);
posLeft = resetPos(tool, padding, posLeft);
for (GuiEventListener widget : children()) {
if (!(widget instanceof PositionedIconActionable))
continue;
PositionedIconActionable button = (PositionedIconActionable) widget;
if (!button.visible) {
continue;
}
boolean isRight = button.position == right;
int pos = isRight ? posRight : posLeft;
if (isDestruction) {
button.x = pos;
} else {
button.y = pos;
}
if (isRight) {
posRight += dim + padding;
} else {
posLeft += dim + padding;
}
}
}
use of net.minecraft.client.gui.components.events.GuiEventListener in project TAS-Battle by MCPfannkuchenYT.
the class TASBattleScreen method init.
/**
* Adds all TASBattle Widgets
*/
@Override
protected void init() {
int x = 5;
for (int i = 0; i < TASBattle.servers.size(); i++) {
int FUCKYOUJAVAIWILLKILLYOU = i;
btns.add(addRenderableWidget(new Button(x, 35, 20, 20, new TextComponent(""), b -> {
for (GuiEventListener btnl : new ArrayList<>(children())) if (btns.contains(btnl))
((Button) btnl).active = true;
b.active = false;
/* Add Labels */
selected = TASBattle.servers.get(FUCKYOUJAVAIWILLKILLYOU);
}) {
ResourceLocation loc = new ResourceLocation("textures/" + TASBattle.servers.get(FUCKYOUJAVAIWILLKILLYOU).item + ".png");
@Override
public void renderButton(PoseStack poseStack, int i, int j, float f) {
super.renderButton(poseStack, i, j, f);
if (this.isHovered()) {
this.renderToolTip(poseStack, i, j);
}
// how to draw image 101
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, loc);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
RenderSystem.enableTexture();
blit(poseStack, x + 2, y + 2, 0, 0, 16, 16, 16, 16);
}
}));
x += 20;
}
addRenderableWidget(new Button(5, height - 30, 250, 20, new TextComponent("Connect to the server"), b -> {
ConnectScreen.startConnecting(this, minecraft, new ServerAddress("mgnet.work", 25567), new ServerData("asd", "mgnet.work:25567", false));
}));
addRenderableWidget(new Button(255, height - 30, width - 260, 20, new TextComponent("Connect to the anarchy server"), b -> {
ConnectScreen.startConnecting(this, minecraft, new ServerAddress("mgnet.work", 25568), new ServerData("asd", "mgnet.work:25568", false));
}));
}
use of net.minecraft.client.gui.components.events.GuiEventListener in project Cyclic by Lothrazar.
the class ScreenBase method drawButtonTooltips.
public void drawButtonTooltips(PoseStack ms, int mouseX, int mouseY) {
for (GuiEventListener btn : this.children()) {
if (btn instanceof IHasTooltip && btn.isMouseOver(mouseX, mouseY) && btn instanceof AbstractWidget) {
((AbstractWidget) btn).renderToolTip(ms, mouseX, mouseY);
List<Component> localTooltip = ((IHasTooltip) btn).getTooltip();
if (localTooltip != null) {
this.renderComponentTooltip(ms, localTooltip, mouseX - leftPos, mouseY - topPos);
}
}
}
for (GuiEventListener widget : this.children()) {
if (widget instanceof IHasTooltip && widget.isMouseOver(mouseX, mouseY)) {
IHasTooltip txt = (IHasTooltip) widget;
if (txt.getTooltip() != null) {
this.renderComponentTooltip(ms, txt.getTooltip(), mouseX - leftPos, mouseY - topPos);
}
}
}
}
use of net.minecraft.client.gui.components.events.GuiEventListener in project RoughlyEnoughItems by shedaniel.
the class DraggableWidget method mouseDragged.
@Override
public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
Point mouse = PointHelper.ofMouse();
if (int_1 == 0) {
if (!dragged) {
if (getGrabBounds().contains(mouse)) {
startPoint = new Point(midPoint.x, midPoint.y);
relateX = mouse.x - midPoint.x;
relateY = mouse.y - midPoint.y;
dragged = true;
}
} else {
Window window = minecraft.getWindow();
midPoint = processMidPoint(midPoint, mouse, startPoint, window, relateX, relateY);
updateWidgets(midPoint);
}
return true;
}
for (GuiEventListener listener : children()) if (listener.mouseDragged(double_1, double_2, int_1, double_3, double_4))
return true;
return false;
}
Aggregations