Considerations: Targeting Overlay
 Posted: 03 Nov 2012, 19:22
Posted: 03 Nov 2012, 19:22I'm currently looking through the targeting overlay code and I'm thinking about fixing it up to make it usable. I was able to find out the cause for an infamous bug that plagued the targeting overlay in the past but my limited experience with java2d does not allow me to find the proper solution to the bug. So far, there are two issues that I see with the targeting overlay after I re-enable it:
1) Sometimes, targeting arcs are drawn the wrong way (I'll get to this in a second).
2) The game crashes when the targeting arcs are in the "mouse over only" mode (will talk a bit about it in the end).
The culprit in the first bug is the following line in TargetingOverlay.java:
The following code actually allows to draw the arc in the right direction when p[0].getX() > p[1].getX(), because it draws a different part of the ellipse which is directed the right way:
As for the second issue (with the game crashing when the targeting arcs are switched to the "mouse over only" mode), the crash happens because only the card panel of the card over which the mouse is positioned is included in the list of endpoints, while we need also the list of the cards that it's enchanted by or that it enchants (if it's an enchantment) or that it blocks (if it's a combat scenario). Unfortunately, this might be difficult to implement, because as far as I can tell, there's no (easy?) way to go from e.g. getCard().getEnchantedBy() to the CardPanel that represents that card.
Personally I think that if we either:
1) Use straight lines instead of arcs (a bit ugly) OR find the proper way to align the arcs when p[0].getX() > p[1].getX() (don't know how),
2) Either solve the crash or at least temporarily disable the "mouse over only" mode (I wish I knew how),
we could make the targeting arcs functional at a basic level, which would at least work without serious problems and which could be expanded later as new solutions are developed and as e.g. I gain experience with Java.
If you have any advice or considerations about the above, please let me know, as for now, I'll keep struggling with the code and read a bit more about Java2D and see if I can make it work the right way.
- Agetian
			1) Sometimes, targeting arcs are drawn the wrong way (I'll get to this in a second).
2) The game crashes when the targeting arcs are in the "mouse over only" mode (will talk a bit about it in the end).
The culprit in the first bug is the following line in TargetingOverlay.java:
- Code: Select all
- g2d.drawArc(x, y, 2 * w, 2 * h, 0, 90);
The following code actually allows to draw the arc in the right direction when p[0].getX() > p[1].getX(), because it draws a different part of the ellipse which is directed the right way:
- Code: Select all
- g2d.drawArc(x, y, 2 * w, 2 * h, 270, 90);
- Code: Select all
- if (p[1].getX() > p[0].getX()) {
 g2d.drawArc(x, y, 2 * w, 2 * h, 0, 90)
 } else {
 // ???? maybe: g2d.drawArc(x, y, 2 * w, 2 * h, 270, 90);
 // and then some transformation applied to put it in the proper place
 // or just some magic with AffineTransform to flip the original arc?..
 }
- Code: Select all
- g2d.drawArc(x, y, 2 * w, 2 * h, 0, 90);
- Code: Select all
- g2d.drawLine((int) p[0].getX(), (int) p[0].getY(),
 (int) p[1].getX(), (int) p[1].getY());
As for the second issue (with the game crashing when the targeting arcs are switched to the "mouse over only" mode), the crash happens because only the card panel of the card over which the mouse is positioned is included in the list of endpoints, while we need also the list of the cards that it's enchanted by or that it enchants (if it's an enchantment) or that it blocks (if it's a combat scenario). Unfortunately, this might be difficult to implement, because as far as I can tell, there's no (easy?) way to go from e.g. getCard().getEnchantedBy() to the CardPanel that represents that card.
Personally I think that if we either:
1) Use straight lines instead of arcs (a bit ugly) OR find the proper way to align the arcs when p[0].getX() > p[1].getX() (don't know how),
2) Either solve the crash or at least temporarily disable the "mouse over only" mode (I wish I knew how),
we could make the targeting arcs functional at a basic level, which would at least work without serious problems and which could be expanded later as new solutions are developed and as e.g. I gain experience with Java.
If you have any advice or considerations about the above, please let me know, as for now, I'll keep struggling with the code and read a bit more about Java2D and see if I can make it work the right way.
- Agetian

