diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-01-20 14:24:34 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-01-20 14:24:34 +1000 |
| commit | 869c206c4fcc8001bd2e1d66f704290331813835 (patch) | |
| tree | 96735ce8fe4665e2759c3374221d6f06f4527df2 /src/Java/binnie/craftgui/binniecore | |
| parent | ec2c72827f01dd4bb2174137f1ab162f9ddaab62 (diff) | |
| download | GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.gz GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.bz2 GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.zip | |
Initial Commit
Diffstat (limited to 'src/Java/binnie/craftgui/binniecore')
| -rw-r--r-- | src/Java/binnie/craftgui/binniecore/WindowFieldKit.java | 334 | ||||
| -rw-r--r-- | src/Java/binnie/craftgui/binniecore/WindowGenesis.java | 264 |
2 files changed, 598 insertions, 0 deletions
diff --git a/src/Java/binnie/craftgui/binniecore/WindowFieldKit.java b/src/Java/binnie/craftgui/binniecore/WindowFieldKit.java new file mode 100644 index 0000000000..d52a6cde31 --- /dev/null +++ b/src/Java/binnie/craftgui/binniecore/WindowFieldKit.java @@ -0,0 +1,334 @@ +package binnie.craftgui.binniecore; + +import binnie.Binnie; +import binnie.core.AbstractMod; +import binnie.core.BinnieCore; +import binnie.core.genetics.BreedingSystem; +import binnie.core.genetics.ManagerGenetics; +import binnie.core.language.ManagerLanguage; +import binnie.core.machines.inventory.SlotValidator; +import binnie.core.machines.inventory.ValidatorIcon; +import binnie.craftgui.controls.ControlText; +import binnie.craftgui.controls.core.Control; +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.geometry.TextJustification; +import binnie.craftgui.core.renderer.Renderer; +import binnie.craftgui.events.EventHandler.Origin; +import binnie.craftgui.events.EventValueChanged; +import binnie.craftgui.events.EventValueChanged.Handler; +import binnie.craftgui.minecraft.InventoryType; +import binnie.craftgui.minecraft.Window; +import binnie.craftgui.minecraft.WindowInventory; +import binnie.craftgui.minecraft.control.ControlImage; +import binnie.craftgui.minecraft.control.ControlPlayerInventory; +import binnie.craftgui.minecraft.control.ControlSlot; +import binnie.craftgui.resource.StyleSheet; +import binnie.craftgui.resource.minecraft.CraftGUITexture; +import binnie.craftgui.resource.minecraft.PaddedTexture; +import binnie.craftgui.resource.minecraft.StandardTexture; +import binnie.extrabees.core.ExtraBeeTexture; +import binnie.extrabees.gui.punnett.ExtraBeeGUITexture; +import binnie.genetics.gui.ControlChromosome; +import binnie.genetics.machine.Analyser; +import cpw.mods.fml.relauncher.Side; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IGenome; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class WindowFieldKit + extends Window +{ + public WindowFieldKit(EntityPlayer player, IInventory inventory, Side side) + { + super(280.0F, 230.0F, player, inventory, side); + } + + protected AbstractMod getMod() + { + return BinnieCore.instance; + } + + protected String getName() + { + return "Field Kit"; + } + + private void setupValidators() + { + getWindowInventory().setValidator(0, new SlotValidator(null) + { + public boolean isValid(ItemStack object) + { + return (AlleleManager.alleleRegistry.isIndividual(object)) || (Binnie.Genetics.getConversion(object) != null); + } + + public String getTooltip() + { + return "Individual"; + } + }); + getWindowInventory().setValidator(1, new SlotValidator(null) + { + public boolean isValid(ItemStack object) + { + return object.getItem() == Items.paper; + } + + public String getTooltip() + { + return "Paper"; + } + }); + getWindowInventory().disableAutoDispense(1); + } + + public void initialiseClient() + { + setTitle("Field Kit"); + + CraftGUI.Render.stylesheet(new StyleSheetPunnett()); + + getWindowInventory().createSlot(0); + getWindowInventory().createSlot(1); + + setupValidators(); + + new ControlPlayerInventory(this); + + IPoint handGlass = new IPoint(16.0F, 32.0F); + this.GlassControl = new ControlImage(this, handGlass.x(), handGlass.y(), new StandardTexture(0, 160, 96, 96, ExtraBeeTexture.GUIPunnett)); + new ControlSlot(this, handGlass.x() + 54.0F, handGlass.y() + 26.0F).assign(InventoryType.Window, 0); + + new ControlSlot(this, 208.0F, 8.0F).assign(InventoryType.Window, 1); + + this.text = new ControlText(this, new IPoint(232.0F, 13.0F), "Paper"); + this.text.setColour(2236962); + + this.text = new ControlText(this, new IArea(0.0F, 120.0F, w(), 24.0F), "", TextJustification.MiddleCenter); + this.text.setColour(2236962); + + this.chromo = new ControlChromosome(this, 150.0F, 24.0F); + + addEventHandler(new EventValueChanged.Handler() + { + public void onEvent(EventValueChanged event) + { + IChromosomeType type = (IChromosomeType)event.getValue(); + if ((type != null) && (WindowFieldKit.this.info.containsKey(type))) + { + String t = (String)WindowFieldKit.this.info.get(type); + WindowFieldKit.this.text.setValue(t); + } + else + { + WindowFieldKit.this.text.setValue(""); + } + } + }.setOrigin(EventHandler.Origin.DirectChild, this.chromo)); + } + + public void initialiseServer() + { + ItemStack kit = getPlayer().getHeldItem(); + int sheets = 64 - kit.getItemDamage(); + if (sheets != 0) { + getWindowInventory().setInventorySlotContents(1, new ItemStack(Items.paper, sheets)); + } + setupValidators(); + } + + private float glassOffsetX = 0.0F; + private float glassOffsetY = 0.0F; + private float glassVX = 0.0F; + private float glassVY = 0.0F; + private Random glassRand = new Random(); + private Control GlassControl; + private ControlChromosome chromo; + private ControlText text; + private float analyseProgress = 1.0F; + private boolean isAnalysing = false; + + public void onUpdateClient() + { + super.onUpdateClient(); + if (this.isAnalysing) + { + this.analyseProgress += 0.01F; + if (this.analyseProgress >= 1.0F) + { + this.isAnalysing = false; + this.analyseProgress = 1.0F; + ItemStack stack = getWindowInventory().getStackInSlot(0); + if (stack != null) { + sendClientAction("analyse", new NBTTagCompound()); + } + refreshSpecies(); + } + } + this.glassVX += this.glassRand.nextFloat() - 0.5F - this.glassOffsetX * 0.2F; + this.glassVY += this.glassRand.nextFloat() - 0.5F - this.glassOffsetY * 0.2F; + + this.glassOffsetX += this.glassVX; + this.glassOffsetX *= (1.0F - this.analyseProgress); + this.glassOffsetY += this.glassVY; + this.glassOffsetY *= (1.0F - this.analyseProgress); + + this.GlassControl.setOffset(new IPoint(this.glassOffsetX, this.glassOffsetY)); + } + + private Map<IChromosomeType, String> info = new HashMap(); + + private void refreshSpecies() + { + ItemStack item = getWindowInventory().getStackInSlot(0); + if ((item == null) || (!AlleleManager.alleleRegistry.isIndividual(item))) { + return; + } + IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item); + if (ind == null) { + return; + } + ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item); + this.chromo.setRoot(root); + Random rand = new Random(); + this.info.clear(); + for (IChromosomeType type : root.getKaryotype()) { + if (!Binnie.Genetics.isInvalidChromosome(type)) + { + IAllele allele = ind.getGenome().getActiveAllele(type); + List<String> infos = new ArrayList(); + int i = 0; + String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + "."; + while (Binnie.Language.canLocalise(pref + i)) + { + infos.add(Binnie.Language.localise(pref + i)); + i++; + } + String text = Binnie.Genetics.getSystem(root).getAlleleName(type, allele); + if (!infos.isEmpty()) { + text = (String)infos.get(rand.nextInt(infos.size())); + } + this.info.put(type, text); + this.chromo.setRoot(root); + } + } + } + + private ItemStack prev = null; + + public void onWindowInventoryChanged() + { + super.onWindowInventoryChanged(); + if (isServer()) + { + ItemStack kit = getPlayer().getHeldItem(); + int sheets = 64 - kit.getItemDamage(); + int size = getWindowInventory().getStackInSlot(1) == null ? 0 : getWindowInventory().getStackInSlot(1).stackSize; + if (sheets != size) { + kit.setItemDamage(64 - size); + } + ((EntityPlayerMP)getPlayer()).updateHeldItem(); + } + if (isClient()) + { + ItemStack item = getWindowInventory().getStackInSlot(0); + this.prev = item; + this.text.setValue(""); + if ((item != null) && (!Analyser.isAnalysed(item))) + { + if (getWindowInventory().getStackInSlot(1) == null) + { + this.text.setValue("No Paper!"); + this.isAnalysing = false; + this.analyseProgress = 1.0F; + } + else + { + startAnalysing(); + this.chromo.setRoot(null); + if (!damageKit()) {} + } + } + else if (item != null) + { + this.isAnalysing = false; + this.analyseProgress = 1.0F; + refreshSpecies(); + if (!damageKit()) {} + } + else + { + this.isAnalysing = false; + this.analyseProgress = 1.0F; + + this.chromo.setRoot(null); + } + } + } + + private boolean damageKit() + { + return false; + } + + private void startAnalysing() + { + this.glassVX = 0.0F; + this.glassVY = 0.0F; + this.glassOffsetX = 0.0F; + this.glassOffsetY = 0.0F; + this.isAnalysing = true; + this.analyseProgress = 0.0F; + } + + public boolean showHelpButton() + { + return true; + } + + public String showInfoButton() + { + return "The Field Kit analyses bees, trees, flowers and butterflies. All that is required is a piece of paper to jot notes"; + } + + public void recieveGuiNBT(Side side, EntityPlayer player, String name, NBTTagCompound action) + { + super.recieveGuiNBT(side, player, name, action); + if ((side == Side.SERVER) && (name.equals("analyse"))) + { + getWindowInventory().setInventorySlotContents(0, Analyser.analyse(getWindowInventory().getStackInSlot(0))); + getWindowInventory().decrStackSize(1, 1); + } + } + + static class StyleSheetPunnett + extends StyleSheet + { + public StyleSheetPunnett() + { + this.textures.put(CraftGUITexture.Window, new PaddedTexture(0, 0, 160, 160, 0, ExtraBeeTexture.GUIPunnett, 32, 32, 32, 32)); + this.textures.put(CraftGUITexture.Slot, new StandardTexture(160, 0, 18, 18, 0, ExtraBeeTexture.GUIPunnett)); + this.textures.put(ExtraBeeGUITexture.Chromosome, new StandardTexture(160, 36, 16, 16, 0, ExtraBeeTexture.GUIPunnett)); + this.textures.put(ExtraBeeGUITexture.Chromosome2, new StandardTexture(160, 52, 16, 16, 0, ExtraBeeTexture.GUIPunnett)); + this.textures.put(CraftGUITexture.HelpButton, new StandardTexture(178, 0, 16, 16, 0, ExtraBeeTexture.GUIPunnett)); + this.textures.put(CraftGUITexture.InfoButton, new StandardTexture(178, 16, 16, 16, 0, ExtraBeeTexture.GUIPunnett)); + } + } +} diff --git a/src/Java/binnie/craftgui/binniecore/WindowGenesis.java b/src/Java/binnie/craftgui/binniecore/WindowGenesis.java new file mode 100644 index 0000000000..8295645f5a --- /dev/null +++ b/src/Java/binnie/craftgui/binniecore/WindowGenesis.java @@ -0,0 +1,264 @@ +package binnie.craftgui.binniecore; + +import binnie.Binnie; +import binnie.core.AbstractMod; +import binnie.core.BinnieCore; +import binnie.core.genetics.BreedingSystem; +import binnie.core.genetics.Gene; +import binnie.core.genetics.ManagerGenetics; +import binnie.craftgui.controls.listbox.ControlList; +import binnie.craftgui.controls.listbox.ControlListBox; +import binnie.craftgui.controls.listbox.ControlTextOption; +import binnie.craftgui.controls.tab.ControlTab; +import binnie.craftgui.controls.tab.ControlTabBar; +import binnie.craftgui.core.IWidget; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.Position; +import binnie.craftgui.events.EventHandler.Origin; +import binnie.craftgui.events.EventMouse.Down; +import binnie.craftgui.events.EventMouse.Down.Handler; +import binnie.craftgui.events.EventValueChanged; +import binnie.craftgui.events.EventValueChanged.Handler; +import binnie.craftgui.minecraft.MinecraftGUI.PanelType; +import binnie.craftgui.minecraft.Window; +import binnie.craftgui.minecraft.control.ControlItemDisplay; +import binnie.craftgui.minecraft.control.ControlPlayerInventory; +import binnie.craftgui.minecraft.control.ControlTabIcon; +import binnie.craftgui.window.Panel; +import binnie.genetics.gui.ControlGenesisOption; +import cpw.mods.fml.relauncher.Side; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class WindowGenesis + extends Window +{ + private ISpeciesRoot root; + private IAllele[] template; + private ControlListBox<Gene> geneList; + private ControlListBox<Gene> geneOptions; + private Panel panelPickup; + + public WindowGenesis(EntityPlayer player, IInventory inventory, Side side) + { + super(342.0F, 228.0F, player, inventory, side); + } + + protected AbstractMod getMod() + { + return BinnieCore.instance; + } + + protected String getName() + { + return "Genesis"; + } + + public void initialiseClient() + { + new ControlPlayerInventory(this); + setTitle("Genesis"); + + ControlTabBar<BreedingSystem> tabSystems = new ControlTabBar(this, 8.0F, 28.0F, 23.0F, 100.0F, Position.Left) + { + public ControlTab<BreedingSystem> createTab(float x, float y, float w, float h, BreedingSystem value) + { + new ControlTabIcon(this, x, y, w, h, value) + { + public ItemStack getItemStack() + { + int type = ((BreedingSystem)this.value).getDefaultType(); + IIndividual ind = ((BreedingSystem)this.value).getDefaultIndividual(); + return ((BreedingSystem)this.value).getSpeciesRoot().getMemberStack(ind, type); + } + + public String getName() + { + return ((BreedingSystem)this.value).getName(); + } + + public int getOutlineColour() + { + return ((BreedingSystem)this.value).getColour(); + } + + public boolean hasOutline() + { + return true; + } + }; + } + }; + tabSystems.setValues(Binnie.Genetics.getActiveSystems()); + + this.root = ((BreedingSystem)Binnie.Genetics.getActiveSystems().iterator().next()).getSpeciesRoot(); + this.template = this.root.getDefaultTemplate(); + + IArea one = new IArea(32.0F, 28.0F, 170.0F, 100.0F); + IArea two = new IArea(214.0F, 28.0F, 100.0F, 100.0F); + + new Panel(this, one.outset(1), MinecraftGUI.PanelType.Black); + new Panel(this, two.outset(1), MinecraftGUI.PanelType.Black); + + this.geneList = new ControlListBox(this, one.x(), one.y(), one.w(), one.h(), 10.0F) + { + public IWidget createOption(Gene value, int y) + { + return new ControlGenesisOption((ControlList)getContent(), value, y); + } + }; + this.geneOptions = new ControlListBox(this, two.x(), two.y(), two.w(), two.h(), 10.0F) + { + public IWidget createOption(Gene value, int y) + { + return new ControlTextOption((ControlList)getContent(), value, y); + } + }; + tabSystems.addEventHandler(new EventValueChanged.Handler() + { + public void onEvent(EventValueChanged event) + { + WindowGenesis.this.root = ((BreedingSystem)event.getValue()).getSpeciesRoot(); + WindowGenesis.this.template = WindowGenesis.this.root.getDefaultTemplate(); + WindowGenesis.this.refreshTemplate(null); + } + }.setOrigin(EventHandler.Origin.Self, tabSystems)); + + + + this.geneList.addEventHandler(new EventValueChanged.Handler() + { + public void onEvent(EventValueChanged event) + { + Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(WindowGenesis.this.root); + List<Gene> opts = new ArrayList(); + IChromosomeType chromo = ((Gene)event.value).getChromosome(); + for (IAllele allele : (List)map.get(chromo)) { + opts.add(new Gene(allele, chromo, WindowGenesis.this.root)); + } + WindowGenesis.this.geneOptions.setOptions(opts); + } + }.setOrigin(EventHandler.Origin.Self, this.geneList)); + + + + this.geneOptions.addEventHandler(new EventValueChanged.Handler() + { + public void onEvent(EventValueChanged event) + { + if (event.value == null) { + return; + } + IChromosomeType chromo = ((Gene)event.value).getChromosome(); + WindowGenesis.this.template[chromo.ordinal()] = ((Gene)event.value).getAllele(); + if (chromo == ((Gene)event.value).getSpeciesRoot().getKaryotypeKey()) { + WindowGenesis.this.template = ((Gene)event.value).getSpeciesRoot().getTemplate(((Gene)event.value).getAllele().getUID()); + } + WindowGenesis.this.refreshTemplate(chromo); + } + }.setOrigin(EventHandler.Origin.Self, this.geneOptions)); + + + + + this.panelPickup = new Panel(this, 16.0F, 140.0F, 60.0F, 42.0F, MinecraftGUI.PanelType.Black); + + refreshTemplate(null); + } + + private void refreshTemplate(IChromosomeType selection) + { + List<Gene> genes = new ArrayList(); + IChromosomeType[] chromos = (IChromosomeType[])Binnie.Genetics.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]); + for (IChromosomeType type : chromos) + { + IAllele allele = this.template[type.ordinal()]; + if (allele == null) { + throw new NullPointerException("Allele missing for Chromosome " + type.getName()); + } + genes.add(new Gene(allele, type, this.root)); + } + Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(this.root); + this.geneList.setOptions(genes); + if (selection != null) { + this.geneList.setValue(new Gene(this.template[selection.ordinal()], selection, this.root)); + } else { + this.geneOptions.setOptions(new ArrayList()); + } + refreshPickup(); + } + + private void refreshPickup() + { + this.panelPickup.deleteAllChildren(); + int i = 0; + for (int type : Binnie.Genetics.getSystem(this.root).getActiveTypes()) + { + IIndividual ind = this.root.templateAsIndividual(this.template); + ind.analyze(); + final ItemStack stack = this.root.getMemberStack(ind, type); + ControlItemDisplay display = new ControlItemDisplay(this.panelPickup, 4 + i % 3 * 18, 4 + i / 3 * 18); + display.setItemStack(stack); + display.setTooltip(); + display.addEventHandler(new EventMouse.Down.Handler() + { + public void onEvent(EventMouse.Down event) + { + NBTTagCompound nbt = new NBTTagCompound(); + stack.writeToNBT(nbt); + Window.get(event.getOrigin()).sendClientAction("genesis", nbt); + } + }.setOrigin(EventHandler.Origin.Self, display)); + + + + i++; + } + } + + public void recieveGuiNBT(Side side, EntityPlayer player, String name, NBTTagCompound action) + { + super.recieveGuiNBT(side, player, name, action); + if ((side == Side.SERVER) && (name.equals("genesis"))) + { + ItemStack stack = ItemStack.loadItemStackFromNBT(action); + InventoryPlayer playerInv = player.inventory; + if (stack == null) { + return; + } + if (playerInv.getItemStack() == null) + { + playerInv.setItemStack(stack); + } + else if ((playerInv.getItemStack().isItemEqual(stack)) && (ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), stack))) + { + int fit = stack.getMaxStackSize() - (stack.stackSize + playerInv.getItemStack().stackSize); + if (fit >= 0) + { + ItemStack rec = stack; + rec.stackSize += playerInv.getItemStack().stackSize; + playerInv.setItemStack(rec); + } + } + player.openContainer.detectAndSendChanges(); + if ((player instanceof EntityPlayerMP)) { + ((EntityPlayerMP)player).updateHeldItem(); + } + } + } +} |
