Move Card LIstener
Moderators: silly freak, CCGHQ Admins
Move Card LIstener
by nantuko84 » 08 Sep 2010, 19:23
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).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.
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.
Mage\MagicWars blog: http://mwars.blogspot.com/
Re: Move Card LIstener
by silly freak » 08 Sep 2010, 20:21
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
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
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Move Card LIstener
by nantuko84 » 08 Sep 2010, 20:33
hm, didn't understand
in Card.java:
in Card.java:
- Code: Select all
addMoveCardListener(new MoveCard()); // this how it was but doesn't work with undo
addPropertyChangeListener("???", new CardPropertyChange());
Mage\MagicWars blog: http://mwars.blogspot.com/
Re: Move Card LIstener
by silly freak » 08 Sep 2010, 20:43
"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);
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Move Card LIstener
by nantuko84 » 08 Sep 2010, 20:45
just was posting reply:
so it works now as I wanted. thanks for help. =)
but you was firstit was "zone", but how should have I guess that?
so it works now as I wanted. thanks for help. =)
Mage\MagicWars blog: http://mwars.blogspot.com/
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest