It is currently 16 Apr 2024, 11:32
   
Text Size

Move Card LIstener

Moderators: silly freak, CCGHQ Admins

Move Card LIstener

Postby nantuko84 » 08 Sep 2010, 19:23

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.
Mage\MagicWars blog: http://mwars.blogspot.com/
nantuko84
DEVELOPER
 
Posts: 266
Joined: 08 Feb 2009, 21:14
Has thanked: 2 times
Been thanked: 9 times

Re: Move Card LIstener

Postby 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 ;)
___

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

Postby nantuko84 » 08 Sep 2010, 20:33

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?
Mage\MagicWars blog: http://mwars.blogspot.com/
nantuko84
DEVELOPER
 
Posts: 266
Joined: 08 Feb 2009, 21:14
Has thanked: 2 times
Been thanked: 9 times

Re: Move Card LIstener

Postby 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);
In this case, I even took the time to declare a constant ;)
___

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

Postby nantuko84 » 08 Sep 2010, 20:45

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. =)
Mage\MagicWars blog: http://mwars.blogspot.com/
nantuko84
DEVELOPER
 
Posts: 266
Joined: 08 Feb 2009, 21:14
Has thanked: 2 times
Been thanked: 9 times


Return to Development

Who is online

Users browsing this forum: No registered users and 5 guests


Who is online

In total there are 5 users online :: 0 registered, 0 hidden and 5 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 5 guests

Login Form