More work on the new manual

This commit is contained in:
gigabit101 2016-02-26 12:56:15 +00:00
parent e01fe31da8
commit 19e66c1c93
15 changed files with 680 additions and 40 deletions

View file

@ -10,10 +10,17 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import techreborn.init.ModBlocks;
import techreborn.items.ItemParts;
import techreborn.items.ItemPlates;
import techreborn.manual.pages.BasicMachinesPage;
import techreborn.manual.pages.ContentsPage;
import techreborn.manual.pages.CraftingInfoPage;
import techreborn.manual.pages.DescriptionPage;
import techreborn.manual.pages.GeneratingPowerPage;
import techreborn.manual.pages.GettingStartedPage;
@SideOnly(Side.CLIENT)
@ -38,12 +45,33 @@ public class GuiManual extends GuiScreen
{
pageIndex = 0;
final PageCollection pageCollection = new PageCollection();
pageCollection.addPage(new ContentsPage("CONTENTS", pageCollection));
pageCollection.addPage(new ContentsPage(Reference.pageNames.CONTENTS_PAGE, pageCollection));
//GETTING STARTED
pageCollection.addPage(new GettingStartedPage(Reference.pageNames.GETTINGSTARTED_PAGE, pageCollection));
pageCollection.addPage(new DescriptionPage(Reference.pageNames.GETTINGRUBBER_PAGE, pageCollection, true));
pageCollection.addPage(new DescriptionPage(Reference.pageNames.GETTINGRUBBER_PAGE, pageCollection, true, Reference.pageNames.GETTINGRUBBER2_PAGE));
pageCollection.addPage(new CraftingInfoPage(Reference.pageNames.GETTINGRUBBER2_PAGE, pageCollection, ItemParts.getPartByName("rubber"), "", Reference.pageNames.GETTINGRUBBER_PAGE));
pageCollection.addPage(new CraftingInfoPage(Reference.pageNames.CRAFTINGPLATES_PAGE, pageCollection, ItemPlates.getPlateByName("iron"), "", Reference.pageNames.GETTINGSTARTED_PAGE));
//POWER GENERATION
pageCollection.addPage(new GeneratingPowerPage(Reference.pageNames.GENERATINGPOWER_PAGE, pageCollection));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.Generator.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.Generator), "", Reference.pageNames.GENERATINGPOWER_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.thermalGenerator.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.thermalGenerator), "", Reference.pageNames.GENERATINGPOWER_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.solarPanel.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.solarPanel), "", Reference.pageNames.GENERATINGPOWER_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.heatGenerator.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.heatGenerator), "", Reference.pageNames.GENERATINGPOWER_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.LightningRod.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.LightningRod), "", Reference.pageNames.GENERATINGPOWER_PAGE));
//BASIC MACHINES
pageCollection.addPage(new BasicMachinesPage(Reference.pageNames.BASICMACHINES_PAGE, pageCollection));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.Grinder.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.Grinder), "", Reference.pageNames.BASICMACHINES_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.ElectricFurnace.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.ElectricFurnace), "", Reference.pageNames.BASICMACHINES_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.AlloySmelter.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.AlloySmelter), "", Reference.pageNames.BASICMACHINES_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.Extractor.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.Extractor), "", Reference.pageNames.BASICMACHINES_PAGE));
pageCollection.addPage(new CraftingInfoPage(ModBlocks.Compressor.getLocalizedName(), pageCollection, new ItemStack(ModBlocks.Compressor), "", Reference.pageNames.BASICMACHINES_PAGE));
return pageCollection;
}

View file

@ -13,7 +13,7 @@ import techreborn.manual.pages.BasePage;
public class PageCollection extends Gui {
public final List<BasePage> pages = Lists.newArrayList();
private String ACTIVE_PAGE = "CONTENTS";
private String ACTIVE_PAGE = Reference.pageNames.CONTENTS_PAGE;
protected int x;
protected int y;

View file

@ -4,11 +4,23 @@ public class Reference
{
public static final String CONTENTS_KEY = "techreborn.manual.contents";
public static final String GETTINGSTARTED_KEY = "techreborn.manual.gettingstarted";
public static final String GENERATINGPOWER_KEY = "techreborn.manual.generatingpower";
public static final String BASICMACHINES_KEY = "techreborn.manual.basicmachines";
public static final String GETTINGRUBBER_KEY = "techreborn.manual.gettingrubber";
public static final String CRAFTINGPLATES_KEY = "techreborn.manual.gettingplates";
public class pageNames
{
public static final String CONTENTS_PAGE = "contents";
public static final String BASICMACHINES_PAGE = "basicmachines";
public static final String GETTINGSTARTED_PAGE = "gettingstarted";
public static final String GETTINGRUBBER_PAGE = "gettingrubber";
public static final String GETTINGRUBBER2_PAGE = "gettingrubber2";
public static final String CRAFTINGPLATES_PAGE = "gettingplates";
public static final String GENERATINGPOWER_PAGE = "generatingpower";
}
}

View file

@ -6,6 +6,7 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import java.io.IOException;
@ -58,13 +59,6 @@ public class BasePage extends GuiScreen {
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;
}
@ -88,7 +82,7 @@ public class BasePage extends GuiScreen {
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 0) collection.changeActivePage("CONTENTS");
if (button.id == 0) collection.changeActivePage(Reference.pageNames.CONTENTS_PAGE);
}
@Override

View file

@ -0,0 +1,47 @@
package techreborn.manual.pages;
import java.awt.Color;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
import techreborn.init.ModBlocks;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.ButtonUtil;
import techreborn.manual.util.GuiButtonItemTexture;
public class BasicMachinesPage extends TitledPage
{
public BasicMachinesPage(String name, PageCollection collection)
{
super(name, false, collection, Reference.BASICMACHINES_KEY, Color.white.getRGB());
}
@Override
public void initGui()
{
buttonList.clear();
ButtonUtil.addBackButton(0, width / 2 - 60, height / 2 + 64, buttonList);
buttonList.add(new GuiButtonItemTexture(1, getXMin() + 20, getYMin() + 20, 0, 46, 100, 20, new ItemStack(ModBlocks.Grinder),
ModBlocks.Grinder.getUnlocalizedName(), ttl(ModBlocks.Grinder.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(2, getXMin() + 20, getYMin() + 40, 0, 46, 100, 20, new ItemStack(ModBlocks.ElectricFurnace),
ModBlocks.ElectricFurnace.getUnlocalizedName(), ttl(ModBlocks.ElectricFurnace.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(3, getXMin() + 20, getYMin() + 60, 0, 46, 100, 20, new ItemStack(ModBlocks.AlloySmelter),
ModBlocks.AlloySmelter.getUnlocalizedName(), ttl(ModBlocks.AlloySmelter.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(4, getXMin() + 20, getYMin() + 80, 0, 46, 100, 20, new ItemStack(ModBlocks.Extractor),
ModBlocks.Extractor.getUnlocalizedName(), ttl(ModBlocks.Extractor.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(5, getXMin() + 20, getYMin() + 100, 0, 46, 100, 20, new ItemStack(ModBlocks.Compressor),
ModBlocks.Compressor.getUnlocalizedName(), ttl(ModBlocks.Compressor.getLocalizedName())));
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.CONTENTS_PAGE);
if (button.id == 1) collection.changeActivePage(ModBlocks.Grinder.getLocalizedName());
if (button.id == 2) collection.changeActivePage(ModBlocks.ElectricFurnace.getLocalizedName());
if (button.id == 3) collection.changeActivePage(ModBlocks.AlloySmelter.getLocalizedName());
if (button.id == 4) collection.changeActivePage(ModBlocks.Extractor.getLocalizedName());
if (button.id == 5) collection.changeActivePage(ModBlocks.Compressor.getLocalizedName());
}
}

View file

@ -11,7 +11,7 @@ import techreborn.init.ModItems;
import techreborn.items.ItemPlates;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.GuiButtonCustomTexture;
import techreborn.manual.util.GuiButtonItemTexture;
public class ContentsPage extends TitledPage
{
@ -25,8 +25,12 @@ public class ContentsPage extends TitledPage
public void initGui()
{
buttonList.clear();
buttonList.add(new GuiButtonCustomTexture(0, getXMin() + 25, getYMin() + 20, 0, 46, 100, 20, ItemPlates.getPlateByName("iron"),
buttonList.add(new GuiButtonItemTexture(0, getXMin() + 20, getYMin() + 20, 0, 46, 100, 20, ItemPlates.getPlateByName("iron"),
Reference.pageNames.GETTINGSTARTED_PAGE, ttl(Reference.GETTINGSTARTED_KEY)));
buttonList.add(new GuiButtonItemTexture(1, getXMin() + 20, getYMin() + 40, 0, 46, 100, 20, new ItemStack(ModBlocks.Generator),
Reference.pageNames.GENERATINGPOWER_PAGE, ttl(Reference.GENERATINGPOWER_KEY)));
buttonList.add(new GuiButtonItemTexture(2, getXMin() + 20, getYMin() + 60, 0, 46, 100, 20, new ItemStack(ModBlocks.ElectricFurnace),
Reference.pageNames.BASICMACHINES_PAGE, ttl(Reference.BASICMACHINES_KEY)));
}
@Override
@ -39,5 +43,7 @@ public class ContentsPage extends TitledPage
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.GETTINGSTARTED_PAGE);
if (button.id == 1) collection.changeActivePage(Reference.pageNames.GENERATINGPOWER_PAGE);
if (button.id == 2) collection.changeActivePage(Reference.pageNames.BASICMACHINES_PAGE);
}
}

View file

@ -0,0 +1,352 @@
package techreborn.manual.pages;
import java.awt.Color;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.ButtonUtil;
public class CraftingInfoPage extends TitledPage
{
public ItemStack result;
private boolean isSmelting = false;
private ItemStack[] recipe = new ItemStack[9];
private boolean hasRecipe = false;
private String rawDescription;
private List<String> formattedDescription;
private float descriptionScale = 0.66f;
public String imageprefix = "techreborn:textures/manual/elements/";
public String backpage;
public CraftingInfoPage(String name, PageCollection collection, ItemStack itemStack, String unlocalizedDescription, String backPage)
{
super(name, true, collection, itemStack.getUnlocalizedName() + ".name", Color.white.getRGB());
this.result = itemStack;
this.recipe = getFirstRecipeForItem(itemStack);
this.backpage = backPage;
for (ItemStack stack : recipe) if (stack != null) hasRecipe = true;
if (unlocalizedDescription == "") rawDescription = ttl(itemStack.getUnlocalizedName() + ".description");
else rawDescription = ttl(unlocalizedDescription);
}
@Override
public void initGui()
{
buttonList.clear();
ButtonUtil.addBackButton(0, width / 2 - 60, height / 2 + 64, buttonList);
}
@Override
public void renderBackgroundLayer(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
super.renderBackgroundLayer(minecraft, offsetX, offsetY, mouseX, mouseY);
GL11.glPushMatrix();
if (isSmelting)
{
renderImage(offsetX + 15, offsetY + 10, "furnacerecipe");
}
else
{
if (hasRecipe)
{
renderImage(offsetX, offsetY + 10, "craftingtable");
}
else
{
drawString(fontRendererObj, "No Crafting Recipe", offsetX + 40, offsetY + 22, Color.black.getRGB());
}
}
GL11.glPopMatrix();
}
public void drawScreen(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY)
{
super.drawScreen(minecraft, offsetX, offsetY, mouseX, mouseY);
int relativeMouseX = mouseX + offsetX;
int relativeMouseY = mouseY + offsetY;
int gridOffsetX = isSmelting ? 85 : 71;
int gridOffsetY = 18;
int itemBoxSize = 18;
addDescription(minecraft, offsetX + 8, offsetY);
ItemStack tooltip = null;
int i = 0;
for (ItemStack input : recipe)
{
if (input != null) {
int row = (i % 3);
int column = i / 3;
int itemX = offsetX + gridOffsetX + (row * itemBoxSize) - 54;
int itemY = offsetY + gridOffsetY + (column * itemBoxSize) + 2;
drawItemStack(input, itemX, itemY, "");
if (relativeMouseX > itemX - 2 && relativeMouseX < itemX - 2 + itemBoxSize &&
relativeMouseY > itemY - 2 && relativeMouseY < itemY - 2 + itemBoxSize) {
tooltip = input;
}
}
i++;
}
int itemX = offsetX + (isSmelting ? 92 : 112);
int itemY = offsetY + (isSmelting ? 40 : 38);
if (!hasRecipe) {
itemX = offsetX + 20;
itemY = offsetY + 18;
}
drawItemStack(result, itemX, itemY, "");
if (relativeMouseX > itemX - 2 && relativeMouseX < itemX - 2 + itemBoxSize &&
relativeMouseY > itemY - 2 && relativeMouseY < itemY - 2 + itemBoxSize) {
tooltip = result;
}
if (tooltip != null) {
drawItemStackTooltip(tooltip, relativeMouseX, relativeMouseY);
}
}
public void renderImage(int offsetX, int offsetY, String imagename)
{
TextureManager render = Minecraft.getMinecraft().renderEngine;
render.bindTexture(new ResourceLocation(imageprefix + imagename + ".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 - 14, 0, 0, 140, this.height);
GL11.glDisable(GL11.GL_BLEND);
}
public void addDescription(Minecraft minecraft, int offsetX, int offsetY)
{
GL11.glPushMatrix();
if (hasRecipe) GL11.glTranslated(offsetX + 5, offsetY + 75, 1);
else GL11.glTranslated(offsetX + 5, 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, 370));
return formattedDescription;
}
List<String> segments = new ArrayList();
String raw = rawDescription;
int escape = 0;
while (raw.contains("\\n")) {
segments.add(raw.substring(0, raw.indexOf("\\n")));
raw = raw.substring(raw.indexOf("\\n") + 2);
if (!raw.contains("\\n")) segments.add(raw);
escape++;
if (escape > 100) {
break;
}
}
for (String s : segments)
formattedDescription.addAll(ImmutableList.copyOf(fr.listFormattedStringToWidth(s, 370)));
}
return formattedDescription;
}
protected void drawItemStackTooltip(ItemStack stack, int x, int y)
{
final Minecraft mc = Minecraft.getMinecraft();
FontRenderer font = Objects.firstNonNull(stack.getItem().getFontRenderer(stack), mc.fontRendererObj);
@SuppressWarnings("unchecked")
List<String> list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
List<String> colored = Lists.newArrayListWithCapacity(list.size());
colored.add(stack.getRarity().rarityColor + list.get(0));
for (String line : list)
colored.add(EnumChatFormatting.GRAY + line);
if (colored.size() >= 2) colored.remove(1);
drawHoveringText(colored, x, y, font);
}
private void drawItemStack(ItemStack par1ItemStack, int par2, int par3, String par4Str)
{
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
RenderHelper.enableGUIStandardItemLighting();
GL11.glColor3f(1f, 1f, 1f);
GL11.glEnable(GL11.GL_NORMALIZE);
FontRenderer font = null;
if (par1ItemStack != null) font = par1ItemStack.getItem().getFontRenderer(par1ItemStack);
if (font == null) font = Minecraft.getMinecraft().fontRendererObj;
renderItemStack(par1ItemStack, par2, par3);
this.zLevel = 0.0F;
}
public void renderItemStack(ItemStack stack, int x, int y)
{
if (stack != null)
{
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.enableGUIStandardItemLighting();
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
itemRenderer.renderItemAndEffectIntoGUI(stack, x, y);
GL11.glDisable(GL11.GL_LIGHTING);
}
}
@SuppressWarnings("unchecked")
private ItemStack[] getFirstRecipeForItem(ItemStack resultingItem)
{
ItemStack[] recipeItems = new ItemStack[9];
for (IRecipe recipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList())
{
if (recipe == null) continue;
ItemStack result = recipe.getRecipeOutput();
if (result == null || !result.isItemEqual(resultingItem)) continue;
Object[] input = getRecipeInput(recipe);
if (input == null) continue;
for (int i = 0; i < input.length; i++)
recipeItems[i] = convertToStack(input[i]);
break;
}
Iterator iterator = FurnaceRecipes.instance().getSmeltingList().entrySet().iterator();
Map.Entry entry;
while (iterator.hasNext())
{
entry = (Map.Entry) iterator.next();
if (entry.getKey() instanceof ItemStack && ((ItemStack) entry.getValue()).isItemEqual(result))
{
isSmelting = true;
recipeItems[0] = (ItemStack) entry.getKey();
}
}
return recipeItems;
}
protected ItemStack convertToStack(Object obj)
{
ItemStack entry = null;
if (obj instanceof ItemStack) {
entry = (ItemStack) obj;
} else if (obj instanceof List) {
@SuppressWarnings("unchecked")
List<ItemStack> list = (List<ItemStack>) obj;
if (list.size() > 0) entry = list.get(0);
}
if (entry == null) return null;
entry = entry.copy();
if (entry.getItemDamage() == OreDictionary.WILDCARD_VALUE) entry.setItemDamage(0);
return entry;
}
@SuppressWarnings("unchecked")
private Object[] getRecipeInput(IRecipe recipe)
{
if (recipe instanceof ShapelessOreRecipe) return ((ShapelessOreRecipe) recipe).getInput().toArray();
else if (recipe instanceof ShapedOreRecipe) return getShapedOreRecipe((ShapedOreRecipe) recipe);
else if (recipe instanceof ShapedRecipes) return ((ShapedRecipes) recipe).recipeItems;
else if (recipe instanceof ShapelessRecipes)
return ((ShapelessRecipes) recipe).recipeItems.toArray(new ItemStack[0]);
return null;
}
private Object[] getShapedOreRecipe(ShapedOreRecipe recipe)
{
try
{
Field field = ShapedOreRecipe.class.getDeclaredField("width");
if (field != null) {
field.setAccessible(true);
int width = field.getInt(recipe);
Object[] input = recipe.getInput();
Object[] grid = new Object[9];
for (int i = 0, offset = 0, y = 0; y < 3; y++)
{
for (int x = 0; x < 3; x++, i++) {
if (x < width && offset < input.length)
{
grid[i] = input[offset];
offset++;
} else
{
grid[i] = null;
}
}
}
return grid;
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(backpage);
}
}

View file

@ -11,26 +11,31 @@ import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
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;
import techreborn.manual.util.ButtonUtil;
import techreborn.manual.util.GuiButtonCustomTexture;
public class DescriptionPage extends TitledPage
{
public boolean hasImage;
public String secondpage;
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)
public DescriptionPage(String name, PageCollection collection, boolean hasImage, String secondPage)
{
super(name, false, collection, Reference.GETTINGSTARTED_KEY, Color.white.getRGB());
this.hasImage = hasImage;
this.rawDescription = "techreborn.manual." + this.getReferenceName() + ".description";
this.secondpage = secondPage;
}
@Override
@ -45,6 +50,17 @@ public class DescriptionPage extends TitledPage
addDescription(mc, offsetX, offsetY);
}
@Override
public void initGui()
{
buttonList.clear();
ButtonUtil.addBackButton(0, width / 2 - 60, height / 2 + 64, buttonList);
if(secondpage != null)
{
ButtonUtil.addNextButton(1, width / 2 + 40, height / 2 + 64, buttonList);
}
}
public void renderImage(int offsetX, int offsetY)
{
TextureManager render = Minecraft.getMinecraft().renderEngine;
@ -103,4 +119,15 @@ public class DescriptionPage extends TitledPage
}
return formattedDescription;
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.GETTINGSTARTED_PAGE);
if(secondpage != null)
{
if (button.id == 1) collection.changeActivePage(secondpage);
}
}
}

View file

@ -0,0 +1,49 @@
package techreborn.manual.pages;
import java.awt.Color;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
import techreborn.init.ModBlocks;
import techreborn.items.ItemParts;
import techreborn.items.ItemPlates;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.ButtonUtil;
import techreborn.manual.util.GuiButtonItemTexture;
public class GeneratingPowerPage extends TitledPage
{
public GeneratingPowerPage(String name, PageCollection collection)
{
super(name, false, collection, Reference.GENERATINGPOWER_KEY, Color.white.getRGB());
}
@Override
public void initGui()
{
buttonList.clear();
ButtonUtil.addBackButton(0, width / 2 - 60, height / 2 + 64, buttonList);
buttonList.add(new GuiButtonItemTexture(1, getXMin() + 20, getYMin() + 20, 0, 46, 100, 20, new ItemStack(ModBlocks.Generator),
ModBlocks.Generator.getUnlocalizedName(), ttl(ModBlocks.Generator.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(2, getXMin() + 20, getYMin() + 40, 0, 46, 100, 20, new ItemStack(ModBlocks.thermalGenerator),
ModBlocks.thermalGenerator.getUnlocalizedName(), ttl(ModBlocks.thermalGenerator.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(3, getXMin() + 20, getYMin() + 60, 0, 46, 100, 20, new ItemStack(ModBlocks.solarPanel),
ModBlocks.solarPanel.getUnlocalizedName(), ttl(ModBlocks.solarPanel.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(4, getXMin() + 20, getYMin() + 80, 0, 46, 100, 20, new ItemStack(ModBlocks.heatGenerator),
ModBlocks.heatGenerator.getUnlocalizedName(), ttl(ModBlocks.heatGenerator.getLocalizedName())));
buttonList.add(new GuiButtonItemTexture(5, getXMin() + 20, getYMin() + 100, 0, 46, 100, 20, new ItemStack(ModBlocks.LightningRod),
ModBlocks.LightningRod.getUnlocalizedName(), ttl(ModBlocks.LightningRod.getLocalizedName())));
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.CONTENTS_PAGE);
if (button.id == 1) collection.changeActivePage(ModBlocks.Generator.getLocalizedName());
if (button.id == 2) collection.changeActivePage(ModBlocks.thermalGenerator.getLocalizedName());
if (button.id == 3) collection.changeActivePage(ModBlocks.solarPanel.getLocalizedName());
if (button.id == 4) collection.changeActivePage(ModBlocks.heatGenerator.getLocalizedName());
if (button.id == 5) collection.changeActivePage(ModBlocks.LightningRod.getLocalizedName());
}
}

View file

@ -7,7 +7,8 @@ import techreborn.items.ItemParts;
import techreborn.items.ItemPlates;
import techreborn.manual.PageCollection;
import techreborn.manual.Reference;
import techreborn.manual.util.GuiButtonCustomTexture;
import techreborn.manual.util.ButtonUtil;
import techreborn.manual.util.GuiButtonItemTexture;
public class GettingStartedPage extends TitledPage
{
@ -20,13 +21,19 @@ public class GettingStartedPage extends TitledPage
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)));
ButtonUtil.addBackButton(0, width / 2 - 60, height / 2 + 64, buttonList);
buttonList.add(new GuiButtonItemTexture(1, getXMin() + 20, getYMin() + 20, 0, 46, 100, 20, ItemParts.getPartByName("rubberSap"),
Reference.pageNames.GETTINGRUBBER_PAGE, ttl(Reference.GETTINGRUBBER_KEY)));
buttonList.add(new GuiButtonItemTexture(2, getXMin() + 20, getYMin() + 40, 0, 46, 100, 20, ItemPlates.getPlateByName("iron"),
Reference.pageNames.CRAFTINGPLATES_PAGE, ttl(Reference.CRAFTINGPLATES_KEY)));
}
@Override
public void actionPerformed(GuiButton button)
{
if (button.id == 0) collection.changeActivePage(Reference.pageNames.GETTINGRUBBER_PAGE);
if (button.id == 0) collection.changeActivePage(Reference.pageNames.CONTENTS_PAGE);
if (button.id == 1) collection.changeActivePage(Reference.pageNames.GETTINGRUBBER_PAGE);
if (button.id == 2) collection.changeActivePage(Reference.pageNames.CRAFTINGPLATES_PAGE);
}
}

View file

@ -0,0 +1,22 @@
package techreborn.manual.util;
import java.util.List;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ButtonUtil
{
@SideOnly(Side.CLIENT)
public static void addBackButton(int ID, int X, int Y, List buttonList)
{
buttonList.add(new GuiButtonCustomTexture(ID, X, Y, 50, 60, 17, 12, "button", "", "", 0, 11, 10, 16));
}
@SideOnly(Side.CLIENT)
public static void addNextButton(int ID, int X, int Y, List buttonList)
{
buttonList.add(new GuiButtonCustomTexture(ID, X, Y, 50, 60, 17, 12, "button", "", "", 0, 1, 10, 17));
}
}

View file

@ -1,33 +1,52 @@
package techreborn.manual.util;
import java.awt.Color;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiButtonExt;
import org.lwjgl.opengl.GL11;
import java.awt.*;
public class GuiButtonCustomTexture extends GuiButtonExt {
public class GuiButtonCustomTexture extends GuiButtonExt
{
public int textureU;
public int textureV;
public ItemStack itemstack;
public String texturename;
public String LINKED_PAGE;
public String NAME;
public String imageprefix = "techreborn:textures/manual/elements/";
public int buttonHeight;
public int buttonWidth;
public int buttonU;
public int buttonV;
public int textureH;
public int textureW;
public GuiButtonCustomTexture(int id, int xPos, int yPos, int u, int v, int width, int height, ItemStack stack, String linkedPage, String name) {
super(id, xPos, yPos, width, height, "_");
textureU = u;
textureV = v;
itemstack = stack;
NAME = name;
public GuiButtonCustomTexture(int id, int xPos, int yPos, int u, int v, int buttonWidth, int buttonHeight, String texturename, String linkedPage, String name, int buttonU, int buttonV, int textureH, int textureW)
{
super(id, xPos, yPos, buttonWidth, buttonHeight, "_");
this.textureU = u;
this.textureV = v;
this.texturename = texturename;
this.NAME = name;
this.LINKED_PAGE = linkedPage;
this.buttonHeight = height;
this.buttonWidth = width;
this.buttonU = buttonU;
this.buttonV = buttonV;
this.textureH = textureH;
this.textureW = textureW;
}
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
public void drawButton(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;
@ -35,7 +54,8 @@ public class GuiButtonCustomTexture extends GuiButtonExt {
int u = textureU;
int v = textureV;
if (flag) {
if (flag)
{
u += width;
GL11.glPushMatrix();
GL11.glColor4f(0f, 0f, 0f, 1f);
@ -46,14 +66,25 @@ public class GuiButtonCustomTexture extends GuiButtonExt {
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
itemRenderer.renderItemIntoGUI(itemstack, this.xPosition, this.yPosition);
renderImage(this.xPosition, this.yPosition);
this.drawString(mc.fontRendererObj, this.NAME, this.xPosition + 20, this.yPosition + 3, Color.white.getRGB());
}
}
public void renderImage(int offsetX, int offsetY)
{
TextureManager render = Minecraft.getMinecraft().renderEngine;
render.bindTexture(new ResourceLocation(imageprefix + this.texturename + ".png"));
public boolean getIsHovering() {
return hovered;
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, this.buttonU, this.buttonV, this.textureW, this.textureH);
GL11.glDisable(GL11.GL_BLEND);
}
public boolean getIsHovering()
{
return hovered;
}
}

View file

@ -0,0 +1,59 @@
package techreborn.manual.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.client.config.GuiButtonExt;
import org.lwjgl.opengl.GL11;
import java.awt.*;
public class GuiButtonItemTexture extends GuiButtonExt {
public int textureU;
public int textureV;
public ItemStack itemstack;
public String LINKED_PAGE;
public String NAME;
public GuiButtonItemTexture(int id, int xPos, int yPos, int u, int v, int width, int height, ItemStack stack, String linkedPage, String name) {
super(id, xPos, yPos, width, height, "_");
textureU = u;
textureV = v;
itemstack = stack;
NAME = name;
this.LINKED_PAGE = linkedPage;
}
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;
mc.getTextureManager().bindTexture(buttonTextures);
int u = textureU;
int v = textureV;
if (flag) {
u += width;
GL11.glPushMatrix();
GL11.glColor4f(0f, 0f, 0f, 1f);
this.drawTexturedModalRect(this.xPosition, this.yPosition, u, v, width, height);
GL11.glPopMatrix();
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826);
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
itemRenderer.renderItemIntoGUI(itemstack, this.xPosition, this.yPosition);
this.drawString(mc.fontRendererObj, this.NAME, this.xPosition + 20, this.yPosition + 3, Color.white.getRGB());
}
}
public boolean getIsHovering() {
return hovered;
}
}

View file

@ -927,8 +927,14 @@ Cable.tinCable.name=Tin Cable
#Manual
techreborn.manual.contents=Contents Page
techreborn.manual.gettingstarted=Getting Started
techreborn.manual.generatingpower=Generating Power
techreborn.manual.basicmachines=Basic Machines
techreborn.manual.gettingrubber=Collecting Rubber
techreborn.manual.backbutton=Back
techreborn.manual.gettingplates=Crafting Plates
item.techreborn.advancedDrill.description=This Tool is a advanced version of the mining drill, when this item is activated it will dig out a 3x3.
tile.techreborn.alloyfurnace.description=This Machine is your first step into TechReborn with this you can fuse metals into other metals. These other metals can be used to craft the higher tier machines.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB