From 13fbcb9ba8f2b23d6cc68faac32fc44f511a0319 Mon Sep 17 00:00:00 2001 From: genNAowl <68400583+genNAowl@users.noreply.github.com> Date: Thu, 7 Jan 2021 10:38:31 -0800 Subject: [PATCH] Launch UI Max Button (#4238) * max * Add @Nullable Co-authored-by: Leonwang4234 <62972692+Leonwang4234@users.noreply.github.com> --- core/assets/bundles/bundle.properties | 1 + .../mindustry/ui/dialogs/LaunchLoadoutDialog.java | 5 ++++- core/src/mindustry/ui/dialogs/LoadoutDialog.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 2bd0b64eaf..db940ba4a2 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -287,6 +287,7 @@ cancel = Cancel openlink = Open Link copylink = Copy Link back = Back +max = Max crash.export = Export Crash Logs crash.none = No crash logs found. crash.exported = Crash logs exported. diff --git a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java index c8ea27ae97..77ae944639 100644 --- a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java +++ b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java @@ -86,7 +86,10 @@ public class LaunchLoadoutDialog extends BaseDialog{ ItemSeq stacks = universe.getLaunchResources(); Seq out = stacks.toSeq(); - loadout.show(selected.findCore().itemCapacity, out, UnlockableContent::unlocked, out::clear, () -> {}, () -> { + ItemSeq realItems = sitems.copy(); + selected.requirements().each(realItems::remove); + + loadout.show(selected.findCore().itemCapacity, realItems, out, UnlockableContent::unlocked, out::clear, () -> {}, () -> { universe.updateLaunchResources(new ItemSeq(out)); update.run(); rebuildItems.run(); diff --git a/core/src/mindustry/ui/dialogs/LoadoutDialog.java b/core/src/mindustry/ui/dialogs/LoadoutDialog.java index d818f5ecda..24e3b2d8f4 100644 --- a/core/src/mindustry/ui/dialogs/LoadoutDialog.java +++ b/core/src/mindustry/ui/dialogs/LoadoutDialog.java @@ -22,6 +22,7 @@ public class LoadoutDialog extends BaseDialog{ private Boolf 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 stacks, Boolf validator, Runnable reseter, Runnable updater, Runnable hider){ + show(capacity, null, stacks, validator, reseter, updater, hider); + } + + public void show(int capacity, ItemSeq total, Seq stacks, Boolf 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();