From 1a0ad91845e774fd73994a1130beaeb3f1d66e17 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Tue, 20 Dec 2011 17:31:11 +0000 Subject: [PATCH] Adding tournament name to table. --- .../gempukku/lotro/hall/HallInfoVisitor.java | 2 +- .../com/gempukku/lotro/hall/HallServer.java | 20 ++++++++++++++++--- .../gempukku/lotro/server/HallResource.java | 3 ++- .../src/main/webapp/js/hallUi.js | 8 ++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java index ab061a5f6..ac96f747a 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallInfoVisitor.java @@ -5,7 +5,7 @@ import java.util.Set; public interface HallInfoVisitor { public void playerIsWaiting(boolean waiting); - public void visitTable(String tableId, String gameId, String tableStatus, String formatName, Set playerIds, String winner); + public void visitTable(String tableId, String gameId, String tableStatus, String formatName, String tournamentName, Set playerIds, String winner); public void runningPlayerGame(String gameId); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index 0dccb7ab0..bc20fc413 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -27,6 +27,7 @@ public class HallServer extends AbstractServer { private Map _awaitingTables = new ConcurrentHashMap(); private Map _runningTables = new ConcurrentHashMap(); private Map _runningTableFormatNames = new ConcurrentHashMap(); + private Map _runningTableTournamentNames = new ConcurrentHashMap(); private int _nextTableId = 1; private final int _playerInactivityPeriod = 1000 * 10; // 10 seconds @@ -171,6 +172,14 @@ public class HallServer extends AbstractServer { createGame(tableId, awaitingTable); } + private String getTournamentName(AwaitingTable table) { + String tournamentName = "Casual"; + final League league = table.getLeague(); + if (league != null) + tournamentName = league.getName() + " - " + table.getLeagueSerie().getType(); + return tournamentName; + } + private void createGame(String tableId, AwaitingTable awaitingTable) { Set players = awaitingTable.getPlayers(); LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]); @@ -182,6 +191,7 @@ public class HallServer extends AbstractServer { lotroGameMediator.startGame(); _runningTables.put(tableId, gameId); _runningTableFormatNames.put(tableId, awaitingTable.getLotroFormat().getName()); + _runningTableTournamentNames.put(tableId, getTournamentName(awaitingTable)); _awaitingTables.remove(tableId); } @@ -208,14 +218,17 @@ public class HallServer extends AbstractServer { visitor.playerIsWaiting(isPlayerWaiting(player.getName())); Map copy = new HashMap(_awaitingTables); - for (Map.Entry table : copy.entrySet()) - visitor.visitTable(table.getKey(), null, "Waiting", table.getValue().getLotroFormat().getName(), table.getValue().getPlayerNames(), null); + for (Map.Entry tableInformation : copy.entrySet()) { + final AwaitingTable table = tableInformation.getValue(); + + visitor.visitTable(tableInformation.getKey(), null, "Waiting", table.getLotroFormat().getName(), getTournamentName(table), table.getPlayerNames(), null); + } Map runningCopy = new LinkedHashMap(_runningTables); for (Map.Entry runningGame : runningCopy.entrySet()) { LotroGameMediator lotroGameMediator = _lotroServer.getGameById(runningGame.getValue()); if (lotroGameMediator != null) - visitor.visitTable(runningGame.getKey(), runningGame.getValue(), lotroGameMediator.getGameStatus(), _runningTableFormatNames.get(runningGame.getKey()), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getWinner()); + visitor.visitTable(runningGame.getKey(), runningGame.getValue(), lotroGameMediator.getGameStatus(), _runningTableFormatNames.get(runningGame.getKey()), _runningTableTournamentNames.get(runningGame.getKey()), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getWinner()); } String playerTable = getNonFinishedPlayerTable(player.getName()); @@ -267,6 +280,7 @@ public class HallServer extends AbstractServer { if (_lotroServer.getGameById(runningTable.getValue()) == null) { _runningTables.remove(runningTable.getKey()); _runningTableFormatNames.remove(runningTable.getKey()); + _runningTableTournamentNames.remove(runningTable.getKey()); } } diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/HallResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/HallResource.java index 9ce6edba5..a6e588cba 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/HallResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/HallResource.java @@ -136,13 +136,14 @@ public class HallResource extends AbstractResource { } @Override - public void visitTable(String tableId, String gameId, String tableStatus, String formatName, Set playerIds, String winner) { + public void visitTable(String tableId, String gameId, String tableStatus, String formatName, String tournamentName, Set playerIds, String winner) { Element table = _doc.createElement("table"); table.setAttribute("id", tableId); if (gameId != null) table.setAttribute("gameId", gameId); table.setAttribute("status", tableStatus); table.setAttribute("format", formatName); + table.setAttribute("tournament", tournamentName); table.setAttribute("players", mergeStrings(playerIds)); if (winner != null) table.setAttribute("winner", winner); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js index a2d1c8a5a..75a4ff1f1 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/hallUi.js @@ -153,13 +153,13 @@ var GempLotrHallUI = Class.extend({ var status = table.getAttribute("status"); var playersAttr = table.getAttribute("players"); var formatName = table.getAttribute("format"); + var tournamentName = table.getAttribute("tournament"); var players = new Array(); if (playersAttr.length > 0) players = playersAttr.split(","); var winner = table.getAttribute("winner"); - var tableDiv = this.createTableDiv(id, gameId, status, formatName, players, waiting, winner); - this.tablesDiv.append(tableDiv); + var tableDiv = this.appendTable(this.tablesDiv, id, gameId, status, formatName, tournamentName, players, waiting, winner); } var games = root.getElementsByTagName("game"); @@ -202,7 +202,7 @@ var GempLotrHallUI = Class.extend({ } }, - createTableDiv: function(id, gameId, status, formatName, players, waiting, winner) { + appendTable: function(container, id, gameId, status, formatName, tournamentName, players, waiting, winner) { var tableDiv = $("
"); tableDiv.css({ display: "inline-table", width: "120px", height: "120px", margin: "5px", "background-color": "#333300", color: "#ffffff"}); tableDiv.append("
" + formatName + "
"); @@ -247,6 +247,6 @@ var GempLotrHallUI = Class.extend({ tableDiv.append(but); } - return tableDiv; + this.container.append(tableDiv); } }); \ No newline at end of file