// public void DrawScoreForPlayer( Player netControl, // List<string> teamsFoundSoFar, List<string> teamStrings, string headerString ) { public IEnumerable <TableEntryData> GetRowEntries(object row, float x, float y, float labelHeight, int areaWidth, List <float> widthPercentages, int fontSize) { TableEntryData entryData = new TableEntryData(); entryData.fontSize = fontSize; Player player = row as Player; bool isDead = false; if (player != null) { isDead = null == player.PlayerGameObject; } List <object> values = func_getValuesForRow(row); for (int i = 0; i < widthPercentages.Count; i++) { entryData.color = Color.white; if (isDead) { entryData.color = Color.black; } entryData.text = values [i].ToString(); // switch (i) { // case 0: // s += player.playerName; // break ; // case 1: // s += player.GetComponent<Score>().numKills; // break; // case 2: // s += player.GetComponent<Score>().numDeaths; // break; // case 3: // s += player.Ping; // break; // case 4: // s += player.health; // break; // case 5: // s += player.GetComponent<NetworkIdentity> ().netId.Value; // break; // case 6: // if (!isDead && player.PlayerGameObject != null) // s += player.PlayerGameObject.GetComponent<NetworkIdentity> ().netId.Value.ToString (); // break; // case 7: // s += player.status.ToString (); // break; // case 8: // if (player.conn != null) // s += player.conn.address.ToString (); // break; // } entryData.rect = new Rect(x, y, areaWidth * widthPercentages [i], labelHeight); yield return(entryData); x += areaWidth * widthPercentages [i]; } /* * string s = ""; * if (isDead) * s += "<color=black>"; * s += string.Format ("{0,-35} {1,-7} {2,-8} {3,-6}", new object[] { * netControl.playerName, * netControl.numKills, * netControl.numDeaths, * netControl.ping + " ms" * }); * // add on server: health, net id of net control object, net id of playing object, status, ip * if (NetworkManager.singleton.IsServer ()) { * // {0,-9} {1,-7} {2,-7} {3,-15} {4,-15} * * Player player = NetworkManager.singleton.GetPlayerByName (netControl.playerName); * string playingObjectIdStr = "" ; * if (!isDead && netControl.playerGameObject != null) * playingObjectIdStr = netControl.playerGameObject.GetComponent<NetworkIdentity> ().netId.Value.ToString (); * string addressStr = ""; * if (player.conn != null) * addressStr = player.conn.address.ToString (); * * s += string.Format ("{0,-9} {1,-7} {2,-7} {3,-15} {4,-15}", new object[] { * netControl.health, * netControl.GetComponent<NetworkIdentity>().netId.Value, * playingObjectIdStr, * player.status.ToString(), * addressStr * }); * * } * * if (isDead) * s += "</color>"; * * int index = teamsFoundSoFar.FindIndex (teamName => teamName == netControl.team); * if (index < 0) { * teamsFoundSoFar.Add (netControl.team); * teamStrings.Add ("<color=red>Team: " + netControl.team + "\n" + headerString + "</color>" + s + "\n"); * } else { * // already found this team * teamStrings [index] += s + "\n"; * } */ }
public virtual IEnumerable <TableEntryData> GetTableEntries() { int width = GetTableWidth(); int height = GetTableHeight(); width -= HorizontalMargin * 2; height -= VerticalMargin * 2; // gather necessery info var rowsPerTeam = func_getRowsPerTeam(); int numPlayers = rowsPerTeam.Sum(rpt => rpt.rows.Count); int numRows = numPlayers + rowsPerTeam.Count * 2; // from 0 to 4 int spaceBetween = Mathf.FloorToInt(4 - numRows / 10.0f); if (spaceBetween < 0) { spaceBetween = 0; } int totalSpaceBetween = (numRows - 1) * spaceBetween; // float labelHeightF = 18 * (height - totalSpaceBetween) / 400.0f ; // if (numRows != 0) // labelHeightF *= 20.0f / numRows; float labelHeightF = (height - totalSpaceBetween); if (numRows != 0) { labelHeightF /= numRows; } if (labelHeightF > 30) { labelHeightF = 30; } float fontSizeF = labelHeightF * 0.6f; // * height / 400.0f ; if (fontSizeF > 15) { fontSizeF = 15; } // if (numPlayers > 20) { // if num players is higher than 20, font size and label height need to be decreased // fontSizeF *= 20.0f / numPlayers ; // labelHeightF *= 20.0f / numPlayers ; // } int fontSize = Mathf.FloorToInt(fontSizeF); var widthPercentages = func_getColumnsWidthPercentages(); var columnNames = func_getColumnsNames(); /* * string headerStr = string.Format( "{0,-35} {1,-7} {2,-8} {3,-6}", new object[] {"name", "kills", "deaths", "ping"} ) ; * // add on server: health, net id of net control object and playing object, status, ip * if (NetworkManager.singleton.IsServer ()) { * headerStr += string.Format ("{0,-9} {1,-7} {2,-7} {3,-15} {4,-15}", new object[] { "health", "NetControlObjectId", "PlayingObjectId", "status", "ip" }); * } * headerStr += "\n"; */ // float x = rect.x; // float y = rect.y; float x = HorizontalMargin; float y = VerticalMargin; TableEntryData entryData = new TableEntryData(); entryData.color = Color.black; entryData.fontSize = fontSize; entryData.isHeader = false; // GUI.Label( new Rect( x, y, rect.width, labelHeightF ), "font size: " + fontSize + ", label height: " + labelHeightF, labelStyle ); // y += labelHeightF + spaceBetween; foreach (var pair in rowsPerTeam) { string team = pair.team; // team name entryData.color = Color.red; entryData.rect = new Rect(x, y, width, labelHeightF); entryData.text = team; yield return(entryData); y += labelHeightF + spaceBetween; // column header names entryData.isHeader = true; for (int j = 0; j < widthPercentages.Count; j++) { entryData.color = Color.red; entryData.text = columnNames [j]; if (SortingColumn == entryData.text) { // add a little sign, so that we know this is the sorting column if (DescendingSort) { entryData.text += singleton.sortingColumnDescendingTextSuffix; } else { entryData.text += singleton.sortingColumnAscendingTextSuffix; } } entryData.rect = new Rect(x, y, width * widthPercentages [j], labelHeightF); yield return(entryData); x += width * widthPercentages [j]; } entryData.isHeader = false; // x = rect.x ; x = HorizontalMargin; y += labelHeightF + spaceBetween; // rows SortRows(pair.rows); foreach (var row in pair.rows) { foreach (var e in this.GetRowEntries(row, x, y, labelHeightF, width, widthPercentages, fontSize)) { yield return(e); } y += labelHeightF + spaceBetween; } } }