diff --git a/WebContent/cah.css b/WebContent/cah.css index 138f0f8..99830aa 100644 --- a/WebContent/cah.css +++ b/WebContent/cah.css @@ -151,12 +151,13 @@ #chat { border: 1px solid black; - left: -4px; - right: 46px; + left: -2px; + /*right: 46px;*/ + bottom: -1px; height: 17px; position: absolute; - bottom: -1px; padding: 0px; + width: 90%; } #chat_submit { @@ -182,10 +183,6 @@ span.debug { height: 200px; border: 1px solid gray; padding: 15px; - /* - position: absolute; - bottom: 0px; - */ font-family: Arial, Verdana, san-serif; font-size: 18pt; float: left; @@ -208,9 +205,9 @@ span.debug { color: black; } -.cah { +.game_hand_cards .cah { position: absolute; - bottom: 0px; + bottom: -150px; left: 0px; margin: 15px; } @@ -237,7 +234,7 @@ span.debug { bottom: 0px; left: 0px; right: 0px; - height: 33%; + height: 30%; border-top: 1px solid black; } @@ -246,11 +243,6 @@ span.debug { bottom: 0px; height: 100%; width: 100%; - /* * / - zoom: .35; - -moz-transform: scale(.35); - -moz-transform-origin: 0 0; - / * */ cursor: pointer; } @@ -262,11 +254,6 @@ span.debug { .card_holder { float: left; position: relative; - /* - zoom: .35; - -moz-transform: scale(.35); - -moz-transform-origin: 0 0; - */ } .scoreboard { diff --git a/WebContent/js/cah.ajax.handlers.js b/WebContent/js/cah.ajax.handlers.js index 4500d28..1ad86a8 100644 --- a/WebContent/js/cah.ajax.handlers.js +++ b/WebContent/js/cah.ajax.handlers.js @@ -99,10 +99,20 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data) { game.dispose(); delete cah.currentGames[data[cah.$.AjaxResponse.GAME_ID]]; } - // This will get updated when the server fires a refresh event + cah.GameList.instance.update(); cah.GameList.instance.show(); }; cah.ajax.SuccessHandlers[cah.$.AjaxOperation.START_GAME] = function(data) { // pass }; + +cah.ajax.SuccessHandlers[cah.$.AjaxOperation.GET_HAND] = function(data) { + var gameId = data[cah.$.AjaxResponse.GAME_ID]; + var game = cah.currentGames[gameId]; + if (game) { + game.dealtCards(data[cah.$.AjaxResponse.HAND]); + } else { + cah.log.error("Received hand for unknown game id " + gameId); + } +}; diff --git a/WebContent/js/cah.constants.js b/WebContent/js/cah.constants.js index 9e49458..250469a 100644 --- a/WebContent/js/cah.constants.js +++ b/WebContent/js/cah.constants.js @@ -11,6 +11,7 @@ cah.$.AjaxOperation.FIRST_LOAD = "firstload"; cah.$.AjaxOperation.LOG_OUT = "logout"; cah.$.AjaxOperation.GAME_LIST = "games"; cah.$.AjaxOperation.JOIN_GAME = "join_game"; +cah.$.AjaxOperation.GET_HAND = "get_hand"; cah.$.AjaxOperation.GET_GAME_INFO = "get_game_info"; cah.$.AjaxOperation.REGISTER = "register"; cah.$.AjaxOperation.CREATE_GAME = "create_game"; @@ -32,17 +33,18 @@ cah.$.AjaxResponse = function() { // pass }; cah.$.AjaxResponse.prototype.dummy = undefined; -cah.$.AjaxResponse.NEXT = "next"; cah.$.AjaxResponse.GAME_ID = "game_id"; -cah.$.AjaxResponse.GAME_INFO = "game_info"; -cah.$.AjaxResponse.ERROR = "error"; +cah.$.AjaxResponse.HAND = "hand"; cah.$.AjaxResponse.PLAYER_INFO = "player_info"; -cah.$.AjaxResponse.ERROR_CODE = "error_code"; -cah.$.AjaxResponse.SERIAL = "serial"; -cah.$.AjaxResponse.MAX_GAMES = "max_games"; cah.$.AjaxResponse.IN_PROGRESS = "in_progress"; cah.$.AjaxResponse.GAMES = "games"; cah.$.AjaxResponse.NICKNAME = "nickname"; +cah.$.AjaxResponse.NEXT = "next"; +cah.$.AjaxResponse.GAME_INFO = "game_info"; +cah.$.AjaxResponse.ERROR = "error"; +cah.$.AjaxResponse.ERROR_CODE = "error_code"; +cah.$.AjaxResponse.SERIAL = "serial"; +cah.$.AjaxResponse.MAX_GAMES = "max_games"; cah.$.AjaxResponse.NAMES = "names"; cah.$.DisconnectReason = function() { diff --git a/WebContent/js/cah.game.js b/WebContent/js/cah.game.js index e083869..2d70ff1 100644 --- a/WebContent/js/cah.game.js +++ b/WebContent/js/cah.game.js @@ -77,6 +77,7 @@ cah.Game = function(id) { */ cah.Game.joinGame = function(gameId) { cah.Ajax.build(cah.$.AjaxOperation.GET_GAME_INFO).withGameId(gameId).run(); + cah.Ajax.build(cah.$.AjaxOperation.GET_HAND).withGameId(gameId).run(); cah.GameList.instance.hide(); var game = new cah.Game(gameId); cah.currentGames[gameId] = game; @@ -118,48 +119,34 @@ cah.Game.prototype.dealtCard = function(card) { var element = card.getElement(); jQuery(".game_hand_cards", this.element_).append(element); - $(element).css("zoom", ".35"); - var data = { - card : element, - }; + // animate it so we don't have to hard-code per browser + $(element).animate({ + scale : .35, + }, { + duration : 1, + }); + + $(element).css("transform", "scale(0.35, 0.35)").css("transform-origin", "0 0"); + + // TODO scale on available width and number of cards + var origSize = parseInt($(element).css("width")); + $(element).css("width", origSize * .35).css("height", origSize * .35); + var options = { duration : 200, queue : false, }; - - if ($.browser.mozilla || $.browser.opera) { - var origSize = parseInt($(element).css("width")); - if ($.browser.mozilla) { - $(element).css("-moz-transform", "scale(0.35, 0.35)").css("-moz-transform-origin", "0 0"); - } else { - $(element).css("-o-transform", "scale(0.35, 0.35)").css("-o-transform-origin", "0 0"); - } - $(element).css("width", origSize * .35).css("height", origSize * .35).css("z-index", - this.badBrowserZOrderHack_--); - $(".cah", element).css("bottom", "-150px"); - - $(element).mouseenter(data, function(e) { - $(e.data.card).animate({ - scale : .7, - }, options); - }).mouseleave(data, function(e) { - $(e.data.card).animate({ - scale : .35, - }, options); - }); - - } else { - - $(element).mouseenter(data, function(e) { - $(e.data.card).animate({ - zoom : .7 - }, options); - }).mouseleave(data, function(e) { - $(e.data.card).animate({ - zoom : .35 - }, options); - }); - } + $(element).mouseenter(function(e) { + $(this).animate({ + scale : .6, + "z-index" : 2, + }, options); + }).mouseleave(function(e) { + $(this).animate({ + scale : .35, + "z-index" : 1, + }, options); + }); }; cah.Game.prototype.insertIntoDocument = function() { diff --git a/src/net/socialgamer/cah/Constants.java b/src/net/socialgamer/cah/Constants.java index c597bca..9ec83f3 100644 --- a/src/net/socialgamer/cah/Constants.java +++ b/src/net/socialgamer/cah/Constants.java @@ -57,6 +57,7 @@ public class Constants { FIRST_LOAD("firstload"), GAME_LIST("games"), GET_GAME_INFO("get_game_info"), + GET_HAND("get_hand"), JOIN_GAME("join_game"), LEAVE_GAME("leave_game"), LOG_OUT("logout"), @@ -101,6 +102,7 @@ public class Constants { GAME_ID("game_id"), GAME_INFO("game_info"), GAMES("games"), + HAND("hand"), IN_PROGRESS("in_progress"), MAX_GAMES("max_games"), NAMES("names"), diff --git a/src/net/socialgamer/cah/data/Game.java b/src/net/socialgamer/cah/data/Game.java index 99bc7bc..ec895e6 100644 --- a/src/net/socialgamer/cah/data/Game.java +++ b/src/net/socialgamer/cah/data/Game.java @@ -232,15 +232,22 @@ public class Game { hand.add(card); newCards.add(card); } - sendDealtCardsToPlayer(player, newCards); + sendCardsToPlayer(player, newCards); } } } - private void sendDealtCardsToPlayer(final Player player, final List cards) { + private void sendCardsToPlayer(final Player player, final List cards) { final Map data = new HashMap(); data.put(LongPollResponse.EVENT, LongPollEvent.HAND_DEAL.toString()); data.put(LongPollResponse.GAME_ID, id); + final List> cardData = handSubsetToClient(cards); + data.put(LongPollResponse.HAND, cardData); + final QueuedMessage qm = new QueuedMessage(MessageType.GAME_EVENT, data); + player.getUser().enqueueMessage(qm); + } + + private List> handSubsetToClient(final List cards) { final List> cardData = new ArrayList>(cards.size()); for (final WhiteCard card : cards) { @@ -249,9 +256,18 @@ public class Game { thisCard.put(WhiteCardData.TEXT, card.getText()); cardData.add(thisCard); } - data.put(LongPollResponse.HAND, cardData); - final QueuedMessage qm = new QueuedMessage(MessageType.GAME_EVENT, data); - player.getUser().enqueueMessage(qm); + return cardData; + } + + public List> getHand(final User user) { + synchronized (players) { + for (final Player player : players) { + if (player.getUser() == user) { + return handSubsetToClient(player.getHand()); + } + } + } + return null; } private List playersToUsers() { diff --git a/src/net/socialgamer/cah/handlers/GetHandHandler.java b/src/net/socialgamer/cah/handlers/GetHandHandler.java new file mode 100644 index 0000000..1b8b5d8 --- /dev/null +++ b/src/net/socialgamer/cah/handlers/GetHandHandler.java @@ -0,0 +1,47 @@ +package net.socialgamer.cah.handlers; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import net.socialgamer.cah.Constants.AjaxOperation; +import net.socialgamer.cah.Constants.AjaxResponse; +import net.socialgamer.cah.Constants.ReturnableData; +import net.socialgamer.cah.Constants.WhiteCardData; +import net.socialgamer.cah.RequestWrapper; +import net.socialgamer.cah.data.Game; +import net.socialgamer.cah.data.GameManager; +import net.socialgamer.cah.data.User; + +import com.google.inject.Inject; + + +public class GetHandHandler extends GameHandler { + + @Inject + public GetHandHandler(final GameManager gameManager) { + super(gameManager); + } + + public static final String OP = AjaxOperation.GET_HAND.toString(); + + @SuppressWarnings("unchecked") + @Override + public Map handle(final RequestWrapper request, + final HttpSession session, final User user, final Game game) { + final Map data = new HashMap(); + + final List> hand = user.getGame().getHand(user); + if (hand != null) { + data.put(AjaxResponse.HAND, hand); + } else { + data.put(AjaxResponse.HAND, Arrays.asList(new HashMap())); + } + + data.put(AjaxResponse.GAME_ID, game.getId()); + return data; + } +} diff --git a/src/net/socialgamer/cah/handlers/Handlers.java b/src/net/socialgamer/cah/handlers/Handlers.java index 16dea62..eed6693 100644 --- a/src/net/socialgamer/cah/handlers/Handlers.java +++ b/src/net/socialgamer/cah/handlers/Handlers.java @@ -15,6 +15,7 @@ public class Handlers { LIST.put(FirstLoadHandler.OP, FirstLoadHandler.class); LIST.put(GameListHandler.OP, GameListHandler.class); LIST.put(GetGameInfoHandler.OP, GetGameInfoHandler.class); + LIST.put(GetHandHandler.OP, GetHandHandler.class); LIST.put(JoinGameHandler.OP, JoinGameHandler.class); LIST.put(LeaveGameHandler.OP, LeaveGameHandler.class); LIST.put(LogoutHandler.OP, LogoutHandler.class);