Add "Edit" button to replay viewer gui
This commit is contained in:
@@ -5,9 +5,8 @@ import com.replaymod.editor.ReplayModEditor;
|
||||
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 de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
@@ -39,25 +38,18 @@ public class GuiHandler {
|
||||
}
|
||||
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() {
|
||||
replayViewer.replaySpecificButtons.add(new GuiButton(replayViewer.editorButton).onClick(() -> {
|
||||
try {
|
||||
new GuiEditReplay(replayViewer, replayViewer.list.getSelected().file.toPath()) {
|
||||
@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"), () -> {});
|
||||
}
|
||||
protected void close() {
|
||||
super.close();
|
||||
replayViewer.list.load();
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.replayeditor").setDisabled();
|
||||
}.open();
|
||||
} catch (IOException e) {
|
||||
Utils.error(ReplayModEditor.LOGGER, replayViewer, CrashReport.makeCrashReport(e, "Opening replay editor"), () -> {});
|
||||
}
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.edit").setDisabled());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,22 +74,15 @@ public class GuiHandler {
|
||||
}
|
||||
final GuiReplayViewer replayViewer = (GuiReplayViewer) guiScreen;
|
||||
// Inject Upload 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() {
|
||||
File replayFile = replayViewer.list.getSelected().file;
|
||||
GuiUploadReplay uploadGui = new GuiUploadReplay(replayViewer, mod, replayFile);
|
||||
if (mod.isLoggedIn()) {
|
||||
uploadGui.display();
|
||||
} else {
|
||||
new GuiLoginPrompt(mod.getApiClient(), replayViewer, uploadGui, true);
|
||||
}
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.upload").setDisabled();
|
||||
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);
|
||||
if (mod.isLoggedIn()) {
|
||||
uploadGui.display();
|
||||
} else {
|
||||
new GuiLoginPrompt(mod.getApiClient(), replayViewer, uploadGui, true);
|
||||
}
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.upload").setDisabled());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -55,7 +55,10 @@ import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.replaymod.replay.ReplayModReplay.LOGGER;
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
@@ -66,7 +69,7 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
public final GuiReplayList list = new GuiReplayList(this).onSelectionChanged(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
replayButtonPanel.forEach(IGuiButton.class).setEnabled(list.getSelected() != null);
|
||||
replaySpecificButtons.forEach(b -> b.setEnabled(list.getSelected() != null));
|
||||
if (list.getSelected() != null && list.getSelected().incompatible) {
|
||||
loadButton.setDisabled();
|
||||
}
|
||||
@@ -88,7 +91,7 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.load").setDisabled();
|
||||
}).setSize(150, 20).setI18nLabel("replaymod.gui.load").setDisabled();
|
||||
|
||||
public final GuiButton folderButton = new GuiButton().onClick(new Runnable() {
|
||||
@Override
|
||||
@@ -199,13 +202,17 @@ public class GuiReplayViewer extends GuiScreen {
|
||||
}
|
||||
}).setSize(73, 20).setI18nLabel("replaymod.gui.cancel");
|
||||
|
||||
public final GuiPanel replayButtonPanel = new GuiPanel().setLayout(new GridLayout().setSpacingX(5).setSpacingY(5)
|
||||
.setColumns(2)).addElements(null, loadButton, new GuiPanel() /* Upload */, renameButton, deleteButton);
|
||||
public final GuiPanel generalButtonPanel = new GuiPanel().setLayout(new VerticalLayout().setSpacing(5))
|
||||
.addElements(null, folderButton, new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, settingsButton, cancelButton));
|
||||
public final GuiPanel buttonPanel = new GuiPanel(this).setLayout(new HorizontalLayout().setSpacing(6))
|
||||
.addElements(null, replayButtonPanel, generalButtonPanel);
|
||||
public final List<GuiButton> replaySpecificButtons = new ArrayList<>();
|
||||
{ replaySpecificButtons.addAll(Arrays.asList(loadButton, renameButton, deleteButton)); }
|
||||
public final GuiPanel uploadButton = new GuiPanel();
|
||||
public final GuiPanel editorButton = new GuiPanel();
|
||||
|
||||
public final GuiPanel upperButtonPanel = new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, loadButton, editorButton, uploadButton);
|
||||
public final GuiPanel lowerButtonPanel = new GuiPanel().setLayout(new HorizontalLayout().setSpacing(5))
|
||||
.addElements(null, renameButton, deleteButton, settingsButton, cancelButton);
|
||||
public final GuiPanel buttonPanel = new GuiPanel(this).setLayout(new VerticalLayout().setSpacing(5))
|
||||
.addElements(null, upperButtonPanel, lowerButtonPanel);
|
||||
|
||||
public GuiReplayViewer(ReplayModReplay mod) {
|
||||
this.mod = mod;
|
||||
|
||||
Reference in New Issue
Block a user