Search in sources :

Example 1 with ControlTabBar

use of binnie.core.gui.controls.tab.ControlTabBar in project Binnie by ForestryMC.

the class ControlTabIcon method onUpdateClient.

@Override
@SideOnly(Side.CLIENT)
public void onUpdateClient() {
    super.onUpdateClient();
    this.item.setItemStack(this.getItemStack());
    ControlTabBar parent = (ControlTabBar) this.getParent();
    final int x = parent.getDirection().x();
    boolean selected = this.isCurrentSelection() || this.isMouseOver();
    int xOffset = selected ? 0 : (-4 * x);
    Point offset = new Point(xOffset, 0);
    this.item.setOffset(offset);
}
Also used : Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) Point(binnie.core.gui.geometry.Point) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with ControlTabBar

use of binnie.core.gui.controls.tab.ControlTabBar in project Binnie by ForestryMC.

the class WindowAbstractDatabase method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    this.setSize(new Point(176 + this.selectionBoxWidth + 22 + 8, 208));
    this.addEventHandler(EventValueChanged.class, event -> {
        Object value = event.getValue();
        IWidget eventOriginParent = event.getOrigin().getParent();
        if (eventOriginParent instanceof ControlPage && !(value instanceof DatabaseTab)) {
            ControlPage parent = (ControlPage) eventOriginParent;
            if (parent.getValue() instanceof IDatabaseMode) {
                for (IWidget child : parent.getChildren()) {
                    if (child instanceof ControlPages) {
                        if (value == null) {
                            child.hide();
                        } else {
                            child.show();
                            for (IWidget widget : child.getChildren()) {
                                if (widget instanceof PageAbstract) {
                                    PageAbstract pageAbstract = (PageAbstract) widget;
                                    pageAbstract.onValueChanged(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
    this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.DIRECT_CHILD, this, event -> {
        for (final ModeWidgets widgets : WindowAbstractDatabase.this.modes.values()) {
            widgets.getListBox().setValidator(object -> {
                if (Objects.equals(event.getValue(), "")) {
                    return true;
                }
                ControlTextOption controlTextOption = (ControlTextOption) object;
                return controlTextOption.getText().toLowerCase().contains(event.getValue().toLowerCase());
            });
        }
    });
    new ControlHelp(this, 4, 4);
    (this.panelInformation = new Panel(this, 24, 24, 144, 176, MinecraftGUI.PanelType.BLACK)).setColor(860416);
    (this.panelSearch = new Panel(this, 176, 24, this.selectionBoxWidth, 160, MinecraftGUI.PanelType.BLACK)).setColor(860416);
    this.modePages = new ControlPages<>(this, 0, 0, this.getSize().xPos(), this.getSize().yPos());
    new ControlTextEdit(this, 176, 184, this.selectionBoxWidth, 16);
    this.createMode(Mode.SPECIES, new ModeWidgets(Mode.SPECIES, this, (area, modePage) -> {
        final GameProfile playerName = this.getUsername();
        final Collection<IAlleleSpecies> speciesList = this.master ? this.system.getAllSpecies() : this.system.getDiscoveredSpecies(this.getWorld(), playerName);
        ControlSpeciesBox controlSpeciesBox = new ControlSpeciesBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
        controlSpeciesBox.setOptions(speciesList);
        return controlSpeciesBox;
    }));
    this.createMode(Mode.BRANCHES, new ModeWidgets(Mode.BRANCHES, this, (area, modePage) -> {
        final EntityPlayer player = this.getPlayer();
        final GameProfile playerName = player.getGameProfile();
        final Collection<IClassification> speciesList = this.master ? this.system.getAllBranches() : this.system.getDiscoveredBranches(this.getWorld(), playerName);
        ControlBranchBox controlBranchBox = new ControlBranchBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
        controlBranchBox.setOptions(speciesList);
        return controlBranchBox;
    }));
    this.createMode(Mode.BREEDER, new ModeWidgets(Mode.BREEDER, this, (area, modePage) -> {
        return new ControlListBox(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
    }));
    this.addTabs();
    final ControlTabBar<IDatabaseMode> tab = new ControlTabBar<>(this, 176 + this.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, this.modePages.getValues(), DatabaseControlTab::new);
    CraftGUIUtil.linkWidgets(tab, this.modePages);
    this.changeMode(Mode.SPECIES);
    for (final IDatabaseMode mode : this.modes.keySet()) {
        ModeWidgets modeWidgets = this.modes.get(mode);
        modeWidgets.setInfoTabs(new ControlTabBar<>(modeWidgets.getModePage(), 8, 24, 16, 176, Alignment.LEFT, modeWidgets.getInfoPages().getValues()));
        CraftGUIUtil.linkWidgets(modeWidgets.getInfoTabs(), modeWidgets.getInfoPages());
    }
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) ControlTextOption(binnie.core.gui.controls.listbox.ControlTextOption) GameProfile(com.mojang.authlib.GameProfile) HashMap(java.util.HashMap) ControlListBox(binnie.core.gui.controls.listbox.ControlListBox) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) Panel(binnie.core.gui.window.Panel) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) IWidget(binnie.core.api.gui.IWidget) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) CraftGUIUtil(binnie.core.gui.geometry.CraftGUIUtil) MinecraftGUI(binnie.core.gui.minecraft.MinecraftGUI) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ControlPages(binnie.core.gui.controls.page.ControlPages) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) Collection(java.util.Collection) EventTextEdit(binnie.core.gui.events.EventTextEdit) ControlTab(binnie.core.gui.controls.tab.ControlTab) EventValueChanged(binnie.core.gui.events.EventValueChanged) ControlHelp(binnie.core.gui.minecraft.control.ControlHelp) I18N(binnie.core.util.I18N) Objects(java.util.Objects) Alignment(binnie.core.api.gui.Alignment) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EventHandlerOrigin(binnie.core.api.gui.events.EventHandlerOrigin) ControlPage(binnie.core.gui.controls.page.ControlPage) IClassification(forestry.api.genetics.IClassification) Point(binnie.core.gui.geometry.Point) Window(binnie.core.gui.minecraft.Window) ControlPage(binnie.core.gui.controls.page.ControlPage) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) ControlListBox(binnie.core.gui.controls.listbox.ControlListBox) ControlTextOption(binnie.core.gui.controls.listbox.ControlTextOption) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) Panel(binnie.core.gui.window.Panel) ControlPages(binnie.core.gui.controls.page.ControlPages) GameProfile(com.mojang.authlib.GameProfile) ControlHelp(binnie.core.gui.minecraft.control.ControlHelp) Collection(java.util.Collection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IWidget(binnie.core.api.gui.IWidget) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with ControlTabBar

use of binnie.core.gui.controls.tab.ControlTabBar in project Binnie by ForestryMC.

the class WindowGeneBank method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    super.initialiseClient();
    this.addEventHandler(EventValueChanged.class, event -> {
        if (event.getValue() instanceof BreedingSystem) {
            WindowGeneBank.this.genes.setValue((IBreedingSystem) event.getValue());
        }
    });
    int x = 16;
    final int y = 32;
    new ControlPlayerInventory(this, x, y);
    x += 124;
    int boxX = x;
    final int geneBoxWidth = 120;
    new Panel(this, boxX + 24, 32, geneBoxWidth, 120, MinecraftGUI.PanelType.BLACK);
    new Panel(this, boxX + 24 + geneBoxWidth, 32, 14, 120, MinecraftGUI.PanelType.GRAY);
    final ControlScrollableContent<ControlGeneScroll> scroll = new ControlScrollableContent<>(this, boxX + 24 + 2, 34, geneBoxWidth + 10, 116, 12);
    final ControlTextEdit edit = new ControlTextEdit(this, boxX + 27 + geneBoxWidth - 70, 18, 80, 12);
    this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, edit, event -> {
        String value = event.getValue();
        if (value == null) {
            value = "";
        }
        WindowGeneBank.this.genes.setFilter(value);
    });
    this.genes = new ControlGeneScroll(scroll, 1, 1, geneBoxWidth, 116);
    scroll.setScrollableContent(this.genes);
    this.genes.setGenes(Binnie.GENETICS.getFirstActiveSystem());
    final ControlTabBar<IBreedingSystem> tabBar = new GeneBankTabBar(this, boxX);
    tabBar.setValue(Binnie.GENETICS.getFirstActiveSystem());
    boxX -= 8;
    final ControlTabBar<String> infoTabs = new ControlTabBar<>(this, boxX + 8, 160, 16, 50, Alignment.LEFT, Arrays.asList("Info", "Stats", "Ranking"));
    final Panel panelProject = new Panel(this, boxX + 24, 160, geneBoxWidth + 20, 50, MinecraftGUI.PanelType.BLACK);
    int totalGenes = 0;
    int seqGenes = 0;
    for (final IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        final GeneTracker tracker = GeneTracker.getTracker(this.getWorld(), this.getUsername());
        final Map<IChromosomeType, List<IAllele>> genes = Binnie.GENETICS.getChromosomeMap(system.getSpeciesRoot());
        for (final Map.Entry<IChromosomeType, List<IAllele>> entry : genes.entrySet()) {
            totalGenes += entry.getValue().size();
            for (final IAllele allele : entry.getValue()) {
                final Gene gene = new Gene(allele, entry.getKey(), system.getSpeciesRoot());
                if (tracker.isSequenced(gene)) {
                    ++seqGenes;
                }
            }
        }
    }
    new ControlText(panelProject, new Point(4, 4), "§nFull Genome Project");
    new ControlText(panelProject, new Point(4, 18), "§oSequenced §r" + seqGenes + '/' + totalGenes + " §oGenes");
}
Also used : BreedingSystem(binnie.core.genetics.BreedingSystem) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) ControlText(binnie.core.gui.controls.ControlText) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) Point(binnie.core.gui.geometry.Point) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) IAllele(forestry.api.genetics.IAllele) Panel(binnie.core.gui.window.Panel) Gene(binnie.core.genetics.Gene) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType) GeneTracker(binnie.genetics.genetics.GeneTracker) Map(java.util.Map) ControlScrollableContent(binnie.core.gui.controls.scroll.ControlScrollableContent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with ControlTabBar

use of binnie.core.gui.controls.tab.ControlTabBar in project Binnie by ForestryMC.

the class WindowCompartment method initialiseClient.

// TODO: Clean Up, Localise
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    IInventory inventory = this.getInventory();
    IMachine machine = Machine.getMachine(inventory);
    MachinePackage machinePackage = machine.getPackage();
    this.setTitle(machinePackage.getDisplayName());
    int x = 16;
    final int y = 32;
    final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class);
    Integer[] tabs1 = new Integer[0];
    Integer[] tabs2 = new Integer[0];
    if (inv.getTabCount() == 4) {
        tabs1 = new Integer[] { 0, 1 };
        tabs2 = new Integer[] { 2, 3 };
    }
    if (inv.getTabCount() == 6) {
        tabs1 = new Integer[] { 0, 1, 2 };
        tabs2 = new Integer[] { 3, 4, 5 };
    }
    if (inv.getTabCount() == 8) {
        tabs1 = new Integer[] { 0, 1, 2, 3 };
        tabs2 = new Integer[] { 4, 5, 6, 7 };
    }
    final boolean doubleTabbed = tabs2.length > 0;
    final int compartmentPageWidth = 16 + 18 * inv.getPageSize() / 5;
    final int compartmentPageHeight = 106;
    final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24);
    final int compartmentHeight = compartmentPageHeight;
    final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight);
    final ControlTabBar<Integer> tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), (x1, y1, w, h, value) -> {
        return new CompartmentTabIcon(this, x1, y1, w, h, value);
    });
    final String[] tabHelp = { "Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately." };
    tab.addHelp(tabHelp);
    tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> {
        if (event.getValue() == null) {
            return;
        }
        final NBTTagCompound nbt = new NBTTagCompound();
        final int i = (Integer) event.getValue();
        nbt.setByte("i", (byte) i);
        Window.get(tab).sendClientAction("tab-change", nbt);
        WindowCompartment.this.currentTab = i;
    });
    x += 24;
    final ControlPages<Integer> compartmentPages = new ControlPages<>(controlCompartment, 24, 0, compartmentPageWidth, compartmentPageHeight);
    final ControlPage[] page = new ControlPage[inv.getTabCount()];
    for (int p = 0; p < inv.getTabCount(); ++p) {
        page[p] = new ControlPage<>(compartmentPages, p);
    }
    CraftGUIUtil.linkWidgets(tab, compartmentPages);
    int i = 0;
    for (int p2 = 0; p2 < inv.getTabCount(); ++p2) {
        final ControlPage thisPage = page[p2];
        final Panel panel = new CompartmentCenterPanel(this, thisPage);
        this.panels.put(panel, p2);
        final int[] slotsIDs = new int[inv.getPageSize()];
        for (int k = 0; k < inv.getPageSize(); ++k) {
            slotsIDs[k] = i++;
        }
        new ControlSlotArray.Builder(thisPage, 8, 8, inv.getPageSize() / 5, 5).create(slotsIDs);
    }
    x += compartmentPageWidth;
    if (tabs2.length > 0) {
        final ControlTabBar<Integer> tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), (x1, y1, w, h, value) -> {
            return new CompartmentTabIcon(this, x1, y1, w, h, value);
        });
        tab2.setValue(tabs1[0]);
        tab2.addHelp(tabHelp);
        tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> {
            if (event.getValue() == null) {
                return;
            }
            final NBTTagCompound nbt = new NBTTagCompound();
            final int iVal = (Integer) event.getValue();
            nbt.setByte("i", (byte) iVal);
            Window.get(tab).sendClientAction("tab-change", nbt);
            WindowCompartment.this.currentTab = iVal;
        });
        CraftGUIUtil.linkWidgets(tab2, compartmentPages);
        x += 24;
    }
    x += 16;
    this.setSize(new Point(Math.max(32 + compartmentWidth, 252), this.getHeight()));
    controlCompartment.setPosition(new Point((this.getWidth() - controlCompartment.getWidth()) / 2, controlCompartment.getYPos()));
    final ControlPlayerInventory invent = new ControlPlayerInventory(this, true);
    final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT);
    slide.setLabel("Tab Properties");
    slide.setSlide(false);
    slide.addHelp("Tab Properties");
    slide.addHelp("The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it.");
    final Panel tabPropertyPanel = new Panel(slide, 16, 8, 112, 76, MinecraftGUI.PanelType.GRAY);
    int y2 = 4;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Name:");
    final Panel parent = tabPropertyPanel;
    final int x2 = 4;
    y2 += 12;
    (this.tabName = new ControlTextEdit(parent, x2, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> {
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        currentTab.setName(event.getValue());
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Icon: ");
    (this.tabIcon = new ControlItemDisplay(tabPropertyPanel, 58, y2 - 4)).setItemStack(new ItemStack(Items.PAPER));
    this.tabIcon.addAttribute(Attribute.MOUSE_OVER);
    this.tabIcon.addSelfEventHandler(EventMouse.Down.class, event -> {
        if (WindowCompartment.this.getHeldItemStack().isEmpty()) {
            return;
        }
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        final ItemStack stack = WindowCompartment.this.getHeldItemStack().copy();
        stack.setCount(1);
        currentTab.setIcon(stack);
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    this.tabColour = new ControlColourSelector(tabPropertyPanel, 82, y2 - 4, 16, 16, EnumColor.WHITE);
    this.tabIcon.addHelp("Icon for Current Tab");
    this.tabIcon.addHelp("Click here with an item to change");
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Colour: ");
    final int cw = 8;
    final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY);
    for (int cc = 0; cc < 16; ++cc) {
        final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]);
        color.addSelfEventHandler(EventMouse.Down.class, event -> {
            final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
            currentTab.setColor(color.getValue());
            final NBTTagCompound nbt = new NBTTagCompound();
            currentTab.writeToNBT(nbt);
            WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
        });
        color.addHelp("Colour Selector");
        color.addHelp("Select a colour to highlight the current tab");
    }
    y2 += 20;
    final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight);
    searchButton.addHelp("Search Button");
    searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items.");
}
Also used : ControlItemDisplay(binnie.core.gui.minecraft.control.ControlItemDisplay) ControlSlotArray(binnie.core.gui.minecraft.control.ControlSlotArray) ControlPage(binnie.core.gui.controls.page.ControlPage) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Control(binnie.core.gui.controls.core.Control) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) ControlSlide(binnie.core.gui.minecraft.control.ControlSlide) IInventory(net.minecraft.inventory.IInventory) IMachine(binnie.core.machines.IMachine) ControlText(binnie.core.gui.controls.ControlText) Point(binnie.core.gui.geometry.Point) MachinePackage(binnie.core.machines.MachinePackage) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) ControlButton(binnie.core.gui.controls.button.ControlButton) Panel(binnie.core.gui.window.Panel) ControlPages(binnie.core.gui.controls.page.ControlPages) EventMouse(binnie.core.gui.events.EventMouse) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ControlTabBar (binnie.core.gui.controls.tab.ControlTabBar)4 Point (binnie.core.gui.geometry.Point)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 ControlTextEdit (binnie.core.gui.controls.ControlTextEdit)3 Panel (binnie.core.gui.window.Panel)3 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)2 ControlText (binnie.core.gui.controls.ControlText)2 ControlPage (binnie.core.gui.controls.page.ControlPage)2 ControlPages (binnie.core.gui.controls.page.ControlPages)2 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)2 Map (java.util.Map)2 Alignment (binnie.core.api.gui.Alignment)1 IWidget (binnie.core.api.gui.IWidget)1 EventHandlerOrigin (binnie.core.api.gui.events.EventHandlerOrigin)1 BreedingSystem (binnie.core.genetics.BreedingSystem)1 Gene (binnie.core.genetics.Gene)1 ControlButton (binnie.core.gui.controls.button.ControlButton)1 Control (binnie.core.gui.controls.core.Control)1 ControlListBox (binnie.core.gui.controls.listbox.ControlListBox)1 ControlTextOption (binnie.core.gui.controls.listbox.ControlTextOption)1