Search in sources :

Example 6 with Module

use of com.teamwizardry.wizardry.api.spell.module.Module 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)

Example 7 with Module

use of com.teamwizardry.wizardry.api.spell.module.Module in project Wizardry by TeamWizardry.

the class SpellBuilder method toSpell.

private List<SpellRing> toSpell(List<ItemStack> inventory) {
    List<SpellRing> spellList = new ArrayList<>();
    Set<List<SpellRing>> spellChains = new HashSet<>();
    List<List<ItemStack>> lines = brancher(inventory, codeLineBreak);
    // Spell chain from multiple chains
    for (List<ItemStack> line : lines) {
        // List is made of all modules that aren't modifiers for this spellData chain.
        Deque<SpellRing> uncompressedChain = new ArrayDeque<>();
        // Step through each item in line. If modifier, add to lastModule, if not, add to compiled.
        for (ItemStack stack : line) {
            Module module = ModuleRegistry.INSTANCE.getModule(stack);
            if (module == null)
                continue;
            if (module instanceof ModuleModifier) {
                if (!uncompressedChain.isEmpty()) {
                    for (int i = 0; i < stack.getCount(); i++) {
                        SpellRing lastRing = uncompressedChain.peekLast();
                        lastRing.addModifier((ModuleModifier) module);
                    }
                }
            } else {
                for (int i = 0; i < stack.getCount(); i++) {
                    SpellRing ring = new SpellRing(module);
                    uncompressedChain.add(ring);
                }
            }
        }
        spellChains.add(new ArrayList<>(uncompressedChain));
    }
    // We now have a code line of modules. link them as children in order.
    for (List<SpellRing> rings : spellChains) {
        if (rings.isEmpty())
            continue;
        Deque<SpellRing> deque = new ArrayDeque<>(rings);
        SpellRing ringHead = deque.pop();
        SpellRing lastRing = ringHead;
        while (!deque.isEmpty()) {
            SpellRing child = deque.pop();
            lastRing.setChildRing(child);
            child.setParentRing(lastRing);
            lastRing = child;
        }
        spellList.add(ringHead);
    }
    for (SpellRing ring : spellList) {
        SpellRing chainEnd = ring;
        while (chainEnd != null) {
            if (chainEnd.getChildRing() == null) {
                chainEnd.processModifiers();
                if (chainEnd.getModule() != null) {
                    chainEnd.setPrimaryColor(chainEnd.getModule().getPrimaryColor());
                    chainEnd.setSecondaryColor(chainEnd.getModule().getSecondaryColor());
                }
                chainEnd.updateColorChain();
                break;
            }
            chainEnd.processModifiers();
            chainEnd = chainEnd.getChildRing();
        }
    }
    return spellList;
}
Also used : ModuleModifier(com.teamwizardry.wizardry.api.spell.module.ModuleModifier) ItemStack(net.minecraft.item.ItemStack) Module(com.teamwizardry.wizardry.api.spell.module.Module)

Example 8 with Module

use of com.teamwizardry.wizardry.api.spell.module.Module in project Wizardry by TeamWizardry.

the class CommandWizardry method execute.

@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));
    if (args[0].equalsIgnoreCase("reload")) {
        ModuleRegistry.INSTANCE.loadUnprocessedModules();
        ModuleRegistry.INSTANCE.copyMissingModulesFromResources(CommonProxy.directory);
        ModuleRegistry.INSTANCE.processModules();
        if (server.isDedicatedServer()) {
            PacketHandler.NETWORK.sendToAll(new PacketSyncModules(ModuleRegistry.INSTANCE.modules));
        }
        notifyCommandListener(sender, this, "wizardry.command.success");
    } else if (args[0].equalsIgnoreCase("reset")) {
        notifyCommandListener(sender, this, "wizardry.command.reset");
        File moduleDirectory = new File(CommonProxy.directory, "modules");
        if (moduleDirectory.exists()) {
            File[] files = moduleDirectory.listFiles();
            if (files != null)
                for (File file : files) {
                    String name = file.getName();
                    if (!file.delete()) {
                        throw new CommandException("wizardry.command.fail", name);
                    } else {
                        notifyCommandListener(sender, this, "wizardry.command.success_delete", name);
                    }
                }
            if (!moduleDirectory.delete()) {
                throw new CommandException("wizardry.command.fail_dir_delete");
            }
        }
        if (!moduleDirectory.exists())
            if (!moduleDirectory.mkdirs()) {
                throw new CommandException("wizardry.command.fail_dir_create");
            }
        ModuleRegistry.INSTANCE.setDirectory(moduleDirectory);
        ModuleRegistry.INSTANCE.loadUnprocessedModules();
        ModuleRegistry.INSTANCE.copyMissingModulesFromResources(CommonProxy.directory);
        ModuleRegistry.INSTANCE.processModules();
        if (server.isDedicatedServer()) {
            PacketHandler.NETWORK.sendToAll(new PacketSyncModules(ModuleRegistry.INSTANCE.modules));
        }
        notifyCommandListener(sender, this, "wizardry.command.success");
    } else if (args[0].equalsIgnoreCase("listModules")) {
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module List");
        for (Module module : ModuleRegistry.INSTANCE.modules) {
            notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + module.getID() + TextFormatting.RESET + ": " + TextFormatting.GRAY + module.getReadableName());
        }
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
    } else if (args[0].equalsIgnoreCase("debug")) {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));
        Module module = ModuleRegistry.INSTANCE.getModule(args[1]);
        if (module == null) {
            notifyCommandListener(sender, this, "Module not found.");
            return;
        }
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module " + module.getReadableName() + ":");
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Description           " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getDescription());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Item Stack            " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getItemStack().getDisplayName());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Burnout Fill          " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutFill());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |  |_ " + TextFormatting.DARK_GREEN + "Burnout Multiplier" + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutMultiplier());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Mana Drain           " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaDrain());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |  |_" + TextFormatting.DARK_GREEN + "Mana Multiplier     " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaMultiplier());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Power Multiplier     " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getPowerMultiplier());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Charge Up Time      " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getChargeupTime());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Cooldown Time        " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getCooldownTime());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Primary Color        " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getPrimaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getPrimaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getPrimaryColor().getBlue());
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Secondary Color    " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getSecondaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getSecondaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getSecondaryColor().getBlue());
        if (!module.getAttributes().isEmpty())
            notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Default AttributeRegistry");
        for (AttributeModifier attributeModifier : module.getAttributes()) notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |  |_ " + TextFormatting.GRAY + attributeModifier.toString());
        ModuleModifier[] modifierList = module.applicableModifiers();
        if (modifierList != null) {
            notifyCommandListener(sender, this, TextFormatting.YELLOW + " |  |_ " + TextFormatting.GREEN + "Applicable Modifiers ");
            for (ModuleModifier modifier : modifierList) notifyCommandListener(sender, this, TextFormatting.YELLOW + " |     |_ " + TextFormatting.DARK_GREEN + modifier.getID());
        }
        notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
    } else {
        throw new WrongUsageException(getUsage(sender));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) PacketSyncModules(com.teamwizardry.wizardry.common.network.PacketSyncModules) ModuleModifier(com.teamwizardry.wizardry.api.spell.module.ModuleModifier) CommandException(net.minecraft.command.CommandException) Module(com.teamwizardry.wizardry.api.spell.module.Module) AttributeModifier(com.teamwizardry.wizardry.api.spell.attribute.AttributeModifier) File(java.io.File)

Aggregations

Module (com.teamwizardry.wizardry.api.spell.module.Module)8 GuiComponent (com.teamwizardry.librarianlib.features.gui.component.GuiComponent)5 ModuleModifier (com.teamwizardry.wizardry.api.spell.module.ModuleModifier)4 GuiComponentEvents (com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents)2 Vec2d (com.teamwizardry.librarianlib.features.math.Vec2d)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