mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Improve BugReportDialog by making it a screen
This commit is contained in:
@@ -9,60 +9,100 @@ import forge.Graphics;
|
|||||||
import forge.assets.FSkinColor;
|
import forge.assets.FSkinColor;
|
||||||
import forge.assets.FSkinFont;
|
import forge.assets.FSkinFont;
|
||||||
import forge.assets.FSkinColor.Colors;
|
import forge.assets.FSkinColor.Colors;
|
||||||
|
import forge.screens.FScreen;
|
||||||
|
import forge.toolbox.FButton;
|
||||||
|
import forge.toolbox.FEvent;
|
||||||
|
import forge.toolbox.FEvent.FEventHandler;
|
||||||
import forge.toolbox.FOptionPane;
|
import forge.toolbox.FOptionPane;
|
||||||
import forge.toolbox.FScrollPane;
|
import forge.toolbox.FScrollPane;
|
||||||
|
import forge.toolbox.FTextArea;
|
||||||
|
import forge.util.Callback;
|
||||||
import forge.util.Utils;
|
import forge.util.Utils;
|
||||||
|
|
||||||
public class BugReportDialog extends FOptionPane {
|
public class BugReportDialog extends FScreen { //use screen rather than dialog so screen with bug isn't rendered
|
||||||
private static boolean dialogShown;
|
private static final float PADDING = Utils.scaleMin(5);
|
||||||
|
private static boolean isOpen;
|
||||||
|
|
||||||
public static void show(String title, String text, boolean showExitAppBtn) {
|
public static void show(String title, String text, boolean showExitAppBtn) {
|
||||||
if (dialogShown || Forge.getCurrentScreen() == null) { return; } //don't allow showing if Forge not finished initializing yet
|
if (isOpen || Forge.getCurrentScreen() == null) { return; } //don't allow showing if Forge not finished initializing yet
|
||||||
|
|
||||||
dialogShown = true;
|
isOpen = true;
|
||||||
BugReportDialog dialog = new BugReportDialog(title, text, showExitAppBtn);
|
Forge.openScreen(new BugReportDialog(title, text, showExitAppBtn));
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String text;
|
private final FTextArea lblHeader = add(new FTextArea(BugReporter.HELP_TEXT));
|
||||||
|
private final TemplateView tvDetails;
|
||||||
|
private final FButton btnReport = add(new FButton(BugReporter.REPORT));
|
||||||
|
private final FButton btnSave = add(new FButton(BugReporter.SAVE));
|
||||||
|
private final FButton btnContinue = add(new FButton(BugReporter.CONTINUE));
|
||||||
|
private final FButton btnExit = add(new FButton(BugReporter.EXIT));
|
||||||
|
|
||||||
private BugReportDialog(String title, String text0, boolean showExitAppBtn) {
|
private BugReportDialog(String title, String text0, boolean showExitAppBtn) {
|
||||||
super(BugReporter.HELP_TEXT + "\n\n" + BugReporter.HELP_URL_LABEL + " " + BugReporter.HELP_URL + ".",
|
super(title);
|
||||||
title, null, new TemplateView(text0),
|
lblHeader.setFont(FSkinFont.get(12));
|
||||||
getOptions(showExitAppBtn), 0, null);
|
tvDetails = add(new TemplateView(text0));
|
||||||
text = text0;
|
btnReport.setCommand(new FEventHandler() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(FEvent e) {
|
||||||
|
BugReporter.copyAndGoToForums(tvDetails.text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnSave.setCommand(new FEventHandler() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(FEvent e) {
|
||||||
|
BugReporter.saveToFile(tvDetails.text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnContinue.setCommand(new FEventHandler() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(FEvent e) {
|
||||||
|
Forge.back();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (showExitAppBtn) {
|
||||||
|
btnExit.setCommand(new FEventHandler() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(FEvent e) {
|
||||||
|
Gdx.app.exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
btnExit.setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResult(final int option) {
|
public void onClose(Callback<Boolean> canCloseCallback) {
|
||||||
switch (option) {
|
super.onClose(canCloseCallback);
|
||||||
case 0:
|
isOpen = false;
|
||||||
BugReporter.copyAndGoToForums(text);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
BugReporter.saveToFile(text);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
hide();
|
|
||||||
dialogShown = false;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
hide();
|
|
||||||
Gdx.app.exit();
|
|
||||||
dialogShown = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getOptions(boolean showExitAppBtn) {
|
@Override
|
||||||
String[] options = new String[showExitAppBtn ? 4 : 3];
|
protected void doLayout(float startY, float width, float height) {
|
||||||
options[0] = BugReporter.REPORT;
|
float x = PADDING;
|
||||||
options[1] = BugReporter.SAVE;
|
float y = startY + PADDING;
|
||||||
options[2] = BugReporter.CONTINUE;
|
float w = width - 2 * PADDING;
|
||||||
if (showExitAppBtn) {
|
|
||||||
options[3] = BugReporter.EXIT;
|
lblHeader.setBounds(x, y, w, lblHeader.getPreferredHeight(w));
|
||||||
|
y += lblHeader.getHeight() + PADDING;
|
||||||
|
|
||||||
|
float buttonWidth = (w - PADDING) / 2;
|
||||||
|
float buttonHeight = FOptionPane.BUTTON_HEIGHT;
|
||||||
|
|
||||||
|
tvDetails.setBounds(x, y, w, height - 2 * buttonHeight - 3 * PADDING - y);
|
||||||
|
y += tvDetails.getHeight() + PADDING;
|
||||||
|
|
||||||
|
btnReport.setBounds(x, y, buttonWidth, buttonHeight);
|
||||||
|
btnSave.setBounds(x + buttonWidth + PADDING, y, buttonWidth, buttonHeight);
|
||||||
|
y += buttonHeight + PADDING;
|
||||||
|
if (btnExit.isVisible()) {
|
||||||
|
btnContinue.setBounds(x, y, buttonWidth, buttonHeight);
|
||||||
|
btnExit.setBounds(x + buttonWidth + PADDING, y, buttonWidth, buttonHeight);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
btnContinue.setBounds(x, y, w, buttonHeight);
|
||||||
}
|
}
|
||||||
return options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TemplateView extends FScrollPane {
|
private static class TemplateView extends FScrollPane {
|
||||||
|
|||||||
Reference in New Issue
Block a user