Rename a couple methods and fix some unintended GL color state "leaks"

This commit is contained in:
pupnewfster committed 2019-07-08 11:48:14 -04:00
1 parent a872655ec6
commit d8a75fa4e8
6 files changed
+30 -15

No files matched your search

@@ -70,10 +70,17 @@ public abstract class GuiMekanism extends GuiContainer implements IGuiWrapper {
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
int xAxis = mouseX - guiLeft;
int yAxis = mouseY - guiTop;
guiElements.forEach(element -> element.renderForeground(xAxis, yAxis));
//Ensure that the GL color is white, as drawing rectangles, text boxes, or even text might have changed the color from
// what we assume it is at the start. This prevents any unintentional color state leaks. GlStateManager, will ensure that
// GL changes only get ran if it is not already the color we are assuming it is.
GLSMHelper.INSTANCE.resetColor();
guiElements.forEach(element -> {
element.renderForeground(xAxis, yAxis);
//Continue ensuring color is what we are assuming.
GLSMHelper.INSTANCE.resetColor();
});
}
protected boolean isMouseOverSlot(Slot slot, int mouseX, int mouseY) {
@@ -90,7 +97,15 @@ public abstract class GuiMekanism extends GuiContainer implements IGuiWrapper {
int xAxis = mouseX - guiLeft;
int yAxis = mouseY - guiTop;
drawGuiContainerBackgroundLayer(xAxis, yAxis);
guiElements.forEach(element -> element.renderBackground(xAxis, yAxis, guiLeft, guiTop));
//Ensure that the GL color is white, as drawing rectangles, text boxes, or even text might have changed the color from
// what we assume it is at the start. This prevents any unintentional color state leaks. GlStateManager, will ensure that
// GL changes only get ran if it is not already the color we are assuming it is.
GLSMHelper.INSTANCE.resetColor();
guiElements.forEach(element -> {
element.renderBackground(xAxis, yAxis, guiLeft, guiTop);
//Continue ensuring color is what we are assuming.
GLSMHelper.INSTANCE.resetColor();
});
}
@Override
@@ -63,12 +63,12 @@ public abstract class GuiGauge<T> extends GuiElement {
mc.renderEngine.bindTexture(RESOURCE);
guiObj.drawTexturedRect(guiWidth + xLocation, guiHeight + yLocation, texX, texY, width, height);
if (!dummy) {
renderScale(xAxis, yAxis, guiWidth, guiHeight);
renderScale(guiWidth, guiHeight);
}
mc.renderEngine.bindTexture(defaultLocation);
}
public void renderScale(int xAxis, int yAxis, int guiWidth, int guiHeight) {
public void renderScale(int guiWidth, int guiHeight) {
if (getScaledLevel() == 0 || getIcon() == null) {
guiObj.drawTexturedRect(guiWidth + xLocation, guiHeight + yLocation, width, 0, width, height);
return;
@@ -46,7 +46,7 @@ public abstract class GuiFilterBase<FILTER extends IFilter, TILE extends TileEnt
}
}
protected void drawRect(int xAxis, int yAxis, int xMin, int xMax, int yMin, int yMax) {
protected void drawPositionedRect(int xAxis, int yAxis, int xMin, int xMax, int yMin, int yMax) {
if (xAxis >= xMin && xAxis <= xMax && yAxis >= yMin && yAxis <= yMax) {
int x = guiLeft + xMin;
int y = guiTop + yMin;
@@ -70,7 +70,7 @@ public abstract class GuiTextFilter<FILTER extends IFilter, TILE extends TileEnt
if (tileEntity instanceof TileEntityDigitalMiner) {
drawTexturedModalRect(guiLeft + 148, guiTop + 45, 199, xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59, 14);
text.drawTextBox();
drawRect(xAxis, yAxis, 149, 165, 19, 35);
drawPositionedRect(xAxis, yAxis, 149, 165, 19, 35);
} else if (tileEntity instanceof TileEntityLogisticalSorter) {
drawTexturedModalRect(guiLeft + 11, guiTop + 64, 199, xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75, 11);
text.drawTextBox();
@@ -24,12 +24,12 @@ public abstract class GuiTypeFilter<FILTER extends IFilter, TILE extends TileEnt
if (tileEntity instanceof TileEntityDigitalMiner) {
drawTexturedModalRect(guiLeft + 148, guiTop + 45, 199, xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59, 14);
drawItemStackBackground(xAxis, yAxis);
drawRect(xAxis, yAxis, 149, 165, 19, 35);
drawPositionedRect(xAxis, yAxis, 149, 165, 19, 35);
} else if (tileEntity instanceof TileEntityLogisticalSorter) {
drawTexturedModalRect(guiLeft + 11, guiTop + 64, 198, xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75, 11);
drawItemStackBackground(xAxis, yAxis);
}
drawRect(xAxis, yAxis, 12, 28, 19, 35);
drawPositionedRect(xAxis, yAxis, 12, 28, 19, 35);
}
protected abstract void drawForegroundLayer(int mouseX, int mouseY);
@@ -36,14 +36,14 @@ public abstract class GuiRobit extends GuiMekanism {
@Override
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
boolean correctX = xAxis >= 179 && xAxis <= 197;
drawRect(correctX, yAxis, 10, 0);
drawRect(correctX, yAxis, 30, 36);
drawRect(correctX, yAxis, 50, 72);
drawRect(correctX, yAxis, 70, 108);
drawRect(correctX, yAxis, 90, 144);
drawPositionedRect(correctX, yAxis, 10, 0);
drawPositionedRect(correctX, yAxis, 30, 36);
drawPositionedRect(correctX, yAxis, 50, 72);
drawPositionedRect(correctX, yAxis, 70, 108);
drawPositionedRect(correctX, yAxis, 90, 144);
}
private void drawRect(boolean correctX, int yAxis, int heightBonus, int textureY) {
private void drawPositionedRect(boolean correctX, int yAxis, int heightBonus, int textureY) {
int yBonus = correctX && yAxis >= heightBonus && yAxis <= heightBonus + 18 ? 0 : 18;
drawTexturedModalRect(guiLeft + 179, guiTop + heightBonus, 201, textureY + yBonus, 18, 18);
}