Start on the new manual

This commit is contained in:
gigabit101 2016-02-25 18:25:52 +00:00
parent 7d6c982847
commit 82d2de7eb1
30 changed files with 423 additions and 81 deletions

View file

@ -0,0 +1,103 @@
package techreborn.manual.pages;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.manual.PageCollection;
import java.io.IOException;
public class BasePage extends GuiScreen {
//Name used to reference the page
private String REFERENCE_NAME;
//Name Displayed in the index page
public String INDEX_NAME;
public boolean hasIndexButton = false;
public static final ResourceLocation PAGE_TEXTURE = new ResourceLocation("techreborn:textures/manual/gui/manual.png");
private final int xSize = 146;
private final int ySize = 180;
protected PageCollection collection;
public BasePage() {
}
public BasePage(String referenceName, PageCollection collection) {
this.REFERENCE_NAME = referenceName;
this.mc = Minecraft.getMinecraft();
this.collection = collection;
initGui();
}
public BasePage(String referenceName, boolean showInMenue, PageCollection collection) {
this(referenceName, collection);
this.hasIndexButton = showInMenue;
}
public int getXMin() {
return (this.width - xSize) / 2;
}
public int getYMin() {
return (this.height - ySize) / 2;
}
public void setXMin(int x) {
this.width = x;
}
public void setYMin(int y) {
this.height = y;
}
//Unlocalized Index Page Name
public BasePage setIndexName(String unlocalizedName) {
this.INDEX_NAME = ttl(unlocalizedName);
return this;
}
@SuppressWarnings("unchecked")
@Override
public void initGui() {
buttonList.clear();
buttonList.add(new GuiButton(0, getXMin() + 30, getYMin() + 150, 80, 16, ttl("techreborn.manual.backbutton")));
}
public void setReferenceName(String name) {
REFERENCE_NAME = name;
}
public String getReferenceName() {
return REFERENCE_NAME;
}
public void renderBackgroundLayer(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
minecraft.renderEngine.bindTexture(PAGE_TEXTURE);
drawTexturedModalRect(offsetX, offsetY, 0, 0, xSize, ySize);
}
public void renderOverlayComponents(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
}
public void drawScreen(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
super.drawScreen(mouseX + offsetX, mouseY + offsetY, 0);
renderOverlayComponents(minecraft, offsetX, offsetY, mouseX, mouseY);
}
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 0) collection.changeActivePage("CONTENTS");
}
@Override
public void mouseClicked(int par1, int par2, int par3) throws IOException {
super.mouseClicked(par1, par2, par3);
}
//Translate To Local
public String ttl(String unlocalizedName) {
return StatCollector.translateToLocal(unlocalizedName);
}
}

View file

@ -0,0 +1,43 @@
package techreborn.manual.pages;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
import techreborn.config.TechRebornConfigGui;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.items.ItemPlates;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.GuiButtonCustomTexture;
public class ContentsPage extends TitledPage
{
public ContentsPage(String name, PageCollection collection)
{
super(name, false, collection, Reference.CONTENTS_KEY, Color.white.getRGB());
}
@SuppressWarnings("unchecked")
@Override
public void initGui()
{
buttonList.clear();
buttonList.add(new GuiButtonCustomTexture(0, getXMin() + 25, getYMin() + 20, 0, 46, 100, 20, ItemPlates.getPlateByName("iron"),
Reference.pageNames.GETTINGSTARTED_PAGE, ttl(Reference.GETTINGSTARTED_KEY)));
}
@Override
public void renderBackgroundLayer(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY)
{
super.renderBackgroundLayer(minecraft, offsetX, offsetY, mouseX, mouseY);
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.GETTINGSTARTED_PAGE);
}
}

View file

@ -0,0 +1,106 @@
package techreborn.manual.pages;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.opengl.GL11;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
public class DescriptionPage extends TitledPage
{
public boolean hasImage;
private String rawDescription;
private List<String> formattedDescription;
private float descriptionScale = 0.88f;
public String imageprefix = "techreborn:textures/manual/screenshots/";
public DescriptionPage(String name, PageCollection collection, boolean hasImage)
{
super(name, false, collection, Reference.GETTINGSTARTED_KEY, Color.white.getRGB());
this.hasImage = hasImage;
this.rawDescription = "techreborn.manual." + this.getReferenceName() + ".description";
}
@Override
public void renderOverlayComponents(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY)
{
if(hasImage)
{
renderImage(offsetX, offsetY);
addDescription(mc, offsetX, offsetY + 50);
}
else
addDescription(mc, offsetX, offsetY);
}
public void renderImage(int offsetX, int offsetY)
{
TextureManager render = Minecraft.getMinecraft().renderEngine;
render.bindTexture(new ResourceLocation(imageprefix + this.getReferenceName() + ".png"));
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, 1F);
drawTexturedModalRect(offsetX, offsetY - 16, 0, 0, 120, this.height);
GL11.glDisable(GL11.GL_BLEND);
}
public void addDescription(Minecraft minecraft, int offsetX, int offsetY)
{
GL11.glPushMatrix();
GL11.glTranslated(offsetX + 15, offsetY + 40, 1);
GL11.glScalef(descriptionScale, descriptionScale, descriptionScale);
int offset = 0;
for (String s : getFormattedText(fontRendererObj))
{
if (s == null) break;
if (s.contains("\\%") && s.substring(0, 2).equals("\\%"))
{
s = s.substring(2);
offset += fontRendererObj.FONT_HEIGHT / 2;
}
fontRendererObj.drawString(s, 0, offset, Color.black.getRGB());
offset += fontRendererObj.FONT_HEIGHT;
}
GL11.glPopMatrix();
}
@SuppressWarnings("unchecked")
public List<String> getFormattedText(FontRenderer fr)
{
if (formattedDescription == null)
{
formattedDescription = new ArrayList<String>();
if (Strings.isNullOrEmpty(rawDescription))
{
formattedDescription = ImmutableList.of();
return formattedDescription;
}
if (!rawDescription.contains("\\n"))
{
formattedDescription = ImmutableList.copyOf(fr.listFormattedStringToWidth(rawDescription, 130));
return formattedDescription;
}
List<String> segments = new ArrayList();
String raw = rawDescription;
for (String s : segments)
formattedDescription.addAll(ImmutableList.copyOf(fr.listFormattedStringToWidth(s, 370)));
}
return formattedDescription;
}
}

View file

@ -0,0 +1,32 @@
package techreborn.manual.pages;
import java.awt.Color;
import net.minecraft.client.gui.GuiButton;
import techreborn.items.ItemParts;
import techreborn.items.ItemPlates;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.GuiButtonCustomTexture;
public class GettingStartedPage extends TitledPage
{
public GettingStartedPage(String name, PageCollection collection)
{
super(name, false, collection, Reference.GETTINGSTARTED_KEY, Color.white.getRGB());
}
@Override
public void initGui()
{
buttonList.clear();
buttonList.add(new GuiButtonCustomTexture(0, getXMin() + 25, getYMin() + 20, 0, 46, 100, 20, ItemParts.getPartByName("rubberSap"),
Reference.pageNames.GETTINGRUBBER_PAGE, ttl(Reference.GETTINGRUBBER_KEY)));
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.GETTINGRUBBER_PAGE);
}
}

View file

@ -0,0 +1,22 @@
package techreborn.manual.pages;
import net.minecraft.client.Minecraft;
import techreborn.manual.PageCollection;
public class TitledPage extends BasePage {
private String title;
public boolean drawTitle = true;
private int colour;
public TitledPage(String name, boolean showInMenue, PageCollection collection, String unlocalizedTitle, int colour) {
super(name, showInMenue, collection);
this.title = unlocalizedTitle;
this.colour = colour;
}
@Override
public void renderOverlayComponents(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
if (title == null) title = INDEX_NAME;
if (drawTitle) drawCenteredString(minecraft.fontRendererObj, ttl(title), offsetX + 70, offsetY + 10, colour);
}
}