Launch UI Max Button (#4238)

* max

* Add @Nullable

Co-authored-by: Leonwang4234 <62972692+Leonwang4234@users.noreply.github.com>
This commit is contained in:
genNAowl
2021-01-07 10:38:31 -08:00
committed by GitHub
parent 9774095df4
commit 13fbcb9ba8
3 changed files with 19 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ public class LoadoutDialog extends BaseDialog{
private Boolf<Item> validator = i -> true;
private Table items;
private int capacity;
private @Nullable ItemSeq total;
public LoadoutDialog(){
super("@configure");
@@ -46,6 +47,8 @@ public class LoadoutDialog extends BaseDialog{
buttons.button("@back", Icon.left, this::hide).size(210f, 64f);
buttons.button("@max", Icon.export, this::maxItems).size(210f, 64f);
buttons.button("@settings.reset", Icon.refresh, () -> {
resetter.run();
reseed();
@@ -54,12 +57,23 @@ public class LoadoutDialog extends BaseDialog{
}).size(210f, 64f);
}
public void maxItems() {
for(ItemStack stack : stacks){
stack.amount = total == null ? capacity : Math.min(capacity, total.get(stack.item));
}
}
public void show(int capacity, Seq<ItemStack> stacks, Boolf<Item> validator, Runnable reseter, Runnable updater, Runnable hider){
show(capacity, null, stacks, validator, reseter, updater, hider);
}
public void show(int capacity, ItemSeq total, Seq<ItemStack> stacks, Boolf<Item> validator, Runnable reseter, Runnable updater, Runnable hider){
this.originalStacks = stacks;
this.validator = validator;
this.resetter = reseter;
this.updater = updater;
this.capacity = capacity;
this.total = total;
this.hider = hider;
reseed();
show();