Continued work on deck builder.
This commit is contained in:
@@ -22,6 +22,7 @@ public class DefaultCardCollection implements CardCollection {
|
|||||||
|
|
||||||
List<CardType> cardTypes = getEnumFilter(CardType.values(), CardType.class, "cardType", Arrays.asList(CardType.values()), filterParams);
|
List<CardType> cardTypes = getEnumFilter(CardType.values(), CardType.class, "cardType", Arrays.asList(CardType.values()), filterParams);
|
||||||
List<Keyword> keywords = getEnumFilter(Keyword.values(), Keyword.class, "keyword", Collections.<Keyword>emptyList(), filterParams);
|
List<Keyword> keywords = getEnumFilter(Keyword.values(), Keyword.class, "keyword", Collections.<Keyword>emptyList(), filterParams);
|
||||||
|
Integer siteNumber = getSiteNumber(filterParams);
|
||||||
|
|
||||||
Map<String, Integer> result = new LinkedHashMap<String, Integer>();
|
Map<String, Integer> result = new LinkedHashMap<String, Integer>();
|
||||||
for (Map.Entry<String, LotroCardBlueprint> stringLotroCardBlueprintEntry : _cards.entrySet()) {
|
for (Map.Entry<String, LotroCardBlueprint> stringLotroCardBlueprintEntry : _cards.entrySet()) {
|
||||||
@@ -29,11 +30,20 @@ public class DefaultCardCollection implements CardCollection {
|
|||||||
LotroCardBlueprint blueprint = stringLotroCardBlueprintEntry.getValue();
|
LotroCardBlueprint blueprint = stringLotroCardBlueprintEntry.getValue();
|
||||||
if (cardTypes.contains(blueprint.getCardType()))
|
if (cardTypes.contains(blueprint.getCardType()))
|
||||||
if (containsAllKeywords(blueprint, keywords))
|
if (containsAllKeywords(blueprint, keywords))
|
||||||
|
if (siteNumber == null || blueprint.getSiteNumber() == siteNumber.intValue())
|
||||||
result.put(blueprintId, _cardsCount.get(blueprintId));
|
result.put(blueprintId, _cardsCount.get(blueprintId));
|
||||||
}
|
}
|
||||||
return result;
|
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<Keyword> keywords) {
|
private boolean containsAllKeywords(LotroCardBlueprint blueprint, List<Keyword> keywords) {
|
||||||
for (Keyword keyword : keywords) {
|
for (Keyword keyword : keywords) {
|
||||||
if (!blueprint.hasKeyword(keyword))
|
if (!blueprint.hasKeyword(keyword))
|
||||||
|
|||||||
@@ -1,18 +1,131 @@
|
|||||||
var GempLotrDeckBuildingUI = Class.extend({
|
var GempLotrDeckBuildingUI = Class.extend({
|
||||||
deckDiv: null,
|
deckDiv: null,
|
||||||
|
ringBearerDiv: null,
|
||||||
|
ringBearerGroup: null,
|
||||||
|
ringDiv: null,
|
||||||
|
ringGroup: null,
|
||||||
|
siteDivs: null,
|
||||||
|
siteGroups: null,
|
||||||
collectionDiv: null,
|
collectionDiv: null,
|
||||||
collectionGroup: null,
|
normalCollectionDiv: null,
|
||||||
|
normalCollectionGroup: null,
|
||||||
|
specialCollectionDiv: null,
|
||||||
|
specialCollectionGroup: null,
|
||||||
loadCollectionFunc: null,
|
loadCollectionFunc: null,
|
||||||
|
selectionFunc: null,
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var that = this;
|
||||||
|
|
||||||
this.deckDiv = $("#deckDiv");
|
this.deckDiv = $("#deckDiv");
|
||||||
|
|
||||||
this.collectionDiv = $("#collectionDiv");
|
this.collectionDiv = $("#collectionDiv");
|
||||||
|
|
||||||
this.collectionGroup = new NormalCardGroup(null, function(card) {
|
this.normalCollectionDiv = $("<div></div>");
|
||||||
return (card.zone == "collection");
|
this.normalCollectionDiv.css
|
||||||
|
this.normalCollectionGroup = new NormalCardGroup(null, this.normalCollectionDiv, function(card) {
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
this.collectionDiv.append(this.normalCollectionDiv);
|
||||||
|
|
||||||
|
this.specialCollectionDiv = $("<div></div>");
|
||||||
|
this.specialCollectionDiv.hide();
|
||||||
|
this.specialCollectionGroup = new NormalCardGroup(null, this.specialCollectionDiv, function(card) {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
this.collectionDiv.append(this.specialCollectionDiv);
|
||||||
|
|
||||||
|
this.ringBearerDiv = $("<div>Ring Bearer</div>");
|
||||||
|
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 = $("<div>Ring</div>");
|
||||||
|
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 = $("<div>Site " + i + "</div>");
|
||||||
|
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 = $("<div></div>");
|
||||||
|
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) {
|
setLoadCollectionFunc: function(func) {
|
||||||
@@ -26,6 +139,11 @@ var GempLotrDeckBuildingUI = Class.extend({
|
|||||||
displayCollection: function(xml) {
|
displayCollection: function(xml) {
|
||||||
var root = xml.documentElement;
|
var root = xml.documentElement;
|
||||||
if (root.tagName == "collection") {
|
if (root.tagName == "collection") {
|
||||||
|
if (this.normalCollectionDiv.is(":visible"))
|
||||||
|
this.normalCollectionDiv.html("");
|
||||||
|
else
|
||||||
|
this.specialCollectionDiv.html("");
|
||||||
|
|
||||||
var cards = root.getElementsByTagName("card");
|
var cards = root.getElementsByTagName("card");
|
||||||
for (var i = 0; i < cards.length; i++) {
|
for (var i = 0; i < cards.length; i++) {
|
||||||
var cardElem = cards[i];
|
var cardElem = cards[i];
|
||||||
@@ -34,16 +152,43 @@ var GempLotrDeckBuildingUI = Class.extend({
|
|||||||
var card = new Card(blueprintId, "collection", "collection" + i, "player");
|
var card = new Card(blueprintId, "collection", "collection" + i, "player");
|
||||||
var cardDiv = createCardDiv(card.imageUrl, null);
|
var cardDiv = createCardDiv(card.imageUrl, null);
|
||||||
cardDiv.data("card", card);
|
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() {
|
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) {
|
processError: function (xhr, ajaxOptions, thrownError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user