Search in sources :

Example 1 with GuiSliderInt

use of com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt in project BuildingGadgets by Direwolf20-MC.

the class ModeRadialMenu method init.

@Override
public void init() {
    this.conditionalButtons.clear();
    ItemStack tool = this.getGadget();
    boolean isDestruction = tool.getItem() instanceof GadgetDestruction;
    ScreenPosition right = isDestruction ? ScreenPosition.TOP : ScreenPosition.RIGHT;
    ScreenPosition left = isDestruction ? ScreenPosition.BOTTOM : ScreenPosition.LEFT;
    if (isDestruction) {
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.DESTRUCTION_OVERLAY, "destroy_overlay", right, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketChangeRange());
            return GadgetDestruction.getOverlay(this.getGadget());
        }));
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.FLUID_ONLY, "fluid_only", right, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketToggleFluidOnly());
            return GadgetDestruction.getIsFluidOnly(this.getGadget());
        }));
    } else {
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.ROTATE, "rotate", left, false, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketRotateMirror(PacketRotateMirror.Operation.ROTATE));
            return false;
        }));
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.MIRROR, "mirror", left, false, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketRotateMirror(PacketRotateMirror.Operation.MIRROR));
            return false;
        }));
    }
    if (!(tool.getItem() instanceof GadgetCopyPaste)) {
        if (!isDestruction || Config.GADGETS.GADGET_DESTRUCTION.nonFuzzyEnabled.get()) {
            Button button = new PositionedIconActionable(RadialTranslation.FUZZY, "fuzzy", right, send -> {
                if (send) {
                    PacketHandler.sendToServer(new PacketToggleFuzzy());
                }
                return AbstractGadget.getFuzzy(this.getGadget());
            });
            addRenderableWidget(button);
            conditionalButtons.add(button);
        }
        if (!isDestruction) {
            Button button = new PositionedIconActionable(RadialTranslation.CONNECTED_SURFACE, "connected_area", right, send -> {
                if (send) {
                    PacketHandler.sendToServer(new PacketToggleConnectedArea());
                }
                return AbstractGadget.getConnectedArea(this.getGadget());
            });
            addRenderableWidget(button);
            conditionalButtons.add(button);
        }
        if (!isDestruction) {
            int widthSlider = 82;
            GuiSliderInt sliderRange = new GuiSliderInt(width / 2 - widthSlider / 2, height / 2 + 72, widthSlider, 14, GuiTranslation.SINGLE_RANGE.componentTranslation().append(new TextComponent(": ")), new TextComponent(""), 1, Config.GADGETS.maxRange.get(), GadgetUtils.getToolRange(tool), false, true, Color.DARK_GRAY, slider -> {
                GuiSliderInt sliderI = (GuiSliderInt) slider;
                this.sendRangeUpdate(sliderI.getValueInt());
            }, (slider, amount) -> {
                int value = slider.getValueInt();
                int valueNew = Mth.clamp(value + amount, 1, Config.GADGETS.maxRange.get());
                sendRangeUpdate(valueNew);
                slider.setValue(valueNew);
                slider.updateSlider();
            });
            sliderRange.precision = 1;
            sliderRange.getComponents().forEach(this::addRenderableWidget);
        }
    } else {
        // Copy Paste specific
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.OPEN_GUI, "copypaste_opengui", right, send -> {
            if (!send)
                return false;
            assert this.getMinecraft().player != null;
            getMinecraft().player.closeContainer();
            if (GadgetCopyPaste.getToolMode(tool) == GadgetCopyPaste.ToolMode.COPY)
                getMinecraft().setScreen(new CopyGUI(tool));
            else
                getMinecraft().setScreen(new PasteGUI(tool));
            return true;
        }));
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.OPEN_MATERIAL_LIST, "copypaste_materiallist", right, send -> {
            if (!send)
                return false;
            assert this.getMinecraft().player != null;
            getMinecraft().player.closeContainer();
            getMinecraft().setScreen(new MaterialListGUI(tool));
            return true;
        }));
    }
    addRenderableWidget(new PositionedIconActionable(RadialTranslation.RAYTRACE_FLUID, "raytrace_fluid", right, send -> {
        if (send)
            PacketHandler.sendToServer(new PacketToggleRayTraceFluid());
        return AbstractGadget.shouldRayTraceFluid(this.getGadget());
    }));
    if (tool.getItem() instanceof GadgetBuilding) {
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.PLACE_ON_TOP, "building_place_atop", right, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketToggleBlockPlacement());
            return GadgetBuilding.shouldPlaceAtop(this.getGadget());
        }));
    }
    addRenderableWidget(new PositionedIconActionable(RadialTranslation.ANCHOR, "anchor", left, send -> {
        if (send)
            PacketHandler.sendToServer(new PacketAnchor());
        ItemStack stack = this.getGadget();
        if (stack.getItem() instanceof GadgetCopyPaste || stack.getItem() instanceof GadgetDestruction) {
            return ((AbstractGadget) stack.getItem()).getAnchor(stack) != null;
        }
        return GadgetUtils.getAnchor(stack).isPresent();
    }));
    if (!(tool.getItem() instanceof GadgetExchanger)) {
        addRenderableWidget(new PositionedIconActionable(RadialTranslation.UNDO, "undo", left, false, send -> {
            if (send)
                PacketHandler.sendToServer(new PacketUndo());
            return false;
        }));
    }
    this.updateButtons(tool);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Arrays(java.util.Arrays) InputConstants(com.mojang.blaze3d.platform.InputConstants) com.direwolf20.buildinggadgets.common.network.packets(com.direwolf20.buildinggadgets.common.network.packets) KeyBindings(com.direwolf20.buildinggadgets.client.KeyBindings) Item(net.minecraft.world.item.Item) Styles(com.direwolf20.buildinggadgets.common.util.lang.Styles) Matrix4f(com.mojang.math.Matrix4f) BuildingModes(com.direwolf20.buildinggadgets.common.items.modes.BuildingModes) GadgetUtils(com.direwolf20.buildinggadgets.common.util.GadgetUtils) GuiSliderInt(com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt) RadialTranslation(com.direwolf20.buildinggadgets.common.util.lang.RadialTranslation) MessageTranslation(com.direwolf20.buildinggadgets.common.util.lang.MessageTranslation) PoseStack(com.mojang.blaze3d.vertex.PoseStack) ArrayList(java.util.ArrayList) OurRenderTypes(com.direwolf20.buildinggadgets.client.renderer.OurRenderTypes) Config(com.direwolf20.buildinggadgets.common.config.Config) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) Button(net.minecraft.client.gui.components.Button) GameRenderer(net.minecraft.client.renderer.GameRenderer) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) Screen(net.minecraft.client.gui.screens.Screen) PacketHandler(com.direwolf20.buildinggadgets.common.network.PacketHandler) Collectors(java.util.stream.Collectors) GuiEventListener(net.minecraft.client.gui.components.events.GuiEventListener) java.awt(java.awt) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Reference(com.direwolf20.buildinggadgets.common.util.ref.Reference) Vec3(net.minecraft.world.phys.Vec3) ExchangingModes(com.direwolf20.buildinggadgets.common.items.modes.ExchangingModes) GuiIconActionable(com.direwolf20.buildinggadgets.client.screen.components.GuiIconActionable) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) KeyMapping(net.minecraft.client.KeyMapping) ForgeI18n(net.minecraftforge.common.ForgeI18n) com.direwolf20.buildinggadgets.common.items(com.direwolf20.buildinggadgets.common.items) ItemStack(net.minecraft.world.item.ItemStack) Mth(net.minecraft.util.Mth) OurSounds(com.direwolf20.buildinggadgets.client.OurSounds) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) GuiTranslation(com.direwolf20.buildinggadgets.common.util.lang.GuiTranslation) GuiSliderInt(com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt) Button(net.minecraft.client.gui.components.Button) TextComponent(net.minecraft.network.chat.TextComponent) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

KeyBindings (com.direwolf20.buildinggadgets.client.KeyBindings)1 OurSounds (com.direwolf20.buildinggadgets.client.OurSounds)1 OurRenderTypes (com.direwolf20.buildinggadgets.client.renderer.OurRenderTypes)1 GuiIconActionable (com.direwolf20.buildinggadgets.client.screen.components.GuiIconActionable)1 GuiSliderInt (com.direwolf20.buildinggadgets.client.screen.components.GuiSliderInt)1 Config (com.direwolf20.buildinggadgets.common.config.Config)1 com.direwolf20.buildinggadgets.common.items (com.direwolf20.buildinggadgets.common.items)1 BuildingModes (com.direwolf20.buildinggadgets.common.items.modes.BuildingModes)1 ExchangingModes (com.direwolf20.buildinggadgets.common.items.modes.ExchangingModes)1 PacketHandler (com.direwolf20.buildinggadgets.common.network.PacketHandler)1 com.direwolf20.buildinggadgets.common.network.packets (com.direwolf20.buildinggadgets.common.network.packets)1 GadgetUtils (com.direwolf20.buildinggadgets.common.util.GadgetUtils)1 GuiTranslation (com.direwolf20.buildinggadgets.common.util.lang.GuiTranslation)1 MessageTranslation (com.direwolf20.buildinggadgets.common.util.lang.MessageTranslation)1 RadialTranslation (com.direwolf20.buildinggadgets.common.util.lang.RadialTranslation)1 Styles (com.direwolf20.buildinggadgets.common.util.lang.Styles)1 Reference (com.direwolf20.buildinggadgets.common.util.ref.Reference)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 InputConstants (com.mojang.blaze3d.platform.InputConstants)1