Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/content/Development/MUI2/Syncing/Basic-Sync-Example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Basic Sync Example

```java
public class MuiTestMachine extends MetaMachine implements IMuiMachine {

public int ticks = 0;
public MuiTestMachine(BlockEntityCreationInfo info) {
super(info);
this.subscribeServerTick(() -> ticks++);
}

@Override
public ModularPanel buildUI(PosGuiData data, PanelSyncManager syncManager, UISettings settings) {
var panel = GTGuis.createPanel(this, 176, 168);
var tickSyncValue = new IntSyncValue(() -> this.ticks, (newValue) -> this.ticks = newValue);
syncManager.syncValue("tickSyncValue", tickSyncValue);

panel.child(IKey.dynamic(() -> Component.literal("Ticks: "+ this.ticks))
.asWidget()
.margin(4));

return panel;
}
}
```

Here, we create a basic `SyncValue` for an integer. This takes a `Supplier<Integer>` and a `Consumer<Integer>`, more commonly known as a getter and a setter. Generally speaking, `SyncValue`s will take a `Supplier` and `Consumer` of the type of value they are syncing.

If the value returned by the getter changed on the server, the value gets serialized and sent to the client by the `SyncManager`. The `SyncHandler`'s value can always be manually updated, for example to do client-to-server syncing.

If you try to access values on the client that aren't synced or don't have a `SyncValue` or `SyncHandler`, they will have a default value, but they will not reflect the values or changes happening on the server.
6 changes: 6 additions & 0 deletions docs/content/Development/MUI2/Syncing/SyncManager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SyncManager
A `PanelSyncManager` is the panel-level coordinator that keeps server state and client UI in sync.

You register `SyncValue`s and other `SyncHandler`s on it during `buildUI`. Then, these are checked every server tick, and any changes are shipped to the other side.

This is what makes widgets reflect live data and makes client-side interactions safely update the server.
1 change: 1 addition & 0 deletions docs/content/Development/MUI2/Syncing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Syncing is the concept of synchronising data between client and server. This folder will contain files relevant to setting up syncing on your UIs.
35 changes: 35 additions & 0 deletions docs/content/Development/MUI2/Test-Machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Making a MUI2 Test Machine
To make a basic machine to test your UI, simply create the following class:

```java title="MultiMachines.java"
public class MuiTestMachine extends MetaMachine implements IMuiMachine {

public MuiTestMachine(BlockEntityCreationInfo info) {
super(info);
}

@Override
public ModularPanel buildUI(PosGuiData data, PanelSyncManager syncManager, UISettings settings) {
var panel = GTGuis.createPanel(this, 176, 168);
// Do stuff with your panel here, add children, etc.
// For example:
panel.child(IKey.str("Test machine")
.asWidget()
.margin(4));

return panel;
}
}
```

and in your machines definitions class, add the following entry:

```java
public static final MachineDefinition MUI_TEST_MACHINE = REGISTRATE
.machine("mui_test", MuiTestMachine::new)
.model(createOverlayCasingMachineModel(GTCEu.id("block/casings/solid/machine_casing_clean_stainless_steel"),
GTCEu.id("block/machine/part/computer_monitor")))
.register();
```

Make sure to run datagen after making the initial machine to register the lang keys, model, etc. Running datagen afterward for UI changes is not required.
5 changes: 5 additions & 0 deletions docs/content/Development/MUI2/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ModularUI 2
ModularUI 2 is the UI library used in GTM starting from 8.0.0, and is the successor to LDLib UI.
From ModularUI 1.12's github:

With ModularUI you can build GUIs fast by adding Widgets to panels with layout widgets, so you don't have to calculate positions and sizes yourself. ModularUI is very dynamic and allows for very complicated client-server synced GUIs.