Massive amount of refactoring for local multiplayer, annotations
This commit is contained in:
4
annotations/build.gradle
Normal file
4
annotations/build.gradle
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||||
BIN
annotations/build/libs/annotations-release.jar
Normal file
BIN
annotations/build/libs/annotations-release.jar
Normal file
Binary file not shown.
2
annotations/build/tmp/jar/MANIFEST.MF
Normal file
2
annotations/build/tmp/jar/MANIFEST.MF
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package io.anuke.annotations;
|
||||||
|
|
||||||
|
import javax.annotation.processing.*;
|
||||||
|
import javax.lang.model.SourceVersion;
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
|
import javax.lang.model.util.Types;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||||
|
@SupportedAnnotationTypes({
|
||||||
|
"java.lang.Override"
|
||||||
|
})
|
||||||
|
public class AnnotationProcessor extends AbstractProcessor {
|
||||||
|
private Types typeUtils;
|
||||||
|
private Elements elementUtils;
|
||||||
|
private Filer filer;
|
||||||
|
private Messager messager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||||
|
super.init(processingEnv);
|
||||||
|
typeUtils = processingEnv.getTypeUtils();
|
||||||
|
elementUtils = processingEnv.getElementUtils();
|
||||||
|
filer = processingEnv.getFiler();
|
||||||
|
messager = processingEnv.getMessager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Override.class)) {
|
||||||
|
messager.printMessage(Kind.ERROR, "an element has the override class: ", annotatedElement);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
build.gradle
14
build.gradle
@@ -148,6 +148,8 @@ project(":core") {
|
|||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile project(":annotations")
|
||||||
|
|
||||||
boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
|
boolean comp = System.properties["release"] == null || System.properties["release"] == "false"
|
||||||
|
|
||||||
if(!comp){
|
if(!comp){
|
||||||
@@ -165,10 +167,16 @@ project(":core") {
|
|||||||
if(new File('../GDXGifRecorder').exists() && comp) {
|
if(new File('../GDXGifRecorder').exists() && comp) {
|
||||||
compile project(":GDXGifRecorder")
|
compile project(":GDXGifRecorder")
|
||||||
}
|
}
|
||||||
|
|
||||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileJava.options.compilerArgs = [
|
||||||
|
"-proc:only",
|
||||||
|
"-processor", "io.anuke.annotations.AnnotationProcessor"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":server") {
|
project(":server") {
|
||||||
@@ -182,6 +190,12 @@ project(":server") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project(":annotations") {
|
||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
dependencies {}
|
||||||
|
}
|
||||||
|
|
||||||
project(":kryonet") {
|
project(":kryonet") {
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ public class Vars{
|
|||||||
//whether to show block debug
|
//whether to show block debug
|
||||||
public static boolean showBlockDebug = false;
|
public static boolean showBlockDebug = false;
|
||||||
|
|
||||||
|
public static final int maxTextLength = 150;
|
||||||
|
|
||||||
public static boolean headless = false;
|
public static boolean headless = false;
|
||||||
|
|
||||||
public static float controllerMin = 0.25f;
|
public static float controllerMin = 0.25f;
|
||||||
@@ -143,7 +145,7 @@ public class Vars{
|
|||||||
public static NetServer netServer;
|
public static NetServer netServer;
|
||||||
public static NetClient netClient;
|
public static NetClient netClient;
|
||||||
|
|
||||||
public static Player[] players;
|
public static Player[] players = {};
|
||||||
|
|
||||||
public static final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
|
public static final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
|
||||||
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.core;
|
package io.anuke.mindustry.core;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.Input.Buttons;
|
import com.badlogic.gdx.Input.Buttons;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
@@ -25,10 +26,7 @@ import io.anuke.ucore.core.Inputs.DeviceType;
|
|||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.modules.Module;
|
import io.anuke.ucore.modules.Module;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Atlas;
|
import io.anuke.ucore.util.*;
|
||||||
import io.anuke.ucore.util.Input;
|
|
||||||
import io.anuke.ucore.util.InputProxy;
|
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -37,19 +35,14 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
* Should <i>not</i> handle any logic-critical state.
|
* Should <i>not</i> handle any logic-critical state.
|
||||||
* This class is not created in the headless server.*/
|
* This class is not created in the headless server.*/
|
||||||
public class Control extends Module{
|
public class Control extends Module{
|
||||||
private Tutorial tutorial = new Tutorial();
|
|
||||||
private boolean hiscore = false;
|
private boolean hiscore = false;
|
||||||
|
|
||||||
private boolean wasPaused = false;
|
private boolean wasPaused = false;
|
||||||
|
|
||||||
private Saves saves;
|
private Saves saves;
|
||||||
|
private InputHandler[] inputs = {};
|
||||||
|
|
||||||
private InputHandler[] inputs;
|
|
||||||
|
|
||||||
private InputProxy proxy;
|
|
||||||
private float controlx, controly;
|
|
||||||
private boolean controlling;
|
|
||||||
private Throwable error;
|
private Throwable error;
|
||||||
|
private InputProxy proxy;
|
||||||
|
private Input gdxInput;
|
||||||
|
|
||||||
public Control(){
|
public Control(){
|
||||||
saves = new Saves();
|
saves = new Saves();
|
||||||
@@ -58,28 +51,6 @@ public class Control extends Module{
|
|||||||
|
|
||||||
Gdx.input.setCatchBackKey(true);
|
Gdx.input.setCatchBackKey(true);
|
||||||
|
|
||||||
proxy = new InputProxy(Gdx.input){
|
|
||||||
@Override
|
|
||||||
public int getY() {
|
|
||||||
return controlling ? (int)controly : input.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getX() {
|
|
||||||
return controlling ? (int)controlx : input.getX();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getY(int pointer) {
|
|
||||||
return pointer == 0 ? getY() : super.getY(pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getX(int pointer) {
|
|
||||||
return pointer == 0 ? getX() : super.getX(pointer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Effects.setShakeFalloff(10000f);
|
Effects.setShakeFalloff(10000f);
|
||||||
|
|
||||||
Core.atlas = new Atlas("sprites.atlas");
|
Core.atlas = new Atlas("sprites.atlas");
|
||||||
@@ -88,6 +59,32 @@ public class Control extends Module{
|
|||||||
item.init();
|
item.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gdxInput = Gdx.input;
|
||||||
|
|
||||||
|
proxy = new InputProxy(Gdx.input){
|
||||||
|
@Override
|
||||||
|
public int getX(int pointer) {
|
||||||
|
return pointer >= inputs.length ? super.getX(pointer) : (int)inputs[pointer].getMouseX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY(int pointer) {
|
||||||
|
return pointer >= inputs.length ? super.getY(pointer) : (int)inputs[pointer].getMouseY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return (int)inputs[0].getMouseX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
return (int)inputs[0].getMouseY();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Gdx.input = proxy;
|
||||||
|
|
||||||
Sounds.load("shoot.mp3", "place.mp3", "explosion.mp3", "enemyshoot.mp3",
|
Sounds.load("shoot.mp3", "place.mp3", "explosion.mp3", "enemyshoot.mp3",
|
||||||
"corexplode.mp3", "break.mp3", "spawn.mp3", "flame.mp3", "die.mp3",
|
"corexplode.mp3", "break.mp3", "spawn.mp3", "flame.mp3", "die.mp3",
|
||||||
"respawn.mp3", "purchase.mp3", "flame2.mp3", "bigshot.mp3", "laser.mp3", "lasershot.mp3",
|
"respawn.mp3", "purchase.mp3", "flame2.mp3", "bigshot.mp3", "laser.mp3", "lasershot.mp3",
|
||||||
@@ -102,8 +99,11 @@ public class Control extends Module{
|
|||||||
Settings.defaultList(
|
Settings.defaultList(
|
||||||
"ip", "localhost",
|
"ip", "localhost",
|
||||||
"port", port+"",
|
"port", port+"",
|
||||||
"servers", "",
|
"color-0", Color.rgba8888(playerColors[8]),
|
||||||
"color", Color.rgba8888(playerColors[8]),
|
"color-1", Color.rgba8888(playerColors[11]),
|
||||||
|
"color-2", Color.rgba8888(playerColors[13]),
|
||||||
|
"color-3", Color.rgba8888(playerColors[9]),
|
||||||
|
"name", "player",
|
||||||
"lastBuild", 0
|
"lastBuild", 0
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -156,7 +156,6 @@ public class Control extends Module{
|
|||||||
Events.on(GameOverEvent.class, () -> {
|
Events.on(GameOverEvent.class, () -> {
|
||||||
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
|
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
|
||||||
|
|
||||||
|
|
||||||
//TODO game over effect
|
//TODO game over effect
|
||||||
ui.restart.show();
|
ui.restart.show();
|
||||||
|
|
||||||
@@ -166,10 +165,20 @@ public class Control extends Module{
|
|||||||
|
|
||||||
//TODO drop player method
|
//TODO drop player method
|
||||||
public void addPlayer(int index){
|
public void addPlayer(int index){
|
||||||
|
if(players.length < index + 1){
|
||||||
|
Player[] old = players;
|
||||||
|
players = new Player[index + 1];
|
||||||
|
System.arraycopy(old, 0, players, 0, old.length);
|
||||||
|
|
||||||
|
InputHandler[] oldi = inputs;
|
||||||
|
inputs = new InputHandler[index + 1];
|
||||||
|
System.arraycopy(old, 0, inputs, 0, oldi.length);
|
||||||
|
}
|
||||||
|
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.name = Settings.getString("name-" + index, "player");
|
player.name = Settings.getString("name");
|
||||||
player.mech = mobile ? Mechs.standardShip : Mechs.standard;
|
player.mech = mobile ? Mechs.standardShip : Mechs.standard;
|
||||||
player.color.set(Settings.getInt("color"));
|
player.color.set(Settings.getInt("color-" + index));
|
||||||
player.isLocal = true;
|
player.isLocal = true;
|
||||||
player.playerIndex = index;
|
player.playerIndex = index;
|
||||||
players[index] = player;
|
players[index] = player;
|
||||||
@@ -186,9 +195,8 @@ public class Control extends Module{
|
|||||||
Inputs.addProcessor(input);
|
Inputs.addProcessor(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME figure out what's causing this problem in the first place
|
public Input gdxInput(){
|
||||||
public void triggerInputUpdate(){
|
return gdxInput;
|
||||||
Gdx.input = proxy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setError(Throwable error){
|
public void setError(Throwable error){
|
||||||
@@ -199,14 +207,14 @@ public class Control extends Module{
|
|||||||
return saves;
|
return saves;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean showCursor(){
|
|
||||||
return controlling;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputHandler input(int index){
|
public InputHandler input(int index){
|
||||||
return inputs[index];
|
return inputs[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void triggerUpdateInput(){
|
||||||
|
Gdx.input = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
public void playMap(Map map){
|
public void playMap(Map map){
|
||||||
ui.loadfrag.show();
|
ui.loadfrag.show();
|
||||||
saves.resetSave();
|
saves.resetSave();
|
||||||
@@ -224,10 +232,6 @@ public class Control extends Module{
|
|||||||
return hiscore;
|
return hiscore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tutorial tutorial(){
|
|
||||||
return tutorial;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
Platform.instance.onGameExit();
|
Platform.instance.onGameExit();
|
||||||
@@ -261,52 +265,10 @@ public class Control extends Module{
|
|||||||
throw new RuntimeException(error);
|
throw new RuntimeException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.input = proxy;
|
|
||||||
|
|
||||||
if(Inputs.keyTap("console")){
|
if(Inputs.keyTap("console")){
|
||||||
console = !console;
|
console = !console;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(KeyBinds.getSection("default").device.type == DeviceType.controller){
|
|
||||||
if(Inputs.keyTap("select")){
|
|
||||||
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Inputs.keyRelease("select")){
|
|
||||||
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
float xa = Inputs.getAxis("cursor_x");
|
|
||||||
float ya = Inputs.getAxis("cursor_y");
|
|
||||||
|
|
||||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
|
||||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
|
||||||
controlx += xa*baseControllerSpeed*scl;
|
|
||||||
controly -= ya*baseControllerSpeed*scl;
|
|
||||||
controlling = true;
|
|
||||||
|
|
||||||
Gdx.input.setCursorCatched(true);
|
|
||||||
|
|
||||||
Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
|
||||||
controly = Mathf.clamp(controly, 0, Gdx.graphics.getHeight());
|
|
||||||
|
|
||||||
if(Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1) {
|
|
||||||
controlling = false;
|
|
||||||
Gdx.input.setCursorCatched(false);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
controlling = false;
|
|
||||||
Gdx.input.setCursorCatched(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!controlling){
|
|
||||||
controlx = Gdx.input.getX();
|
|
||||||
controly = Gdx.input.getY();
|
|
||||||
}
|
|
||||||
|
|
||||||
saves.update();
|
saves.update();
|
||||||
|
|
||||||
if(!state.is(State.menu)){
|
if(!state.is(State.menu)){
|
||||||
@@ -335,10 +297,6 @@ public class Control extends Module{
|
|||||||
if(!state.is(State.paused) || Net.active()){
|
if(!state.is(State.paused) || Net.active()){
|
||||||
Entities.update(effectGroup);
|
Entities.update(effectGroup);
|
||||||
Entities.update(groundEffectGroup);
|
Entities.update(groundEffectGroup);
|
||||||
|
|
||||||
if(tutorial.active()){
|
|
||||||
tutorial.update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(!state.is(State.paused) || Net.active()){
|
if(!state.is(State.paused) || Net.active()){
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class Logic extends Module {
|
|||||||
|
|
||||||
if(!state.is(State.menu)){
|
if(!state.is(State.menu)){
|
||||||
|
|
||||||
if(control != null) control.triggerInputUpdate();
|
if(control != null) control.triggerUpdateInput();
|
||||||
|
|
||||||
if(!state.is(State.paused) || Net.active()){
|
if(!state.is(State.paused) || Net.active()){
|
||||||
Timers.update();
|
Timers.update();
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public class NetClient extends Module {
|
|||||||
public NetClient(){
|
public NetClient(){
|
||||||
|
|
||||||
Net.handleClient(Connect.class, packet -> {
|
Net.handleClient(Connect.class, packet -> {
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
player.isAdmin = false;
|
player.isAdmin = false;
|
||||||
|
|
||||||
Net.setClientLoaded(false);
|
Net.setClientLoaded(false);
|
||||||
@@ -71,7 +73,7 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
ConnectPacket c = new ConnectPacket();
|
ConnectPacket c = new ConnectPacket();
|
||||||
c.name = player.name;
|
c.name = player.name;
|
||||||
c.android = mobile;
|
c.mobile = mobile;
|
||||||
c.color = Color.rgba8888(player.color);
|
c.color = Color.rgba8888(player.color);
|
||||||
c.uuid = Platform.instance.getUUID();
|
c.uuid = Platform.instance.getUUID();
|
||||||
|
|
||||||
@@ -101,13 +103,14 @@ public class NetClient extends Module {
|
|||||||
Net.handleClient(WorldData.class, data -> {
|
Net.handleClient(WorldData.class, data -> {
|
||||||
Log.info("Recieved world data: {0} bytes.", data.stream.available());
|
Log.info("Recieved world data: {0} bytes.", data.stream.available());
|
||||||
NetworkIO.loadWorld(data.stream);
|
NetworkIO.loadWorld(data.stream);
|
||||||
player.set(world.getSpawnX(), world.getSpawnY());
|
|
||||||
|
|
||||||
finishConnecting();
|
finishConnecting();
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handleClient(SyncPacket.class, packet -> {
|
Net.handleClient(SyncPacket.class, packet -> {
|
||||||
if (connecting) return;
|
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
int players = 0;
|
int players = 0;
|
||||||
int enemies = 0;
|
int enemies = 0;
|
||||||
|
|
||||||
@@ -256,7 +259,6 @@ public class NetClient extends Module {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleClient(GameOverPacket.class, packet -> {
|
Net.handleClient(GameOverPacket.class, packet -> {
|
||||||
//TODO core death effects
|
|
||||||
quiet = true;
|
quiet = true;
|
||||||
ui.restart.show();
|
ui.restart.show();
|
||||||
});
|
});
|
||||||
@@ -272,7 +274,7 @@ public class NetClient extends Module {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleClient(UpgradePacket.class, packet -> {
|
Net.handleClient(UpgradePacket.class, packet -> {
|
||||||
Weapon weapon = Upgrade.getByID(packet.id);
|
Weapon weapon = Upgrade.getByID(packet.upgradeid);
|
||||||
|
|
||||||
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
||||||
for(Player player : players) {
|
for(Player player : players) {
|
||||||
@@ -326,20 +328,16 @@ public class NetClient extends Module {
|
|||||||
Net.disconnect();
|
Net.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearRecieved(){
|
|
||||||
recieved.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void sync(){
|
void sync(){
|
||||||
requests = 0;
|
requests = 0;
|
||||||
|
|
||||||
if(timer.get(0, playerSyncTime)){
|
if(timer.get(0, playerSyncTime)){
|
||||||
for(Player player : players) {
|
Player player = players[0];
|
||||||
|
|
||||||
PositionPacket packet = new PositionPacket();
|
PositionPacket packet = new PositionPacket();
|
||||||
packet.player = player;
|
packet.player = player;
|
||||||
Net.send(packet, SendMode.udp);
|
Net.send(packet, SendMode.udp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(timer.get(1, 60)){
|
if(timer.get(1, 60)){
|
||||||
Net.updatePing();
|
Net.updatePing();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.core;
|
|||||||
import com.badlogic.gdx.utils.Base64Coder;
|
import com.badlogic.gdx.utils.Base64Coder;
|
||||||
import com.badlogic.gdx.utils.IntMap;
|
import com.badlogic.gdx.utils.IntMap;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.content.Mechs;
|
import io.anuke.mindustry.content.Mechs;
|
||||||
import io.anuke.mindustry.content.Recipes;
|
import io.anuke.mindustry.content.Recipes;
|
||||||
import io.anuke.mindustry.content.UpgradeRecipes;
|
import io.anuke.mindustry.content.UpgradeRecipes;
|
||||||
@@ -67,7 +68,7 @@ public class NetServer extends Module{
|
|||||||
TraceInfo trace = admins.getTraceByID(uuid);
|
TraceInfo trace = admins.getTraceByID(uuid);
|
||||||
PlayerInfo info = admins.getInfo(uuid);
|
PlayerInfo info = admins.getInfo(uuid);
|
||||||
trace.uuid = uuid;
|
trace.uuid = uuid;
|
||||||
trace.android = packet.android;
|
trace.android = packet.mobile;
|
||||||
|
|
||||||
if(admins.isIDBanned(uuid)){
|
if(admins.isIDBanned(uuid)){
|
||||||
kick(id, KickReason.banned);
|
kick(id, KickReason.banned);
|
||||||
@@ -106,7 +107,7 @@ public class NetServer extends Module{
|
|||||||
player.clientid = id;
|
player.clientid = id;
|
||||||
player.name = packet.name;
|
player.name = packet.name;
|
||||||
player.uuid = uuid;
|
player.uuid = uuid;
|
||||||
player.mech = packet.android ? Mechs.standardShip : Mechs.standard;
|
player.mech = packet.mobile ? Mechs.standardShip : Mechs.standard;
|
||||||
player.set(world.getSpawnX(), world.getSpawnY());
|
player.set(world.getSpawnX(), world.getSpawnY());
|
||||||
player.setNet(player.x, player.y);
|
player.setNet(player.x, player.y);
|
||||||
player.setNet(player.x, player.y);
|
player.setNet(player.x, player.y);
|
||||||
@@ -261,6 +262,12 @@ public class NetServer extends Module{
|
|||||||
Net.sendTo(id, warn, SendMode.tcp);
|
Net.sendTo(id, warn, SendMode.tcp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(packet.text.length() > Vars.maxTextLength){
|
||||||
|
ChatPacket warn = new ChatPacket();
|
||||||
|
warn.text = "[scarlet]That message is too long.";
|
||||||
|
Net.sendTo(id, warn, SendMode.tcp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Player player = connections.get(id);
|
Player player = connections.get(id);
|
||||||
packet.name = player.name;
|
packet.name = player.name;
|
||||||
packet.id = player.id;
|
packet.id = player.id;
|
||||||
@@ -270,7 +277,7 @@ public class NetServer extends Module{
|
|||||||
Net.handleServer(UpgradePacket.class, (id, packet) -> {
|
Net.handleServer(UpgradePacket.class, (id, packet) -> {
|
||||||
Player player = connections.get(id);
|
Player player = connections.get(id);
|
||||||
|
|
||||||
Weapon weapon = Upgrade.getByID(packet.id);
|
Weapon weapon = Upgrade.getByID(packet.upgradeid);
|
||||||
|
|
||||||
if(!state.inventory.hasItems(UpgradeRecipes.get(weapon))){
|
if(!state.inventory.hasItems(UpgradeRecipes.get(weapon))){
|
||||||
return;
|
return;
|
||||||
@@ -283,7 +290,7 @@ public class NetServer extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
||||||
Net.sendTo(id, packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(WeaponSwitchPacket.class, (id, packet) -> {
|
Net.handleServer(WeaponSwitchPacket.class, (id, packet) -> {
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ public class Renderer extends RendererModule{
|
|||||||
for(Player player : players){
|
for(Player player : players){
|
||||||
avgPosition.add(player.x, player.y);
|
avgPosition.add(player.x, player.y);
|
||||||
}
|
}
|
||||||
|
avgPosition.scl(1f / players.length);
|
||||||
return avgPosition;
|
return avgPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Interpolation;
|
|||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.editor.MapEditorDialog;
|
import io.anuke.mindustry.editor.MapEditorDialog;
|
||||||
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.ui.dialogs.*;
|
import io.anuke.mindustry.ui.dialogs.*;
|
||||||
import io.anuke.mindustry.ui.fragments.*;
|
import io.anuke.mindustry.ui.fragments.*;
|
||||||
@@ -19,6 +20,7 @@ import io.anuke.ucore.function.Consumer;
|
|||||||
import io.anuke.ucore.function.Listenable;
|
import io.anuke.ucore.function.Listenable;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.modules.SceneModule;
|
import io.anuke.ucore.modules.SceneModule;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.Skin;
|
import io.anuke.ucore.scene.Skin;
|
||||||
import io.anuke.ucore.scene.builders.build;
|
import io.anuke.ucore.scene.builders.build;
|
||||||
import io.anuke.ucore.scene.ui.Dialog;
|
import io.anuke.ucore.scene.ui.Dialog;
|
||||||
@@ -52,16 +54,13 @@ public class UI extends SceneModule{
|
|||||||
public ChangelogDialog changelog;
|
public ChangelogDialog changelog;
|
||||||
|
|
||||||
public final MenuFragment menufrag = new MenuFragment();
|
public final MenuFragment menufrag = new MenuFragment();
|
||||||
public final ToolFragment toolfrag = new ToolFragment();
|
|
||||||
public final HudFragment hudfrag = new HudFragment();
|
public final HudFragment hudfrag = new HudFragment();
|
||||||
public final PlacementFragment placefrag = new PlacementFragment();
|
public final PlacementFragment placefrag = new PlacementFragment();
|
||||||
public final ChatFragment chatfrag = new ChatFragment();
|
public final ChatFragment chatfrag = new ChatFragment();
|
||||||
public final PlayerListFragment listfrag = new PlayerListFragment();
|
public final PlayerListFragment listfrag = new PlayerListFragment();
|
||||||
public final BackgroundFragment backfrag = new BackgroundFragment();
|
public final BackgroundFragment backfrag = new BackgroundFragment();
|
||||||
public final LoadingFragment loadfrag = new LoadingFragment();
|
public final LoadingFragment loadfrag = new LoadingFragment();
|
||||||
public final BlockConfigFragment configfrag = new BlockConfigFragment();
|
|
||||||
public final DebugFragment debugfrag = new DebugFragment();
|
public final DebugFragment debugfrag = new DebugFragment();
|
||||||
public final BlockInventoryFragment blockinvfrag = new BlockInventoryFragment();
|
|
||||||
public final PlayerMenuFragment playermenufrag = new PlayerMenuFragment();
|
public final PlayerMenuFragment playermenufrag = new PlayerMenuFragment();
|
||||||
|
|
||||||
private Locale lastLocale;
|
private Locale lastLocale;
|
||||||
@@ -134,19 +133,24 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
act();
|
act();
|
||||||
|
|
||||||
if(debug && !ui.chatfrag.chatOpen())
|
if(debug && !ui.chatfrag.chatOpen()) {
|
||||||
renderer.record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
renderer.record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
||||||
|
}
|
||||||
|
|
||||||
if(control.showCursor()) {
|
for(int i = 0; i < players.length; i ++){
|
||||||
|
InputHandler input = control.input(i);
|
||||||
|
|
||||||
|
if(input.isCursorVisible()) {
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|
||||||
float scl = Unit.dp.scl(3f);
|
float scl = Unit.dp.scl(3f);
|
||||||
|
|
||||||
Graphics.begin();
|
Graphics.begin();
|
||||||
Draw.rect("controller-cursor", Graphics.mouse().x, Graphics.mouse().y, 16*scl, 16*scl);
|
Draw.rect("controller-cursor", input.getMouseX(), Gdx.graphics.getHeight() - input.getMouseY(), 16*scl, 16*scl);
|
||||||
Graphics.end();
|
Graphics.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
@@ -170,18 +174,17 @@ public class UI extends SceneModule{
|
|||||||
|
|
||||||
build.begin(scene);
|
build.begin(scene);
|
||||||
|
|
||||||
backfrag.build();
|
Group group = Core.scene.getRoot();
|
||||||
hudfrag.build();
|
|
||||||
configfrag.build();
|
backfrag.build(group);
|
||||||
menufrag.build();
|
hudfrag.build(group);
|
||||||
placefrag.build();
|
menufrag.build(group);
|
||||||
toolfrag.build();
|
placefrag.build(group);
|
||||||
chatfrag.build();
|
chatfrag.build(group);
|
||||||
listfrag.build();
|
listfrag.build(group);
|
||||||
debugfrag.build();
|
debugfrag.build(group);
|
||||||
blockinvfrag.build();
|
playermenufrag.build(group);
|
||||||
playermenufrag.build();
|
loadfrag.build(group);
|
||||||
loadfrag.build();
|
|
||||||
|
|
||||||
build.end();
|
build.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ public class Player extends Unit{
|
|||||||
movement.y += ya*speed;
|
movement.y += ya*speed;
|
||||||
movement.x += xa*speed;
|
movement.x += xa*speed;
|
||||||
|
|
||||||
boolean shooting = control.input().canShoot() && control.input().isShooting() && inventory.hasAmmo();
|
boolean shooting = control.input(playerIndex).canShoot() && control.input(playerIndex).isShooting() && inventory.hasAmmo();
|
||||||
|
|
||||||
if(shooting){
|
if(shooting){
|
||||||
weapon.update(this, true);
|
weapon.update(this, true);
|
||||||
|
|||||||
@@ -244,7 +244,6 @@ public class Tutorial{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onSwitch(){
|
void onSwitch(){
|
||||||
control.input().recipe = null;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
drillInfo{
|
drillInfo{
|
||||||
@@ -320,7 +319,6 @@ public class Tutorial{
|
|||||||
//world.tile(world.getCore().x + 2, world.getCore().y - 2 + i).setBlock(DistributionBlocks.conveyor, 1);
|
//world.tile(world.getCore().x + 2, world.getCore().y - 2 + i).setBlock(DistributionBlocks.conveyor, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
control.input().recipe = null;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
turretExplanation{
|
turretExplanation{
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ public class BlockRenderer{
|
|||||||
private int requestidx = 0;
|
private int requestidx = 0;
|
||||||
private int iterateidx = 0;
|
private int iterateidx = 0;
|
||||||
|
|
||||||
private float storeX, storeY;
|
|
||||||
|
|
||||||
public BlockRenderer(){
|
public BlockRenderer(){
|
||||||
floorRenderer = new FloorRenderer();
|
floorRenderer = new FloorRenderer();
|
||||||
|
|
||||||
@@ -205,40 +203,4 @@ public class BlockRenderer{
|
|||||||
r.layer = layer;
|
r.layer = layer;
|
||||||
requestidx ++;
|
requestidx ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawPreview(Block block, float drawx, float drawy, float rotation, float opacity) {
|
|
||||||
Draw.alpha(opacity);
|
|
||||||
Draw.rect(block.name(), drawx, drawy, rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handlePreview(Block block, float rotation, float drawx, float drawy, int tilex, int tiley) {
|
|
||||||
|
|
||||||
if(control.input().recipe != null && state.inventory.hasItems(control.input().recipe.requirements)
|
|
||||||
&& control.input().validPlace(tilex, tiley, block) && (mobile || control.input().cursorNear())) {
|
|
||||||
|
|
||||||
if(block.isMultiblock()) {
|
|
||||||
float halfBlockWidth = (block.size * tilesize) / 2;
|
|
||||||
float halfBlockHeight = (block.size * tilesize) / 2;
|
|
||||||
if((storeX == 0 && storeY == 0)) {
|
|
||||||
storeX = drawx;
|
|
||||||
storeY = drawy;
|
|
||||||
}
|
|
||||||
if((storeX == drawx - halfBlockWidth || storeX == drawx + halfBlockWidth || storeY == drawy - halfBlockHeight || storeY == drawy + halfBlockHeight) &&
|
|
||||||
((tiley - control.input().getBlockY()) % block.size != 0 || (tilex - control.input().getBlockX()) % block.size != 0)) {
|
|
||||||
return;
|
|
||||||
}else{
|
|
||||||
storeX = drawx;
|
|
||||||
storeY = drawy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float opacity = (float) Settings.getInt("previewopacity") / 100f;
|
|
||||||
Draw.color(Color.WHITE);
|
|
||||||
Draw.alpha(opacity);
|
|
||||||
|
|
||||||
drawPreview(block, drawx, drawy, rotation, opacity);
|
|
||||||
|
|
||||||
Draw.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package io.anuke.mindustry.graphics;
|
package io.anuke.mindustry.graphics;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Colors;
|
import com.badlogic.gdx.graphics.Colors;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||||
import io.anuke.mindustry.input.InputHandler;
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
@@ -31,53 +31,49 @@ public class OverlayRenderer {
|
|||||||
|
|
||||||
public void draw(){
|
public void draw(){
|
||||||
|
|
||||||
|
for(Player player : players) {
|
||||||
|
|
||||||
|
InputHandler input = control.input(player.playerIndex);
|
||||||
|
|
||||||
//draw config selected block
|
//draw config selected block
|
||||||
if(ui.configfrag.isShown()){
|
if(input.frag.config.isShown()){
|
||||||
Tile tile = ui.configfrag.getSelectedTile();
|
Tile tile = input.frag.config.getSelectedTile();
|
||||||
tile.block().drawConfigure(tile);
|
tile.block().drawConfigure(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tilex = control.input().getBlockX();
|
int tilex = input.getBlockX();
|
||||||
int tiley = control.input().getBlockY();
|
int tiley = input.getBlockY();
|
||||||
|
|
||||||
if(mobile){
|
|
||||||
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
|
|
||||||
tilex = Mathf.scl2(vec.x, tilesize);
|
|
||||||
tiley = Mathf.scl2(vec.y, tilesize);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputHandler input = control.input();
|
|
||||||
|
|
||||||
//draw placement box
|
//draw placement box
|
||||||
if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
||||||
&& control.input().drawPlace())){
|
&& input.drawPlace())) {
|
||||||
|
|
||||||
input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
input.placeMode.draw(input, input.getBlockX(),
|
||||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||||
|
|
||||||
if (input.breakMode == PlaceMode.holdDelete)
|
if (input.breakMode == PlaceMode.holdDelete)
|
||||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||||
|
|
||||||
}else if(input.breakMode.delete && control.input().drawPlace()
|
} else if (input.breakMode.delete && input.drawPlace()
|
||||||
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
||||||
&& (input.placeMode.delete || input.breakMode.both || !mobile)) {
|
&& (input.placeMode.delete || input.breakMode.both || !mobile)) {
|
||||||
|
|
||||||
if (input.breakMode == PlaceMode.holdDelete)
|
if (input.breakMode == PlaceMode.holdDelete)
|
||||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||||
else
|
else
|
||||||
input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
input.breakMode.draw(input, input.getBlockX(),
|
||||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ui.toolfrag.confirming){
|
if (input.frag.tool.confirming) {
|
||||||
ToolFragment t = ui.toolfrag;
|
ToolFragment t = input.frag.tool;
|
||||||
PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
|
PlaceMode.areaDelete.draw(input, t.px, t.py, t.px2, t.py2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
//draw selected block bars and info
|
//draw selected block bars and info
|
||||||
if(input.recipe == null && !ui.hasMouse() && !ui.configfrag.isShown()){
|
if (input.recipe == null && !ui.hasMouse() && !input.frag.config.isShown()) {
|
||||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||||
|
|
||||||
if (tile != null && tile.block() != Blocks.air) {
|
if (tile != null && tile.block() != Blocks.air) {
|
||||||
@@ -137,7 +133,7 @@ public class OverlayRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(control.input().isDroppingItem()){
|
if (input.isDroppingItem()) {
|
||||||
Vector2 v = Graphics.mouseWorld();
|
Vector2 v = Graphics.mouseWorld();
|
||||||
float size = 8;
|
float size = 8;
|
||||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||||
@@ -154,6 +150,8 @@ public class OverlayRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||||
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
|
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
|
||||||
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ public class AndroidInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(placing && pointer == 0 && !placeMode.pan && !breaking()){
|
if(placing && pointer == 0 && !placeMode.pan && !breaking()){
|
||||||
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||||
}else if(pointer == 0 && !breakMode.pan && breaking() && drawPlace()){
|
}else if(pointer == 0 && !breakMode.pan && breaking() && drawPlace()){
|
||||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||||
}
|
}
|
||||||
|
|
||||||
placing = false;
|
placing = false;
|
||||||
@@ -79,9 +79,9 @@ public class AndroidInput extends InputHandler{
|
|||||||
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
||||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||||
if(linked != null && linked.block().isConfigurable(linked)){
|
if(linked != null && linked.block().isConfigurable(linked)){
|
||||||
ui.configfrag.showConfig(linked);
|
frag.config.showConfig(linked);
|
||||||
}else if(!ui.configfrag.hasConfigMouse()){
|
}else if(!frag.config.hasConfigMouse()){
|
||||||
ui.configfrag.hideConfig();
|
frag.config.hideConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(linked != null) {
|
if(linked != null) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.input;
|
package io.anuke.mindustry.input;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input.Buttons;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
@@ -8,13 +9,10 @@ import io.anuke.mindustry.net.Net;
|
|||||||
import io.anuke.mindustry.net.NetEvents;
|
import io.anuke.mindustry.net.NetEvents;
|
||||||
import io.anuke.mindustry.resource.Weapon;
|
import io.anuke.mindustry.resource.Weapon;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.core.Inputs;
|
|
||||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||||
import io.anuke.ucore.core.KeyBinds;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.core.Timers;
|
|
||||||
import io.anuke.ucore.scene.utils.Cursors;
|
import io.anuke.ucore.scene.utils.Cursors;
|
||||||
import io.anuke.ucore.util.Input;
|
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -22,8 +20,10 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
public class DesktopInput extends InputHandler{
|
public class DesktopInput extends InputHandler{
|
||||||
float mousex, mousey;
|
float mousex, mousey;
|
||||||
float endx, endy;
|
float endx, endy;
|
||||||
|
private float controlx, controly;
|
||||||
private boolean enableHold = false;
|
private boolean enableHold = false;
|
||||||
private boolean beganBreak;
|
private boolean beganBreak;
|
||||||
|
private boolean controlling;
|
||||||
|
|
||||||
public DesktopInput(Player player){
|
public DesktopInput(Player player){
|
||||||
super(player);
|
super(player);
|
||||||
@@ -37,14 +37,17 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
|
updateController();
|
||||||
|
|
||||||
if(player.isDead()) return;
|
if(player.isDead()) return;
|
||||||
|
|
||||||
if(Inputs.keyRelease("select")){
|
if(Inputs.keyRelease("select")){
|
||||||
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyRelease("break") && !beganBreak){
|
if(Inputs.keyRelease("break") && !beganBreak){
|
||||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Inputs.keyDown("select")){
|
if(!Inputs.keyDown("select")){
|
||||||
@@ -104,7 +107,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
if(Inputs.keyTap("weapon_" + keyIndex)){
|
if(Inputs.keyTap("weapon_" + keyIndex)){
|
||||||
player.weapon = (Weapon) player.upgrades.get(i);
|
player.weapon = (Weapon) player.upgrades.get(i);
|
||||||
if(Net.active()) NetEvents.handleWeaponSwitch();
|
if(Net.active()) NetEvents.handleWeaponSwitch(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
keyIndex ++;
|
keyIndex ++;
|
||||||
@@ -126,13 +129,13 @@ public class DesktopInput extends InputHandler{
|
|||||||
showCursor = true;
|
showCursor = true;
|
||||||
if(Inputs.keyTap("select")){
|
if(Inputs.keyTap("select")){
|
||||||
canBeginShoot = false;
|
canBeginShoot = false;
|
||||||
ui.blockinvfrag.showFor(target);
|
frag.inv.showFor(target);
|
||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){
|
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){
|
||||||
ui.blockinvfrag.hide();
|
frag.inv.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(target != null && target.block().isConfigurable(target)){
|
if(target != null && target.block().isConfigurable(target)){
|
||||||
@@ -141,14 +144,14 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
|
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
|
||||||
if(target.block().isConfigurable(target)){
|
if(target.block().isConfigurable(target)){
|
||||||
if((!ui.configfrag.isShown()
|
if((!frag.config.isShown()
|
||||||
|| ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor))) {
|
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
||||||
ui.configfrag.showConfig(target);
|
frag.config.showConfig(target);
|
||||||
canBeginShoot = false;
|
canBeginShoot = false;
|
||||||
}
|
}
|
||||||
}else if(!ui.configfrag.hasConfigMouse()){
|
}else if(!frag.config.hasConfigMouse()){
|
||||||
if(ui.configfrag.isShown() && ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor)) {
|
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor)) {
|
||||||
ui.configfrag.hideConfig();
|
frag.config.hideConfig();
|
||||||
canBeginShoot = false;
|
canBeginShoot = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,7 +161,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyTap("break")){
|
if(Inputs.keyTap("break")){
|
||||||
ui.configfrag.hideConfig();
|
frag.config.hideConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Inputs.keyRelease("break")){
|
if(Inputs.keyRelease("break")){
|
||||||
@@ -196,6 +199,61 @@ public class DesktopInput extends InputHandler{
|
|||||||
Cursors.restoreCursor();
|
Cursors.restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMouseX() {
|
||||||
|
return controlx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMouseY() {
|
||||||
|
return controly;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCursorVisible() {
|
||||||
|
return controlling;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateController(){
|
||||||
|
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||||
|
|
||||||
|
if(KeyBinds.getSection("default").device.type == DeviceType.controller && !mousemove){
|
||||||
|
if(Inputs.keyTap("select")){
|
||||||
|
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Inputs.keyRelease("select")){
|
||||||
|
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xa = Inputs.getAxis("cursor_x");
|
||||||
|
float ya = Inputs.getAxis("cursor_y");
|
||||||
|
|
||||||
|
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
||||||
|
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
||||||
|
controlx += xa*baseControllerSpeed*scl;
|
||||||
|
controly -= ya*baseControllerSpeed*scl;
|
||||||
|
controlling = true;
|
||||||
|
|
||||||
|
Gdx.input.setCursorCatched(true);
|
||||||
|
|
||||||
|
Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
||||||
|
controly = Mathf.clamp(controly, 0, Gdx.graphics.getHeight());
|
||||||
|
}else{
|
||||||
|
controlling = false;
|
||||||
|
Gdx.input.setCursorCatched(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!controlling){
|
||||||
|
controlx = control.gdxInput().getX();
|
||||||
|
controly = control.gdxInput().getY();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int tilex(){
|
public int tilex(){
|
||||||
|
|||||||
@@ -30,30 +30,30 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
public boolean tap (float x, float y, int count, int button) {
|
public boolean tap (float x, float y, int count, int button) {
|
||||||
if(ui.hasMouse() || input.brokeBlock) return false;
|
if(ui.hasMouse() || input.brokeBlock) return false;
|
||||||
|
|
||||||
if(!control.input().placeMode.pan || control.input().recipe == null){
|
if(!input.placeMode.pan || input.recipe == null){
|
||||||
input.mousex = x;
|
input.mousex = x;
|
||||||
input.mousey = y;
|
input.mousey = y;
|
||||||
|
|
||||||
if(control.input().recipe == null)
|
if(input.recipe == null)
|
||||||
control.input().breakMode.tapped(input.getBlockX(), input.getBlockY());
|
input.breakMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||||
else
|
else
|
||||||
control.input().placeMode.tapped(input.getBlockX(), input.getBlockY());
|
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||||
if(control.showCursor() && !Inputs.keyDown("select")) return false;
|
if(input.isCursorVisible() && !Inputs.keyDown("select")) return false;
|
||||||
|
|
||||||
if(!control.showCursor() && !(control.input().recipe != null
|
if(!input.isCursorVisible() && !(input.recipe != null
|
||||||
&& control.input().placeMode.lockCamera && state.inventory.hasItems(control.input().recipe.requirements)) &&
|
&& input.placeMode.lockCamera && state.inventory.hasItems(input.recipe.requirements)) &&
|
||||||
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
|
!(input.recipe == null && input.breakMode.lockCamera)){
|
||||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||||
player.x -= dx;
|
input.player.x -= dx;
|
||||||
player.y += dy;
|
input.player.y += dy;
|
||||||
player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
input.player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||||
}else if(control.input().placeMode.lockCamera && (control.input().placeMode.pan && control.input().recipe != null)){
|
}else if(input.placeMode.lockCamera && (input.placeMode.pan && input.recipe != null)){
|
||||||
input.mousex += deltaX;
|
input.mousex += deltaX;
|
||||||
input.mousey += deltaY;
|
input.mousey += deltaY;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||||
if(control.input().recipe == null && !control.input().breakMode.lockCamera)
|
if(input.recipe == null && !input.breakMode.lockCamera)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(pinch1.x < 0){
|
if(pinch1.x < 0){
|
||||||
@@ -73,8 +73,8 @@ public class GestureHandler extends GestureAdapter{
|
|||||||
|
|
||||||
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
||||||
|
|
||||||
player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
input.player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||||
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
input.player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||||
|
|
||||||
pinch1.set(pointer1);
|
pinch1.set(pointer1);
|
||||||
pinch2.set(pointer2);
|
pinch2.set(pointer2);
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ import io.anuke.mindustry.net.Net;
|
|||||||
import io.anuke.mindustry.net.NetEvents;
|
import io.anuke.mindustry.net.NetEvents;
|
||||||
import io.anuke.mindustry.resource.ItemStack;
|
import io.anuke.mindustry.resource.ItemStack;
|
||||||
import io.anuke.mindustry.resource.Recipe;
|
import io.anuke.mindustry.resource.Recipe;
|
||||||
|
import io.anuke.mindustry.ui.fragments.OverlayFragment;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Placement;
|
import io.anuke.mindustry.world.Placement;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
@@ -23,6 +26,9 @@ import io.anuke.ucore.util.Translator;
|
|||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public abstract class InputHandler extends InputAdapter{
|
public abstract class InputHandler extends InputAdapter{
|
||||||
|
public final static float playerSelectRange = Unit.dp.scl(60f);
|
||||||
|
private final static Translator stackTrns = new Translator();
|
||||||
|
|
||||||
public float breaktime = 0;
|
public float breaktime = 0;
|
||||||
public Recipe recipe;
|
public Recipe recipe;
|
||||||
public int rotation;
|
public int rotation;
|
||||||
@@ -33,12 +39,11 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
public PlaceMode lastBreakMode = breakMode;
|
public PlaceMode lastBreakMode = breakMode;
|
||||||
public boolean droppingItem, transferring;
|
public boolean droppingItem, transferring;
|
||||||
public boolean shooting;
|
public boolean shooting;
|
||||||
public float playerSelectRange = Unit.dp.scl(60f);
|
public OverlayFragment frag = new OverlayFragment(this);
|
||||||
|
|
||||||
private Translator stackTrns = new Translator();
|
|
||||||
|
|
||||||
public InputHandler(Player player){
|
public InputHandler(Player player){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
@@ -46,11 +51,19 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
public abstract float getCursorY();
|
public abstract float getCursorY();
|
||||||
public abstract float getCursorEndX();
|
public abstract float getCursorEndX();
|
||||||
public abstract float getCursorEndY();
|
public abstract float getCursorEndY();
|
||||||
|
public float getMouseX(){ return Gdx.input.getX(); };
|
||||||
|
public float getMouseY(){ return Gdx.input.getY(); };
|
||||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
|
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
|
||||||
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
|
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
|
||||||
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
||||||
public void resetCursor(){}
|
public void resetCursor(){}
|
||||||
|
public boolean isCursorVisible(){ return false; }
|
||||||
|
|
||||||
|
public void remove(){
|
||||||
|
Inputs.removeProcessor(this);
|
||||||
|
frag.remove();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canShoot(){
|
public boolean canShoot(){
|
||||||
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
||||||
@@ -183,7 +196,7 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Net.active()){
|
if(Net.active()){
|
||||||
NetEvents.handlePlace(x, y, result, rotation);
|
NetEvents.handlePlace(player, x, y, result, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Net.client()){
|
if(!Net.client()){
|
||||||
|
|||||||
@@ -24,35 +24,33 @@ public enum PlaceMode{
|
|||||||
pan = true;
|
pan = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
float x = tilex * tilesize;
|
float x = tilex * tilesize;
|
||||||
float y = tiley * tilesize;
|
float y = tiley * tilesize;
|
||||||
|
|
||||||
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (mobile || control.input().cursorNear());
|
boolean valid = input.validPlace(tilex, tiley, input.recipe.result) && (mobile || input.cursorNear());
|
||||||
|
|
||||||
Vector2 offset = control.input().recipe.result.getPlaceOffset();
|
Vector2 offset = input.recipe.result.getPlaceOffset();
|
||||||
|
|
||||||
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
|
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
|
||||||
|
|
||||||
renderer.getBlocks().handlePreview(control.input().recipe.result, control.input().recipe.result.rotate ? control.input().rotation * 90 : 0f, x + offset.x, y + offset.y, tilex, tiley);
|
|
||||||
|
|
||||||
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
|
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.size + si,
|
Lines.crect(x + offset.x, y + offset.y, tilesize * input.recipe.result.size + si,
|
||||||
tilesize * control.input().recipe.result.size + si);
|
tilesize * input.recipe.result.size + si);
|
||||||
|
|
||||||
control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
|
input.recipe.result.drawPlace(tilex, tiley, input.rotation, valid);
|
||||||
|
|
||||||
if(control.input().recipe.result.rotate){
|
if(input.recipe.result.rotate){
|
||||||
|
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
tr.trns(control.input().rotation * 90, 7, 0);
|
tr.trns(input.rotation * 90, 7, 0);
|
||||||
Lines.line(x, y, x + tr.x, y + tr.y);
|
Lines.line(x, y, x + tr.x, y + tr.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tapped(int tilex, int tiley){
|
public void tapped(InputHandler input, int tilex, int tiley){
|
||||||
control.input().tryPlaceBlock(tilex, tiley, true);
|
input.tryPlaceBlock(tilex, tiley, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
touch{
|
touch{
|
||||||
@@ -63,8 +61,8 @@ public enum PlaceMode{
|
|||||||
showCancel = true;
|
showCancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tapped(int x, int y){
|
public void tapped(InputHandler input, int x, int y){
|
||||||
control.input().tryPlaceBlock(x, y, true);
|
input.tryPlaceBlock(x, y, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
none{
|
none{
|
||||||
@@ -81,15 +79,15 @@ public enum PlaceMode{
|
|||||||
both = true;
|
both = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
Tile tile = world.tile(tilex, tiley);
|
Tile tile = world.tile(tilex, tiley);
|
||||||
|
|
||||||
if(tile != null && control.input().validBreak(tilex, tiley)){
|
if(tile != null && input.validBreak(tilex, tiley)){
|
||||||
if(tile.isLinked())
|
if(tile.isLinked())
|
||||||
tile = tile.getLinked();
|
tile = tile.getLinked();
|
||||||
float fin = control.input().breaktime / tile.getBreakTime();
|
float fin = input.breaktime / tile.getBreakTime();
|
||||||
|
|
||||||
if(mobile && control.input().breaktime > 0){
|
if(mobile && input.breaktime > 0){
|
||||||
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
|
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
|
||||||
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
|
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
|
||||||
}
|
}
|
||||||
@@ -106,8 +104,8 @@ public enum PlaceMode{
|
|||||||
delete = true;
|
delete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tapped(int x, int y){
|
public void tapped(InputHandler input, int x, int y){
|
||||||
control.input().tryDeleteBlock(x, y, true);
|
input.tryDeleteBlock(x, y, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
areaDelete{
|
areaDelete{
|
||||||
@@ -123,7 +121,7 @@ public enum PlaceMode{
|
|||||||
delete = true;
|
delete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
float t = tilesize;
|
float t = tilesize;
|
||||||
|
|
||||||
process(tilex, tiley, endx, endy);
|
process(tilex, tiley, endx, endy);
|
||||||
@@ -150,7 +148,7 @@ public enum PlaceMode{
|
|||||||
Tile tile = world.tile(cx, cy);
|
Tile tile = world.tile(cx, cy);
|
||||||
if(tile != null && tile.getLinked() != null)
|
if(tile != null && tile.getLinked() != null)
|
||||||
tile = tile.getLinked();
|
tile = tile.getLinked();
|
||||||
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
if(tile != null && input.validBreak(tile.x, tile.y)){
|
||||||
Lines.crect(tile.drawx(), tile.drawy(),
|
Lines.crect(tile.drawx(), tile.drawy(),
|
||||||
tile.block().size * t, tile.block().size * t);
|
tile.block().size * t, tile.block().size * t);
|
||||||
}
|
}
|
||||||
@@ -158,20 +156,20 @@ public enum PlaceMode{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
|
Draw.color(input.cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
|
||||||
Lines.rect(x, y, x2 - x, y2 - y);
|
Lines.rect(x, y, x2 - x, y2 - y);
|
||||||
Draw.alpha(0.3f);
|
Draw.alpha(0.3f);
|
||||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void released(int tilex, int tiley, int endx, int endy){
|
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
process(tilex, tiley, endx, endy);
|
process(tilex, tiley, endx, endy);
|
||||||
tilex = this.tilex; tiley = this.tiley;
|
tilex = this.tilex; tiley = this.tiley;
|
||||||
endx = this.endx; endy = this.endy;
|
endx = this.endx; endy = this.endy;
|
||||||
|
|
||||||
if(mobile){
|
if(mobile){
|
||||||
ToolFragment t = ui.toolfrag;
|
ToolFragment t = input.frag.tool;
|
||||||
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
||||||
t.confirming = true;
|
t.confirming = true;
|
||||||
t.px = tilex;
|
t.px = tilex;
|
||||||
@@ -186,7 +184,7 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
for(int cx = tilex; cx <= endx; cx ++){
|
for(int cx = tilex; cx <= endx; cx ++){
|
||||||
for(int cy = tiley; cy <= endy; cy ++){
|
for(int cy = tiley; cy <= endy; cy ++){
|
||||||
if(control.input().tryDeleteBlock(cx, cy, first)){
|
if(input.tryDeleteBlock(cx, cy, first)){
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,16 +233,16 @@ public enum PlaceMode{
|
|||||||
showRotate = true;
|
showRotate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
if(mobile && !Gdx.input.isTouched(0) && !control.showCursor()){
|
if(mobile && !Gdx.input.isTouched(0) && !input.isCursorVisible()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float t = tilesize;
|
float t = tilesize;
|
||||||
Block block = control.input().recipe.result;
|
Block block = input.recipe.result;
|
||||||
Vector2 offset = block.getPlaceOffset();
|
Vector2 offset = block.getPlaceOffset();
|
||||||
|
|
||||||
process(tilex, tiley, endx, endy);
|
process(input, tilex, tiley, endx, endy);
|
||||||
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
||||||
tilex = this.tilex; tiley = this.tiley;
|
tilex = this.tilex; tiley = this.tiley;
|
||||||
endx = this.endx; endy = this.endy;
|
endx = this.endx; endy = this.endy;
|
||||||
@@ -267,10 +265,10 @@ public enum PlaceMode{
|
|||||||
y2 += offset.y;
|
y2 += offset.y;
|
||||||
|
|
||||||
if(tilex == endx && tiley == endy){
|
if(tilex == endx && tiley == endy){
|
||||||
cursor.draw(tilex, tiley, endx, endy);
|
cursor.draw(input, tilex, tiley, endx, endy);
|
||||||
}else{
|
}else{
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Draw.color(control.input().cursorNear() ? "place" : "placeInvalid");
|
Draw.color(input.cursorNear() ? "place" : "placeInvalid");
|
||||||
Lines.rect(x, y, x2 - x, y2 - y);
|
Lines.rect(x, y, x2 - x, y2 - y);
|
||||||
Draw.alpha(0.3f);
|
Draw.alpha(0.3f);
|
||||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||||
@@ -285,9 +283,7 @@ public enum PlaceMode{
|
|||||||
py = ty + cy * Mathf.sign(ey - ty);
|
py = ty + cy * Mathf.sign(ey - ty);
|
||||||
|
|
||||||
//step by the block size if it's valid
|
//step by the block size if it's valid
|
||||||
if(control.input().validPlace(px, py, control.input().recipe.result) && state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
if(input.validPlace(px, py, input.recipe.result) && state.inventory.hasItems(input.recipe.requirements, amount)){
|
||||||
|
|
||||||
renderer.getBlocks().handlePreview(control.input().recipe.result, block.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
|
|
||||||
|
|
||||||
if(isX){
|
if(isX){
|
||||||
cx += block.size;
|
cx += block.size;
|
||||||
@@ -296,7 +292,7 @@ public enum PlaceMode{
|
|||||||
}
|
}
|
||||||
amount ++;
|
amount ++;
|
||||||
}else{ //otherwise, step by 1 until it is valid
|
}else{ //otherwise, step by 1 until it is valid
|
||||||
if(control.input().cursorNear()){
|
if(input.cursorNear()){
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Draw.color("placeInvalid");
|
Draw.color("placeInvalid");
|
||||||
Lines.crect(
|
Lines.crect(
|
||||||
@@ -316,7 +312,7 @@ public enum PlaceMode{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(control.input().recipe.result.rotate){
|
if(input.recipe.result.rotate){
|
||||||
float cx = tx * t, cy = ty * t;
|
float cx = tx * t, cy = ty * t;
|
||||||
Lines.stroke(2f);
|
Lines.stroke(2f);
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
@@ -327,15 +323,15 @@ public enum PlaceMode{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void released(int tilex, int tiley, int endx, int endy){
|
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
process(tilex, tiley, endx, endy);
|
process(input, tilex, tiley, endx, endy);
|
||||||
|
|
||||||
control.input().rotation = this.rotation;
|
input.rotation = this.rotation;
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||||
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
||||||
if(control.input().tryPlaceBlock(
|
if(input.tryPlaceBlock(
|
||||||
tilex + x * Mathf.sign(endx - tilex),
|
tilex + x * Mathf.sign(endx - tilex),
|
||||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||||
first = false;
|
first = false;
|
||||||
@@ -345,7 +341,7 @@ public enum PlaceMode{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(int tilex, int tiley, int endx, int endy){
|
void process(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||||
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
||||||
endy = tiley;
|
endy = tiley;
|
||||||
}else{
|
}else{
|
||||||
@@ -369,7 +365,7 @@ public enum PlaceMode{
|
|||||||
else if(endy < tiley)
|
else if(endy < tiley)
|
||||||
rotation = 3;
|
rotation = 3;
|
||||||
else
|
else
|
||||||
rotation = control.input().rotation;
|
rotation = input.rotation;
|
||||||
|
|
||||||
if(endx < tilex){
|
if(endx < tilex){
|
||||||
int t = endx;
|
int t = endx;
|
||||||
@@ -398,17 +394,9 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
private static final Translator tr = new Translator();
|
private static final Translator tr = new Translator();
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){}
|
||||||
|
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){}
|
||||||
}
|
public void tapped(InputHandler input, int x, int y){}
|
||||||
|
|
||||||
public void released(int tilex, int tiley, int endx, int endy){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tapped(int x, int y){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class BundleLoader {
|
|||||||
|
|
||||||
public static void load(){
|
public static void load(){
|
||||||
Settings.defaults("locale", "default");
|
Settings.defaults("locale", "default");
|
||||||
Settings.load("io.anuke.moment");
|
Settings.load("io.anuke.mindustry");
|
||||||
loadBundle();
|
loadBundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,10 +172,10 @@ public class Invoke {
|
|||||||
|
|
||||||
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Remote{}
|
public @interface Remote{}
|
||||||
|
|
||||||
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Local{}
|
public @interface Local{}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Invoke.Local;
|
|||||||
import io.anuke.mindustry.net.Invoke.Remote;
|
import io.anuke.mindustry.net.Invoke.Remote;
|
||||||
import io.anuke.mindustry.net.Net.SendMode;
|
import io.anuke.mindustry.net.Net.SendMode;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
|
import io.anuke.mindustry.resource.Upgrade;
|
||||||
import io.anuke.mindustry.resource.Weapon;
|
import io.anuke.mindustry.resource.Weapon;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -63,20 +64,21 @@ public class NetEvents {
|
|||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleWeaponSwitch(){
|
public static void handleWeaponSwitch(Player player){
|
||||||
WeaponSwitchPacket packet = Pools.obtain(WeaponSwitchPacket.class);
|
WeaponSwitchPacket packet = Pools.obtain(WeaponSwitchPacket.class);
|
||||||
packet.weapon = Vars.player.weapon.id;
|
packet.weapon = player.weapon.id;
|
||||||
packet.playerid = Vars.player.id;
|
packet.playerid = player.id;
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleUpgrade(Weapon weapon){
|
public static void handleUpgrade(Player player, Upgrade weapon){
|
||||||
UpgradePacket packet = Pools.obtain(UpgradePacket.class);
|
UpgradePacket packet = Pools.obtain(UpgradePacket.class);
|
||||||
packet.id = weapon.id;
|
packet.upgradeid = weapon.id;
|
||||||
|
packet.playerid = player.id;
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleSendMessage(String message){
|
public static void handleSendMessage(Player player, String message){
|
||||||
ChatPacket packet = Pools.obtain(ChatPacket.class);
|
ChatPacket packet = Pools.obtain(ChatPacket.class);
|
||||||
packet.text = message;
|
packet.text = message;
|
||||||
packet.name = player.name;
|
packet.name = player.name;
|
||||||
@@ -99,12 +101,12 @@ public class NetEvents {
|
|||||||
Net.send(packet, SendMode.udp);
|
Net.send(packet, SendMode.udp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handlePlace(int x, int y, Block block, int rotation){
|
public static void handlePlace(Player player, int x, int y, Block block, int rotation){
|
||||||
PlacePacket packet = Pools.obtain(PlacePacket.class);
|
PlacePacket packet = Pools.obtain(PlacePacket.class);
|
||||||
packet.x = (short)x;
|
packet.x = (short)x;
|
||||||
packet.y = (short)y;
|
packet.y = (short)y;
|
||||||
packet.rotation = (byte)rotation;
|
packet.rotation = (byte)rotation;
|
||||||
packet.playerid = Vars.player.id;
|
packet.playerid = player.id;
|
||||||
packet.block = block.id;
|
packet.block = block.id;
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ public class NetworkIO {
|
|||||||
/**Return whether a custom map is expected, and thus whether the client should wait for additional data.*/
|
/**Return whether a custom map is expected, and thus whether the client should wait for additional data.*/
|
||||||
public static void loadWorld(InputStream is){
|
public static void loadWorld(InputStream is){
|
||||||
|
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
//TODO !! use map name as the network map in Maps, so getMap() isn't null.
|
//TODO !! use map name as the network map in Maps, so getMap() isn't null.
|
||||||
|
|
||||||
try(DataInputStream stream = new DataInputStream(is)){
|
try(DataInputStream stream = new DataInputStream(is)){
|
||||||
|
|||||||
@@ -86,16 +86,16 @@ public class Packets {
|
|||||||
public static class ConnectPacket implements Packet{
|
public static class ConnectPacket implements Packet{
|
||||||
public int version;
|
public int version;
|
||||||
public int players;
|
public int players;
|
||||||
public String[] names;
|
public String name;
|
||||||
public boolean android;
|
public boolean mobile;
|
||||||
public int[] colors;
|
public int color;
|
||||||
public byte[] uuid;
|
public byte[] uuid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
buffer.putInt(Version.build);
|
buffer.putInt(Version.build);
|
||||||
IOUtils.writeString(buffer, name);
|
IOUtils.writeString(buffer, name);
|
||||||
buffer.put(android ? (byte)1 : 0);
|
buffer.put(mobile ? (byte)1 : 0);
|
||||||
buffer.putInt(color);
|
buffer.putInt(color);
|
||||||
buffer.put(uuid);
|
buffer.put(uuid);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ public class Packets {
|
|||||||
public void read(ByteBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
version = buffer.getInt();
|
version = buffer.getInt();
|
||||||
name = IOUtils.readString(buffer);
|
name = IOUtils.readString(buffer);
|
||||||
android = buffer.get() == 1;
|
mobile = buffer.get() == 1;
|
||||||
color = buffer.getInt();
|
color = buffer.getInt();
|
||||||
uuid = new byte[8];
|
uuid = new byte[8];
|
||||||
buffer.get(uuid);
|
buffer.get(uuid);
|
||||||
@@ -392,16 +392,19 @@ public class Packets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class UpgradePacket implements Packet{
|
public static class UpgradePacket implements Packet{
|
||||||
public byte id; //weapon ID only, currently
|
public byte upgradeid; //weapon ID only, currently
|
||||||
|
public int playerid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
buffer.put(id);
|
buffer.put(upgradeid);
|
||||||
|
buffer.putInt(playerid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
id = buffer.get();
|
upgradeid = buffer.get();
|
||||||
|
playerid = buffer.getInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ public class Weapon extends Upgrade{
|
|||||||
public void shoot(Player p, float x, float y, float angle, boolean left){
|
public void shoot(Player p, float x, float y, float angle, boolean left){
|
||||||
shootInternal(p, x, y, angle, left);
|
shootInternal(p, x, y, angle, left);
|
||||||
|
|
||||||
if(Net.active() && p == Vars.player){
|
if(Net.active() && p.isLocal){
|
||||||
NetEvents.handleShoot(Vars.player, x, y, angle, Bits.packShort(id, (byte)(left ? 1 : 0)));
|
NetEvents.handleShoot(p, x, y, angle, Bits.packShort(id, (byte)(left ? 1 : 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
p.inventory.useAmmo();
|
p.inventory.useAmmo();
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import io.anuke.ucore.scene.ui.Dialog;
|
|||||||
import io.anuke.ucore.scene.ui.ImageButton;
|
import io.anuke.ucore.scene.ui.ImageButton;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.player;
|
|
||||||
import static io.anuke.mindustry.Vars.playerColors;
|
import static io.anuke.mindustry.Vars.playerColors;
|
||||||
|
import static io.anuke.mindustry.Vars.players;
|
||||||
|
|
||||||
public class ColorPickDialog extends Dialog{
|
public class ColorPickDialog extends Dialog{
|
||||||
private Consumer<Color> cons;
|
private Consumer<Color> cons;
|
||||||
@@ -29,7 +29,7 @@ public class ColorPickDialog extends Dialog{
|
|||||||
cons.accept(color);
|
cons.accept(color);
|
||||||
hide();
|
hide();
|
||||||
}).size(44, 48).pad(0).padBottom(-5.1f).get();
|
}).size(44, 48).pad(0).padBottom(-5.1f).get();
|
||||||
button.setChecked(player.getColor().equals(color));
|
button.setChecked(players[0].getColor().equals(color));
|
||||||
button.getStyle().imageUpColor = color;
|
button.getStyle().imageUpColor = color;
|
||||||
|
|
||||||
if(i%4 == 3){
|
if(i%4 == 3){
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.dialogs;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
@@ -11,7 +12,7 @@ import io.anuke.ucore.util.Strings;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.player;
|
import static io.anuke.mindustry.Vars.players;
|
||||||
import static io.anuke.mindustry.Vars.ui;
|
import static io.anuke.mindustry.Vars.ui;
|
||||||
|
|
||||||
public class HostDialog extends FloatingDialog{
|
public class HostDialog extends FloatingDialog{
|
||||||
@@ -20,13 +21,15 @@ public class HostDialog extends FloatingDialog{
|
|||||||
public HostDialog(){
|
public HostDialog(){
|
||||||
super("$text.hostserver");
|
super("$text.hostserver");
|
||||||
|
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
addCloseButton();
|
addCloseButton();
|
||||||
|
|
||||||
content().table(t -> {
|
content().table(t -> {
|
||||||
t.add("$text.name").padRight(10);
|
t.add("$text.name").padRight(10);
|
||||||
t.addField(Settings.getString("name"), text -> {
|
t.addField(Settings.getString("name"), text -> {
|
||||||
if(text.isEmpty()) return;
|
if(text.isEmpty()) return;
|
||||||
Vars.player.name = text;
|
player.name = text;
|
||||||
Settings.put("name", text);
|
Settings.put("name", text);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
ui.listfrag.rebuild();
|
ui.listfrag.rebuild();
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package io.anuke.mindustry.ui.dialogs;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import com.badlogic.gdx.utils.Json;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.net.Host;
|
import io.anuke.mindustry.net.Host;
|
||||||
@@ -21,7 +23,7 @@ import io.anuke.ucore.util.Bundles;
|
|||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.player;
|
import static io.anuke.mindustry.Vars.players;
|
||||||
import static io.anuke.mindustry.Vars.ui;
|
import static io.anuke.mindustry.Vars.ui;
|
||||||
|
|
||||||
public class JoinDialog extends FloatingDialog {
|
public class JoinDialog extends FloatingDialog {
|
||||||
@@ -31,6 +33,7 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
Table local = new Table();
|
Table local = new Table();
|
||||||
Table remote = new Table();
|
Table remote = new Table();
|
||||||
Table hosts = new Table();
|
Table hosts = new Table();
|
||||||
|
Json json = new Json();
|
||||||
float w = 500;
|
float w = 500;
|
||||||
|
|
||||||
public JoinDialog(){
|
public JoinDialog(){
|
||||||
@@ -187,6 +190,8 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
hosts.clear();
|
hosts.clear();
|
||||||
|
|
||||||
hosts.add(remote).growX();
|
hosts.add(remote).growX();
|
||||||
@@ -205,7 +210,7 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
t.add("$text.name").padRight(10);
|
t.add("$text.name").padRight(10);
|
||||||
t.addField(Settings.getString("name"), text -> {
|
t.addField(Settings.getString("name"), text -> {
|
||||||
if(text.isEmpty()) return;
|
if(text.isEmpty()) return;
|
||||||
Vars.player.name = text;
|
player.name = text;
|
||||||
Settings.put("name", text);
|
Settings.put("name", text);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}).grow().pad(8).get().setMaxLength(40);
|
}).grow().pad(8).get().setMaxLength(40);
|
||||||
@@ -304,39 +309,27 @@ public class JoinDialog extends FloatingDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadServers(){
|
private void loadServers(){
|
||||||
String h = Settings.getString("servers");
|
String h = Settings.getString("serverlist","{}");
|
||||||
String[] list = h.split("\\|\\|\\|");
|
servers = json.fromJson(Array.class, h);
|
||||||
for(String fname : list){
|
|
||||||
if(fname.isEmpty()) continue;
|
|
||||||
String[] split = fname.split(":");
|
|
||||||
String host = split[0];
|
|
||||||
int port = Strings.parseInt(split[1]);
|
|
||||||
|
|
||||||
if(port != Integer.MIN_VALUE) servers.add(new Server(host, port));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveServers(){
|
private void saveServers(){
|
||||||
StringBuilder out = new StringBuilder();
|
Settings.putString("serverlist", json.toJson(servers));
|
||||||
for(Server server : servers){
|
|
||||||
out.append(server.ip);
|
|
||||||
out.append(":");
|
|
||||||
out.append(server.port);
|
|
||||||
out.append("|||");
|
|
||||||
}
|
|
||||||
Settings.putString("servers", out.toString());
|
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Server{
|
static class Server{
|
||||||
public String ip;
|
String ip;
|
||||||
public int port;
|
int port;
|
||||||
public Host host;
|
|
||||||
public Table content;
|
|
||||||
|
|
||||||
public Server(String ip, int port){
|
transient Host host;
|
||||||
|
transient Table content;
|
||||||
|
|
||||||
|
Server(String ip, int port){
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Server(){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ public class PausedDialog extends FloatingDialog{
|
|||||||
if(control.getSaves().getCurrent() == null ||
|
if(control.getSaves().getCurrent() == null ||
|
||||||
!control.getSaves().getCurrent().isAutosave()){
|
!control.getSaves().getCurrent().isAutosave()){
|
||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
control.tutorial().reset();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
@@ -12,7 +13,7 @@ import static io.anuke.mindustry.Vars.state;
|
|||||||
public class BackgroundFragment implements Fragment {
|
public class BackgroundFragment implements Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
|
|
||||||
Core.scene.table().addRect((a, b, w, h) -> {
|
Core.scene.table().addRect((a, b, w, h) -> {
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
|||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.scene.Element;
|
import io.anuke.ucore.scene.Element;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
@@ -17,9 +18,9 @@ public class BlockConfigFragment implements Fragment {
|
|||||||
private Tile configTile;
|
private Tile configTile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
table = new Table();
|
table = new Table();
|
||||||
Core.scene.add(table);
|
parent.addChild(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShown(){
|
public boolean isShown(){
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.IntSet;
|
import com.badlogic.gdx.utils.IntSet;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
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.Item;
|
||||||
import io.anuke.mindustry.ui.ItemImage;
|
import io.anuke.mindustry.ui.ItemImage;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
@@ -16,6 +18,7 @@ import io.anuke.ucore.core.Inputs;
|
|||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.function.BooleanProvider;
|
import io.anuke.ucore.function.BooleanProvider;
|
||||||
import io.anuke.ucore.function.Callable;
|
import io.anuke.ucore.function.Callable;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.event.HandCursorListener;
|
import io.anuke.ucore.scene.event.HandCursorListener;
|
||||||
import io.anuke.ucore.scene.event.Touchable;
|
import io.anuke.ucore.scene.event.Touchable;
|
||||||
@@ -29,12 +32,20 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
public class BlockInventoryFragment implements Fragment {
|
public class BlockInventoryFragment implements Fragment {
|
||||||
private Table table;
|
private Table table;
|
||||||
|
private boolean shown;
|
||||||
private Tile tile;
|
private Tile tile;
|
||||||
|
private InputHandler input;
|
||||||
|
|
||||||
|
public BlockInventoryFragment(InputHandler input){
|
||||||
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
table = new Table();
|
table = new Table();
|
||||||
table.setVisible(() -> !state.is(State.menu));
|
table.setVisible(() -> !state.is(State.menu) && shown);
|
||||||
|
parent.addChild(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showFor(Tile t){
|
public void showFor(Tile t){
|
||||||
@@ -44,18 +55,20 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hide(){
|
public void hide(){
|
||||||
|
shown = false;
|
||||||
table.clear();
|
table.clear();
|
||||||
table.remove();
|
|
||||||
table.setTouchable(Touchable.disabled);
|
table.setTouchable(Touchable.disabled);
|
||||||
table.update(() -> {});
|
table.update(() -> {});
|
||||||
tile = null;
|
tile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rebuild(){
|
private void rebuild(){
|
||||||
|
Player player = input.player;
|
||||||
|
|
||||||
|
shown = true;
|
||||||
IntSet container = new IntSet();
|
IntSet container = new IntSet();
|
||||||
|
|
||||||
table.clear();
|
table.clear();
|
||||||
if(table.getParent() == null) Core.scene.add(table);
|
|
||||||
table.background("clear");
|
table.background("clear");
|
||||||
table.setTouchable(Touchable.enabled);
|
table.setTouchable(Touchable.enabled);
|
||||||
table.update(() -> {
|
table.update(() -> {
|
||||||
@@ -137,6 +150,8 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void move(TextureRegion region, Vector2 v, Callable c, Color color){
|
private void move(TextureRegion region, Vector2 v, Callable c, Color color){
|
||||||
|
Player player = input.player;
|
||||||
|
|
||||||
Vector2 tv = Graphics.screen(player.x + Angles.trnsx(player.rotation + 180f, 5f), player.y + Angles.trnsy(player.rotation + 180f, 5f));
|
Vector2 tv = Graphics.screen(player.x + Angles.trnsx(player.rotation + 180f, 5f), player.y + Angles.trnsy(player.rotation + 180f, 5f));
|
||||||
float tx = tv.x, ty = tv.y;
|
float tx = tv.x, ty = tv.y;
|
||||||
float dur = 40f / 60f;
|
float dur = 40f / 60f;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import io.anuke.mindustry.world.BlockStats;
|
|||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.graphics.Hue;
|
import io.anuke.ucore.graphics.Hue;
|
||||||
import io.anuke.ucore.scene.Element;
|
import io.anuke.ucore.scene.Element;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
import io.anuke.ucore.scene.event.ClickListener;
|
import io.anuke.ucore.scene.event.ClickListener;
|
||||||
@@ -40,8 +41,8 @@ public class BlocksFragment implements Fragment{
|
|||||||
private Recipe hoveredDescriptionRecipe;
|
private Recipe hoveredDescriptionRecipe;
|
||||||
private IntSet itemset = new IntSet();
|
private IntSet itemset = new IntSet();
|
||||||
|
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
InputHandler input = control.input();
|
InputHandler input = control.input(0);
|
||||||
|
|
||||||
new table(){{
|
new table(){{
|
||||||
abottom();
|
abottom();
|
||||||
@@ -180,10 +181,9 @@ public class BlocksFragment implements Fragment{
|
|||||||
table.add(image).size(size + 8);
|
table.add(image).size(size + 8);
|
||||||
|
|
||||||
image.update(() -> {
|
image.update(() -> {
|
||||||
boolean canPlace = !control.tutorial().active() || control.tutorial().canPlace();
|
boolean has = (state.inventory.hasItems(r.requirements));
|
||||||
boolean has = (state.inventory.hasItems(r.requirements)) && canPlace;
|
|
||||||
image.setChecked(input.recipe == r);
|
image.setChecked(input.recipe == r);
|
||||||
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
|
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));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.net.NetEvents;
|
|||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.ui.Label;
|
import io.anuke.ucore.scene.ui.Label;
|
||||||
import io.anuke.ucore.scene.ui.Label.LabelStyle;
|
import io.anuke.ucore.scene.ui.Label.LabelStyle;
|
||||||
import io.anuke.ucore.scene.ui.TextField;
|
import io.anuke.ucore.scene.ui.TextField;
|
||||||
@@ -21,13 +22,13 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.players;
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
import static io.anuke.ucore.core.Core.scene;
|
import static io.anuke.ucore.core.Core.scene;
|
||||||
import static io.anuke.ucore.core.Core.skin;
|
import static io.anuke.ucore.core.Core.skin;
|
||||||
|
|
||||||
public class ChatFragment extends Table implements Fragment{
|
public class ChatFragment extends Table implements Fragment{
|
||||||
private final static int messagesShown = 10;
|
private final static int messagesShown = 10;
|
||||||
private final static int maxLength = 150;
|
|
||||||
private Array<ChatMessage> messages = new Array<>();
|
private Array<ChatMessage> messages = new Array<>();
|
||||||
private float fadetime;
|
private float fadetime;
|
||||||
private boolean chatOpen = false;
|
private boolean chatOpen = false;
|
||||||
@@ -79,7 +80,7 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
scene.add(this);
|
scene.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +96,12 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
fieldlabel.setStyle(fieldlabel.getStyle());
|
fieldlabel.setStyle(fieldlabel.getStyle());
|
||||||
|
|
||||||
chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
|
chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
|
||||||
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < maxLength);
|
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < Vars.maxTextLength);
|
||||||
chatfield.getStyle().background = null;
|
chatfield.getStyle().background = null;
|
||||||
chatfield.getStyle().fontColor = Color.WHITE;
|
chatfield.getStyle().fontColor = Color.WHITE;
|
||||||
chatfield.getStyle().font = skin.getFont("default-font-chat");
|
chatfield.getStyle().font = skin.getFont("default-font-chat");
|
||||||
chatfield.setStyle(chatfield.getStyle());
|
chatfield.setStyle(chatfield.getStyle());
|
||||||
Platform.instance.addDialog(chatfield, maxLength);
|
Platform.instance.addDialog(chatfield, Vars.maxTextLength);
|
||||||
|
|
||||||
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
|
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
if(message.replaceAll(" ", "").isEmpty()) return;
|
if(message.replaceAll(" ", "").isEmpty()) return;
|
||||||
|
|
||||||
history.insert(1, message);
|
history.insert(1, message);
|
||||||
NetEvents.handleSendMessage(message);
|
NetEvents.handleSendMessage(players[0], message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggle(){
|
public void toggle(){
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import io.anuke.mindustry.entities.Player;
|
|||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.builders.button;
|
import io.anuke.ucore.scene.builders.button;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
@@ -41,7 +41,10 @@ public class DebugFragment implements Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
|
|
||||||
|
Player player = players[0];
|
||||||
|
|
||||||
new table(){{
|
new table(){{
|
||||||
visible(() -> debug);
|
visible(() -> debug);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package io.anuke.mindustry.ui.fragments;
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
|
|
||||||
public interface Fragment{
|
public interface Fragment{
|
||||||
public void build();
|
public void build(Group parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import io.anuke.ucore.core.Core;
|
|||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
@@ -36,7 +37,7 @@ public class HudFragment implements Fragment{
|
|||||||
private float dsize = 58;
|
private float dsize = 58;
|
||||||
private float isize = 40;
|
private float isize = 40;
|
||||||
|
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
|
|
||||||
//menu at top left
|
//menu at top left
|
||||||
new table(){{
|
new table(){{
|
||||||
@@ -116,13 +117,6 @@ public class HudFragment implements Fragment{
|
|||||||
|
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
//tutorial ui table
|
|
||||||
new table(){{
|
|
||||||
control.tutorial().buildUI(this);
|
|
||||||
|
|
||||||
visible(() -> control.tutorial().active());
|
|
||||||
}}.end();
|
|
||||||
|
|
||||||
new table(){{
|
new table(){{
|
||||||
visible(() -> !state.is(State.menu));
|
visible(() -> !state.is(State.menu));
|
||||||
atop();
|
atop();
|
||||||
@@ -174,17 +168,6 @@ public class HudFragment implements Fragment{
|
|||||||
});
|
});
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
//respawn table
|
|
||||||
new table(){{
|
|
||||||
new table("pane"){{
|
|
||||||
|
|
||||||
new label(()->"[orange]"+Bundles.get("text.respawn")+" " + (int)(control.getRespawnTime()/60)).scale(0.75f).pad(10);
|
|
||||||
|
|
||||||
visible(()->false);
|
|
||||||
|
|
||||||
}}.end();
|
|
||||||
}}.end();
|
|
||||||
|
|
||||||
new table(){{
|
new table(){{
|
||||||
abottom();
|
abottom();
|
||||||
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
||||||
@@ -193,7 +176,7 @@ public class HudFragment implements Fragment{
|
|||||||
|
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
blockfrag.build();
|
blockfrag.build(Core.scene.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleMenus(){
|
private void toggleMenus(){
|
||||||
@@ -236,7 +219,7 @@ public class HudFragment implements Fragment{
|
|||||||
|
|
||||||
new label(()-> state.enemies > 0 ?
|
new label(()-> state.enemies > 0 ?
|
||||||
getEnemiesRemaining() :
|
getEnemiesRemaining() :
|
||||||
(control.tutorial().active() || state.mode.disableWaveTimer) ? "$text.waiting"
|
(state.mode.disableWaveTimer) ? "$text.waiting"
|
||||||
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f)))
|
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f)))
|
||||||
.minWidth(126).padLeft(-6).left();
|
.minWidth(126).padLeft(-6).left();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.ui.fragments;
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Colors;
|
import com.badlogic.gdx.graphics.Colors;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
import io.anuke.ucore.scene.event.Touchable;
|
import io.anuke.ucore.scene.event.Touchable;
|
||||||
@@ -11,7 +12,7 @@ public class LoadingFragment implements Fragment {
|
|||||||
private Table table;
|
private Table table;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
|
|
||||||
table = new table("loadDim"){{
|
table = new table("loadDim"){{
|
||||||
touchable(Touchable.enabled);
|
touchable(Touchable.enabled);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.io.Platform;
|
|||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.ui.MenuButton;
|
import io.anuke.mindustry.ui.MenuButton;
|
||||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
@@ -14,7 +15,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
public class MenuFragment implements Fragment{
|
public class MenuFragment implements Fragment{
|
||||||
|
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
new table(){{
|
new table(){{
|
||||||
visible(() -> state.is(State.menu));
|
visible(() -> state.is(State.menu));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
|
|
||||||
|
public class OverlayFragment implements Fragment{
|
||||||
|
public final BlockInventoryFragment inv;
|
||||||
|
public final ToolFragment tool;
|
||||||
|
public final BlockConfigFragment config;
|
||||||
|
|
||||||
|
private Group group = new Group();
|
||||||
|
|
||||||
|
public OverlayFragment(InputHandler input){
|
||||||
|
tool = new ToolFragment(input);
|
||||||
|
inv = new BlockInventoryFragment(input);
|
||||||
|
config = new BlockConfigFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Group parent){
|
||||||
|
group.setFillParent(true);
|
||||||
|
parent.addChild(group);
|
||||||
|
|
||||||
|
inv.build(group);
|
||||||
|
tool.build(group);
|
||||||
|
config.build(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(){
|
||||||
|
group.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import io.anuke.mindustry.input.AndroidInput;
|
|||||||
import io.anuke.mindustry.input.InputHandler;
|
import io.anuke.mindustry.input.InputHandler;
|
||||||
import io.anuke.mindustry.input.PlaceMode;
|
import io.anuke.mindustry.input.PlaceMode;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
@@ -28,10 +29,10 @@ public class PlacementFragment implements Fragment{
|
|||||||
Table breaktable, next, container;
|
Table breaktable, next, container;
|
||||||
Label modelabel;
|
Label modelabel;
|
||||||
|
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
if(!mobile) return;
|
if(!mobile) return;
|
||||||
|
|
||||||
InputHandler input = control.input();
|
InputHandler input = control.input(0);
|
||||||
|
|
||||||
float s = 50f;
|
float s = 50f;
|
||||||
float translation = Unit.dp.scl(58f);
|
float translation = Unit.dp.scl(58f);
|
||||||
@@ -130,7 +131,7 @@ public class PlacementFragment implements Fragment{
|
|||||||
defaults().padBottom(-5.5f);
|
defaults().padBottom(-5.5f);
|
||||||
|
|
||||||
ImageButton button = new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
ImageButton button = new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
||||||
control.input().resetCursor();
|
input.resetCursor();
|
||||||
input.breakMode = mode;
|
input.breakMode = mode;
|
||||||
input.lastBreakMode = mode;
|
input.lastBreakMode = mode;
|
||||||
if (!mode.both){
|
if (!mode.both){
|
||||||
@@ -183,7 +184,7 @@ public class PlacementFragment implements Fragment{
|
|||||||
if (!mode.shown || mode.delete) continue;
|
if (!mode.shown || mode.delete) continue;
|
||||||
|
|
||||||
new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
||||||
control.input().resetCursor();
|
input.resetCursor();
|
||||||
input.placeMode = mode;
|
input.placeMode = mode;
|
||||||
input.lastPlaceMode = mode;
|
input.lastPlaceMode = mode;
|
||||||
modeText(Bundles.format("text.mode.place", mode.toString()));
|
modeText(Bundles.format("text.mode.place", mode.toString()));
|
||||||
@@ -215,6 +216,8 @@ public class PlacementFragment implements Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void toggle(boolean show){
|
private void toggle(boolean show){
|
||||||
|
InputHandler input = control.input(0);
|
||||||
|
|
||||||
float dur = 0.3f;
|
float dur = 0.3f;
|
||||||
Interpolation in = Interpolation.pow3Out;
|
Interpolation in = Interpolation.pow3Out;
|
||||||
|
|
||||||
@@ -223,8 +226,8 @@ public class PlacementFragment implements Fragment{
|
|||||||
breaktable.getParent().swapActor(breaktable, next);
|
breaktable.getParent().swapActor(breaktable, next);
|
||||||
|
|
||||||
if(!show){
|
if(!show){
|
||||||
control.input().breakMode = PlaceMode.none;
|
input.breakMode = PlaceMode.none;
|
||||||
if(control.input().placeMode.delete) control.input().placeMode = PlaceMode.none;
|
if(input.placeMode.delete) input.placeMode = PlaceMode.none;
|
||||||
breaktable.actions(Actions.translateBy(-breaktable.getWidth() - 5, 0, dur, in), Actions.call(() -> shown = false));
|
breaktable.actions(Actions.translateBy(-breaktable.getWidth() - 5, 0, dur, in), Actions.call(() -> shown = false));
|
||||||
}else{
|
}else{
|
||||||
shown = true;
|
shown = true;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.ui.BorderImage;
|
|||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.scene.Element;
|
import io.anuke.ucore.scene.Element;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.builders.button;
|
import io.anuke.ucore.scene.builders.button;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
@@ -32,7 +33,7 @@ public class PlayerListFragment implements Fragment{
|
|||||||
ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(){
|
public void build(Group parent){
|
||||||
new table(){{
|
new table(){{
|
||||||
new table("pane"){{
|
new table("pane"){{
|
||||||
margin(14f);
|
margin(14f);
|
||||||
@@ -124,7 +125,7 @@ public class PlayerListFragment implements Fragment{
|
|||||||
|
|
||||||
button.addImage("icon-admin").size(14*2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
|
button.addImage("icon-admin").size(14*2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
|
||||||
|
|
||||||
if((Net.server() || Vars.player.isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())){
|
if((Net.server() || players[0].isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())){
|
||||||
button.add().growY();
|
button.add().growY();
|
||||||
|
|
||||||
float bs = (h + 14)/2f;
|
float bs = (h + 14)/2f;
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package io.anuke.mindustry.ui.fragments;
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
|
|
||||||
public class PlayerMenuFragment implements Fragment {
|
public class PlayerMenuFragment implements Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build(Group parent) {
|
||||||
/*
|
/*
|
||||||
new table(){{
|
new table(){{
|
||||||
new table("clear"){{
|
new table("clear"){{
|
||||||
|
|||||||
@@ -9,16 +9,22 @@ import io.anuke.mindustry.input.InputHandler;
|
|||||||
import io.anuke.mindustry.input.PlaceMode;
|
import io.anuke.mindustry.input.PlaceMode;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
public class ToolFragment implements Fragment{
|
public class ToolFragment implements Fragment{
|
||||||
private Table tools;
|
private Table tools;
|
||||||
|
private InputHandler input;
|
||||||
|
|
||||||
public int px, py, px2, py2;
|
public int px, py, px2, py2;
|
||||||
public boolean confirming;
|
public boolean confirming;
|
||||||
|
|
||||||
public void build(){
|
public ToolFragment(InputHandler input){
|
||||||
InputHandler input = control.input();
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Group parent){
|
||||||
float isize = 14*3;
|
float isize = 14*3;
|
||||||
|
|
||||||
tools = new Table();
|
tools = new Table();
|
||||||
@@ -38,15 +44,13 @@ public class ToolFragment implements Fragment{
|
|||||||
|
|
||||||
tools.addImageButton("icon-check", isize, () -> {
|
tools.addImageButton("icon-check", isize, () -> {
|
||||||
if(input.placeMode == PlaceMode.areaDelete && confirming){
|
if(input.placeMode == PlaceMode.areaDelete && confirming){
|
||||||
input.placeMode.released(px, py, px2, py2);
|
input.placeMode.released(input, px, py, px2, py2);
|
||||||
confirming = false;
|
confirming = false;
|
||||||
}else{
|
}else{
|
||||||
input.placeMode.tapped(control.input().getBlockX(), control.input().getBlockY());
|
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Core.scene.add(tools);
|
|
||||||
|
|
||||||
tools.setVisible(() ->
|
tools.setVisible(() ->
|
||||||
!state.is(State.menu) && mobile && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
|
!state.is(State.menu) && mobile && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
|
||||||
input.placeMode == PlaceMode.cursor) || confirming)
|
input.placeMode == PlaceMode.cursor) || confirming)
|
||||||
@@ -58,13 +62,16 @@ public class ToolFragment implements Fragment{
|
|||||||
tools.setPosition(v.x, v.y, Align.top);
|
tools.setPosition(v.x, v.y, Align.top);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
tools.setPosition(control.input().getCursorX(),
|
tools.setPosition(input.getCursorX(),
|
||||||
Gdx.graphics.getHeight() - control.input().getCursorY() - 15*Core.cameraScale, Align.top);
|
Gdx.graphics.getHeight() - input.getCursorY() - 15*Core.cameraScale, Align.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(input.placeMode != PlaceMode.areaDelete){
|
if(input.placeMode != PlaceMode.areaDelete){
|
||||||
confirming = false;
|
confirming = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
parent.addChild(tools);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
include 'desktop', 'html', 'core', 'android', 'kryonet', 'server', 'ios'
|
include 'desktop', 'html', 'core', 'android', 'kryonet', 'server', 'ios', 'annotations'
|
||||||
|
|
||||||
if(System.properties["release"] == null || System.properties["release"].equals("false")){
|
if(System.properties["release"] == null || System.properties["release"].equals("false")){
|
||||||
if (new File(settingsDir, '../uCore').exists()) {
|
if (new File(settingsDir, '../uCore').exists()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user