mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Fix load conquests screen
Prevent crash if you pause during startup
This commit is contained in:
@@ -48,7 +48,7 @@ public class ConquestMapScreen extends LaunchScreen {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
setHeaderCaption(FModel.getConquest().getName() + "\n" + FModel.getConquest().getCurrentPlane());
|
||||
setHeaderCaption(FModel.getConquest().getName() + " - " + FModel.getConquest().getCurrentPlane());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.FThreads;
|
||||
@@ -31,6 +32,7 @@ import forge.screens.settings.SettingsScreen;
|
||||
import forge.toolbox.FButton;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FList;
|
||||
import forge.toolbox.FTextArea;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.util.ThreadUtil;
|
||||
import forge.util.Utils;
|
||||
@@ -38,8 +40,10 @@ import forge.util.gui.SOptionPane;
|
||||
|
||||
public class LoadConquestScreen extends FScreen {
|
||||
private static final float PADDING = Utils.AVG_FINGER_HEIGHT * 0.1f;
|
||||
private static final FSkinColor OLD_CONQUESTS_BACK_COLOR = FSkinColor.get(Colors.CLR_INACTIVE).getContrastColor(20);
|
||||
private static final FSkinColor SEL_COLOR = FSkinColor.get(Colors.CLR_ACTIVE);
|
||||
|
||||
private final FTextArea lblOldConquests = add(new FTextArea(false, "Loading Existing Conquests..."));
|
||||
private final ConquestFileLister lstConquests = add(new ConquestFileLister());
|
||||
private final FButton btnNewConquest = add(new FButton("New"));
|
||||
private final FButton btnRenameConquest = add(new FButton("Rename"));
|
||||
@@ -48,6 +52,9 @@ public class LoadConquestScreen extends FScreen {
|
||||
public LoadConquestScreen() {
|
||||
super("Load Planar Conquest");
|
||||
|
||||
lblOldConquests.setFont(FSkinFont.get(12));
|
||||
lblOldConquests.setAlignment(HAlignment.CENTER);
|
||||
|
||||
btnNewConquest.setFont(FSkinFont.get(16));
|
||||
btnNewConquest.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
@@ -110,10 +117,25 @@ public class LoadConquestScreen extends FScreen {
|
||||
else {
|
||||
qc.load(null);
|
||||
}
|
||||
Gdx.app.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lblOldConquests.setText("Old conquest data? Put into \""
|
||||
+ ForgeConstants.CONQUEST_SAVE_DIR.replace('\\', '/') + "\" and restart Forge.");
|
||||
revalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
super.drawBackground(g);
|
||||
float y = getHeader().getBottom();
|
||||
g.fillRect(OLD_CONQUESTS_BACK_COLOR, 0, y, getWidth(), lstConquests.getTop() - y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawOverlay(Graphics g) {
|
||||
float y = lstConquests.getTop();
|
||||
@@ -126,6 +148,8 @@ public class LoadConquestScreen extends FScreen {
|
||||
float buttonHeight = btnNewConquest.getAutoSizeBounds().height * 1.2f;
|
||||
|
||||
float y = startY + 2 * PADDING;
|
||||
lblOldConquests.setBounds(0, y, width, lblOldConquests.getPreferredHeight(width));
|
||||
y += lblOldConquests.getHeight() + PADDING;
|
||||
lstConquests.setBounds(0, y, width, height - y - buttonHeight - 2 * PADDING);
|
||||
y += lstConquests.getHeight() + PADDING;
|
||||
|
||||
@@ -152,14 +176,14 @@ public class LoadConquestScreen extends FScreen {
|
||||
String questName;
|
||||
String oldConquestName = quest.getName();
|
||||
while (true) {
|
||||
questName = SOptionPane.showInputDialog("Enter new name for quest:", "Rename Conquest", null, oldConquestName);
|
||||
questName = SOptionPane.showInputDialog("Enter new name for conquest:", "Rename Conquest", null, oldConquestName);
|
||||
if (questName == null) { return; }
|
||||
|
||||
questName = QuestUtil.cleanString(questName);
|
||||
if (questName.equals(oldConquestName)) { return; } //quit if chose same name
|
||||
|
||||
if (questName.isEmpty()) {
|
||||
SOptionPane.showMessageDialog("Please specify a quest name.");
|
||||
SOptionPane.showMessageDialog("Please specify a conquest name.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -171,7 +195,7 @@ public class LoadConquestScreen extends FScreen {
|
||||
}
|
||||
}
|
||||
if (exists) {
|
||||
SOptionPane.showMessageDialog("A quest already exists with that name. Please pick another quest name.");
|
||||
SOptionPane.showMessageDialog("A conquest already exists with that name. Please pick another quest name.");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -251,7 +275,6 @@ public class LoadConquestScreen extends FScreen {
|
||||
float cardsWidth = font.getBounds(cards).width + iconSize + SettingsScreen.SETTING_PADDING;
|
||||
g.drawImage(FSkinImage.HAND, x + w - cardsWidth + iconOffset, y - SettingsScreen.SETTING_PADDING, iconSize, iconSize);
|
||||
g.drawText(cards, font, SettingsScreen.DESC_COLOR, x + w - cardsWidth + iconSize + SettingsScreen.SETTING_PADDING, y, w, h, false, HAlignment.LEFT, false);
|
||||
g.drawImage(FSkinImage.QUEST_COINSTACK, x + w + iconOffset, y - SettingsScreen.SETTING_PADDING, iconSize, iconSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.player.LobbyPlayerHuman;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.quest.QuestController;
|
||||
import forge.sound.MusicPlaylist;
|
||||
@@ -396,9 +397,12 @@ public class MatchUtil {
|
||||
}
|
||||
|
||||
public static void pause() {
|
||||
ForgePreferences prefs = FModel.getPreferences();
|
||||
if (prefs == null) { return; } //do nothing if prefs haven't been initialized yet
|
||||
|
||||
SoundSystem.instance.pause();
|
||||
//pause playback if needed
|
||||
if (FModel.getPreferences().getPrefBoolean(FPref.UI_PAUSE_WHILE_MINIMIZED)) {
|
||||
if (prefs.getPrefBoolean(FPref.UI_PAUSE_WHILE_MINIMIZED)) {
|
||||
InputQueue inputQueue = getInputQueue();
|
||||
if (inputQueue != null && inputQueue.getInput() instanceof InputPlaybackControl) {
|
||||
((InputPlaybackControl) inputQueue.getInput()).pause();
|
||||
|
||||
Reference in New Issue
Block a user