Tutorial improvements

This commit is contained in:
Anuken
2019-08-09 12:18:08 -04:00
parent 69e7b442e2
commit 2c4379acd1
9 changed files with 96 additions and 38 deletions

View File

@@ -228,7 +228,8 @@ public class Control implements ApplicationListener{
});
}
public void playTutorial(Zone zone){
public void playTutorial(){
Zone zone = Zones.groundZero;
ui.loadAnd(() -> {
logic.reset();
Net.reset();
@@ -313,7 +314,7 @@ public class Control implements ApplicationListener{
//play tutorial on stop
if(!settings.getBool("tutorial", false)){
Core.app.post(() -> playTutorial(Zones.groundZero));
Core.app.post(this::playTutorial);
}
//display UI scale changed dialog

View File

@@ -72,7 +72,7 @@ public class Saves{
lastTimestamp = Time.millis();
}
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave() && !state.rules.tutorial){
time += Time.delta();
if(time > Core.settings.getInt("saveinterval") * 60){
saving = true;

View File

@@ -24,6 +24,7 @@ public class Tutorial{
private ObjectSet<String> events = new ObjectSet<>();
private ObjectIntMap<Block> blocksPlaced = new ObjectIntMap<>();
private int sentence;
public TutorialStage stage = TutorialStage.values()[0];
public Tutorial(){
@@ -43,7 +44,7 @@ public class Tutorial{
/** update tutorial state, transition if needed */
public void update(){
if(stage.done.get()){
if(stage.done.get() && !canNext()){
next();
}else{
stage.update();
@@ -52,15 +53,18 @@ public class Tutorial{
/** draw UI overlay */
public void draw(){
stage.draw();
if(!Core.scene.hasDialog()){
stage.draw();
}
}
/** Resets tutorial state. */
public void reset(){
stage = TutorialStage.values()[4];
stage = TutorialStage.values()[0];
stage.begin();
blocksPlaced.clear();
events.clear();
sentence = 0;
}
/** Goes on to the next tutorial step. */
@@ -69,11 +73,32 @@ public class Tutorial{
stage.begin();
blocksPlaced.clear();
events.clear();
sentence = 0;
}
public boolean canNext(){
return sentence + 1 < stage.sentences.size;
}
public void nextSentence(){
if(canNext()){
sentence ++;
}
}
public boolean canPrev(){
return sentence > 0;
}
public void prevSentence(){
if(canPrev()){
sentence --;
}
}
public enum TutorialStage{
intro(
line -> Core.bundle.format(line, item(Items.copper), mineCopper),
line -> Strings.format(line, item(Items.copper), mineCopper),
() -> item(Items.copper) >= mineCopper
),
drill(() -> placed(Blocks.mechanicalDrill, 1)){
@@ -90,7 +115,7 @@ public class Tutorial{
}
},
conveyor(
line -> Core.bundle.format(line, Math.min(placed(Blocks.conveyor), 2), 2),
line -> Strings.format(line, Math.min(placed(Blocks.conveyor), 2), 2),
() -> placed(Blocks.conveyor, 2) && event("lineconfirm") && event("coreitem")){
void draw(){
outline("category-distribution");
@@ -111,6 +136,13 @@ public class Tutorial{
}
}
},
unpause(() -> !state.isPaused()){
void draw(){
if(mobile){
outline("pause");
}
}
},
breaking(TutorialStage::blocksBroken){
void begin(){
placeBlocks();
@@ -157,21 +189,23 @@ public class Tutorial{
protected final String line = Core.bundle.has("tutorial." + name() + ".mobile") && mobile ? "tutorial." + name() + ".mobile" : "tutorial." + name();
protected final Function<String, String> text;
protected final Array<String> sentences;
protected final BooleanProvider done;
TutorialStage(Function<String, String> text, BooleanProvider done){
this.text = text;
this.done = done;
this.sentences = Array.select(Core.bundle.get(line).split("\n"), s -> !s.isEmpty());
}
TutorialStage(BooleanProvider done){
this.text = line -> Core.bundle.get(line);
this.done = done;
this(line -> line, done);
}
/** displayed tutorial stage text.*/
public String text(){
return text.get(line);
String line = sentences.get(control.tutorial.sentence);
return line.contains("{") ? text.get(line) : line;
}
/** called every frame when this stage is active.*/

View File

@@ -106,7 +106,7 @@ public class PausedDialog extends FloatingDialog{
return;
}
if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave()){
if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave() || state.rules.tutorial){
state.set(State.menu);
return;
}

View File

@@ -185,6 +185,17 @@ public class SettingsMenuDialog extends SettingsDialog{
}
});
game.pref(new Setting(){
@Override
public void add(SettingsTable table){
table.addButton("$tutorial.retake", () -> {
control.playTutorial();
}).size(220f, 60f).pad(6).left();
table.add();
table.row();
}
});
graphics.sliderPref("uiscale", 100, 25, 400, 25, s -> {
if(Core.graphics.getFrameId() > 10){
Log.info("changed");

View File

@@ -13,7 +13,6 @@ import io.anuke.arc.scene.actions.*;
import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.style.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.UnitScl;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*;
@@ -314,11 +313,20 @@ public class HudFragment extends Fragment{
//tutorial text
parent.fill(t -> {
t.touchable(Touchable.disabled);
Runnable resize = () -> {
t.clearChildren();
t.top().right().visible(() -> state.rules.tutorial);
t.table("button-trans", f -> f.labelWrap(() -> control.tutorial.stage.text()).width(!Core.graphics.isPortrait() ? 450f : 180f).pad(3f));
t.stack(new Button("default"){{
marginLeft(48f);
labelWrap(() -> control.tutorial.stage.text() + (control.tutorial.canNext() ? "\n\n" + Core.bundle.get("tutorial.next") : "")).width(!Core.graphics.isPortrait() ? 400f : 160f).pad(2f);
clicked(() -> control.tutorial.nextSentence());
setDisabled(() -> !control.tutorial.canNext());
}},
new Table(f -> {
f.left().addImageButton("icon-arrow-left-small", "empty", iconsizesmall, () -> {
control.tutorial.prevSentence();
}).width(44f).growY().visible(() -> control.tutorial.canPrev());
}));
};
resize.run();

View File

@@ -1,12 +1,10 @@
package io.anuke.mindustry.world.blocks.production;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
import io.anuke.arc.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.*;
public class Fracker extends SolidPump{
protected final float itemUseTime = 100f;
@@ -41,7 +39,7 @@ public class Fracker extends SolidPump{
@Override
public boolean canProduce(Tile tile){
return tile.entity.liquids.get(result) < liquidCapacity;
return tile.entity.liquids.get(result) < liquidCapacity - 0.01f;
}
@Override