Added buttons to clear campaign saves & research

This commit is contained in:
Anuken
2020-10-23 09:08:17 -04:00
parent 436a020c3e
commit d66cf13ac6
5 changed files with 61 additions and 5 deletions

View File

@ -574,6 +574,10 @@ settings.clear.confirm = Are you sure you want to clear this data?\nWhat is done
settings.clearall.confirm = [scarlet]WARNING![]\nThis will clear all data, including saves, maps, unlocks and keybinds.\nOnce you press 'ok' the game will wipe all data and automatically exit.
settings.clearsaves.confirm = Are you sure you want to clear all your saves?
settings.clearsaves = Clear Saves
settings.clearresearch = Clear Research
settings.clearresearch.confirm = Are you sure you want to clear all of your campaign research?
settings.clearcampaignsaves = Clear Campaign Saves
settings.clearcampaignsaves.confirm = Are you sure you want to clear all of your campaign saves?
paused = [accent]< Paused >
clear = Clear
banned = [scarlet]Banned

View File

@ -605,8 +605,6 @@ public class TechTree implements ContentList{
public final ItemStack[] finishedRequirements;
/** Extra objectives needed to research this. */
public Seq<Objective> objectives = new Seq<>();
/** Time required to research this content, in seconds. */
public float time;
/** Nodes that depend on this node. */
public final Seq<TechNode> children = new Seq<>();
@ -617,7 +615,6 @@ public class TechTree implements ContentList{
this.content = content;
this.requirements = requirements;
this.depth = parent == null ? 0 : parent.depth + 1;
this.time = Seq.with(requirements).mapFloat(i -> i.item.cost * i.amount).sum() * 10;
this.finishedRequirements = new ItemStack[requirements.length];
//load up the requirements that have been finished if settings are available
@ -632,6 +629,14 @@ public class TechTree implements ContentList{
all.add(this);
}
/** Resets finished requirements and saves. */
public void reset(){
for(ItemStack stack : finishedRequirements){
stack.amount = 0;
}
save();
}
/** Removes this node from the tech tree. */
public void remove(){
all.remove(this);

View File

@ -125,6 +125,14 @@ public abstract class UnlockableContent extends MappableContent{
return unlocked || alwaysUnlocked;
}
/** Locks this content again. */
public void clearUnlock(){
if(unlocked){
unlocked = false;
Core.settings.put(name + "-unlocked", false);
}
}
/** @return whether this content is unlocked, or the player is in a custom (non-campaign) game. */
public boolean unlockedNow(){
return unlocked() || !state.isCampaign();

View File

@ -15,8 +15,7 @@ import static mindustry.Vars.*;
/** A small section of a planet. */
public class Sector{
private static final Seq<Sector> tmpSeq1 = new Seq<>(), tmpSeq2 = new Seq<>(), tmpSeq3 = new Seq<>();
private static final ObjectSet<Sector> tmpSet = new ObjectSet<>();
private static final Seq<Sector> tmpSeq1 = new Seq<>();
public final SectorRect rect;
public final Plane plane;
@ -80,6 +79,12 @@ public class Sector{
info = Core.settings.getJson(planet.name + "-s-" + id + "-info", SectorInfo.class, SectorInfo::new);
}
/** Removes any sector info. */
public void clearInfo(){
info = new SectorInfo();
Core.settings.remove(planet.name + "-s-" + id + "-info");
}
public float getProductionScale(){
return Math.max(1f - info.damage, 0);
}

View File

@ -14,8 +14,11 @@ import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.content.*;
import mindustry.content.TechTree.*;
import mindustry.core.GameState.*;
import mindustry.core.*;
import mindustry.ctype.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@ -116,6 +119,37 @@ public class SettingsMenuDialog extends SettingsDialog{
t.row();
t.button("@settings.clearresearch", Icon.trash, style, () -> {
ui.showConfirm("@confirm", "@settings.clearresearch.confirm", () -> {
for(TechNode node : TechTree.all){
node.reset();
}
content.each(c -> {
if(c instanceof UnlockableContent u){
u.clearUnlock();
}
});
});
}).marginLeft(4);
t.row();
t.button("@settings.clearcampaignsaves", Icon.trash, style, () -> {
ui.showConfirm("@confirm", "@settings.clearcampaignsaves.confirm", () -> {
for(var planet : content.planets()){
for(var sec : planet.sectors){
sec.clearInfo();
if(sec.save != null){
sec.save.delete();
sec.save = null;
}
}
}
});
}).marginLeft(4);
t.row();
t.button("@data.export", Icon.upload, style, () -> {
if(ios){
Fi file = Core.files.local("mindustry-data-export.zip");