Massive amount of refactoring for local multiplayer, annotations
This commit is contained in:
@@ -87,6 +87,8 @@ public class Vars{
|
||||
//whether to show block debug
|
||||
public static boolean showBlockDebug = false;
|
||||
|
||||
public static final int maxTextLength = 150;
|
||||
|
||||
public static boolean headless = false;
|
||||
|
||||
public static float controllerMin = 0.25f;
|
||||
@@ -143,7 +145,7 @@ public class Vars{
|
||||
public static NetServer netServer;
|
||||
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<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
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.modules.Module;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Atlas;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.util.InputProxy;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
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.
|
||||
* This class is not created in the headless server.*/
|
||||
public class Control extends Module{
|
||||
private Tutorial tutorial = new Tutorial();
|
||||
private boolean hiscore = false;
|
||||
|
||||
private boolean wasPaused = false;
|
||||
|
||||
private Saves saves;
|
||||
private InputHandler[] inputs = {};
|
||||
|
||||
private InputHandler[] inputs;
|
||||
|
||||
private InputProxy proxy;
|
||||
private float controlx, controly;
|
||||
private boolean controlling;
|
||||
private Throwable error;
|
||||
private InputProxy proxy;
|
||||
private Input gdxInput;
|
||||
|
||||
public Control(){
|
||||
saves = new Saves();
|
||||
@@ -58,28 +51,6 @@ public class Control extends Module{
|
||||
|
||||
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);
|
||||
|
||||
Core.atlas = new Atlas("sprites.atlas");
|
||||
@@ -88,6 +59,32 @@ public class Control extends Module{
|
||||
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",
|
||||
"corexplode.mp3", "break.mp3", "spawn.mp3", "flame.mp3", "die.mp3",
|
||||
"respawn.mp3", "purchase.mp3", "flame2.mp3", "bigshot.mp3", "laser.mp3", "lasershot.mp3",
|
||||
@@ -102,8 +99,11 @@ public class Control extends Module{
|
||||
Settings.defaultList(
|
||||
"ip", "localhost",
|
||||
"port", port+"",
|
||||
"servers", "",
|
||||
"color", Color.rgba8888(playerColors[8]),
|
||||
"color-0", 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
|
||||
);
|
||||
|
||||
@@ -156,7 +156,6 @@ public class Control extends Module{
|
||||
Events.on(GameOverEvent.class, () -> {
|
||||
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
|
||||
|
||||
|
||||
//TODO game over effect
|
||||
ui.restart.show();
|
||||
|
||||
@@ -166,10 +165,20 @@ public class Control extends Module{
|
||||
|
||||
//TODO drop player method
|
||||
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.name = Settings.getString("name-" + index, "player");
|
||||
player.name = Settings.getString("name");
|
||||
player.mech = mobile ? Mechs.standardShip : Mechs.standard;
|
||||
player.color.set(Settings.getInt("color"));
|
||||
player.color.set(Settings.getInt("color-" + index));
|
||||
player.isLocal = true;
|
||||
player.playerIndex = index;
|
||||
players[index] = player;
|
||||
@@ -186,10 +195,9 @@ public class Control extends Module{
|
||||
Inputs.addProcessor(input);
|
||||
}
|
||||
|
||||
//FIXME figure out what's causing this problem in the first place
|
||||
public void triggerInputUpdate(){
|
||||
Gdx.input = proxy;
|
||||
}
|
||||
public Input gdxInput(){
|
||||
return gdxInput;
|
||||
}
|
||||
|
||||
public void setError(Throwable error){
|
||||
this.error = error;
|
||||
@@ -199,14 +207,14 @@ public class Control extends Module{
|
||||
return saves;
|
||||
}
|
||||
|
||||
public boolean showCursor(){
|
||||
return controlling;
|
||||
}
|
||||
|
||||
public InputHandler input(int index){
|
||||
return inputs[index];
|
||||
}
|
||||
|
||||
public void triggerUpdateInput(){
|
||||
Gdx.input = proxy;
|
||||
}
|
||||
|
||||
public void playMap(Map map){
|
||||
ui.loadfrag.show();
|
||||
saves.resetSave();
|
||||
@@ -224,10 +232,6 @@ public class Control extends Module{
|
||||
return hiscore;
|
||||
}
|
||||
|
||||
public Tutorial tutorial(){
|
||||
return tutorial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
Platform.instance.onGameExit();
|
||||
@@ -261,52 +265,10 @@ public class Control extends Module{
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
|
||||
Gdx.input = proxy;
|
||||
|
||||
if(Inputs.keyTap("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();
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
@@ -335,10 +297,6 @@ public class Control extends Module{
|
||||
if(!state.is(State.paused) || Net.active()){
|
||||
Entities.update(effectGroup);
|
||||
Entities.update(groundEffectGroup);
|
||||
|
||||
if(tutorial.active()){
|
||||
tutorial.update();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!state.is(State.paused) || Net.active()){
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Logic extends Module {
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
|
||||
if(control != null) control.triggerInputUpdate();
|
||||
if(control != null) control.triggerUpdateInput();
|
||||
|
||||
if(!state.is(State.paused) || Net.active()){
|
||||
Timers.update();
|
||||
|
||||
@@ -54,6 +54,8 @@ public class NetClient extends Module {
|
||||
public NetClient(){
|
||||
|
||||
Net.handleClient(Connect.class, packet -> {
|
||||
Player player = players[0];
|
||||
|
||||
player.isAdmin = false;
|
||||
|
||||
Net.setClientLoaded(false);
|
||||
@@ -71,7 +73,7 @@ public class NetClient extends Module {
|
||||
|
||||
ConnectPacket c = new ConnectPacket();
|
||||
c.name = player.name;
|
||||
c.android = mobile;
|
||||
c.mobile = mobile;
|
||||
c.color = Color.rgba8888(player.color);
|
||||
c.uuid = Platform.instance.getUUID();
|
||||
|
||||
@@ -101,13 +103,14 @@ public class NetClient extends Module {
|
||||
Net.handleClient(WorldData.class, data -> {
|
||||
Log.info("Recieved world data: {0} bytes.", data.stream.available());
|
||||
NetworkIO.loadWorld(data.stream);
|
||||
player.set(world.getSpawnX(), world.getSpawnY());
|
||||
|
||||
finishConnecting();
|
||||
});
|
||||
|
||||
Net.handleClient(SyncPacket.class, packet -> {
|
||||
if (connecting) return;
|
||||
|
||||
Player player = players[0];
|
||||
|
||||
int players = 0;
|
||||
int enemies = 0;
|
||||
|
||||
@@ -256,7 +259,6 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(GameOverPacket.class, packet -> {
|
||||
//TODO core death effects
|
||||
quiet = true;
|
||||
ui.restart.show();
|
||||
});
|
||||
@@ -272,7 +274,7 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(UpgradePacket.class, packet -> {
|
||||
Weapon weapon = Upgrade.getByID(packet.id);
|
||||
Weapon weapon = Upgrade.getByID(packet.upgradeid);
|
||||
|
||||
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
||||
for(Player player : players) {
|
||||
@@ -326,19 +328,15 @@ public class NetClient extends Module {
|
||||
Net.disconnect();
|
||||
}
|
||||
|
||||
public void clearRecieved(){
|
||||
recieved.clear();
|
||||
}
|
||||
|
||||
void sync(){
|
||||
requests = 0;
|
||||
|
||||
if(timer.get(0, playerSyncTime)){
|
||||
for(Player player : players) {
|
||||
PositionPacket packet = new PositionPacket();
|
||||
packet.player = player;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
Player player = players[0];
|
||||
|
||||
PositionPacket packet = new PositionPacket();
|
||||
packet.player = player;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
if(timer.get(1, 60)){
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.core;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.content.Recipes;
|
||||
import io.anuke.mindustry.content.UpgradeRecipes;
|
||||
@@ -67,7 +68,7 @@ public class NetServer extends Module{
|
||||
TraceInfo trace = admins.getTraceByID(uuid);
|
||||
PlayerInfo info = admins.getInfo(uuid);
|
||||
trace.uuid = uuid;
|
||||
trace.android = packet.android;
|
||||
trace.android = packet.mobile;
|
||||
|
||||
if(admins.isIDBanned(uuid)){
|
||||
kick(id, KickReason.banned);
|
||||
@@ -106,7 +107,7 @@ public class NetServer extends Module{
|
||||
player.clientid = id;
|
||||
player.name = packet.name;
|
||||
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.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);
|
||||
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);
|
||||
packet.name = player.name;
|
||||
packet.id = player.id;
|
||||
@@ -270,7 +277,7 @@ public class NetServer extends Module{
|
||||
Net.handleServer(UpgradePacket.class, (id, packet) -> {
|
||||
Player player = connections.get(id);
|
||||
|
||||
Weapon weapon = Upgrade.getByID(packet.id);
|
||||
Weapon weapon = Upgrade.getByID(packet.upgradeid);
|
||||
|
||||
if(!state.inventory.hasItems(UpgradeRecipes.get(weapon))){
|
||||
return;
|
||||
@@ -283,7 +290,7 @@ public class NetServer extends Module{
|
||||
}
|
||||
|
||||
state.inventory.removeItems(UpgradeRecipes.get(weapon));
|
||||
Net.sendTo(id, packet, SendMode.tcp);
|
||||
Net.send(packet, SendMode.tcp);
|
||||
});
|
||||
|
||||
Net.handleServer(WeaponSwitchPacket.class, (id, packet) -> {
|
||||
|
||||
@@ -281,6 +281,7 @@ public class Renderer extends RendererModule{
|
||||
for(Player player : players){
|
||||
avgPosition.add(player.x, player.y);
|
||||
}
|
||||
avgPosition.scl(1f / players.length);
|
||||
return avgPosition;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.editor.MapEditorDialog;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.ui.dialogs.*;
|
||||
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.graphics.Draw;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.Skin;
|
||||
import io.anuke.ucore.scene.builders.build;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
@@ -52,16 +54,13 @@ public class UI extends SceneModule{
|
||||
public ChangelogDialog changelog;
|
||||
|
||||
public final MenuFragment menufrag = new MenuFragment();
|
||||
public final ToolFragment toolfrag = new ToolFragment();
|
||||
public final HudFragment hudfrag = new HudFragment();
|
||||
public final PlacementFragment placefrag = new PlacementFragment();
|
||||
public final ChatFragment chatfrag = new ChatFragment();
|
||||
public final PlayerListFragment listfrag = new PlayerListFragment();
|
||||
public final BackgroundFragment backfrag = new BackgroundFragment();
|
||||
public final LoadingFragment loadfrag = new LoadingFragment();
|
||||
public final BlockConfigFragment configfrag = new BlockConfigFragment();
|
||||
public final DebugFragment debugfrag = new DebugFragment();
|
||||
public final BlockInventoryFragment blockinvfrag = new BlockInventoryFragment();
|
||||
public final PlayerMenuFragment playermenufrag = new PlayerMenuFragment();
|
||||
|
||||
private Locale lastLocale;
|
||||
@@ -134,18 +133,23 @@ public class UI extends SceneModule{
|
||||
|
||||
act();
|
||||
|
||||
if(debug && !ui.chatfrag.chatOpen())
|
||||
renderer.record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
||||
if(debug && !ui.chatfrag.chatOpen()) {
|
||||
renderer.record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
||||
}
|
||||
|
||||
if(control.showCursor()) {
|
||||
Draw.color();
|
||||
for(int i = 0; i < players.length; i ++){
|
||||
InputHandler input = control.input(i);
|
||||
|
||||
float scl = Unit.dp.scl(3f);
|
||||
if(input.isCursorVisible()) {
|
||||
Draw.color();
|
||||
|
||||
Graphics.begin();
|
||||
Draw.rect("controller-cursor", Graphics.mouse().x, Graphics.mouse().y, 16*scl, 16*scl);
|
||||
Graphics.end();
|
||||
}
|
||||
float scl = Unit.dp.scl(3f);
|
||||
|
||||
Graphics.begin();
|
||||
Draw.rect("controller-cursor", input.getMouseX(), Gdx.graphics.getHeight() - input.getMouseY(), 16*scl, 16*scl);
|
||||
Graphics.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,19 +173,18 @@ public class UI extends SceneModule{
|
||||
traces = new TraceDialog();
|
||||
|
||||
build.begin(scene);
|
||||
|
||||
Group group = Core.scene.getRoot();
|
||||
|
||||
backfrag.build();
|
||||
hudfrag.build();
|
||||
configfrag.build();
|
||||
menufrag.build();
|
||||
placefrag.build();
|
||||
toolfrag.build();
|
||||
chatfrag.build();
|
||||
listfrag.build();
|
||||
debugfrag.build();
|
||||
blockinvfrag.build();
|
||||
playermenufrag.build();
|
||||
loadfrag.build();
|
||||
backfrag.build(group);
|
||||
hudfrag.build(group);
|
||||
menufrag.build(group);
|
||||
placefrag.build(group);
|
||||
chatfrag.build(group);
|
||||
listfrag.build(group);
|
||||
debugfrag.build(group);
|
||||
playermenufrag.build(group);
|
||||
loadfrag.build(group);
|
||||
|
||||
build.end();
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ public class Player extends Unit{
|
||||
movement.y += ya*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){
|
||||
weapon.update(this, true);
|
||||
|
||||
@@ -244,7 +244,6 @@ public class Tutorial{
|
||||
}
|
||||
|
||||
void onSwitch(){
|
||||
control.input().recipe = null;
|
||||
}
|
||||
},
|
||||
drillInfo{
|
||||
@@ -320,7 +319,6 @@ public class Tutorial{
|
||||
//world.tile(world.getCore().x + 2, world.getCore().y - 2 + i).setBlock(DistributionBlocks.conveyor, 1);
|
||||
}
|
||||
|
||||
control.input().recipe = null;
|
||||
}
|
||||
},
|
||||
turretExplanation{
|
||||
|
||||
@@ -27,8 +27,6 @@ public class BlockRenderer{
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
||||
private float storeX, storeY;
|
||||
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
|
||||
@@ -205,40 +203,4 @@ public class BlockRenderer{
|
||||
r.layer = layer;
|
||||
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;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
@@ -31,127 +31,125 @@ public class OverlayRenderer {
|
||||
|
||||
public void draw(){
|
||||
|
||||
//draw config selected block
|
||||
if(ui.configfrag.isShown()){
|
||||
Tile tile = ui.configfrag.getSelectedTile();
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
for(Player player : players) {
|
||||
|
||||
int tilex = control.input().getBlockX();
|
||||
int tiley = control.input().getBlockY();
|
||||
InputHandler input = control.input(player.playerIndex);
|
||||
|
||||
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
|
||||
if((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
||||
&& control.input().drawPlace())){
|
||||
|
||||
input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
||||
|
||||
if(input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
||||
|
||||
}else if(input.breakMode.delete && control.input().drawPlace()
|
||||
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
||||
&& (input.placeMode.delete || input.breakMode.both || !mobile)){
|
||||
|
||||
if(input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(tilex, tiley, 0, 0);
|
||||
else
|
||||
input.breakMode.draw(control.input().getBlockX(), control.input().getBlockY(),
|
||||
control.input().getBlockEndX(), control.input().getBlockEndY());
|
||||
}
|
||||
|
||||
if(ui.toolfrag.confirming){
|
||||
ToolFragment t = ui.toolfrag;
|
||||
PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
||||
//draw selected block bars and info
|
||||
if(input.recipe == null && !ui.hasMouse() && !ui.configfrag.isShown()){
|
||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
|
||||
if(tile != null && tile.block() != Blocks.air){
|
||||
Tile target = tile;
|
||||
if(tile.isLinked())
|
||||
target = tile.getLinked();
|
||||
|
||||
if(showBlockDebug && target.entity != null){
|
||||
Draw.color(Color.RED);
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Vector2 v = new Vector2();
|
||||
|
||||
Draw.tcolor(Color.YELLOW);
|
||||
Draw.tscl(0.25f);
|
||||
Array<Object> arr = target.block().getDebugInfo(target);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for(int i = 0; i < arr.size/2; i ++){
|
||||
result.append(arr.get(i*2));
|
||||
result.append(": ");
|
||||
result.append(arr.get(i*2 + 1));
|
||||
result.append("\n");
|
||||
}
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.color(0f, 0f, 0f, 0.5f);
|
||||
Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.tscl(fontscale);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if(Inputs.keyDown("block_info") && target.block().isAccessible()){
|
||||
Draw.color(Colors.get("accent"));
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
if(target.entity != null) {
|
||||
int bot = 0, top = 0;
|
||||
for (BlockBar bar : target.block().bars.list()) {
|
||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
||||
(bar.top ? -1f : 0f);
|
||||
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if(MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
|
||||
if (bar.top)
|
||||
top++;
|
||||
else
|
||||
bot++;
|
||||
}
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
//draw config selected block
|
||||
if(input.frag.config.isShown()){
|
||||
Tile tile = input.frag.config.getSelectedTile();
|
||||
tile.block().drawConfigure(tile);
|
||||
}
|
||||
|
||||
int tilex = input.getBlockX();
|
||||
int tiley = input.getBlockY();
|
||||
|
||||
//draw placement box
|
||||
if ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
|
||||
&& input.drawPlace())) {
|
||||
|
||||
input.placeMode.draw(input, input.getBlockX(),
|
||||
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||
|
||||
if (input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||
|
||||
} else if (input.breakMode.delete && input.drawPlace()
|
||||
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
|
||||
&& (input.placeMode.delete || input.breakMode.both || !mobile)) {
|
||||
|
||||
if (input.breakMode == PlaceMode.holdDelete)
|
||||
input.breakMode.draw(input, tilex, tiley, 0, 0);
|
||||
else
|
||||
input.breakMode.draw(input, input.getBlockX(),
|
||||
input.getBlockY(), input.getBlockEndX(), input.getBlockEndY());
|
||||
}
|
||||
|
||||
if (input.frag.tool.confirming) {
|
||||
ToolFragment t = input.frag.tool;
|
||||
PlaceMode.areaDelete.draw(input, t.px, t.py, t.px2, t.py2);
|
||||
}
|
||||
}
|
||||
|
||||
if(control.input().isDroppingItem()){
|
||||
Vector2 v = Graphics.mouseWorld();
|
||||
float size = 8;
|
||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||
Draw.color("accent");
|
||||
Lines.circle(v.x, v.y, 6 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.reset();
|
||||
|
||||
Tile tile = world.tileWorld(v.x, v.y);
|
||||
if(tile != null) tile = tile.target();
|
||||
if(tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0){
|
||||
Draw.color("place");
|
||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size*tilesize/2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.color();
|
||||
//draw selected block bars and info
|
||||
if (input.recipe == null && !ui.hasMouse() && !input.frag.config.isShown()) {
|
||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
|
||||
if (tile != null && tile.block() != Blocks.air) {
|
||||
Tile target = tile;
|
||||
if (tile.isLinked())
|
||||
target = tile.getLinked();
|
||||
|
||||
if (showBlockDebug && target.entity != null) {
|
||||
Draw.color(Color.RED);
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Vector2 v = new Vector2();
|
||||
|
||||
Draw.tcolor(Color.YELLOW);
|
||||
Draw.tscl(0.25f);
|
||||
Array<Object> arr = target.block().getDebugInfo(target);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < arr.size / 2; i++) {
|
||||
result.append(arr.get(i * 2));
|
||||
result.append(": ");
|
||||
result.append(arr.get(i * 2 + 1));
|
||||
result.append("\n");
|
||||
}
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.color(0f, 0f, 0f, 0.5f);
|
||||
Fill.rect(target.drawx(), target.drawy(), v.x, v.y);
|
||||
Draw.textc(result.toString(), target.drawx(), target.drawy(), v);
|
||||
Draw.tscl(fontscale);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
if (Inputs.keyDown("block_info") && target.block().isAccessible()) {
|
||||
Draw.color(Colors.get("accent"));
|
||||
Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
if (target.entity != null) {
|
||||
int bot = 0, top = 0;
|
||||
for (BlockBar bar : target.block().bars.list()) {
|
||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
||||
(bar.top ? -1f : 0f);
|
||||
|
||||
float value = bar.value.get(target);
|
||||
|
||||
if (MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
|
||||
if (bar.top)
|
||||
top++;
|
||||
else
|
||||
bot++;
|
||||
}
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (input.isDroppingItem()) {
|
||||
Vector2 v = Graphics.mouseWorld();
|
||||
float size = 8;
|
||||
Draw.rect(player.inventory.getItem().item.region, v.x, v.y, size, size);
|
||||
Draw.color("accent");
|
||||
Lines.circle(v.x, v.y, 6 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.reset();
|
||||
|
||||
Tile tile = world.tileWorld(v.x, v.y);
|
||||
if (tile != null) tile = tile.target();
|
||||
if (tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0) {
|
||||
Draw.color("place");
|
||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||
|
||||
@@ -46,9 +46,9 @@ public class AndroidInput extends InputHandler{
|
||||
}
|
||||
|
||||
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()){
|
||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
placing = false;
|
||||
@@ -79,9 +79,9 @@ public class AndroidInput extends InputHandler{
|
||||
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||
if(linked != null && linked.block().isConfigurable(linked)){
|
||||
ui.configfrag.showConfig(linked);
|
||||
}else if(!ui.configfrag.hasConfigMouse()){
|
||||
ui.configfrag.hideConfig();
|
||||
frag.config.showConfig(linked);
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(linked != null) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
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.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -22,8 +20,10 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class DesktopInput extends InputHandler{
|
||||
float mousex, mousey;
|
||||
float endx, endy;
|
||||
private float controlx, controly;
|
||||
private boolean enableHold = false;
|
||||
private boolean beganBreak;
|
||||
private boolean controlling;
|
||||
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
@@ -37,14 +37,17 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
updateController();
|
||||
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break") && !beganBreak){
|
||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown("select")){
|
||||
@@ -104,7 +107,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(Inputs.keyTap("weapon_" + keyIndex)){
|
||||
player.weapon = (Weapon) player.upgrades.get(i);
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch();
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch(player);
|
||||
}
|
||||
|
||||
keyIndex ++;
|
||||
@@ -126,13 +129,13 @@ public class DesktopInput extends InputHandler{
|
||||
showCursor = true;
|
||||
if(Inputs.keyTap("select")){
|
||||
canBeginShoot = false;
|
||||
ui.blockinvfrag.showFor(target);
|
||||
frag.inv.showFor(target);
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){
|
||||
ui.blockinvfrag.hide();
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
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.block().isConfigurable(target)){
|
||||
if((!ui.configfrag.isShown()
|
||||
|| ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor))) {
|
||||
ui.configfrag.showConfig(target);
|
||||
if((!frag.config.isShown()
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
||||
frag.config.showConfig(target);
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}else if(!ui.configfrag.hasConfigMouse()){
|
||||
if(ui.configfrag.isShown() && ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor)) {
|
||||
ui.configfrag.hideConfig();
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor)) {
|
||||
frag.config.hideConfig();
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}
|
||||
@@ -158,7 +161,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
if(Inputs.keyTap("break")){
|
||||
ui.configfrag.hideConfig();
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break")){
|
||||
@@ -196,8 +199,63 @@ public class DesktopInput extends InputHandler{
|
||||
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(){
|
||||
return (recipe != null && recipe.result.isMultiblock() &&
|
||||
recipe.result.size % 2 == 0) ?
|
||||
|
||||
@@ -30,30 +30,30 @@ public class GestureHandler extends GestureAdapter{
|
||||
public boolean tap (float x, float y, int count, int button) {
|
||||
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.mousey = y;
|
||||
|
||||
if(control.input().recipe == null)
|
||||
control.input().breakMode.tapped(input.getBlockX(), input.getBlockY());
|
||||
if(input.recipe == null)
|
||||
input.breakMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
else
|
||||
control.input().placeMode.tapped(input.getBlockX(), input.getBlockY());
|
||||
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
&& control.input().placeMode.lockCamera && state.inventory.hasItems(control.input().recipe.requirements)) &&
|
||||
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
|
||||
if(!input.isCursorVisible() && !(input.recipe != null
|
||||
&& input.placeMode.lockCamera && state.inventory.hasItems(input.recipe.requirements)) &&
|
||||
!(input.recipe == null && input.breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
player.x -= dx;
|
||||
player.y += dy;
|
||||
player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}else if(control.input().placeMode.lockCamera && (control.input().placeMode.pan && control.input().recipe != null)){
|
||||
input.player.x -= dx;
|
||||
input.player.y += dy;
|
||||
input.player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}else if(input.placeMode.lockCamera && (input.placeMode.pan && input.recipe != null)){
|
||||
input.mousex += deltaX;
|
||||
input.mousey += deltaY;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
if(pinch1.x < 0){
|
||||
@@ -72,9 +72,9 @@ public class GestureHandler extends GestureAdapter{
|
||||
}
|
||||
|
||||
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;
|
||||
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
input.player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
input.player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
pinch1.set(pointer1);
|
||||
pinch2.set(pointer2);
|
||||
|
||||
@@ -10,10 +10,13 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.ui.fragments.OverlayFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Placement;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
@@ -23,6 +26,9 @@ import io.anuke.ucore.util.Translator;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
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 Recipe recipe;
|
||||
public int rotation;
|
||||
@@ -33,12 +39,11 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public PlaceMode lastBreakMode = breakMode;
|
||||
public boolean droppingItem, transferring;
|
||||
public boolean shooting;
|
||||
public float playerSelectRange = Unit.dp.scl(60f);
|
||||
|
||||
private Translator stackTrns = new Translator();
|
||||
public OverlayFragment frag = new OverlayFragment(this);
|
||||
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||
}
|
||||
|
||||
public abstract void update();
|
||||
@@ -46,11 +51,19 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public abstract float getCursorY();
|
||||
public abstract float getCursorEndX();
|
||||
public abstract float getCursorEndY();
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||
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 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 getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
||||
public void resetCursor(){}
|
||||
public boolean isCursorVisible(){ return false; }
|
||||
|
||||
public void remove(){
|
||||
Inputs.removeProcessor(this);
|
||||
frag.remove();
|
||||
}
|
||||
|
||||
public boolean canShoot(){
|
||||
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
||||
@@ -183,7 +196,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
if(Net.active()){
|
||||
NetEvents.handlePlace(x, y, result, rotation);
|
||||
NetEvents.handlePlace(player, x, y, result, rotation);
|
||||
}
|
||||
|
||||
if(!Net.client()){
|
||||
|
||||
@@ -24,35 +24,33 @@ public enum PlaceMode{
|
||||
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 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;
|
||||
|
||||
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"));
|
||||
Lines.stroke(2f);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.size + si,
|
||||
tilesize * control.input().recipe.result.size + si);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * 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"));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void tapped(int tilex, int tiley){
|
||||
control.input().tryPlaceBlock(tilex, tiley, true);
|
||||
public void tapped(InputHandler input, int tilex, int tiley){
|
||||
input.tryPlaceBlock(tilex, tiley, true);
|
||||
}
|
||||
},
|
||||
touch{
|
||||
@@ -63,8 +61,8 @@ public enum PlaceMode{
|
||||
showCancel = true;
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.input().tryPlaceBlock(x, y, true);
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryPlaceBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
none{
|
||||
@@ -81,15 +79,15 @@ public enum PlaceMode{
|
||||
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);
|
||||
|
||||
if(tile != null && control.input().validBreak(tilex, tiley)){
|
||||
if(tile != null && input.validBreak(tilex, tiley)){
|
||||
if(tile.isLinked())
|
||||
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);
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
|
||||
}
|
||||
@@ -106,8 +104,8 @@ public enum PlaceMode{
|
||||
delete = true;
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.input().tryDeleteBlock(x, y, true);
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryDeleteBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
areaDelete{
|
||||
@@ -123,7 +121,7 @@ public enum PlaceMode{
|
||||
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;
|
||||
|
||||
process(tilex, tiley, endx, endy);
|
||||
@@ -150,7 +148,7 @@ public enum PlaceMode{
|
||||
Tile tile = world.tile(cx, cy);
|
||||
if(tile != null && tile.getLinked() != null)
|
||||
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(),
|
||||
tile.block().size * t, tile.block().size * t);
|
||||
}
|
||||
@@ -158,20 +156,20 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
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);
|
||||
Draw.alpha(0.3f);
|
||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||
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);
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
|
||||
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) {
|
||||
t.confirming = true;
|
||||
t.px = tilex;
|
||||
@@ -186,7 +184,7 @@ public enum PlaceMode{
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
if(control.input().tryDeleteBlock(cx, cy, first)){
|
||||
if(input.tryDeleteBlock(cx, cy, first)){
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
@@ -235,16 +233,16 @@ public enum PlaceMode{
|
||||
showRotate = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
if(mobile && !Gdx.input.isTouched(0) && !control.showCursor()){
|
||||
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
if(mobile && !Gdx.input.isTouched(0) && !input.isCursorVisible()){
|
||||
return;
|
||||
}
|
||||
|
||||
float t = tilesize;
|
||||
Block block = control.input().recipe.result;
|
||||
Block block = input.recipe.result;
|
||||
Vector2 offset = block.getPlaceOffset();
|
||||
|
||||
process(tilex, tiley, endx, endy);
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
@@ -267,10 +265,10 @@ public enum PlaceMode{
|
||||
y2 += offset.y;
|
||||
|
||||
if(tilex == endx && tiley == endy){
|
||||
cursor.draw(tilex, tiley, endx, endy);
|
||||
cursor.draw(input, tilex, tiley, endx, endy);
|
||||
}else{
|
||||
Lines.stroke(2f);
|
||||
Draw.color(control.input().cursorNear() ? "place" : "placeInvalid");
|
||||
Draw.color(input.cursorNear() ? "place" : "placeInvalid");
|
||||
Lines.rect(x, y, x2 - x, y2 - y);
|
||||
Draw.alpha(0.3f);
|
||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||
@@ -285,9 +283,7 @@ public enum PlaceMode{
|
||||
py = ty + cy * Mathf.sign(ey - ty);
|
||||
|
||||
//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)){
|
||||
|
||||
renderer.getBlocks().handlePreview(control.input().recipe.result, block.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
|
||||
if(input.validPlace(px, py, input.recipe.result) && state.inventory.hasItems(input.recipe.requirements, amount)){
|
||||
|
||||
if(isX){
|
||||
cx += block.size;
|
||||
@@ -296,7 +292,7 @@ public enum PlaceMode{
|
||||
}
|
||||
amount ++;
|
||||
}else{ //otherwise, step by 1 until it is valid
|
||||
if(control.input().cursorNear()){
|
||||
if(input.cursorNear()){
|
||||
Lines.stroke(2f);
|
||||
Draw.color("placeInvalid");
|
||||
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;
|
||||
Lines.stroke(2f);
|
||||
Draw.color(Colors.get("placeRotate"));
|
||||
@@ -327,15 +323,15 @@ public enum PlaceMode{
|
||||
}
|
||||
}
|
||||
|
||||
public void released(int tilex, int tiley, int endx, int endy){
|
||||
process(tilex, tiley, endx, endy);
|
||||
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
|
||||
control.input().rotation = this.rotation;
|
||||
input.rotation = this.rotation;
|
||||
|
||||
boolean first = true;
|
||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||
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),
|
||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||
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)){
|
||||
endy = tiley;
|
||||
}else{
|
||||
@@ -369,7 +365,7 @@ public enum PlaceMode{
|
||||
else if(endy < tiley)
|
||||
rotation = 3;
|
||||
else
|
||||
rotation = control.input().rotation;
|
||||
rotation = input.rotation;
|
||||
|
||||
if(endx < tilex){
|
||||
int t = endx;
|
||||
@@ -398,17 +394,9 @@ public enum PlaceMode{
|
||||
|
||||
private static final Translator tr = new Translator();
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
|
||||
}
|
||||
|
||||
public void released(int tilex, int tiley, int endx, int endy){
|
||||
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
|
||||
}
|
||||
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){}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
|
||||
@@ -16,7 +16,7 @@ public class BundleLoader {
|
||||
|
||||
public static void load(){
|
||||
Settings.defaults("locale", "default");
|
||||
Settings.load("io.anuke.moment");
|
||||
Settings.load("io.anuke.mindustry");
|
||||
loadBundle();
|
||||
}
|
||||
|
||||
|
||||
@@ -172,10 +172,10 @@ public class Invoke {
|
||||
|
||||
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Remote{}
|
||||
public @interface Remote{}
|
||||
|
||||
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||
@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.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -63,20 +64,21 @@ public class NetEvents {
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleWeaponSwitch(){
|
||||
public static void handleWeaponSwitch(Player player){
|
||||
WeaponSwitchPacket packet = Pools.obtain(WeaponSwitchPacket.class);
|
||||
packet.weapon = Vars.player.weapon.id;
|
||||
packet.playerid = Vars.player.id;
|
||||
packet.weapon = player.weapon.id;
|
||||
packet.playerid = player.id;
|
||||
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);
|
||||
packet.id = weapon.id;
|
||||
packet.upgradeid = weapon.id;
|
||||
packet.playerid = player.id;
|
||||
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);
|
||||
packet.text = message;
|
||||
packet.name = player.name;
|
||||
@@ -99,12 +101,12 @@ public class NetEvents {
|
||||
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);
|
||||
packet.x = (short)x;
|
||||
packet.y = (short)y;
|
||||
packet.rotation = (byte)rotation;
|
||||
packet.playerid = Vars.player.id;
|
||||
packet.playerid = player.id;
|
||||
packet.block = block.id;
|
||||
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.*/
|
||||
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.
|
||||
|
||||
try(DataInputStream stream = new DataInputStream(is)){
|
||||
|
||||
@@ -86,16 +86,16 @@ public class Packets {
|
||||
public static class ConnectPacket implements Packet{
|
||||
public int version;
|
||||
public int players;
|
||||
public String[] names;
|
||||
public boolean android;
|
||||
public int[] colors;
|
||||
public String name;
|
||||
public boolean mobile;
|
||||
public int color;
|
||||
public byte[] uuid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(Version.build);
|
||||
IOUtils.writeString(buffer, name);
|
||||
buffer.put(android ? (byte)1 : 0);
|
||||
buffer.put(mobile ? (byte)1 : 0);
|
||||
buffer.putInt(color);
|
||||
buffer.put(uuid);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Packets {
|
||||
public void read(ByteBuffer buffer) {
|
||||
version = buffer.getInt();
|
||||
name = IOUtils.readString(buffer);
|
||||
android = buffer.get() == 1;
|
||||
mobile = buffer.get() == 1;
|
||||
color = buffer.getInt();
|
||||
uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
@@ -392,16 +392,19 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class UpgradePacket implements Packet{
|
||||
public byte id; //weapon ID only, currently
|
||||
public byte upgradeid; //weapon ID only, currently
|
||||
public int playerid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(id);
|
||||
buffer.put(upgradeid);
|
||||
buffer.putInt(playerid);
|
||||
}
|
||||
|
||||
@Override
|
||||
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){
|
||||
shootInternal(p, x, y, angle, left);
|
||||
|
||||
if(Net.active() && p == Vars.player){
|
||||
NetEvents.handleShoot(Vars.player, x, y, angle, Bits.packShort(id, (byte)(left ? 1 : 0)));
|
||||
if(Net.active() && p.isLocal){
|
||||
NetEvents.handleShoot(p, x, y, angle, Bits.packShort(id, (byte)(left ? 1 : 0)));
|
||||
}
|
||||
|
||||
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.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.player;
|
||||
import static io.anuke.mindustry.Vars.playerColors;
|
||||
import static io.anuke.mindustry.Vars.players;
|
||||
|
||||
public class ColorPickDialog extends Dialog{
|
||||
private Consumer<Color> cons;
|
||||
@@ -29,7 +29,7 @@ public class ColorPickDialog extends Dialog{
|
||||
cons.accept(color);
|
||||
hide();
|
||||
}).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;
|
||||
|
||||
if(i%4 == 3){
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -11,7 +12,7 @@ import io.anuke.ucore.util.Strings;
|
||||
|
||||
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;
|
||||
|
||||
public class HostDialog extends FloatingDialog{
|
||||
@@ -20,13 +21,15 @@ public class HostDialog extends FloatingDialog{
|
||||
public HostDialog(){
|
||||
super("$text.hostserver");
|
||||
|
||||
Player player = players[0];
|
||||
|
||||
addCloseButton();
|
||||
|
||||
content().table(t -> {
|
||||
t.add("$text.name").padRight(10);
|
||||
t.addField(Settings.getString("name"), text -> {
|
||||
if(text.isEmpty()) return;
|
||||
Vars.player.name = text;
|
||||
player.name = text;
|
||||
Settings.put("name", text);
|
||||
Settings.save();
|
||||
ui.listfrag.rebuild();
|
||||
|
||||
@@ -3,7 +3,9 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
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.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.player;
|
||||
import static io.anuke.mindustry.Vars.players;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class JoinDialog extends FloatingDialog {
|
||||
@@ -31,6 +33,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
Table local = new Table();
|
||||
Table remote = new Table();
|
||||
Table hosts = new Table();
|
||||
Json json = new Json();
|
||||
float w = 500;
|
||||
|
||||
public JoinDialog(){
|
||||
@@ -187,6 +190,8 @@ public class JoinDialog extends FloatingDialog {
|
||||
}
|
||||
|
||||
void setup(){
|
||||
Player player = players[0];
|
||||
|
||||
hosts.clear();
|
||||
|
||||
hosts.add(remote).growX();
|
||||
@@ -205,7 +210,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
t.add("$text.name").padRight(10);
|
||||
t.addField(Settings.getString("name"), text -> {
|
||||
if(text.isEmpty()) return;
|
||||
Vars.player.name = text;
|
||||
player.name = text;
|
||||
Settings.put("name", text);
|
||||
Settings.save();
|
||||
}).grow().pad(8).get().setMaxLength(40);
|
||||
@@ -304,39 +309,27 @@ public class JoinDialog extends FloatingDialog {
|
||||
}
|
||||
|
||||
private void loadServers(){
|
||||
String h = Settings.getString("servers");
|
||||
String[] list = h.split("\\|\\|\\|");
|
||||
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));
|
||||
}
|
||||
String h = Settings.getString("serverlist","{}");
|
||||
servers = json.fromJson(Array.class, h);
|
||||
}
|
||||
|
||||
private void saveServers(){
|
||||
StringBuilder out = new StringBuilder();
|
||||
for(Server server : servers){
|
||||
out.append(server.ip);
|
||||
out.append(":");
|
||||
out.append(server.port);
|
||||
out.append("|||");
|
||||
}
|
||||
Settings.putString("servers", out.toString());
|
||||
Settings.putString("serverlist", json.toJson(servers));
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
private class Server{
|
||||
public String ip;
|
||||
public int port;
|
||||
public Host host;
|
||||
public Table content;
|
||||
static class Server{
|
||||
String ip;
|
||||
int port;
|
||||
|
||||
public Server(String ip, int port){
|
||||
transient Host host;
|
||||
transient Table content;
|
||||
|
||||
Server(String ip, int port){
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
Server(){}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,6 @@ public class PausedDialog extends FloatingDialog{
|
||||
if(control.getSaves().getCurrent() == null ||
|
||||
!control.getSaves().getCurrent().isAutosave()){
|
||||
state.set(State.menu);
|
||||
control.tutorial().reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
@@ -12,7 +13,7 @@ import static io.anuke.mindustry.Vars.state;
|
||||
public class BackgroundFragment implements Fragment {
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
|
||||
Core.scene.table().addRect((a, b, w, h) -> {
|
||||
Draw.color();
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
@@ -17,9 +18,9 @@ public class BlockConfigFragment implements Fragment {
|
||||
private Tile configTile;
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
table = new Table();
|
||||
Core.scene.add(table);
|
||||
parent.addChild(table);
|
||||
}
|
||||
|
||||
public boolean isShown(){
|
||||
@@ -41,7 +42,7 @@ public class BlockConfigFragment implements Fragment {
|
||||
table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true),
|
||||
Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out));
|
||||
|
||||
table.update(()->{
|
||||
table.update(() -> {
|
||||
table.setOrigin(Align.center);
|
||||
Vector2 pos = Graphics.screen(tile.drawx(), tile.drawy());
|
||||
table.setPosition(pos.x, pos.y, Align.center);
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
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.ui.ItemImage;
|
||||
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.function.BooleanProvider;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.event.HandCursorListener;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
@@ -29,12 +32,20 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BlockInventoryFragment implements Fragment {
|
||||
private Table table;
|
||||
private boolean shown;
|
||||
private Tile tile;
|
||||
private InputHandler input;
|
||||
|
||||
public BlockInventoryFragment(InputHandler input){
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
table = new Table();
|
||||
table.setVisible(() -> !state.is(State.menu));
|
||||
table.setVisible(() -> !state.is(State.menu) && shown);
|
||||
parent.addChild(table);
|
||||
}
|
||||
|
||||
public void showFor(Tile t){
|
||||
@@ -44,18 +55,20 @@ public class BlockInventoryFragment implements Fragment {
|
||||
}
|
||||
|
||||
public void hide(){
|
||||
shown = false;
|
||||
table.clear();
|
||||
table.remove();
|
||||
table.setTouchable(Touchable.disabled);
|
||||
table.update(() -> {});
|
||||
tile = null;
|
||||
}
|
||||
|
||||
private void rebuild(){
|
||||
Player player = input.player;
|
||||
|
||||
shown = true;
|
||||
IntSet container = new IntSet();
|
||||
|
||||
table.clear();
|
||||
if(table.getParent() == null) Core.scene.add(table);
|
||||
table.background("clear");
|
||||
table.setTouchable(Touchable.enabled);
|
||||
table.update(() -> {
|
||||
@@ -137,6 +150,8 @@ public class BlockInventoryFragment implements Fragment {
|
||||
}
|
||||
|
||||
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));
|
||||
float tx = tv.x, ty = tv.y;
|
||||
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.Hue;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.event.ClickListener;
|
||||
@@ -40,8 +41,8 @@ public class BlocksFragment implements Fragment{
|
||||
private Recipe hoveredDescriptionRecipe;
|
||||
private IntSet itemset = new IntSet();
|
||||
|
||||
public void build(){
|
||||
InputHandler input = control.input();
|
||||
public void build(Group parent){
|
||||
InputHandler input = control.input(0);
|
||||
|
||||
new table(){{
|
||||
abottom();
|
||||
@@ -180,10 +181,9 @@ public class BlocksFragment implements Fragment{
|
||||
table.add(image).size(size + 8);
|
||||
|
||||
image.update(() -> {
|
||||
boolean canPlace = !control.tutorial().active() || control.tutorial().canPlace();
|
||||
boolean has = (state.inventory.hasItems(r.requirements)) && canPlace;
|
||||
boolean has = (state.inventory.hasItems(r.requirements));
|
||||
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));
|
||||
});
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
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.LabelStyle;
|
||||
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.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.players;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.ucore.core.Core.scene;
|
||||
import static io.anuke.ucore.core.Core.skin;
|
||||
|
||||
public class ChatFragment extends Table implements Fragment{
|
||||
private final static int messagesShown = 10;
|
||||
private final static int maxLength = 150;
|
||||
private Array<ChatMessage> messages = new Array<>();
|
||||
private float fadetime;
|
||||
private boolean chatOpen = false;
|
||||
@@ -79,7 +80,7 @@ public class ChatFragment extends Table implements Fragment{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
scene.add(this);
|
||||
}
|
||||
|
||||
@@ -95,12 +96,12 @@ public class ChatFragment extends Table implements Fragment{
|
||||
fieldlabel.setStyle(fieldlabel.getStyle());
|
||||
|
||||
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().fontColor = Color.WHITE;
|
||||
chatfield.getStyle().font = skin.getFont("default-font-chat");
|
||||
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);
|
||||
|
||||
@@ -167,7 +168,7 @@ public class ChatFragment extends Table implements Fragment{
|
||||
if(message.replaceAll(" ", "").isEmpty()) return;
|
||||
|
||||
history.insert(1, message);
|
||||
NetEvents.handleSendMessage(message);
|
||||
NetEvents.handleSendMessage(players[0], message);
|
||||
}
|
||||
|
||||
public void toggle(){
|
||||
|
||||
@@ -9,9 +9,9 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
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.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
@@ -41,7 +41,10 @@ public class DebugFragment implements Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(){
|
||||
public void build(Group parent){
|
||||
|
||||
Player player = players[0];
|
||||
|
||||
new table(){{
|
||||
visible(() -> debug);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
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.Settings;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
@@ -36,7 +37,7 @@ public class HudFragment implements Fragment{
|
||||
private float dsize = 58;
|
||||
private float isize = 40;
|
||||
|
||||
public void build(){
|
||||
public void build(Group parent){
|
||||
|
||||
//menu at top left
|
||||
new table(){{
|
||||
@@ -116,13 +117,6 @@ public class HudFragment implements Fragment{
|
||||
|
||||
}}.end();
|
||||
|
||||
//tutorial ui table
|
||||
new table(){{
|
||||
control.tutorial().buildUI(this);
|
||||
|
||||
visible(() -> control.tutorial().active());
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
visible(() -> !state.is(State.menu));
|
||||
atop();
|
||||
@@ -174,17 +168,6 @@ public class HudFragment implements Fragment{
|
||||
});
|
||||
}}.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(){{
|
||||
abottom();
|
||||
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
||||
@@ -193,7 +176,7 @@ public class HudFragment implements Fragment{
|
||||
|
||||
}}.end();
|
||||
|
||||
blockfrag.build();
|
||||
blockfrag.build(Core.scene.getRoot());
|
||||
}
|
||||
|
||||
private void toggleMenus(){
|
||||
@@ -236,7 +219,7 @@ public class HudFragment implements Fragment{
|
||||
|
||||
new label(()-> state.enemies > 0 ?
|
||||
getEnemiesRemaining() :
|
||||
(control.tutorial().active() || state.mode.disableWaveTimer) ? "$text.waiting"
|
||||
(state.mode.disableWaveTimer) ? "$text.waiting"
|
||||
: Bundles.format("text.wave.waiting", (int) (state.wavetime / 60f)))
|
||||
.minWidth(126).padLeft(-6).left();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
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.table;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
@@ -11,7 +12,7 @@ public class LoadingFragment implements Fragment {
|
||||
private Table table;
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
|
||||
table = new table("loadDim"){{
|
||||
touchable(Touchable.enabled);
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.ui.MenuButton;
|
||||
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.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
@@ -14,7 +15,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class MenuFragment implements Fragment{
|
||||
|
||||
public void build(){
|
||||
public void build(Group parent){
|
||||
new table(){{
|
||||
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.PlaceMode;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
@@ -28,10 +29,10 @@ public class PlacementFragment implements Fragment{
|
||||
Table breaktable, next, container;
|
||||
Label modelabel;
|
||||
|
||||
public void build(){
|
||||
public void build(Group parent){
|
||||
if(!mobile) return;
|
||||
|
||||
InputHandler input = control.input();
|
||||
InputHandler input = control.input(0);
|
||||
|
||||
float s = 50f;
|
||||
float translation = Unit.dp.scl(58f);
|
||||
@@ -130,7 +131,7 @@ public class PlacementFragment implements Fragment{
|
||||
defaults().padBottom(-5.5f);
|
||||
|
||||
ImageButton button = new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
||||
control.input().resetCursor();
|
||||
input.resetCursor();
|
||||
input.breakMode = mode;
|
||||
input.lastBreakMode = mode;
|
||||
if (!mode.both){
|
||||
@@ -183,7 +184,7 @@ public class PlacementFragment implements Fragment{
|
||||
if (!mode.shown || mode.delete) continue;
|
||||
|
||||
new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
|
||||
control.input().resetCursor();
|
||||
input.resetCursor();
|
||||
input.placeMode = mode;
|
||||
input.lastPlaceMode = mode;
|
||||
modeText(Bundles.format("text.mode.place", mode.toString()));
|
||||
@@ -215,6 +216,8 @@ public class PlacementFragment implements Fragment{
|
||||
}
|
||||
|
||||
private void toggle(boolean show){
|
||||
InputHandler input = control.input(0);
|
||||
|
||||
float dur = 0.3f;
|
||||
Interpolation in = Interpolation.pow3Out;
|
||||
|
||||
@@ -223,8 +226,8 @@ public class PlacementFragment implements Fragment{
|
||||
breaktable.getParent().swapActor(breaktable, next);
|
||||
|
||||
if(!show){
|
||||
control.input().breakMode = PlaceMode.none;
|
||||
if(control.input().placeMode.delete) control.input().placeMode = PlaceMode.none;
|
||||
input.breakMode = PlaceMode.none;
|
||||
if(input.placeMode.delete) input.placeMode = PlaceMode.none;
|
||||
breaktable.actions(Actions.translateBy(-breaktable.getWidth() - 5, 0, dur, in), Actions.call(() -> shown = false));
|
||||
}else{
|
||||
shown = true;
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.ui.BorderImage;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
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.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
@@ -32,7 +33,7 @@ public class PlayerListFragment implements Fragment{
|
||||
ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
||||
|
||||
@Override
|
||||
public void build(){
|
||||
public void build(Group parent){
|
||||
new table(){{
|
||||
new table("pane"){{
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
float bs = (h + 14)/2f;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
public class PlayerMenuFragment implements Fragment {
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
public void build(Group parent) {
|
||||
/*
|
||||
new table(){{
|
||||
new table("clear"){{
|
||||
|
||||
@@ -9,16 +9,22 @@ import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
public class ToolFragment implements Fragment{
|
||||
private Table tools;
|
||||
private InputHandler input;
|
||||
|
||||
public int px, py, px2, py2;
|
||||
public boolean confirming;
|
||||
|
||||
public void build(){
|
||||
InputHandler input = control.input();
|
||||
|
||||
|
||||
public ToolFragment(InputHandler input){
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
float isize = 14*3;
|
||||
|
||||
tools = new Table();
|
||||
@@ -38,15 +44,13 @@ public class ToolFragment implements Fragment{
|
||||
|
||||
tools.addImageButton("icon-check", isize, () -> {
|
||||
if(input.placeMode == PlaceMode.areaDelete && confirming){
|
||||
input.placeMode.released(px, py, px2, py2);
|
||||
input.placeMode.released(input, px, py, px2, py2);
|
||||
confirming = false;
|
||||
}else{
|
||||
input.placeMode.tapped(control.input().getBlockX(), control.input().getBlockY());
|
||||
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
}
|
||||
});
|
||||
|
||||
Core.scene.add(tools);
|
||||
|
||||
tools.setVisible(() ->
|
||||
!state.is(State.menu) && mobile && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
|
||||
input.placeMode == PlaceMode.cursor) || confirming)
|
||||
@@ -58,13 +62,16 @@ public class ToolFragment implements Fragment{
|
||||
tools.setPosition(v.x, v.y, Align.top);
|
||||
|
||||
}else{
|
||||
tools.setPosition(control.input().getCursorX(),
|
||||
Gdx.graphics.getHeight() - control.input().getCursorY() - 15*Core.cameraScale, Align.top);
|
||||
tools.setPosition(input.getCursorX(),
|
||||
Gdx.graphics.getHeight() - input.getCursorY() - 15*Core.cameraScale, Align.top);
|
||||
}
|
||||
|
||||
if(input.placeMode != PlaceMode.areaDelete){
|
||||
confirming = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
parent.addChild(tools);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user