66
77import org .joml .Quaternionf ;
88
9+ import com .aurus .tinytactics .data .TacticsDrawToolMap ;
910import com .aurus .tinytactics .data .TacticsRulerMap ;
11+ import com .aurus .tinytactics .data .TacticsShape ;
12+ import com .aurus .tinytactics .data .TacticsShapeMap ;
13+ import com .aurus .tinytactics .util .Collection ;
1014import com .aurus .tinytactics .util .ListCollection ;
15+ import com .aurus .tinytactics .util .MapCollection ;
1116
17+ import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderContext ;
1218import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderEvents ;
1319import net .minecraft .util .math .BlockPos ;
1420import net .minecraft .util .math .Vec3d ;
1824
1925public class RenderManager {
2026
21- private TacticsRulerMap map ;
27+ private TacticsRulerMap tacticsRulerMap ;
28+ private TacticsShapeMap tacticsShapeMap ;
2229
2330 private static RenderManager manager ;
2431
@@ -28,8 +35,11 @@ public class RenderManager {
2835 private static final double CORNER_RULER_LINE_OPACITY = 0.5 ;
2936 private static final float CORNER_RULER_LINE_WIDTH = 0.02F ;
3037
38+ private static final double SHAPE_OPACITY = 0.5 ;
39+
3140 private RenderManager () {
32- map = TacticsRulerMap .DEFAULT ;
41+ tacticsRulerMap = TacticsRulerMap .DEFAULT ;
42+ tacticsShapeMap = TacticsShapeMap .DEFAULT ;
3343 }
3444
3545 public static RenderManager getManager () {
@@ -40,33 +50,63 @@ public static RenderManager getManager() {
4050 }
4151
4252 public void init () {
43- WorldRenderEvents .AFTER_ENTITIES .register (context -> {
44- for (Map <DyeColor , ListCollection <BlockPos >> userMap : map .getFullMap ().values ()) {
45- for (DyeColor color : userMap .keySet ()) {
53+ WorldRenderEvents .AFTER_TRANSLUCENT .register (context -> {
54+ renderAllRulerLines (context );
55+ renderAllShapes (context );
56+
57+ ConeDrawer .renderDebugCone (context );
58+ });
59+ }
60+
61+ public void updateRulerMap (TacticsRulerMap map ) {
62+ this .tacticsRulerMap = map ;
63+ }
64+
65+ public void updateShapeMap (TacticsShapeMap map ) {
66+ this .tacticsShapeMap = map ;
67+ }
4668
47- List <BlockPos > list = userMap .get (color ).getEntries ();
48- List <Vec3d > vecs = blockPosToVec3ds (list );
69+ private <E extends TacticsDrawToolMap <T , C >, T , C extends Collection <T >> void renderAllDrawFeatures (
70+ WorldRenderContext context , E map , CollectionConsumer <T > consumer ) {
71+ for (Map <DyeColor , C > userMap : map .getFullMap ().values ()) {
72+ for (DyeColor color : userMap .keySet ()) {
73+ consumer .consume (userMap .get (color ), color );
74+ }
75+ }
76+ }
4977
50- if (vecs .size () >= 2 ) {
51- int mainColor = setColorAlpha (color .getEntityColor (), MAIN_RULER_LINE_OPACITY );
52- LineDrawer .renderQuadCrossLineStrip (context , vecs , mainColor , MAIN_RULER_LINE_WIDTH );
78+ private void renderAllRulerLines (WorldRenderContext context ) {
79+ renderAllDrawFeatures (context , tacticsRulerMap , (collection , color ) -> {
80+ List <BlockPos > list = ((ListCollection <BlockPos >) collection ).getEntries ();
81+ List <Vec3d > vecs = blockPosToVec3ds (list );
5382
54- Vec3d from = vecs .get (Math .max (vecs .size () - 2 , 0 ));
55- Vec3d to = vecs .get (Math .max (vecs .size () - 1 , 0 ));
56- int conerColor = setColorAlpha (mainColor , CORNER_RULER_LINE_OPACITY );
57- LineDrawer .renderLinesToCorners (context , from , to , conerColor ,
58- CORNER_RULER_LINE_WIDTH );
59- }
83+ if (vecs .size () >= 2 ) {
84+ int mainColor = setColorAlpha (color .getEntityColor (), MAIN_RULER_LINE_OPACITY );
85+ LineDrawer .renderQuadCrossLineStrip (context , vecs , mainColor , MAIN_RULER_LINE_WIDTH );
6086
61- }
87+ Vec3d from = vecs .get (Math .max (vecs .size () - 2 , 0 ));
88+ Vec3d to = vecs .get (Math .max (vecs .size () - 1 , 0 ));
89+ int conerColor = setColorAlpha (mainColor , CORNER_RULER_LINE_OPACITY );
90+ LineDrawer .renderLinesToCorners (context , from , to , conerColor ,
91+ CORNER_RULER_LINE_WIDTH );
6292 }
93+ });
94+ }
6395
64- ConeDrawer .renderDebugCone (context );
96+ private void renderAllShapes (WorldRenderContext context ) {
97+ renderAllDrawFeatures (context , tacticsShapeMap , (collection , color ) -> {
98+ Map <TacticsShape .Type , TacticsShape > map = ((MapCollection <TacticsShape .Type , TacticsShape >) collection )
99+ .getEntries ();
100+ TacticsShape cone = map .get (TacticsShape .Type .CONE );
101+ if (cone != null ) {
102+ ConeDrawer .renderCone (context , blockPosToVec3d (cone .getOrigin ()), cone .getLength (), cone .getDiameter (),
103+ cone .getDirection (), setColorAlpha (color .getEntityColor (), SHAPE_OPACITY ));
104+ }
65105 });
66106 }
67107
68- public void updateMap ( TacticsRulerMap map ) {
69- this . map = map ;
108+ public interface CollectionConsumer < T > {
109+ void consume ( Collection < T > collection , DyeColor color ) ;
70110 }
71111
72112 public static List <Vec3d > blockPosToVec3ds (List <BlockPos > blockPos ) {
0 commit comments