Sort assets by name in AssetManager and ObjectManager
This commit is contained in:
@@ -15,6 +15,7 @@ public interface ReplayAsset<T> extends GuiEntryListEntry {
|
||||
|
||||
void drawToScreen(int x, int y, int maxWidth, int maxHeight);
|
||||
|
||||
String getAssetName();
|
||||
void setAssetName(String name);
|
||||
|
||||
ReplayAsset<T> copy();
|
||||
|
||||
@@ -40,6 +40,11 @@ public class ReplayImageAsset implements ReplayAsset<BufferedImage> {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssetName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAssetName(String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -18,6 +18,9 @@ import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOverlay {
|
||||
|
||||
@@ -63,6 +66,7 @@ public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOve
|
||||
try {
|
||||
ReplayAsset newAsset = assetRepository.addAsset(file.getName(), new FileInputStream(file));
|
||||
assetGuiEntryList.addElement(newAsset);
|
||||
sortAssetList();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -109,7 +113,11 @@ public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOve
|
||||
assetGuiEntryList.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void onSelectionChanged(int selectionIndex) {
|
||||
currentAsset = assetGuiEntryList.getElement(selectionIndex);
|
||||
ReplayAsset newAsset = assetGuiEntryList.getElement(selectionIndex);
|
||||
if (newAsset == currentAsset) {
|
||||
return;
|
||||
}
|
||||
currentAsset = newAsset;
|
||||
inputElements.setElementEnabled(currentAsset != null);
|
||||
|
||||
assetNameInput.setText(currentAsset != null ? currentAsset.getDisplayString() : "");
|
||||
@@ -121,6 +129,7 @@ public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOve
|
||||
for(ReplayAsset asset : assetRepository.getCopyOfReplayAssets()) {
|
||||
assetGuiEntryList.addElement(asset);
|
||||
}
|
||||
sortAssetList();
|
||||
}
|
||||
|
||||
int visibleEntries = (int)Math.floor(((double)this.height-(45+20+15+20))/14);
|
||||
@@ -179,6 +188,7 @@ public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOve
|
||||
|
||||
if(currentAsset != null) {
|
||||
currentAsset.setAssetName(assetNameInput.getText());
|
||||
sortAssetList();
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
@@ -199,4 +209,15 @@ public class GuiAssetManager extends GuiScreen implements GuiReplayOverlay.NoOve
|
||||
}
|
||||
}, "replaymod-asset-saver").start();
|
||||
}
|
||||
|
||||
private void sortAssetList() {
|
||||
List<ReplayAsset> list = assetGuiEntryList.getElements();
|
||||
Collections.sort(list, new Comparator<ReplayAsset>() {
|
||||
@Override
|
||||
public int compare(ReplayAsset o1, ReplayAsset o2) {
|
||||
return o1.getAssetName().compareTo(o2.getAssetName());
|
||||
}
|
||||
});
|
||||
assetGuiEntryList.setSelectionIndex(list.indexOf(currentAsset));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -129,11 +131,18 @@ public class GuiObjectManager extends GuiScreen implements GuiReplayOverlay.NoOv
|
||||
|
||||
dropdownLabel = new GuiString(0, 0, Color.WHITE, I18n.format("replaymod.gui.assets.filechooser")+": ");
|
||||
assetDropdown = new GuiDropdown<GuiEntryListValueEntry<UUID>>(fontRendererObj, 0, 0, 0, 5);
|
||||
if(ReplayHandler.getAssetRepository().getCopyOfReplayAssets().isEmpty()) {
|
||||
List<ReplayAsset> assets = ReplayHandler.getAssetRepository().getCopyOfReplayAssets();
|
||||
Collections.sort(assets, new Comparator<ReplayAsset>() {
|
||||
@Override
|
||||
public int compare(ReplayAsset o1, ReplayAsset o2) {
|
||||
return o1.getAssetName().compareTo(o2.getAssetName());
|
||||
}
|
||||
});
|
||||
if(assets.isEmpty()) {
|
||||
assetDropdown.addElement(new GuiEntryListValueEntry<UUID>(I18n.format("replaymod.gui.assets.emptylist"), null));
|
||||
} else {
|
||||
assetDropdown.addElement(new GuiEntryListValueEntry<UUID>(I18n.format("replaymod.gui.assets.noselection"), null));
|
||||
for(ReplayAsset asset : ReplayHandler.getAssetRepository().getCopyOfReplayAssets()) {
|
||||
for(ReplayAsset asset : assets) {
|
||||
assetDropdown.addElement(new GuiEntryListValueEntry<UUID>(
|
||||
asset.getDisplayString(), ReplayHandler.getAssetRepository().getUUIDForAsset(asset)));
|
||||
}
|
||||
|
||||
@@ -153,6 +153,9 @@ public class GuiEntryList<T extends GuiEntryListEntry> extends GuiAdvancedTextFi
|
||||
public List<T> getCopyOfElements() {
|
||||
return new ArrayList<T>(elements);
|
||||
}
|
||||
public List<T> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void replaceElement(int index, T replace) {
|
||||
elements.set(index, replace);
|
||||
|
||||
Reference in New Issue
Block a user