Jump to content

[Solved] [1.8] Textures of radio buttons go black


Earthcomputer

Recommended Posts

Anyone have any idea why my second radio button is going black? The first radio button above it isn't going black.

 

Screenshot:

http://imgur.com/k2xqGA5

Radio button texture:

http://imgur.com/0MIZeW3

Code:

 

 

Draw method in CommandSlotCommand (the orange rectangle)

@Override
public void draw(int x, int y, int mouseX, int mouseY, float partialTicks) {
GlStateManager.disableLighting();
GlStateManager.disableFog();

Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 0, 1);
GlStateManager.disableAlpha();
GlStateManager.shadeModel(GL11.GL_SMOOTH);

drawRect(x, y, x + getWidth(), y + getHeight(), 0xffc08000);
drawHorizontalLine(x, x + getWidth(), y, 0xff000000);
drawHorizontalLine(x, x + getWidth(), y + getHeight(), 0xff000000);
drawVerticalLine(x, y, y + getHeight(), 0xff000000);
drawVerticalLine(x + getWidth(), y, y + getHeight(), 0xff000000);

FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
int height = 3;
for (IGuiCommandSlot child : children) {
	child.draw(x + 3, y + height, mouseX, mouseY, partialTicks);
	height += child.getHeight() + 2;
}

GlStateManager.enableTexture2D();
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}

 

CommandSlotRadioList.java:

package net.earthcomputer.easyeditors.gui.command;

import java.util.List;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import net.earthcomputer.easyeditors.gui.ISizeChangeListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;

public abstract class CommandSlotRadioList extends GuiCommandSlotImpl implements ISizeChangeListener {

private static final ResourceLocation radioButtonLocation = new ResourceLocation(
		"easyeditors:textures/gui/radio_button.png");

private List<IGuiCommandSlot> children;
private int[] heights;
private int[] childTops;
private int[] buttonTops;

private int selectedIndex = 0;

private int x;
private int y;

public CommandSlotRadioList(IGuiCommandSlot... children) {
	super(calcWidth(children), calcHeight(children));
	this.children = Lists.newArrayList(children);
	for (IGuiCommandSlot child : children) {
		child.addSizeChangeListener(this);
	}
	heights = new int[children.length];
	childTops = new int[children.length];
	buttonTops = new int[children.length];
	refreshHeights();
}

private static int calcWidth(IGuiCommandSlot[] children) {
	int max = 0;
	for (IGuiCommandSlot child : children) {
		if (child.getWidth() > max)
			max = child.getWidth();
	}
	return max + 20;
}

private static int calcHeight(IGuiCommandSlot[] children) {
	int total = children.length == 0 ? 0 : children.length * 2 - 2;
	for (IGuiCommandSlot child : children) {
		total += child.getHeight() > 16 ? child.getHeight() : 16;
	}
	return total;
}

public int getSelectedIndex() {
	return selectedIndex;
}

public void setSelectedIndex(int selectedIndex) {
	this.selectedIndex = selectedIndex;
}

@Override
public boolean canReadFromString() {
	return !children.isEmpty() && Iterables.all(children, new Predicate<IGuiCommandSlot>() {
		@Override
		public boolean apply(IGuiCommandSlot child) {
			return child.canReadFromString();
		}
	});
}

@Override
public void readFromString(String rawCommand) throws CommandSyntaxException {
	if (!children.isEmpty()) {
		selectedIndex = getSelectedIndexForString(rawCommand);
		children.get(selectedIndex).readFromString(rawCommand);
	}
}

@Override
public String getText() {
	return children.isEmpty() ? "" : children.get(selectedIndex).getText();
}

@Override
public boolean isEmpty() {
	return children.isEmpty() || children.get(selectedIndex).isEmpty();
}

@Override
public void draw(int x, int y, int mouseX, int mouseY, float partialTicks) {
	this.x = x;
	this.y = y;
	for (int i = 0; i < children.size(); i++) {
		IGuiCommandSlot child = children.get(i);
		Minecraft.getMinecraft().getTextureManager().bindTexture(radioButtonLocation);
		drawModalRectWithCustomSizedTexture(x, y + buttonTops[i], i == selectedIndex ? 16 : 0,
				mouseX >= x && mouseY >= y + buttonTops[i] && mouseX < x + 16 && mouseY < y + buttonTops[i] + 16
						? 16 : 0,
				16, 16, 32, 32);
		child.draw(x + 20, y + childTops[i], mouseX, mouseY, partialTicks);
	}
}

protected abstract int getSelectedIndexForString(String rawCommand) throws CommandSyntaxException;

@Override
public void onKeyTyped(char typedChar, int keyCode) {
	if (!children.isEmpty())
		children.get(selectedIndex).onKeyTyped(typedChar, keyCode);
}

@Override
public void onMouseClicked(int mouseX, int mouseY, int mouseButton) {
	boolean clickedButton = false;
	if (mouseX >= x && mouseX < x + 16) {
		for (int i = 0; i < buttonTops.length; i++) {
			if (mouseY >= y + buttonTops[i] && mouseY < y + buttonTops[i] + 16) {
				clickedButton = true;
				selectedIndex = i;
				break;
			}
		}
	}
	if (!clickedButton && !children.isEmpty()) {
		children.get(selectedIndex).onMouseClicked(mouseX, mouseY, mouseButton);
	}
}

@Override
public void onMouseReleased(int mouseX, int mouseY, int mouseButton) {
	if (!children.isEmpty())
		children.get(selectedIndex).onMouseReleased(mouseX, mouseY, mouseButton);
}

@Override
public void onMouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
	if (!children.isEmpty())
		children.get(selectedIndex).onMouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}

@Override
public void onWidthChange(int oldWidth, int newWidth) {
	int max = 0;
	for (IGuiCommandSlot child : children) {
		if (child.getWidth() > max)
			max = child.getWidth();
	}
	setWidth(max + 20);
}

@Override
public void onHeightChange(int oldHeight, int newHeight) {
	int total = children.size() == 0 ? 0 : children.size() * 2 - 2;
	for (IGuiCommandSlot child : children) {
		total += child.getHeight() > 16 ? child.getHeight() : 16;
	}
	setHeight(total);
	refreshHeights();
}

private void refreshHeights() {
	int height = 0;
	for (int i = 0; i < heights.length; i++) {
		IGuiCommandSlot child = children.get(i);
		if (child.getHeight() > 16) {
			heights[i] = child.getHeight();
			childTops[i] = height;
			buttonTops[i] = height + child.getHeight() / 2 - 8;
		} else {
			heights[i] = 16;
			childTops[i] = height + 8 - child.getHeight() / 2;
			buttonTops[i] = height;
		}
		height += heights[i];
		height += 2;
	}
}

}

 

The draw method of CommandSlotTextField (the black rectangles to the right of the radio buttons)

@Override
public void draw(int x, int y, int mouseX, int mouseY, float partialTicks) {
	if (x != this.x || y != this.y) {
		this.x = x;
		this.y = y;
		onTextChanged();
	}
	wrappedTextField.drawTextBox(); // GuiTextField.drawTextBox()
}

 

 

 

Thanks in advance for help :)

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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