Fork me on GitHub
#cljfx
<
2023-12-11
>
Jonathan Bennett12:12:47

Bit of a conceptual question: I need to draw a hexagonal map that's going to be the main place where clicks and interactions are going to end up happening. I think maybe a canvas is correct but it looks like it'll be a whole lot of Java interop in order to do that. Is that actually the best way to go?

Jonathan Bennett12:12:16

It just feels like it would put a massive chunk of code and complexity in a single place. But I don't know about about GUI programming in general or cljfx in particular to know if there is another alternative.

Jonathan Bennett13:12:15

Ok, I'm just reading through the help-ui from cljfx/dev and I think this may also work, but I'm curious if someone with some more experience can still chime in: The whole map area is a scroll-pane . Inside that, I draw polygon hexagons and then on top of those I draw image-viewsprites. My questions are: 1. Is the Clojure that I end up writing from that going to be any easier to break down into smaller components (I'm hoping a hex-draw function, a draw-sprite function, and a draw-terrain function, maybe? 2. Are the events for that going to be simpler because I'll be able to tell which hex is clicked without needing to do math to check (I feel like that must be a yes, but I'm just sanity checking)? 3. Is there a big downside to this route that I'm not aware of?

Nundrum15:12:40

I recently wrote some Clojure2D that involved a ton of hexagons. All the math you need to do to handle placement and clicks isn't terribly difficult, and you only need it get it right once 😉 This is the main resource you would need: https://www.redblobgames.com/grids/hexagons/ I suspect that using Polygons would make your life simpler. It looks like the Polygon class inherits all of the interaction methods you would expect. You could also apply shapes to other UI elements, as described here: https://genuinecoder.com/javafx-buttons-with-custom-shape/ You'll be able to break down the code into smaller units either way. But if you use UI elements you can lean on the UI framework more and it might feel more natural.

👍 1
Jonathan Bennett22:12:17

Excellent, that confirms what I was thinking. I've already written up the code from redblobgames, first in Common Lisp and now in Clojure. Thanks for the confirmation.