mirror of
https://github.com/darksaid98/draggable_lists.git
synced 2026-12-01 14:38:47 +00:00
Add this stuff
This commit is contained in:
17 files changed
+467
-402
No files matched your search
@@ -0,0 +1,14 @@
|
||||
package com.mrmelon54.DraggableLists;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
|
||||
public interface DragItem<T, E extends ObjectSelectionList.Entry<?>> {
|
||||
T draggable_lists$getUnderlyingData();
|
||||
|
||||
E draggable_lists$getUnderlyingEntry();
|
||||
|
||||
void draggable_lists$render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta);
|
||||
|
||||
void draggable_lists$setBeingDragged(boolean v);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.mrmelon54.DraggableLists;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
|
||||
public interface DragList<T, E extends ObjectSelectionList.Entry<?>> {
|
||||
DragItem<T, E> draggable_lists$getEntryAtPosition(double mouseX, double mouseY);
|
||||
|
||||
int draggable_lists$getIndexOfEntry(DragItem<T, E> selectedItem);
|
||||
|
||||
void draggable_lists$setDragging(boolean b);
|
||||
|
||||
int draggable_lists$getHeaderHeight();
|
||||
|
||||
int draggable_lists$getY();
|
||||
|
||||
int draggable_lists$getBottom();
|
||||
|
||||
int draggable_lists$getItemHeight();
|
||||
|
||||
int draggable_lists$getRowTop(int i);
|
||||
|
||||
int draggable_lists$getRowBottom(int i);
|
||||
|
||||
double draggable_lists$getRowLeft();
|
||||
|
||||
int draggable_lists$getRowWidth();
|
||||
|
||||
double draggable_lists$getScrollAmount();
|
||||
|
||||
void draggable_lists$setScrollAmount(double v);
|
||||
|
||||
void draggable_lists$moveServerEntry(DragItem<T, E> item, int n);
|
||||
|
||||
int draggable_lists$getItemCount();
|
||||
|
||||
void draggable_lists$renderItem(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta, int i, int rowLeft, int rowTop, int rowWidth, int rowHeight);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.mrmelon54.DraggableLists;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class DragManager<T, E extends ObjectSelectionList.Entry<?>> {
|
||||
private final DragList<T, E> dragList;
|
||||
private DragItem<T, E> selectedItem;
|
||||
private double draggingStartX = 0;
|
||||
private double draggingStartY = 0;
|
||||
private double draggingOffsetX = 0;
|
||||
private double draggingOffsetY = 0;
|
||||
private double softScrollingTimer = 0;
|
||||
private double softScrollingOrigin = 0;
|
||||
|
||||
public DragManager(DragList<T, E> dragList) {
|
||||
this.dragList = dragList;
|
||||
}
|
||||
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button != 0 || selectedItem != null || !isCapMouseY((int) mouseY)) return false;
|
||||
|
||||
selectedItem = dragList.draggable_lists$getEntryAtPosition(mouseX, mouseY);
|
||||
if (selectedItem == null) return false;
|
||||
|
||||
// Save the mouse origin position and the offset for the top left corner of the widget
|
||||
draggingStartX = mouseX;
|
||||
draggingStartY = mouseY;
|
||||
draggingOffsetX = dragList.draggable_lists$getRowLeft() - draggingStartX;
|
||||
int entryIndex = dragList.draggable_lists$getIndexOfEntry(selectedItem);
|
||||
if (entryIndex < 0) {
|
||||
selectedItem = null;
|
||||
return false;
|
||||
}
|
||||
draggingOffsetY = dragList.draggable_lists$getRowTop(entryIndex) - draggingStartY;
|
||||
|
||||
// Don't grab if inside the server icon
|
||||
if (draggingOffsetX > -32f) {
|
||||
selectedItem = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
dragList.draggable_lists$setDragging(true);
|
||||
selectedItem.draggable_lists$getUnderlyingEntry().setFocused(true);
|
||||
selectedItem.draggable_lists$setBeingDragged(true);
|
||||
softScrollingTimer = 0;
|
||||
Cursor.setDragging();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
dragList.draggable_lists$setDragging(false);
|
||||
if (selectedItem == null) return false;
|
||||
|
||||
DragItem<T, E> selectedItem1 = selectedItem;
|
||||
selectedItem = null;
|
||||
softScrollingTimer = 0;
|
||||
|
||||
Cursor.reset();
|
||||
double y = capYCoordinate((int) mouseY, true);
|
||||
selectedItem1.draggable_lists$setBeingDragged(false);
|
||||
|
||||
DragItem<T, E> hoveredEntry = dragList.draggable_lists$getEntryAtPosition(mouseX, y);
|
||||
if (hoveredEntry == null) return false;
|
||||
|
||||
T draggingData = selectedItem1.draggable_lists$getUnderlyingData();
|
||||
T hoveredData = hoveredEntry.draggable_lists$getUnderlyingData();
|
||||
|
||||
// if the items are null, identical or a dragServerItem call fails then stop here
|
||||
return draggingData != null && hoveredData != null && draggingData != hoveredData && dragServerItem(selectedItem1, y);
|
||||
}
|
||||
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
return selectedItem != null;
|
||||
}
|
||||
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
return selectedItem != null;
|
||||
}
|
||||
|
||||
public void renderListItems(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta) {
|
||||
int rowLeft = (int) dragList.draggable_lists$getRowLeft();
|
||||
int rowWidth = dragList.draggable_lists$getRowWidth();
|
||||
int rowHeight = dragList.draggable_lists$getItemHeight() - 4;
|
||||
int n = dragList.draggable_lists$getItemCount();
|
||||
|
||||
int draggingIndex = selectedItem == null ? -1 : dragList.draggable_lists$getIndexOfEntry(selectedItem);
|
||||
int draggedPosition = selectedItem == null ? -1 : getIndexFromMouseY(mouseY);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int renderRow = otherItemIndexShift(i, draggingIndex, draggedPosition);
|
||||
System.out.println("real: " + i + " / renderRow: " + renderRow + " / selected: " + draggingIndex);
|
||||
int rowTop = dragList.draggable_lists$getRowTop(renderRow);
|
||||
int rowBottom = dragList.draggable_lists$getRowBottom(renderRow);
|
||||
if (rowBottom >= dragList.draggable_lists$getY() && rowTop <= dragList.draggable_lists$getBottom()) {
|
||||
if (i == draggingIndex) {
|
||||
|
||||
} else {
|
||||
int outTop = rowTop - (int) dragList.draggable_lists$getScrollAmount();
|
||||
dragList.draggable_lists$renderItem(guiGraphics, mouseX, mouseY, tickDelta, i, rowLeft, outTop, rowWidth, rowHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int otherItemIndexShift(int i, int draggingIndex, int draggedPosition) {
|
||||
if (i == draggingIndex) return draggedPosition;
|
||||
if (draggingIndex < draggedPosition) return i >= draggingIndex && i <= draggedPosition ? i - 1 : i;
|
||||
return i >= draggedPosition && i <= draggingIndex ? i + 1 : i;
|
||||
}
|
||||
|
||||
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||
if (selectedItem == null) return;
|
||||
|
||||
int z = Mth.floor(mouseY + draggingOffsetY);
|
||||
int x = Mth.floor(draggingStartX + draggingOffsetX);
|
||||
int y = capYCoordinate(z);
|
||||
int entryHeight = dragList.draggable_lists$getItemHeight() - 4;
|
||||
int entryWidth = dragList.draggable_lists$getRowWidth();
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
float shaderColorValue = 191f / 255f;
|
||||
RenderSystem.setShaderColor(shaderColorValue, shaderColorValue, shaderColorValue, 0.5f);
|
||||
guiGraphics.fill(x - 1, y - 1, x + entryWidth - 2, y + entryHeight + 1, 0xbfbfbfff);
|
||||
selectedItem.draggable_lists$render(guiGraphics, 0, y, x, entryWidth, entryHeight, mouseX, mouseY, false, delta);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
guiGraphics.pose().popPose();
|
||||
|
||||
if (y < z) {
|
||||
if (softScrollingTimer == 0) {
|
||||
softScrollingTimer = Util.getMillis();
|
||||
softScrollingOrigin = dragList.draggable_lists$getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - softScrollingTimer) / 5f;
|
||||
dragList.draggable_lists$setScrollAmount(softScrollingOrigin + f);
|
||||
} else if (y > z) {
|
||||
if (softScrollingTimer == 0) {
|
||||
softScrollingTimer = Util.getMillis();
|
||||
softScrollingOrigin = dragList.draggable_lists$getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - softScrollingTimer) / 5f;
|
||||
dragList.draggable_lists$setScrollAmount(softScrollingOrigin - f);
|
||||
} else {
|
||||
softScrollingTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int capYCoordinate(int y, boolean useScreenSpace) {
|
||||
int scrollableTop = dragList.draggable_lists$getY() + 4;
|
||||
int scrollableHeight = dragList.draggable_lists$getBottom() - dragList.draggable_lists$getY() - (useScreenSpace ? 2 : dragList.draggable_lists$getItemHeight() + 2);
|
||||
if (y < scrollableTop) y = scrollableTop;
|
||||
if (y > scrollableTop + scrollableHeight) y = scrollableTop + scrollableHeight;
|
||||
return y;
|
||||
}
|
||||
|
||||
private int capYCoordinate(int y) {
|
||||
return capYCoordinate(y, false);
|
||||
}
|
||||
|
||||
private boolean isCapMouseY(int y) {
|
||||
return capYCoordinate(y, true) == y;
|
||||
}
|
||||
|
||||
private int getIndexFromMouseY(double mouseY) {
|
||||
int m = Mth.floor(mouseY - (double) dragList.draggable_lists$getY()) - dragList.draggable_lists$getHeaderHeight() - (int) dragList.draggable_lists$getScrollAmount() - 4;
|
||||
return m / dragList.draggable_lists$getItemHeight();
|
||||
}
|
||||
|
||||
private boolean dragServerItem(DragItem<T, E> item, double mouseY) {
|
||||
int n = getIndexFromMouseY(mouseY);
|
||||
dragList.draggable_lists$moveServerEntry(item, n);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import com.mrmelon54.DraggableLists.config.ConfigStructure;
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.packs.PackSelectionModel;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@@ -2,6 +2,4 @@ package com.mrmelon54.DraggableLists.duck;
|
||||
|
||||
public interface AbstractPackDuckProvider {
|
||||
void draggable_lists$moveTo(int j);
|
||||
|
||||
int draggable_lists$getIndexInSelectedList();
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.mrmelon54.DraggableLists.duck;
|
||||
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
|
||||
public interface MultiplayerScreenDuckProvider {
|
||||
int draggable_lists$getIndexOfServerInfo(ServerData serverInfo);
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.mrmelon54.DraggableLists.duck;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.packs.PackSelectionModel;
|
||||
|
||||
public interface ResourcePackEntryDuckProvider {
|
||||
PackSelectionModel.Entry draggable_lists$getUnderlyingPack();
|
||||
|
||||
void draggable_lists$renderPoppedOut(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta);
|
||||
|
||||
void draggable_lists$setBeingDragged(boolean v);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.mrmelon54.DraggableLists.duck;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
|
||||
public interface ServerEntryDuckProvider {
|
||||
ServerData draggable_lists$getUnderlyingServer();
|
||||
|
||||
void draggable_lists$renderPoppedOut(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta);
|
||||
|
||||
void draggable_lists$setBeingDragged(boolean v);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.mrmelon54.DraggableLists.duck;
|
||||
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
|
||||
public interface ServerListDuckProvider {
|
||||
void draggable_lists$add(int index, ServerData serverInfo);
|
||||
void draggable_lists$moveItem(DragItem<ServerData, ServerSelectionList.OnlineServerEntry> item, int position);
|
||||
}
|
||||
-4
@@ -44,8 +44,4 @@ public abstract class PackSelectionModel_EntryBaseMixin implements AbstractPackD
|
||||
duckProvider.draggable_lists$updateSelectedList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getIndexInSelectedList() {
|
||||
return getSelfList().indexOf(pack);
|
||||
}
|
||||
}
|
||||
+7
@@ -39,4 +39,11 @@ public class PackSelectionScreenMixin extends Screen {
|
||||
if (availablePackList.isDragging()) availablePackList.mouseReleased(d, e, i);
|
||||
return super.mouseReleased(d, e, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (selectedPackList.isDragging()) selectedPackList.mouseReleased(0, 0, 0);
|
||||
if (availablePackList.isDragging()) availablePackList.mouseReleased(0, 0, 0);
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
+98
-140
@@ -1,194 +1,152 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.packs;
|
||||
|
||||
import com.mrmelon54.DraggableLists.Cursor;
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import com.mrmelon54.DraggableLists.DragList;
|
||||
import com.mrmelon54.DraggableLists.DragManager;
|
||||
import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider;
|
||||
import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.gui.screens.packs.PackSelectionModel;
|
||||
import net.minecraft.client.gui.screens.packs.PackSelectionScreen;
|
||||
import net.minecraft.client.gui.screens.packs.TransferableSelectionList;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(TransferableSelectionList.class)
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract class TransferableSelectionListMixin extends ObjectSelectionList<TransferableSelectionList.PackEntry> {
|
||||
public abstract class TransferableSelectionListMixin extends ObjectSelectionList<TransferableSelectionList.PackEntry> implements DragList<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> {
|
||||
@Shadow
|
||||
@Final
|
||||
PackSelectionScreen screen;
|
||||
|
||||
@Unique
|
||||
private TransferableSelectionList.PackEntry draggable_lists$draggingObject = null;
|
||||
@Unique
|
||||
private double draggable_lists$draggingStartX = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingStartY = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingOffsetX = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingOffsetY = 0;
|
||||
@Unique
|
||||
private long draggable_lists$softScrollingTimer = 0;
|
||||
@Unique
|
||||
private double draggable_lists$softScrollingOrigin = 0;
|
||||
private final DragManager<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> draggable_lists$dragManager = new DragManager<>(this);
|
||||
|
||||
public TransferableSelectionListMixin(Minecraft minecraft, int i, int j, int k, int l, int m) {
|
||||
super(minecraft, i, j, k, l);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderListItems(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta) {
|
||||
draggable_lists$dragManager.renderListItems(guiGraphics, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button != 0 || draggable_lists$draggingObject != null || !draggable_lists$isCapMouseY((int) mouseY)) {
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
draggable_lists$draggingObject = this.getEntryAtPosition(mouseX, mouseY);
|
||||
if ((draggable_lists$draggingObject != null) && (draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider) && draggable_lists$isValidForDragging(duckProvider)) {
|
||||
// Save the mouse origin position and the offset for the top left corner of the widget
|
||||
draggable_lists$draggingStartX = mouseX;
|
||||
draggable_lists$draggingStartY = mouseY;
|
||||
draggable_lists$draggingOffsetX = getRowLeft() - draggable_lists$draggingStartX;
|
||||
draggable_lists$draggingOffsetY = getRowTop(this.children().indexOf(draggable_lists$draggingObject)) - draggable_lists$draggingStartY;
|
||||
|
||||
// Don't grab if inside the pack icon
|
||||
if (draggable_lists$draggingOffsetX > -32f) {
|
||||
draggable_lists$draggingObject = null;
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
this.setDragging(true);
|
||||
this.setFocused(draggable_lists$draggingObject);
|
||||
duckProvider.draggable_lists$setBeingDragged(true);
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
Cursor.setDragging();
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
this.setSelected(null);
|
||||
return true;
|
||||
}
|
||||
draggable_lists$draggingObject = null;
|
||||
if (draggable_lists$dragManager.mouseClicked(mouseX, mouseY, button)) return true;
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
this.setDragging(false);
|
||||
if (draggable_lists$draggingObject != null) {
|
||||
Cursor.reset();
|
||||
if (draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider)
|
||||
duckProvider.draggable_lists$setBeingDragged(false);
|
||||
}
|
||||
draggable_lists$draggingObject = null;
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
if (draggable_lists$dragManager.mouseReleased(mouseX, mouseY, button)) return true;
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
if (button == 0 && draggable_lists$updateDragEvent(mouseX, mouseY)) return true;
|
||||
if (draggable_lists$dragManager.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) return true;
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
|
||||
if (draggable_lists$draggingObject != null) return true;
|
||||
if (draggable_lists$dragManager.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true;
|
||||
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$updateDragEvent(double mouseX, double mouseY) {
|
||||
if (mouseX < getX()) {
|
||||
draggable_lists$draggingStartX = mouseX;
|
||||
}
|
||||
double y = draggable_lists$capYCoordinate((int) mouseY, true);
|
||||
|
||||
TransferableSelectionList.PackEntry hoveredEntry = this.getEntryAtPosition(mouseX, y);
|
||||
|
||||
PackSelectionModel.Entry draggingPack = draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider ? duckProvider.draggable_lists$getUnderlyingPack() : null;
|
||||
PackSelectionModel.Entry hoveredPack = hoveredEntry instanceof ResourcePackEntryDuckProvider duckProvider ? duckProvider.draggable_lists$getUnderlyingPack() : null;
|
||||
|
||||
if (draggingPack != null && hoveredPack != null && draggingPack != hoveredPack && draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider underlyingPackProvider) {
|
||||
if (draggingPack instanceof AbstractPackDuckProvider abstractPack && draggable_lists$dragResourcePack(underlyingPackProvider, y)) {
|
||||
draggable_lists$draggingStartY = mouseY;
|
||||
int z = abstractPack.draggable_lists$getIndexInSelectedList();
|
||||
draggable_lists$draggingObject = z == -1 ? null : getEntry(z);
|
||||
if (draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider)
|
||||
duckProvider.draggable_lists$setBeingDragged(true);
|
||||
this.setSelected(null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||
super.renderWidget(guiGraphics, mouseX, mouseY, delta);
|
||||
draggable_lists$dragManager.renderWidget(guiGraphics, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
if (this.draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider) {
|
||||
int z = Mth.floor(mouseY + draggable_lists$draggingOffsetY);
|
||||
int x = Mth.floor(draggable_lists$draggingStartX + draggable_lists$draggingOffsetX);
|
||||
int y = draggable_lists$capYCoordinate(z);
|
||||
int entryHeight = this.itemHeight - 4;
|
||||
int entryWidth = this.getRowWidth();
|
||||
duckProvider.draggable_lists$renderPoppedOut(guiGraphics, 0, y, x, entryWidth, entryHeight, mouseX, mouseY, false, delta);
|
||||
@Override
|
||||
public DragItem<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> draggable_lists$getEntryAtPosition(double mouseX, double mouseY) {
|
||||
TransferableSelectionList.PackEntry entryAtPosition = getEntryAtPosition(mouseX, mouseY);
|
||||
return (DragItem<PackSelectionModel.Entry, TransferableSelectionList.PackEntry>) entryAtPosition;
|
||||
}
|
||||
|
||||
if (y < z) {
|
||||
if (draggable_lists$softScrollingTimer == 0) {
|
||||
draggable_lists$softScrollingTimer = Util.getMillis();
|
||||
draggable_lists$softScrollingOrigin = getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - draggable_lists$softScrollingTimer) / 5f;
|
||||
setScrollAmount(draggable_lists$softScrollingOrigin + f);
|
||||
} else if (y > z) {
|
||||
if (draggable_lists$softScrollingTimer == 0) {
|
||||
draggable_lists$softScrollingTimer = Util.getMillis();
|
||||
draggable_lists$softScrollingOrigin = getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - draggable_lists$softScrollingTimer) / 5f;
|
||||
setScrollAmount(draggable_lists$softScrollingOrigin - f);
|
||||
} else {
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
}
|
||||
@Override
|
||||
public int draggable_lists$getIndexOfEntry(DragItem<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> selectedItem) {
|
||||
return children().indexOf(selectedItem.draggable_lists$getUnderlyingEntry());
|
||||
}
|
||||
|
||||
draggable_lists$updateDragEvent(mouseX, mouseY);
|
||||
@Override
|
||||
public void draggable_lists$setDragging(boolean b) {
|
||||
super.setDragging(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getHeaderHeight() {
|
||||
return headerHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getY() {
|
||||
return getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getBottom() {
|
||||
return getBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getItemHeight() {
|
||||
return itemHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getRowTop(int i) {
|
||||
return getRowTop(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getRowBottom(int i) {
|
||||
return getRowBottom(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double draggable_lists$getRowLeft() {
|
||||
return getRowLeft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getRowWidth() {
|
||||
return getRowWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double draggable_lists$getScrollAmount() {
|
||||
return getScrollAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$setScrollAmount(double v) {
|
||||
setScrollAmount(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$moveServerEntry(DragItem<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> item, int n) {
|
||||
TransferableSelectionList.PackEntry pack = item.draggable_lists$getUnderlyingEntry();
|
||||
if (pack instanceof AbstractPackDuckProvider duckProvider) {
|
||||
duckProvider.draggable_lists$moveTo(n);
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
int draggable_lists$capYCoordinate(int y, boolean useScreenSpace) {
|
||||
int scrollableTop = getY() + (useScreenSpace ? 0 : (int) Math.max(headerHeight - getScrollAmount() + 2, 0)) + 2;
|
||||
int scrollableHeight = getBottom() - getY() - (useScreenSpace ? 0 : itemHeight + (int) Math.max(headerHeight - getScrollAmount() + 2, 0));
|
||||
if (y < scrollableTop) y = scrollableTop;
|
||||
if (y > scrollableTop + scrollableHeight) y = scrollableTop + scrollableHeight;
|
||||
return y;
|
||||
@Override
|
||||
public int draggable_lists$getItemCount() {
|
||||
return getItemCount();
|
||||
}
|
||||
|
||||
@Unique
|
||||
int draggable_lists$capYCoordinate(int y) {
|
||||
return draggable_lists$capYCoordinate(y, false);
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$isCapMouseY(int y) {
|
||||
return draggable_lists$capYCoordinate(y, true) == y;
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$dragResourcePack(ResourcePackEntryDuckProvider underlyingPackProvider, double mouseY) {
|
||||
int m = Mth.floor(mouseY - (double) getY()) - this.headerHeight + (int) this.getScrollAmount() - 4;
|
||||
int n = m / this.itemHeight;
|
||||
|
||||
PackSelectionModel.Entry pack = underlyingPackProvider.draggable_lists$getUnderlyingPack();
|
||||
if (pack instanceof AbstractPackDuckProvider duckProvider)
|
||||
duckProvider.draggable_lists$moveTo(n);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$isValidForDragging(ResourcePackEntryDuckProvider resourcePackEntryDuckProvider) {
|
||||
PackSelectionModel.Entry entry = resourcePackEntryDuckProvider.draggable_lists$getUnderlyingPack();
|
||||
return !entry.isFixedPosition() && entry.isSelected();
|
||||
@Override
|
||||
public void draggable_lists$renderItem(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta, int i, int rowLeft, int rowTop, int rowWidth, int rowHeight) {
|
||||
renderItem(guiGraphics, mouseX, mouseY, tickDelta, i, rowLeft, rowTop, rowWidth, rowHeight);
|
||||
}
|
||||
}
|
||||
+18
-22
@@ -1,9 +1,8 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.packs;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.WrapWithCondition;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import com.mrmelon54.DraggableLists.DraggableLists;
|
||||
import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.gui.screens.packs.PackSelectionModel;
|
||||
@@ -19,21 +18,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(TransferableSelectionList.PackEntry.class)
|
||||
public abstract class TransferableSelectionList_PackEntryMixin extends ObjectSelectionList.Entry<TransferableSelectionList.PackEntry> implements ResourcePackEntryDuckProvider {
|
||||
@Shadow
|
||||
@Final
|
||||
private PackSelectionModel.Entry pack;
|
||||
public abstract class TransferableSelectionList_PackEntryMixin extends ObjectSelectionList.Entry<TransferableSelectionList.PackEntry> implements DragItem<PackSelectionModel.Entry, TransferableSelectionList.PackEntry> {
|
||||
@Shadow
|
||||
@Final
|
||||
private TransferableSelectionList parent;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private PackSelectionModel.Entry pack;
|
||||
|
||||
@Unique
|
||||
private boolean draggable_lists$isBeingDragged = false;
|
||||
|
||||
@Override
|
||||
public PackSelectionModel.Entry draggable_lists$getUnderlyingPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f, CallbackInfo ci) {
|
||||
if (draggable_lists$isBeingDragged)
|
||||
@@ -73,19 +69,19 @@ public abstract class TransferableSelectionList_PackEntryMixin extends ObjectSel
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$renderPoppedOut(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
public PackSelectionModel.Entry draggable_lists$getUnderlyingData() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransferableSelectionList.PackEntry draggable_lists$getUnderlyingEntry() {
|
||||
return (TransferableSelectionList.PackEntry) (Object) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
if (!draggable_lists$isBeingDragged) return;
|
||||
|
||||
draggable_lists$isBeingDragged = false;
|
||||
guiGraphics.pose().pushPose();
|
||||
|
||||
float z = 191f / 255f;
|
||||
RenderSystem.setShaderColor(z, z, z, 0.5f);
|
||||
guiGraphics.fill(x - 1, y - 1, x + entryWidth - 9, y + entryHeight + 1, 0xbfbfbfff);
|
||||
render(guiGraphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
guiGraphics.pose().popPose();
|
||||
draggable_lists$isBeingDragged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-15
@@ -1,11 +1,8 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.server;
|
||||
|
||||
import com.mrmelon54.DraggableLists.duck.MultiplayerScreenDuckProvider;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -14,13 +11,10 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(JoinMultiplayerScreen.class)
|
||||
public abstract class JoinMultiplayerScreenMixin extends Screen implements MultiplayerScreenDuckProvider {
|
||||
public abstract class JoinMultiplayerScreenMixin extends Screen {
|
||||
@Shadow
|
||||
protected ServerSelectionList serverSelectionList;
|
||||
|
||||
@Shadow
|
||||
public abstract ServerList getServers();
|
||||
|
||||
protected JoinMultiplayerScreenMixin(Component component) {
|
||||
super(component);
|
||||
}
|
||||
@@ -41,12 +35,4 @@ public abstract class JoinMultiplayerScreenMixin extends Screen implements Multi
|
||||
if (serverSelectionList.isDragging()) serverSelectionList.mouseReleased(0, 0, 0);
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int draggable_lists$getIndexOfServerInfo(ServerData serverData) {
|
||||
ServerList servers = getServers();
|
||||
for (int i = 0; i < servers.size(); i++)
|
||||
if (servers.get(i) == serverData) return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+24
-36
@@ -1,9 +1,8 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.server;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.WrapWithCondition;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import com.mrmelon54.DraggableLists.DraggableLists;
|
||||
import com.mrmelon54.DraggableLists.duck.ServerEntryDuckProvider;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
@@ -15,11 +14,10 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ServerSelectionList.OnlineServerEntry.class)
|
||||
public abstract class OnlineServerEntryMixin extends ObjectSelectionList.Entry<ServerSelectionList.Entry> implements ServerEntryDuckProvider {
|
||||
public abstract class OnlineServerEntryMixin extends ObjectSelectionList.Entry<ServerSelectionList.Entry> implements DragItem<ServerData, ServerSelectionList.OnlineServerEntry> {
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerData serverData;
|
||||
@@ -37,37 +35,6 @@ public abstract class OnlineServerEntryMixin extends ObjectSelectionList.Entry<S
|
||||
@Unique
|
||||
private boolean draggable_lists$isBeingDragged;
|
||||
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f, CallbackInfo ci) {
|
||||
if (draggable_lists$isBeingDragged) ci.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerData draggable_lists$getUnderlyingServer() {
|
||||
return serverData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$renderPoppedOut(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
if (!draggable_lists$isBeingDragged) return;
|
||||
|
||||
draggable_lists$isBeingDragged = false;
|
||||
guiGraphics.pose().pushPose();
|
||||
|
||||
float z = 191f / 255f;
|
||||
RenderSystem.setShaderColor(z, z, z, 0.5f);
|
||||
guiGraphics.fill(x - 1, y - 1, x + entryWidth - 2, y + entryHeight + 1, 0xbfbfbfff);
|
||||
render(guiGraphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
guiGraphics.pose().popPose();
|
||||
draggable_lists$isBeingDragged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$setBeingDragged(boolean v) {
|
||||
draggable_lists$isBeingDragged = v;
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3))
|
||||
public boolean removeUpOnButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
|
||||
return !DraggableLists.CONFIG.disableServerArrows;
|
||||
@@ -100,4 +67,25 @@ public abstract class OnlineServerEntryMixin extends ObjectSelectionList.Entry<S
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerData draggable_lists$getUnderlyingData() {
|
||||
return serverData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSelectionList.OnlineServerEntry draggable_lists$getUnderlyingEntry() {
|
||||
return (ServerSelectionList.OnlineServerEntry) (Object) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
if (!draggable_lists$isBeingDragged) return;
|
||||
render(guiGraphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draggable_lists$setBeingDragged(boolean v) {
|
||||
draggable_lists$isBeingDragged = v;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.server;
|
||||
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import com.mrmelon54.DraggableLists.duck.ServerListDuckProvider;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerList;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -16,7 +18,9 @@ public class ServerListMixin implements ServerListDuckProvider {
|
||||
private List<ServerData> serverList;
|
||||
|
||||
@Override
|
||||
public void draggable_lists$add(int index, ServerData serverData) {
|
||||
serverList.add(index, serverData);
|
||||
public void draggable_lists$moveItem(DragItem<ServerData, ServerSelectionList.OnlineServerEntry> item, int position) {
|
||||
ServerData serverData = item.draggable_lists$getUnderlyingData();
|
||||
serverList.remove(serverData);
|
||||
serverList.add(position, serverData);
|
||||
}
|
||||
}
|
||||
+80
-147
@@ -1,10 +1,11 @@
|
||||
package com.mrmelon54.DraggableLists.mixin.server;
|
||||
|
||||
import com.mrmelon54.DraggableLists.Cursor;
|
||||
import com.mrmelon54.DraggableLists.duck.MultiplayerScreenDuckProvider;
|
||||
import com.mrmelon54.DraggableLists.duck.ServerEntryDuckProvider;
|
||||
import com.mrmelon54.DraggableLists.DragItem;
|
||||
import com.mrmelon54.DraggableLists.DragList;
|
||||
import com.mrmelon54.DraggableLists.DragManager;
|
||||
import com.mrmelon54.DraggableLists.duck.ServerListDuckProvider;
|
||||
import net.minecraft.Util;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
@@ -12,18 +13,17 @@ import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerList;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Mixin(ServerSelectionList.class)
|
||||
public abstract class ServerSelectionListMixin extends ObjectSelectionList<ServerSelectionList.Entry> {
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract class ServerSelectionListMixin extends ObjectSelectionList<ServerSelectionList.Entry> implements DragList<ServerData, ServerSelectionList.OnlineServerEntry> {
|
||||
@Shadow
|
||||
@Final
|
||||
private JoinMultiplayerScreen screen;
|
||||
@@ -31,192 +31,125 @@ public abstract class ServerSelectionListMixin extends ObjectSelectionList<Serve
|
||||
@Shadow
|
||||
public abstract void setSelected(@Nullable ServerSelectionList.Entry entry);
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private List<ServerSelectionList.OnlineServerEntry> onlineServers;
|
||||
|
||||
@Shadow
|
||||
public abstract void updateOnlineServers(ServerList serverList);
|
||||
|
||||
@Shadow
|
||||
public abstract int getRowWidth();
|
||||
|
||||
@Unique
|
||||
private ServerSelectionList.OnlineServerEntry draggable_lists$draggingObject = null;
|
||||
@Unique
|
||||
private double draggable_lists$draggingStartX = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingStartY = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingOffsetX = 0;
|
||||
@Unique
|
||||
private double draggable_lists$draggingOffsetY = 0;
|
||||
@Unique
|
||||
private long draggable_lists$softScrollingTimer = 0;
|
||||
@Unique
|
||||
private double draggable_lists$softScrollingOrigin = 0;
|
||||
private final DragManager<ServerData, ServerSelectionList.OnlineServerEntry> draggable_lists$dragManager = new DragManager<>(this);
|
||||
|
||||
public ServerSelectionListMixin(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderListItems(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta) {
|
||||
draggable_lists$dragManager.renderListItems(guiGraphics, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0 && draggable_lists$draggingObject == null && draggable_lists$isCapMouseY((int) mouseY)) {
|
||||
ServerSelectionList.Entry a = this.getEntryAtPosition(mouseX, mouseY);
|
||||
draggable_lists$draggingObject = a instanceof ServerSelectionList.OnlineServerEntry b ? b : null;
|
||||
if (draggable_lists$draggingObject != null && draggable_lists$draggingObject instanceof ServerEntryDuckProvider duckProvider) {
|
||||
// Save the mouse origin position and the offset for the top left corner of the widget
|
||||
draggable_lists$draggingStartX = mouseX;
|
||||
draggable_lists$draggingStartY = mouseY;
|
||||
draggable_lists$draggingOffsetX = getRowLeft() - draggable_lists$draggingStartX;
|
||||
draggable_lists$draggingOffsetY = getRowTop(this.children().indexOf(draggable_lists$draggingObject)) - draggable_lists$draggingStartY;
|
||||
|
||||
// Don't grab if inside the server icon
|
||||
if (draggable_lists$draggingOffsetX > -32f) {
|
||||
draggable_lists$draggingObject = null;
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
this.setDragging(true);
|
||||
this.setFocused(draggable_lists$draggingObject);
|
||||
duckProvider.draggable_lists$setBeingDragged(true);
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
Cursor.setDragging();
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
return true;
|
||||
} else {
|
||||
draggable_lists$draggingObject = null;
|
||||
}
|
||||
}
|
||||
if (draggable_lists$dragManager.mouseClicked(mouseX, mouseY, button)) return true;
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
this.setDragging(false);
|
||||
if (draggable_lists$draggingObject != null) {
|
||||
Cursor.reset();
|
||||
if (draggable_lists$draggingObject instanceof ServerEntryDuckProvider duckProvider)
|
||||
duckProvider.draggable_lists$setBeingDragged(false);
|
||||
}
|
||||
draggable_lists$draggingObject = null;
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
if (draggable_lists$dragManager.mouseReleased(mouseX, mouseY, button)) return true;
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
if (button == 0 && draggable_lists$updateDragEvent(mouseX, mouseY)) return true;
|
||||
if (draggable_lists$dragManager.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) return true;
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
|
||||
if (draggable_lists$draggingObject != null) return true;
|
||||
if (draggable_lists$dragManager.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true;
|
||||
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$updateDragEvent(double mouseX, double mouseY) {
|
||||
double y = draggable_lists$capYCoordinate((int) mouseY, true);
|
||||
|
||||
ServerSelectionList.Entry hoveredEntry = this.getEntryAtPosition(mouseX, y);
|
||||
|
||||
ServerData draggingPack = draggable_lists$draggingObject instanceof ServerEntryDuckProvider duckProvider ? duckProvider.draggable_lists$getUnderlyingServer() : null;
|
||||
ServerData hoveredPack = hoveredEntry instanceof ServerEntryDuckProvider duckProvider ? duckProvider.draggable_lists$getUnderlyingServer() : null;
|
||||
|
||||
if (draggingPack != null && hoveredPack != null && draggingPack != hoveredPack && draggable_lists$draggingObject instanceof ServerEntryDuckProvider serverEntryDuckProvider) {
|
||||
if (draggable_lists$dragServerItem(serverEntryDuckProvider, y)) {
|
||||
draggable_lists$draggingStartY = mouseY;
|
||||
if (screen instanceof MultiplayerScreenDuckProvider multiplayerScreenDuckProvider) {
|
||||
int z = multiplayerScreenDuckProvider.draggable_lists$getIndexOfServerInfo(serverEntryDuckProvider.draggable_lists$getUnderlyingServer());
|
||||
draggable_lists$draggingObject = z == -1 ? null : (getEntry(z) instanceof ServerSelectionList.OnlineServerEntry b ? b : null);
|
||||
if (draggable_lists$draggingObject instanceof ServerEntryDuckProvider duckProvider)
|
||||
duckProvider.draggable_lists$setBeingDragged(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||
super.renderWidget(guiGraphics, mouseX, mouseY, delta);
|
||||
draggable_lists$dragManager.renderWidget(guiGraphics, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
if (this.draggable_lists$draggingObject instanceof ServerEntryDuckProvider duckProvider) {
|
||||
int z = Mth.floor(mouseY + draggable_lists$draggingOffsetY);
|
||||
int x = Mth.floor(draggable_lists$draggingStartX + draggable_lists$draggingOffsetX);
|
||||
int y = draggable_lists$capYCoordinate(z);
|
||||
int entryHeight = this.itemHeight - 4;
|
||||
int entryWidth = this.getRowWidth();
|
||||
duckProvider.draggable_lists$renderPoppedOut(guiGraphics, 0, y, x, entryWidth, entryHeight, mouseX, mouseY, false, delta);
|
||||
|
||||
if (y < z) {
|
||||
if (draggable_lists$softScrollingTimer == 0) {
|
||||
draggable_lists$softScrollingTimer = Util.getMillis();
|
||||
draggable_lists$softScrollingOrigin = getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - draggable_lists$softScrollingTimer) / 5f;
|
||||
setScrollAmount(draggable_lists$softScrollingOrigin + f);
|
||||
} else if (y > z) {
|
||||
if (draggable_lists$softScrollingTimer == 0) {
|
||||
draggable_lists$softScrollingTimer = Util.getMillis();
|
||||
draggable_lists$softScrollingOrigin = getScrollAmount();
|
||||
}
|
||||
float f = (float) (Util.getMillis() - draggable_lists$softScrollingTimer) / 5f;
|
||||
setScrollAmount(draggable_lists$softScrollingOrigin - f);
|
||||
} else {
|
||||
draggable_lists$softScrollingTimer = 0;
|
||||
}
|
||||
|
||||
draggable_lists$updateDragEvent(mouseX, mouseY);
|
||||
@Override
|
||||
public DragItem<ServerData, ServerSelectionList.OnlineServerEntry> draggable_lists$getEntryAtPosition(double mouseX, double mouseY) {
|
||||
ServerSelectionList.Entry entryAtPosition = getEntryAtPosition(mouseX, mouseY);
|
||||
if (entryAtPosition instanceof ServerSelectionList.OnlineServerEntry onlineServerEntry) {
|
||||
return (DragItem<ServerData, ServerSelectionList.OnlineServerEntry>) onlineServerEntry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Unique
|
||||
int draggable_lists$capYCoordinate(int y, boolean useScreenSpace) {
|
||||
int scrollableTop = getY() + 4;
|
||||
int scrollableHeight = getBottom() - getY() - (useScreenSpace ? 2 : itemHeight + 2);
|
||||
if (y < scrollableTop) y = scrollableTop;
|
||||
if (y > scrollableTop + scrollableHeight) y = scrollableTop + scrollableHeight;
|
||||
return y;
|
||||
public int draggable_lists$getIndexOfEntry(DragItem<ServerData, ServerSelectionList.OnlineServerEntry> selectedItem) {
|
||||
return children().indexOf(selectedItem.draggable_lists$getUnderlyingEntry());
|
||||
}
|
||||
|
||||
@Unique
|
||||
int draggable_lists$capYCoordinate(int y) {
|
||||
return draggable_lists$capYCoordinate(y, false);
|
||||
public void draggable_lists$setDragging(boolean b) {
|
||||
super.setDragging(b);
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$isCapMouseY(int y) {
|
||||
return draggable_lists$capYCoordinate(y, true) == y;
|
||||
public int draggable_lists$getHeaderHeight() {
|
||||
return headerHeight;
|
||||
}
|
||||
|
||||
@Unique
|
||||
boolean draggable_lists$dragServerItem(ServerEntryDuckProvider underlyingServerProvider, double mouseY) {
|
||||
if (screen instanceof MultiplayerScreenDuckProvider multiplayerScreenDuckProvider) {
|
||||
int i = multiplayerScreenDuckProvider.draggable_lists$getIndexOfServerInfo(underlyingServerProvider.draggable_lists$getUnderlyingServer());
|
||||
if (i == -1) return false;
|
||||
|
||||
int m = Mth.floor(mouseY - (double) this.getY()) - this.headerHeight + (int) this.getScrollAmount() - 4;
|
||||
int n = m / this.itemHeight;
|
||||
|
||||
if (n >= 0 && n < onlineServers.size()) {
|
||||
draggable_lists$moveServerEntry(i, n);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public int draggable_lists$getY() {
|
||||
return getY();
|
||||
}
|
||||
|
||||
@Unique
|
||||
void draggable_lists$moveServerEntry(int a, int b) {
|
||||
ServerList servers = this.screen.getServers();
|
||||
public int draggable_lists$getBottom() {
|
||||
return getBottom();
|
||||
}
|
||||
|
||||
public int draggable_lists$getItemHeight() {
|
||||
return itemHeight;
|
||||
}
|
||||
|
||||
public int draggable_lists$getRowTop(int i) {
|
||||
return getRowTop(i);
|
||||
}
|
||||
|
||||
public int draggable_lists$getRowBottom(int i) {
|
||||
return getRowBottom(i);
|
||||
}
|
||||
|
||||
public double draggable_lists$getRowLeft() {
|
||||
return getRowLeft();
|
||||
}
|
||||
|
||||
public int draggable_lists$getRowWidth() {
|
||||
return getRowWidth();
|
||||
}
|
||||
|
||||
public double draggable_lists$getScrollAmount() {
|
||||
return getScrollAmount();
|
||||
}
|
||||
|
||||
public void draggable_lists$setScrollAmount(double v) {
|
||||
setScrollAmount(v);
|
||||
}
|
||||
|
||||
public void draggable_lists$moveServerEntry(DragItem<ServerData, ServerSelectionList.OnlineServerEntry> item, int n) {
|
||||
ServerList servers = screen.getServers();
|
||||
if (servers instanceof ServerListDuckProvider duckProvider) {
|
||||
ServerData serverData = servers.get(a);
|
||||
servers.remove(serverData);
|
||||
duckProvider.draggable_lists$add(b, serverData);
|
||||
duckProvider.draggable_lists$moveItem(item, n);
|
||||
servers.save();
|
||||
updateOnlineServers(servers);
|
||||
}
|
||||
}
|
||||
|
||||
public int draggable_lists$getItemCount() {
|
||||
return getItemCount();
|
||||
}
|
||||
|
||||
public void draggable_lists$renderItem(GuiGraphics guiGraphics, int mouseX, int mouseY, float tickDelta, int i, int rowLeft, int rowTop, int rowWidth, int rowHeight) {
|
||||
renderItem(guiGraphics, mouseX, mouseY, tickDelta, i, rowLeft, rowTop, rowWidth, rowHeight);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user