44import org .broken .arrow .library .itemcreator .meta .map .cursor .MapCursorAdapter ;
55import org .broken .arrow .library .itemcreator .meta .map .cursor .MapCursorWrapper ;
66import org .broken .arrow .library .itemcreator .meta .map .font .CharacterSprite ;
7+ import org .broken .arrow .library .itemcreator .meta .map .font .MapFontWrapper ;
78import org .broken .arrow .library .itemcreator .meta .map .pixel .ImageOverlay ;
89import org .broken .arrow .library .itemcreator .meta .map .pixel .MapPixel ;
910import org .broken .arrow .library .itemcreator .meta .map .pixel .MapColoredPixel ;
2324import java .util .List ;
2425import java .util .Map ;
2526import java .util .Objects ;
27+ import java .util .function .Consumer ;
2628import java .util .stream .Collectors ;
2729
2830/**
@@ -45,6 +47,7 @@ public class MapRendererData {
4547 private MapCursorAdapter mapCursors = new MapCursorAdapter ();
4648 private final List <MapPixel > pixels = new ArrayList <>();
4749 private MapRenderHandler dynamicRenderer ;
50+ private char [] fontChars = Characters .getFontCharsArray ();
4851
4952 /**
5053 * Constructs a new MapRendererData instance with no associated {@link MapRenderer}.
@@ -97,29 +100,45 @@ public void addPixel(@Nonnull final MapColoredPixel mapColoredPixel) {
97100 /**
98101 * Adds a text overlay to the map without a custom font character sprite.
99102 *
100- * @param x The x-coordinate of the text.
101- * @param y The y-coordinate of the text.
102- * @param text The text to display.
103+ * @param x The x-coordinate of the text.
104+ * @param y The y-coordinate of the text.
105+ * @param text The text to display.
103106 */
104107 public void addText (final int x , int y , final String text ) {
105- TextOverlay textOverlay = new TextOverlay (x , y , text );
106- pixels .add (textOverlay );
108+ this .addText (x , y , text , null , null );
109+ }
110+
111+ /**
112+ * Adds a text overlay to the map with a custom font character sprite. Will use the default set
113+ * of characters instead.
114+ *
115+ * @param x The x-coordinate of the text.
116+ * @param y The y-coordinate of the text.
117+ * @param text The text to display.
118+ * @param font The font for the character.
119+ */
120+ public void addText (final int x , int y , final String text , @ Nullable final Font font ) {
121+ this .addText (x , y , text , null , font );
107122 }
108123
109124 /**
110125 * Adds a text overlay to the map with a custom font character sprite.
111126 *
112- * @param x The x-coordinate of the text.
113- * @param y The y-coordinate of the text.
114- * @param text The text to display.
115- * @param ch The character associated with the custom font.
116- * @param sprite The {@link CharacterSprite} for the font character.
127+ * @param x The x-coordinate of the text.
128+ * @param y The y-coordinate of the text.
129+ * @param text The text to display.
130+ * @param fontChars Set the characters you want to replace in your text with the font.
131+ * @param font The font for the character
117132 */
118- public void addText (final int x , int y , final String text , final char ch , @ Nullable CharacterSprite sprite ) {
133+ public void addText (final int x , int y ,@ Nonnull final String text , @ Nullable final char [] fontChars , @ Nullable final Font font ) {
119134 TextOverlay textOverlay = new TextOverlay (x , y , text );
120- if (sprite != null )
121- textOverlay .setMapFont (ch , sprite );
122- pixels .add (textOverlay );
135+ if (font != null ) {
136+ if (fontChars != null && fontChars .length > 0 ) {
137+ this .fontChars = fontChars ;
138+ }
139+ textOverlay .setMapFont (this .fontChars , font );
140+ }
141+ this .addText (textOverlay );
123142 }
124143
125144 /**
@@ -138,7 +157,7 @@ public void addText(@Nonnull final TextOverlay textOverlay) {
138157 * @param y The y-coordinate of the image.
139158 * @param image The image to display.
140159 */
141- public void addImage (final int x ,final int y ,@ Nonnull final Image image ) {
160+ public void addImage (final int x , final int y , @ Nonnull final Image image ) {
142161 pixels .add (new ImageOverlay (x , y , image ));
143162 }
144163
@@ -211,9 +230,9 @@ public MapCursorAdapter getMapCursors() {
211230 }
212231
213232 /**
214- * Returns the current collection of map cursors .
233+ * Returns the current collection of map pixels .
215234 *
216- * @return The {@link MapCursorAdapter} managing cursors .
235+ * @return The {@link MapCursorAdapter} managing pixels .
217236 */
218237 public List <MapPixel > getPixels () {
219238 return pixels ;
@@ -226,18 +245,14 @@ public List<MapPixel> getPixels() {
226245 * @return The {@link MapRenderer} instance.
227246 */
228247 public MapRenderer getMapRenderer () {
229- /* if (this.mapRenderer != null) {
230- mapRenderer.render();
248+ if (this .mapRenderer != null ) {
231249 return mapRenderer ;
232- }*/
250+ }
233251 return new MapRenderer () {
234252 @ Override
235253 public void render (@ Nonnull MapView map , @ Nonnull MapCanvas canvas , @ Nonnull Player player ) {
236254 if (dynamicRenderer != null && dynamicRenderer .render (map , canvas , player ))
237255 return ;
238- if (mapRenderer != null ) {
239- mapRenderer .render (map , canvas , player );
240- }
241256 canvas .setCursors (mapCursors .getMapCursorCollection ());
242257 if (!getPixels ().isEmpty ()) {
243258 setPixels (canvas );
@@ -246,26 +261,6 @@ public void render(@Nonnull MapView map, @Nonnull MapCanvas canvas, @Nonnull Pla
246261 };
247262 }
248263
249- private void setPixels (final MapCanvas canvas ) {
250- getPixels ().forEach (mapPixel -> {
251- if (mapPixel instanceof MapColoredPixel ) {
252- if (ItemCreator .getServerVersion () < 20.0F )
253- canvas .setPixel (mapPixel .getX (), mapPixel .getY (), MapPalette .matchColor (((MapColoredPixel ) mapPixel ).getColor ()));
254- else
255- canvas .setPixelColor (mapPixel .getX (), mapPixel .getY (), ((MapColoredPixel ) mapPixel ).getColor ());
256- }
257- if (mapPixel instanceof TextOverlay ) {
258- TextOverlay textOverlay = (TextOverlay ) mapPixel ;
259- canvas .drawText (mapPixel .getX (), mapPixel .getY (), textOverlay .getMapFont (), textOverlay .getText ());
260- }
261- if (mapPixel instanceof ImageOverlay ) {
262- ImageOverlay textOverlay = (ImageOverlay ) mapPixel ;
263- final Image image = textOverlay .getImage ();
264- if (image != null )
265- canvas .drawImage (mapPixel .getX (), mapPixel .getY (), image );
266- }
267- });
268- }
269264
270265 @ Override
271266 public boolean equals (Object o ) {
@@ -336,4 +331,26 @@ public String toString() {
336331 ", dynamicRenderer=" + dynamicRenderer +
337332 '}' ;
338333 }
334+
335+ private void setPixels (@ Nonnull final MapCanvas canvas ) {
336+ getPixels ().forEach (mapPixel -> {
337+ if (mapPixel instanceof MapColoredPixel ) {
338+ final Color color = ((MapColoredPixel ) mapPixel ).getColor ();
339+ if (ItemCreator .getServerVersion () < 20.0F )
340+ canvas .setPixel (mapPixel .getX (), mapPixel .getY (), MapPalette .matchColor (color ));
341+ else
342+ canvas .setPixelColor (mapPixel .getX (), mapPixel .getY (), color );
343+ }
344+ if (mapPixel instanceof TextOverlay ) {
345+ TextOverlay textOverlay = (TextOverlay ) mapPixel ;
346+ canvas .drawText (mapPixel .getX (), mapPixel .getY (), textOverlay .getMapFont (), textOverlay .getText ());
347+ }
348+ if (mapPixel instanceof ImageOverlay ) {
349+ ImageOverlay textOverlay = (ImageOverlay ) mapPixel ;
350+ final Image image = textOverlay .getImage ();
351+ if (image != null )
352+ canvas .drawImage (mapPixel .getX (), mapPixel .getY (), image );
353+ }
354+ });
355+ }
339356}
0 commit comments