It is currently 09 Sep 2025, 08:06
   
Text Size

Considerations: Targeting Overlay

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Considerations: Targeting Overlay

Postby 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:

Code: Select all
g2d.drawArc(x, y, 2 * w, 2 * h, 0, 90);
since we're dealing with an arc coming from one card (the endpoint of which is identified with p[0].getX() and p[0].getY()) to another (the endpoint of which is p[1].getX() and p[1].getY()), the arc is drawn fine when the X coordinate of the first card is less than that of the second card, since the drawArc method takes X and Y to be the top left coordinates for the arc. If, however, the first card (p[0]) is located to the right of the second card (p[1]), thus the X coordinate of the second card is less than that of the first card, then the arc becomes "inverted" because it's drawn from the wrong starting point (the top left coordinate passed to the drawArc method is actually in the top right, if you get my meaning).

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);
However, in this case the arc is translated incorrectly (the endpoints still don't match) simply because the drawn part of the arc is located to the bottom of where it should actually be. I think that combined with some translation/flipping the above might be made to work (or, if I knew how, if the original ellipse part could have been flipped horizontally with the anchor point located at its center), however, all my attempts at AffineTransform'ing and doing some other magic to the arc shape failed simply because I don't have enough experience yet with the Java2D package. The drawArc method works kinda awkwardly for the task at hand because it draws an arc from the top left corner to the given angle, which is not very suitable (as far as I can see) for cases when you need to draw an arc from the top right to the bottom left. At any rate, the mockup code for the solution as I see it is something like:

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?..
}
Interestingly, it's very easy to make targeting arcs work if we change from arcs to simple lines, because replacing this line:
Code: Select all
g2d.drawArc(x, y, 2 * w, 2 * h, 0, 90);
with this line:
Code: Select all
g2d.drawLine((int) p[0].getX(), (int) p[0].getY(),
             (int) p[1].getX(), (int) p[1].getY());
works perfectly fine and the targeting arcs are always drawn in the right direction from one card to another (simply because there's no issue with having to draw the proper part of the targeting arc flipped somehow in the right direction). However, straight lines look uglier than the curved arcs, though they do work.

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

Postby 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
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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

Postby Agetian » 04 Nov 2012, 16:19

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.
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.

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

Postby jeffwadsworth » 04 Nov 2012, 16:23

Agetian wrote:
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.
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.

- Agetian
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.
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

Postby Agetian » 04 Nov 2012, 16:24

Oh kk no problem, glad it's working for you!

- Agetian
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby Max mtg » 04 Nov 2012, 17:38

I've seen some correcly looking arcs today.
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

Postby 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
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby Agetian » 25 Nov 2012, 11:42

r18387: Fixed an annoying bug in the card mouseover mode, should now be all good (hopefully).

- Agetian
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: Considerations: Targeting Overlay

Postby 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
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 31 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 31 users online :: 0 registered, 0 hidden and 31 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 31 guests

Login Form