Weapons are now displayed for players
This commit is contained in:
@@ -252,6 +252,15 @@ public class NetClient extends Module {
|
||||
GameState.set(State.menu);
|
||||
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked." + KickReason.values()[packet.reason].name()));
|
||||
});
|
||||
|
||||
Net.handle(WeaponSwitchPacket.class, packet -> {
|
||||
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
||||
|
||||
if(player == null) return;
|
||||
|
||||
player.weaponLeft = (Weapon)Upgrade.getByID(packet.left);
|
||||
player.weaponRight = (Weapon)Upgrade.getByID(packet.right);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -265,6 +274,14 @@ public class NetClient extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleWeaponSwitch(){
|
||||
WeaponSwitchPacket packet = new WeaponSwitchPacket();
|
||||
packet.left = Vars.player.weaponLeft.id;
|
||||
packet.right = Vars.player.weaponRight.id;
|
||||
packet.playerid = Vars.player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public void handleUpgrade(Weapon weapon){
|
||||
UpgradePacket packet = new UpgradePacket();
|
||||
packet.id = weapon.id;
|
||||
|
||||
@@ -147,8 +147,7 @@ public class NetServer extends Module{
|
||||
Net.handleServer(ChatPacket.class, packet -> {
|
||||
Player player = connections.get(Net.getLastConnection());
|
||||
|
||||
if(player == null)
|
||||
return; //GHOSTS AAAA
|
||||
if(player == null) return; //GHOSTS AAAA
|
||||
|
||||
packet.name = player.name;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
@@ -158,6 +157,19 @@ public class NetServer extends Module{
|
||||
Weapon weapon = (Weapon)Upgrade.getByID(packet.id);
|
||||
Vars.control.removeItems(UpgradeRecipes.get(weapon));
|
||||
});
|
||||
|
||||
Net.handleServer(WeaponSwitchPacket.class, packet -> {
|
||||
Player player = connections.get(Net.getLastConnection());
|
||||
|
||||
if(player == null) return;
|
||||
|
||||
packet.playerid = player.id;
|
||||
|
||||
player.weaponLeft = (Weapon)Upgrade.getByID(packet.left);
|
||||
player.weaponRight = (Weapon)Upgrade.getByID(packet.right);
|
||||
|
||||
Net.sendExcept(player.clientid, packet, SendMode.tcp);
|
||||
});
|
||||
}
|
||||
|
||||
public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){
|
||||
|
||||
@@ -88,15 +88,28 @@ public class Player extends DestructibleEntity implements Syncable{
|
||||
}
|
||||
|
||||
if((Vars.debug && (!Vars.showPlayer || !Vars.showUI)) || (isAndroid && isLocal)) return;
|
||||
boolean snap = Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal;
|
||||
|
||||
String part = isAndroid ? "ship" : "mech";
|
||||
|
||||
if(Vars.snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal){
|
||||
if(snap){
|
||||
Draw.rect(part + "-" + mech.name, (int)x, (int)y, angle-90);
|
||||
}else{
|
||||
Draw.rect(part + "-" + mech.name, x, y, angle-90);
|
||||
}
|
||||
|
||||
|
||||
if(!isAndroid) {
|
||||
for (boolean b : new boolean[]{true, false}) {
|
||||
Angles.translation(angle + Mathf.sign(b) * -50f, 3.5f);
|
||||
String name = b ? weaponLeft.name : weaponRight.name;
|
||||
float s = 5f;
|
||||
if(snap){
|
||||
Draw.rect(name, (int)x + Angles.x(), (int)y + Angles.y(), s, s, angle- 90);
|
||||
}else{
|
||||
Draw.rect(name, x + Angles.x(), y + Angles.y(), s, s, angle - 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@@ -81,6 +82,7 @@ public class DesktopInput extends InputHandler{
|
||||
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
|
||||
if(Inputs.keyTap("weapon_" + i)){
|
||||
player.weaponLeft = player.weaponRight = control.getWeapons().get(i - 1);
|
||||
Vars.netClient.handleWeaponSwitch();
|
||||
ui.weaponfrag.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,4 +118,9 @@ public class Packets {
|
||||
public static class UpgradePacket{
|
||||
public byte id; //weapon ID only, currently
|
||||
}
|
||||
|
||||
public static class WeaponSwitchPacket{
|
||||
public int playerid;
|
||||
public byte left, right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class Registrator {
|
||||
ChatPacket.class,
|
||||
KickPacket.class,
|
||||
UpgradePacket.class,
|
||||
WeaponSwitchPacket.class,
|
||||
|
||||
Class.class,
|
||||
byte[].class,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@@ -48,6 +49,7 @@ public class WeaponFragment implements Fragment{
|
||||
player.weaponLeft = weapon;
|
||||
}
|
||||
button.setChecked(true);
|
||||
Vars.netClient.handleWeaponSwitch();
|
||||
});
|
||||
|
||||
button.update(() -> button.setChecked(weapon == player.weaponLeft || weapon == player.weaponRight)); //TODO
|
||||
|
||||
Reference in New Issue
Block a user