Skip to content

Commit

Permalink
Merge pull request #6440 from kevlahnota/master2
Browse files Browse the repository at this point in the history
refactor mobile ImageCache, ImageView, FChoiceList
  • Loading branch information
kevlahnota authored Oct 27, 2024
2 parents 2169263 + 89bc9c1 commit 16b0bd2
Show file tree
Hide file tree
Showing 42 changed files with 681 additions and 669 deletions.
4 changes: 4 additions & 0 deletions forge-game/src/main/java/forge/game/keyword/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ public static Set<Keyword> setValueOf(String value) {
return result;
}

public String getReminderText() {
return reminderText;
}

public boolean isMultipleRedundant() {
return isMultipleRedundant;
}
Expand Down
58 changes: 34 additions & 24 deletions forge-gui-desktop/src/main/java/forge/control/FControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import forge.screens.deckeditor.CDeckEditorUI;
import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin;
import forge.util.BuildInfo;
import forge.util.FileUtil;
import forge.util.Localizer;
import forge.util.RestartUtil;
Expand All @@ -86,14 +87,22 @@ public enum FControl implements KeyEventDispatcher {
private boolean altKeyLastDown;
private CloseAction closeAction;
private final List<HostedMatch> currentMatches = Lists.newArrayList();
private String snapsVersion = "";
private String snapsVersion = "", currentVersion = "";
private boolean isSnapshot;
private Localizer localizer;

public enum CloseAction {
NONE,
CLOSE_SCREEN,
EXIT_FORGE
}

public Localizer getLocalizer() {
if (localizer == null)
localizer = Localizer.getInstance();
return localizer;
}

private boolean hasCurrentMatches() {
cleanMatches();
return !currentMatches.isEmpty();
Expand Down Expand Up @@ -126,16 +135,15 @@ private void cleanMatches() {
* instantiated separately by each screen's top level view class.
*/
FControl() {
final Localizer localizer = Localizer.getInstance();
Singletons.getView().getFrame().addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
switch (closeAction) {
case NONE: //prompt user for close action if not previously specified
final List<String> options = ImmutableList.of(localizer.getMessage("lblCloseScreen"), localizer.getMessage("lblExitForge"), localizer.getMessage("lblCancel"));
final List<String> options = ImmutableList.of(getLocalizer().getMessage("lblCloseScreen"), getLocalizer().getMessage("lblExitForge"), getLocalizer().getMessage("lblCancel"));
final int reply = FOptionPane.showOptionDialog(
localizer.getMessage("txCloseAction1") + "\n\n" + localizer.getMessage("txCloseAction2"),
localizer.getMessage("titCloseAction"),
getLocalizer().getMessage("txCloseAction1") + "\n\n" + getLocalizer().getMessage("txCloseAction2"),
getLocalizer().getMessage("titCloseAction"),
FOptionPane.INFORMATION_ICON,
options,
2);
Expand Down Expand Up @@ -178,14 +186,13 @@ public void setCloseAction(final CloseAction closeAction0) {
}

public boolean canExitForge(final boolean forRestart) {
final Localizer localizer = Localizer.getInstance();
final String action = (forRestart ? localizer.getMessage("lblRestart") : localizer.getMessage("lblExit"));
String userPrompt =(forRestart ? localizer.getMessage("lblAreYouSureYouWishRestartForge") : localizer.getMessage("lblAreYouSureYouWishExitForge"));
final String action = (forRestart ? getLocalizer().getMessage("lblRestart") : getLocalizer().getMessage("lblExit"));
String userPrompt =(forRestart ? getLocalizer().getMessage("lblAreYouSureYouWishRestartForge") : getLocalizer().getMessage("lblAreYouSureYouWishExitForge"));
final boolean hasCurrentMatches = hasCurrentMatches();
if (hasCurrentMatches) {
userPrompt = localizer.getMessage("lblOneOrMoreGamesActive") + ". " + userPrompt;
userPrompt = getLocalizer().getMessage("lblOneOrMoreGamesActive") + ". " + userPrompt;
}
if (!FOptionPane.showConfirmDialog(userPrompt, action + " Forge", action, localizer.getMessage("lblCancel"), !hasCurrentMatches)) { //default Yes if no game active
if (!FOptionPane.showConfirmDialog(userPrompt, action + " Forge", action, getLocalizer().getMessage("lblCancel"), !hasCurrentMatches)) { //default Yes if no game active
return false;
}
return CDeckEditorUI.SINGLETON_INSTANCE.canSwitchAway(true);
Expand Down Expand Up @@ -214,27 +221,29 @@ public boolean exitForge() {

/** After view and model have been initialized, control can start.*/
public void initialize() {
final ForgePreferences prefs = FModel.getPreferences();
currentVersion = BuildInfo.getVersionString();
isSnapshot = currentVersion.contains("SNAPSHOT");
//get version string
try {
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/version.txt");
snapsVersion = FileUtil.readFileToString(url);
if (isSnapshot && prefs.getPrefBoolean(FPref.CHECK_SNAPSHOT_AT_STARTUP)) {
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/version.txt");
snapsVersion = FileUtil.readFileToString(url);
}

} catch (Exception e) {}
} catch (Exception ignored) {}
// Preloads skin components (using progress bar).
FSkin.loadFull(true);

display = FView.SINGLETON_INSTANCE.getLpnDocument();

final ForgePreferences prefs = FModel.getPreferences();

//set ExperimentalNetworkOption from preference
boolean propertyConfig = prefs != null && prefs.getPrefBoolean(ForgePreferences.FPref.UI_NETPLAY_COMPAT);
GuiBase.enablePropertyConfig(propertyConfig);

closeAction = CloseAction.valueOf(prefs.getPref(FPref.UI_CLOSE_ACTION));

final Localizer localizer = Localizer.getInstance();
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(localizer.getMessage("lblLoadingQuest"));
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(getLocalizer().getMessage("lblLoadingQuest"));
// Preload quest data if present
final File dirQuests = new File(ForgeConstants.QUEST_SAVE_DIR);
final String questname = FModel.getQuestPreferences().getPref(QPref.CURRENT_QUEST);
Expand Down Expand Up @@ -272,14 +281,16 @@ public void componentMoved(final ComponentEvent e) {
FView.SINGLETON_INSTANCE.getLpnDocument().addComponentListener(SResizingUtil.getWindowResizeListener());

setGlobalKeyboardHandler();
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(localizer.getMessage("lblOpeningMainWindow"));
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(getLocalizer().getMessage("lblOpeningMainWindow"));
SwingUtilities.invokeLater(() -> Singletons.getView().initialize());
}
public String compareVersion(String currentVersion) {
if (currentVersion.isEmpty() || snapsVersion.isEmpty()
|| !currentVersion.contains("SNAPSHOT") || currentVersion.equalsIgnoreCase(snapsVersion))
public boolean isSnapshot() {
return isSnapshot;
}
public String getSnapshotNotification() {
if (!isSnapshot || snapsVersion.isEmpty() || currentVersion.equalsIgnoreCase(snapsVersion))
return "";
return "NEW SNAPSHOT AVAILABLE!!!";
return getLocalizer().getMessage("lblNewSnapshotVersion", snapsVersion);
}

private void setGlobalKeyboardHandler() {
Expand Down Expand Up @@ -332,8 +343,7 @@ public boolean setCurrentScreen(final FScreen screen, final boolean previousScre
try {
SLayoutIO.loadLayout(null);
} catch (final InvalidLayoutFileException ex) {
final Localizer localizer = Localizer.getInstance();
SOptionPane.showMessageDialog(String.format(localizer.getMessage("lblerrLoadingLayoutFile"), screen.getTabCaption()), "Warning!");
SOptionPane.showMessageDialog(String.format(getLocalizer().getMessage("lblerrLoadingLayoutFile"), screen.getTabCaption()), "Warning!");
if (screen.deleteLayoutFile()) {
SLayoutIO.loadLayout(null); //try again
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void initialize() {
lstControls.add(Pair.of(view.getCbTimedTargOverlay(), FPref.UI_TIMED_TARGETING_OVERLAY_UPDATES));
lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU));
lstControls.add(Pair.of(view.getCbUseSentry(), FPref.USE_SENTRY));
lstControls.add(Pair.of(view.getCbCheckSnapshot(), FPref.CHECK_SNAPSHOT_AT_STARTUP));
lstControls.add(Pair.of(view.getCbPromptFreeBlocks(), FPref.MATCHPREF_PROMPT_FREE_BLOCKS));
lstControls.add(Pair.of(view.getCbPauseWhileMinimized(), FPref.UI_PAUSE_WHILE_MINIMIZED));
lstControls.add(Pair.of(view.getCbWorkshopSyntax(), FPref.DEV_WORKSHOP_SYNTAX));
Expand Down Expand Up @@ -192,14 +193,12 @@ public void initialize() {

view.getBtnTokenPreviewer().setCommand((UiCommand) CSubmenuPreferences.this::openTokenPreviewer);

view.getBtnResetJavaFutureCompatibilityWarnings().setCommand((UiCommand) () -> {
prefs.setPref(FPref.DISABLE_DISPLAY_JAVA_8_UPDATE_WARNING, false);
view.getBtnContentDirectoryUI().setCommand((UiCommand) CSubmenuPreferences.this::openContentDirectory);
view.getCbCheckSnapshot().addItemListener(e -> {
Singletons.getView().getNavigationBar().setUpdaterVisibility();
prefs.save();
FOptionPane.showMessageDialog(localizer.getMessage("CompatibilityWarningsReEnabled"));
});

view.getBtnContentDirectoryUI().setCommand((UiCommand) CSubmenuPreferences.this::openContentDirectory);

initializeGameLogVerbosityComboBox();
initializeCloseActionComboBox();
initializeDefaultFontSizeComboBox();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package forge.screens.home.settings;

import forge.control.FControl;
import forge.control.FControl.CloseAction;
import forge.control.KeyboardShortcuts;
import forge.control.KeyboardShortcuts.Shortcut;
Expand Down Expand Up @@ -55,7 +56,6 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
private final FLabel btnDeleteWorkshopUI = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnDeleteWorkshopUI")).build();
private final FLabel btnUserProfileUI = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnUserProfileUI")).build();
private final FLabel btnContentDirectoryUI = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnContentDirectoryUI")).build();
private final FLabel btnResetJavaFutureCompatibilityWarnings = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnResetJavaFutureCompatibilityWarnings")).build();
private final FLabel btnClearImageCache = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnClearImageCache")).build();
private final FLabel btnTokenPreviewer = new FLabel.Builder().opaque(true).hoverable(true).text(localizer.getMessage("btnTokenPreviewer")).build();

Expand Down Expand Up @@ -112,6 +112,7 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
private final JCheckBox cbShowStormCount = new OptionsCheckBox(localizer.getMessage("cbShowStormCount"));
private final JCheckBox cbRemindOnPriority = new OptionsCheckBox(localizer.getMessage("cbRemindOnPriority"));
private final JCheckBox cbUseSentry = new OptionsCheckBox(localizer.getMessage("cbUseSentry"));
private final JCheckBox cbCheckSnapshot = new OptionsCheckBox(localizer.getMessage("cbSnapshotUpdate"));
private final JCheckBox cbEnableUnknownCards = new OptionsCheckBox(localizer.getMessage("lblEnableUnknownCards"));
private final JCheckBox cbEnableNonLegalCards = new OptionsCheckBox(localizer.getMessage("lblEnableNonLegalCards"));
private final JCheckBox cbAllowCustomCardsDeckConformance = new OptionsCheckBox(localizer.getMessage("lblAllowCustomCardsInDecks"));
Expand Down Expand Up @@ -193,7 +194,10 @@ public enum VSubmenuPreferences implements IVSubmenu<CSubmenuPreferences> {
pnlPrefs.add(cbUseSentry, titleConstraints);
pnlPrefs.add(new NoteLabel(localizer.getMessage("nlUseSentry")), descriptionConstraints);

pnlPrefs.add(btnResetJavaFutureCompatibilityWarnings, "w 300px!, h 30px!, gap 27px 0 0 20px, span 2 1");
if (FControl.instance.isSnapshot()) {
pnlPrefs.add(cbCheckSnapshot, titleConstraints);
pnlPrefs.add(new NoteLabel(localizer.getMessage("nlSnapshotUpdate")), descriptionConstraints);
}

// Gameplay Options
pnlPrefs.add(new SectionLabel(localizer.getMessage("GamePlay")), sectionConstraints);
Expand Down Expand Up @@ -625,6 +629,11 @@ public final JCheckBox getCbUseSentry() {
return cbUseSentry;
}

/** @return {@link javax.swing.JCheckBox} */
public final JCheckBox getCbCheckSnapshot() {
return cbCheckSnapshot;
}

/** @return {@link javax.swing.JCheckBox} */
public final JCheckBox getCbRemoveSmall() {
return cbRemoveSmall;
Expand Down Expand Up @@ -985,10 +994,6 @@ public final FLabel getBtnDeleteWorkshopUI() {
public final FLabel getBtnClearImageCache() { return btnClearImageCache; }
public final FLabel getBtnTokenPreviewer() { return btnTokenPreviewer; }

public final FLabel getBtnResetJavaFutureCompatibilityWarnings() {
return btnResetJavaFutureCompatibilityWarnings;
}

/* (non-Javadoc)
* @see forge.gui.framework.IVDoc#getDocumentID()
*/
Expand Down
22 changes: 14 additions & 8 deletions forge-gui-desktop/src/main/java/forge/view/FTitleBarBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import forge.toolbox.FSkin.SkinColor;
import forge.toolbox.FSkin.SkinnedLabel;
import forge.toolbox.FSkin.SkinnedMenuBar;
import forge.util.BuildInfo;
import forge.util.Localizer;
import forge.util.RSSReader;

Expand Down Expand Up @@ -95,7 +94,10 @@ protected void addControls() {

public abstract void setTitle(String title);
public abstract void setIconImage(Image image);

public void setUpdaterVisibility() {
if (btnUpdateShortcut != null)
btnUpdateShortcut.updateVisibility();
}
public void updateButtons() {
boolean fullScreen = owner.isFullScreen();
btnLockTitleBar.setVisible(fullScreen);
Expand Down Expand Up @@ -422,13 +424,14 @@ public void paintComponent(Graphics g) {
}
}
public class UpdaterButton extends TitleBarButton {
final int MARQUEE_SPEED_DIV = 15;
final int REPAINT_WITHIN_MS = 25;
final String displayText = FControl.instance.compareVersion(BuildInfo.getVersionString());
private UpdaterButton() {
final int MARQUEE_SPEED_DIV = 50;
final int REPAINT_WITHIN_MS = 50;
final int wMod = 60;
final String displayText = FControl.instance.getSnapshotNotification();
public UpdaterButton() {
setToolTipText(Localizer.getInstance().getMessage("btnCheckForUpdates"));
setPreferredSize(new Dimension(160, 25));
setEnabled(!displayText.isEmpty());
updateVisibility();
}
@Override
protected void onClick() {
Expand All @@ -440,7 +443,7 @@ protected void onClick() {
}
@Override
public void paintComponent(Graphics g) {
g.translate((int)((System.currentTimeMillis() / MARQUEE_SPEED_DIV) % (getWidth() * 2)) - getWidth(), 0);
g.translate(-((int)((System.currentTimeMillis() / MARQUEE_SPEED_DIV) % ((getWidth() + wMod) * 2)) - (getWidth() + wMod)), 0);
super.paintComponent(g);
int thickness = 2;
Graphics2D g2d = (Graphics2D) g;
Expand All @@ -450,5 +453,8 @@ public void paintComponent(Graphics g) {
g2d.drawString(displayText, 0, 17);
repaint(REPAINT_WITHIN_MS);
}
private void updateVisibility() {
setVisible(!isVisible());
}
}
}
Loading

0 comments on commit 16b0bd2

Please sign in to comment.