Add multi-select to keyframe repository (see #318)
This commit is contained in:
@@ -887,6 +887,10 @@ public class MCVer {
|
|||||||
//$$ public static final int KEY_Z = org.lwjgl.input.Keyboard.KEY_Z;
|
//$$ public static final int KEY_Z = org.lwjgl.input.Keyboard.KEY_Z;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
public static boolean hasControlDown() {
|
||||||
|
return Screen.hasControlDown();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isKeyDown(int keyCode) {
|
public static boolean isKeyDown(int keyCode) {
|
||||||
//#if MC>=11500
|
//#if MC>=11500
|
||||||
return InputUtil.isKeyPressed(getMinecraft().getWindow().getHandle(), keyCode);
|
return InputUtil.isKeyPressed(getMinecraft().getWindow().getHandle(), keyCode);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.google.common.util.concurrent.Futures;
|
|||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import com.replaymod.core.ReplayMod;
|
import com.replaymod.core.ReplayMod;
|
||||||
import com.replaymod.core.utils.Utils;
|
import com.replaymod.core.utils.Utils;
|
||||||
|
import com.replaymod.core.versions.MCVer;
|
||||||
import com.replaymod.replay.ReplayModReplay;
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||||
import com.replaymod.replaystudio.pathing.path.Path;
|
import com.replaymod.replaystudio.pathing.path.Path;
|
||||||
@@ -32,8 +33,10 @@ import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
|||||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gui for loading and saving {@link Timeline Timelines}.
|
* Gui for loading and saving {@link Timeline Timelines}.
|
||||||
@@ -51,7 +54,9 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||||
Utils.addCallback(popup.getFuture(), doIt -> {
|
Utils.addCallback(popup.getFuture(), doIt -> {
|
||||||
if (doIt) {
|
if (doIt) {
|
||||||
timelines.put(selectedEntry.name, currentTimeline);
|
for (Entry entry : selectedEntries) {
|
||||||
|
timelines.put(entry.name, currentTimeline);
|
||||||
|
}
|
||||||
overwriteButton.setDisabled();
|
overwriteButton.setDisabled();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@@ -105,7 +110,7 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
getMinecraft().openScreen(null);
|
getMinecraft().openScreen(null);
|
||||||
try {
|
try {
|
||||||
Timeline timeline = timelines.get(selectedEntry.name);
|
Timeline timeline = timelines.get(selectedEntries.iterator().next().name);
|
||||||
for (Path path : timeline.getPaths()) {
|
for (Path path : timeline.getPaths()) {
|
||||||
path.updateAll();
|
path.updateAll();
|
||||||
}
|
}
|
||||||
@@ -118,6 +123,7 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
public final GuiButton renameButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
public final GuiButton renameButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Entry selectedEntry = selectedEntries.iterator().next();
|
||||||
final GuiTextField nameField = new GuiTextField().setSize(200, 20).setFocused(true).setText(selectedEntry.name);
|
final GuiTextField nameField = new GuiTextField().setSize(200, 20).setFocused(true).setText(selectedEntry.name);
|
||||||
final GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this,
|
final GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this,
|
||||||
new GuiLabel().setI18nText("replaymod.gui.rename").setColor(Colors.BLACK),
|
new GuiLabel().setI18nText("replaymod.gui.rename").setColor(Colors.BLACK),
|
||||||
@@ -168,14 +174,13 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean delete) {
|
public void onSuccess(Boolean delete) {
|
||||||
if (delete) {
|
if (delete) {
|
||||||
timelines.remove(selectedEntry.name);
|
for (Entry entry : selectedEntries) {
|
||||||
list.getListPanel().removeElement(selectedEntry);
|
timelines.remove(entry.name);
|
||||||
|
list.getListPanel().removeElement(entry);
|
||||||
|
}
|
||||||
|
|
||||||
selectedEntry = null;
|
selectedEntries.clear();
|
||||||
overwriteButton.setDisabled();
|
updateButtons();
|
||||||
loadButton.setDisabled();
|
|
||||||
renameButton.setDisabled();
|
|
||||||
removeButton.setDisabled();
|
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,7 +199,7 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
private final PathingRegistry registry;
|
private final PathingRegistry registry;
|
||||||
private final ReplayFile replayFile;
|
private final ReplayFile replayFile;
|
||||||
|
|
||||||
private Entry selectedEntry;
|
private final Set<Entry> selectedEntries = new HashSet<>();
|
||||||
|
|
||||||
{
|
{
|
||||||
setBackground(Background.NONE);
|
setBackground(Background.NONE);
|
||||||
@@ -234,6 +239,15 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateButtons() {
|
||||||
|
int selected = selectedEntries.size();
|
||||||
|
|
||||||
|
overwriteButton.setEnabled(selected >= 1);
|
||||||
|
loadButton.setEnabled(selected == 1);
|
||||||
|
renameButton.setEnabled(selected == 1);
|
||||||
|
removeButton.setEnabled(selected >= 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display() {
|
public void display() {
|
||||||
super.display();
|
super.display();
|
||||||
@@ -281,13 +295,20 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
selectedEntry = this;
|
if (!MCVer.Keyboard.hasControlDown()) {
|
||||||
buttonPanel.forEach(IGuiButton.class).setEnabled();
|
selectedEntries.clear();
|
||||||
|
}
|
||||||
|
if (selectedEntries.contains(this)) {
|
||||||
|
selectedEntries.remove(this);
|
||||||
|
} else {
|
||||||
|
selectedEntries.add(this);
|
||||||
|
}
|
||||||
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
if (selectedEntry == this) {
|
if (selectedEntries.contains(this)) {
|
||||||
renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), Colors.BLACK);
|
renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), Colors.BLACK);
|
||||||
renderer.drawRect(0, 0, 2, size.getHeight(), Colors.WHITE);
|
renderer.drawRect(0, 0, 2, size.getHeight(), Colors.WHITE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user