Change how the UI lays out the cards when receiving events from server.

This commit is contained in:
marcins78@gmail.com
2011-09-12 13:57:27 +00:00
parent 830d93f0c9
commit 5b02be0860
3 changed files with 103 additions and 132 deletions

View File

@@ -224,6 +224,12 @@ public class GameState {
if (!b)
throw new RuntimeException("Card was not found in the expected zone");
if (zone == Zone.ATTACHED)
((PhysicalCardImpl) card).attachTo(null);
if (zone == Zone.STACKED)
((PhysicalCardImpl) card).stackOn(null);
for (Skirmish assignment : new LinkedList<Skirmish>(_assignments)) {
if (assignment.getFellowshipCharacter() == card)
removeAssignment(assignment);
@@ -245,12 +251,6 @@ public class GameState {
else if (isZonePrivate(zone))
for (GameStateListener listener : getPrivateGameStateListeners(card))
listener.cardRemoved(card);
if (zone == Zone.ATTACHED)
((PhysicalCardImpl) card).attachTo(null);
if (zone == Zone.STACKED)
((PhysicalCardImpl) card).stackOn(null);
}
public void addCardToZone(PhysicalCard card, Zone zone) {

View File

@@ -163,52 +163,52 @@ var GempLotrGameUI = Class.extend({
initializeDialogs: function() {
this.dialogInstance = $("<div></div>")
.dialog({
autoOpen: false,
closeOnEscape: false,
resizable: false,
minHeight: 80
});
autoOpen: false,
closeOnEscape: false,
resizable: false,
minHeight: 80
});
this.assignmentDialog = $("<div></div>")
.dialog({
autoOpen: false,
closeOnEscape: false,
title: "Assignments",
resizable: true,
minHeight: 240,
minWidth: 400,
width: 500,
height: 200,
position: ["right", "bottom"]
});
autoOpen: false,
closeOnEscape: false,
title: "Assignments",
resizable: true,
minHeight: 240,
minWidth: 400,
width: 500,
height: 200,
position: ["right", "bottom"]
});
this.skirmishDialog = $("<div></div>")
.dialog({
autoOpen: false,
closeOnEscape: false,
title: "Skirmish",
resizable: true,
minHeight: 240,
minWidth: 400,
width: 500,
height: 200,
position: ["right", "top"]
});
autoOpen: false,
closeOnEscape: false,
title: "Skirmish",
resizable: true,
minHeight: 240,
minWidth: 400,
width: 500,
height: 200,
position: ["right", "top"]
});
$(".ui-dialog-titlebar-close").hide();
this.infoDialog = $("<div></div>")
.dialog({
autoOpen: false,
closeOnEscape: true,
resizable: false,
title: "Card information",
minHeight: 80,
minWidth: 200,
width: 600,
height: 300,
maxHeight: 300
});
autoOpen: false,
closeOnEscape: true,
resizable: false,
title: "Card information",
minHeight: 80,
minWidth: 200,
width: 600,
height: 300,
maxHeight: 300
});
},
@@ -299,6 +299,8 @@ var GempLotrGameUI = Class.extend({
this.removeTokens(gameEvent);
}
}
if (gameEvents.length > 0)
this.layoutZones();
var decisions = element.getElementsByTagName("decision");
if (decisions.length == 1) {
@@ -340,9 +342,6 @@ var GempLotrGameUI = Class.extend({
if (cardData.tokens[token] == null)
cardData.tokens[token] = 0;
cardData.tokens[token] += count;
this.layoutZone(zone);
this.assignmentsChanged();
},
removeTokens: function(element) {
@@ -357,9 +356,6 @@ var GempLotrGameUI = Class.extend({
if (cardData.tokens[token] == null)
cardData.tokens[token] = 0;
cardData.tokens[token] -= count;
this.layoutZone(zone);
this.assignmentsChanged();
},
startSkirmish: function(element) {
@@ -381,7 +377,6 @@ var GempLotrGameUI = Class.extend({
});
this.skirmishDialogResized();
this.assignmentsChanged();
},
endSkirmish: function() {
@@ -398,8 +393,6 @@ var GempLotrGameUI = Class.extend({
});
this.skirmishDialog.html("");
this.assignmentsChanged();
},
removeAssignment: function(element) {
@@ -421,8 +414,6 @@ var GempLotrGameUI = Class.extend({
if ($(".card:cardId(" + opposingCardIds[i] + ")").data("card").assign != cardId)
this.assignMinion(opposingCardIds[i], cardId);
}
this.assignmentsChanged();
},
putCardInPlay: function(element) {
@@ -439,34 +430,32 @@ var GempLotrGameUI = Class.extend({
var cardDiv = this.createCardDiv(card);
$("#main").append(cardDiv);
var affectedZone = zone;
if (targetCardId != null) {
var targetCardData = $(".card:cardId(" + targetCardId + ")").data("card");
targetCardData.attachedCards.push(cardDiv);
affectedZone = targetCardData.zone;
}
this.layoutZone(affectedZone);
}
},
layoutZone: function(zone) {
if (zone == "ADVENTURE_PATH") {
this.advPathGroup.layoutCards();
} else if (zone == "FREE_CHARACTERS") {
this.charactersPlayer.layoutCards();
this.charactersOpponent.layoutCards();
} else if (zone == "FREE_SUPPORT") {
this.supportPlayer.layoutCards();
this.supportOpponent.layoutCards();
} else if (zone == "HAND") {
this.hand.layoutCards();
} else if (zone == "SHADOW_CHARACTERS") {
this.shadow.layoutCards();
} else if (zone == "SHADOW_SUPPORT") {
this.shadowPlayer.layoutCards();
this.shadowOpponent.layoutCards();
layoutZones: function() {
this.advPathGroup.layoutCards();
this.charactersPlayer.layoutCards();
this.charactersOpponent.layoutCards();
this.supportPlayer.layoutCards();
this.supportOpponent.layoutCards();
this.hand.layoutCards();
this.shadow.layoutCards();
this.shadowPlayer.layoutCards();
this.shadowOpponent.layoutCards();
this.skirmishFellowshipGroup.layoutCards();
this.skirmishShadowGroup.layoutCards();
for (var characterId in this.shadowAssignGroups) {
if (this.shadowAssignGroups.hasOwnProperty(characterId)) {
this.shadowAssignGroups[characterId].layoutCards();
this.freePeopleAssignGroups[characterId].layoutCards();
}
}
},
@@ -483,26 +472,26 @@ var GempLotrGameUI = Class.extend({
removeCardFromPlay: function(element) {
var cardId = element.getAttribute("cardId");
var zone = element.getAttribute("zone");
var targetCardId = element.getAttribute("targetCardId");
var card = $(".card:cardId(" + cardId + ")")
var card = $(".card:cardId(" + cardId + ")");
if (targetCardId != null) {
var targetCardData = $(".card:cardId(" + targetCardId + ")").data("card");
var index = -1;
for (var i = 0; i < targetCardData.attachedCards.length; i++) {
if (targetCardData.attachedCards[i].data("card").cardId == cardId) {
index = i;
break;
}
}
if (index != -1)
targetCardData.attachedCards.splice(index, 1);
if (zone == "ATTACHED" || zone == "STACKED") {
$(".card").each(
function() {
var cardData = $(this).data("card");
var index = -1;
for (var i = 0; i < cardData.attachedCards.length; i++)
if (cardData.attachedCards[i].data("card").cardId == cardId) {
index = i;
break;
}
if (index != -1)
cardData.attachedCards.splice(index, 1);
}
);
}
card.remove();
this.layoutZone(zone);
},
gamePhaseChange: function(element) {
@@ -564,13 +553,13 @@ var GempLotrGameUI = Class.extend({
this.dialogInstance
.html(text + "<br /><input id='integerDecision' type='text' value='0'>")
.dialog("option", "buttons",
{
"OK": function() {
$(this).dialog("close");
that.decisionFunction(id, $("#integerDecision").val());
}
}
)
{
"OK": function() {
$(this).dialog("close");
that.decisionFunction(id, $("#integerDecision").val());
}
}
)
.dialog("option", "width", "400")
.dialog("option", "height", "auto");
;
@@ -604,13 +593,13 @@ var GempLotrGameUI = Class.extend({
this.dialogInstance
.html(html)
.dialog("option", "buttons",
{
"OK": function() {
$(this).dialog("close");
that.decisionFunction(id, $("#multipleChoiceDecision").val());
}
}
)
{
"OK": function() {
$(this).dialog("close");
that.decisionFunction(id, $("#multipleChoiceDecision").val());
}
}
)
.dialog("option", "width", "400")
.dialog("option", "height", "auto");
@@ -943,13 +932,13 @@ var GempLotrGameUI = Class.extend({
if (this.shadowAssignGroups[characterId] == null) {
this.shadowAssignGroups[characterId] = new NormalCardGroup(this.assignmentDialog, function (card) {
return (card.zone == "SHADOW_CHARACTERS" && card.assign == characterId);
}
);
return (card.zone == "SHADOW_CHARACTERS" && card.assign == characterId);
}
);
this.freePeopleAssignGroups[characterId] = new NormalCardGroup(this.assignmentDialog, function (card) {
return (card.cardId == characterId);
}
);
return (card.cardId == characterId);
}
);
this.moveCardToElement(characterId, this.assignmentDialog);
this.assignDialogResized();
@@ -971,7 +960,7 @@ var GempLotrGameUI = Class.extend({
} else {
that.unassignMinion(cardId);
}
that.assignmentsChanged();
that.layoutZones();
that.doAssignments(freeCharacters, minions);
};
@@ -1023,24 +1012,6 @@ var GempLotrGameUI = Class.extend({
this.skirmishFellowshipGroup.setBounds(0, cellHeight, width, cellHeight);
},
assignmentsChanged: function() {
this.charactersPlayer.layoutCards();
this.supportPlayer.layoutCards();
this.charactersOpponent.layoutCards();
this.supportOpponent.layoutCards();
this.shadow.layoutCards();
this.skirmishFellowshipGroup.layoutCards();
this.skirmishShadowGroup.layoutCards();
for (var characterId in this.shadowAssignGroups) {
if (this.shadowAssignGroups.hasOwnProperty(characterId)) {
this.shadowAssignGroups[characterId].layoutCards();
this.freePeopleAssignGroups[characterId].layoutCards();
}
}
},
clearSelection: function() {
$(".selectableCard").removeClass("selectableCard").data("action", null);
$(".selectedCard").removeClass("selectedCard");

View File

@@ -1,9 +1,4 @@
TO DO:
3. Refactor Effect to return EffectResult upon playEffect, which will contain information about what actually
happened. Modify the Blueprints to have the "before" methods to take Effect parameter only and the "after" to
take the EffectResult parameter only. Effects which modify cards should take filters as parameters, use
overloaded constructor for single cards for backward compatibility, this constructor will call another constructor
with Filters.sameCard(...) filter.
4. Modify the Blueprint hierarchy to return possible return objects (PlayEventAction), TriggeredAction, etc. Use
final methods were possible to avoid implementation errors on new cards added.
5. Introduce move card operation in communication between the server and client to change the zone/params of the card.
@@ -21,3 +16,8 @@ and go with different selection.
DONE:
1. Introduce AbstractPermanent into Blueprint hierarchy.
2. Migrate Race (Orc, Elf, etc) into separate enum from Keyword.
3. Refactor Effect to return EffectResult upon playEffect, which will contain information about what actually
happened. Modify the Blueprints to have the "before" methods to take Effect parameter only and the "after" to
take the EffectResult parameter only. Effects which modify cards should take filters as parameters, use
overloaded constructor for single cards for backward compatibility, this constructor will call another constructor
with Filters.sameCard(...) filter.