yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
454 stars 46 forks source link

[Proposal] add SquidMessageBox internal border method to SquidPanel and subclasses #188

Closed Rakaneth closed 6 years ago

Rakaneth commented 6 years ago

I happen to really like the border effect of SquidMessageBox, and I've written a utility method that does the same thing for SquidPanels.

Is this something we want to add to SquidPanel, or even things like SparseLayers?

image

The bottom left panel is an actual SquidMessageBox; the bottom right is a SquidPanel bordered with my utility method.

tommyettinger commented 6 years ago

That looks really good, and the border definitely helps visually separate your different UI areas. I think having a border would be good for a lot of things, but the question then is if it should write over the existing contents of a SquidPanel, or if it should expand its size in some way. If a border was added to the map area in your screenshot, then it would write the line over the light brown wall on the far left. For SquidLayers and SparseLayers, the border could just be drawn in a top-level layer or one close to being on top, where the border is allowed to sit on top of other chars if some happen to be under it. There's no standard API for SquidLayers and SparseLayers, but maybe there should be (probably closer to SparseLayers' smaller and cleaner subset). If you want to submit your code as a pull request on GitHub, I'll accept it since the screenshot really shows that it improves the appearance there. If you don't want to deal with making a fork to submit a pull request, feel free to attach any relevant code files to this issue; this seems like it should be pretty quick to integrate into the library if it's all or mostly one method.

Rakaneth commented 6 years ago

Currently, the bordering method of SquidMessageBox (which is what I based my code on) is a private method in that class. Could it be as simple as pulling that method up to SquidPanel and making it public, so that it can be called at whim, and leave the automatic bordering in SquidMessageBox?

tommyettinger commented 6 years ago

Sure, good idea. I'll try it now.

tommyettinger commented 6 years ago

This is implemented now; thanks again for the tip on the code I had forgotten about. The version in SquidPanel allows a color to be specified for the border, and currently places chars directly into that SquidPanel instead of allocating a 2D char array, but no longer affects the cells in the interior of the panel. In SquidMessageBox, these are filled instead by ArrayTools.fill(char[][], char, int, int, int, int), which fills an area of a 2D char array with the given char. This fill method could easily and quickly be written by a user, but having it just helps a little for convenience. I'll close this, and reopen it if there are any issues you encounter with this.

Rakaneth commented 6 years ago

One thing that I forgot mention is that, shortly after I wrote my utility method, I improved it to take a string caption that would be written at (1, 0).

image

I'll update to the latest version and perhaps try my hand at forking to include the caption.