From b3f29f100d562ea9279f8d1b08c62152ea042310 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 28 Jun 2020 13:33:53 -0400 Subject: [PATCH] Custom launch items --- core/assets/bundles/bundle.properties | 5 +- core/src/mindustry/core/Control.java | 1 + core/src/mindustry/game/Schematics.java | 7 ++ core/src/mindustry/game/Universe.java | 12 +++ core/src/mindustry/graphics/CacheLayer.java | 1 - .../maps/generators/FileMapGenerator.java | 7 +- .../maps/planet/TODOPlanetGenerator.java | 2 +- core/src/mindustry/mod/ContentParser.java | 1 - .../ui/dialogs/CustomGameDialog.java | 1 - .../ui/dialogs/LaunchLoadoutDialog.java | 77 +++++++++++++------ .../mindustry/ui/dialogs/PlanetDialog.java | 1 - .../mindustry/world/modules/ItemModule.java | 6 ++ 12 files changed, 85 insertions(+), 36 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 3ea8a674a7..a6b9264f9a 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -471,13 +471,14 @@ launch.confirm = This will launch all resources in your core.\nYou will not be a launch.skip.confirm = If you skip now, you will not be able to launch until later waves. uncover = Uncover configure = Configure Loadout +#TODO +loadout = Loadout +resources = Resources bannedblocks = Banned Blocks addall = Add All -configure.locked = [lightgray]Unlock configuring loadout: {0}. configure.invalid = Amount must be a number between 0 and {0}. zone.unlocked = [lightgray]{0} unlocked. zone.requirement.complete = Requirement for {0} completed:[lightgray]\n{1} -zone.config.unlocked = Loadout unlocked:[lightgray]\n{0} zone.resources = [lightgray]Resources Detected: zone.objective = [lightgray]Objective: [accent]{0} zone.objective.survival = Survive diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index e1432fad55..3a237d74d9 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -251,6 +251,7 @@ public class Control implements ApplicationListener, Loadable{ //remove schematic requirements from core tile.items.remove(universe.getLastLoadout().requirements()); + tile.items.remove(universe.getLaunchResources()); } public void playSector(Sector sector){ diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index 400e01a3c7..5ddc9bb9da 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -399,6 +399,13 @@ public class Schematics implements Loadable{ } } + /** Places the last launch loadout at the coordinates and fills it with the launch resources. */ + public static void placeLaunchLoadout(int x, int y){ + placeLoadout(universe.getLastLoadout(), x, y); + if(world.tile(x, y).build == null) throw new RuntimeException("No core at loadout coordinates!"); + world.tile(x, y).build.items.add(universe.getLaunchResources()); + } + public static void placeLoadout(Schematic schem, int x, int y){ placeLoadout(schem, x, y, state.rules.defaultTeam, Blocks.oreCopper); } diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index 8a6c11b310..c5a1824542 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -20,7 +20,9 @@ public class Universe{ private float secondCounter; private int turn; private float turnCounter; + private Schematic lastLoadout = Loadouts.basicShard; + private Seq lastLaunchResources = new Seq<>(); public Universe(){ load(); @@ -75,6 +77,16 @@ public class Universe{ } } + public Seq getLaunchResources(){ + lastLaunchResources = Core.settings.getJson("launch-resources", Seq.class, ItemStack.class, Seq::new); + return lastLaunchResources; + } + + public void updateLaunchResources(Seq stacks){ + this.lastLaunchResources = stacks; + Core.settings.putJson("launch-resources", ItemStack.class, lastLaunchResources); + } + /** Updates selected loadout for future deployment. */ public void updateLoadout(CoreBlock block, Schematic schem){ Core.settings.put("lastloadout-" + block.name, schem.file == null ? "" : schem.file.nameWithoutExtension()); diff --git a/core/src/mindustry/graphics/CacheLayer.java b/core/src/mindustry/graphics/CacheLayer.java index 5807db7490..00bd578dc4 100644 --- a/core/src/mindustry/graphics/CacheLayer.java +++ b/core/src/mindustry/graphics/CacheLayer.java @@ -2,7 +2,6 @@ package mindustry.graphics; import arc.*; import arc.graphics.*; -import arc.graphics.g2d.*; import arc.graphics.gl.*; import static mindustry.Vars.renderer; diff --git a/core/src/mindustry/maps/generators/FileMapGenerator.java b/core/src/mindustry/maps/generators/FileMapGenerator.java index 395f8130e5..e0b8bf3946 100644 --- a/core/src/mindustry/maps/generators/FileMapGenerator.java +++ b/core/src/mindustry/maps/generators/FileMapGenerator.java @@ -54,14 +54,9 @@ public class FileMapGenerator implements WorldGenerator{ } if(tile.isCenter() && tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam && !anyCores){ - Schematics.placeLoadout(universe.getLastLoadout(), tile.x, tile.y); + Schematics.placeLaunchLoadout(tile.x, tile.y); anyCores = true; } - - //add random decoration - //if(Mathf.chance(0.015) && !tile.floor().isLiquid && tile.block() == Blocks.air){ - // tile.setBlock(tile.floor().decoration); - //} } if(!anyCores){ diff --git a/core/src/mindustry/maps/planet/TODOPlanetGenerator.java b/core/src/mindustry/maps/planet/TODOPlanetGenerator.java index f1b5c47f81..8f50cf3ff1 100644 --- a/core/src/mindustry/maps/planet/TODOPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/TODOPlanetGenerator.java @@ -279,7 +279,7 @@ public class TODOPlanetGenerator extends PlanetGenerator{ } }); - Schematics.placeLoadout(universe.getLastLoadout(), spawn.x, spawn.y); + Schematics.placeLaunchLoadout(spawn.x, spawn.y); if(sector.hasEnemyBase()){ basegen.generate(tiles, enemies.map(r -> tiles.getn(r.x, r.y)), tiles.get(spawn.x, spawn.y), state.rules.waveTeam, sector); diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index 000d3d6521..d093918062 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -7,7 +7,6 @@ import arc.files.*; import arc.func.*; import arc.graphics.*; import arc.mock.*; -import arc.struct.Seq; import arc.struct.*; import arc.util.ArcAnnotate.*; import arc.util.*; diff --git a/core/src/mindustry/ui/dialogs/CustomGameDialog.java b/core/src/mindustry/ui/dialogs/CustomGameDialog.java index 1d7aa2d07b..f3f4e6b029 100644 --- a/core/src/mindustry/ui/dialogs/CustomGameDialog.java +++ b/core/src/mindustry/ui/dialogs/CustomGameDialog.java @@ -2,7 +2,6 @@ package mindustry.ui.dialogs; import arc.*; import arc.graphics.g2d.*; -import arc.math.*; import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; diff --git a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java index 8a45169b77..3042aba33d 100644 --- a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java +++ b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java @@ -1,8 +1,10 @@ package mindustry.ui.dialogs; import arc.*; +import arc.func.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; +import arc.struct.*; import mindustry.game.*; import mindustry.gen.*; import mindustry.type.*; @@ -14,7 +16,14 @@ import static mindustry.Vars.*; /** Dialog for selecting loadout at sector launch. */ public class LaunchLoadoutDialog extends BaseDialog{ + LoadoutDialog loadout = new LoadoutDialog(); + //total as a map + ObjectIntMap totalMap = new ObjectIntMap<>(); + //total required items + Seq total = new Seq<>(); + //currently selected schematic Schematic selected; + //validity of loadout items boolean valid; public LaunchLoadoutDialog(){ @@ -24,8 +33,51 @@ public class LaunchLoadoutDialog extends BaseDialog{ public void show(CoreBlock core, Building build, Runnable confirm){ cont.clear(); buttons.clear(); + totalMap.clear(); + + Seq stacks = universe.getLaunchResources(); addCloseButton(); + + //updates sum requirements + Runnable update = () -> { + totalMap.clear(); + total.clear(); + selected.requirements().each(i -> totalMap.increment(i.item, i.amount)); + universe.getLaunchResources().each(i -> totalMap.increment(i.item, i.amount)); + for(Item item : content.items()){ + if(totalMap.containsKey(item)) total.add(new ItemStack(item, totalMap.get(item))); + } + valid = build.items.has(total); + }; + + Cons rebuild = table -> { + table.clearChildren(); + int i = 0; + + for(ItemStack s : total){ + table.image(s.item.icon(Cicon.small)).left(); + table.add((build.items.has(s.item, s.amount)) ? "[lightgray]" + s.amount + "" : + "[scarlet]" + (Math.min(build.items.get(s.item), s.amount) + "[lightgray]/" + s.amount)).padLeft(2).left().padRight(4); + + if(++i % 4 == 0){ + table.row(); + } + } + }; + + Table items = new Table(); + + Runnable rebuildItems = () -> rebuild.get(items); + + buttons.button("$resources", Icon.terrain, () -> { + loadout.show(core.itemCapacity, stacks, stacks::clear, () -> {}, () -> { + universe.updateLaunchResources(stacks); + update.run(); + rebuildItems.run(); + }); + }); + buttons.button("$launch.text", Icon.ok, () -> { universe.updateLoadout(core, selected); confirm.run(); @@ -36,24 +88,6 @@ public class LaunchLoadoutDialog extends BaseDialog{ ButtonGroup