generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
db8228f
commit 9e73431
Showing
20 changed files
with
236 additions
and
243 deletions.
There are no files selected for viewing
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
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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/mystic/holographicrenders/client/TextboxScreenRoot.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,41 @@ | ||
package com.mystic.holographicrenders.client; | ||
|
||
import com.mystic.holographicrenders.HolographicRenders; | ||
import io.github.cottonmc.cotton.gui.ItemSyncedGuiDescription; | ||
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; | ||
import io.github.cottonmc.cotton.gui.widget.WButton; | ||
import io.github.cottonmc.cotton.gui.widget.WGridPanel; | ||
import io.github.cottonmc.cotton.gui.widget.WLabel; | ||
import io.github.cottonmc.cotton.gui.widget.WTextField; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.inventory.StackReference; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.Identifier; | ||
|
||
|
||
public class TextboxScreenRoot extends LightweightGuiDescription { | ||
|
||
public TextboxScreenRoot(Hand hand) { | ||
WGridPanel root = new WGridPanel(); | ||
WButton button = new WButton(); | ||
WTextField textFieldWidget = new WTextField(Text.of("Please enter a valid URL!")); | ||
WLabel label = new WLabel(Text.literal("Save URL")); | ||
setRootPanel(root); | ||
root.setSize(256, 240); | ||
textFieldWidget.setMaxLength(90); | ||
root.add(textFieldWidget, 0, 5, 15, 10); | ||
root.add(button, 4, 8, 6, 20); | ||
root.add(label, 4, 8); | ||
root.validate(this); | ||
button.setOnClick(() -> { | ||
PacketByteBuf buf = PacketByteBufs.create(); | ||
buf.writeString(textFieldWidget.getText(), 2000); | ||
buf.writeEnumConstant(hand); | ||
ClientPlayNetworking.send(new Identifier(HolographicRenders.MOD_ID, "url_packet"), buf); | ||
}); | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
src/main/java/com/mystic/holographicrenders/client/TextureRenderLayer.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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/mystic/holographicrenders/client/WidgetScreenRoot.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,13 @@ | ||
package com.mystic.holographicrenders.client; | ||
|
||
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; | ||
import io.github.cottonmc.cotton.gui.widget.WGridPanel; | ||
import net.minecraft.util.Hand; | ||
|
||
public class WidgetScreenRoot extends LightweightGuiDescription { | ||
|
||
public WidgetScreenRoot(Hand hand) { | ||
WGridPanel root = new WGridPanel(); | ||
root.validate(this); | ||
} | ||
} |
95 changes: 56 additions & 39 deletions
95
src/main/java/com/mystic/holographicrenders/gui/ProjectorScreen.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 |
---|---|---|
@@ -1,63 +1,80 @@ | ||
package com.mystic.holographicrenders.gui; | ||
|
||
import static com.teamwizardry.librarianlib.core.util.Shorthand.vec; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mystic.holographicrenders.network.ProjectorScreenPacket; | ||
import com.teamwizardry.librarianlib.facade.container.FacadeView; | ||
import com.teamwizardry.librarianlib.facade.layers.SpriteLayer; | ||
import com.teamwizardry.librarianlib.facade.layers.TextLayer; | ||
import com.teamwizardry.librarianlib.facade.layers.text.TextFit; | ||
import com.teamwizardry.librarianlib.facade.pastry.layers.PastryCheckbox; | ||
import com.teamwizardry.librarianlib.facade.pastry.layers.PastryToggle; | ||
import com.teamwizardry.librarianlib.mosaic.Mosaic; | ||
import com.teamwizardry.librarianlib.mosaic.MosaicSprite; | ||
import ll.dev.thecodewarrior.bitfont.typesetting.TextLayoutManager; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.gui.widget.CheckboxWidget; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.Language; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class ProjectorScreen extends FacadeView<ProjectorScreenHandler> { | ||
private static final MosaicSprite TEXTURE = new Mosaic(new Identifier("holographic_renders", "textures/gui_hologram_projector.png"), 256,256).getSprite("main"); | ||
public class ProjectorScreen extends HandledScreen<ProjectorScreenHandler> { | ||
private static final Identifier TEXTURE = new Identifier("holographic_renders", "textures/gui_hologram_projector.png"); | ||
|
||
private boolean lightsEnabled = false; | ||
|
||
public ProjectorScreen(ProjectorScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
getMain().setSize(vec(Textures.main.getWidth(), Textures.main.getHeight())); | ||
|
||
SpriteLayer sprite = new SpriteLayer(Textures.main); | ||
TextLayer text = new TextLayer(128, 7, Language.getInstance().get("block.holographic_renders.projector")); | ||
text.fitToText(TextFit.BOTH); | ||
text.setTextAlignment(TextLayoutManager.Alignment.LEFT); | ||
sprite.add(text); | ||
|
||
PastryCheckbox checkbox = new PastryCheckbox(110, 39, false); | ||
checkbox.BUS.hook(PastryToggle.StateWillChangeEvent.class, event -> client.getNetworkHandler().sendPacket(ProjectorScreenPacket.createLightAction(event.getNewState()))); | ||
TextLayer light = new TextLayer(8, -1,"Light"); | ||
light.fitToText(TextFit.BOTH); | ||
light.setTextAlignment(TextLayoutManager.Alignment.LEFT); | ||
checkbox.add(light); | ||
checkbox.setState(handler.getLight()); | ||
|
||
getMain().add(sprite); | ||
getMain().add(checkbox); | ||
|
||
getMain().onLayout(() -> { | ||
text.setX(getMain().getWidth() * 0.5 - text.getWidth() * 0.5); | ||
} | ||
|
||
@Override | ||
protected void drawBackground(DrawContext matrices, float delta, int mouseX, int mouseY) { | ||
RenderSystem.setShaderFogColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
client.getTextureManager().bindTexture(TEXTURE); | ||
int x = (width - backgroundWidth) / 2; | ||
int y = (height - backgroundHeight) / 2; | ||
matrices.drawTexture(TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight); | ||
} | ||
|
||
@Override | ||
public void render(DrawContext matrices, int mouseX, int mouseY, float delta) { | ||
renderBackground(matrices); | ||
super.render(matrices, mouseX, mouseY, delta); | ||
drawMouseoverTooltip(matrices, mouseX, mouseY); | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
// Center the title | ||
titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2; | ||
|
||
int x = (width - backgroundWidth) / 2; | ||
int y = (height - backgroundHeight) / 2; | ||
|
||
CheckboxWidget lightCheckbox = new CallbackCheckboxWidget(x + 110, y + 33, Text.of("Light"), lightsEnabled, aBoolean -> { | ||
client.getNetworkHandler().sendPacket(ProjectorScreenPacket.createLightAction(aBoolean)); | ||
}); | ||
addDrawable(lightCheckbox); | ||
|
||
} | ||
|
||
public void setLights(boolean lightsEnabled) { | ||
this.lightsEnabled = lightsEnabled; | ||
reload(); | ||
} | ||
|
||
private void reload() { | ||
this.init(MinecraftClient.getInstance(), this.width, this.height); | ||
} | ||
|
||
protected static class CallbackCheckboxWidget extends CheckboxWidget { | ||
|
||
private final Consumer<Boolean> changeCallback; | ||
|
||
public CallbackCheckboxWidget(int x, int y, Text message, boolean checked, Consumer<Boolean> changeCallback) { | ||
super(x, y, 20, 20, message, checked); | ||
this.changeCallback = changeCallback; | ||
} | ||
|
||
@Override | ||
public void onPress() { | ||
super.onPress(); | ||
changeCallback.accept(isChecked()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.