Update to MC 1.14 / Fabric
This commit is contained in:
@@ -10,7 +10,7 @@ import com.replaymod.online.gui.GuiReplayDownloading;
|
||||
import com.replaymod.online.gui.GuiSaveModifiedReplay;
|
||||
import com.replaymod.online.handler.GuiHandler;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replay.events.ReplayClosedCallback;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
@@ -18,15 +18,8 @@ import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//#if MC<11300
|
||||
//$$ import net.minecraftforge.common.config.Configuration;
|
||||
//#if MC>=10800
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
import java.io.File;
|
||||
@@ -87,14 +80,24 @@ public class ReplayModOnline implements Module {
|
||||
}
|
||||
|
||||
new GuiHandler(this).register();
|
||||
FML_BUS.register(this);
|
||||
ReplayClosedCallback.EVENT.register(replayHandler -> onReplayClosed());
|
||||
|
||||
// Initial login prompt
|
||||
if (!core.getSettingsRegistry().get(Setting.SKIP_LOGIN_PROMPT)) {
|
||||
if (!isLoggedIn()) {
|
||||
core.runLater(() -> {
|
||||
GuiScreen parent = GuiScreen.wrap(getMinecraft().currentScreen);
|
||||
new GuiLoginPrompt(apiClient, parent, parent, false).display();
|
||||
core.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//#if MC>=11400
|
||||
//$$ if (getMinecraft().overlay != null) {
|
||||
//$$ // delay until after resources have been loaded
|
||||
//$$ core.runLater(this);
|
||||
//$$ return;
|
||||
//$$ }
|
||||
//#endif
|
||||
GuiScreen parent = GuiScreen.wrap(getMinecraft().currentScreen);
|
||||
new GuiLoginPrompt(apiClient, parent, parent, false).display();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -161,8 +164,7 @@ public class ReplayModOnline implements Module {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onReplayClosed(ReplayCloseEvent.Post event) {
|
||||
private void onReplayClosed() {
|
||||
if (currentReplayOutputFile != null) {
|
||||
if (currentReplayOutputFile.exists()) { // Replay was modified, ask user for new name
|
||||
new GuiSaveModifiedReplay(currentReplayOutputFile).display();
|
||||
|
||||
@@ -10,7 +10,8 @@ public enum MinecraftVersion {
|
||||
MC_1_12("Minecraft 1.12", "1.12"),
|
||||
MC_1_12_1("Minecraft 1.12.1", "1.12.1"),
|
||||
MC_1_12_2("Minecraft 1.12.2", "1.12.2"),
|
||||
MC_1_13_2("Minecraft 1.13.2", "1.13.2");
|
||||
MC_1_13_2("Minecraft 1.13.2", "1.13.2"),
|
||||
MC_1_14("Minecraft 1.14", "1.14");
|
||||
|
||||
private String niceName, apiName;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
@@ -44,12 +45,7 @@ public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
|
||||
switch (apiClient.login(username.getText(), password.getText())) {
|
||||
case SUCCESS:
|
||||
statusLabel.setText("");
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
successScreen.display();
|
||||
}
|
||||
});
|
||||
ReplayMod.instance.runLater(successScreen::display);
|
||||
break;
|
||||
case INVALID_DATA:
|
||||
statusLabel.setI18nText("replaymod.gui.login.incorrect");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
@@ -82,12 +83,7 @@ public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
|
||||
String password = passwordInput.getText();
|
||||
apiClient.register(username, mail, password);
|
||||
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
parent.getSuccessScreen().display();
|
||||
}
|
||||
});
|
||||
ReplayMod.instance.runLater(parent.getSuccessScreen()::display);
|
||||
} catch (ApiException ae) {
|
||||
statusLabel.setText(ae.getLocalizedMessage());
|
||||
} catch (AuthenticationException aue) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.google.common.base.Supplier;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
@@ -40,6 +39,7 @@ import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
@@ -417,9 +417,9 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
this.downloaded = downloaded;
|
||||
ReplayMetaData metaData = fileInfo.getMetadata();
|
||||
|
||||
name.setText(ChatFormatting.UNDERLINE + Utils.fileNameToReplayName(fileInfo.getName()));
|
||||
name.setText(TextFormatting.UNDERLINE + Utils.fileNameToReplayName(fileInfo.getName()));
|
||||
author.setI18nText("replaymod.gui.center.author",
|
||||
"" + ChatFormatting.GRAY + ChatFormatting.ITALIC, fileInfo.getOwner());
|
||||
"" + TextFormatting.GRAY + TextFormatting.ITALIC, fileInfo.getOwner());
|
||||
if (StringUtils.isEmpty(metaData.getServerName())) {
|
||||
server.setI18nText("replaymod.gui.iphidden").setColor(Colors.DARK_RED);
|
||||
} else {
|
||||
@@ -443,7 +443,7 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
favorites.setText("⭑" + fileInfo.getFavorites());
|
||||
likes.setText("⬆" + fileInfo.getRatings().getPositive());
|
||||
dislikes.setText("⬇" + fileInfo.getRatings().getNegative());
|
||||
category.setText(ChatFormatting.ITALIC + Optional.fromNullable(Category.fromId(fileInfo.getCategory()))
|
||||
category.setText(TextFormatting.ITALIC + Optional.fromNullable(Category.fromId(fileInfo.getCategory()))
|
||||
.or(Category.MISCELLANEOUS).toNiceString());
|
||||
addElements(null, durationPanel, downloadsPanel);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.replaymod.online.gui;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.api.ApiClient;
|
||||
import com.replaymod.online.api.ApiException;
|
||||
@@ -10,6 +10,7 @@ import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -33,7 +34,7 @@ public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading
|
||||
this.apiClient = mod.getApiClient();
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.viewer.download.title"));
|
||||
final GuiLabel subTitle = new GuiLabel(this).setI18nText("replaymod.gui.viewer.download.message",
|
||||
ChatFormatting.UNDERLINE + name + ChatFormatting.RESET);
|
||||
TextFormatting.UNDERLINE + name + TextFormatting.RESET);
|
||||
setLayout(new CustomLayout<GuiReplayDownloading>() {
|
||||
@Override
|
||||
protected void layout(GuiReplayDownloading container, int width, int height) {
|
||||
@@ -53,14 +54,11 @@ public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading
|
||||
try {
|
||||
apiClient.downloadFile(replayId, replayFile, progressBar::setProgress);
|
||||
if (replayFile.exists()) {
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mod.startReplay(replayId, null, null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ReplayMod.instance.runLater(() -> {
|
||||
try {
|
||||
mod.startReplay(replayId, null, null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,35 +1,33 @@
|
||||
package com.replaymod.online.handler;
|
||||
|
||||
import de.johni0702.minecraft.gui.utils.EventRegistrations;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.online.gui.GuiLoginPrompt;
|
||||
import com.replaymod.online.gui.GuiReplayCenter;
|
||||
import com.replaymod.online.gui.GuiUploadReplay;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import com.replaymod.replay.handler.GuiHandler.InjectedButton;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
//#if MC>=11400
|
||||
//$$ import de.johni0702.minecraft.gui.versions.callbacks.InitScreenCallback;
|
||||
//$$ import net.minecraft.client.gui.Screen;
|
||||
//$$ import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
//$$ import java.util.List;
|
||||
//#else
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import java.util.ArrayList;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class GuiHandler {
|
||||
public class GuiHandler extends EventRegistrations {
|
||||
private static final int BUTTON_REPLAY_CENTER = 17890236;
|
||||
|
||||
private final ReplayModOnline mod;
|
||||
@@ -38,42 +36,46 @@ public class GuiHandler {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FML_BUS.register(this);
|
||||
FORGE_BUS.register(this);
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
//$$ { on(InitScreenCallback.EVENT, this::injectIntoMainMenu); }
|
||||
//$$ public void injectIntoMainMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
@SubscribeEvent
|
||||
public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
if (!(getGui(event) instanceof GuiMainMenu)) {
|
||||
final net.minecraft.client.gui.GuiScreen guiScreen = getGui(event);
|
||||
//#endif
|
||||
if (!(guiScreen instanceof GuiMainMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiButton button = new GuiButton(
|
||||
GuiButton button = new InjectedButton(
|
||||
guiScreen,
|
||||
BUTTON_REPLAY_CENTER,
|
||||
getGui(event).width / 2 + 2,
|
||||
getGui(event).height / 4 + 10 + 4 * 24,
|
||||
I18n.format("replaymod.gui.replaycenter")
|
||||
) {
|
||||
//#if MC>=11300
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
onButton(new GuiScreenEvent.ActionPerformedEvent.Pre(getGui(event), this, new ArrayList<>()));
|
||||
}
|
||||
//#endif
|
||||
};
|
||||
button.width = button.width / 2 - 2;
|
||||
addButton(event, button);
|
||||
guiScreen.width / 2 + 2,
|
||||
guiScreen.height / 4 + 10 + 4 * 24,
|
||||
98,
|
||||
20,
|
||||
I18n.format("replaymod.gui.replaycenter"),
|
||||
this::onButton
|
||||
);
|
||||
addButton(guiScreen, button);
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
//$$ { on(InitScreenCallback.EVENT, this::injectIntoReplayViewer); }
|
||||
//$$ public void injectIntoReplayViewer(Screen vanillaGuiScreen, List<AbstractButtonWidget> buttonList) {
|
||||
//#else
|
||||
@SubscribeEvent
|
||||
public void injectIntoReplayViewer(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(getGui(event));
|
||||
net.minecraft.client.gui.GuiScreen vanillaGuiScreen = getGui(event);
|
||||
//#endif
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(vanillaGuiScreen);
|
||||
if (!(guiScreen instanceof GuiReplayViewer)) {
|
||||
return;
|
||||
}
|
||||
final GuiReplayViewer replayViewer = (GuiReplayViewer) guiScreen;
|
||||
// Inject Upload button
|
||||
if (!replayViewer.uploadButton.getChildren().isEmpty()) return;
|
||||
replayViewer.replaySpecificButtons.add(new de.johni0702.minecraft.gui.element.GuiButton(replayViewer.uploadButton).onClick(() -> {
|
||||
File replayFile = replayViewer.list.getSelected().file;
|
||||
GuiUploadReplay uploadGui = new GuiUploadReplay(replayViewer, mod, replayFile);
|
||||
@@ -85,17 +87,24 @@ public class GuiHandler {
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.upload").setDisabled());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if(!getButton(event).enabled) return;
|
||||
//#if MC>=11300
|
||||
private void onButton(InjectedButton button) {
|
||||
net.minecraft.client.gui.GuiScreen guiScreen = button.guiScreen;
|
||||
//#else
|
||||
//$$ @SubscribeEvent
|
||||
//$$ public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
//$$ net.minecraft.client.gui.GuiScreen guiScreen = getGui(event);
|
||||
//$$ GuiButton button = getButton(event);
|
||||
//#endif
|
||||
if(!button.enabled) return;
|
||||
|
||||
if (getGui(event) instanceof GuiMainMenu) {
|
||||
if (getButton(event).id == BUTTON_REPLAY_CENTER) {
|
||||
if (guiScreen instanceof GuiMainMenu) {
|
||||
if (button.id == BUTTON_REPLAY_CENTER) {
|
||||
GuiReplayCenter replayCenter = new GuiReplayCenter(mod);
|
||||
if (mod.isLoggedIn()) {
|
||||
replayCenter.display();
|
||||
} else {
|
||||
new GuiLoginPrompt(mod.getApiClient(), GuiScreen.wrap(getGui(event)), replayCenter, true).display();
|
||||
new GuiLoginPrompt(mod.getApiClient(), GuiScreen.wrap(guiScreen), replayCenter, true).display();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user