Skip to content

Commit

Permalink
#1 Add max height config for inventory tooltip
Browse files Browse the repository at this point in the history
changed row size to max width because english
  • Loading branch information
deirn committed Sep 15, 2020
1 parent aab7fcc commit e20630f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ yarn = 1.16.2+build.46
loader = 0.9.3+build.207

# Mod Properties
mod = 1.0+1.16
mod = 1.0.1+1.16
group = com.github.badasintended
archiveBaseName = megane

Expand Down
19 changes: 14 additions & 5 deletions src/main/java/badasintended/megane/config/MeganeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ public class MeganeConfig {

public static class Inventory {
private boolean enabled = true;
private int rowSize = 9;
private int maxWidth = 9;
private int maxHeight = 3;
private Set<Identifier> blacklist = new HashSet<>();

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public void setRowSize(int rowSize) {
this.rowSize = rowSize;
public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}

public void setBlacklist(Set<Identifier> blacklist) {
Expand All @@ -37,8 +42,12 @@ public boolean isEnabled() {
return enabled;
}

public int getRowSize() {
return rowSize;
public int getMaxWidth() {
return maxWidth;
}

public int getMaxHeight() {
return maxHeight;
}

public Set<Identifier> getBlacklist() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public OptionsListWidget getOptions() {
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(toggleBool("enabled", config().inventory.isEnabled(), config().inventory::setEnabled));
options.add(input("inventory.rowSize", config().inventory.getRowSize(), config().inventory::setRowSize, s -> s.matches("^[0-9]*$")));
options.add(input("inventory.maxWidth", config().inventory.getMaxWidth(), config().inventory::setMaxWidth, s -> s.matches("^[0-9]*$")));
options.add(input("inventory.maxHeight", config().inventory.getMaxHeight(), config().inventory::setMaxHeight, s -> s.matches("^[0-9]*$")));
options.add(button("blacklist", w -> client.openScreen(new BlacklistConfigScreen(this, tl(tlKey("inventory.blacklist")), config().inventory.getBlacklist()))));
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ public class InventoryRenderer implements ITooltipRenderer {
private DefaultedList<ItemStack> stacks = DefaultedList.ofSize(0, ItemStack.EMPTY);
private final Set<Item> items = new LinkedHashSet<>();

private int w;
private int h;

@Override
public Dimension getSize(CompoundTag data, ICommonAccessor accessor) {
int row = config().inventory.getRowSize();
w = config().inventory.getMaxWidth();
h = config().inventory.getMaxHeight();
int size = data.getInt(key("invSize"));

stacks = DefaultedList.ofSize(size, ItemStack.EMPTY);
Expand All @@ -38,12 +42,11 @@ public Dimension getSize(CompoundTag data, ICommonAccessor accessor) {
});

if (items.size() == 0) return ZERO;
return new Dimension(18 * Math.min(items.size(), row), 18 * (items.size() / row + 1) + 2);
return new Dimension(18 * Math.min(items.size(), w), 18 * Math.min(items.size() / w + 1, h) + 2);
}

@Override
public void draw(MatrixStack matrices, CompoundTag data, ICommonAccessor accessor, int x, int y) {
int row = config().inventory.getRowSize();
List<ItemStack> combinedStacks = new ArrayList<>();
items.forEach(item -> {
int count = stacks.stream().filter(stack -> stack.getItem() == item).mapToInt(ItemStack::getCount).sum();
Expand All @@ -52,8 +55,8 @@ public void draw(MatrixStack matrices, CompoundTag data, ICommonAccessor accesso

combinedStacks.sort(Comparator.comparing(ItemStack::getCount, Comparator.reverseOrder()));

for (int i = 0; i < combinedStacks.size(); i++) {
drawStack(combinedStacks.get(i), x + (18 * (i % row)) + 1, y + (18 * (i / row)) + 1);
for (int i = 0; i < Math.min(combinedStacks.size(), config().inventory.getMaxHeight() * w); i++) {
drawStack(combinedStacks.get(i), x + (18 * (i % w)) + 1, y + (18 * (i / w)) + 1);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/megane/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"config.waila.megane.add" : "Add New",
"config.waila.megane.blacklist" : "Blacklist",
"config.waila.megane.inventory" : "Inventory",
"config.waila.megane.inventory.rowSize" : "Row Size",
"config.waila.megane.inventory.maxWidth" : "Max Width",
"config.waila.megane.inventory.maxHeight": "Max Height",
"config.waila.megane.inventory.blacklist": "Inventory Blacklist",
"config.waila.megane.energy" : "Energy",
"config.waila.megane.energy.color" : "Bar Colors",
Expand Down

0 comments on commit e20630f

Please sign in to comment.