Skip to content

Commit

Permalink
Improved guide gui. Scroll panel is now properly sized and doesn't fi…
Browse files Browse the repository at this point in the history
…ght with the scroll bar. Added overlays over the scroll panel for smooth scrolling.
  • Loading branch information
ShadedDimension committed Feb 7, 2014
1 parent d86059a commit 12cd5b1
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/tppitweaks/client/gui/modGuides/GuiGuideBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.TreeMap;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
Expand All @@ -31,6 +33,8 @@ public class GuiGuideBase extends GuiBase implements INEIGuiHandler

protected static final int LENGTH = 180;

protected GuideButton homeButton;

public GuiGuideBase()
{
super(new ResourceLocation("tppitweaks", "textures/gui/guiGuide.png"));
Expand Down Expand Up @@ -69,13 +73,13 @@ public void initGui()
// element list and then re-adding with updated text
protected void initPanel()
{
ElementScrollPanel panel = new ElementScrollPanel(this, this.xSize / 6, this.ySize / 9, this.xSize, (int) (this.ySize / 1.35));
ElementScrollPanel panel = new ElementScrollPanel(this, (this.xSize / 6) - 7, (this.ySize / 9) - 5, this.xSize - 75, (int) (this.ySize / 1.35) + 14);
List<String> lines = getLines();

int length = 0;
for (int i = 0; i < lines.size(); i++)
{
panel.addElement(new ElementText(this, 0, (length * 10), lines.get(i), null, 0x282828, false));
panel.addElement(new ElementText(this, 0, 3 + (length * 10), lines.get(i), null, 0x282828, false));
length++;

}
Expand All @@ -94,14 +98,32 @@ protected void initPanel()
this.addElement(new ElementScrollBar(this, 217, 15, 6, 139, panel));
}

@Override
public void drawGuiBackgroundLayer(float f, int mouseX, int mouseY)
{
super.drawGuiBackgroundLayer(f, mouseX, mouseY);

if (texture != null) // Draw these parts of the texture again, so they overlap a portion of the scroll panel, allowing for smooth-looking scrolling
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
getMinecraft().renderEngine.bindTexture(texture);
drawTexturedModalRect(guiLeft + 35, guiTop, 35, 0, this.xSize - 75, 14);
drawTexturedModalRect(guiLeft + 35, guiTop + ySize - 24, 35, ySize - 24, this.xSize - 75, 14);
}

homeButton.draw(); // Make sure this button is on top of the overlay
}

private void initPanel(List<String> lines, List<String> modids)
{
ElementScrollPanel panel = new ElementScrollPanel(this, this.xSize / 6, this.ySize / 9, this.xSize, (int) (this.ySize / 1.35));
ElementScrollPanel panel = new ElementScrollPanel(this, (this.xSize / 6) - 7, (this.ySize / 9) - 5, this.xSize - 75, (int) (this.ySize / 1.35) + 14);

for (int i = 0; i < lines.size(); i++)
{
panel.addElement(new ElementTextClickable(this, 0, i * 10, lines.get(i), null, 0x282828, modids.get(i)));
panel.addElement(new ElementTextClickable(this, 0, 3 + i * 10, lines.get(i), null, 0x282828, modids.get(i)));
}

panel.addElement(new ElementText(this, 0, 3 + (lines.size() * 10), "", null)); // Adding an extra element because of the overlays & positions of the first element, stops the last element from being half visible when fully scrolled

ArrayList<ElementBase> elementsNew = new ArrayList<ElementBase>();

Expand Down Expand Up @@ -179,7 +201,8 @@ private void initButtons()
this.addElement(new GuideButton(this, 5, 228, 40));
this.addElement(new GuideButton(this, 6, 228, 70));
this.addElement(new GuideButton(this, 7, 228, 100));
this.addElement(new GuideButton(this, 8, 114, 157));
homeButton = new GuideButton(this, 8, 114, 157);
this.addElement(homeButton);
}

@Override
Expand Down

0 comments on commit 12cd5b1

Please sign in to comment.