-
Notifications
You must be signed in to change notification settings - Fork 198
MUI for multiblock I/O buses #2266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7b7517b
partially done, ghost circuit doesnt sync
serenibyss e8be52a
"API" programming
serenibyss f768baf
we're gaming
serenibyss 323689d
Block slot interaction if panel is open
serenibyss f86c6f5
fix tooltip
serenibyss 7514552
move IntCircuitBehavior to GT slot asset
serenibyss 571a740
reviews
serenibyss 04e7b32
refresh UI
serenibyss f23ae8e
fix unavailable ghost slot widget
serenibyss 8fd3def
fix steam buses
serenibyss 3cbd68b
fix button tooltips
serenibyss 77fe2fc
refactor ghost circuit SH
serenibyss 6b95181
review
serenibyss 6cd8912
collapsing tweak, fix steam bus names
serenibyss ad25137
fix
serenibyss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
86 changes: 86 additions & 0 deletions
86
src/main/java/gregtech/api/mui/synchandler/GhostCircuitSyncHandler.java
This file contains hidden or 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,86 @@ | ||
package gregtech.api.mui.synchandler; | ||
|
||
import gregtech.api.capability.impl.GhostCircuitItemStackHandler; | ||
import gregtech.api.recipes.ingredients.IntCircuitIngredient; | ||
|
||
import net.minecraft.network.PacketBuffer; | ||
import net.minecraftforge.items.IItemHandler; | ||
|
||
import com.cleanroommc.modularui.utils.MouseData; | ||
import com.cleanroommc.modularui.value.sync.ItemSlotSH; | ||
import com.cleanroommc.modularui.widgets.slot.ModularSlot; | ||
|
||
import java.io.IOException; | ||
|
||
public class GhostCircuitSyncHandler extends ItemSlotSH { | ||
|
||
public GhostCircuitSyncHandler(ModularSlot slot) { | ||
super(slot); | ||
} | ||
|
||
@Override | ||
protected void phantomClick(MouseData mouseData) { | ||
if (mouseData.mouseButton == 0) { | ||
// increment on left-click | ||
setCircuitValue(getNextCircuitValue(1)); | ||
} else if (mouseData.mouseButton == 1 && mouseData.shift) { | ||
// clear on shift-right-click | ||
setCircuitValue(GhostCircuitItemStackHandler.NO_CONFIG); | ||
} else if (mouseData.mouseButton == 1) { | ||
// decrement on right-click | ||
setCircuitValue(getNextCircuitValue(-1)); | ||
} | ||
} | ||
|
||
@Override | ||
protected void phantomScroll(MouseData mouseData) { | ||
setCircuitValue(getNextCircuitValue(mouseData.mouseButton)); | ||
} | ||
|
||
private void setCircuitValue(int value) { | ||
GhostCircuitItemStackHandler handler = getGhostCircuitHandler(); | ||
handler.setCircuitValue(value); | ||
syncToClient(1, buf -> { | ||
buf.writeBoolean(false); | ||
buf.writeItemStack(handler.getStackInSlot(0)); | ||
buf.writeBoolean(false); | ||
}); | ||
} | ||
|
||
@Override | ||
public void readOnServer(int id, PacketBuffer buf) throws IOException { | ||
if (id == 10) { | ||
serenibyss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setCircuitValue(buf.readShort()); | ||
} else { | ||
super.readOnServer(id, buf); | ||
} | ||
} | ||
|
||
private int getNextCircuitValue(int delta) { | ||
GhostCircuitItemStackHandler handler = getGhostCircuitHandler(); | ||
|
||
// if no circuit, skip 0 and return 32 if decrementing, | ||
// or, skip 0 and return 1 when incrementing | ||
if (!handler.hasCircuitValue()) { | ||
return delta == 1 ? 1 : IntCircuitIngredient.CIRCUIT_MAX; | ||
// if at max, loop around to no circuit | ||
} else if (handler.getCircuitValue() + delta > IntCircuitIngredient.CIRCUIT_MAX) { | ||
return GhostCircuitItemStackHandler.NO_CONFIG; | ||
// if at 1, skip 0 and return to no circuit | ||
} else if (handler.getCircuitValue() + delta < 1) { | ||
return GhostCircuitItemStackHandler.NO_CONFIG; | ||
} | ||
|
||
// normal case: change by "delta" which is either 1 or -1 | ||
return handler.getCircuitValue() + delta; | ||
} | ||
|
||
public GhostCircuitItemStackHandler getGhostCircuitHandler() { | ||
IItemHandler handler = getSlot().getItemHandler(); | ||
if (!(handler instanceof GhostCircuitItemStackHandler ghostHandler)) { | ||
throw new IllegalStateException( | ||
"GhostCircuitSyncHandler has IItemHandler that is not GhostCircuitItemStackHandler"); | ||
} | ||
return ghostHandler; | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java
This file contains hidden or 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,133 @@ | ||
package gregtech.api.mui.widget; | ||
|
||
import gregtech.api.capability.impl.GhostCircuitItemStackHandler; | ||
import gregtech.api.mui.GTGuiTextures; | ||
import gregtech.api.mui.GTGuis; | ||
import gregtech.api.mui.synchandler.GhostCircuitSyncHandler; | ||
import gregtech.api.recipes.ingredients.IntCircuitIngredient; | ||
import gregtech.client.utils.TooltipHelper; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.text.TextComponentTranslation; | ||
|
||
import com.cleanroommc.modularui.api.drawable.IKey; | ||
import com.cleanroommc.modularui.api.widget.IWidget; | ||
import com.cleanroommc.modularui.drawable.ItemDrawable; | ||
import com.cleanroommc.modularui.screen.ModularScreen; | ||
import com.cleanroommc.modularui.screen.Tooltip; | ||
import com.cleanroommc.modularui.utils.MouseData; | ||
import com.cleanroommc.modularui.value.sync.ItemSlotSH; | ||
import com.cleanroommc.modularui.widgets.ButtonWidget; | ||
import com.cleanroommc.modularui.widgets.ItemSlot; | ||
import com.cleanroommc.modularui.widgets.layout.Grid; | ||
import com.cleanroommc.modularui.widgets.slot.ModularSlot; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class GhostCircuitSlotWidget extends ItemSlot { | ||
|
||
public GhostCircuitSlotWidget() { | ||
tooltipBuilder(this::getCircuitSlotTooltip); | ||
} | ||
|
||
@Override | ||
public @NotNull Result onMousePressed(int mouseButton) { | ||
if (!isSelectorPanelOpen()) { | ||
if (mouseButton == 0 && TooltipHelper.isShiftDown()) { | ||
createSelectorPanel(); | ||
} else { | ||
MouseData mouseData = MouseData.create(mouseButton); | ||
getSyncHandler().syncToServer(2, mouseData::writeToPacket); | ||
} | ||
} | ||
return Result.SUCCESS; | ||
} | ||
|
||
@Override | ||
public boolean onMouseScroll(ModularScreen.UpOrDown scrollDirection, int amount) { | ||
if (isSelectorPanelOpen()) return true; | ||
MouseData mouseData = MouseData.create(scrollDirection.modifier); | ||
getSyncHandler().syncToServer(3, mouseData::writeToPacket); | ||
return false; | ||
} | ||
|
||
@Override | ||
public ItemSlot slot(ModularSlot slot) { | ||
ItemSlotSH sh = new GhostCircuitSyncHandler(slot); | ||
isValidSyncHandler(sh); | ||
setSyncHandler(sh); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected List<String> getItemTooltip(ItemStack stack) { | ||
// we don't want the item tooltip | ||
return Collections.emptyList(); | ||
} | ||
|
||
protected void getCircuitSlotTooltip(@NotNull Tooltip tooltip) { | ||
String configString; | ||
int value = getSyncHandler().getGhostCircuitHandler().getCircuitValue(); | ||
if (value == GhostCircuitItemStackHandler.NO_CONFIG) { | ||
configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value").getFormattedText(); | ||
} else { | ||
configString = String.valueOf(value); | ||
} | ||
|
||
tooltip.addLine(IKey.lang("gregtech.gui.configurator_slot.tooltip", configString)); | ||
} | ||
|
||
@Override | ||
public @NotNull GhostCircuitSyncHandler getSyncHandler() { | ||
return (GhostCircuitSyncHandler) super.getSyncHandler(); | ||
} | ||
|
||
@Override | ||
public void onMouseDrag(int mouseButton, long timeSinceClick) {} | ||
|
||
@Override | ||
public boolean onMouseRelease(int mouseButton) { | ||
return true; | ||
} | ||
|
||
private boolean isSelectorPanelOpen() { | ||
return getPanel().getScreen().isPanelOpen("circuit_selector"); | ||
} | ||
|
||
private void createSelectorPanel() { | ||
ItemDrawable circuitPreview = new ItemDrawable(getSyncHandler().getSlot().getStack()); | ||
|
||
List<List<IWidget>> options = new ArrayList<>(); | ||
for (int i = 0; i < 4; i++) { | ||
options.add(new ArrayList<>()); | ||
for (int j = 0; j < 9; j++) { | ||
int index = i * 9 + j; | ||
if (index > 32) break; | ||
options.get(i).add(new ButtonWidget<>() | ||
.size(18) | ||
.background(GTGuiTextures.SLOT, new ItemDrawable( | ||
IntCircuitIngredient.getIntegratedCircuit(index)).asIcon()) | ||
.onMousePressed(mouseButton -> { | ||
getSyncHandler().syncToServer(10, buf -> buf.writeShort(index)); | ||
serenibyss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(index)); | ||
return true; | ||
})); | ||
} | ||
} | ||
|
||
getPanel().getScreen().openPanel(GTGuis.createPanel("circuit_selector", 176, 120) | ||
.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5)) | ||
.child(circuitPreview.asIcon().size(16).asWidget() | ||
.size(18) | ||
.top(19).alignX(0.5f) | ||
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY)) | ||
.child(new Grid() | ||
.left(7).right(7).top(41).height(4 * 18) | ||
.matrix(options) | ||
.minColWidth(18).minRowHeight(18) | ||
.minElementMargin(0, 0))); | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.