Added 'block info' tool, fixed sorter corruptions

This commit is contained in:
Anuken
2018-02-03 21:49:43 -05:00
parent da22f8fbce
commit 1c9395ed43
13 changed files with 102 additions and 77 deletions

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
@@ -34,6 +35,10 @@ import static io.anuke.mindustry.Vars.*;
public class Logic extends Module {
private final Array<EnemySpawn> spawns = WaveCreator.getSpawns();
public Logic(){
Timers.setDeltaProvider(() -> Math.min(Gdx.graphics.getDeltaTime()*60f, 60));
}
@Override
public void init(){
Entities.initPhysics();

View File

@@ -400,6 +400,12 @@ public class Renderer extends RendererModule{
if(tile.isLinked())
target = tile.getLinked();
if(Inputs.keyDown("block_info") && target.block().fullDescription != null){
Draw.color(Colors.get("accent"));
Lines.crect(target.drawx(), target.drawy(), target.block().width * tilesize, target.block().height * tilesize);
Draw.color();
}
//if(target.entity != null)
// drawHealth(target.drawx(), target.drawy() - 3f - target.block().height / 2f * tilesize, target.entity.health, target.entity.tile.block().health);

View File

@@ -12,7 +12,6 @@ import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
@@ -179,10 +178,7 @@ public class AndroidInput extends InputHandler{
for(ItemStack stack : recipe.requirements){
state.inventory.removeItem(stack);
}
if(!state.inventory.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;
}
return false;

View File

@@ -23,6 +23,7 @@ public class DefaultKeybinds {
"dash", Input.SHIFT_LEFT,
"rotate_alt", new Axis(Input.R, Input.E),
"rotate", new Axis(Input.SCROLL),
"block_info", Input.CONTROL_LEFT,
"player_list", Input.TAB,
"chat", Input.ENTER,
"console", Input.GRAVE,

View File

@@ -96,19 +96,27 @@ public class DesktopInput extends InputHandler{
}
Tile cursor = world.tile(tilex(), tiley());
Tile target = cursor == null ? null : cursor.isLinked() ? cursor.getLinked() : cursor;
boolean showCursor = false;
if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info")
&& target.block().fullDescription != null){
showCursor = true;
if(Inputs.keyTap("select")){
ui.hudfrag.blockfrag.showBlockInfo(target.block());
Cursors.restoreCursor();
}
}
if(Inputs.keyTap("select") && cursor != null && !ui.hasMouse()){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if(linked != null && linked.block().isConfigurable(linked)){
ui.configfrag.showConfig(linked);
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
if(target.block().isConfigurable(target)){
ui.configfrag.showConfig(target);
}else if(!ui.configfrag.hasConfigMouse()){
ui.configfrag.hideConfig();
}
if(linked != null) {
linked.block().tapped(linked);
if(Net.active()) NetEvents.handleBlockTap(linked);
}
target.block().tapped(target);
if(Net.active()) NetEvents.handleBlockTap(target);
}
if(Inputs.keyTap("break")){
@@ -122,7 +130,6 @@ public class DesktopInput extends InputHandler{
if(recipe != null && Inputs.keyTap("break")){
beganBreak = true;
recipe = null;
Cursors.restoreCursor();
}
//block breaking
@@ -136,6 +143,17 @@ public class DesktopInput extends InputHandler{
breaktime = 0f;
}
if(recipe != null){
showCursor = validPlace(tilex(), tiley(), control.input().recipe.result) && control.input().cursorNear();
}
if(!ui.hasMouse()) {
if (showCursor)
Cursors.setHand();
else
Cursors.restoreCursor();
}
}
public int tilex(){

View File

@@ -22,7 +22,6 @@ import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
@@ -68,10 +67,7 @@ public abstract class InputHandler extends InputAdapter{
for(ItemStack stack : recipe.requirements){
state.inventory.removeItem(stack);
}
if(!state.inventory.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;
}
return false;

View File

@@ -10,7 +10,6 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
@@ -48,11 +47,6 @@ public enum PlaceMode{
Tmp.v1.set(7, 0).rotate(control.input().rotation * 90);
Lines.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
}
if(valid)
Cursors.setHand();
else
Cursors.restoreCursor();
}
public void tapped(int tilex, int tiley){

View File

@@ -19,6 +19,7 @@ import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.BlockPart;
import io.anuke.mindustry.world.blocks.types.Rock;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.util.Log;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -190,6 +191,8 @@ public class Save15 extends SaveFileVersion {
Tile tile = world.tile(pos % world.width(), pos / world.width());
Log.info("Load tile {0} {1}", pos, blockid > Block.getAllBlocks().size || blockid < 0 ? null : Block.getByID(blockid));
tile.setBlock(map.get(blockid));
if(blockid == Blocks.blockpart.id){

View File

@@ -9,6 +9,7 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.*;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.scene.actions.Actions;
@@ -218,55 +219,7 @@ public class BlocksFragment implements Fragment{
//extra info
if(recipe.result.fullDescription != null){
header.addButton("?", ()->{
statlist.clear();
recipe.result.getStats(statlist);
Label desclabel = new Label(recipe.result.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = state.is(State.paused);
state.set(State.paused);
FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo");
Table table = new Table();
table.defaults().pad(1f);
ScrollPane pane = new ScrollPane(table, "clear");
pane.setFadeScrollBars(false);
Table top = new Table();
top.left();
top.add(new Image(Draw.region(recipe.result.name))).size(8*5 * recipe.result.width);
top.add("[accent]"+recipe.result.formalName).padLeft(6f);
table.add(top).fill().left();
table.row();
table.add(desclabel).width(600);
table.row();
d.content().add(pane).grow();
if(statlist.size > 0){
table.add("$text.blocks.extrainfo").padTop(6).padBottom(5).left();
table.row();
}
for(String s : statlist){
if(s.contains(":")) {
String color = s.substring(0, s.indexOf("]")+1);
String first = s.substring(color.length(), s.indexOf(":")).replace("/", "").replace(" ", "").toLowerCase();
String last = s.substring(s.indexOf(":"), s.length());
s = color + Bundles.get("text.blocks." + first) + last;
}
table.add(s).left();
table.row();
}
d.buttons().addButton("$text.ok", ()->{
if(!wasPaused) state.set(State.playing);
d.hide();
}).size(110, 50).pad(10f);
d.show();
}).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
header.addButton("?", () -> showBlockInfo(recipe.result)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
}
desctable.add().pad(2);
@@ -300,7 +253,56 @@ public class BlocksFragment implements Fragment{
Label label = new Label("[health]"+ Bundles.get("text.health")+": " + recipe.result.health);
label.setWrap(true);
desctable.add(label).width(200).padTop(4).padBottom(2);
}
public void showBlockInfo(Block block){
statlist.clear();
block.getStats(statlist);
Label desclabel = new Label(block.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = state.is(State.paused);
state.set(State.paused);
FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo");
Table table = new Table();
table.defaults().pad(1f);
ScrollPane pane = new ScrollPane(table, "clear");
pane.setFadeScrollBars(false);
Table top = new Table();
top.left();
top.add(new Image(Draw.region(block.name))).size(8*5 * block.width);
top.add("[accent]"+block.formalName).padLeft(6f);
table.add(top).fill().left();
table.row();
table.add(desclabel).width(600);
table.row();
d.content().add(pane).grow();
if(statlist.size > 0){
table.add("$text.blocks.extrainfo").padTop(6).padBottom(5).left();
table.row();
}
for(String s : statlist){
if(s.contains(":")) {
String color = s.substring(0, s.indexOf("]")+1);
String first = s.substring(color.length(), s.indexOf(":")).replace("/", "").replace(" ", "").toLowerCase();
String last = s.substring(s.indexOf(":"), s.length());
s = color + Bundles.get("text.blocks." + first) + last;
}
table.add(s).left();
table.row();
}
d.buttons().addButton("$text.ok", ()->{
if(!wasPaused) state.set(State.playing);
d.hide();
}).size(110, 50).pad(10f);
d.show();
}
public void updateItems(){

View File

@@ -20,11 +20,11 @@ import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*;
public class HudFragment implements Fragment{
public final BlocksFragment blockfrag = new BlocksFragment();
private ImageButton menu, flip;
private Table respawntable;
private Table wavetable;
private boolean shown = true;
private BlocksFragment blockfrag = new BlocksFragment();
public void build(){

View File

@@ -23,6 +23,8 @@ public class Sorter extends Block{
public Sorter(String name) {
super(name);
update = true;
solid = true;
}
@Override
@@ -65,7 +67,7 @@ public class Sorter extends Block{
int dir = source.relativeTo(dest.x, dest.y);
if(dir == -1) return null;
Tile to = null;
Tile to;
if(item == entity.sortItem){
to = dest.getNearby()[dir];