public void writeTo(DataOutputStream dos) throws IOException { dos.writeShort(INITIAL_VERSION); dos.writeBoolean(available); if (available) { dos.writeByte(teamId == null ? -1 : teamId); dos.writeUTF(civilisation == null ? "" : civilisation.name()); dos.writeUTF(playerType == null ? "" : playerType.name()); } }
public static PlayerSetting readFromStream(DataInputStream dis) throws IOException { dis.readShort(); // read version boolean available = dis.readBoolean(); if (available) { byte readTeamId = dis.readByte(); Byte teamId = readTeamId == -1 ? null : readTeamId; String civilizationName = dis.readUTF(); ECivilisation civilisation = civilizationName.isEmpty() ? null : ECivilisation.valueOf(civilizationName); String playerTypeName = dis.readUTF(); EPlayerType playerType = playerTypeName.isEmpty() ? null : EPlayerType.valueOf(playerTypeName); return new PlayerSetting(true, playerType, civilisation, teamId); } else { return new PlayerSetting(); } }
@Override public String toString() { if (civilisation == null) { return Labels.getString("civilisation-random"); } return Labels.getString("civilisation-" + civilisation.name()); } }
private void updateAiPlayerName() { if (typeComboBox.getSelectedItem() == null || civilisationComboBox.getSelectedItem() == null) { return; } if (EPlayerType.HUMAN != getPlayerType()) { ECivilisation civilisation = getCivilisation(); if (civilisation != null) { setPlayerName(Labels.getString("player-name-" + getCivilisation().name() + "-" + ((PlayerTypeUiWrapper) typeComboBox.getSelectedItem()).getPlayerType().name())); } else { setPlayerName(Labels.getString("player-name-random")); } setReady(true); } else { setReady(false); } }