Card delivery revamp (each collection in separate popup window).
This commit is contained in:
@@ -15,7 +15,7 @@ public class DeliveryService {
|
||||
|
||||
private ReadWriteLock _deliveryLock = new ReentrantReadWriteLock(false);
|
||||
|
||||
public void addPackage(Player player, String collectionType, CardCollection itemCollection) {
|
||||
public void addPackage(Player player, String packageName, CardCollection itemCollection) {
|
||||
_deliveryLock.writeLock().lock();
|
||||
try {
|
||||
Map<String, MutableCardCollection> playerDeliverables = _undeliveredDeliverables.get(player.getName());
|
||||
@@ -23,10 +23,10 @@ public class DeliveryService {
|
||||
playerDeliverables = new HashMap<String, MutableCardCollection>();
|
||||
_undeliveredDeliverables.put(player.getName(), playerDeliverables);
|
||||
}
|
||||
MutableCardCollection deliverablesInCollection = playerDeliverables.get(collectionType);
|
||||
MutableCardCollection deliverablesInCollection = playerDeliverables.get(packageName);
|
||||
if (deliverablesInCollection == null) {
|
||||
deliverablesInCollection = new DefaultCardCollection();
|
||||
playerDeliverables.put(collectionType, deliverablesInCollection);
|
||||
playerDeliverables.put(packageName, deliverablesInCollection);
|
||||
}
|
||||
for (Map.Entry<String, Integer> itemToAdd : itemCollection.getAll().entrySet()) {
|
||||
String blueprintId = itemToAdd.getKey();
|
||||
|
||||
@@ -136,7 +136,7 @@ public class AdminResource extends AbstractResource {
|
||||
collection.addItem(productItem.getKey(), productItem.getValue());
|
||||
Player player = _playerDao.getPlayer(playerId);
|
||||
_collectionDao.setCollectionForPlayer(player, leagueType, collection);
|
||||
_deliveryService.addPackage(player, leagueType, items);
|
||||
_deliveryService.addPackage(player, league.getName(), items);
|
||||
}
|
||||
|
||||
return "OK";
|
||||
@@ -151,6 +151,8 @@ public class AdminResource extends AbstractResource {
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
validateAdmin(request);
|
||||
|
||||
String packageName = getPackageNameByCollectionType(collectionType);
|
||||
|
||||
DefaultCardCollection items = new DefaultCardCollection();
|
||||
|
||||
Map<String, Integer> productItems = getProductItems(product);
|
||||
@@ -166,12 +168,25 @@ public class AdminResource extends AbstractResource {
|
||||
for (Map.Entry<String, Integer> productItem : productItems.entrySet())
|
||||
collection.addItem(productItem.getKey(), productItem.getValue());
|
||||
_collectionDao.setCollectionForPlayer(player, collectionType, collection);
|
||||
_deliveryService.addPackage(player, collectionType, items);
|
||||
_deliveryService.addPackage(player, packageName, items);
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
private String getPackageNameByCollectionType(String collectionType) {
|
||||
String packageName;
|
||||
if (collectionType.equals("permanent"))
|
||||
packageName = "My cards";
|
||||
else {
|
||||
League league = getLeagueByType(collectionType);
|
||||
if (league == null)
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
packageName = league.getName();
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
private MutableCardCollection getPlayerCollection(Player player, String collectionType) {
|
||||
MutableCardCollection collection = _collectionDao.getCollectionForPlayer(player, collectionType);
|
||||
if (collection == null && collectionType.equals("permanent"))
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.game.*;
|
||||
import com.gempukku.lotro.league.LeagueService;
|
||||
@@ -32,6 +33,8 @@ public class CollectionResource extends AbstractResource {
|
||||
@Context
|
||||
private CollectionDAO _collectionDao;
|
||||
@Context
|
||||
private LeagueDAO _leagueDao;
|
||||
@Context
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
@Context
|
||||
private LeagueService _leagueService;
|
||||
@@ -152,7 +155,7 @@ public class CollectionResource extends AbstractResource {
|
||||
MutableCardCollection modifiableColleciton = (MutableCardCollection) collection;
|
||||
|
||||
CardCollection packContents = modifiableColleciton.openPack(packId, _packStorage);
|
||||
_deliveryService.addPackage(resourceOwner, collectionType, packContents);
|
||||
_deliveryService.addPackage(resourceOwner, getPackageNameByCollectionType(collectionType), packContents);
|
||||
|
||||
if (packContents == null)
|
||||
sendError(Response.Status.NOT_FOUND);
|
||||
@@ -189,4 +192,24 @@ public class CollectionResource extends AbstractResource {
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
private String getPackageNameByCollectionType(String collectionType) {
|
||||
String packageName;
|
||||
if (collectionType.equals("permanent"))
|
||||
packageName = "My cards";
|
||||
else {
|
||||
League league = getLeagueByType(collectionType);
|
||||
if (league == null)
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
packageName = league.getName();
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
private League getLeagueByType(String leagueType) {
|
||||
for (League league : _leagueDao.getActiveLeagues())
|
||||
if (league.getType().equals(leagueType))
|
||||
return league;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,19 @@
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.cardCount {
|
||||
width: 20px;
|
||||
height: 18px;
|
||||
background-color: #000000;
|
||||
color: #ffffff;
|
||||
font-size: 120%;
|
||||
font-weight: bolder;
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.tableFormatName {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var deliveryDialog = null;
|
||||
var deliveryGroup = null;
|
||||
var deliveryDialogs = {};
|
||||
var deliveryGroups = {};
|
||||
|
||||
function deliveryService(xml) {
|
||||
log("Delivered a package:");
|
||||
@@ -7,38 +7,40 @@ function deliveryService(xml) {
|
||||
|
||||
var root = xml.documentElement;
|
||||
if (root.tagName == "delivery") {
|
||||
|
||||
var deliveryDialogResize = function() {
|
||||
var width = deliveryDialog.width() + 10;
|
||||
var height = deliveryDialog.height() + 10;
|
||||
deliveryGroup.setBounds(2, 2, width - 2 * 2, height - 2 * 2);
|
||||
};
|
||||
|
||||
if (deliveryDialog == null) {
|
||||
deliveryDialog = $("<div></div>").dialog({
|
||||
title: "You've received the following items",
|
||||
autoOpen: false,
|
||||
closeOnEscape: false,
|
||||
resizable: true,
|
||||
width: 400,
|
||||
height: 200
|
||||
});
|
||||
|
||||
deliveryGroup = new NormalCardGroup(deliveryDialog, function(card) {
|
||||
return true;
|
||||
}, false);
|
||||
|
||||
deliveryDialog.bind("dialogresize", deliveryDialogResize);
|
||||
deliveryDialog.bind("dialogclose",
|
||||
function() {
|
||||
deliveryDialog.html("");
|
||||
});
|
||||
}
|
||||
|
||||
var collections = root.getElementsByTagName("collectionType");
|
||||
for (var i = 0; i < collections.length; i++) {
|
||||
var collection = collections[i];
|
||||
|
||||
var collectionName = collection.getAttribute("name");
|
||||
var deliveryDialogResize = (function(name) {
|
||||
return function() {
|
||||
var width = deliveryDialogs[name].width() + 10;
|
||||
var height = deliveryDialogs[name].height() + 10;
|
||||
deliveryGroups[name].setBounds(2, 2, width - 2 * 2, height - 2 * 2);
|
||||
};
|
||||
})(collectionName);
|
||||
|
||||
if (deliveryDialogs[collectionName] == null) {
|
||||
deliveryDialogs[collectionName] = $("<div></div>").dialog({
|
||||
title: "New items - " + collectionName,
|
||||
autoOpen: false,
|
||||
closeOnEscape: false,
|
||||
resizable: true,
|
||||
width: 400,
|
||||
height: 200
|
||||
});
|
||||
|
||||
deliveryGroups[collectionName] = new NormalCardGroup(deliveryDialogs[collectionName], function(card) {
|
||||
return true;
|
||||
}, false);
|
||||
|
||||
deliveryDialogs[collectionName].bind("dialogresize", deliveryDialogResize);
|
||||
deliveryDialogs[collectionName].bind("dialogclose",
|
||||
function() {
|
||||
deliveryDialogs[collectionName].html("");
|
||||
});
|
||||
}
|
||||
|
||||
var packs = collection.getElementsByTagName("pack");
|
||||
for (var j = 0; j < packs.length; j++) {
|
||||
var packElem = packs[j];
|
||||
@@ -48,7 +50,7 @@ function deliveryService(xml) {
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), true);
|
||||
cardDiv.data("card", card);
|
||||
deliveryDialog.append(cardDiv);
|
||||
deliveryDialogs[collectionName].append(cardDiv);
|
||||
}
|
||||
|
||||
var cards = collection.getElementsByTagName("card");
|
||||
@@ -60,11 +62,11 @@ function deliveryService(xml) {
|
||||
card.tokens = {"count":count};
|
||||
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil());
|
||||
cardDiv.data("card", card);
|
||||
deliveryDialog.append(cardDiv);
|
||||
deliveryDialogs[collectionName].append(cardDiv);
|
||||
}
|
||||
}
|
||||
|
||||
deliveryDialog.dialog("open");
|
||||
deliveryDialogResize();
|
||||
deliveryDialogs[collectionName].dialog("open");
|
||||
deliveryDialogResize();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user