Implemented name colors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
@@ -32,8 +33,10 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class NetClient extends Module {
|
||||
public static final Color[] colorArray = {Color.ORANGE, Color.SCARLET, Color.LIME,
|
||||
Color.GOLD, Color.PINK, Color.SKY, Color.GOLD};
|
||||
boolean connecting = false;
|
||||
boolean gotEntities = false;
|
||||
boolean gotEntities = false, gotData = false;
|
||||
boolean kicked = false;
|
||||
float playerSyncTime = 2;
|
||||
float dataTimeout = 60*10;
|
||||
@@ -43,6 +46,7 @@ public class NetClient extends Module {
|
||||
Net.handle(Connect.class, packet -> {
|
||||
connecting = true;
|
||||
gotEntities = false;
|
||||
gotData = false;
|
||||
kicked = false;
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
@@ -87,6 +91,7 @@ public class NetClient extends Module {
|
||||
connecting = false;
|
||||
Vars.ui.loadfrag.hide();
|
||||
Vars.ui.join.hide();
|
||||
gotData = true;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,8 +101,10 @@ public class NetClient extends Module {
|
||||
Timers.run(10f, () -> { //TODO hack. should only run once world data is recieved
|
||||
Vars.control.playerGroup.remap(Vars.player, data.playerid);
|
||||
|
||||
for (Player player : data.players) {
|
||||
for (int i = 0; i < data.players.length; i ++) {
|
||||
Player player = data.players[i];
|
||||
if (player.id != data.playerid) {
|
||||
player.weaponLeft = player.weaponRight = (Weapon) Upgrade.getByID(data.playerWeapons[i]);
|
||||
player.add();
|
||||
}
|
||||
}
|
||||
@@ -249,7 +256,7 @@ public class NetClient extends Module {
|
||||
|
||||
Net.handle(Player.class, Player::add);
|
||||
|
||||
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, packet.name)));
|
||||
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name))));
|
||||
|
||||
Net.handle(KickPacket.class, packet -> {
|
||||
kicked = true;
|
||||
@@ -285,12 +292,16 @@ public class NetClient extends Module {
|
||||
if(!Net.client() || !Net.active()) return;
|
||||
|
||||
if(!GameState.is(State.menu) && Net.active()){
|
||||
sync();
|
||||
if(gotEntities && gotData) sync();
|
||||
}else if(!connecting){
|
||||
Net.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public String colorizeName(int id, String name){
|
||||
return name == null ? null : "[#" + colorArray[id % colorArray.length].toString().toUpperCase() + "]" + name;
|
||||
}
|
||||
|
||||
public void handleBlockConfig(Tile tile, byte data){
|
||||
BlockConfigPacket packet = new BlockConfigPacket();
|
||||
packet.data = data;
|
||||
@@ -322,9 +333,10 @@ public class NetClient extends Module {
|
||||
ChatPacket packet = new ChatPacket();
|
||||
packet.text = message;
|
||||
packet.name = Vars.player.name;
|
||||
packet.id = Vars.player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
|
||||
Vars.ui.chatfrag.addMessage(packet.text, Vars.player.name);
|
||||
Vars.ui.chatfrag.addMessage(packet.text, colorizeName(Vars.player.id, Vars.player.name));
|
||||
}
|
||||
|
||||
public void handleShoot(Weapon weapon, float x, float y, float angle){
|
||||
|
||||
@@ -66,8 +66,13 @@ public class NetServer extends Module{
|
||||
|
||||
dp.playerid = player.id;
|
||||
dp.players = Vars.control.playerGroup.all().toArray(Player.class);
|
||||
dp.playerWeapons = new byte[dp.players.length];
|
||||
dp.weapons = weapons.get(packet.name, new ByteArray()).toArray();
|
||||
|
||||
for(int i = 0; i < dp.playerWeapons.length; i ++){
|
||||
dp.playerWeapons[i] = dp.players[i].weaponLeft.id;
|
||||
}
|
||||
|
||||
UCore.log("Sending entities: " + Arrays.toString(dp.players));
|
||||
|
||||
Net.sendExcept(id, player, SendMode.tcp);
|
||||
@@ -140,8 +145,9 @@ public class NetServer extends Module{
|
||||
}
|
||||
|
||||
packet.name = player.name;
|
||||
packet.id = player.id;
|
||||
Net.sendExcept(player.clientid, packet, SendMode.tcp);
|
||||
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, packet.name));
|
||||
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name)));
|
||||
});
|
||||
|
||||
Net.handleServer(UpgradePacket.class, packet -> {
|
||||
|
||||
@@ -4,10 +4,12 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -214,12 +216,21 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
void drawPlayerNames(){
|
||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
||||
|
||||
Draw.tscl(0.25f/2);
|
||||
for(Player player : Vars.control.playerGroup.all()){
|
||||
if(!player.isLocal){
|
||||
Draw.text(player.name, player.x, player.y + 7);
|
||||
if(!player.isLocal){
|
||||
layout.setText(Core.font, player.name);
|
||||
Draw.color(0f, 0f, 0f, 0.3f);
|
||||
Draw.rect("blank", player.x, player.y + 8 - layout.height/2, layout.width + 2, layout.height + 2);
|
||||
Draw.color();
|
||||
Draw.tcolor(NetClient.colorArray[player.id % NetClient.colorArray.length]);
|
||||
Draw.text(player.name, player.x, player.y + 8);
|
||||
Draw.tcolor();
|
||||
}
|
||||
}
|
||||
Pools.free(layout);
|
||||
Draw.tscl(Vars.fontscale);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
@@ -182,7 +183,7 @@ public class EnemyType {
|
||||
|
||||
//no tile found
|
||||
if(enemy.target == null){
|
||||
enemy.target = Entities.getClosest(Vars.control.playerGroup, enemy.x, enemy.y, range, e -> true);
|
||||
enemy.target = Entities.getClosest(Vars.control.playerGroup, enemy.x, enemy.y, range, e -> !((Player)e).isAndroid);
|
||||
}
|
||||
}else if(nearCore){
|
||||
enemy.target = Vars.control.getCore().entity;
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Packets {
|
||||
|
||||
public static class EntityDataPacket{
|
||||
public Player[] players;
|
||||
public byte[] playerWeapons;
|
||||
public int playerid;
|
||||
public byte[] weapons;
|
||||
}
|
||||
@@ -106,6 +107,7 @@ public class Packets {
|
||||
public static class ChatPacket{
|
||||
public String name;
|
||||
public String text;
|
||||
public int id;
|
||||
}
|
||||
|
||||
public static class KickPacket{
|
||||
|
||||
@@ -194,7 +194,7 @@ public class ChatFragment extends Table implements Fragment{
|
||||
if(sender == null){ //no sender, this is a server message?
|
||||
formattedMessage = message;
|
||||
}else{
|
||||
formattedMessage = "[CORAL]["+sender+"]: [YELLOW]"+message;
|
||||
formattedMessage = "[CORAL][["+sender+"[CORAL]]:[WHITE] "+message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user