1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.modifier;
20
21 import java.awt.Graphics;
22 import java.awt.Image;
23 import java.util.List;
24
25 import net.sf.magicproject.clickable.ability.Ability;
26 import net.sf.magicproject.clickable.targetable.card.CardFactory;
27 import net.sf.magicproject.clickable.targetable.card.MCard;
28 import net.sf.magicproject.event.MEventListener;
29 import net.sf.magicproject.expression.Expression;
30 import net.sf.magicproject.operation.Operation;
31 import net.sf.magicproject.stack.StackManager;
32 import net.sf.magicproject.test.Test;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 * @since 0.86
37 */
38 public class ObjectIdCardModifier extends IdCardModifier {
39
40 /***
41 * Creates a new instance of ObjectIdCardModifier <br>
42 *
43 * @param name
44 * the modifier name
45 * @param to
46 * the component to be attached to
47 * @param ability
48 * is the ability owning this test. The card component of this
49 * ability should correspond to the card owning this test too.
50 * @param whileCondition
51 * the test conditionning the activation of this modifier.
52 * @param linkedEvents
53 * the events to be registered. This events would cause this modifier
54 * to be updated.
55 * @param until
56 * this modifier exists while this test is true.
57 * @param linked
58 * is the creator is linked to this modifier.
59 * @param layer
60 * is the strategy used to add this modifier within the existing
61 * chain.
62 * @param propertyId
63 * the propety to add/remove
64 * @param hasNot
65 * Indicates if this modifier remove occurence of the given property.
66 * If False, it adds one instance.
67 * @param main
68 * is this object modifier is the main modifier.
69 */
70 ObjectIdCardModifier(String name, MCard to, Ability ability,
71 Test whileCondition, List<MEventListener> linkedEvents,
72 List<MEventListener> until, boolean linked, int layer, Expression idCard,
73 Operation op, boolean main) {
74 super(name, to, ability, whileCondition, linkedEvents, until, linked,
75 layer, idCard, op);
76 objectPicture = ObjectFactory.getObjectPicture(name);
77 this.main = main;
78 }
79
80 @Override
81 public Modifier removeObject(String objectName, Test objectTest) {
82 if (name.equals(objectName) && objectTest.test(ability, to)) {
83 StackManager.postRefreshIdCard(to);
84 return next;
85 }
86 return super.removeObject(objectName, objectTest);
87 }
88
89 @Override
90 public int paintObject(Graphics g, int startX, int startY) {
91 if (main) {
92 if (startX + 13 > CardFactory.cardWidth) {
93 return paintObject(g, 3, startY - 16);
94 }
95 g.drawImage(objectPicture, startX, startY, 13, 15, null);
96 return super.paintObject(g, startX + 3, startY);
97 }
98 return super.paintObject(g, startX, startY);
99 }
100
101 @Override
102 public int getNbObjects(String objectName, Test objectTest) {
103 if (main && objectName.equals(name) && objectTest.test(ability, to)) {
104 if (next == null) {
105 return 1;
106 }
107 return 1 + next.getNbObjects(objectName, objectTest);
108 }
109 return super.getNbObjects(objectName, objectTest);
110 }
111
112 /***
113 * Picture representing this object
114 */
115 private Image objectPicture;
116
117 /***
118 * is this object modifier is the main modifier
119 */
120 private boolean main;
121 }