Implemented local multiplayer fully

This commit is contained in:
Anuken
2018-05-13 20:48:44 -07:00
parent d1a3752b2d
commit ca24e64c42
14 changed files with 161 additions and 49 deletions
@@ -0,0 +1,59 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.utils.Scaling;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.entities.Player;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
public class LocalPlayerDialog extends FloatingDialog{
public LocalPlayerDialog() {
super("$text.addplayers");
addCloseButton();
shown(this::rebuild);
}
private void rebuild(){
float size = 140f;
content().clear();
if(players.length > 1) {
content().addImageButton("icon-cancel", 14 * 2, () -> {
control.removePlayer();
rebuild();
}).size(50f, size).pad(5).bottom();
}else{
content().add().size(50f, size);
}
for(Player player : players){
Table table = new Table();
Stack stack = new Stack();
stack.add(new Image("button"));
Image img = new Image(Draw.region("icon-chat"));
img.setScaling(Scaling.fill);
stack.add(img);
table.add("Player " + (player.playerIndex + 1)).update(label -> label.setColor(player.color));
table.row();
table.add(stack).size(size);
content().add(table).pad(5);
}
if(players.length < 4) {
content().addImageButton("icon-add", 14 * 2, () -> {
control.addPlayer(players.length);
rebuild();
}).size(50f, size).pad(5).bottom();
}
}
}
@@ -54,6 +54,11 @@ public class PausedDialog extends FloatingDialog{
load.show();
}).disabled(b -> Net.active());
content().row();
content().addButton("$text.addplayers", () -> {
ui.localplayers.show();
}).disabled(b -> Net.active());
content().row();
if(!gwt) {
@@ -14,12 +14,11 @@ import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.ui.layout.Table;
public class BlockConfigFragment implements Fragment {
private Table table;
private Table table = new Table();
private Tile configTile;
@Override
public void build(Group parent) {
table = new Table();
parent.addChild(table);
}
@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import io.anuke.mindustry.content.Recipes;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
@@ -161,30 +162,44 @@ public class BlocksFragment implements Fragment{
}
});
image.clicked(() -> {
// note: input.recipe only gets set here during a click.
// during a hover only the visual description will be updated.
boolean nothingSelectedYet = input.recipe == null;
boolean selectedSomethingElse = !nothingSelectedYet && input.recipe != r;
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
if (shouldMakeSelection) {
input.recipe = r;
hoveredDescriptionRecipe = r;
updateRecipe(r);
} else {
input.recipe = null;
hoveredDescriptionRecipe = null;
updateRecipe(null);
}
});
image.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
// note: input.recipe only gets set here during a click.
// during a hover only the visual description will be updated.
InputHandler handler = mobile ? input : control.input(event.getPointer());
boolean nothingSelectedYet = handler.recipe == null;
boolean selectedSomethingElse = !nothingSelectedYet && handler.recipe != r;
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
if (shouldMakeSelection) {
handler.recipe = r;
hoveredDescriptionRecipe = r;
updateRecipe(r);
} else {
handler.recipe = null;
hoveredDescriptionRecipe = null;
updateRecipe(null);
}
}
});
table.add(image).size(size + 8);
image.update(() -> {
boolean has = (state.inventory.hasItems(r.requirements));
image.setChecked(input.recipe == r);
image.setTouchable(Touchable.enabled);
for(Element e : istack.getChildren()) e.setColor(has ? Color.WHITE : Hue.lightness(0.33f));
for(Element e : istack.getChildren()){
e.setColor(has ? Color.WHITE : Hue.lightness(0.33f));
}
for(Player player : players){
if(control.input(player.playerIndex).recipe == r){
image.setChecked(true);
return;
}
}
image.setChecked(false);
});
if (i % rows == rows - 1)