| 1 | package net.minecraft.client.gui.components;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.gui.ComponentPath;
|
| 6 | import net.minecraft.client.gui.components.events.ContainerEventHandler;
|
| 7 | import net.minecraft.client.gui.components.events.GuiEventListener;
|
| 8 | import net.minecraft.client.gui.navigation.FocusNavigationEvent;
|
| 9 | import net.minecraft.client.input.MouseButtonEvent;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public abstract class AbstractContainerWidget extends AbstractScrollArea implements ContainerEventHandler {
|
| 15 | private @Nullable GuiEventListener focused;
|
| 16 | private boolean isDragging;
|
| 17 |
|
| 18 | public AbstractContainerWidget(final int x, final int y, final int width, final int height, final Component message) {
|
| 19 | super(x, y, width, height, message, AbstractScrollArea.ScrollbarSettings.NO_SCROLL);
|
| 20 | }
|
| 21 |
|
| 22 | public AbstractContainerWidget(
|
| 23 | final int x, final int y, final int width, final int height, final Component message, final AbstractScrollArea.ScrollbarSettings scrollbarSettings
|
| 24 | ) {
|
| 25 | super(x, y, width, height, message, scrollbarSettings);
|
| 26 | }
|
| 27 |
|
| 28 | @Override
|
| 29 | public final boolean isDragging() {
|
| 30 | return this.isDragging;
|
| 31 | }
|
| 32 |
|
| 33 | @Override
|
| 34 | public final void setDragging(final boolean dragging) {
|
| 35 | this.isDragging = dragging;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public @Nullable GuiEventListener getFocused() {
|
| 40 | return this.focused;
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public void setFocused(final @Nullable GuiEventListener focused) {
|
| 45 | if (this.focused != null) {
|
| 46 | this.focused.setFocused(false);
|
| 47 | }
|
| 48 |
|
| 49 | if (focused != null) {
|
| 50 | focused.setFocused(true);
|
| 51 | }
|
| 52 |
|
| 53 | this.focused = focused;
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public @Nullable ComponentPath nextFocusPath(final FocusNavigationEvent navigationEvent) {
|
| 58 | return ContainerEventHandler.super.nextFocusPath(navigationEvent);
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick) {
|
| 63 | boolean scrolling = this.updateScrolling(event);
|
| 64 | return ContainerEventHandler.super.mouseClicked(event, doubleClick) || scrolling;
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public boolean mouseReleased(final MouseButtonEvent event) {
|
| 69 | super.mouseReleased(event);
|
| 70 | return ContainerEventHandler.super.mouseReleased(event);
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public boolean mouseDragged(final MouseButtonEvent event, final double dx, final double dy) {
|
| 75 | super.mouseDragged(event, dx, dy);
|
| 76 | return ContainerEventHandler.super.mouseDragged(event, dx, dy);
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public boolean isFocused() {
|
| 81 | return ContainerEventHandler.super.isFocused();
|
| 82 | }
|
| 83 |
|
| 84 | @Override
|
| 85 | public void setFocused(final boolean focused) {
|
| 86 | ContainerEventHandler.super.setFocused(focused);
|
| 87 | }
|
| 88 | }
|
| 89 |
|