diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java index 1d76f0c7d..d56bec629 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallChannelVisitor.java @@ -14,6 +14,10 @@ public interface HallChannelVisitor { public void updateTournamentQueue(String queueId, Map props); public void removeTournamentQueue(String queueId); + public void addTournament(String tournamentId, Map props); + public void updateTournament(String tournamentId, Map props); + public void removeTournament(String tournamentId); + public void addTable(String tableId, Map props); public void updateTable(String tableId, Map props); public void removeTable(String tableId); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java index 499769e3d..e6c0040b6 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallCommunicationChannel.java @@ -14,6 +14,7 @@ public class HallCommunicationChannel { private long _lastConsumed; private String _lastMotd; private Map> _tournamentQueuePropsOnClient = new LinkedHashMap>(); + private Map> _tournamentPropsOnClient = new LinkedHashMap>(); private Map> _tablePropsOnClient = new LinkedHashMap>(); public HallCommunicationChannel(int channelNumber) { @@ -32,8 +33,9 @@ public class HallCommunicationChannel { hallChannelVisitor.channelNumber(_channelNumber); final MutableObject newMotd = new MutableObject(); - final Map> tournamentsOnServer = new LinkedHashMap>(); + final Map> tournamentQueuesOnServer = new LinkedHashMap>(); final Map> tablesOnServer = new LinkedHashMap>(); + final Map> tournamentsOnServer = new LinkedHashMap>(); hallServer.processHall(player, new HallInfoVisitor() { @@ -82,7 +84,23 @@ public class HallCommunicationChannel { props.put("start", startCondition); props.put("signedUp", String.valueOf(playerSignedUp)); - tournamentsOnServer.put(tournamentQueueKey, props); + tournamentQueuesOnServer.put(tournamentQueueKey, props); + } + + @Override + public void visitTournament(String tournamentKey, String collectionName, String formatName, String tournamentName, String pairingDescription, + String tournamentStage, int round, int playerCount, boolean playerInCompetition) { + Map props = new HashMap(); + props.put("collection", collectionName); + props.put("format", formatName); + props.put("name", tournamentName); + props.put("system", pairingDescription); + props.put("stage", tournamentStage); + props.put("round", String.valueOf(round)); + props.put("playerCount", String.valueOf(playerCount)); + props.put("signedUp", String.valueOf(playerInCompetition)); + + tournamentsOnServer.put(tournamentKey, props); } @Override @@ -91,24 +109,22 @@ public class HallCommunicationChannel { } }); - for (Map.Entry> tournamentQueueOnClient : _tournamentQueuePropsOnClient.entrySet()) { - String tournamentQueueId = tournamentQueueOnClient.getKey(); - Map tournamentProps = tournamentQueueOnClient.getValue(); - Map tournamentLatestProps = tournamentsOnServer.get(tournamentQueueId); - if (tournamentLatestProps != null) { - if (!tournamentProps.equals(tournamentLatestProps)) - hallChannelVisitor.updateTournamentQueue(tournamentQueueId, tournamentLatestProps); - } else { - hallChannelVisitor.removeTournamentQueue(tournamentQueueId); - } - } + notifyAboutTournamentQueues(hallChannelVisitor, tournamentQueuesOnServer); + _tournamentQueuePropsOnClient = tournamentQueuesOnServer; - for (Map.Entry> tournamentQueueOnServer : tournamentsOnServer.entrySet()) - if (!_tournamentQueuePropsOnClient.containsKey(tournamentQueueOnServer.getKey())) - hallChannelVisitor.addTournamentQueue(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue()); + notifyAboutTournaments(hallChannelVisitor, tournamentsOnServer); + _tournamentPropsOnClient = tournamentsOnServer; - _tournamentQueuePropsOnClient = tournamentsOnServer; + notifyAboutTables(hallChannelVisitor, tablesOnServer); + _tablePropsOnClient = tablesOnServer; + if (newMotd.getValue() != null && !newMotd.equals(_lastMotd)) + hallChannelVisitor.motdChanged((String) newMotd.getValue()); + + _lastConsumed = System.currentTimeMillis(); + } + + private void notifyAboutTables(HallChannelVisitor hallChannelVisitor, Map> tablesOnServer) { for (Map.Entry> tableOnClient : _tablePropsOnClient.entrySet()) { String tableId = tableOnClient.getKey(); Map tableProps = tableOnClient.getValue(); @@ -124,12 +140,41 @@ public class HallCommunicationChannel { for (Map.Entry> tableOnServer : tablesOnServer.entrySet()) if (!_tablePropsOnClient.containsKey(tableOnServer.getKey())) hallChannelVisitor.addTable(tableOnServer.getKey(), tableOnServer.getValue()); + } - if (newMotd.getValue() != null && !newMotd.equals(_lastMotd)) - hallChannelVisitor.motdChanged((String) newMotd.getValue()); + private void notifyAboutTournamentQueues(HallChannelVisitor hallChannelVisitor, Map> tournamentQueuesOnServer) { + for (Map.Entry> tournamentQueueOnClient : _tournamentQueuePropsOnClient.entrySet()) { + String tournamentQueueId = tournamentQueueOnClient.getKey(); + Map tournamentProps = tournamentQueueOnClient.getValue(); + Map tournamentLatestProps = tournamentQueuesOnServer.get(tournamentQueueId); + if (tournamentLatestProps != null) { + if (!tournamentProps.equals(tournamentLatestProps)) + hallChannelVisitor.updateTournamentQueue(tournamentQueueId, tournamentLatestProps); + } else { + hallChannelVisitor.removeTournamentQueue(tournamentQueueId); + } + } - _tablePropsOnClient = tablesOnServer; + for (Map.Entry> tournamentQueueOnServer : tournamentQueuesOnServer.entrySet()) + if (!_tournamentQueuePropsOnClient.containsKey(tournamentQueueOnServer.getKey())) + hallChannelVisitor.addTournamentQueue(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue()); + } - _lastConsumed = System.currentTimeMillis(); + private void notifyAboutTournaments(HallChannelVisitor hallChannelVisitor, Map> tournamentsOnServer) { + for (Map.Entry> tournamentOnClient : _tournamentPropsOnClient.entrySet()) { + String tournamentId = tournamentOnClient.getKey(); + Map tournamentProps = tournamentOnClient.getValue(); + Map tournamentLatestProps = tournamentsOnServer.get(tournamentId); + if (tournamentLatestProps != null) { + if (!tournamentProps.equals(tournamentLatestProps)) + hallChannelVisitor.updateTournament(tournamentId, tournamentLatestProps); + } else { + hallChannelVisitor.removeTournament(tournamentId); + } + } + + for (Map.Entry> tournamentQueueOnServer : tournamentsOnServer.entrySet()) + if (!_tournamentPropsOnClient.containsKey(tournamentQueueOnServer.getKey())) + hallChannelVisitor.addTournament(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue()); } } 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 368de1246..378c1739c 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 @@ -18,5 +18,7 @@ public interface HallInfoVisitor { public void visitTournamentQueue(String tournamentQueueKey, int cost, String collectionName, String formatName, String tournamentQueueName, String tournamentPrizes, String pairingDescription, String startCondition, int playerCount, boolean playerSignedUp); + public void visitTournament(String tournamentKey, String collectionName, String formatName, String tournamentName, String pairingDescription, String tournamentStage, int round, int playerCount, boolean playerInCompetition); + 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 5e864b0f2..71a2844fd 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 @@ -346,6 +346,15 @@ public class HallServer extends AbstractServer { tournamentQueue.getPlayerCount(), tournamentQueue.isPlayerSignedUp(player.getName())); } + for (Map.Entry tournamentEntry: _runningTournaments.entrySet()){ + String tournamentKey = tournamentEntry.getKey(); + Tournament tournament = tournamentEntry.getValue(); + visitor.visitTournament(tournamentKey, tournament.getCollectionType().getFullName(), + _formatLibrary.getFormat(tournament.getFormat()).getName(), tournament.getTournamentName(), tournament.getPlayOffSystem(), + tournament.getTournamentStage().getHumanReadable(), + tournament.getCurrentRound(), tournament.getPlayersInCompetitionCount(), tournament.isPlayerInCompetition(player.getName())); + } + String gameId = getPlayingPlayerGameId(player.getName()); if (gameId != null) visitor.runningPlayerGame(gameId); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/DefaultTournament.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/DefaultTournament.java index 043ea7154..dc3c7f531 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/DefaultTournament.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/DefaultTournament.java @@ -98,6 +98,16 @@ public class DefaultTournament implements Tournament { _waitForPairingsTime = waitForPairingsTime; } + @Override + public String getPlayOffSystem() { + return _pairingMechanism.getPlayOffSystem(); + } + + @Override + public int getPlayersInCompetitionCount() { + return _players.size() - _droppedPlayers.size(); + } + @Override public String getTournamentId() { return _tournamentId; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/PairingMechanism.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/PairingMechanism.java index 8bb6e50a2..0dd985dee 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/PairingMechanism.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/PairingMechanism.java @@ -12,4 +12,6 @@ public interface PairingMechanism { public boolean isFinished(int round, Set players, Set droppedPlayers); public boolean pairPlayers(int round, Set players, Set droppedPlayers, Map playerByes, List currentStandings, Map pairingResults, Set byeResults); + + public String getPlayOffSystem(); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/SingleEliminationPairing.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/SingleEliminationPairing.java index 5f3b1189e..8a53fd594 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/SingleEliminationPairing.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/SingleEliminationPairing.java @@ -10,6 +10,11 @@ public class SingleEliminationPairing implements PairingMechanism { return players.size() - droppedPlayers.size() < 2; } + @Override + public String getPlayOffSystem() { + return "Single elimination"; + } + @Override public boolean pairPlayers(int round, Set players, Set droppedPlayers, Map playerByes, List currentStandings, Map pairingResults, Set byeResults) { if (isFinished(round, players, droppedPlayers)) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/Tournament.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/Tournament.java index 8336ea8e0..f4203ee23 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/Tournament.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/tournament/Tournament.java @@ -28,9 +28,11 @@ public interface Tournament { public String getFormat(); public CollectionType getCollectionType(); public String getTournamentName(); + public String getPlayOffSystem(); public Stage getTournamentStage(); public int getCurrentRound(); + public int getPlayersInCompetitionCount(); public void advanceTournament(TournamentCallback tournamentCallback, CollectionsManager collectionsManager); diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java index c6bc8eee9..10b323232 100644 --- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java +++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/HallResource.java @@ -324,6 +324,34 @@ public class HallResource extends AbstractResource { _hall.appendChild(queue); } + @Override + public void addTournament(String tournamentId, Map props) { + Element tournament = _doc.createElement("tournament"); + tournament.setAttribute("action", "add"); + tournament.setAttribute("id", tournamentId); + for (Map.Entry attribute : props.entrySet()) + tournament.setAttribute(attribute.getKey(), attribute.getValue()); + _hall.appendChild(tournament); + } + + @Override + public void updateTournament(String tournamentId, Map props) { + Element tournament = _doc.createElement("tournament"); + tournament.setAttribute("action", "update"); + tournament.setAttribute("id", tournamentId); + for (Map.Entry attribute : props.entrySet()) + tournament.setAttribute(attribute.getKey(), attribute.getValue()); + _hall.appendChild(tournament); + } + + @Override + public void removeTournament(String tournamentId) { + Element tournament = _doc.createElement("tournament"); + tournament.setAttribute("action", "remove"); + tournament.setAttribute("id", tournamentId); + _hall.appendChild(tournament); + } + @Override public void addTable(String tableId, Map props) { Element table = _doc.createElement("table"); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js index 285334980..14107443e 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-014/hallUi.js @@ -41,6 +41,7 @@ var GempLotrHallUI = Class.extend({ this.tablesDiv.css({overflow:"auto", left:"0px", top:"0px", width:width + "px", height:(height - 30) + "px"}); this.addQueuesTable(); + this.addTournamentsTable(); this.addWaitingTablesTable(); this.addPlayingTablesTable(); this.addFinishedTablesTable(); @@ -135,6 +136,38 @@ var GempLotrHallUI = Class.extend({ this.tablesDiv.append(content); }, + addTournamentsTable: function() { + var header = $("
"); + + var content = $("
"); + + var toggleContent = $("
Toggle tournaments
").button({ + icons: { + primary: "ui-icon-circlesmall-minus" + }, + text: false + }); + toggleContent.css({width: "13px", height: "15px"}); + toggleContent.click( + function() { + if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus") + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"}); + else + toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"}); + content.toggle("blind", {}, 200); + }); + header.append(toggleContent); + header.append(" Tournaments"); + header.append(" (0)"); + + var table = $("
"); + table.append("FormatCollectionTournament nameSystemStageRoundPlayersActions"); + content.append(table); + + this.tablesDiv.append(header); + this.tablesDiv.append(content); + }, + addWaitingTablesTable: function() { var header = $("
"); @@ -372,6 +405,51 @@ var GempLotrHallUI = Class.extend({ } } + var tournaments = root.getElementsByTagName("tournament"); + for (var i = 0; i < tournaments.length; i++) { + var tournament = tournaments[i]; + var id = tournament.getAttribute("id"); + var action = tournament.getAttribute("action"); + if (action == "add" || action == "update") { + var actionsField = $(""); + + var joined = tournament.getAttribute("signedUp"); + if (joined == "true") { + var but = $(""); + $(but).button().click(( + function(tournamentId) { + return function () { + that.comm.dropFromTournament(tournamentId, function (xml) { + that.processResponse(xml); + }); + }; + } + )(id)); + actionsField.append(but); + } + + var row = $("" + tournament.getAttribute("format") + "" + + "" + tournament.getAttribute("collection") + "" + + "" + tournament.getAttribute("name") + "" + + "" + tournament.getAttribute("system") + "" + + "" + tournament.getAttribute("stage") + "" + + "" + tournament.getAttribute("round") + "" + + "" + tournament.getAttribute("playerCount") + "" + + ""); + + row.append(actionsField); + + if (action == "add") { + $("table.tournaments", this.tablesDiv) + .append(row); + } else if (action == "update") { + $(".tournament" + id, this.tablesDiv).replaceWith(row); + } + } else if (action == "remove") { + $(".tournament" + id, this.tablesDiv).remove(); + } + } + var tables = root.getElementsByTagName("table"); for (var i = 0; i < tables.length; i++) { var table = tables[i]; @@ -482,6 +560,7 @@ var GempLotrHallUI = Class.extend({ } $(".count", $(".eventHeader.queues")).html("("+($("tr", $("table.queues")).length-1)+")"); + $(".count", $(".eventHeader.tournaments")).html("("+($("tr", $("table.tournaments")).length-1)+")"); $(".count", $(".eventHeader.waitingTables")).html("("+($("tr", $("table.waitingTables")).length-1)+")"); $(".count", $(".eventHeader.playingTables")).html("("+($("tr", $("table.playingTables")).length-1)+")"); $(".count", $(".eventHeader.finishedTables")).html("("+($("tr", $("table.finishedTables")).length-1)+")");