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.85
37 */
38 public class ObjectRegisterModifier extends RegisterModifier {
39
40 /***
41 * Creates a new instance of IdCardModifiers <br>
42 *
43 * @param name
44 * the object's 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 index
63 * the modified index
64 * @param rightExpression
65 * the expression used to modify the register
66 * @param op
67 * the operation applied to previous value with the value of this
68 * modifier.
69 * @param main
70 * is this object modifier is the main modifier.
71 */
72 ObjectRegisterModifier(String name, MCard to, Ability ability,
73 Test whileCondition, List<MEventListener> linkedEvents,
74 List<MEventListener> until, boolean linked, int layer, int index,
75 Expression rightExpression, Operation op, boolean main) {
76 super(name, to, ability, whileCondition, linkedEvents, until, linked,
77 layer, index, rightExpression, op);
78 objectPicture = ObjectFactory.getObjectPicture(name);
79 this.main = main;
80 }
81
82 @Override
83 public Modifier removeObject(String objectName, Test objectTest) {
84 if (name.equals(objectName) && objectTest.test(ability, to)) {
85 StackManager.postRefreshRegisters(to, index);
86 return next;
87 }
88 return super.removeObject(objectName, objectTest);
89 }
90
91 @Override
92 public int paintObject(Graphics g, int startX, int startY) {
93 if (main) {
94 if (startX + 13 > CardFactory.cardWidth) {
95 return paintObject(g, 3, startY - 16);
96 }
97 g.drawImage(objectPicture, startX, startY, 13, 15, null);
98 return super.paintObject(g, startX + 3, startY);
99 }
100 return super.paintObject(g, startX, startY);
101 }
102
103 @Override
104 public int getNbObjects(String objectName, Test objectTest) {
105 if (main && objectName.equals(name) && objectTest.test(ability, to)) {
106 if (next == null) {
107 return 1;
108 }
109 return 1 + next.getNbObjects(objectName, objectTest);
110 }
111 return super.getNbObjects(objectName, objectTest);
112 }
113
114 /***
115 * Picture representing this object
116 */
117 private Image objectPicture;
118
119 /***
120 * is this object modifier is the main modifier
121 */
122 private boolean main;
123 }