Considerations: Targeting Overlay
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
14 posts
• Page 1 of 1
Considerations: Targeting Overlay
by Agetian » 03 Nov 2012, 19:22
I'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
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 04 Nov 2012, 11:52
OK, I managed to fix bug #1 (moved away from drawArc and used a different approach to drawing curves between cards, seems to work like a charm so far, will test some more).
Once the testing is done, I'm on to bug #2.
- Agetian
Once the testing is done, I'm on to bug #2.
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 04 Nov 2012, 12:04
Bug #2 is currently fixed by disabling the "mouse-over only" mode (it's implemented incorrectly and I have a very vague idea as to how to implement it correctly at the moment). As of right now, the targeting overlay seems functional and does not crash. I'll keep testing it and will commit it to the SVN when I'm done.
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 04 Nov 2012, 12:58
OK, the experimental corrections are currently submitted to the SVN. Most tests went fine, no crashes, no arcs pointing in the wrong direction; however, once the targeting arc (as well as the ellipses) did not show once I attached Sicken to an opponent's creature; no idea why, could not reproduce via a test case (showed fine the next few times). Hopefully at least the overlay will now be in functional enough state to be maintained further. I'll see what I can do with it in the future too.
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by jeffwadsworth » 04 Nov 2012, 16:16
Thanks for working on this feature, long time coming. Perhaps I am doing something wrong: to enable the targeting overlay, I press "T", but nothing happens. Using 17843.
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Considerations: Targeting Overlay
by Agetian » 04 Nov 2012, 16:19
No problem, I also believe this feature is important to preserve and develop! Hmm, I haven't checked whether the shortcut worked or not, the button in the dock definitely works. I'll take a look at the shortcut soon.jeffwadsworth wrote:Thanks for working on this feature, long time coming. Perhaps I am doing something wrong: to enable the targeting overlay, I press "T", but nothing happens. Using 17843.
EDIT: Hmm I tested the shortcut (T) and it seems to work fine for me... I'm not sure why it won't work for you, to be honest. Can anyone else please take a look whether it works for you or not? (it works fine for me both ways - with the button and with the press of a key)
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by jeffwadsworth » 04 Nov 2012, 16:23
My fault. I assumed that an attacking creature would show an arrow to the opponent's avatar. I do in fact see an arrow from a defender to the attacker just fine. Sorry about that. Mage was on my mind.Agetian wrote:No problem, I also believe this feature is important to preserve and develop! Hmm, I haven't checked whether the shortcut worked or not, the button in the dock definitely works. I'll take a look at the shortcut soon.jeffwadsworth wrote:Thanks for working on this feature, long time coming. Perhaps I am doing something wrong: to enable the targeting overlay, I press "T", but nothing happens. Using 17843.
- Agetian
- jeffwadsworth
- Super Tester Elite
- Posts: 1172
- Joined: 20 Oct 2010, 04:47
- Location: USA
- Has thanked: 287 times
- Been thanked: 70 times
Re: Considerations: Targeting Overlay
by Agetian » 04 Nov 2012, 16:24
Oh kk no problem, glad it's working for you!
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Max mtg » 04 Nov 2012, 17:38
I've seen some correcly looking arcs today.
With they were more beautifut though
With they were more beautifut though

Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Considerations: Targeting Overlay
by Agetian » 05 Nov 2012, 05:08
Yeah, that's true - but oh well, maybe when I finally get to read about Java2D in detail, I'll update them to be prettier 
- Agetian

- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 25 Nov 2012, 10:34
OK, with r18382 I'm bringing you the much improved visuals for targeting arrows, with an adaptation of the arrow drawing code from MAGE, as fully permitted by the team working on MAGE. Now I'm working on trying to fix the "mouseover-only" mode, and as soon as it's done, I believe the targeting overlay will finally be in a fully usable and good-looking state.
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 25 Nov 2012, 11:37
r18384: Card mouseover mode is now fixed and enabled, the targeting overlay now switches between three modes - off, on (mouseover only mode), and on (all arrows shown at all times).
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 25 Nov 2012, 11:42
r18387: Fixed an annoying bug in the card mouseover mode, should now be all good (hopefully).
- Agetian
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
Re: Considerations: Targeting Overlay
by Agetian » 27 Nov 2012, 05:46
r18414: In card mouseover mode, the targeting arrows will be shown for the creature blocked with multiple blockers when the order of blockers needs to be declared - first, all arrows are shown for all the blockers; then, individual arrows are shown when the blocker is selected in the list.
With this commit, the initial developer target for targeting overlay is considered complete. Hopefully it's useful enough now, I'll temporarily go back to the card support code developer target.
- Agetian
With this commit, the initial developer target for targeting overlay is considered complete. Hopefully it's useful enough now, I'll temporarily go back to the card support code developer target.
- Agetian
- Agetian
- Programmer
- Posts: 3489
- Joined: 14 Mar 2011, 05:58
- Has thanked: 684 times
- Been thanked: 572 times
14 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 31 guests