public boolean setCurrentScreen(final FScreen screen, final boolean previousScreenClosed) { // TODO: Uncomment the line below if this function stops being used to refresh // the current screen in some places (such as Continue and Restart in the match screen) // if (currentScreen == screen) { return; } // give previous screen a chance to perform special switch handling and/or cancel switching away // from screen if (currentScreen != screen && !Singletons.getView().getNavigationBar().canSwitch(screen)) { return false; } if (currentScreen != null && currentScreen .isMatchScreen()) { // hide targeting overlay and reset image if was on match screen // SOverlayUtils.hideTargetingOverlay(); if (isMatchBackgroundImageVisible()) { FView.SINGLETON_INSTANCE.getPnlInsets().setForegroundImage(new ImageIcon()); } } clearChildren(JLayeredPane.DEFAULT_LAYER); SOverlayUtils.hideOverlay(); ImageCache.clear(); // reduce memory usage by clearing image cache when switching screens currentScreen = screen; // load layout for new current screen screen.getController().register(); try { SLayoutIO.loadLayout(null); } catch (final InvalidLayoutFileException ex) { SOptionPane.showMessageDialog( String.format( "Your %s layout file could not be read. It will be deleted after you press OK.\nThe game will proceed with default layout.", screen.getTabCaption()), "Warning!"); if (screen.deleteLayoutFile()) { SLayoutIO.loadLayout(null); // try again } } screen.getController().initialize(); screen.getView().populate(); if (screen.isMatchScreen()) { if (isMatchBackgroundImageVisible()) { FView.SINGLETON_INSTANCE .getPnlInsets() .setForegroundImage(FSkin.getIcon(FSkinProp.BG_MATCH)); } // SOverlayUtils.showTargetingOverlay(); } Singletons.getView().getNavigationBar().updateSelectedTab(); return true; }
/** After view and model have been initialized, control can start. */ public void initialize() { // Preloads skin components (using progress bar). FSkin.loadFull(true); display = FView.SINGLETON_INSTANCE.getLpnDocument(); final ForgePreferences prefs = FModel.getPreferences(); closeAction = CloseAction.valueOf(prefs.getPref(FPref.UI_CLOSE_ACTION)); FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Loading quest..."); // Preload quest data if present final File dirQuests = new File(ForgeConstants.QUEST_SAVE_DIR); final String questname = FModel.getQuestPreferences().getPref(QPref.CURRENT_QUEST); final File data = new File(dirQuests.getPath(), questname); if (data.exists()) { FModel.getQuest().load(QuestDataIO.loadData(data)); } // Handles resizing in null layouts of layers in JLayeredPane as well as saving window layout final FFrame window = Singletons.getView().getFrame(); window.addComponentListener( new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { sizeChildren(); window.updateNormalBounds(); SLayoutIO.saveWindowLayout(); } @Override public void componentMoved(final ComponentEvent e) { window.updateNormalBounds(); SLayoutIO.saveWindowLayout(); } }); FView.SINGLETON_INSTANCE .getLpnDocument() .addMouseListener(SOverflowUtil.getHideOverflowListener()); FView.SINGLETON_INSTANCE .getLpnDocument() .addComponentListener(SResizingUtil.getWindowResizeListener()); setGlobalKeyboardHandler(); FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Opening main window..."); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { Singletons.getView().initialize(); } }); }
public void openLayout() { SOverlayUtils.genericOverlay(); final SaveOpenDialog dlgOpen = new SaveOpenDialog(); final FileLocation layoutFile = Singletons.getControl().getCurrentScreen().getLayoutFile(); final File defFile = layoutFile != null ? new File(layoutFile.userPrefLoc) : null; final File loadFile = dlgOpen.OpenDialog(defFile, Filetypes.LAYOUT); if (loadFile != null) { FView.SINGLETON_INSTANCE.getPnlContent().removeAll(); // let it redraw everything first FThreads.invokeInEdtLater( new Runnable() { @Override public void run() { if (loadFile != null) { SLayoutIO.loadLayout(loadFile); SLayoutIO.saveLayout(null); } SOverlayUtils.hideOverlay(); } }); } }
/** Remove all children from a specified layer. */ private void clearChildren(final int layer0) { final Component[] children = FView.SINGLETON_INSTANCE.getLpnDocument().getComponentsInLayer(layer0); for (final Component c : children) { display.remove(c); } }
/** Toggle targeting overlay painting. */ public void toggleTargeting() { arcState++; if (arcState == 3) { arcState = 0; } refreshArcStateDisplay(); FView.SINGLETON_INSTANCE.getFrame().repaint(); // repaint the match UI }
public void revertLayout() { SOverlayUtils.genericOverlay(); FView.SINGLETON_INSTANCE.getPnlContent().removeAll(); FThreads.invokeInEdtLater( new Runnable() { @Override public void run() { SLayoutIO.loadLayout(null); SOverlayUtils.hideOverlay(); } }); }