Search in sources :

Example 1 with GuiComponent

use of com.teamwizardry.librarianlib.features.gui.component.GuiComponent in project Wizardry by TeamWizardry.

the class ComponentWhitelistedModifiers method refresh.

public void refresh() {
    if (worktable.selectedComponent == null) {
        setVisible(false);
        addTag("disabled");
        return;
    } else {
        setVisible(true);
        removeTag("disabled");
    }
    HashSet<GuiComponent> temp = new HashSet<>(list.getChildren());
    for (GuiComponent component : temp) {
        list.relationships.remove(component);
    }
    Module module = worktable.getModule(worktable.selectedComponent);
    if (module == null)
        return;
    if (module.applicableModifiers() == null)
        return;
    if (Objects.requireNonNull(module.applicableModifiers()).length <= 0)
        return;
    ModuleModifier[] modifiers = module.applicableModifiers();
    if (modifiers == null)
        return;
    for (ModuleModifier modifier : modifiers) {
        ComponentRect bar = new ComponentRect(0, 0, getSize().getXi(), 16);
        bar.getColor().setValue(new Color(0x80000000, true));
        ComponentSprite plate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
        bar.add(plate);
        Sprite icon = new Sprite(new ResourceLocation(Wizardry.MODID, "textures/gui/worktable/icons/" + modifier.getID() + ".png"));
        ComponentSprite iconComp = new ComponentSprite(icon, 2, 2, 12, 12);
        plate.add(iconComp);
        ComponentText text = new ComponentText(20, 4, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP);
        text.getText().setValue(TextFormatting.GREEN + modifier.getShortHandName());
        bar.add(text);
        bar.render.getTooltip().func((Function<GuiComponent, java.util.List<String>>) t -> {
            List<String> txt = new ArrayList<>();
            for (GuiComponent comp : worktable.paperComponents.keySet()) if (comp.hasTag("dragging"))
                return txt;
            txt.add(TextFormatting.GOLD + module.getReadableName());
            if (GuiScreen.isShiftKeyDown())
                txt.add(TextFormatting.GRAY + module.getDescription());
            else
                txt.add(TextFormatting.GRAY + LibrarianLib.PROXY.translate("wizardry.misc.sneak"));
            return txt;
        });
        bar.BUS.hook(GuiComponentEvents.MouseInEvent.class, event -> {
            bar.getColor().setValue(new Color(0x66000000, true));
        });
        bar.BUS.hook(GuiComponentEvents.MouseOutEvent.class, event -> {
            bar.getColor().setValue(new Color(0x80000000, true));
        });
        bar.BUS.hook(GuiComponentEvents.MouseDownEvent.class, event -> {
            if (event.component.getMouseOver()) {
                bar.getColor().setValue(new Color(0x4D000000, true));
            }
        });
        bar.BUS.hook(GuiComponentEvents.MouseUpEvent.class, event -> {
            if (event.component.getMouseOver()) {
                bar.getColor().setValue(new Color(0x80000000, true));
            }
        });
        bar.BUS.hook(GuiComponentEvents.MouseClickEvent.class, (event) -> {
            if (!event.component.getMouseOver())
                return;
            int i = worktable.selectedComponent.hasData(Integer.class, modifier.getID()) ? worktable.selectedComponent.getData(Integer.class, modifier.getID()) : 0;
            int status = -1;
            if (event.getButton() == EnumMouseButton.LEFT) {
                worktable.selectedComponent.setData(Integer.class, modifier.getID(), ++i);
                status = 0;
            } else if (event.getButton() == EnumMouseButton.RIGHT) {
                if (worktable.selectedComponent.hasData(Integer.class, modifier.getID())) {
                    if (worktable.selectedComponent.getData(Integer.class, modifier.getID()) > 0) {
                        worktable.selectedComponent.setData(Integer.class, modifier.getID(), --i);
                        status = 1;
                    } else {
                        worktable.selectedComponent.removeData(Integer.class, modifier.getID());
                    }
                }
            }
            ComponentSprite fakePlate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
            bar.add(fakePlate);
            ComponentSprite fakeIconComp = new ComponentSprite(icon, 2, 2, 12, 12);
            fakePlate.add(fakeIconComp);
            ScheduledEventAnimation scheduled = new ScheduledEventAnimation(20, fakePlate::invalidate);
            Vec2d r = worktable.selectedComponent.thisPosToOtherContext(bar);
            KeyframeAnimation<ComponentSprite> animX = new KeyframeAnimation<>(fakePlate, "pos.x");
            animX.setDuration(20);
            if (status == 0) {
                animX.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getX(), Easing.easeInBack) });
            } else if (status == 1) {
                animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getX(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
            }
            KeyframeAnimation<ComponentSprite> animY = new KeyframeAnimation<>(fakePlate, "pos.y");
            animY.setDuration(20);
            if (status == 0) {
                animY.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getY(), Easing.easeInBack) });
            } else if (status == 1) {
                animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getY(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
            }
            worktable.getMainComponents().add(scheduled, animX, animY);
        });
        list.add(bar);
    }
}
Also used : ComponentList(com.teamwizardry.librarianlib.features.gui.components.ComponentList) ComponentRect(com.teamwizardry.librarianlib.features.gui.components.ComponentRect) Sprite(com.teamwizardry.librarianlib.features.sprite.Sprite) ModuleModifier(com.teamwizardry.wizardry.api.spell.module.ModuleModifier) LibrarianLib(com.teamwizardry.librarianlib.core.LibrarianLib) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Keyframe(com.teamwizardry.librarianlib.features.animator.animations.Keyframe) Easing(com.teamwizardry.librarianlib.features.animator.Easing) Module(com.teamwizardry.wizardry.api.spell.module.Module) ScheduledEventAnimation(com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation) KeyframeAnimation(com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) TextFormatting(net.minecraft.util.text.TextFormatting) Wizardry(com.teamwizardry.wizardry.Wizardry) EnumMouseButton(com.teamwizardry.librarianlib.features.gui.EnumMouseButton) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) java.awt(java.awt) Objects(java.util.Objects) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d) ResourceLocation(net.minecraft.util.ResourceLocation) GuiComponentEvents(com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents) ComponentText(com.teamwizardry.librarianlib.features.gui.components.ComponentText) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d) Keyframe(com.teamwizardry.librarianlib.features.animator.animations.Keyframe) KeyframeAnimation(com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation) ModuleModifier(com.teamwizardry.wizardry.api.spell.module.ModuleModifier) ResourceLocation(net.minecraft.util.ResourceLocation) ComponentList(com.teamwizardry.librarianlib.features.gui.components.ComponentList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Sprite(com.teamwizardry.librarianlib.features.sprite.Sprite) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) GuiComponentEvents(com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents) ScheduledEventAnimation(com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation) ComponentRect(com.teamwizardry.librarianlib.features.gui.components.ComponentRect) Module(com.teamwizardry.wizardry.api.spell.module.Module) ComponentText(com.teamwizardry.librarianlib.features.gui.components.ComponentText)

Example 2 with GuiComponent

use of com.teamwizardry.librarianlib.features.gui.component.GuiComponent in project Wizardry by TeamWizardry.

the class WorktableGui method sync.

public void sync() {
    if (!Minecraft.getMinecraft().world.isBlockLoaded(worktablePos))
        return;
    IBlockState state = Minecraft.getMinecraft().world.getBlockState(worktablePos);
    if (state.getBlock() != ModBlocks.MAGICIANS_WORKTABLE)
        return;
    TileEntity table = Minecraft.getMinecraft().world.getTileEntity(worktablePos);
    if (!(table instanceof TileMagiciansWorktable))
        return;
    HashMap<SpellRing, UUID> convertComponents = new HashMap<>();
    for (Map.Entry<GuiComponent, UUID> entrySet : paperComponents.entrySet()) {
        Module module1 = getModule(entrySet.getKey());
        if (module1 == null)
            continue;
        SpellRing ring = new SpellRing(module1);
        ring.getInformationTag().setDouble("worktable_x", entrySet.getKey().getPos().getX());
        ring.getInformationTag().setDouble("worktable_y", entrySet.getKey().getPos().getY());
        convertComponents.put(ring, entrySet.getValue());
    }
    ((TileMagiciansWorktable) table).componentLinks = componentLinks;
    ((TileMagiciansWorktable) table).paperComponents = convertComponents;
    PacketHandler.NETWORK.sendToServer(new PacketWorktableUpdate(Minecraft.getMinecraft().world.provider.getDimension(), worktablePos, convertComponents, componentLinks));
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketWorktableUpdate(com.teamwizardry.wizardry.common.network.PacketWorktableUpdate) TileMagiciansWorktable(com.teamwizardry.wizardry.common.tile.TileMagiciansWorktable) IBlockState(net.minecraft.block.state.IBlockState) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) Module(com.teamwizardry.wizardry.api.spell.module.Module) BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap)

Example 3 with GuiComponent

use of com.teamwizardry.librarianlib.features.gui.component.GuiComponent in project Wizardry by TeamWizardry.

the class WorktableGui method addModules.

private ComponentGrid addModules(ComponentSprite parent, ModuleType type) {
    ComponentGrid grid = new ComponentGrid(0, 0, 16, 16, 3);
    parent.add(grid);
    ArrayList<GuiComponent> tmp = new ArrayList<>();
    for (Module module : ModuleRegistry.INSTANCE.getModules(type)) {
        TableModule item = new TableModule(this, parent, module, false, true);
        tmp.add(item.component);
    }
    // ArrayList<GuiComponent> scrollable = (ArrayList<GuiComponent>) Utils.getVisibleComponents(tmp, 0);
    for (GuiComponent component : tmp) {
        grid.add(component);
    }
    return grid;
}
Also used : GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) Module(com.teamwizardry.wizardry.api.spell.module.Module)

Example 4 with GuiComponent

use of com.teamwizardry.librarianlib.features.gui.component.GuiComponent in project Wizardry by TeamWizardry.

the class WorktableGui method compileModule.

private void compileModule(ArrayList<Module> stream, @Nullable GuiComponent component) {
    if (component == null)
        return;
    Module module = getModule(component);
    if (module == null)
        return;
    stream.add(module);
    for (Module modifier : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
        if (!(modifier instanceof ModuleModifier))
            continue;
        if (component.hasData(Integer.class, modifier.getID())) {
            int x = component.getData(Integer.class, modifier.getID());
            for (int i = 0; i < x; i++) {
                stream.add(modifier);
            }
        }
    }
    if (!componentLinks.containsKey(getUUID(component)))
        return;
    UUID uuidChild = componentLinks.get(getUUID(component));
    GuiComponent childComp = getComponent(uuidChild);
    if (childComp == null)
        return;
    Module child = getModule(childComp);
    if (child == null)
        return;
    compileModule(stream, childComp);
}
Also used : ModuleModifier(com.teamwizardry.wizardry.api.spell.module.ModuleModifier) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) Module(com.teamwizardry.wizardry.api.spell.module.Module)

Example 5 with GuiComponent

use of com.teamwizardry.librarianlib.features.gui.component.GuiComponent in project Wizardry by TeamWizardry.

the class WorktableGui method addScrollbar.

private void addScrollbar(ComponentSprite parent, ComponentGrid gridView, int x, int y, ModuleType type, int trackSize) {
    ComponentSprite scrollBar = new ComponentSprite(SCROLL_BAR_GRIP, x, y, 5, 80);
    ComponentSprite bar = new ComponentSprite(SCROLL_BAR, 1, 0, 3, 11);
    int moduleCount = ModuleRegistry.INSTANCE.getModules(type).size();
    scrollBar.BUS.hook(GuiComponentEvents.MouseDragEvent.class, (event) -> {
        if (!event.component.getMouseOver() && !parent.getMouseOver())
            return;
        for (GuiComponent comp : paperComponents.keySet()) if (comp.hasTag("dragging"))
            return;
        float contentSize = (float) ((moduleCount / 3.0) * 16.0);
        float windowSize = trackSize;
        float windowContentRatio = windowSize / contentSize;
        float gripSize = MathHelper.clamp(trackSize * windowContentRatio, SCROLL_BAR_GRIP.getHeight(), gridView.getSize().getYi());
        float windowScrollAreaSize = contentSize - windowSize;
        float windowPosition = 100;
        float windowPositionRatio = windowPosition / windowScrollAreaSize;
        float trackScrollAreaSize = trackSize - gripSize;
        float gripPositionOnTrack = trackScrollAreaSize * windowPositionRatio;
        float mousePositionDelta = event.getMousePos().getYi();
        float newGripPosition = MathHelper.clamp(gripPositionOnTrack + mousePositionDelta, 0, trackScrollAreaSize);
        float newGripPositionRatio = newGripPosition / trackScrollAreaSize;
        windowPosition = newGripPositionRatio * windowScrollAreaSize;
        float percent = windowPosition / contentSize;
        ArrayList<GuiComponent> compTmp = new ArrayList<>(gridView.getChildren());
        compTmp.forEach(gridView.relationships::remove);
        ArrayList<GuiComponent> tmp = new ArrayList<>();
        for (Module module : ModuleRegistry.INSTANCE.getModules(type)) {
            TableModule item = new TableModule(this, parent, module, false, false);
            tmp.add(item.component);
        }
        ArrayList<GuiComponent> scrollable = (ArrayList<GuiComponent>) Utils.getVisibleComponents(tmp, percent);
        for (GuiComponent component : scrollable) {
            gridView.add(component);
        }
    });
    scrollBar.BUS.hook(GuiComponentEvents.MouseWheelEvent.class, (event) -> {
        if (!event.component.getMouseOver() && !parent.getMouseOver())
            return;
        for (GuiComponent comp : paperComponents.keySet()) if (comp.hasTag("dragging"))
            return;
        int dir = event.getDirection().ydirection * -16;
        double barPos = bar.getPos().getY();
        double clamp = MathHelper.clamp(barPos + dir, 0, (gridView.getSize().getY() - 1) - 11);
        bar.setPos(new Vec2d(bar.getPos().getX(), clamp));
        double percent = MathHelper.clamp(clamp / ((gridView.getSize().getY() - 1) - 11), 0, 1);
        ArrayList<GuiComponent> compTmp = new ArrayList<>(gridView.getChildren());
        compTmp.forEach(gridView.relationships::remove);
        ArrayList<GuiComponent> tmp = new ArrayList<>();
        for (Module module : ModuleRegistry.INSTANCE.getModules(type)) {
            TableModule item = new TableModule(this, parent, module, false, false);
            tmp.add(item.component);
        }
        ArrayList<GuiComponent> scrollable = (ArrayList<GuiComponent>) Utils.getVisibleComponents(tmp, percent);
        for (GuiComponent component : scrollable) {
            gridView.add(component);
        }
    });
    scrollBar.add(bar);
    getMainComponents().add(scrollBar);
}
Also used : GuiComponentEvents(com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) Module(com.teamwizardry.wizardry.api.spell.module.Module) Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d)

Aggregations

GuiComponent (com.teamwizardry.librarianlib.features.gui.component.GuiComponent)5 Module (com.teamwizardry.wizardry.api.spell.module.Module)5 GuiComponentEvents (com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents)2 Vec2d (com.teamwizardry.librarianlib.features.math.Vec2d)2 ModuleModifier (com.teamwizardry.wizardry.api.spell.module.ModuleModifier)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 LibrarianLib (com.teamwizardry.librarianlib.core.LibrarianLib)1 Easing (com.teamwizardry.librarianlib.features.animator.Easing)1 Keyframe (com.teamwizardry.librarianlib.features.animator.animations.Keyframe)1 KeyframeAnimation (com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation)1 ScheduledEventAnimation (com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation)1 EnumMouseButton (com.teamwizardry.librarianlib.features.gui.EnumMouseButton)1 ComponentList (com.teamwizardry.librarianlib.features.gui.components.ComponentList)1 ComponentRect (com.teamwizardry.librarianlib.features.gui.components.ComponentRect)1 ComponentSprite (com.teamwizardry.librarianlib.features.gui.components.ComponentSprite)1 ComponentText (com.teamwizardry.librarianlib.features.gui.components.ComponentText)1 Sprite (com.teamwizardry.librarianlib.features.sprite.Sprite)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 SpellRing (com.teamwizardry.wizardry.api.spell.SpellRing)1