mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-11 07:39:39 +07:00
Custom launch items
This commit is contained in:
parent
6386cae19a
commit
b3f29f100d
@ -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
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ public class Universe{
|
||||
private float secondCounter;
|
||||
private int turn;
|
||||
private float turnCounter;
|
||||
|
||||
private Schematic lastLoadout = Loadouts.basicShard;
|
||||
private Seq<ItemStack> lastLaunchResources = new Seq<>();
|
||||
|
||||
public Universe(){
|
||||
load();
|
||||
@ -75,6 +77,16 @@ public class Universe{
|
||||
}
|
||||
}
|
||||
|
||||
public Seq<ItemStack> getLaunchResources(){
|
||||
lastLaunchResources = Core.settings.getJson("launch-resources", Seq.class, ItemStack.class, Seq::new);
|
||||
return lastLaunchResources;
|
||||
}
|
||||
|
||||
public void updateLaunchResources(Seq<ItemStack> 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());
|
||||
|
@ -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;
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
|
@ -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.*;
|
||||
|
@ -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.*;
|
||||
|
@ -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<Item> totalMap = new ObjectIntMap<>();
|
||||
//total required items
|
||||
Seq<ItemStack> 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<ItemStack> 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<Table> 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<Button> group = new ButtonGroup<>();
|
||||
selected = universe.getLoadout(core);
|
||||
|
||||
Table items = new Table();
|
||||
|
||||
Runnable rebuildItems = () -> {
|
||||
items.clearChildren();
|
||||
int i = 0;
|
||||
|
||||
for(ItemStack s : selected.requirements()){
|
||||
items.image(s.item.icon(Cicon.small)).left();
|
||||
items.add((state.rules.infiniteResources || build.items.has(s.item, s.amount)) ? "[lightgray]" + s.amount + "" :
|
||||
((build.items.has(s.item, s.amount) ? "[lightgray]" : "[scarlet]") + Math.min(build.items.get(s.item), s.amount) + "[lightgray]/" + s.amount))
|
||||
.padLeft(2).left().padRight(4);
|
||||
|
||||
if(++i % 4 == 0){
|
||||
items.row();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cont.pane(t -> {
|
||||
int i = 0;
|
||||
|
||||
@ -61,8 +95,8 @@ public class LaunchLoadoutDialog extends BaseDialog{
|
||||
|
||||
t.button(b -> b.add(new SchematicImage(s)), Styles.togglet, () -> {
|
||||
selected = s;
|
||||
update.run();
|
||||
rebuildItems.run();
|
||||
valid = build.items.has(selected.requirements());
|
||||
}).group(group).pad(4).disabled(!build.items.has(s.requirements())).checked(s == selected).size(200f);
|
||||
|
||||
if(++i % cols == 0){
|
||||
@ -72,14 +106,11 @@ public class LaunchLoadoutDialog extends BaseDialog{
|
||||
}).growX().get().setScrollingDisabled(true, false);
|
||||
|
||||
cont.row();
|
||||
|
||||
cont.add(items);
|
||||
|
||||
update.run();
|
||||
rebuildItems.run();
|
||||
|
||||
//TODO configure items to launch with
|
||||
|
||||
show();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.graphics.g3d.PlanetRenderer.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.Sector.*;
|
||||
import mindustry.ui.*;
|
||||
|
@ -207,6 +207,12 @@ public class ItemModule extends BlockModule{
|
||||
items[item.id] = amount;
|
||||
}
|
||||
|
||||
public void add(Iterable<ItemStack> stacks){
|
||||
for(ItemStack stack : stacks){
|
||||
add(stack.item, stack.amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Item item, int amount){
|
||||
add(item.id, amount);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user