2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.config;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import static codechicken.lib.gui.GuiDraw.drawString;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.LayoutManager;
|
|
|
|
|
import com.google.common.collect.ArrayListMultimap;
|
|
|
|
|
import com.google.common.collect.Multimap;
|
2019-12-24 13:37:41 -08:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public abstract class OptionStringSet extends Option {
|
2019-12-30 20:19:16 -08:00
|
|
|
public final LinkedList<String> options = new LinkedList<>();
|
|
|
|
|
public final Multimap<String, String> dependants = ArrayListMultimap.create();
|
|
|
|
|
public final Map<String, String> dependancies = new HashMap<>();
|
|
|
|
|
public final Multimap<String, String> groups = ArrayListMultimap.create();
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public OptionStringSet(String name) {
|
2014-04-29 10:54:20 +10:00
|
|
|
super(name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void addDep(String base, String dep) {
|
2014-04-29 10:54:20 +10:00
|
|
|
dependants.put(dep, base);
|
|
|
|
|
dependancies.put(base, dep);
|
|
|
|
|
}
|
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 void draw(int mousex, int mousey, float frame) {
|
2014-04-29 10:54:20 +10:00
|
|
|
drawPrefix();
|
|
|
|
|
drawButtons();
|
|
|
|
|
drawIcons();
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public void drawPrefix() {
|
|
|
|
|
drawString(translateN(name), 10, 6, -1);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void drawButtons() {
|
2014-04-29 10:54:20 +10:00
|
|
|
int x = buttonX();
|
|
|
|
|
List<String> values = values();
|
2014-06-29 20:31:37 +10:00
|
|
|
for (String option : options) {
|
|
|
|
|
LayoutManager.drawButtonBackground(x, 0, 20, 20, true, values.contains(option) ? 1 : 0);
|
|
|
|
|
x += 24;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void drawIcons();
|
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 List<String> handleTooltip(int mousex, int mousey, List<String> currenttip) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (new Rectangle4i(4, 4, 50, 20).contains(mousex, mousey)) currenttip.add(translateN(name + ".tip"));
|
2014-04-29 10:54:20 +10:00
|
|
|
int x = buttonX();
|
2014-06-29 20:31:37 +10:00
|
|
|
for (String option : options) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (new Rectangle4i(x, 0, 20, 20).contains(mousex, mousey)) currenttip.add(translateN(name + "." + option));
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
x += 24;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
return currenttip;
|
|
|
|
|
}
|
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 void mouseClicked(int x, int y, int button) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (clickButton(x, y, button)) playClickSound();
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public boolean clickButton(int mousex, int mousey, int button) {
|
2014-04-29 10:54:20 +10:00
|
|
|
int x = buttonX();
|
|
|
|
|
List<String> values = values();
|
2019-12-24 13:37:41 -08:00
|
|
|
for (String option : options) {
|
2014-06-29 20:31:37 +10:00
|
|
|
if (new Rectangle4i(x, 0, 20, 20).contains(mousex, mousey)) {
|
2019-12-30 20:19:16 -08:00
|
|
|
boolean set = values.contains(option);
|
2014-06-29 20:31:37 +10:00
|
|
|
if (button == 0 && !set) {
|
2019-12-30 20:19:16 -08:00
|
|
|
setValue(option);
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
if (button == 1 && set) {
|
2019-12-30 20:19:16 -08:00
|
|
|
remValue(option);
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
x += 24;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void setValue(String s) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (values().contains(s)) return;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
String dep = dependancies.get(s);
|
2022-06-24 12:32:13 +01:00
|
|
|
if (dep != null) setValue(dep);
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (groups.containsKey(s)) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (String grp : groups.get(s)) setValue(grp);
|
2014-06-29 20:31:37 +10:00
|
|
|
} else {
|
2019-12-30 20:19:16 -08:00
|
|
|
List<String> setUtils = new LinkedList<>(values());
|
2014-04-29 10:54:20 +10:00
|
|
|
setUtils.add(s);
|
|
|
|
|
setValues(setUtils);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void remValue(String s) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (String dep : dependants.get(s)) remValue(dep);
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
if (groups.containsKey(s)) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (String grp : groups.get(s)) remValue(grp);
|
2014-06-29 20:31:37 +10:00
|
|
|
} else {
|
2019-12-30 20:19:16 -08:00
|
|
|
List<String> values = new LinkedList<>(values());
|
2014-04-29 10:54:20 +10:00
|
|
|
values.remove(s);
|
|
|
|
|
setValues(values);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public void setValues(List<String> values) {
|
2014-04-29 10:54:20 +10:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2014-06-29 20:31:37 +10:00
|
|
|
for (String s : values) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (sb.length() > 0) sb.append(", ");
|
2014-04-29 10:54:20 +10:00
|
|
|
sb.append(s);
|
|
|
|
|
}
|
|
|
|
|
getTag().setValue(sb.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public List<String> values() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return Arrays.asList(renderTag().getValue().replace(" ", "").split(","));
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int buttonX() {
|
|
|
|
|
return slot.slotWidth() - (24 * options.size() - 4);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|