Incomplete tutorial basics

This commit is contained in:
Anuken 2019-08-08 17:03:45 -04:00
parent 0a07c62b63
commit 4811578c95
17 changed files with 825 additions and 660 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -861,10 +861,12 @@ unit.chaos-array.name = Chaos Array
unit.eradicator.name = Eradicator unit.eradicator.name = Eradicator
unit.lich.name = Lich unit.lich.name = Lich
unit.reaper.name = Reaper unit.reaper.name = Reaper
tutorial.begin = Your mission here is to eradicate the[lightgray] enemy[].\n\nBegin by[accent] mining copper[]. Tap a copper ore vein near your core to do this. tutorial.intro = Begin by[accent] mining copper[]. Tap a copper ore vein near your core to do this.\n\n[accent]{0}/{1} copper
tutorial.drill = Mining manually is inefficient.\n[accent]Drills []can mine automatically.\nPlace one on a copper vein. tutorial.drill = Mining manually is inefficient.\n[accent]Drills []can mine automatically.\n\nClick the drill tab in the bottom right, then select the[accent] mechanical drill[]. Place it on a copper vein by clicking.
tutorial.conveyor = [accent]Conveyors[] are used to transport items to the core.\nMake a line of conveyors from the drill to the core. tutorial.drill.mobile = Mining manually is inefficient.\n[accent]Drills []can mine automatically.\n\nTap the drill tab in the bottom right, then select the[accent] mechanical drill[]. Place it on a copper vein by tapping, then press the[accent] checkmark[] below to confirm your selection.\nPress the[accent] X button[] to cancel placement.
tutorial.morecopper = More copper is required.\n\nEither mine it manually, or place more drills.
tutorial.conveyor = [accent]Conveyors[] are used to transport items to the core.\nMake a line of conveyors from the drill to the core.[yellow] Hold down the mouse to place in a line.[]\nHold[accent] CTRL[] while selecting a line to place diagonally.\n\n[accent]{0}/{1} conveyors
tutorial.conveyor.mobile = [accent]Conveyors[] are used to transport items to the core.\nMake a line of conveyors from the drill to the core.[yellow] Place in a line by holding down your finger for a few seconds[] and dragging in a direction.\n\n[accent]{0}/{1} conveyors
tutorial.turret = Defensive structures must be built to repel the[lightgray] enemy[].\nBuild a duo turret near your base. tutorial.turret = Defensive structures must be built to repel the[lightgray] enemy[].\nBuild a duo turret near your base.
tutorial.drillturret = Duo turrets require[accent] copper ammo []to shoot.\nPlace a drill next to the turret to supply it with mined copper. tutorial.drillturret = Duo turrets require[accent] copper ammo []to shoot.\nPlace a drill next to the turret to supply it with mined copper.
tutorial.waves = The[lightgray] enemy[] approaches.\n\nDefend your core for 2 waves. Build more turrets. tutorial.waves = The[lightgray] enemy[] approaches.\n\nDefend your core for 2 waves. Build more turrets.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 676 KiB

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 461 KiB

After

Width:  |  Height:  |  Size: 462 KiB

View File

@ -4,8 +4,9 @@ import io.anuke.arc.*;
import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.input.*; import io.anuke.arc.input.*;
import io.anuke.arc.math.geom.*;
import io.anuke.arc.scene.ui.*; 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.arc.util.*;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.core.GameState.*;
@ -20,6 +21,7 @@ import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.dialogs.*; import io.anuke.mindustry.ui.dialogs.*;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.storage.*;
import java.io.*; import java.io.*;
@ -226,6 +228,57 @@ public class Control implements ApplicationListener{
}); });
} }
public void playTutorial(Zone zone){
ui.loadAnd(() -> {
logic.reset();
Net.reset();
world.beginMapLoad();
world.createTiles(zone.generator.width, zone.generator.height);
zone.generator.generate(world.getTiles());
Tile coreb = null;
out:
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
if(world.rawTile(x, y).block() instanceof CoreBlock){
coreb = world.rawTile(x, y);
break out;
}
}
}
Geometry.circle(coreb.x, coreb.y, 10, (cx, cy) -> {
Tile tile = world.ltile(cx, cy);
if(tile != null && tile.getTeam() == defaultTeam && !(tile.block() instanceof CoreBlock)){
world.removeBlock(tile);
}
});
Geometry.circle(coreb.x, coreb.y, 5, (cx, cy) -> world.tile(cx, cy).clearOverlay());
world.endMapLoad();
zone.rules.accept(state.rules);
state.rules.zone = zone;
for(Tile core : state.teams.get(defaultTeam).cores){
for(ItemStack stack : zone.getStartingItems()){
core.entity.items.add(stack.item, stack.amount);
}
}
Tile core = state.teams.get(defaultTeam).cores.first();
core.entity.items.clear();
state.set(State.playing);
control.saves.zoneSave();
logic.play();
state.rules.waveTimer = false;
state.rules.tutorial = true;
});
}
public boolean isHighScore(){ public boolean isHighScore(){
return hiscore; return hiscore;
} }
@ -258,10 +311,7 @@ public class Control implements ApplicationListener{
//play tutorial on stop //play tutorial on stop
if(!settings.getBool("tutorial", false)){ if(!settings.getBool("tutorial", false)){
Core.app.post(() -> { Core.app.post(() -> playTutorial(Zones.groundZero));
playZone(Zones.groundZero);
state.rules.tutorial = true;
});
} }
//display UI scale changed dialog //display UI scale changed dialog
@ -333,6 +383,10 @@ public class Control implements ApplicationListener{
} }
} }
if(state.rules.tutorial){
tutorial.update();
}
//auto-update rpc every 5 seconds //auto-update rpc every 5 seconds
if(timer.get(0, 60 * 5)){ if(timer.get(0, 60 * 5)){
Platform.instance.updateRPC(); Platform.instance.updateRPC();

View File

@ -158,6 +158,12 @@ public class UI implements ApplicationListener{
Core.scene.act(); Core.scene.act();
Core.scene.draw(); Core.scene.draw();
//draw overlay for buttons
if(state.rules.tutorial){
control.tutorial.draw();
Draw.flush();
}
} }
@Override @Override

View File

@ -48,6 +48,11 @@ public class EventType{
} }
/** Called when the player places a line, mobile or desktop.*/
public static class LineConfirmEvent{
}
public static class GameOverEvent{ public static class GameOverEvent{
public final Team winner; public final Team winner;

View File

@ -1,32 +1,147 @@
package io.anuke.mindustry.game; package io.anuke.mindustry.game;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.function.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*; import io.anuke.arc.math.*;
import io.anuke.arc.scene.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*;
/** Handles tutorial state. */ /** Handles tutorial state. */
public class Tutorial{ public class Tutorial{
private static final int mineCopper = 16;
private ObjectSet<String> events = new ObjectSet<>();
private ObjectIntMap<Block> blocksPlaced = new ObjectIntMap<>();
public TutorialStage stage = TutorialStage.values()[0]; public TutorialStage stage = TutorialStage.values()[0];
public Tutorial(){
Events.on(BlockBuildEndEvent.class, event -> {
if(!event.breaking){
blocksPlaced.getAndIncrement(event.tile.block(), 0, 1);
}
});
Events.on(LineConfirmEvent.class, event -> events.add("lineconfirm"));
}
public void update(){
if(stage.done.get()){
next();
}
}
public void draw(){
stage.draw();
}
/** Resets tutorial state. */ /** Resets tutorial state. */
public void reset(){ public void reset(){
stage = TutorialStage.values()[0]; stage = TutorialStage.values()[0];
blocksPlaced.clear();
events.clear();
} }
/** Goes on to the next tutorial step. */ /** Goes on to the next tutorial step. */
public void next(){ public void next(){
stage = TutorialStage.values()[Mathf.clamp(stage.ordinal() + 1, 0, TutorialStage.values().length)]; stage = TutorialStage.values()[Mathf.clamp(stage.ordinal() + 1, 0, TutorialStage.values().length)];
blocksPlaced.clear();
events.clear();
} }
public enum TutorialStage{ public enum TutorialStage{
intro; intro(
line -> Core.bundle.format(line, item(Items.copper), mineCopper),
() -> item(Items.copper) >= mineCopper
),
drill(() -> placed(Blocks.mechanicalDrill, 1)){
void draw(){
outline("category-production");
outline("block-mechanical-drill");
}
},
conveyor(
line -> Core.bundle.format(line, placed(Blocks.conveyor), 3),
() -> placed(Blocks.conveyor, 3) && event("lineconfirm")){
void draw(){
outline("category-distribution");
outline("block-conveyor");
}
},
turret(() -> placed(Blocks.duo, 1)){
void draw(){
outline("category-turrets");
outline("block-duo");
}
};
public final String text; protected final String line = Core.bundle.has("tutorial." + name() + ".mobile") && Vars.mobile ? "tutorial." + name() + ".mobile" : "tutorial." + name();
protected final Function<String, String> text;
protected final BooleanProvider done;
TutorialStage(){ TutorialStage(Function<String, String> text, BooleanProvider done){
text = Core.bundle.get("tutorial." + name()); this.text = text;
this.done = done;
} }
TutorialStage(BooleanProvider done){
this.text = line -> Core.bundle.get(line);
this.done = done;
}
public String text(){
return text.get(line);
}
void draw(){
}
//utility
static boolean event(String name){
return Vars.control.tutorial.events.contains(name);
}
static boolean placed(Block block, int amount){
return placed(block) >= amount;
}
static int placed(Block block){
return Vars.control.tutorial.blocksPlaced.get(block, 0);
}
static int item(Item item){
return Vars.state.teams.get(Vars.defaultTeam).cores.isEmpty() ? 0 : Vars.state.teams.get(Vars.defaultTeam).cores.first().entity.items.get(item);
}
static boolean toggled(String name){
Element element = Core.scene.findVisible(name);
if(element instanceof Button){
return ((Button)element).isChecked();
}
return false;
}
static void outline(String name){
Element element = Core.scene.findVisible(name);
if(element != null && !toggled(name)){
element.localToStageCoordinates(Tmp.v1.setZero());
float sin = Mathf.sin(11f, UnitScl.dp.scl(4f));
Lines.stroke(UnitScl.dp.scl(7f), Pal.place);
Lines.rect(Tmp.v1.x - sin, Tmp.v1.y - sin, element.getWidth() + sin*2, element.getHeight() + sin*2);
Draw.reset();
}
}
} }
} }

View File

@ -10,6 +10,7 @@ import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.input.PlaceUtils.*; import io.anuke.mindustry.input.PlaceUtils.*;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
@ -242,6 +243,7 @@ public class DesktopInput extends InputHandler{
rotation = l.rotation; rotation = l.rotation;
tryPlaceBlock(l.x, l.y); tryPlaceBlock(l.x, l.y);
}); });
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ //touch up while breaking, break everything in selection }else if(mode == breaking){ //touch up while breaking, break everything in selection
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, false, maxLength); NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, false, maxLength);
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){ for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){

View File

@ -1,34 +1,25 @@
package io.anuke.mindustry.input; package io.anuke.mindustry.input;
import io.anuke.arc.Core; import io.anuke.arc.*;
import io.anuke.arc.collection.Array; import io.anuke.arc.collection.*;
import io.anuke.arc.function.BooleanProvider; import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.input.GestureDetector; import io.anuke.arc.input.*;
import io.anuke.arc.input.GestureDetector.GestureListener; import io.anuke.arc.input.GestureDetector.*;
import io.anuke.arc.input.KeyCode; import io.anuke.arc.math.*;
import io.anuke.arc.math.Interpolation;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.*; import io.anuke.arc.math.geom.*;
import io.anuke.arc.scene.actions.Actions;
import io.anuke.arc.scene.event.Touchable;
import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.BuilderTrait.*; import io.anuke.mindustry.entities.traits.BuilderTrait.*;
import io.anuke.mindustry.entities.traits.TargetTrait; import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.entities.type.Unit; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult; import io.anuke.mindustry.input.PlaceUtils.*;
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.input.PlaceMode.*; import static io.anuke.mindustry.input.PlaceMode.*;
@ -171,24 +162,6 @@ public class MobileInput extends InputHandler implements GestureListener{
removals.add(request); removals.add(request);
} }
void showGuide(String type, BooleanProvider done){
if(!Core.settings.getBool(type, false)){
Core.scene.table("guideDim", t -> {
t.margin(10f);
t.touchable(Touchable.disabled);
t.top().table("button", s -> s.add("$" + type).growX().wrap().labelAlign(Align.center, Align.center)).growX();
t.update(() -> {
if((done.get() || state.is(State.menu)) && t.getUserObject() == null){
t.actions(Actions.delay(1f), Actions.fadeOut(1f, Interpolation.fade), Actions.remove());
t.setUserObject("ha");
}
});
});
Core.settings.put(type, true);
data.modified();
}
}
boolean isLinePlacing(){ boolean isLinePlacing(){
return mode == placing && lineMode && Mathf.dst(lineStartX * tilesize, lineStartY * tilesize, Core.input.mouseWorld().x, Core.input.mouseWorld().y) >= 3 * tilesize; return mode == placing && lineMode && Mathf.dst(lineStartX * tilesize, lineStartY * tilesize, Core.input.mouseWorld().x, Core.input.mouseWorld().y) >= 3 * tilesize;
} }
@ -281,9 +254,6 @@ public class MobileInput extends InputHandler implements GestureListener{
table.addImageButton("icon-break-small", "clear-toggle-partial", iconsizesmall, () -> { table.addImageButton("icon-break-small", "clear-toggle-partial", iconsizesmall, () -> {
mode = mode == breaking ? block == null ? none : placing : breaking; mode = mode == breaking ? block == null ? none : placing : breaking;
lastBlock = block; lastBlock = block;
if(mode == breaking){
showGuide("removearea", this::isAreaBreaking);
}
}).update(l -> l.setChecked(mode == breaking)); }).update(l -> l.setChecked(mode == breaking));
//diagonal swap button //diagonal swap button
@ -516,6 +486,7 @@ public class MobileInput extends InputHandler implements GestureListener{
request.scale = 1f; request.scale = 1f;
selection.add(request); selection.add(request);
}); });
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ }else if(mode == breaking){
//normalize area //normalize area
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, rotation, false, maxLength); NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, rotation, false, maxLength);
@ -652,10 +623,6 @@ public class MobileInput extends InputHandler implements GestureListener{
mode = placing; mode = placing;
} }
if(block != null){
showGuide("placeline", this::isLinePlacing);
}
if(block == null && mode == placing){ if(block == null && mode == placing){
mode = none; mode = none;
} }

View File

@ -1,7 +1,7 @@
package io.anuke.mindustry.ui; package io.anuke.mindustry.ui;
import io.anuke.arc.collection.FloatArray; import io.anuke.arc.collection.*;
import io.anuke.arc.math.geom.Rectangle; import io.anuke.arc.math.geom.*;
/** /**
* Algorithm taken from <a href="https://github.com/abego/treelayout">TreeLayout</a>. * Algorithm taken from <a href="https://github.com/abego/treelayout">TreeLayout</a>.

View File

@ -312,16 +312,21 @@ public class HudFragment extends Fragment{
.update(label -> label.getColor().set(Color.ORANGE).lerp(Color.SCARLET, Mathf.absin(Time.time(), 2f, 1f)))).touchable(Touchable.disabled); .update(label -> label.getColor().set(Color.ORANGE).lerp(Color.SCARLET, Mathf.absin(Time.time(), 2f, 1f)))).touchable(Touchable.disabled);
}); });
parent.fill(t -> {
t.top().visible(() -> state.rules.tutorial);
t.table("button-trans", f -> f.labelWrap(() -> control.tutorial.stage.text()).width(400f).pad(3f));
});
//paused table //paused table
parent.fill(t -> { parent.fill(t -> {
t.top().visible(() -> state.isPaused()); t.top().visible(() -> state.isPaused());
t.table("button", top -> top.add("$paused").pad(6f)); t.table("button-trans", top -> top.add("$paused").pad(5f));
}); });
//'saving' indicator //'saving' indicator
parent.fill(t -> { parent.fill(t -> {
t.bottom().visible(() -> control.saves.isSaving()); t.bottom().visible(() -> control.saves.isSaving());
t.add("$saveload"); t.add("$saveload").style("outline");
}); });
blockfrag.build(parent); blockfrag.build(parent);

View File

@ -146,7 +146,7 @@ public class PlacementFragment extends Fragment{
if(unlocked(block)){ if(unlocked(block)){
input.block = input.block == block ? null : block; input.block = input.block == block ? null : block;
} }
}).size(46f).group(group).get(); }).size(46f).group(group).name("block-" + block.name).get();
button.getStyle().imageUp = new TextureRegionDrawable(block.icon(Icon.medium)); button.getStyle().imageUp = new TextureRegionDrawable(block.icon(Icon.medium));
@ -282,7 +282,7 @@ public class PlacementFragment extends Fragment{
categories.addImageButton("icon-" + cat.name() + "-med", "clear-toggle-trans", iconsizemed, () -> { categories.addImageButton("icon-" + cat.name() + "-med", "clear-toggle-trans", iconsizemed, () -> {
currentCategory = cat; currentCategory = cat;
rebuildCategory.run(); rebuildCategory.run();
}).group(group).update(i -> i.setChecked(currentCategory == cat)); }).group(group).update(i -> i.setChecked(currentCategory == cat)).name("category-" + cat.name());
} }
}).touchable(Touchable.enabled); }).touchable(Touchable.enabled);

View File

@ -43,7 +43,7 @@ public class PlayerListFragment extends Fragment{
} }
}); });
cont.table("button", pane -> { cont.table("button-trans", pane -> {
pane.label(() -> Core.bundle.format(playerGroup.size() == 1 ? "players.single" : "players", playerGroup.size())); pane.label(() -> Core.bundle.format(playerGroup.size() == 1 ? "players.single" : "players", playerGroup.size()));
pane.row(); pane.row();
pane.pane(content).grow().get().setScrollingDisabled(true, false); pane.pane(content).grow().get().setScrollingDisabled(true, false);

View File

@ -54,7 +54,8 @@ public class BlockPart extends Block{
@Override @Override
public Tile linked(Tile tile){ public Tile linked(Tile tile){
return tile.getNearby(-dx, -dy); Tile out = tile.getNearby(-dx, -dy);
return out == null ? tile : out;
} }
@Override @Override

View File

@ -209,9 +209,9 @@ public class Generators{
int off = image.width / 2 - mech.weapon.region.getWidth() / 2; int off = image.width / 2 - mech.weapon.region.getWidth() / 2;
image.draw(mech.weapon.region, -(int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, false, false); for(int i : Mathf.signs){
image.draw(mech.weapon.region, (int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, true, false); image.draw(mech.weapon.region, i * (int)mech.weaponOffsetX*4 + off, -(int)mech.weaponOffsetY*4 + off, i > 0, false);
}
image.save("mech-icon-" + mech.name); image.save("mech-icon-" + mech.name);
} }