Re-work Replay Editor UI
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
package com.replaymod.editor.handler;
|
||||
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
import com.replaymod.editor.gui.GuiReplayEditor;
|
||||
import com.replaymod.editor.gui.GuiEditReplay;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import java.util.ArrayList;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
@@ -19,48 +21,42 @@ import java.util.ArrayList;
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class GuiHandler {
|
||||
private static final int BUTTON_REPLAY_EDITOR = 17890237;
|
||||
|
||||
private final ReplayModEditor mod;
|
||||
|
||||
public GuiHandler(ReplayModEditor mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FML_BUS.register(this);
|
||||
FORGE_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
if (!(getGui(event) instanceof GuiMainMenu)) {
|
||||
public void injectIntoReplayViewer(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(getGui(event));
|
||||
if (!(guiScreen instanceof GuiReplayViewer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_EDITOR, getGui(event).width / 2 + 2,
|
||||
getGui(event).height / 4 + 10 + 3 * 24, I18n.format("replaymod.gui.replayeditor")) {
|
||||
//#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);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if(!getButton(event).enabled) return;
|
||||
|
||||
if (getGui(event) instanceof GuiMainMenu) {
|
||||
if (getButton(event).id == BUTTON_REPLAY_EDITOR) {
|
||||
new GuiReplayEditor(GuiScreen.wrap(getGui(event)), mod.getCore()).display();
|
||||
final GuiReplayViewer replayViewer = (GuiReplayViewer) guiScreen;
|
||||
// Inject Edit button
|
||||
for (GuiElement element : replayViewer.replayButtonPanel.getChildren()) {
|
||||
if (element instanceof GuiPanel && (((GuiPanel) element).getChildren().isEmpty())) {
|
||||
new de.johni0702.minecraft.gui.element.GuiButton((GuiPanel) element).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
new GuiEditReplay(replayViewer, replayViewer.list.getSelected().file.toPath()) {
|
||||
@Override
|
||||
protected void close() {
|
||||
super.close();
|
||||
replayViewer.list.load();
|
||||
}
|
||||
}.open();
|
||||
} catch (IOException e) {
|
||||
Utils.error(ReplayModEditor.LOGGER, replayViewer, CrashReport.makeCrashReport(e, "Opening replay editor"), () -> {});
|
||||
}
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.replayeditor").setDisabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user