Search in sources :

Example 1 with RespawnPlayerDialog

use of org.pepsoft.worldpainter.tools.RespawnPlayerDialog in project WorldPainter by Captain-Chaos.

the class App method createToolsMenu.

private JMenu createToolsMenu() {
    JMenuItem menuItem = new JMenuItem(strings.getString("respawn.player") + "...");
    menuItem.addActionListener(e -> {
        RespawnPlayerDialog dialog = new RespawnPlayerDialog(App.this);
        dialog.setVisible(true);
    });
    menuItem.setMnemonic('r');
    JMenu menu = new JMenu(strings.getString("tools"));
    menu.setMnemonic('t');
    menu.add(menuItem);
    menuItem = new JMenuItem(strings.getString("open.custom.brushes.folder"));
    menuItem.addActionListener(e -> {
        File brushesDir = new File(Configuration.getConfigDir(), "brushes");
        if (!brushesDir.exists()) {
            if (!brushesDir.mkdirs()) {
                Toolkit.getDefaultToolkit().beep();
                return;
            }
        }
        DesktopUtils.open(brushesDir);
    });
    menuItem.setMnemonic('c');
    menu.add(menuItem);
    menuItem = new JMenuItem(strings.getString("open.plugins.folder"));
    menuItem.addActionListener(e -> {
        File pluginsDir = new File(Configuration.getConfigDir(), "plugins");
        if (!pluginsDir.exists()) {
            if (!pluginsDir.mkdirs()) {
                Toolkit.getDefaultToolkit().beep();
                return;
            }
        }
        DesktopUtils.open(pluginsDir);
    });
    menuItem.setMnemonic('p');
    menu.add(menuItem);
    menuItem = new JMenuItem(strings.getString("biomes.viewer") + "...");
    // Disable the menu item after the biome scheme manager has been
    // initialised, if it turns out there are no supported biome algorithms
    // (because no supported Minecraft installation could be found, for
    // instance), but without blocking the GUI
    final JMenuItem biomesViewerMenuItem = menuItem;
    new Thread("Biomes Viewer Menu Item Initialiser") {

        @Override
        public void run() {
            if (BiomeSchemeManager.getAvailableBiomeAlgorithms().isEmpty()) {
                logger.info("No supported Minecraft installation found; disabling biomes preview and Biomes Viewer");
                SwingUtilities.invokeLater(() -> {
                    biomesViewerMenuItem.setEnabled(false);
                    biomesViewerMenuItem.setToolTipText("No supported Minecraft installation found");
                });
            }
        }
    }.start();
    menuItem.addActionListener(event -> {
        if (BiomeSchemeManager.getAvailableBiomeAlgorithms().isEmpty()) {
            // the menu item is still enabled
            return;
        }
        if (biomesViewerFrame != null) {
            biomesViewerFrame.requestFocus();
        } else {
            int preferredAlgorithm = -1;
            if ((dimension != null) && (dimension.getDim() == DIM_NORMAL) && (dimension.getMaxHeight() == DEFAULT_MAX_HEIGHT_2)) {
                if (world.getGenerator() == Generator.LARGE_BIOMES) {
                    preferredAlgorithm = BIOME_ALGORITHM_1_7_LARGE;
                } else {
                    preferredAlgorithm = BIOME_ALGORITHM_1_7_DEFAULT;
                }
            }
            logger.info("Opening biomes viewer");
            biomesViewerFrame = new BiomesViewerFrame(dimension.getMinecraftSeed(), world.getSpawnPoint(), preferredAlgorithm, colourSchemes[0], App.this);
            biomesViewerFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            biomesViewerFrame.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent e) {
                    // was
                    if (biomesViewerFrame != null) {
                        biomesViewerFrame.destroy();
                        biomesViewerFrame.dispose();
                        biomesViewerFrame = null;
                    }
                }
            });
            biomesViewerFrame.setLocationRelativeTo(App.this);
            biomesViewerFrame.setVisible(true);
        }
    });
    menuItem.setMnemonic('b');
    menu.add(menuItem);
    // menuItem = new JMenuItem("Manage plugins...");
    // menuItem.addActionListener(e -> {
    // StringBuilder url = new StringBuilder("http://bo.worldpainter.net:8081/wp/plugins/overview.jsp");
    // url.append("?uuid=").append(Configuration.getInstance().getUuid().toString());
    // boolean first = true;
    // for (Plugin plugin: PluginManager.getInstance().getAllPlugins()) {
    // if (plugin.getName().equals("Default")) {
    // continue;
    // }
    // if (first) {
    // url.append("&plugins=");
    // first = false;
    // } else {
    // url.append(',');
    // }
    // url.append(plugin.getName().replaceAll("\\s", "").toLowerCase());
    // }
    // SimpleBrowser browser = new SimpleBrowser(App.this, true, "Manage Plugins", url.toString());
    // browser.setVisible(true);
    // });
    // menuItem.setMnemonic('p');
    // menu.add(menuItem);
    menuItem = new JMenuItem("Run script...");
    menuItem.addActionListener(e -> {
        new ScriptRunner(this, world, dimension, undoManagers.values()).setVisible(true);
    });
    menu.add(menuItem);
    menu.putClientProperty(HELP_KEY_KEY, "Menu/Tools");
    return menu;
}
Also used : RespawnPlayerDialog(org.pepsoft.worldpainter.tools.RespawnPlayerDialog) BiomesViewerFrame(org.pepsoft.worldpainter.tools.BiomesViewerFrame) ScriptRunner(org.pepsoft.worldpainter.tools.scripts.ScriptRunner) Paint(org.pepsoft.worldpainter.painting.Paint)

Aggregations

Paint (org.pepsoft.worldpainter.painting.Paint)1 BiomesViewerFrame (org.pepsoft.worldpainter.tools.BiomesViewerFrame)1 RespawnPlayerDialog (org.pepsoft.worldpainter.tools.RespawnPlayerDialog)1 ScriptRunner (org.pepsoft.worldpainter.tools.scripts.ScriptRunner)1