Skip to content

Commit

Permalink
Manual ready to fill
Browse files Browse the repository at this point in the history
Done with code (probably) for #14
[ci JBUILD]
  • Loading branch information
pauljoda committed Mar 2, 2015
1 parent 018a375 commit d0459ed
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 178 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/dyonovan/modernalchemy/ModernAlchemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.dyonovan.modernalchemy.handlers.*;
import com.dyonovan.modernalchemy.lib.Constants;
import com.dyonovan.modernalchemy.manual.ManualRegistry;
import com.dyonovan.modernalchemy.nei.INEICallback;
import com.dyonovan.modernalchemy.proxy.CommonProxy;
import com.dyonovan.modernalchemy.manual.ManualComponents;
import com.dyonovan.modernalchemy.manual.ManualJson;
import com.dyonovan.modernalchemy.util.ReplicatorUtils;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
Expand All @@ -20,14 +17,10 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.config.Configuration;

import java.io.File;
import java.util.ArrayList;

@Mod(name = Constants.MODNAME, modid = Constants.MODID, version = Constants.VERSION, dependencies = Constants.DEPENDENCIES)

Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/dyonovan/modernalchemy/manual/ManualJson.java

This file was deleted.

59 changes: 31 additions & 28 deletions src/main/java/com/dyonovan/modernalchemy/manual/ManualRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.dyonovan.modernalchemy.helpers.LogHelper;
import com.dyonovan.modernalchemy.manual.component.*;
import com.dyonovan.modernalchemy.manual.pages.GuiManual;
import com.dyonovan.modernalchemy.manual.util.ManualPageDeserializer;
import com.dyonovan.modernalchemy.manual.util.AbstractComponent;
import com.dyonovan.modernalchemy.manual.util.AbstractManualPage;
import com.dyonovan.modernalchemy.util.ReplicatorUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -137,21 +140,22 @@ public GuiManual buildManualFromFile(String input) {
GuiManual page = new GuiManual(input.split(".json")[0]);
InputStream is = ModernAlchemy.class.getResourceAsStream("/manualPages/" + input);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
ManualJson json = readJson(bufferedReader);
AbstractManualPage json = readJson(bufferedReader);

page.setTitle(StatCollector.translateToLocal(json.title)); //Set the title
for (int i = 1; i < json.numPages; i++) //Build the pages
page.pages.add(new ComponentSet());
for (ManualComponents component : json.component) { //Add the components to their page
for (AbstractComponent component : json.component) { //Add the components to their page
page.pages.get(component.pageNum - 1).add(buildFromComponent(component));
}
return page;
}

/**
* Gets all the files in the manual pages directory ("resources/manualPages")
* @return An array of {@link java.lang.String}s containing our info
*/
public ArrayList<String> getFilesForPages() {
public ArrayList<String> getFilesForPages() {
ArrayList<String> files = new ArrayList<String>();
String path = "manualPages";
URL url = ModernAlchemy.class.getResource("/" + path);
Expand All @@ -172,14 +176,14 @@ public ArrayList<String> getFilesForPages() {
LogHelper.severe("Could not find Manual Pages");
}
} else {
try {
File apps = new File(url.toURI());
for (File app : apps.listFiles()) {
files.add(app.getName());
}
} catch (URISyntaxException e) {
LogHelper.severe("Could not find Manual Pages");
try {
File apps = new File(url.toURI());
for (File app : apps.listFiles()) {
files.add(app.getName());
}
} catch (URISyntaxException e) {
LogHelper.severe("Could not find Manual Pages");
}

}
return files;
Expand All @@ -188,33 +192,32 @@ public ArrayList<String> getFilesForPages() {
/**
* Reads the Json into usable information
* @param br {@link java.io.BufferedReader} that contains the json file
* @return A {@link com.dyonovan.modernalchemy.manual.ManualJson} object with all the information in the file
* @return A {@link com.dyonovan.modernalchemy.manual.util.AbstractManualPage} object with all the information in the file
*/
public ManualJson readJson(BufferedReader br) {
public AbstractManualPage readJson(BufferedReader br) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(ManualJson.class, new MJDeserializer());
gsonBuilder.registerTypeAdapter(AbstractManualPage.class, new ManualPageDeserializer());
Gson gson = gsonBuilder.create();
return gson.fromJson(br, ManualJson.class);
return gson.fromJson(br, AbstractManualPage.class);
}
/**
* Converts the {@link com.dyonovan.modernalchemy.manual.ManualComponents} to {@link com.dyonovan.modernalchemy.manual.component.IComponent}
* @param component The {@link com.dyonovan.modernalchemy.manual.ManualComponents} to convert (from Json)
* @return The {@link com.dyonovan.modernalchemy.manual.component.IComponent} of the type definded in the {@link com.dyonovan.modernalchemy.manual.ManualComponents}
* Converts the {@link com.dyonovan.modernalchemy.manual.util.AbstractComponent} to {@link com.dyonovan.modernalchemy.manual.component.IComponent}
* @param component The {@link com.dyonovan.modernalchemy.manual.util.AbstractComponent} to convert (from Json)
* @return The {@link com.dyonovan.modernalchemy.manual.component.IComponent} of the type definded in the {@link com.dyonovan.modernalchemy.manual.util.AbstractComponent}
*/
public IComponent buildFromComponent(ManualComponents component) {
public IComponent buildFromComponent(AbstractComponent component) {
ComponentBase goodComponent;
//Component Types:
//ComponentTextBox - "TEXT_BOX"
//ComponentCraftingRecipe - "CRAFTING"
//ComponentHeader - "HEADER"
//ComponentImage - "IMAGE"
//ComponentItemRender - "ITEM_RENDER"
//ComponentLineBreak - "BREAK"
//ComponentLink - "LINK"

//Component Types:
//ComponentTextBox - "TEXT_BOX"
//ComponentHeader - "HEADER"
//ComponentImage - "IMAGE"
//ComponentItemRender - "ITEM_RENDER"
//ComponentLineBreak - "BREAK"
//ComponentLink - "LINK"

if(component.type.equalsIgnoreCase("TEXT_BOX"))
goodComponent = new ComponentTextBox(StatCollector.translateToLocal(component.text));
else if(component.type.equalsIgnoreCase("CRAFTING"))
goodComponent = new ComponentCraftingRecipe(ReplicatorUtils.getReturn(component.item));
else if(component.type.equalsIgnoreCase("HEADER"))
goodComponent = new ComponentHeader(StatCollector.translateToLocal(component.text));
else if(component.type.equalsIgnoreCase("IMAGE"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dyonovan.modernalchemy.manual.component;

import com.dyonovan.modernalchemy.manual.pages.GuiManual;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -18,7 +19,6 @@ public class ComponentBase extends GuiScreen implements IComponent {
protected ALIGNMENT alignment = ALIGNMENT.CENTER;
protected List<String> toolTip = new ArrayList<String>();
private int delay = 0;
private int inputDelay = 0;
public int xPos = 0;
public int yPos = 0;
public int width = 0;
Expand All @@ -43,20 +43,20 @@ public void addToTip(String tip) {
public void drawComponent(int x, int y, int mouseX, int mouseY) {
if(mouseX > x + xPos && mouseX < x + xPos + width && mouseY > y + yPos && mouseY <= y + yPos + height && !toolTip.isEmpty()) {
if(++delay > 20)
drawHoveringText(toolTip, mouseX, mouseY, Minecraft.getMinecraft().fontRenderer);
drawHoveringText(toolTip, mouseX, mouseY, Minecraft.getMinecraft().fontRenderer);
}
else
delay = 0;

if(mouseX > x + xPos && mouseX < x + xPos + width && mouseY > y + yPos && mouseY <= y + yPos + height) {
if(Mouse.isButtonDown(0) && inputDelay < 0)
if(Mouse.isButtonDown(0) && GuiManual.inputDelay < 0)
onMouseLeftClick();
}
inputDelay--;
}

public void onMouseLeftClick() {
inputDelay = 20;
GuiManual.inputDelay = 20;
GuiManual.playClickSound();
}

public void drawRectangle(int x1, int y1, int x2, int y2, Color color) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
Expand All @@ -21,12 +22,8 @@ public ComponentItemRender(ItemStack itemStack) {
public void drawComponent(int x, int y, int mouseX, int mouseY) {
GL11.glPushMatrix();
RenderHelper.enableGUIStandardItemLighting();

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if(!stack.getDisplayName().contains("Tesla Coil"))
GL11.glTranslated(x + (115 / 2) + 12, y + width, 0);
else
GL11.glTranslated(x + (115 / 2) - 10, y + 10, 0);
GL11.glTranslated(x + xPos - (width / 2), y + yPos + (width / 2), 0);
GL11.glDisable(GL11.GL_CULL_FACE);

GL11.glRotated(150, 1.0, 0.0, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.dyonovan.modernalchemy.manual.component.ComponentHeader;
import com.dyonovan.modernalchemy.manual.component.ComponentSet;
import com.dyonovan.modernalchemy.manual.component.IComponent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.GuiScreenEvent;
Expand All @@ -15,8 +20,10 @@
import java.util.ArrayList;
import java.util.List;

@SideOnly(Side.CLIENT)
public class GuiManual extends BaseGui implements Comparable<GuiManual> {

public static int inputDelay = 0;
/**
* The list of components on the pages
*/
Expand Down Expand Up @@ -97,6 +104,7 @@ public void drawScreen(int mouseX, int mouseY, float par3) {
for(int i = 0; i < pages.get(currentIndex).size(); i++) {
pages.get(currentIndex).get(i).drawComponent(guiLeft, guiTop, mouseX, mouseY);
}
inputDelay--;
}

@Override
Expand Down Expand Up @@ -159,6 +167,10 @@ protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}

public static void playClickSound()
{
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
@Override
public int compareTo(GuiManual o) {
return this.id.equalsIgnoreCase(o.id) ? 0 : 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.dyonovan.modernalchemy.manual;
package com.dyonovan.modernalchemy.manual.util;

import com.dyonovan.modernalchemy.manual.component.IComponent;
import net.minecraft.util.ResourceLocation;

import java.util.ArrayList;

public class ManualComponents {
public class AbstractComponent {

public int xPos, yPos, width, height, pageNum;
public String text, destination, type, item;
public IComponent.ALIGNMENT alignment;
public ResourceLocation resource;
public ArrayList<String> tooltips;

public ManualComponents(String type, int xPos, int yPos, int width, int height, IComponent.ALIGNMENT align, int pageNum, String text, String destination,
String item, ResourceLocation resource, ArrayList<String> tooltips) {
public AbstractComponent(String type, int xPos, int yPos, int width, int height, IComponent.ALIGNMENT align, int pageNum, String text, String destination,
String item, ResourceLocation resource, ArrayList<String> tooltips) {

this.type = type;
this.xPos = xPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dyonovan.modernalchemy.manual.util;

import java.util.ArrayList;

public class AbstractManualPage {

public String title;
public int numPages;
public ArrayList<AbstractComponent> component;

public AbstractManualPage(String title, int numPages, ArrayList<AbstractComponent> component) {
this.title = title;
this.numPages = numPages;
this.component = component;
}
}
Loading

0 comments on commit d0459ed

Please sign in to comment.