2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.config;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class OptionCycled extends OptionButton {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public final int count;
|
|
|
|
|
public final boolean prefixed;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public OptionCycled(String name, int count, boolean prefixed) {
|
2014-04-29 10:54:20 +10:00
|
|
|
super(name);
|
|
|
|
|
this.count = count;
|
|
|
|
|
this.prefixed = prefixed;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public OptionCycled(String name, int count) {
|
2014-04-29 10:54:20 +10:00
|
|
|
this(name, count, false);
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int value() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return renderTag().getIntValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public String getButtonText() {
|
|
|
|
|
return translateN(name + "." + value());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public String getPrefix() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return prefixed ? translateN(name) : null;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2024-12-23 12:21:28 +02:00
|
|
|
@Override
|
|
|
|
|
public String getTooltip() {
|
|
|
|
|
String tooltip = name + "." + value() + ".tip";
|
|
|
|
|
String s = translateN(tooltip);
|
|
|
|
|
|
|
|
|
|
if (!s.equals(namespaced(tooltip))) {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.getTooltip();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean onClick(int button) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return cycle();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public boolean cycle() {
|
2014-04-29 10:54:20 +10:00
|
|
|
int next = value();
|
2022-06-24 12:32:13 +01:00
|
|
|
do next = (next + 1) % count; while (!optionValid(next));
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (next == value()) return false;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
getTag().setIntValue(next);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public boolean optionValid(int index) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|