Jump to content

Recommended Posts

Posted

I want to make a gui with a few pages and buttons which are displayed on the different pages. But this undisplayed buttons overlap others buttons, so I can't interact with them. How to solve this?

Posted
@Override
public void init(Minecraft minecraft, int width, int height) {
	super.init(minecraft, width, height);
	minecraft.keyboardListener.enableRepeatEvents(true);
	this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 30, 32, 32, 192, 0, 128, BUTTONS2, e -> {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue")){
					HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(0, x, y, z));
					ShopGui.handleButtonAction(entity, 0, x, y, z);
					}
			}) {
				@Override
				public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue"))
					super.render(ms, gx, gy, ticks);
			}
			});
	this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 30, 32, 32, 192, 0, 128, BUTTONS2, e -> {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red")){
					HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(1, x, y, z));
					ShopGui.handleButtonAction(entity, 1, x, y, z);
					}
			}) {
				@Override
				public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red"))
					super.render(ms, gx, gy, ticks);
			}
			});
}}

 

Posted

I tried setting the value to false, but it had no effect so I think I'm doing something wrong.

P.S. There's no AbstractWidget in 1.16.5, I only find Widget

Posted

I look more closely at Widget and Button classes, but don't understand how to use the "visible" field so I just tried adding it as ResourseLocation and set it to false, but it did nothing.

Posted (edited)
public class ShopGuiWindow extends ContainerScreen<ShopGui.GuiContainerMod> {
	private World world;
	private int x, y, z;
	private PlayerEntity entity;
	private final static HashMap guistate = ShopGui.guistate;

	public ShopGuiWindow(ShopGui.GuiContainerMod container, PlayerInventory inventory, ITextComponent text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.xSize = 190;
		this.ySize = 166;
	}

	private static final ResourceLocation texture = new ResourceLocation("hyrabw:textures/shop.png");
	private static final ResourceLocation BUTTONS = new ResourceLocation("hyrabw:textures/shop_buttons1.png");
	private static final ResourceLocation BUTTONS2 = new ResourceLocation("hyrabw:textures/shop_buttons2.png");
	public boolean visible = false;


	@Override
	public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderHoveredTooltip(ms, mouseX, mouseY);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.color4f(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);
		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeScreen();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void tick() {
		super.tick();
	}

	@Override
	protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}

	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
		this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 0, 128, BUTTONS2, e -> {
			if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red")) {
				HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(0, x, y, z));
				ShopGui.handleButtonAction(entity, 0, x, y, z);
			}
		}) {
			@Override
			public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red"))
					super.render(ms, gx, gy, ticks);
			}
		});
		this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 32, 128, BUTTONS2, e -> {
			if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue")) {
				HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(1, x, y, z));
				ShopGui.handleButtonAction(entity, 1, x, y, z);
			}
		}) {
			@Override
			public void renderButton(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue"))
					super.renderButton(ms, gx, gy, ticks);
			}
		});
	}
}

 

Edited by Hyrancood
Posted
  Quote

This makes zero sense. Also, why is it static? Why is it using raw types?

Expand  

Because I use Mcreator to base my code. It works, so I haven't paid much attention to it.

  Quote

Why did you add this? It is entirely unused. You must set the visible field on the button instance. And you are still overriding render.

Expand  

I searched visible field in ImageButton constructors, but I still don't know where I'm supposed to put it.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.