-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
common/src/main/java/muramasa/antimatter/gui/widget/SyncableTextWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package muramasa.antimatter.gui.widget; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import muramasa.antimatter.capability.IGuiHandler; | ||
import muramasa.antimatter.gui.GuiInstance; | ||
import muramasa.antimatter.gui.ICanSyncData; | ||
import muramasa.antimatter.gui.IGuiElement; | ||
import muramasa.antimatter.gui.Widget; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Function; | ||
|
||
public class SyncableTextWidget extends TextWidget { | ||
String text = ""; | ||
final Function<IGuiHandler, String> syncFunction; | ||
protected SyncableTextWidget(@NotNull GuiInstance gui, @Nullable IGuiElement parent, int color, Function<IGuiHandler, String> syncFunction) { | ||
super(gui, parent, a-> ((SyncableTextWidget)a).text, color); | ||
this.syncFunction = syncFunction; | ||
|
||
} | ||
|
||
public static WidgetSupplier build(Function<IGuiHandler, String> textSyncFunction, int color) { | ||
return builder((a, b) -> new SyncableTextWidget(a, b, color, textSyncFunction)); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
gui.syncString(() -> syncFunction.apply(gui.handler), s -> text = s, ICanSyncData.SyncDirection.SERVER_TO_CLIENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters