From 6d8082cafeb2a0f38a29badb2006e621e818d9dc Mon Sep 17 00:00:00 2001 From: galaxyoyo Date: Mon, 12 Jan 2015 22:05:31 +0100 Subject: [PATCH] =?UTF-8?q?Fix=C3=A9=20probl=C3=A8me=20de=20scroll=20dans?= =?UTF-8?q?=20l'=C3=A9diteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../galaxyoyo/unknown/client/main/Main.java | 52 +++++++++++++--- .../galaxyoyo/unknown/editor/EditorFrame.java | 60 +++++++++++++------ .../galaxyoyo/unknown/editor/SpriteComp.java | 14 ++++- .../galaxyoyo/unknown/frame/MainFrame.java | 9 +-- .../listeners/CollidMapMouseListener.java | 19 ------ .../frame/listeners/CreateMapListener.java | 2 + .../frame/listeners/MapMouseListener.java | 19 ------ .../frame/listeners/OpenMapListener.java | 4 +- 8 files changed, 109 insertions(+), 70 deletions(-) diff --git a/src/main/java/galaxyoyo/unknown/client/main/Main.java b/src/main/java/galaxyoyo/unknown/client/main/Main.java index 101cecf..4f5eb90 100644 --- a/src/main/java/galaxyoyo/unknown/client/main/Main.java +++ b/src/main/java/galaxyoyo/unknown/client/main/Main.java @@ -9,10 +9,16 @@ import galaxyoyo.unknown.api.editor.sprites.SpriteRegister; import galaxyoyo.unknown.frame.MainFrame; import java.awt.Color; +import java.awt.Desktop; import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; import java.awt.image.BufferedImage; import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; import java.util.Locale; +import java.util.Map; import javax.swing.JOptionPane; @@ -24,7 +30,6 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.appender.ConsoleAppender; -import org.apache.logging.log4j.core.appender.FileAppender; import org.apache.logging.log4j.core.layout.PatternLayout; /** @@ -59,17 +64,16 @@ public class Main { Locale.setDefault(Locale.FRANCE); - DEV = Main.class.getResource("/META-INF/MANIFEST.MF") == null; + DEV = Main.class.getClassLoader().getResource("/META-INF/MANIFEST.MF") == null; Logger LOGGER = (Logger) LogManager.getRootLogger(); ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build(); - FileAppender file = FileAppender.createAppender("Console.log", "false", "false", "File", "true", "true", "true", "8192", PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build(), null, "false", "false", null); console.start(); - file.start(); LOGGER.addAppender(console); - LOGGER.addAppender(file); LOGGER.setLevel(Level.INFO); + checkJava(); + OptionParser parser = new OptionParser(); OptionSpec edit = parser.accepts("edit", "Lancer l'\u00e9diteur de monde").withOptionalArg(); @@ -114,7 +118,41 @@ public class Main launchFrame(); } - + + private static void checkJava() + { + if (GraphicsEnvironment.isHeadless()) + { + HeadlessException ex = new HeadlessException("Impossible de lancer un jeu sans \u00e9cran !"); + LogManager.getLogger("JAVAX-SWING").fatal("Cette application est un jeu, sans écran, elle aura du mal \u00e0 tourner ..."); + LogManager.getLogger("JAVAX-SWING").catching(Level.FATAL, ex); + System.exit(1); + } + + try + { + Map.class.getDeclaredMethod("getOrDefault", Object.class, Object.class); + } + catch (NoSuchMethodException ex) + { + ex.printStackTrace(); + JOptionPane.showMessageDialog(null, "Cette application requiert Java 8.
La page de t\u00e9l\u00e9chargement va maintenant s'ouvrir."); + JOptionPane.showMessageDialog(null, "Si vous êtes certain que Java 8 est installé sur votre machine, assurez-vous qu'il n'y a pas de versions obsolètes de Java,
ou si vous êtes plus expérimentés si le path vers Java est bien défini vers la bonne version."); + try + { + if (Desktop.isDesktopSupported()) + Desktop.getDesktop().browse(new URL("http://java.com/download").toURI()); + else + JOptionPane.showMessageDialog(null, "Votre machine ne supporte pas la classe Desktop, impossible d'ouvrir la page.
Rendez-vous y manuellement sur http://java.com/download pour installer Java."); + } + catch (IOException | URISyntaxException e) + { + e.printStackTrace(); + } + System.exit(1); + } + } + /** * Lance la fenêtre principale * @see #main(String...) @@ -195,8 +233,6 @@ public class Main RawMap rm = EditorAPI.toRawMap(baseWidth, baseHeight); rm.setFont(image); - EditorAPI.saveAs(rm); - EditorAPI.open(rm); } diff --git a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java index 6826750..39dc31d 100644 --- a/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java +++ b/src/main/java/galaxyoyo/unknown/editor/EditorFrame.java @@ -19,6 +19,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JFrame; @@ -29,6 +30,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -40,17 +42,19 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene private final JPanel content = new JPanel(); - private JMenuBar menuBar = new JMenuBar(); - private JMenu fichier = new JMenu("Fichier"); - private JMenuItem nouveau = new JMenuItem("Nouveau"); - private JMenuItem open = new JMenuItem("Ouvrir"); - private JMenuItem save = new JMenuItem("Sauvegarder"); - private JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); - private JMenuItem exit = new JMenuItem("Quitter"); + private final JMenuBar menuBar = new JMenuBar(); + private final JMenu fichier = new JMenu("Fichier"); + private final JMenu tools = new JMenu("Outils"); + private final JMenuItem nouveau = new JMenuItem("Nouveau"); + private final JMenuItem open = new JMenuItem("Ouvrir"); + private final JMenuItem save = new JMenuItem("Sauvegarder"); + private final JMenuItem saveAs = new JMenuItem("Sauvegarder sous ..."); + private final JMenuItem exit = new JMenuItem("Quitter"); + private final JMenu selectionMode = new JMenu("Mode de s\u00e9lection"); private final JTabbedPane tabs = new JTabbedPane(); private final JPanel tabEvents = new JPanel(); - private final CollidPanel tabColl = new CollidPanel(this); - private final MapPanel mapPanel = new MapPanel(this); + private final CollidPanel tabColl; + private final MapPanel mapPanel; private final JTabbedPane resources = new JTabbedPane(); private final JPanel couche1 = new JPanel(); private final JPanel couche2 = new JPanel(); @@ -71,43 +75,60 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene this.setVisible(true); this.setVisible(false); - nouveau.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_N); + fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); + + nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK, true)); nouveau.addActionListener(new CreateMapListener()); fichier.add(nouveau); - open.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_O); + open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, true)); open.addActionListener(new OpenMapListener()); fichier.add(open); fichier.addSeparator(); - save.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_S); + save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK, true)); save.addActionListener(this); fichier.add(save); - saveAs.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_MASK + KeyEvent.VK_S); + saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK, true)); saveAs.addActionListener(this); fichier.add(saveAs); fichier.addSeparator(); - exit.setMnemonic(KeyEvent.CTRL_DOWN_MASK + KeyEvent.VK_Q); + exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true)); exit.addActionListener(this); fichier.add(exit); menuBar.add(fichier); + + tools.setMnemonic(KeyEvent.VK_O + KeyEvent.ALT_DOWN_MASK); + + tools.add(selectionMode); + + menuBar.add(tools); this.setJMenuBar(menuBar); + mapPanel = new MapPanel(this); mapPanel.addMouseListener(new MapMouseListener(mapPanel, this)); mapPanel.addMouseMotionListener(new MapMouseListener(mapPanel, this)); + tabColl = new CollidPanel(this); tabColl.addMouseListener(new CollidMapMouseListener(tabColl, this)); tabColl.addMouseMotionListener(new CollidMapMouseListener(tabColl, this)); - tabs.addTab("Carte", new JScrollPane(mapPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + JScrollPane scrollMap = new JScrollPane(mapPanel); + scrollMap.getHorizontalScrollBar().setUnitIncrement(34); + scrollMap.getVerticalScrollBar().setUnitIncrement(34); + JScrollPane scrollCollidMap = new JScrollPane(tabColl); + scrollCollidMap.getHorizontalScrollBar().setUnitIncrement(34); + scrollCollidMap.getVerticalScrollBar().setUnitIncrement(34); + + tabs.addTab("Carte", scrollMap); tabs.addTab("\u00c9vennments", new JScrollPane(tabEvents)); - tabs.addTab("Collisions", new JScrollPane(tabColl)); + tabs.addTab("Collisions", scrollCollidMap); tabs.addChangeListener(this); content.add(tabs, BorderLayout.CENTER); @@ -189,8 +210,13 @@ public class EditorFrame extends JFrame implements ChangeListener, ActionListene int cursorPos = ((JScrollPane) resources.getSelectedComponent()).getVerticalScrollBar().getValue(); tabs.setPreferredSize(new Dimension(getWidth(), getHeight() / 5)); tabs.setLocation(0, 0); - mapPanel.setPreferredSize(new Dimension(getWidth() / 4 * 3, getHeight() / 5 * 4)); + BufferedImage img = getMap().getFont(); + int width = img.getWidth() * 2; + int height = img.getHeight() * 2; + mapPanel.setPreferredSize(new Dimension(width, height)); mapPanel.setLocation(0, getHeight() / 5); + tabColl.setPreferredSize(new Dimension(width, height)); + tabColl.setLocation(0, getHeight() / 5); resources.setPreferredSize(new Dimension(getWidth() / 4 - 15, getHeight() / 5 * 4 - 40)); resources.setLocation(getWidth() / 4 * 3, getHeight() / 5); diff --git a/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java b/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java index 4302f19..de861eb 100644 --- a/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java +++ b/src/main/java/galaxyoyo/unknown/editor/SpriteComp.java @@ -12,8 +12,8 @@ public class SpriteComp extends JComponent { private static final long serialVersionUID = -6512257366877053285L; - private final Sprite sprite; - private final int couche; + private Sprite sprite; + private int couche; private boolean selected; public SpriteComp(Sprite sprite, int couche) @@ -34,11 +34,21 @@ public class SpriteComp extends JComponent return sprite; } + public void setSprite(Sprite s) + { + this.sprite = s; + } + public int getCouche() { return couche; } + public void setCouche(int couche) + { + this.couche = couche; + } + public boolean isSelected() { return selected; diff --git a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java b/src/main/java/galaxyoyo/unknown/frame/MainFrame.java index e9b2b8f..7b6ded8 100644 --- a/src/main/java/galaxyoyo/unknown/frame/MainFrame.java +++ b/src/main/java/galaxyoyo/unknown/frame/MainFrame.java @@ -7,6 +7,7 @@ import galaxyoyo.unknown.frame.listeners.CreateMapListener; import galaxyoyo.unknown.frame.listeners.OpenMapListener; import java.awt.Dimension; +import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; @@ -43,7 +44,6 @@ public class MainFrame extends JFrame private JMenuBar menuBar = new JMenuBar(); private JMenu fichier = new JMenu("Fichier"); - private JMenu editer = new JMenu("\u00c9diter"); private JMenu editMaps = new JMenu("Cartes"); private JMenuItem createMap = new JMenuItem("Cr\u00e9er"); private JMenuItem openMap = new JMenuItem("Ouvrir"); @@ -63,15 +63,16 @@ public class MainFrame extends JFrame this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - menuBar.add(fichier); + fichier.setMnemonic(KeyEvent.VK_F + KeyEvent.ALT_DOWN_MASK); createMap.addActionListener(new CreateMapListener()); editMaps.add(createMap); openMap.addActionListener(new OpenMapListener()); editMaps.add(openMap); - editer.add(editMaps); - menuBar.add(editer); + fichier.add(editMaps); + + menuBar.add(fichier); this.setJMenuBar(menuBar); } diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java b/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java index 3aaaeb9..e70c7f1 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java +++ b/src/main/java/galaxyoyo/unknown/frame/listeners/CollidMapMouseListener.java @@ -6,7 +6,6 @@ import galaxyoyo.unknown.editor.CollidPanel; import galaxyoyo.unknown.editor.EditorFrame; import galaxyoyo.unknown.editor.Map; -import java.awt.Cursor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -25,24 +24,6 @@ public class CollidMapMouseListener extends MouseAdapter { return frame; } - - @Override - public void mouseMoved(MouseEvent event) - { - Map map = getFrame().getMap(); - - int x = panel.getWidth() / 2 - map.getFont().getWidth(); - int y = panel.getHeight() / 2 - map.getFont().getHeight(); - - if (map.getCase((event.getX() - x - 2) / 34, (event.getY() - y - 2) / 34) != null && event.getX() - x >= 2 && event.getY() - y >= 2) - { - getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - else - { - getFrame().setCursor(Cursor.getDefaultCursor()); - } - } @Override public void mouseReleased(MouseEvent event) diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java b/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java index bf10408..0ba9555 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java +++ b/src/main/java/galaxyoyo/unknown/frame/listeners/CreateMapListener.java @@ -4,6 +4,7 @@ package galaxyoyo.unknown.frame.listeners; import galaxyoyo.unknown.client.main.Main; +import galaxyoyo.unknown.frame.MainFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -20,5 +21,6 @@ public class CreateMapListener implements ActionListener public void actionPerformed(ActionEvent event) { Main.main("--edit", Main.isInDebugMode() ? " --debug true" : ""); + MainFrame.getInstance().dispose(); } } diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java b/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java index ecf4c95..62301f5 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java +++ b/src/main/java/galaxyoyo/unknown/frame/listeners/MapMouseListener.java @@ -5,7 +5,6 @@ import galaxyoyo.unknown.editor.EditorFrame; import galaxyoyo.unknown.editor.Map; import galaxyoyo.unknown.editor.MapPanel; -import java.awt.Cursor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -24,24 +23,6 @@ public class MapMouseListener extends MouseAdapter { return frame; } - - @Override - public void mouseMoved(MouseEvent event) - { - Map map = getFrame().getMap(); - - int x = panel.getWidth() / 2 - map.getFont().getWidth(); - int y = panel.getHeight() / 2 - map.getFont().getHeight(); - - if (map.getCase((event.getX() - x - 2) / 34, (event.getY() - y - 2) / 34) != null && event.getX() - x >= 2 && event.getY() - y >= 2) - { - getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - else - { - getFrame().setCursor(Cursor.getDefaultCursor()); - } - } @Override public void mouseReleased(MouseEvent event) diff --git a/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java b/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java index 2d61bc4..13959bd 100644 --- a/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java +++ b/src/main/java/galaxyoyo/unknown/frame/listeners/OpenMapListener.java @@ -1,6 +1,7 @@ package galaxyoyo.unknown.frame.listeners; import galaxyoyo.unknown.api.editor.EditorAPI; +import galaxyoyo.unknown.frame.MainFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -13,6 +14,7 @@ public class OpenMapListener implements ActionListener @Override public void actionPerformed(ActionEvent event) { - EditorAPI.open(); + if (EditorAPI.open() != null) + MainFrame.getInstance().dispose(); } }