Started work on a scroll list GUI element
This commit is contained in:
parent
c66f3a44b7
commit
89bc7edc95
|
@ -21,12 +21,16 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
public class GuiDictionary extends GuiMekanism
|
||||
{
|
||||
public ItemStack itemType;
|
||||
|
||||
public GuiScrollList scrollList;
|
||||
|
||||
public List<String> oreDictNames;
|
||||
|
||||
public GuiDictionary(InventoryPlayer inventory)
|
||||
{
|
||||
super(new ContainerDictionary(inventory));
|
||||
|
||||
guiElements.add(scrollList = new GuiScrollList(this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalOxidizer.png"), 8, 30, 160, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,28 +42,11 @@ public class GuiDictionary extends GuiMekanism
|
|||
fontRendererObj.drawString(MekanismUtils.localize("item.Dictionary.name"), 64, 5, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, ySize - 96 + 2, 0x404040);
|
||||
|
||||
if(itemType != null)
|
||||
{
|
||||
if(!oreDictNames.isEmpty())
|
||||
{
|
||||
int currentY = 57;
|
||||
|
||||
for(String name : oreDictNames)
|
||||
{
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.key") + ": " + name, 9, currentY, 0x00CD00);
|
||||
currentY += 9;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.dictionary.noKey"), 9, 57, 0x00CD00);
|
||||
}
|
||||
}
|
||||
|
||||
if(itemType != null)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), itemType, 80, 23);
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), itemType, 6, 6);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
@ -70,8 +57,6 @@ public class GuiDictionary extends GuiMekanism
|
|||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
||||
{
|
||||
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
||||
|
||||
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiDictionary.png"));
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
int guiWidth = (width - xSize) / 2;
|
||||
|
@ -81,20 +66,22 @@ public class GuiDictionary extends GuiMekanism
|
|||
int xAxis = mouseX - guiWidth;
|
||||
int yAxis = mouseY - guiHeight;
|
||||
|
||||
if(xAxis >= 80 && xAxis <= 96 && yAxis >= 23 && yAxis <= 39)
|
||||
if(xAxis >= 6 && xAxis <= 22 && yAxis >= 6 && yAxis <= 22)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
int x = guiWidth + 80;
|
||||
int y = guiHeight + 23;
|
||||
int x = guiWidth + 6;
|
||||
int y = guiHeight + 6;
|
||||
drawGradientRect(x, y, x + 16, y + 16, -2130706433, -2130706433);
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +122,7 @@ public class GuiDictionary extends GuiMekanism
|
|||
itemType = stack.copy();
|
||||
itemType.stackSize = 1;
|
||||
|
||||
oreDictNames = MekanismUtils.getOreDictName(itemType);
|
||||
scrollList.setText(MekanismUtils.getOreDictName(itemType));
|
||||
SoundHandler.playSound("gui.button.press");
|
||||
|
||||
return;
|
||||
|
@ -143,7 +130,7 @@ public class GuiDictionary extends GuiMekanism
|
|||
}
|
||||
}
|
||||
|
||||
if(xAxis >= 80 && xAxis <= 96 && yAxis >= 23 && yAxis <= 39)
|
||||
if(xAxis >= 6 && xAxis <= 22 && yAxis >= 6 && yAxis <= 22)
|
||||
{
|
||||
ItemStack stack = mc.thePlayer.inventory.getItemStack();
|
||||
|
||||
|
@ -152,7 +139,7 @@ public class GuiDictionary extends GuiMekanism
|
|||
itemType = stack.copy();
|
||||
itemType.stackSize = 1;
|
||||
|
||||
oreDictNames = MekanismUtils.getOreDictName(itemType);
|
||||
scrollList.setText(MekanismUtils.getOreDictName(itemType));
|
||||
}
|
||||
else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
||||
{
|
||||
|
|
142
src/main/java/mekanism/client/gui/GuiScrollList.java
Normal file
142
src/main/java/mekanism/client/gui/GuiScrollList.java
Normal file
|
@ -0,0 +1,142 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiScrollList extends GuiElement
|
||||
{
|
||||
public int xSize;
|
||||
public int size;
|
||||
|
||||
public int xPosition;
|
||||
public int yPosition;
|
||||
|
||||
public List<String> textEntries = new ArrayList<String>();
|
||||
|
||||
public int scrollIndex;
|
||||
|
||||
public GuiScrollList(IGuiWrapper gui, ResourceLocation def, int x, int y, int sizeX, int sizeY)
|
||||
{
|
||||
super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiScrollList.png"), gui, def);
|
||||
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
|
||||
xSize = sizeX;
|
||||
size = sizeY;
|
||||
}
|
||||
|
||||
public void setText(List<String> text)
|
||||
{
|
||||
if(text == null)
|
||||
{
|
||||
textEntries.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
textEntries = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle4i getBounds(int guiWidth, int guiHeight)
|
||||
{
|
||||
return new Rectangle4i(guiWidth - 26, guiHeight + 6, 26, 26);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight)
|
||||
{
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
|
||||
drawBlack(guiWidth, guiHeight);
|
||||
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
public void drawBlack(int guiWidth, int guiHeight)
|
||||
{
|
||||
int xDisplays = xSize/10 + (xSize%10 > 0 ? 1 : 0);
|
||||
|
||||
for(int yIter = 0; yIter < size; yIter++)
|
||||
{
|
||||
for(int xIter = 0; xIter < xDisplays; xIter++)
|
||||
{
|
||||
int width = (xSize%10 > 0 && xIter == xDisplays ? xSize%10 : 10);
|
||||
guiObj.drawTexturedRect(guiWidth + xPosition + (xIter*10), guiHeight + yPosition + (yIter*10), 0, 0, width, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScroll()
|
||||
{
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
int xStart = xPosition + xSize - 6;
|
||||
int yStart = yPosition;
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
guiObj.drawTexturedRect(xStart, yStart+(i*10), 10, 1, 6, 10);
|
||||
}
|
||||
|
||||
guiObj.drawTexturedRect(xStart, yStart, 10, 0, 6, 1);
|
||||
guiObj.drawTexturedRect(xStart, yStart+(size*10)-1, 10, 0, 6, 1);
|
||||
|
||||
guiObj.drawTexturedRect(xStart+1, yStart+1+getScroll(), 16, 0, 4, 4);
|
||||
}
|
||||
|
||||
public int getMaxScroll()
|
||||
{
|
||||
return textEntries.size()-size;
|
||||
}
|
||||
|
||||
public int getScroll()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderForeground(int xAxis, int yAxis)
|
||||
{
|
||||
if((scrollIndex > 0 && textEntries.size() <= size) || (scrollIndex > 0 && getMaxScroll() < scrollIndex))
|
||||
{
|
||||
scrollIndex = 0;
|
||||
}
|
||||
|
||||
if(!textEntries.isEmpty())
|
||||
{
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
int index = scrollIndex + i;
|
||||
|
||||
if(index <= textEntries.size()-1)
|
||||
{
|
||||
guiObj.getFont().drawString(textEntries.get(index), xPosition + 1, yPosition + 1 + (10*i), 0x00CD00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mc.renderEngine.bindTexture(RESOURCE);
|
||||
|
||||
drawScroll();
|
||||
|
||||
mc.renderEngine.bindTexture(defaultLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preMouseClicked(int xAxis, int yAxis, int button) {}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xAxis, int yAxis, int button) {}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in a new issue