1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package org.chrisoft.trashyaddon.modules;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.WindowScreen;
import meteordevelopment.meteorclient.gui.screens.settings.ItemSettingScreen;
import meteordevelopment.meteorclient.gui.widgets.WItemWithLabel;
import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
import meteordevelopment.meteorclient.gui.widgets.input.WIntEdit;
import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus;
import meteordevelopment.meteorclient.settings.ItemSetting;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import java.util.ArrayList;
public class AcceptablePricesScreen extends WindowScreen {
private final AcceptablePrices targetValue;
private WTable table;
private ArrayList<Item> rowItems;
public AcceptablePricesScreen(GuiTheme theme, AcceptablePrices prices) {
super(theme, "Configure max prices for each trade");
targetValue = prices;
rowItems = new ArrayList<>();
}
@Override
public void initWidgets() {
this.add(theme.label("The amount set here corresponds to the max number of items in the first input slot."));
table = this.add(theme.table()).expandX().widget();
initTable();
WHorizontalList hl = theme.horizontalList();
hl.add(theme.label("")).expandCellX();
hl.add(theme.plus()).widget().action = () -> {
ItemSetting t = new ItemSetting("", "", Items.AIR, null, null, null,
(Item item) -> AcceptablePrices.allItems.contains(item) && (targetValue.getMaxPriceForItem(item) == null));
ItemSettingScreen screen = new ItemSettingScreen(this.theme, t);
screen.onClosed(() -> {
Item item = t.get();
if (item != null && item != Items.AIR)
addRowForItem(item);
});
MinecraftClient.getInstance().setScreen(screen);
};
this.add(hl).expandX();
}
private void initTable() {
for (Item i : targetValue.allConfiguredItems()) {
addRowForItem(i);
}
}
private void addRowForItem(Item item) {
rowItems.add(item);
WItemWithLabel itemDisplay = theme.itemWithLabel(item.getDefaultStack(), item.getName().getString());
table.add(itemDisplay).expandCellX();
Integer v = targetValue.getMaxPriceForItem(item);
if (v == null) {
targetValue.setMaxPriceForItem(item, 1);
v = 1;
}
WIntEdit priceEdit = theme.intEdit(v, 1, 64, true);
priceEdit.action = () -> {
targetValue.setMaxPriceForItem(item, priceEdit.get());
};
table.add(priceEdit);
WMinus deleteButton = theme.minus();
deleteButton.action = () -> {
table.removeRow(rowItems.indexOf(item));
this.invalidate();
rowItems.remove(item);
targetValue.unsetMaxPriceForItem(item);
};
table.add(deleteButton);
table.row();
}
}
|