Skip to content

Commit

Permalink
Merge branch 'master' into feat/blood_magic_compat
Browse files Browse the repository at this point in the history
# Conflicts:
#	dependencies.gradle
  • Loading branch information
Dream-Master committed Sep 1, 2024
2 parents 252df34 + 71ea2ea commit ffa4aa7
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/main/java/appeng/api/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public enum Settings {

PRIORITY_CARD_MODE(EnumSet.allOf(PriorityCardMode.class)),

TERMINAL_FONT_SIZE(EnumSet.allOf(TerminalFontSize.class));
TERMINAL_FONT_SIZE(EnumSet.allOf(TerminalFontSize.class)),

INTERFACE_TERMINAL_SECTION_ORDER(EnumSet.allOf(StringOrder.class));

private final EnumSet<? extends Enum<?>> values;

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/appeng/api/config/StringOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package appeng.api.config;

import java.util.Comparator;

import appeng.util.AlphanumComparator;

public enum StringOrder {

NATURAL(Comparator.naturalOrder()),

ALPHANUM(AlphanumComparator.INSTANCE);

public final Comparator<String> comparator;

StringOrder(Comparator<String> comparator) {
this.comparator = comparator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
Expand Down Expand Up @@ -44,6 +45,7 @@
import appeng.api.AEApi;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.api.config.StringOrder;
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
import appeng.api.util.DimensionalCoord;
Expand Down Expand Up @@ -105,7 +107,9 @@ public class GuiInterfaceTerminal extends AEBaseGui
AppEng.MOD_ID,
"textures/guis/newinterfaceterminal.png");

private final InterfaceTerminalList masterList = new InterfaceTerminalList();
private final InterfaceTerminalList masterList = new InterfaceTerminalList(
((StringOrder) AEConfig.instance.settings
.getSetting(Settings.INTERFACE_TERMINAL_SECTION_ORDER)).comparator);
private final MEGuiTextField searchFieldOutputs;
private final MEGuiTextField searchFieldInputs;
private final MEGuiTextField searchFieldNames;
Expand All @@ -114,6 +118,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
private final GuiImgButton guiButtonBrokenRecipes;
private final GuiImgButton terminalStyleBox;
private final GuiImgButton searchStringSave;
private final GuiImgButton guiButtonSectionOrder;
private boolean onlyMolecularAssemblers = false;
private boolean onlyBrokenRecipes = false;
private boolean online;
Expand Down Expand Up @@ -179,6 +184,7 @@ public void onTextChange(final String oldText) {
guiButtonAssemblersOnly = new GuiImgButton(0, 0, Settings.ACTIONS, null);
guiButtonHideFull = new GuiImgButton(0, 0, Settings.ACTIONS, null);
guiButtonBrokenRecipes = new GuiImgButton(0, 0, Settings.ACTIONS, null);
guiButtonSectionOrder = new GuiImgButton(0, 0, Settings.INTERFACE_TERMINAL_SECTION_ORDER, StringOrder.NATURAL);

terminalStyleBox = new GuiImgButton(0, 0, Settings.TERMINAL_STYLE, null);

Expand Down Expand Up @@ -224,8 +230,11 @@ public void initGui() {
searchStringSave.xPosition = guiLeft - 18;
searchStringSave.yPosition = terminalStyleBox.yPosition + 18;

guiButtonSectionOrder.xPosition = guiLeft - 18;
guiButtonSectionOrder.yPosition = searchStringSave.yPosition + 18;

guiButtonBrokenRecipes.xPosition = guiLeft - 18;
guiButtonBrokenRecipes.yPosition = searchStringSave.yPosition + 18;
guiButtonBrokenRecipes.yPosition = guiButtonSectionOrder.yPosition + 18;

guiButtonHideFull.xPosition = guiLeft - 18;
guiButtonHideFull.yPosition = guiButtonBrokenRecipes.yPosition + 18;
Expand All @@ -243,6 +252,7 @@ public void initGui() {
buttonList.add(guiButtonAssemblersOnly);
buttonList.add(guiButtonHideFull);
buttonList.add(guiButtonBrokenRecipes);
buttonList.add(guiButtonSectionOrder);
buttonList.add(searchStringSave);
buttonList.add(terminalStyleBox);
}
Expand Down Expand Up @@ -293,6 +303,7 @@ public void drawScreen(final int mouseX, final int mouseY, final float btn) {
guiButtonBrokenRecipes.set(
onlyBrokenRecipes ? ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERN_OFF
: ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERN_ON);
guiButtonSectionOrder.set(AEConfig.instance.settings.getSetting(Settings.INTERFACE_TERMINAL_SECTION_ORDER));

terminalStyleBox.set(AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE));

Expand Down Expand Up @@ -337,6 +348,10 @@ protected void actionPerformed(final GuiButton btn) {
initGui();
} else if (btn == searchStringSave) {
AEConfig.instance.preserveSearchBar = next == YesNo.YES;
} else if (btn == guiButtonSectionOrder) {
AEConfig.instance.settings.putSetting(iBtn.getSetting(), next);
masterList.changeSectionComparator(((StringOrder) next).comparator);
masterList.markDirty();
}

iBtn.set(next);
Expand Down Expand Up @@ -962,16 +977,26 @@ public void setTextFieldValue(final String displayName, final int mousex, final
private class InterfaceTerminalList {

private final Map<Long, InterfaceTerminalEntry> list = new HashMap<>();
private final Map<String, InterfaceSection> sections = new TreeMap<>();
private Map<String, InterfaceSection> sections;
private final List<InterfaceSection> visibleSections = new ArrayList<>();
private boolean isDirty;
private int height;
private InterfaceTerminalEntry hoveredEntry;

InterfaceTerminalList() {
InterfaceTerminalList(Comparator<String> comparator) {
this.sections = comparator == null ? new TreeMap<>() : new TreeMap<>(comparator);
this.isDirty = true;
}

void changeSectionComparator(Comparator<String> comparator) {
if ((this.sections instanceof TreeMap t) && !Objects.equals(comparator, t.comparator())) {
TreeMap<String, InterfaceSection> map = comparator == null ? new TreeMap<>()
: new TreeMap<>(comparator);
map.putAll(this.sections);
this.sections = map;
}
}

/**
* Performs a full update.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.StorageFilter;
import appeng.api.config.StringOrder;
import appeng.api.config.TerminalStyle;
import appeng.api.config.TypeFilter;
import appeng.api.config.ViewItems;
Expand Down Expand Up @@ -769,6 +770,19 @@ public GuiImgButton(final int x, final int y, final Enum idx, final Enum val) {
ButtonToolTips.PriorityCardMode,
ButtonToolTips.PriorityCardMode_Dec);

this.registerApp(
64,
Settings.INTERFACE_TERMINAL_SECTION_ORDER,
StringOrder.NATURAL,
ButtonToolTips.StringOrder,
ButtonToolTips.StringOrderNatural);
this.registerApp(
16,
Settings.INTERFACE_TERMINAL_SECTION_ORDER,
StringOrder.ALPHANUM,
ButtonToolTips.StringOrder,
ButtonToolTips.StringOrderAlphanum);

}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import appeng.api.config.SearchBoxMode;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.StringOrder;
import appeng.api.config.TerminalFontSize;
import appeng.api.config.TerminalStyle;
import appeng.api.config.YesNo;
Expand Down Expand Up @@ -158,6 +159,7 @@ public AEConfig(final File configFile) {
this.settings.registerSetting(Settings.CRAFTING_SORT_BY, CraftingSortOrder.NAME);
this.settings.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.settings.registerSetting(Settings.TERMINAL_FONT_SIZE, TerminalFontSize.SMALL);
this.settings.registerSetting(Settings.INTERFACE_TERMINAL_SECTION_ORDER, StringOrder.NATURAL);

this.spawnChargedChance = (float) (1.0
- this.get("worldGen", "spawnChargedChance", 1.0 - this.spawnChargedChance)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/appeng/core/localization/ButtonToolTips.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ public enum ButtonToolTips {
PriorityCardMode_Inc,
PriorityCardMode_Dec,
ToFollow,
ToUnfollow;
ToUnfollow,

StringOrder,
StringOrderNatural,
StringOrderAlphanum;

private final String root;

Expand Down
109 changes: 109 additions & 0 deletions src/main/java/appeng/util/AlphanumComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package appeng.util;
// This code is copied from the library https://github.com/metamx/alphanum
// spotless:off
/*
* The Alphanum Algorithm is an improved sorting algorithm for strings
* containing numbers. Instead of sorting numbers in ASCII order like
* a standard sort, this algorithm sorts numbers in numeric order.
*
* The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
// spotless:on

import java.util.Comparator;

/**
* This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle
*/
public class AlphanumComparator implements Comparator<String> {

public final static AlphanumComparator INSTANCE = new AlphanumComparator();

private final boolean isDigit(char ch) {
return ch >= 48 && ch <= 57;
}

/**
* Length of string is passed in for improved efficiency (only need to calculate it once) *
*/
private final String getChunk(String s, int slength, int marker) {
StringBuilder chunk = new StringBuilder();
char c = s.charAt(marker);
chunk.append(c);
marker++;
if (isDigit(c)) {
while (marker < slength) {
c = s.charAt(marker);
if (!isDigit(c)) break;
chunk.append(c);
marker++;
}
} else {
while (marker < slength) {
c = s.charAt(marker);
if (isDigit(c)) break;
chunk.append(c);
marker++;
}
}
return chunk.toString();
}

public int compare(String s1, String s2) {
if (s1 == null || s2 == null) {
return 0;
}

int thisMarker = 0;
int thatMarker = 0;
int s1Length = s1.length();
int s2Length = s2.length();

while (thisMarker < s1Length && thatMarker < s2Length) {
String thisChunk = getChunk(s1, s1Length, thisMarker);
thisMarker += thisChunk.length();

String thatChunk = getChunk(s2, s2Length, thatMarker);
thatMarker += thatChunk.length();

// If both chunks contain numeric characters, sort them numerically
int result = 0;
if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) {
// Simple chunk comparison by length.
int thisChunkLength = thisChunk.length();
result = thisChunkLength - thatChunk.length();
// If equal, the first different number counts
if (result == 0) {
for (int i = 0; i < thisChunkLength; i++) {
result = thisChunk.charAt(i) - thatChunk.charAt(i);
if (result != 0) {
return result;
}
}
}
} else {
result = thisChunk.compareTo(thatChunk);
}

if (result != 0) return result;
}

return s1Length - s2Length;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ gui.tooltips.appliedenergistics2.MultiplyOrDividePatternHint=If it's positive, i
gui.tooltips.appliedenergistics2.ToFollow=Click to follow this craft and receive message when it is complete\nYou are not following this crafting job right now
gui.tooltips.appliedenergistics2.ToUnfollow=Click to stop following this craft\nYou are following this crafting job and will receive chat message when it's complete

gui.tooltips.appliedenergistics2.StringOrder=Sorting
gui.tooltips.appliedenergistics2.StringOrderNatural=Default
gui.tooltips.appliedenergistics2.StringOrderAlphanum=Natural Order

# Units
gui.appliedenergistics2.units.appliedenergstics=AE
gui.appliedenergistics2.units.ic2=Energy Units
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ gui.tooltips.appliedenergistics2.MultiplyOrDividePatternHint=如果是正数,就
gui.tooltips.appliedenergistics2.ToFollow=当前并未订阅该合成的消息\n当该合成完成时将不会接收到消息提示\n点击即可订阅
gui.tooltips.appliedenergistics2.ToUnfollow=当前已经订阅该合成的消息\n当该合成完成时将会接收到消息提示\n点击即可取消

gui.tooltips.appliedenergistics2.StringOrder=排序方式
gui.tooltips.appliedenergistics2.StringOrderNatural=默认排序
gui.tooltips.appliedenergistics2.StringOrderAlphanum=自然数序

# Units
gui.appliedenergistics2.units.appliedenergstics=AE
gui.appliedenergistics2.units.ic2=EU
Expand Down

0 comments on commit ffa4aa7

Please sign in to comment.