-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Route Message With Background and Fuel Costs #3189
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3189 +/- ##
============================================
- Coverage 20.94% 18.73% -2.22%
- Complexity 5665 5732 +67
============================================
Files 823 866 +43
Lines 72913 82301 +9388
Branches 11871 13866 +1995
============================================
+ Hits 15274 15420 +146
- Misses 55606 64837 +9231
- Partials 2033 2044 +11
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really looks good, @ron-murhammer.
Probably want a review from @RoiEXLab, too, since he's done a lot of work in MapRouteDrawer
.
@@ -83,7 +87,10 @@ public void testCorrectParameterHandling() { | |||
final Shape mockShape = mock(Shape.class); | |||
final Graphics2D mockGraphics = mock(Graphics2D.class); | |||
when(mockShape.contains(any(Point2D.class))).thenReturn(true); | |||
routeDrawer.drawRoute(mockGraphics, dummyRouteDescription, "2"); | |||
final ResourceCollection mockResourceCollection = mock(ResourceCollection.class); | |||
when(mockResourceCollection.getResourcesCopy()).thenReturn(new IntegerMap<Resource>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I delete the IntegerMap
generic type (i.e. new IntegerMap<>()
), it appears to compile successfully. Are you not seeing the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, no idea why I put the type. Updated.
@@ -89,6 +90,7 @@ | |||
private final TileManager tileManager; | |||
private BufferedImage mouseShadowImage = null; | |||
private String movementLeftForCurrentUnits = ""; | |||
private ResourceCollection movementFuelCost; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is not initialized in the constructor, and only appears to be initialized via setMouseShadowUnits()
. Should it be initialized to an empty ResourceCollection
just in case paint()
gets called before setMouseShadowUnits()
and triggers an NPE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It doesn't seem to ever happen but not sure I can prove it isn't possible. Updated.
final String unitMovementLeft = (maxMovement == null || maxMovement.trim().length() == 0) ? "" : "/" + maxMovement; | ||
final int imageWidth = findMovementLeftImageWidth(curMovement, unitMovementLeft, movementFuelCost); | ||
final BufferedImage image = new BufferedImage(imageWidth, MESSAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB); | ||
final Graphics2D graphics = image.createGraphics(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably be disposing graphics
before returning from this method (reference). Probably best done with a try-finally block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Seems that some of the existing graphics code does use dispose() and other places it doesn't. Something that could probably be improved. Other areas seem to just be calling dispose() at the end of the usage without a try-finally. I think that is probably ok given this is as important as say closing a stream. I'll stick with that pattern for now for consistency and we can always revisit adding dispose() to all graphics areas and whether try-finally would be better.
|
||
// Create temp graphics to calculate necessary image width based on font sizes | ||
final BufferedImage tempImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); | ||
final Graphics2D tempGraphics = tempImage.createGraphics(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on calling Graphics#dispose()
before returning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
graphics.drawRoundRect(0, 0, imageWidth - 2, rectHeight, rectHeight, rectHeight); | ||
|
||
// Draw current movement | ||
graphics.setColor(new Color(255, 120, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that I find this foreground color a bit hard to distinguish between the background color. It looks like it's a medium orange on sand. Not a big deal, just wanted to mention it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted a couple of the colors so that its more of a light gray background and a darker orange.
final ResourceCollection movementFuelCost, final ResourceImageFactory resourceImageFactory) { | ||
|
||
// Create and configure image | ||
final String unitMovementLeft = (maxMovement == null || maxMovement.trim().length() == 0) ? "" : "/" + maxMovement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if " / "
is a better separator than "/"
here. The latter seems a bit too cramped to me, but some may think the former is too spread out. 🤷♂️ Regardless, it's better than the old separator:
" /"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that important, but maxMovement should really be an int with a value of -1 or something for the null replacement if necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that as well but felt without spaces was more coherent and tied the current moves to max moves better.
Yeah, some of the string parameters are a bit interesting but I decided I didn't want to start messing with a bunch of types as they are passed through down to this level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor suggestions.
@@ -568,7 +570,9 @@ public void paint(final Graphics g) { | |||
g2d.drawImage(mouseShadowImage, t, this); | |||
} | |||
if (routeDescription != null) { | |||
routeDrawer.drawRoute(g2d, routeDescription, movementLeftForCurrentUnits); | |||
routeDrawer.drawRoute(g2d, routeDescription, movementLeftForCurrentUnits, movementFuelCost, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if drawRoute would continue to only accept 3 arguments, the third one being a wrapper object to wrap the last 3 objects.
This would keep the related stuff together and the parameter declarations relatively clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a whole there could be some refactoring of parameters across a lot of the MapRouteDrawer and MapPanel. Both in terms of wrapper objects and types used. I decided not to dive into that for this PR. I think looking at even existing objects like RouteDescription which might be expanded to include these. But for now, I think that it would be better in a separate PR.
final ResourceCollection movementFuelCost, final ResourceImageFactory resourceImageFactory) { | ||
|
||
// Create and configure image | ||
final String unitMovementLeft = (maxMovement == null || maxMovement.trim().length() == 0) ? "" : "/" + maxMovement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that important, but maxMovement should really be an int with a value of -1 or something for the null replacement if necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, new colors are a bit easier to read.
Gonna go ahead and merge this so testing can begin. |
Addresses point 3 of https://forums.triplea-game.org/topic/558/fuel-enhancements
Functional Changes
Before
After