2020
2121import com .cleanroommc .modularui .api .drawable .IDrawable ;
2222import com .cleanroommc .modularui .api .drawable .IKey ;
23+ import com .cleanroommc .modularui .api .drawable .IRichTextBuilder ;
2324import com .cleanroommc .modularui .api .widget .IWidget ;
24- import com .cleanroommc .modularui .drawable .text .DynamicKey ;
25+ import com .cleanroommc .modularui .drawable .text .RichText ;
2526import com .cleanroommc .modularui .factory .PosGuiData ;
2627import com .cleanroommc .modularui .screen .ModularPanel ;
28+ import com .cleanroommc .modularui .screen .RichTooltip ;
2729import com .cleanroommc .modularui .utils .Alignment ;
2830import com .cleanroommc .modularui .value .sync .BooleanSyncValue ;
2931import com .cleanroommc .modularui .value .sync .IntSyncValue ;
3537import com .cleanroommc .modularui .widget .scroll .VerticalScrollData ;
3638import com .cleanroommc .modularui .widgets .CycleButtonWidget ;
3739import com .cleanroommc .modularui .widgets .ProgressWidget ;
40+ import com .cleanroommc .modularui .widgets .RichTextWidget ;
3841import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
39- import com .cleanroommc .modularui .widgets .layout .Column ;
4042import com .cleanroommc .modularui .widgets .layout .Flow ;
41- import com .cleanroommc .modularui .widgets .layout .Row ;
42- import it .unimi .dsi .fastutil .ints .Int2ObjectArrayMap ;
43- import it .unimi .dsi .fastutil .ints .Int2ObjectMap ;
4443import org .jetbrains .annotations .NotNull ;
4544import org .jetbrains .annotations .Nullable ;
4645
4746import java .io .IOException ;
4847import java .util .ArrayList ;
49- import java .util .Collections ;
5048import java .util .List ;
49+ import java .util .Objects ;
5150import java .util .function .BiFunction ;
5251import java .util .function .BooleanSupplier ;
5352import java .util .function .Consumer ;
5453import java .util .function .DoubleSupplier ;
55- import java .util .function .Function ;
5654import java .util .function .IntSupplier ;
5755import java .util .function .Supplier ;
5856
@@ -144,7 +142,7 @@ private Widget<?> createIndicator() {
144142 .pos (174 - 5 , screenHeight - 18 - 3 )
145143 .onUpdateListener (w -> w .overlay (getIndicatorOverlay (builder )))
146144 .tooltip (tooltip -> tooltip .setAutoUpdate (true ))
147- .tooltipBuilder (tooltip -> tooltip . addDrawableLines ( builder . getTextList ()) );
145+ .tooltipBuilder (builder :: buildTooltip );
148146 }
149147
150148 private IDrawable getIndicatorOverlay (Builder builder ) {
@@ -308,27 +306,29 @@ public MultiblockUIFactory customScreen(Supplier<ParentWidget<?>> customScreen)
308306 protected Widget <?> createScreen (PanelSyncManager syncManager ) {
309307 final var builder = builder ();
310308 this .displayText .accept (builder );
311- var col = new Column ();
312- builder .build ( col );
309+ var richTextWidget = new RichTextWidget ();
310+ builder .buildDisplay ( richTextWidget );
313311 final var compare = builder ();
314312
315313 return new ParentWidget <>()
316314 .child (createIndicator ())
317315 .child (customScreen != null ? customScreen .get () : new ScrollWidget <>(new VerticalScrollData ())
318316 .sizeRel (1f )
319- .child (col .expanded ()
317+ .child (richTextWidget .sizeRel (1f )
318+ .alignment (Alignment .TopLeft )
320319 .margin (4 , 4 )
321320 .onUpdateListener (column -> {
322321 // really debating on if the display screen should be its own widget
323- compare .clear ();
322+ // compare.clear();
324323 this .displayText .accept (compare );
325- if (!builder .hasChanged (compare ) && !dirty ) return ;
326- builder .clear ();
327- column .getChildren ().clear ();
328- this .displayText .accept (builder );
329- builder .build (column );
330- resize (column );
331- dirty = false ;
324+ // if (!builder.hasChanged(compare) && !dirty) return;
325+ // builder.clear();
326+ if (builder .hasChanged (compare ))
327+ column .markDirty ();
328+ // this.displayText.accept(builder);
329+ // builder.build(column);
330+ // resize(column);
331+ // dirty = false;
332332 })))
333333 .background (GTGuiTextures .DISPLAY )
334334 .size (190 , screenHeight )
@@ -465,9 +465,11 @@ protected static Builder builder() {
465465 @ SuppressWarnings ({ "UnusedReturnValue" , "unused" })
466466 public static class Builder {
467467
468- private final List <IDrawable > textList ;
469- private Function <IDrawable , Widget <?>> widgetFunction = Builder ::keyMapper ;
470- private final Int2ObjectMap <IDrawable > tooltips = new Int2ObjectArrayMap <>();
468+ private final RichText text = new RichText ();
469+ private final List <Consumer <IRichTextBuilder <? extends IRichTextBuilder <?>>>> textList = new ArrayList <>();
470+ // private final List<IDrawable> textList;
471+ // private Function<IDrawable, Widget<?>> widgetFunction = Builder::keyMapper;
472+ // private final Int2ObjectMap<IDrawable> tooltips = new Int2ObjectArrayMap<>();
471473
472474 private BooleanSupplier isWorkingEnabled = () -> false ;
473475 private BooleanSupplier isActive = () -> false ;
@@ -479,15 +481,15 @@ public static class Builder {
479481 private IKey runningKey = IKey .lang ("gregtech.multiblock.running" ).format (TextFormatting .GREEN );
480482 private boolean dirty ;
481483
482- protected static Widget <?> keyMapper (IDrawable key ) {
483- return key .asWidget ()
484- .widthRel (1f )
485- .height (12 );
486- }
484+ // protected static Widget<?> keyMapper(IDrawable key) {
485+ // return key.asWidget()
486+ // .widthRel(1f)
487+ // .height(12);
488+ // }
487489
488- private Builder () {
489- this .textList = new ArrayList <>();
490- }
490+ // private Builder() {
491+ // this.textList = new ArrayList<>();
492+ // }
491493
492494 public Builder structureFormed (boolean structureFormed ) {
493495 this .isStructureFormed = structureFormed ;
@@ -672,11 +674,11 @@ public Builder addWorkingStatusLine() {
672674
673675 addKey (KeyUtil .string (() -> {
674676 if (!isWorkingEnabled .getAsBoolean ()) {
675- return TextFormatting . GOLD + pausedKey .get ();
677+ return pausedKey .getFormatted ();
676678 } else if (isActive .getAsBoolean ()) {
677- return TextFormatting . GREEN + runningKey .get ();
679+ return runningKey .getFormatted ();
678680 } else {
679- return TextFormatting . GRAY + idlingKey .get ();
681+ return idlingKey .getFormatted ();
680682 }
681683 }));
682684 return this ;
@@ -881,23 +883,13 @@ public Builder addFuelNeededLine(String fuelName, IntSupplier previousRecipeDura
881883
882884 /** Insert an empty line into the text list. */
883885 public Builder addEmptyLine () {
884- addKey ( IKey . EMPTY ); // this is going to cause problems maybe
886+ this . text . newLine ();
885887 return this ;
886888 }
887889
888890 /** Add custom text dynamically, allowing for custom application logic. */
889- public Builder addCustom (Consumer <List <IDrawable >> customConsumer ) {
890- List <IDrawable > customKeys = new ArrayList <>();
891- customConsumer .accept (customKeys );
892- customKeys .forEach (this ::addKey );
893- return this ;
894- }
895-
896- /**
897- * @param widgetFunction function to build widgets from keys
898- */
899- public Builder widgetFunction (Function <IDrawable , Widget <?>> widgetFunction ) {
900- this .widgetFunction = widgetFunction ;
891+ public Builder addCustom (Consumer <RichText > customConsumer ) {
892+ customConsumer .accept (this .text );
901893 return this ;
902894 }
903895
@@ -909,41 +901,35 @@ protected void clear() {
909901 textList .clear ();
910902 }
911903
912- protected void build (ParentWidget <?> parent ) {
913- for (int i = 0 ; i < textList .size (); i ++) {
914- var line = this .widgetFunction .apply (textList .get (i ));
915- if (tooltips .containsKey (i ))
916- line .addTooltipLine (tooltips .get (i ));
917- parent .child (line );
918- }
904+ protected void buildDisplay (RichTextWidget parent ) {
905+ parent .textBuilder (richText -> this .textList .forEach (t -> t .accept (richText )));
919906 }
920907
921- protected List < IDrawable > getTextList ( ) {
922- return Collections . unmodifiableList ( textList );
908+ protected void buildTooltip ( RichTooltip tooltip ) {
909+ this . textList . forEach ( t -> t . accept ( tooltip ) );
923910 }
924911
925- protected boolean hasChanged (Builder other ) {
926- if (textList .size () != other .textList .size ()) return true ;
927- for (int i = 0 ; i < textList .size (); i ++) {
928- IDrawable left = textList .get (i ), right = other .textList .get (i );
929-
930- // dynamic keys are impossible to check, skip
931- if (left instanceof DynamicKey && right instanceof DynamicKey )
932- continue ;
912+ protected RichText getTextList () {
913+ return this .text ;
914+ }
933915
934- if (!left .equals (right ))
916+ protected boolean hasChanged (Builder other ) {
917+ List <String > cur = text .getStringRepresentation ();
918+ List <String > oth = other .text .getStringRepresentation ();
919+ if (cur .size () != oth .size ()) return true ;
920+ for (int i = 0 ; i < cur .size (); i ++) {
921+ if (!Objects .equals (cur .get (i ), oth .get (i )))
935922 return true ;
936923 }
937924 return false ;
938925 }
939926
940927 private void addKey (IDrawable key ) {
941- this . textList .add (key );
928+ textList .add (richText -> richText . addLine ( key ) );
942929 }
943930
944- private void addKey (IDrawable key , IDrawable hover ) {
945- this .tooltips .put (textList .size (), hover );
946- addKey (key );
931+ private void addKey (IKey key , IDrawable hover ) {
932+ addKey (key .asTextIcon ().asHoverable ().addTooltipLine (hover ));
947933 }
948934 }
949935}
0 commit comments