mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
the selection
This commit is contained in:
parent
e9b809d9dc
commit
0c9bea7091
@ -41,7 +41,7 @@ public class GUIMachineChemicalPlant extends GuiInfoContainer {
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
|
||||
if(this.checkClick(x, y, 7, 125, 18, 18)) GUIScreenRecipeSelector.openSelector(ChemicalPlantRecipes.INSTANCE, chemplant, "", 0, this);
|
||||
if(this.checkClick(x, y, 7, 125, 18, 18)) GUIScreenRecipeSelector.openSelector(ChemicalPlantRecipes.INSTANCE, chemplant, chemplant.chemplantModule.recipe, 0, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,25 +1,45 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.hbm.interfaces.IControlReceiver;
|
||||
import com.hbm.inventory.recipes.loader.GenericRecipe;
|
||||
import com.hbm.inventory.recipes.loader.GenericRecipes;
|
||||
import com.hbm.lib.RefStrings;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GUIScreenRecipeSelector extends GuiScreen {
|
||||
|
||||
protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_recipe_selector.png");
|
||||
|
||||
//basic GUI setup
|
||||
protected int xSize = 176;
|
||||
protected int ySize = 132;
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
|
||||
// search crap
|
||||
protected GenericRecipes recipeSet;
|
||||
protected List<GenericRecipe> recipes = new ArrayList();
|
||||
protected GuiTextField search;
|
||||
protected int pageIndex;
|
||||
protected int size;
|
||||
protected String selection;
|
||||
// callback
|
||||
protected int index;
|
||||
protected IControlReceiver tile;
|
||||
protected GuiScreen previousScreen;
|
||||
|
||||
public static void openSelector(GenericRecipes recipeSet, IControlReceiver tile, String selection, int index, GuiScreen previousScreen) {
|
||||
@ -27,7 +47,13 @@ public class GUIScreenRecipeSelector extends GuiScreen {
|
||||
}
|
||||
|
||||
public GUIScreenRecipeSelector(GenericRecipes recipeSet, IControlReceiver tile, String selection, int index, GuiScreen previousScreen) {
|
||||
this.recipeSet = recipeSet;
|
||||
this.tile = tile;
|
||||
this.selection = selection;
|
||||
this.index = index;
|
||||
this.previousScreen = previousScreen;
|
||||
|
||||
regenerateRecipes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,6 +61,41 @@ public class GUIScreenRecipeSelector extends GuiScreen {
|
||||
super.initGui();
|
||||
this.guiLeft = (this.width - this.xSize) / 2;
|
||||
this.guiTop = (this.height - this.ySize) / 2;
|
||||
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.search = new GuiTextField(this.fontRendererObj, guiLeft + 28, guiTop + 111, 102, 12);
|
||||
this.search.setTextColor(-1);
|
||||
this.search.setDisabledTextColour(-1);
|
||||
this.search.setEnableBackgroundDrawing(false);
|
||||
this.search.setMaxStringLength(32);
|
||||
}
|
||||
|
||||
private void regenerateRecipes() {
|
||||
|
||||
this.recipes.clear();
|
||||
this.recipes.addAll(recipeSet.recipeOrderedList);
|
||||
|
||||
resetPaging();
|
||||
}
|
||||
|
||||
private void search(String search) {
|
||||
this.recipes.clear();
|
||||
|
||||
if(search.isEmpty()) {
|
||||
this.recipes.addAll(recipeSet.recipeOrderedList);
|
||||
} else {
|
||||
for(Object o : recipeSet.recipeOrderedList) {
|
||||
GenericRecipe recipe = (GenericRecipe) o;
|
||||
if(recipe.matchesSearch(search)) this.recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
resetPaging();
|
||||
}
|
||||
|
||||
private void resetPaging() {
|
||||
this.pageIndex = 0;
|
||||
this.size = Math.max(0, (int)Math.ceil((this.recipes.size() - 40) / 8D));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,6 +105,16 @@ public class GUIScreenRecipeSelector extends GuiScreen {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
this.handleScroll();
|
||||
}
|
||||
|
||||
protected void handleScroll() {
|
||||
|
||||
if(!Mouse.isButtonDown(0) && !Mouse.isButtonDown(1) && Mouse.next()) {
|
||||
int scroll = Mouse.getEventDWheel();
|
||||
if(scroll > 0 && this.pageIndex > 0) this.pageIndex--;
|
||||
if(scroll < 0 && this.pageIndex < this.size) this.pageIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawGuiContainerForegroundLayer(int x, int y) {
|
||||
@ -54,14 +125,53 @@ public class GUIScreenRecipeSelector extends GuiScreen {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
for(int i = pageIndex * 8; i < pageIndex * 8 + 40; i++) {
|
||||
if(i >= recipes.size()) break;
|
||||
|
||||
int ind = i - pageIndex * 8;
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
|
||||
GenericRecipe recipe = recipes.get(i);
|
||||
|
||||
FontRenderer font = recipe.getIcon().getItem().getFontRenderer(recipe.getIcon());
|
||||
if(font == null) font = fontRendererObj;
|
||||
|
||||
itemRender.zLevel = 100.0F;
|
||||
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), recipe.getIcon(), guiLeft + 8 + 18 * (ind % 8), guiTop + 18 + 18 * (ind / 8));
|
||||
|
||||
itemRender.zLevel = 0.0F;
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
this.mc.getTextureManager().bindTexture(texture);
|
||||
|
||||
if(recipe.name.equals(this.selection))
|
||||
this.drawTexturedModalRect(guiLeft + 7 + 18 * (ind % 8), guiTop + 17 + 18 * (ind / 8), 192, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
|
||||
if(this.search.textboxKeyTyped(typedChar, keyCode)) {
|
||||
search(this.search.getText());
|
||||
return;
|
||||
}
|
||||
|
||||
if(keyCode == 1 || keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
FMLCommonHandler.instance().showGuiScreen(previousScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
@Override public boolean doesGuiPauseGame() { return false; }
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@ package com.hbm.inventory.recipes;
|
||||
import com.hbm.inventory.FluidStack;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
import com.hbm.inventory.material.MaterialShapes;
|
||||
import com.hbm.inventory.material.Mats;
|
||||
import com.hbm.inventory.material.NTMMaterial;
|
||||
import com.hbm.inventory.recipes.loader.GenericRecipe;
|
||||
import com.hbm.inventory.recipes.loader.GenericRecipes;
|
||||
import com.hbm.items.ModItems;
|
||||
@ -40,5 +43,12 @@ public class ChemicalPlantRecipes extends GenericRecipes<GenericRecipe> {
|
||||
pool.add(new ChanceOutput(new ItemStack(ModItems.billet_cobalt), 5));
|
||||
}})
|
||||
.setOutputFluids(new FluidStack(Fluids.BIOGAS, 2000)));
|
||||
|
||||
for(NTMMaterial mat : Mats.orderedList) {
|
||||
if(mat.autogen.contains(MaterialShapes.CASTPLATE)) this.register(new GenericRecipe(mat.getUnlocalizedName() + ".plate").setup(60, 100).setOutputItems(new ChanceOutput(new ItemStack(ModItems.plate_cast, 1, mat.id))));
|
||||
if(mat.autogen.contains(MaterialShapes.WELDEDPLATE)) this.register(new GenericRecipe(mat.getUnlocalizedName() + ".weld").setup(60, 100).setOutputItems(new ChanceOutput(new ItemStack(ModItems.plate_welded, 1, mat.id))));
|
||||
if(mat.autogen.contains(MaterialShapes.DENSEWIRE)) this.register(new GenericRecipe(mat.getUnlocalizedName() + ".wire").setup(60, 100).setOutputItems(new ChanceOutput(new ItemStack(ModItems.wire_dense, 1, mat.id))));
|
||||
if(mat.autogen.contains(MaterialShapes.MECHANISM)) this.register(new GenericRecipe(mat.getUnlocalizedName() + ".mechanism").setup(60, 100).setOutputItems(new ChanceOutput(new ItemStack(ModItems.part_mechanism, 1, mat.id))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.hbm.inventory.recipes.loader;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.hbm.inventory.FluidStack;
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
import com.hbm.inventory.recipes.loader.GenericRecipes.ChanceOutput;
|
||||
@ -21,7 +23,7 @@ public class GenericRecipe {
|
||||
public FluidStack[] outputFluid;
|
||||
public int duration;
|
||||
public long power;
|
||||
public ItemStack icon;
|
||||
protected ItemStack icon;
|
||||
public boolean writeIcon = false;
|
||||
public boolean customLocalization = false;
|
||||
|
||||
@ -32,6 +34,7 @@ public class GenericRecipe {
|
||||
public GenericRecipe setDuration(int duration) { this.duration = duration; return this; }
|
||||
public GenericRecipe setPower(long power) { this.power = power; return this; }
|
||||
public GenericRecipe setup(int duration, long power) { return this.setDuration(duration).setPower(power); }
|
||||
public GenericRecipe setupNamed(int duration, long power) { return this.setDuration(duration).setPower(power).setNamed(); }
|
||||
public GenericRecipe setIcon(ItemStack icon) { this.icon = icon; this.writeIcon = true; return this; }
|
||||
public GenericRecipe setIcon(Item item, int meta) { return this.setIcon(new ItemStack(item, 1, meta)); }
|
||||
public GenericRecipe setIcon(Item item) { return this.setIcon(new ItemStack(item)); }
|
||||
@ -60,10 +63,11 @@ public class GenericRecipe {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if(customLocalization) {
|
||||
return I18nUtil.resolveKey(name);
|
||||
}
|
||||
|
||||
if(customLocalization) return I18nUtil.resolveKey(name);
|
||||
return this.getIcon().getDisplayName();
|
||||
}
|
||||
|
||||
public boolean matchesSearch(String substring) {
|
||||
return getName().toLowerCase(Locale.US).contains(substring.toLowerCase(Locale.US));
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ public abstract class GenericRecipes<T extends GenericRecipe> extends Serializab
|
||||
if(this.hasPower()) recipe.setPower(obj.get("power").getAsLong());
|
||||
|
||||
if(obj.has("icon")) recipe.setIcon(this.readItemStack(obj.get("icon").getAsJsonArray()));
|
||||
if(obj.has("named") && obj.get("named").getAsBoolean()) recipe.setNamed();
|
||||
|
||||
readExtraData(element, recipe);
|
||||
|
||||
@ -117,6 +118,8 @@ public abstract class GenericRecipes<T extends GenericRecipe> extends Serializab
|
||||
this.writeItemStack(recipe.icon, writer);
|
||||
}
|
||||
|
||||
if(recipe.customLocalization) writer.name("named").value(true);
|
||||
|
||||
writeExtraData(recipe, writer);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user