Page 1 of 1

Move Card LIstener

PostPosted: 08 Sep 2010, 19:23
by nantuko84
however, since you're talking about GUI, you should probably use a PropertyChangeListener, see here starting at line 161. The reason is that the PCL will also be notified undo. In LM, this happens during the normal flow of the game if you can't pay for an action, for example.
Previously I didn't understand why MoveCardListener couldn't be used for move card events, at least it worked for me fine. Until, as you said, I tried undo - e.g. canceling paying manacost - MoveCardListener is not notified when rollback is in action. So I rewrote this part, using your example in ZonePanelImpl (btw, you have redundant code there checking evt.getSource() == getZone() && Zone.CARDS.equals(evt.getPropertyName()) twice).

It works except one aspect: MoveCardEvent(from, to) is splitted into 2 property change events: remove(card1, from:Zone.Library) and add(card1, to:Zone.Hand). Unfortunately I need them at the same time. I mean clients need information about source and target zones, smth like move(card, from:Zone.Library, to:Zone.Hand) that is used for animation. I know it is a little bit difficult because of lists separated, but may be still possible. Please advise.

p.s. other option that comes to my mind is to track event pairs on clients: whenever card is removed from anywhere, it should have mirror event that adds it to another zone.

Re: Move Card LIstener

PostPosted: 08 Sep 2010, 20:21
by silly freak
that's actually easy. when you register a listener on the zone, the notification is from the zone's perspective: you see the card's index, and you even see when a card moves inside a zone.

If you register the listener to the card instead, you get a notification when the card's zone property changes, and there you get the old zone too ;)

Re: Move Card LIstener

PostPosted: 08 Sep 2010, 20:33
by nantuko84
hm, didn't understand

in Card.java:
Code: Select all
      addMoveCardListener(new MoveCard()); // this how it was but doesn't work with undo
      addPropertyChangeListener("???", new CardPropertyChange());
what property name for card's zone should I use?

Re: Move Card LIstener

PostPosted: 08 Sep 2010, 20:43
by silly freak
"zone" ;) I think I used the property name as from the get methods consistently, but you can always look in the constructor where the property is created:

Code: Select all
zone = properties.property(ZONE);
In this case, I even took the time to declare a constant ;)

Re: Move Card LIstener

PostPosted: 08 Sep 2010, 20:45
by nantuko84
just was posting reply:
it was "zone", but how should have I guess that?
but you was first :)

so it works now as I wanted. thanks for help. =)