Position recording control buttons relative to Exit (fixes #281)
This commit is contained in:
@@ -42,6 +42,12 @@ import net.minecraft.client.gui.widget.ButtonWidget;
|
|||||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
//#if MC>=11600
|
||||||
|
//$$ import net.minecraft.text.TranslatableText;
|
||||||
|
//#else
|
||||||
|
import net.minecraft.client.resource.language.I18n;
|
||||||
|
//#endif
|
||||||
//#else
|
//#else
|
||||||
//$$ import com.google.common.util.concurrent.FutureCallback;
|
//$$ import com.google.common.util.concurrent.FutureCallback;
|
||||||
//$$ import com.google.common.util.concurrent.Futures;
|
//$$ import com.google.common.util.concurrent.Futures;
|
||||||
@@ -119,6 +125,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstraction over things that have changed between different MC versions.
|
* Abstraction over things that have changed between different MC versions.
|
||||||
@@ -603,6 +610,31 @@ public class MCVer {
|
|||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#if MC>=11400
|
||||||
|
public static Optional<AbstractButtonWidget> findButton(List<AbstractButtonWidget> buttonList, @SuppressWarnings("unused") String text, @SuppressWarnings("unused") int id) {
|
||||||
|
//#if MC>=11600
|
||||||
|
//$$ final TranslatableText message = new TranslatableText(text);
|
||||||
|
//#else
|
||||||
|
final String message = I18n.translate(text);
|
||||||
|
//#endif
|
||||||
|
for (AbstractButtonWidget b : buttonList) {
|
||||||
|
if (message.equals(b.getMessage())) {
|
||||||
|
return Optional.of(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
//#else
|
||||||
|
//$$ public static Optional<GuiButton> findButton(List<GuiButton> buttonList, @SuppressWarnings("unused") String text, int id) {
|
||||||
|
//$$ for (GuiButton b : buttonList) {
|
||||||
|
//$$ if (b.id == id) {
|
||||||
|
//$$ return Optional.of(b);
|
||||||
|
//$$ }
|
||||||
|
//$$ }
|
||||||
|
//$$ return Optional.empty();
|
||||||
|
//$$ }
|
||||||
|
//#endif
|
||||||
|
|
||||||
//#if MC>=11400
|
//#if MC>=11400
|
||||||
public static void processKeyBinds() {
|
public static void processKeyBinds() {
|
||||||
((MinecraftMethodAccessor) getMinecraft()).replayModProcessKeyBinds();
|
((MinecraftMethodAccessor) getMinecraft()).replayModProcessKeyBinds();
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import com.replaymod.editor.gui.MarkerProcessor;
|
|||||||
import com.replaymod.recording.Setting;
|
import com.replaymod.recording.Setting;
|
||||||
import com.replaymod.recording.packet.PacketListener;
|
import com.replaymod.recording.packet.PacketListener;
|
||||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
|
||||||
import de.johni0702.minecraft.gui.container.VanillaGuiScreen;
|
import de.johni0702.minecraft.gui.container.VanillaGuiScreen;
|
||||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
//#if FABRIC>=1
|
//#if FABRIC>=1
|
||||||
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||||
@@ -25,6 +25,14 @@ import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
|||||||
//$$ import static com.replaymod.core.versions.MCVer.getGui;
|
//$$ import static com.replaymod.core.versions.MCVer.getGui;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
//#if MC>=11400
|
||||||
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class GuiRecordingControls extends EventRegistrations {
|
public class GuiRecordingControls extends EventRegistrations {
|
||||||
private ReplayMod core;
|
private ReplayMod core;
|
||||||
private PacketListener packetListener;
|
private PacketListener packetListener;
|
||||||
@@ -70,21 +78,6 @@ public class GuiRecordingControls extends EventRegistrations {
|
|||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if FABRIC>=1
|
|
||||||
{ on(InitScreenCallback.EVENT, (screen, buttons) -> {
|
|
||||||
if (screen instanceof GameMenuScreen) {
|
|
||||||
show((GameMenuScreen) screen);
|
|
||||||
}
|
|
||||||
}); }
|
|
||||||
//#else
|
|
||||||
//$$ @SubscribeEvent
|
|
||||||
//$$ public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
|
||||||
//$$ if (getGui(event) instanceof IngameMenuScreen) {
|
|
||||||
//$$ show((IngameMenuScreen) getGui(event));
|
|
||||||
//$$ }
|
|
||||||
//$$ }
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
private void updateState() {
|
private void updateState() {
|
||||||
buttonPauseResume.setI18nLabel("replaymod.gui.recording." + (paused ? "resume" : "pause"));
|
buttonPauseResume.setI18nLabel("replaymod.gui.recording." + (paused ? "resume" : "pause"));
|
||||||
buttonStartStop.setI18nLabel("replaymod.gui.recording." + (stopped ? "start" : "stop"));
|
buttonStartStop.setI18nLabel("replaymod.gui.recording." + (stopped ? "start" : "stop"));
|
||||||
@@ -92,12 +85,32 @@ public class GuiRecordingControls extends EventRegistrations {
|
|||||||
buttonPauseResume.setEnabled(!stopped);
|
buttonPauseResume.setEnabled(!stopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(GameMenuScreen gui) {
|
//#if FABRIC>=1
|
||||||
int modMenuOffset = MCVer.isModLoaded("modmenu") ? 12 : 0;
|
{ on(InitScreenCallback.EVENT, this::injectIntoIngameMenu); }
|
||||||
VanillaGuiScreen.setup(gui).setLayout(new CustomLayout<GuiScreen>() {
|
private void injectIntoIngameMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||||
|
//#else
|
||||||
|
//$$ @SubscribeEvent
|
||||||
|
//$$ public void injectIntoIngameMenu(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||||
|
//$$ Screen guiScreen = getGui(event);
|
||||||
|
//#if MC>=11400
|
||||||
|
//$$ List<Widget> buttonList = MCVer.getButtonList(event);
|
||||||
|
//#else
|
||||||
|
//$$ List<net.minecraft.client.gui.GuiButton> buttonList = MCVer.getButtonList(event);
|
||||||
|
//#endif
|
||||||
|
//#endif
|
||||||
|
if (!(guiScreen instanceof GameMenuScreen)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Function<Integer, Integer> yPos =
|
||||||
|
MCVer.findButton(buttonList, "menu.returnToMenu", 1)
|
||||||
|
.map(Optional::of)
|
||||||
|
.orElse(MCVer.findButton(buttonList, "menu.disconnect", 1))
|
||||||
|
.<Function<Integer, Integer>>map(it -> (height) -> it.y)
|
||||||
|
.orElse((height) -> height / 4 + 120 - 16);
|
||||||
|
VanillaGuiScreen.setup(guiScreen).setLayout(new CustomLayout<de.johni0702.minecraft.gui.container.GuiScreen>() {
|
||||||
@Override
|
@Override
|
||||||
protected void layout(GuiScreen container, int width, int height) {
|
protected void layout(de.johni0702.minecraft.gui.container.GuiScreen container, int width, int height) {
|
||||||
pos(panel, width / 2 - 100, height / 4 + 128 + modMenuOffset);
|
pos(panel, width / 2 - 100, yPos.apply(height) + 16 + 8);
|
||||||
}
|
}
|
||||||
}).addElements(null, panel);
|
}).addElements(null, panel);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user