From e7b71b2249380200e92786510371f156f0ddb802 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Sun, 4 Sep 2011 17:51:59 +0000 Subject: [PATCH] Continued work on deck builder. --- .../lotro/game/DefaultCardCollection.java | 12 +- .../src/main/webapp/js/deckBuildingUi.js | 157 +++++++++++++++++- 2 files changed, 162 insertions(+), 7 deletions(-) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java index a0a7b1f85..c99915fa0 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/DefaultCardCollection.java @@ -22,6 +22,7 @@ public class DefaultCardCollection implements CardCollection { List cardTypes = getEnumFilter(CardType.values(), CardType.class, "cardType", Arrays.asList(CardType.values()), filterParams); List keywords = getEnumFilter(Keyword.values(), Keyword.class, "keyword", Collections.emptyList(), filterParams); + Integer siteNumber = getSiteNumber(filterParams); Map result = new LinkedHashMap(); for (Map.Entry stringLotroCardBlueprintEntry : _cards.entrySet()) { @@ -29,11 +30,20 @@ public class DefaultCardCollection implements CardCollection { LotroCardBlueprint blueprint = stringLotroCardBlueprintEntry.getValue(); if (cardTypes.contains(blueprint.getCardType())) if (containsAllKeywords(blueprint, keywords)) - result.put(blueprintId, _cardsCount.get(blueprintId)); + if (siteNumber == null || blueprint.getSiteNumber() == siteNumber.intValue()) + result.put(blueprintId, _cardsCount.get(blueprintId)); } return result; } + private Integer getSiteNumber(String[] filterParams) { + for (String filterParam : filterParams) { + if (filterParam.startsWith("siteNumber:")) + return Integer.parseInt(filterParam.substring("siteNumber:".length())); + } + return null; + } + private boolean containsAllKeywords(LotroCardBlueprint blueprint, List keywords) { for (Keyword keyword : keywords) { if (!blueprint.hasKeyword(keyword)) diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js index ec1db67ca..b9f0375e0 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js @@ -1,18 +1,131 @@ var GempLotrDeckBuildingUI = Class.extend({ deckDiv: null, + ringBearerDiv: null, + ringBearerGroup: null, + ringDiv: null, + ringGroup: null, + siteDivs: null, + siteGroups: null, collectionDiv: null, - collectionGroup: null, + normalCollectionDiv: null, + normalCollectionGroup: null, + specialCollectionDiv: null, + specialCollectionGroup: null, loadCollectionFunc: null, + selectionFunc: null, init: function() { + var that = this; + this.deckDiv = $("#deckDiv"); + this.collectionDiv = $("#collectionDiv"); - this.collectionGroup = new NormalCardGroup(null, function(card) { - return (card.zone == "collection"); + this.normalCollectionDiv = $("
"); + this.normalCollectionDiv.css + this.normalCollectionGroup = new NormalCardGroup(null, this.normalCollectionDiv, function(card) { + return true; }); + this.collectionDiv.append(this.normalCollectionDiv); + this.specialCollectionDiv = $("
"); + this.specialCollectionDiv.hide(); + this.specialCollectionGroup = new NormalCardGroup(null, this.specialCollectionDiv, function(card) { + return true; + }); + this.collectionDiv.append(this.specialCollectionDiv); + this.ringBearerDiv = $("
Ring Bearer
"); + this.ringBearerDiv.click( + function() { + $(".card", that.ringBearerDiv).remove(); + that.showPredefinedFilter("keyword:RING_BEARER", that.ringBearerDiv); + }); + this.ringBearerGroup = new NormalCardGroup(null, this.ringBearerDiv, function(card) { + return true; + }); + this.deckDiv.append(this.ringBearerDiv); + + this.ringDiv = $("
Ring
"); + this.ringDiv.click( + function() { + $(".card", that.ringDiv).remove(); + that.showPredefinedFilter("cardType:THE_ONE_RING", that.ringDiv); + }); + this.ringGroup = new NormalCardGroup(null, this.ringDiv, function(card) { + return true; + }); + this.deckDiv.append(this.ringDiv); + + this.siteDivs = new Array(); + this.siteGroups = new Array(); + for (var i = 1; i <= 9; i++) { + var siteDiv = $("
Site " + i + "
"); + siteDiv.click( + (function (siteNumber, container) { + return function() { + $(".card", container).remove(); + that.showPredefinedFilter("cardType:SITE siteNumber:" + siteNumber, container); + }; + })(i, siteDiv)); + this.deckDiv.append(siteDiv); + this.siteGroups.push(new NormalCardGroup(null, siteDiv, function(card) { + return true; + })); + this.siteDivs.push(siteDiv); + } + + this.drawDeckDiv = $("
"); + this.drawDeckGroup = new NormalCardGroup(null, this.drawDeckDiv, function(card) { + return true; + }); + this.deckDiv.append(this.drawDeckDiv); + + this.selectionFunc = this.addCardToDeck; + + $("body").click(function (event) { + var tar = $(event.target); + if (tar.hasClass("borderOverlay")) { + var selectedCardElem = tar.parent(); + if (event.which == 1) { + if (event.shiftKey) { + // that.displayCardInfo(selectedCardElem.data("card")); + } else if (selectedCardElem.hasClass("addableCard")) { + that.selectionFunc(selectedCardElem.data("card").blueprintId); + } else if (selectedCardElem.hasClass("removableCard")) { + selectedCardElem.remove(); + that.layoutUI(); + } + } + } + return false; + }); + }, + + addCardToContainer: function(blueprintId, container) { + var card = new Card(blueprintId, "deck", "deckCardId", "player"); + var cardDiv = createCardDiv(card.imageUrl, null); + cardDiv.data("card", card); + container.append(cardDiv); + this.layoutUI(); + return cardDiv; + }, + + showPredefinedFilter: function(filter, container) { + this.normalCollectionDiv.hide(); + this.specialCollectionDiv.show(); + this.loadCollectionFunc("default", filter, 0, 18); + this.selectionFunc = function(blueprintId) { + this.addCardToContainer(blueprintId, container); + this.specialCollectionDiv.hide(); + this.normalCollectionDiv.show(); + this.selectionFunc = this.addCardToDeck; + }; + }, + + addCardToDeck: function(blueprintId) { + var div = this.addCardToContainer(blueprintId, this.drawDeckDiv) + div.addClass("removableCard"); }, setLoadCollectionFunc: function(func) { @@ -26,6 +139,11 @@ var GempLotrDeckBuildingUI = Class.extend({ displayCollection: function(xml) { var root = xml.documentElement; if (root.tagName == "collection") { + if (this.normalCollectionDiv.is(":visible")) + this.normalCollectionDiv.html(""); + else + this.specialCollectionDiv.html(""); + var cards = root.getElementsByTagName("card"); for (var i = 0; i < cards.length; i++) { var cardElem = cards[i]; @@ -34,16 +152,43 @@ var GempLotrDeckBuildingUI = Class.extend({ var card = new Card(blueprintId, "collection", "collection" + i, "player"); var cardDiv = createCardDiv(card.imageUrl, null); cardDiv.data("card", card); - this.collectionDiv.append(cardDiv); + cardDiv.addClass("addableCard"); + if (this.normalCollectionDiv.is(":visible")) + this.normalCollectionDiv.append(cardDiv); + else + this.specialCollectionDiv.append(cardDiv); } - this.collectionGroup.layoutCards(); + this.normalCollectionGroup.layoutCards(); + this.specialCollectionGroup.layoutCards(); } }, layoutUI: function() { + var deckHeight = this.deckDiv.height(); + var rowHeight = Math.floor(deckHeight / 5); + var sitesWidth = Math.floor(1.5 * deckHeight / 5); - this.collectionGroup.setBounds(0, 0, this.collectionDiv.width(), this.collectionDiv.height()); + this.ringBearerDiv.css({ position: "absolute", left: 0, top: 0, width: Math.floor(sitesWidth / 2), height: rowHeight }); + this.ringBearerGroup.setBounds(0, 0, Math.floor(sitesWidth / 2), rowHeight); + this.ringDiv.css({ position: "absolute", left: Math.floor(sitesWidth / 2), top: 0, width: Math.floor(sitesWidth / 2), height: rowHeight }); + this.ringGroup.setBounds(0, 0, Math.floor(sitesWidth / 2), rowHeight); + for (var i = 0; i < 4; i++) { + this.siteDivs[i].css({ position: "absolute", left: 0, top: rowHeight * (i + 1), width: sitesWidth, height: rowHeight }); + this.siteGroups[i].setBounds(0, 0, sitesWidth, rowHeight); + } + for (var i = 4; i < 9; i++) { + this.siteDivs[i].css({ position: "absolute", left: sitesWidth, top: rowHeight * (i - 4), width: sitesWidth, height: rowHeight }); + this.siteGroups[i].setBounds(0, 0, sitesWidth, rowHeight); + } + this.drawDeckDiv.css({ position: "absolute", left: sitesWidth * 2, top: 0, width: this.deckDiv.width() - sitesWidth * 2, height: deckHeight }); + this.drawDeckGroup.setBounds(0, 0, this.deckDiv.width() - sitesWidth * 2, deckHeight); + + this.normalCollectionDiv.css({ position: "absolute", left: 0, top: 0, width: this.collectionDiv.width(), height: this.collectionDiv.height() }) + this.specialCollectionDiv.css({ position: "absolute", left: 0, top: 0, width: this.collectionDiv.width(), height: this.collectionDiv.height() }) + + this.normalCollectionGroup.setBounds(0, 0, this.collectionDiv.width(), this.collectionDiv.height()); + this.specialCollectionGroup.setBounds(0, 0, this.collectionDiv.width(), this.collectionDiv.height()); }, processError: function (xhr, ajaxOptions, thrownError) {