Search in sources :

Example 1 with MapPropertyPanel

use of de.gurkenlabs.utiliti.swing.dialogs.MapPropertyPanel in project litiengine by gurkenlabs.

the class Program method initMapMenu.

private static Menu initMapMenu() {
    Menu mnMap = new Menu(Resources.get("menu_map"));
    MenuItem imp = new MenuItem(Resources.get("menu_import"));
    imp.addActionListener(a -> EditorScreen.instance().getMapComponent().importMap());
    MenuItem exp = new MenuItem(Resources.get("menu_export"));
    exp.addActionListener(a -> EditorScreen.instance().getMapComponent().exportMap());
    MenuItem del2 = new MenuItem(Resources.get("menu_removeMap"));
    del2.addActionListener(a -> EditorScreen.instance().getMapComponent().deleteMap());
    MenuItem mapProps = new MenuItem(Resources.get("menu_properties"));
    mapProps.setShortcut(new MenuShortcut(KeyEvent.VK_M));
    mapProps.addActionListener(a -> {
        if (EditorScreen.instance().getMapComponent().getMaps() == null || EditorScreen.instance().getMapComponent().getMaps().isEmpty()) {
            return;
        }
        MapPropertyPanel panel = new MapPropertyPanel();
        panel.bind(Game.getEnvironment().getMap());
        int option = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), panel, Resources.get("menu_mapProperties"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (option == JOptionPane.OK_OPTION) {
            panel.saveChanges();
            final String colorProp = Game.getEnvironment().getMap().getCustomProperty(MapProperty.AMBIENTCOLOR);
            try {
                if (Game.getEnvironment().getMap().getCustomProperty(MapProperty.AMBIENTALPHA) != null) {
                    int alpha = Integer.parseInt(Game.getEnvironment().getMap().getCustomProperty(MapProperty.AMBIENTALPHA));
                    Game.getEnvironment().getAmbientLight().setAlpha(alpha);
                }
                if (colorProp != null && !colorProp.isEmpty()) {
                    Color ambientColor = Color.decode(colorProp);
                    Game.getEnvironment().getAmbientLight().setColor(ambientColor);
                }
            } catch (final NumberFormatException nfe) {
                log.log(Level.SEVERE, nfe.getLocalizedMessage(), nfe);
            }
            EditorScreen.instance().getMapComponent().loadMaps(EditorScreen.instance().getGameFile().getMaps());
            EditorScreen.instance().getMapComponent().loadEnvironment((Map) Game.getEnvironment().getMap());
        }
    });
    mnMap.add(imp);
    mnMap.add(exp);
    mnMap.add(del2);
    mnMap.addSeparator();
    mnMap.add(mapProps);
    return mnMap;
}
Also used : Color(java.awt.Color) MapPropertyPanel(de.gurkenlabs.utiliti.swing.dialogs.MapPropertyPanel) CheckboxMenuItem(java.awt.CheckboxMenuItem) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) PopupMenu(java.awt.PopupMenu) Menu(java.awt.Menu) JPopupMenu(javax.swing.JPopupMenu) MenuShortcut(java.awt.MenuShortcut)

Aggregations

MapPropertyPanel (de.gurkenlabs.utiliti.swing.dialogs.MapPropertyPanel)1 CheckboxMenuItem (java.awt.CheckboxMenuItem)1 Color (java.awt.Color)1 Menu (java.awt.Menu)1 MenuItem (java.awt.MenuItem)1 MenuShortcut (java.awt.MenuShortcut)1 PopupMenu (java.awt.PopupMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1