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);
}
Aggregations