mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-20 03:59:41 +00:00
Add a new GUI and merge repeated code
This commit is contained in:
1 parent
77932520c2
commit
b9979c365f
15 files changed
+330
-149
No files matched your search
@@ -5,6 +5,7 @@ import mezz.jei.gui.ItemListOverlay;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -93,4 +94,11 @@ public class GuiEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onOpen(GuiOpenEvent event){
|
||||
if(event.gui instanceof GuiCalculator){
|
||||
((GuiCalculator) event.gui).onOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import pers.towdium.justEnoughCalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,7 @@ import pers.towdium.justEnoughCalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
public static final class GuiId{
|
||||
public static final int CALCULATOR = 0;
|
||||
public static final int ITEM_PICKER = 1;
|
||||
public static final int RECIPE_VIEWER = 1;
|
||||
public static final int RECIPE_EDITOR = 2;
|
||||
public static final int RECIPE_PICKER = 3;
|
||||
}
|
||||
@@ -32,8 +34,9 @@ public class GuiHandler implements IGuiHandler {
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
switch (ID) {
|
||||
case GuiId.CALCULATOR: return new GuiCalculator(new ContainerCalculator(player, player.getHeldItem()));
|
||||
case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor());
|
||||
case GuiId.RECIPE_PICKER: return new GuiRecipePicker(new ContainerRecipe(), JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null));
|
||||
case GuiId.RECIPE_VIEWER: return new GuiRecipeViewer(new ContainerRecipeViewer(), null);
|
||||
case GuiId.RECIPE_EDITOR: return new GuiRecipeEditor(new ContainerRecipeEditor(), null);
|
||||
case GuiId.RECIPE_PICKER: return new GuiRecipePicker(new ContainerRecipe(), null, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
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.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.calculator.ContainerCalculator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public abstract class GuiJustEnoughCalculation extends GuiContainer {
|
||||
protected GuiScreen parent;
|
||||
|
||||
public GuiJustEnoughCalculation(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
|
||||
super(inventorySlotsIn);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn != null)
|
||||
{
|
||||
slotId = slotIn.slotNumber;
|
||||
}
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int mouseButton){
|
||||
try {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
public void click(int index){
|
||||
for(GuiButton button : buttonList){
|
||||
if(button.id == index){
|
||||
try {
|
||||
actionPerformed(button);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) {
|
||||
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
public void updateLayout(){}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if(keyCode == 1){
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
ModelManager modelManager = null;
|
||||
Field[] fields = mc.getClass().getDeclaredFields();
|
||||
for(Field field : fields){
|
||||
if(ModelManager.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
modelManager = (ModelManager) field.get(mc);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(modelManager != null){
|
||||
itemRender = new RenderItem(mc.renderEngine, modelManager){
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(fr, stack, xPosition, yPosition, ItemStackWrapper.getDisplayAmount(stack));
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -11,12 +12,15 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* CODE IS DONE BY Zyin055
|
||||
* A GuiScreen replacement that supports putting tooltips onto GuiButtons.
|
||||
* SEE HERE: www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/1437428-guide-1-7-2-how-to-make-button-tooltips
|
||||
*/
|
||||
public abstract class GuiTooltipScreen extends GuiContainer
|
||||
public abstract class GuiTooltipScreen extends GuiJustEnoughCalculation
|
||||
{
|
||||
/** Show a white "?" in the top right part of any button with a tooltip assigned to it */
|
||||
public static boolean ShowTooltipButtonEffect = true;
|
||||
@@ -41,8 +45,8 @@ public abstract class GuiTooltipScreen extends GuiContainer
|
||||
private long mouseoverTime = 0;
|
||||
private long prevSystemTime = -1;
|
||||
|
||||
public GuiTooltipScreen(Container inventorySlotsIn) {
|
||||
super(inventorySlotsIn);
|
||||
public GuiTooltipScreen(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
|
||||
super(inventorySlotsIn, parent);
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float f)
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.commom.recipe;
|
||||
|
||||
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.GlStateManager;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -16,24 +13,19 @@ import pers.towdium.justEnoughCalculation.core.ItemStackWrapper;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiTooltipScreen;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipe extends GuiTooltipScreen{
|
||||
protected GuiScreen parent;
|
||||
protected int activeSlot = -1;
|
||||
|
||||
public GuiRecipe(ContainerRecipe containerRecipe, GuiScreen parent){
|
||||
super(containerRecipe);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public GuiRecipe(ContainerRecipe containerRecipe){
|
||||
super(containerRecipe);
|
||||
public GuiRecipe(@Nonnull Container inventorySlotsIn, @Nullable GuiScreen parent) {
|
||||
super(inventorySlotsIn, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,13 +35,13 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
i = 0; left = 31 + guiLeft; top = 7 + guiTop;
|
||||
for(int a = 0; a < 2; a++){
|
||||
for(int b =0; b < 2; b++){
|
||||
buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "N"));
|
||||
buttonList.add(new GuiButton(i+2*a+b, left+b*59, top+a*24, 20, 20, "#"));
|
||||
}
|
||||
}
|
||||
i = 4; left = 31 + guiLeft; top = 67 + guiTop;
|
||||
for(int a = 0; a < 4; a++){
|
||||
for(int b =0; b < 3; b++){
|
||||
buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "N"));
|
||||
buttonList.add(new GuiButton(i+3*a+b, left+b*59, top+a*24, 20, 20, "#"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,19 +62,16 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
int buttonId = button.id;
|
||||
if(buttonId <= 15){
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
if(button.displayString.equals("N")){
|
||||
if(button.displayString.equals("#")){
|
||||
slot.putStack(ItemStackWrapper.toPercentage(slot.getStack()));
|
||||
button.displayString = "P";
|
||||
button.displayString = "%";
|
||||
}else {
|
||||
slot.putStack(ItemStackWrapper.toNormal(slot.getStack()));
|
||||
button.displayString = "N";
|
||||
button.displayString = "#";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
@@ -93,67 +82,13 @@ public class GuiRecipe extends GuiTooltipScreen{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn != null)
|
||||
{
|
||||
slotId = slotIn.slotNumber;
|
||||
}
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (keyCode == 1) {
|
||||
if(activeSlot != -1){
|
||||
setActiveSlot(-1);
|
||||
}else {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
ModelManager modelManager = null;
|
||||
Field[] fields = mc.getClass().getDeclaredFields();
|
||||
for(Field field : fields){
|
||||
if(ModelManager.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
modelManager = (ModelManager) field.get(mc);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(modelManager != null){
|
||||
itemRender = new RenderItem(mc.renderEngine, modelManager){
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(fr, stack, xPosition, yPosition, ItemStackWrapper.getDisplayAmount(stack));
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void click(int mouseX, int mouseY, int mouseButton){
|
||||
try {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
public void click(int index){
|
||||
for(GuiButton button : buttonList){
|
||||
if(button.id == index){
|
||||
try {
|
||||
actionPerformed(button);
|
||||
} catch (IOException ignored) {}
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-54
@@ -1,12 +1,8 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.guis.calculator;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -19,10 +15,11 @@ import pers.towdium.justEnoughCalculation.gui.commom.recipe.ContainerRecipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipePicker.GuiRecipePicker;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.ContainerRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeViewer.GuiRecipeViewer;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketSyncRecord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -41,14 +38,14 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
Calculator.CostRecord costRecord;
|
||||
int activeSlot = -1;
|
||||
int page = 1;
|
||||
int total = 1;
|
||||
int total = 0;
|
||||
EnumMode mode = EnumMode.INPUT;
|
||||
ItemStack buffer;
|
||||
|
||||
public enum EnumMode {INPUT, OUTPUT, CATALYST}
|
||||
|
||||
public GuiCalculator(ContainerCalculator containerCalculator){
|
||||
super(containerCalculator);
|
||||
super(containerCalculator, null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketSyncRecord());
|
||||
}
|
||||
|
||||
@@ -73,6 +70,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
ItemStack itemStack = ((ContainerCalculator)inventorySlots).getPlayer().getHeldItem();
|
||||
dest.inventory.setInventorySlotContents(dest.getSlotIndex(), ItemStackWrapper.NBT.getItem(itemStack, "dest"));
|
||||
textFieldAmount.setText(ItemStackWrapper.NBT.getString(itemStack, "text"));
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +91,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
fontRendererObj.drawString("x", 30, 13, 4210752);
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 4210752);
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 46, 145, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +101,6 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
case 3: return StatCollector.translateToLocal("gui.calculator.editTooltip");
|
||||
case 7: return StatCollector.translateToLocal("gui.calculator.viewTooltip");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -154,7 +151,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
page = 1;
|
||||
break;
|
||||
case 7:
|
||||
mc.displayGuiScreen(new GuiRecipePicker(new ContainerRecipe(), this, JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null)));
|
||||
mc.displayGuiScreen(new GuiRecipeViewer(new ContainerRecipeViewer(), this));
|
||||
break;
|
||||
}
|
||||
updateLayout();
|
||||
@@ -182,53 +179,12 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
inventorySlots.getSlot(activeSlot).putStack(buffer);
|
||||
setActiveSlot(-1);
|
||||
}else {
|
||||
((ContainerCalculator)inventorySlots).getPlayer().closeScreen();
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().syncItemCalculator(inventorySlots.getSlot(0).getStack(), textFieldAmount.getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
ModelManager modelManager = null;
|
||||
Field[] fields = mc.getClass().getDeclaredFields();
|
||||
for(Field field : fields){
|
||||
if(ModelManager.class.equals(field.getType())){
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
modelManager = (ModelManager) field.get(mc);
|
||||
break;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(modelManager != null){
|
||||
itemRender = new RenderItem(mc.renderEngine, modelManager){
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
super.renderItemOverlayIntoGUI(fr, stack, xPosition, yPosition, ItemStackWrapper.getDisplayAmount(stack));
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
};
|
||||
}
|
||||
costRecord = null;
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn != null)
|
||||
{
|
||||
slotId = slotIn.slotNumber;
|
||||
}
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
public void updateLayout(){
|
||||
@@ -265,6 +221,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
}
|
||||
}else {
|
||||
fillSlotsWith(new ItemStack[0], 0);
|
||||
total = 0;
|
||||
}
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
@@ -284,8 +241,11 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
public void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) {
|
||||
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
|
||||
public void onOpen(){
|
||||
costRecord = null;
|
||||
if(buttonRight != null){
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSlotsWith(ItemStack[] itemStacks, int start){
|
||||
|
||||
+3
-4
@@ -27,10 +27,6 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
super(containerRecipeEditor, parent);
|
||||
}
|
||||
|
||||
public GuiRecipeEditor(ContainerRecipeEditor containerRecipeEditor){
|
||||
super(containerRecipeEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
@@ -41,6 +37,9 @@ public class GuiRecipeEditor extends GuiRecipe{
|
||||
super.initGui();
|
||||
buttonList.add(new GuiButton(16, guiLeft+125, guiTop+7, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.save")));
|
||||
buttonList.add(new GuiButton(17, guiLeft+125, guiTop+31, 44, 20, StatCollector.translateToLocal("gui.recipeEditor.clear")));
|
||||
if(index != -1){
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(index, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-5
@@ -28,11 +28,6 @@ public class GuiRecipePicker extends GuiRecipe{
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public GuiRecipePicker(ContainerRecipe containerRecipe, List<Integer> recipes){
|
||||
super(containerRecipe);
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.guis.recipeViewer;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ContainerRecipeViewer extends Container {
|
||||
InventoryBasic inventory = new InventoryBasic("RecipeViewer", false, 24);
|
||||
|
||||
public ContainerRecipeViewer(){
|
||||
int i, left, top;
|
||||
i = 0; left = 8; top = 8;
|
||||
for(int a = 0; a < 6; a++){
|
||||
for(int b =0; b < 4; b++){
|
||||
addSlotToContainer(new Slot(inventory,i+4*a+b,left+b*18,top+a*22));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package pers.towdium.justEnoughCalculation.gui.guis.recipeViewer;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.fml.client.config.GuiButtonExt;
|
||||
import pers.towdium.justEnoughCalculation.JustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.core.Recipe;
|
||||
import pers.towdium.justEnoughCalculation.gui.commom.GuiJustEnoughCalculation;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.ContainerRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.gui.guis.recipeEditor.GuiRecipeEditor;
|
||||
import pers.towdium.justEnoughCalculation.network.packets.PacketRecipeUpdate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class GuiRecipeViewer extends GuiJustEnoughCalculation {
|
||||
List<Integer> recipes;
|
||||
GuiButton buttonLeft;
|
||||
GuiButton buttonRight;
|
||||
int page = 1;
|
||||
int total;
|
||||
|
||||
public GuiRecipeViewer (@NotNull ContainerRecipeViewer container, @Nullable GuiScreen parent){
|
||||
super(container, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonLeft = new GuiButton(0, guiLeft+7, guiTop+139, 20, 20, "<");
|
||||
buttonRight = new GuiButton(1, guiLeft+149, guiTop+139, 20, 20, ">");
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
for(int i=0; i<6; i++){
|
||||
buttonList.add(new GuiButtonExt(2+2*i, guiLeft+83, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.edit")));
|
||||
buttonList.add(new GuiButtonExt(3+2*i, guiLeft+128, guiTop+7+22*i, 41, 18, StatCollector.translateToLocal("gui.recipeViewer.delete")));
|
||||
}
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.getTextureManager().bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,"textures/gui/guiRecipeViewer.png"));
|
||||
drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 88, 145, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLayout() {
|
||||
recipes = JustEnoughCalculation.proxy.getPlayerHandler().getAllRecipeIndex(null);
|
||||
total = recipes == null ? 0 : (recipes.size()+5)/6;
|
||||
if(page>total){
|
||||
page = total;
|
||||
}
|
||||
displayRecipes();
|
||||
buttonLeft.enabled = page != 1;
|
||||
buttonRight.enabled = page < total;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
int i = button.id;
|
||||
switch (i){
|
||||
case 0:
|
||||
page--;
|
||||
updateLayout();
|
||||
break;
|
||||
case 1:
|
||||
page++;
|
||||
updateLayout();
|
||||
break;
|
||||
default:
|
||||
if(i%2 == 0){
|
||||
mc.displayGuiScreen(new GuiRecipeEditor(new ContainerRecipeEditor(), this, recipes.get((page-1)*6+i/2-1)));
|
||||
}else{
|
||||
JustEnoughCalculation.proxy.getPlayerHandler().removeRecipe(recipes.get((page-1)*6+i/2-1), null);
|
||||
JustEnoughCalculation.networkWrapper.sendToServer(new PacketRecipeUpdate(null, recipes.get((page-1)*6+i/2-1)));
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display the recipe at the position
|
||||
* @param position range 1-6
|
||||
*/
|
||||
public void displayRecipe(@Nullable Recipe recipe, int position){
|
||||
if(recipe != null){
|
||||
List<ItemStack> items = recipe.getOutput();
|
||||
for(int i=0; i<4; i++){
|
||||
if(i<items.size()){
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(items.get(i));
|
||||
}else {
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(null);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(int i=0; i<4; i++){
|
||||
inventorySlots.getSlot((position-1)*4+i).putStack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void displayRecipes(){
|
||||
if(recipes != null){
|
||||
for(int i=1; i<=6; i++){
|
||||
int index = i-1+6*(page-1);
|
||||
if(index<recipes.size()){
|
||||
displayRecipe(JustEnoughCalculation.proxy.getPlayerHandler().getRecipe(recipes.get(index), null), i);
|
||||
}else {
|
||||
displayRecipe(null, i);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for(int i=1; i<=6; i++){
|
||||
displayRecipe(null, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,4 @@ public class ItemCalculator extends Item {
|
||||
playerIn.openGui(JustEnoughCalculation.instance, GuiHandler.GuiId.CALCULATOR, worldIn, 0, 0, 0);
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index, UUID uuid) {
|
||||
return recipes.get(index);
|
||||
return index<recipes.size() ? recipes.get(index) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user