mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-18 11:29:35 +00:00
Update buildscript & apply automatic formatting rules
This commit is contained in:
1 parent
a7683b885d
commit
f7a900e910
173 files changed
+4581
-5321
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.core.gui.GuiScrollSlot;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
@@ -30,43 +32,35 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
public class PresetsWidget extends Widget
|
||||
{
|
||||
public class PresetsWidget extends Widget {
|
||||
|
||||
public static class PresetTag implements ItemFilter
|
||||
{
|
||||
public static class PresetTag implements ItemFilter {
|
||||
public String filename = null;
|
||||
public String displayName = "";
|
||||
public boolean whitelist = true;
|
||||
public HashSet<String> items;
|
||||
|
||||
public PresetTag(String displayName)
|
||||
{
|
||||
public PresetTag(String displayName) {
|
||||
this(displayName, new HashSet<>(), false, null);
|
||||
}
|
||||
|
||||
public PresetTag(String displayName, HashSet<String> items)
|
||||
{
|
||||
public PresetTag(String displayName, HashSet<String> items) {
|
||||
this(displayName, items, true, null);
|
||||
}
|
||||
|
||||
public PresetTag(String displayName, HashSet<String> items, boolean whitelist, String filename)
|
||||
{
|
||||
public PresetTag(String displayName, HashSet<String> items, boolean whitelist, String filename) {
|
||||
this.displayName = displayName;
|
||||
this.items = items != null? items: new HashSet<>();
|
||||
this.items = items != null ? items : new HashSet<>();
|
||||
this.whitelist = whitelist;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public boolean matches(final ItemStack stack)
|
||||
{
|
||||
public boolean matches(final ItemStack stack) {
|
||||
return items.contains(StackInfo.getItemStackGUID(stack)) == whitelist;
|
||||
}
|
||||
|
||||
public static PresetTag loadFromFile(File file)
|
||||
{
|
||||
public static PresetTag loadFromFile(File file) {
|
||||
if (!file.isFile() || !file.exists() || file.getName().equals("selected.ini")) {
|
||||
return null;
|
||||
}
|
||||
@@ -81,14 +75,15 @@ public class PresetsWidget extends Widget
|
||||
NEIClientConfig.logger.error("Failed to load presets from file {}", file, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
final JsonParser parser = new JsonParser();
|
||||
final JsonObject metaObject = parser.parse(itemStrings.remove(0)).getAsJsonObject();
|
||||
final JsonObject metaObject =
|
||||
parser.parse(itemStrings.remove(0)).getAsJsonObject();
|
||||
final String displayName = metaObject.get("displayName").getAsString();
|
||||
final boolean whitelist = metaObject.get("whitelist").getAsBoolean();
|
||||
final HashSet<String> items = new HashSet<>();
|
||||
|
||||
for (String itemStr: itemStrings) {
|
||||
for (String itemStr : itemStrings) {
|
||||
items.add(itemStr);
|
||||
}
|
||||
|
||||
@@ -99,33 +94,29 @@ public class PresetsWidget extends Widget
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteFile()
|
||||
{
|
||||
|
||||
public void deleteFile() {
|
||||
if (presetsDir == null || filename == null) return;
|
||||
final File tagFile = new File(presetsDir, filename);
|
||||
|
||||
if (tagFile.exists()) {
|
||||
tagFile.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveToFile()
|
||||
{
|
||||
public void saveToFile() {
|
||||
if (presetsDir == null) return;
|
||||
|
||||
if (filename == null) {
|
||||
final String sanitized = displayName.replaceAll("[^_\\-.0-9a-zA-Z]", "_");
|
||||
int index = 1;
|
||||
|
||||
|
||||
filename = sanitized + ".ini";
|
||||
|
||||
while ((new File(presetsDir, filename)).exists() || filename.equals("selected.ini")) {
|
||||
filename = sanitized + " (" + index + ").ini";
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final List<String> strings = new ArrayList<>();
|
||||
@@ -141,7 +132,7 @@ public class PresetsWidget extends Widget
|
||||
} catch (JsonSyntaxException e) {
|
||||
NEIClientConfig.logger.error("Failed to stringify presets ItemStack to json string");
|
||||
}
|
||||
|
||||
|
||||
final File tagFile = new File(presetsDir, filename);
|
||||
|
||||
try (FileOutputStream output = new FileOutputStream(tagFile)) {
|
||||
@@ -149,35 +140,32 @@ public class PresetsWidget extends Widget
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save presets list to file {}", tagFile, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public PresetTag copy()
|
||||
{
|
||||
public PresetTag copy() {
|
||||
return new PresetTag(displayName, (HashSet) items.clone(), whitelist, null);
|
||||
}
|
||||
|
||||
}
|
||||
protected static class SubsetListBox extends GuiScrollSlot
|
||||
{
|
||||
|
||||
protected static class SubsetListBox extends GuiScrollSlot {
|
||||
protected final List<PresetTag> presets = new ArrayList<>();
|
||||
protected final List<PresetTag> selected = new ArrayList<>();
|
||||
protected int lastSelectedIndex = 0;
|
||||
|
||||
public SubsetListBox(File presetsDir)
|
||||
{
|
||||
public SubsetListBox(File presetsDir) {
|
||||
super(0, 0, 0, 0);
|
||||
setSmoothScroll(false);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
presets.addAll(ItemList.forkJoinPool
|
||||
.submit(() -> Arrays.asList(presetsDir.listFiles()).parallelStream()
|
||||
.map(f -> PresetTag.loadFromFile(f))
|
||||
.filter(p -> p != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get());
|
||||
|
||||
.submit(() -> Arrays.asList(presetsDir.listFiles()).parallelStream()
|
||||
.map(f -> PresetTag.loadFromFile(f))
|
||||
.filter(p -> p != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
.get());
|
||||
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
@@ -187,14 +175,12 @@ public class PresetsWidget extends Widget
|
||||
sort();
|
||||
}
|
||||
|
||||
public SubsetListBox()
|
||||
{
|
||||
public SubsetListBox() {
|
||||
super(0, 0, 0, 0);
|
||||
setSmoothScroll(false);
|
||||
}
|
||||
|
||||
public void addTag(final PresetTag tag, boolean sel)
|
||||
{
|
||||
public void addTag(final PresetTag tag, boolean sel) {
|
||||
presets.add(tag);
|
||||
|
||||
if (sel) {
|
||||
@@ -202,18 +188,15 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
}
|
||||
|
||||
protected List<PresetTag> getPresets()
|
||||
{
|
||||
protected List<PresetTag> getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
protected List<PresetTag> getSelected()
|
||||
{
|
||||
protected List<PresetTag> getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void replaceSeleted(final PresetTag tag)
|
||||
{
|
||||
public void replaceSeleted(final PresetTag tag) {
|
||||
|
||||
if (selected.size() == 1) {
|
||||
selected.get(0).deleteFile();
|
||||
@@ -229,32 +212,27 @@ public class PresetsWidget extends Widget
|
||||
sort();
|
||||
}
|
||||
|
||||
public void sort()
|
||||
{
|
||||
public void sort() {
|
||||
presets.sort((o1, o2) -> o1.displayName.compareTo(o2.displayName));
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
public void clear() {
|
||||
presets.clear();
|
||||
selected.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotHeight(int slot)
|
||||
{
|
||||
public int getSlotHeight(int slot) {
|
||||
return 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNumSlots()
|
||||
{
|
||||
protected int getNumSlots() {
|
||||
return presets.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void slotClicked(int slot, int button, int mx, int my, int count)
|
||||
{
|
||||
protected void slotClicked(int slot, int button, int mx, int my, int count) {
|
||||
|
||||
if (slot >= presets.size()) {
|
||||
return;
|
||||
@@ -294,9 +272,8 @@ public class PresetsWidget extends Widget
|
||||
if (!sel || size > 1) {
|
||||
selected.add(tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (selected.isEmpty()) {
|
||||
lastSelectedIndex = 0;
|
||||
} else if (!NEIClientUtils.shiftKey()) {
|
||||
@@ -314,13 +291,13 @@ public class PresetsWidget extends Widget
|
||||
|
||||
saveSelToFile();
|
||||
PresetsWidget.edit = null;
|
||||
PresetsWidget.openListBox = !presets.isEmpty() && (NEIClientUtils.controlKey() || NEIClientUtils.shiftKey() || !option.contains(mx, my));
|
||||
PresetsWidget.openListBox = !presets.isEmpty()
|
||||
&& (NEIClientUtils.controlKey() || NEIClientUtils.shiftKey() || !option.contains(mx, my));
|
||||
ItemList.updateFilter.restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSlot(int slot, int x, int y, int mx, int my, float frame)
|
||||
{
|
||||
protected void drawSlot(int slot, int x, int y, int mx, int my, float frame) {
|
||||
if (slot >= presets.size()) {
|
||||
return;
|
||||
}
|
||||
@@ -331,54 +308,51 @@ public class PresetsWidget extends Widget
|
||||
final Rectangle4i option = new Rectangle4i(x + 18, y, width - 18 - 18, 18);
|
||||
final PresetTag tag = presets.get(slot);
|
||||
|
||||
final int optionState = selected.contains(tag)? 0: option.contains(x + mx, y + my)? 1: 2;
|
||||
final int directionState = direction.contains(x + mx, y + my)? 1: 2;
|
||||
final int deleteState = delete.contains(x + mx, y + my)? 1: 2;
|
||||
final int optionState = selected.contains(tag) ? 0 : option.contains(x + mx, y + my) ? 1 : 2;
|
||||
final int directionState = direction.contains(x + mx, y + my) ? 1 : 2;
|
||||
final int deleteState = delete.contains(x + mx, y + my) ? 1 : 2;
|
||||
|
||||
final String displayName = cropText(tag.displayName, option.w - 6);
|
||||
final String dirName = tag.whitelist? translate("presets.whitelist.label"): translate("presets.blacklist.label");
|
||||
final String dirName =
|
||||
tag.whitelist ? translate("presets.whitelist.label") : translate("presets.blacklist.label");
|
||||
|
||||
//blacklist or whitelist
|
||||
LayoutManager.getLayoutStyle().drawSubsetTag(null, direction.x, direction.y, direction.w, direction.h, directionState, false);
|
||||
// blacklist or whitelist
|
||||
LayoutManager.getLayoutStyle()
|
||||
.drawSubsetTag(null, direction.x, direction.y, direction.w, direction.h, directionState, false);
|
||||
GuiDraw.drawString(dirName, direction.x + 6, direction.y + 5, directionState == 2 ? 0xFFE0E0E0 : 0xFFFFA0);
|
||||
|
||||
//option name
|
||||
LayoutManager.getLayoutStyle().drawSubsetTag(null, option.x, option.y, option.w, option.h, optionState, false);
|
||||
|
||||
// option name
|
||||
LayoutManager.getLayoutStyle()
|
||||
.drawSubsetTag(null, option.x, option.y, option.w, option.h, optionState, false);
|
||||
GuiDraw.drawString(displayName, option.x + 3, option.y + 5, optionState == 2 ? 0xFFE0E0E0 : 0xFFFFA0);
|
||||
|
||||
//remove icon
|
||||
LayoutManager.getLayoutStyle().drawSubsetTag(null, delete.x, delete.y, delete.w, delete.h, deleteState, false);
|
||||
// remove icon
|
||||
LayoutManager.getLayoutStyle()
|
||||
.drawSubsetTag(null, delete.x, delete.y, delete.w, delete.h, deleteState, false);
|
||||
GuiDraw.drawString("✕", delete.x + 6, delete.y + 5, deleteState == 2 ? 0xFFE0E0E0 : 0x601010);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(float frame)
|
||||
{
|
||||
}
|
||||
public void drawOverlay(float frame) {}
|
||||
|
||||
@Override
|
||||
public void drawBackground(float frame)
|
||||
{
|
||||
drawRect(x , y, x + width, y + height, 0xFF202020);
|
||||
@Override
|
||||
public void drawBackground(float frame) {
|
||||
drawRect(x, y, x + width, y + height, 0xFF202020);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScrollbar(float frame)
|
||||
{
|
||||
public void drawScrollbar(float frame) {
|
||||
if (hasScrollbar()) {
|
||||
super.drawScrollbar(frame);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scrollbarGuideAlignment()
|
||||
{
|
||||
public int scrollbarGuideAlignment() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected List<PresetTag> loadSelFromFile(File presetsDir, List<PresetTag> presets)
|
||||
{
|
||||
protected List<PresetTag> loadSelFromFile(File presetsDir, List<PresetTag> presets) {
|
||||
final File file = new File(presetsDir, "selected.ini");
|
||||
List<PresetTag> selected = new ArrayList<>();
|
||||
|
||||
@@ -397,32 +371,30 @@ public class PresetsWidget extends Widget
|
||||
|
||||
final HashMap<String, PresetTag> map = new HashMap<>();
|
||||
|
||||
for (PresetTag tag: presets) {
|
||||
for (PresetTag tag : presets) {
|
||||
map.put(tag.filename, tag);
|
||||
}
|
||||
|
||||
for (String filename: itemStrings) {
|
||||
for (String filename : itemStrings) {
|
||||
if (map.containsKey(filename)) {
|
||||
selected.add(map.get(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Throwable th) {
|
||||
NEIClientConfig.logger.error("Failed to load presets selected from file", file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void saveSelToFile()
|
||||
{
|
||||
public void saveSelToFile() {
|
||||
|
||||
final File file = new File(presetsDir, "selected.ini");
|
||||
final List<String> list = new ArrayList<>();
|
||||
|
||||
for (final PresetTag tag: selected) {
|
||||
for (final PresetTag tag : selected) {
|
||||
list.add(tag.filename);
|
||||
}
|
||||
|
||||
@@ -431,12 +403,10 @@ public class PresetsWidget extends Widget
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save presets selected list to file {}", file, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
protected static class MouseSelection
|
||||
{
|
||||
|
||||
protected static class MouseSelection {
|
||||
public int startX = -1;
|
||||
public int startY = -1;
|
||||
public int startIndex = -1;
|
||||
@@ -444,9 +414,8 @@ public class PresetsWidget extends Widget
|
||||
public HashSet<ItemStack> items = new HashSet<>();
|
||||
public boolean append = true;
|
||||
|
||||
public MouseSelection(int slotIndex, boolean append)
|
||||
{
|
||||
final ItemsGrid grid = ItemPanels.itemPanel.getGrid();
|
||||
public MouseSelection(int slotIndex, boolean append) {
|
||||
final ItemsGrid grid = ItemPanels.itemPanel.getGrid();
|
||||
final Rectangle4i rec = grid.getSlotRect(slotIndex - (grid.getPage() - 1) * grid.getPerPage());
|
||||
|
||||
this.append = append;
|
||||
@@ -455,10 +424,9 @@ public class PresetsWidget extends Widget
|
||||
startX = rec.x;
|
||||
startY = rec.y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final static FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
protected static final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
protected static SubsetListBox listbox = new SubsetListBox();
|
||||
protected static File presetsDir;
|
||||
|
||||
@@ -467,33 +435,27 @@ public class PresetsWidget extends Widget
|
||||
protected long lastclicktime;
|
||||
protected static MouseSelection mouseSelection;
|
||||
|
||||
protected final static Button dropdown = new Button()
|
||||
{
|
||||
protected static final Button dropdown = new Button() {
|
||||
|
||||
public boolean onButtonPress(boolean rightclick)
|
||||
{
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (!rightclick) {
|
||||
openListBox = !openListBox;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRenderLabel()
|
||||
{
|
||||
public String getRenderLabel() {
|
||||
return "...";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
protected final static Label selectedValue = new Label("", false)
|
||||
{
|
||||
protected static final Label selectedValue = new Label("", false) {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey)
|
||||
{
|
||||
public void draw(int mousex, int mousey) {
|
||||
final String text = cropText(this.text, w);
|
||||
|
||||
if (text.equals(this.text)) {
|
||||
@@ -501,48 +463,40 @@ public class PresetsWidget extends Widget
|
||||
} else {
|
||||
GuiDraw.drawString(text, x, y + (h - 8) / 2, colour);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip)
|
||||
{
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
||||
if (contains(mx, my) && listbox.getSelected().size() <= 1) {
|
||||
tooltip.add(translate("presets.label.tooltip"));
|
||||
}
|
||||
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
protected final static TextField selectedDisplayName = new TextField("")
|
||||
{
|
||||
|
||||
public void onTextChange(String oldText)
|
||||
{
|
||||
protected static final TextField selectedDisplayName = new TextField("") {
|
||||
|
||||
public void onTextChange(String oldText) {
|
||||
if (edit != null) {
|
||||
edit.displayName = text();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey)
|
||||
{
|
||||
public void draw(int mousex, int mousey) {
|
||||
super.draw(mousex, mousey);
|
||||
|
||||
if (text().isEmpty()) {
|
||||
GuiDraw.drawGradientRect(x - 1, y - 1, 1, h + 2, 0xFFcc3300, 0xFFcc3300); //Left
|
||||
GuiDraw.drawGradientRect(x - 1, y - 1, w + 2, 1, 0xFFcc3300, 0xFFcc3300); //Top
|
||||
GuiDraw.drawGradientRect(x + w, y - 1, 1, h + 2, 0xFFcc3300, 0xFFcc3300); //Left
|
||||
GuiDraw.drawGradientRect(x - 1, y + h, w + 2, 1, 0xFFcc3300, 0xFFcc3300); //Bottom
|
||||
GuiDraw.drawGradientRect(x - 1, y - 1, 1, h + 2, 0xFFcc3300, 0xFFcc3300); // Left
|
||||
GuiDraw.drawGradientRect(x - 1, y - 1, w + 2, 1, 0xFFcc3300, 0xFFcc3300); // Top
|
||||
GuiDraw.drawGradientRect(x + w, y - 1, 1, h + 2, 0xFFcc3300, 0xFFcc3300); // Left
|
||||
GuiDraw.drawGradientRect(x - 1, y + h, w + 2, 1, 0xFFcc3300, 0xFFcc3300); // Bottom
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip)
|
||||
{
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
||||
if (contains(mx, my) && listbox.getSelected().size() <= 1) {
|
||||
tooltip.add(translate("presets.textfield.tooltip.1"));
|
||||
tooltip.add(translate("presets.textfield.tooltip.2"));
|
||||
@@ -550,40 +504,38 @@ public class PresetsWidget extends Widget
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
protected final static Button selectedState = new Button("B")
|
||||
{
|
||||
protected static final Button selectedState = new Button("B") {
|
||||
|
||||
public boolean onButtonPress(boolean rightclick)
|
||||
{
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
if (!rightclick && edit != null) {
|
||||
edit.whitelist = !edit.whitelist;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenderLabel()
|
||||
{
|
||||
return edit != null && edit.whitelist? translate("presets.whitelist.label"): translate("presets.blacklist.label");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTooltips(List<String> tooltip)
|
||||
{
|
||||
if (edit != null) {
|
||||
tooltip.add(edit.whitelist? translate("presets.whitelist.tooltip"): translate("presets.blacklist.tooltip"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRenderLabel() {
|
||||
return edit != null && edit.whitelist
|
||||
? translate("presets.whitelist.label")
|
||||
: translate("presets.blacklist.label");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTooltips(List<String> tooltip) {
|
||||
if (edit != null) {
|
||||
tooltip.add(
|
||||
edit.whitelist
|
||||
? translate("presets.whitelist.tooltip")
|
||||
: translate("presets.blacklist.tooltip"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected static String cropText(String text, int containerWidth)
|
||||
{
|
||||
|
||||
protected static String cropText(String text, int containerWidth) {
|
||||
|
||||
int textWidth = fontRenderer.getStringWidth(text);
|
||||
|
||||
@@ -601,31 +553,26 @@ public class PresetsWidget extends Widget
|
||||
return text;
|
||||
}
|
||||
|
||||
protected static void setEditedTag(final PresetTag tag)
|
||||
{
|
||||
protected static void setEditedTag(final PresetTag tag) {
|
||||
edit = tag;
|
||||
openListBox = false;
|
||||
selectedDisplayName.setText(tag != null? tag.displayName: "");
|
||||
selectedDisplayName.setText(tag != null ? tag.displayName : "");
|
||||
ItemList.updateFilter.restart();
|
||||
}
|
||||
|
||||
public static void addTag(final PresetTag tag)
|
||||
{
|
||||
public static void addTag(final PresetTag tag) {
|
||||
addTag(tag, false);
|
||||
}
|
||||
|
||||
public static void addTag(final PresetTag tag, boolean sel)
|
||||
{
|
||||
public static void addTag(final PresetTag tag, boolean sel) {
|
||||
listbox.addTag(tag, sel);
|
||||
}
|
||||
|
||||
public static boolean inEditMode()
|
||||
{
|
||||
public static boolean inEditMode() {
|
||||
return edit != null;
|
||||
}
|
||||
|
||||
public static boolean isHidden(final ItemStack item)
|
||||
{
|
||||
public static boolean isHidden(final ItemStack item) {
|
||||
|
||||
if (edit != null) {
|
||||
|
||||
@@ -644,14 +591,12 @@ public class PresetsWidget extends Widget
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setHidden(final ItemStack stack, final boolean append)
|
||||
{
|
||||
public static void setHidden(final ItemStack stack, final boolean append) {
|
||||
if (edit == null) {
|
||||
return;
|
||||
}
|
||||
@@ -679,17 +624,14 @@ public class PresetsWidget extends Widget
|
||||
hideItem(items.get(i), append);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
hideItem(stack, append);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static void hideItem(final ItemStack stack, boolean append)
|
||||
{
|
||||
protected static void hideItem(final ItemStack stack, boolean append) {
|
||||
final String guid = StackInfo.getItemStackGUID(stack);
|
||||
|
||||
if (append) {
|
||||
@@ -697,20 +639,18 @@ public class PresetsWidget extends Widget
|
||||
} else {
|
||||
edit.items.remove(guid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static String getModId(final ItemStack stack)
|
||||
{
|
||||
protected static String getModId(final ItemStack stack) {
|
||||
try {
|
||||
return GameRegistry.findUniqueIdentifierFor(stack.getItem()).modId;
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void loadPresets(final String worldPath)
|
||||
{
|
||||
public static void loadPresets(final String worldPath) {
|
||||
final File dir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
||||
presetsDir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath + "/presets");
|
||||
|
||||
@@ -723,7 +663,7 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
|
||||
listbox = new SubsetListBox(presetsDir);
|
||||
|
||||
|
||||
edit = null;
|
||||
openListBox = false;
|
||||
selectedDisplayName.setText("");
|
||||
@@ -732,8 +672,7 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mx, int my)
|
||||
{
|
||||
public void draw(int mx, int my) {
|
||||
|
||||
if (edit != null) {
|
||||
|
||||
@@ -751,48 +690,45 @@ public class PresetsWidget extends Widget
|
||||
} else {
|
||||
final List<PresetTag> selected = listbox.getSelected();
|
||||
final int size = selected.size();
|
||||
|
||||
selectedValue.text = size> 1? translate("presets.label.selected", size): (size == 1? selected.get(0).displayName: "");
|
||||
|
||||
selectedValue.text = size > 1
|
||||
? translate("presets.label.selected", size)
|
||||
: (size == 1 ? selected.get(0).displayName : "");
|
||||
selectedValue.y = y;
|
||||
selectedValue.h = h;
|
||||
selectedValue.w = w - h - 4;
|
||||
selectedValue.x = x;
|
||||
|
||||
selectedValue.draw(mx, my);
|
||||
selectedValue.draw(mx, my);
|
||||
}
|
||||
|
||||
|
||||
dropdown.y = y;
|
||||
dropdown.w = dropdown.h = h;
|
||||
dropdown.x = x + w - dropdown.w;
|
||||
dropdown.state = edit != null || listbox.getNumSlots() == 0? 2: 0;
|
||||
dropdown.state = edit != null || listbox.getNumSlots() == 0 ? 2 : 0;
|
||||
dropdown.draw(mx, my);
|
||||
|
||||
if (openListBox) {
|
||||
final int scrollbarWidth = listbox.hasScrollbar() ? listbox.scrollbarDim().width : 0;
|
||||
|
||||
listbox.setSize(
|
||||
x,
|
||||
y + h + 1,
|
||||
w,
|
||||
Math.min(((LayoutManager.searchField.y - h - y) / 18) * 18, listbox.contentHeight())
|
||||
);
|
||||
x,
|
||||
y + h + 1,
|
||||
w,
|
||||
Math.min(((LayoutManager.searchField.y - h - y) / 18) * 18, listbox.contentHeight()));
|
||||
|
||||
listbox.setMargins(0, 0, scrollbarWidth, 0);
|
||||
listbox.draw(mx, my, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int px, int py)
|
||||
{
|
||||
public boolean contains(int px, int py) {
|
||||
return super.contains(px, py) || openListBox && listbox.contains(px, py);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleClick(int mx, int my, int button)
|
||||
{
|
||||
public boolean handleClick(int mx, int my, int button) {
|
||||
|
||||
if (openListBox && listbox.contains(mx, my)) {
|
||||
listbox.mouseClicked(mx, my, button);
|
||||
@@ -805,7 +741,7 @@ public class PresetsWidget extends Widget
|
||||
selectedState.handleClick(mx, my, button);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (selectedDisplayName.contains(mx, my)) {
|
||||
selectedDisplayName.handleClick(mx, my, button);
|
||||
return true;
|
||||
@@ -822,27 +758,24 @@ public class PresetsWidget extends Widget
|
||||
|
||||
if (button == 0 && selectedValue.contains(mx, my)) {
|
||||
|
||||
if (System.currentTimeMillis() - lastclicktime < 400) { //double click
|
||||
if (System.currentTimeMillis() - lastclicktime < 400) { // double click
|
||||
final List<PresetTag> selected = listbox.getSelected();
|
||||
final int size = selected.size();
|
||||
|
||||
if (size <= 1) {
|
||||
setEditedTag(size == 1? selected.get(0).copy(): new PresetTag(""));
|
||||
setEditedTag(size == 1 ? selected.get(0).copy() : new PresetTag(""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lastclicktime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return contains(mx, my);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleClickExt(int mx, int my, int button)
|
||||
{
|
||||
public boolean handleClickExt(int mx, int my, int button) {
|
||||
|
||||
if (edit != null && mouseSelection == null) {
|
||||
ItemPanelSlot slot = ItemPanels.itemPanel.getSlotMouseOver(mx, my);
|
||||
@@ -851,15 +784,13 @@ public class PresetsWidget extends Widget
|
||||
mouseSelection = new MouseSelection(slot.slotIndex, button == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleKeyPress(int keyID, char keyChar)
|
||||
{
|
||||
public boolean handleKeyPress(int keyID, char keyChar) {
|
||||
if (keyID == Keyboard.KEY_ESCAPE) {
|
||||
openListBox = false;
|
||||
}
|
||||
@@ -868,7 +799,9 @@ public class PresetsWidget extends Widget
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selectedDisplayName.focused() && (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_NUMPADENTER) && !selectedDisplayName.text().isEmpty()) {
|
||||
if (selectedDisplayName.focused()
|
||||
&& (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_NUMPADENTER)
|
||||
&& !selectedDisplayName.text().isEmpty()) {
|
||||
selectedDisplayName.handleKeyPress(keyID, keyChar);
|
||||
selectedDisplayName.setFocus(false);
|
||||
listbox.replaceSeleted(edit);
|
||||
@@ -885,8 +818,7 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mx, int my, int button, long heldTime)
|
||||
{
|
||||
public void mouseDragged(int mx, int my, int button, long heldTime) {
|
||||
|
||||
if (openListBox) {
|
||||
listbox.mouseDragged(mx, my, button, heldTime);
|
||||
@@ -902,32 +834,26 @@ public class PresetsWidget extends Widget
|
||||
|
||||
final Rectangle4i rec = grid.getSlotRect(slot.slotIndex - (grid.getPage() - 1) * grid.getPerPage());
|
||||
final Rectangle4i sel = new Rectangle4i(
|
||||
Math.min(rec.x, mouseSelection.startX),
|
||||
Math.min(rec.y, mouseSelection.startY),
|
||||
Math.max(rec.x, mouseSelection.startX) - Math.min(rec.x, mouseSelection.startX),
|
||||
Math.max(rec.y, mouseSelection.startY) - Math.min(rec.y, mouseSelection.startY)
|
||||
);
|
||||
Math.min(rec.x, mouseSelection.startX),
|
||||
Math.min(rec.y, mouseSelection.startY),
|
||||
Math.max(rec.x, mouseSelection.startX) - Math.min(rec.x, mouseSelection.startX),
|
||||
Math.max(rec.y, mouseSelection.startY) - Math.min(rec.y, mouseSelection.startY));
|
||||
|
||||
for (int x = sel.x; x <= sel.x + sel.w; x += ItemsGrid.SLOT_SIZE) {
|
||||
for (int y = sel.y; y <= sel.y + sel.h; y += ItemsGrid.SLOT_SIZE) {
|
||||
ItemStack stack = ItemPanels.itemPanel.getStackMouseOver(x, y);
|
||||
|
||||
|
||||
if (stack != null) {
|
||||
mouseSelection.items.add(stack);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int mx, int my, int button)
|
||||
{
|
||||
public void mouseUp(int mx, int my, int button) {
|
||||
|
||||
if (openListBox) {
|
||||
listbox.mouseMovedOrUp(mx, my, button);
|
||||
@@ -943,17 +869,14 @@ public class PresetsWidget extends Widget
|
||||
for (ItemStack stack : mouseSelection.items) {
|
||||
hideItem(stack, mouseSelection.append);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
mouseSelection = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMouseWheel(int i, int mx, int my)
|
||||
{
|
||||
public boolean onMouseWheel(int i, int mx, int my) {
|
||||
|
||||
if (openListBox && listbox.hasScrollbar() && listbox.contains(mx, my)) {
|
||||
listbox.scroll(-i);
|
||||
@@ -964,8 +887,7 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClick(int mx, int my)
|
||||
{
|
||||
public void onGuiClick(int mx, int my) {
|
||||
|
||||
if (!contains(mx, my)) {
|
||||
openListBox = false;
|
||||
@@ -975,15 +897,14 @@ public class PresetsWidget extends Widget
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip)
|
||||
{
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
||||
|
||||
if (edit != null) {
|
||||
|
||||
if (selectedState.contains(mx, my)) {
|
||||
return selectedState.handleTooltip(mx, my, tooltip);
|
||||
}
|
||||
|
||||
|
||||
if (selectedDisplayName.contains(mx, my)) {
|
||||
return selectedDisplayName.handleTooltip(mx, my, tooltip);
|
||||
}
|
||||
@@ -993,14 +914,12 @@ public class PresetsWidget extends Widget
|
||||
if (selectedValue.contains(mx, my)) {
|
||||
return selectedValue.handleTooltip(mx, my, tooltip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public static boolean matches(ItemStack stack)
|
||||
{
|
||||
public static boolean matches(ItemStack stack) {
|
||||
|
||||
if (edit != null) {
|
||||
return true;
|
||||
@@ -1016,5 +935,4 @@ public class PresetsWidget extends Widget
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user