Auto-max resources on launch

This commit is contained in:
Anuken 2022-04-06 20:17:17 -04:00
parent 7268ac98f8
commit 14558975cb
3 changed files with 30 additions and 5 deletions

View File

@ -570,6 +570,7 @@ configure = Configure Loadout
loadout = Loadout
resources = Resources
resources.max = Max
bannedblocks = Banned Blocks
bannedunits = Banned Units
addall = Add All
@ -616,7 +617,7 @@ sectors.rename = Rename Sector
sectors.enemybase = [scarlet]Enemy Base
sectors.vulnerable = [scarlet]Vulnerable
sectors.underattack = [scarlet]Under attack! [accent]{0}% damaged
sectors.underattack.nodamage = [scarlet]Under attack!
sectors.underattack.nodamage = [scarlet]Enemy Present
sectors.survives = [accent]Survives {0} waves
sectors.go = Go
sector.curcapture = Sector Captured

View File

@ -2,6 +2,7 @@ package mindustry.ui.dialogs;
import arc.*;
import arc.func.*;
import arc.math.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
@ -66,6 +67,15 @@ public class LaunchLoadoutDialog extends BaseDialog{
ItemSeq schems = selected.requirements();
ItemSeq launches = universe.getLaunchResources();
int capacity = lastCapacity;
if(getMax()){
for(Item item : content.items()){
launches.set(item, Mathf.clamp(sitems.get(item) - launches.get(item), 0, capacity));
}
universe.updateLaunchResources(launches);
}
for(ItemStack s : total){
table.image(s.item.uiIcon).left().size(iconSmall);
@ -87,7 +97,13 @@ public class LaunchLoadoutDialog extends BaseDialog{
Runnable rebuildItems = () -> rebuild.get(items);
buttons.button("@resources", Icon.terrain, () -> {
buttons.button("@resources.max", Icon.add, Styles.togglet, () -> {
setMax(!getMax());
update.run();
rebuildItems.run();
}).checked(b -> getMax());
buttons.button("@resources", Icon.edit, () -> {
ItemSeq stacks = universe.getLaunchResources();
Seq<ItemStack> out = stacks.toSeq();
@ -99,7 +115,7 @@ public class LaunchLoadoutDialog extends BaseDialog{
update.run();
rebuildItems.run();
});
}).width(204);
}).disabled(b -> getMax());
boolean rows = Core.graphics.isPortrait() && mobile;
@ -112,7 +128,7 @@ public class LaunchLoadoutDialog extends BaseDialog{
}).disabled(b -> !valid);
if(rows){
cell.colspan(2).size(160f + 204f + 4f, 64f);
cell.colspan(2).size(160f + 160f + 4f, 64f);
}
int cols = Math.max((int)(Core.graphics.getWidth() / Scl.scl(230)), 1);
@ -169,4 +185,12 @@ public class LaunchLoadoutDialog extends BaseDialog{
show();
}
void setMax(boolean max){
Core.settings.put("maxresources", max);
}
boolean getMax(){
return Core.settings.getBool("maxresources", true);
}
}

View File

@ -328,7 +328,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
//preset sectors can only be selected once unlocked
if(sector.preset != null){
TechNode node = sector.preset.techNode;
return node == null || node.parent == null || node.parent.content.unlocked();
return node == null || node.parent == null || (node.parent.content.unlocked() && (!(node.parent.content instanceof SectorPreset preset) || preset.sector.hasBase()));
}
return sector.planet.generator != null ?