diff options
| author | 2020-05-03 21:06:38 +0100 | |
|---|---|---|
| committer | 2020-05-03 21:06:38 +0100 | |
| commit | 854f4d49407e45d67dd5754afd21a7e59970ca5b (patch) | |
| tree | 582e3245786f9723b5895b0c8d41087b0e6bb416 /src/main/java/cuchaz/enigma/gui/elements | |
| parent | Rewrite search dialog (#233) (diff) | |
| download | enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.gz enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.xz enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.zip | |
Multiplayer support (#221)
* First pass on multiplayer
* Apply review suggestions
* Dedicated Enigma server
* Don't jump to references when other users do stuff
* Better UI + translations
* french translation
* Apply review suggestions
* Document the protocol
* Fix most issues with scrolling.
* Apply review suggestions
* Fix zip hash issues + add a bit more logging
* Optimize zip hash
* Fix a couple of login bugs
* Add message log and user list
* Make Message an abstract class
* Make status bar work, add chat box
* Hide message log/users list when not connected
* Fix status bar not resetting entirely
* Run stop server task on server thread to prevent multithreading race conditions
* Add c2s message to packet id list
* Fix message scroll bar not scrolling to the end
* Formatting
* User list size -> ushort
* Combine contains and remove check
* Check removal before sending packet
* Add password to login packet
* Fix the GUI closing the rename text field when someone else renames something
* Update fr_fr.json
* oups
* Make connection/server create dialogs not useless if it fails once
* Refactor UI state updating
* Fix imports
* Fix Collab menu
* Fix NPE when rename not allowed
* Make the log file a configurable option
* Don't use modified UTF
* Update fr_fr.json
* Bump version to 0.15.4
* Apparently I can't spell neither words nor semantic versions
Co-authored-by: Yanis48 <doublecraft.official@gmail.com>
Co-authored-by: 2xsaiko <git@dblsaiko.net>
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/elements')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/elements/CollapsibleTabbedPane.java | 40 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 79 |
2 files changed, 108 insertions, 11 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/elements/CollapsibleTabbedPane.java b/src/main/java/cuchaz/enigma/gui/elements/CollapsibleTabbedPane.java new file mode 100644 index 0000000..fb497b1 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/elements/CollapsibleTabbedPane.java | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | package cuchaz.enigma.gui.elements; | ||
| 2 | |||
| 3 | import java.awt.event.MouseEvent; | ||
| 4 | |||
| 5 | import javax.swing.JTabbedPane; | ||
| 6 | |||
| 7 | public class CollapsibleTabbedPane extends JTabbedPane { | ||
| 8 | |||
| 9 | public CollapsibleTabbedPane() { | ||
| 10 | } | ||
| 11 | |||
| 12 | public CollapsibleTabbedPane(int tabPlacement) { | ||
| 13 | super(tabPlacement); | ||
| 14 | } | ||
| 15 | |||
| 16 | public CollapsibleTabbedPane(int tabPlacement, int tabLayoutPolicy) { | ||
| 17 | super(tabPlacement, tabLayoutPolicy); | ||
| 18 | } | ||
| 19 | |||
| 20 | @Override | ||
| 21 | protected void processMouseEvent(MouseEvent e) { | ||
| 22 | int id = e.getID(); | ||
| 23 | if (id == MouseEvent.MOUSE_PRESSED) { | ||
| 24 | if (!isEnabled()) return; | ||
| 25 | int tabIndex = getUI().tabForCoordinate(this, e.getX(), e.getY()); | ||
| 26 | if (tabIndex >= 0 && isEnabledAt(tabIndex)) { | ||
| 27 | if (tabIndex == getSelectedIndex()) { | ||
| 28 | if (isFocusOwner() && isRequestFocusEnabled()) { | ||
| 29 | requestFocus(); | ||
| 30 | } else { | ||
| 31 | setSelectedIndex(-1); | ||
| 32 | } | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | super.processMouseEvent(e); | ||
| 38 | } | ||
| 39 | |||
| 40 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 8098178..f8e4f7e 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -1,5 +1,18 @@ | |||
| 1 | package cuchaz.enigma.gui.elements; | 1 | package cuchaz.enigma.gui.elements; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.config.Config; | ||
| 4 | import cuchaz.enigma.config.Themes; | ||
| 5 | import cuchaz.enigma.gui.Gui; | ||
| 6 | import cuchaz.enigma.gui.dialog.AboutDialog; | ||
| 7 | import cuchaz.enigma.gui.dialog.ConnectToServerDialog; | ||
| 8 | import cuchaz.enigma.gui.dialog.CreateServerDialog; | ||
| 9 | import cuchaz.enigma.gui.dialog.SearchDialog; | ||
| 10 | import cuchaz.enigma.gui.stats.StatsMember; | ||
| 11 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 12 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 13 | import cuchaz.enigma.utils.I18n; | ||
| 14 | import cuchaz.enigma.utils.Pair; | ||
| 15 | |||
| 3 | import java.awt.Container; | 16 | import java.awt.Container; |
| 4 | import java.awt.Desktop; | 17 | import java.awt.Desktop; |
| 5 | import java.awt.FlowLayout; | 18 | import java.awt.FlowLayout; |
| @@ -13,21 +26,11 @@ import java.nio.file.Files; | |||
| 13 | import java.nio.file.Path; | 26 | import java.nio.file.Path; |
| 14 | import java.nio.file.Paths; | 27 | import java.nio.file.Paths; |
| 15 | import java.util.*; | 28 | import java.util.*; |
| 29 | import java.util.List; | ||
| 16 | import java.util.stream.Collectors; | 30 | import java.util.stream.Collectors; |
| 17 | import java.util.stream.IntStream; | 31 | import java.util.stream.IntStream; |
| 18 | |||
| 19 | import javax.swing.*; | 32 | import javax.swing.*; |
| 20 | 33 | ||
| 21 | import cuchaz.enigma.config.Config; | ||
| 22 | import cuchaz.enigma.config.Themes; | ||
| 23 | import cuchaz.enigma.gui.Gui; | ||
| 24 | import cuchaz.enigma.gui.dialog.AboutDialog; | ||
| 25 | import cuchaz.enigma.gui.dialog.SearchDialog; | ||
| 26 | import cuchaz.enigma.gui.stats.StatsMember; | ||
| 27 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 28 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 29 | import cuchaz.enigma.utils.I18n; | ||
| 30 | import cuchaz.enigma.utils.Pair; | ||
| 31 | 34 | ||
| 32 | import javax.swing.*; | 35 | import javax.swing.*; |
| 33 | 36 | ||
| @@ -49,6 +52,8 @@ public class MenuBar extends JMenuBar { | |||
| 49 | public final JMenuItem dropMappingsMenu; | 52 | public final JMenuItem dropMappingsMenu; |
| 50 | public final JMenuItem exportSourceMenu; | 53 | public final JMenuItem exportSourceMenu; |
| 51 | public final JMenuItem exportJarMenu; | 54 | public final JMenuItem exportJarMenu; |
| 55 | public final JMenuItem connectToServerMenu; | ||
| 56 | public final JMenuItem startServerMenu; | ||
| 52 | private final Gui gui; | 57 | private final Gui gui; |
| 53 | 58 | ||
| 54 | public MenuBar(Gui gui) { | 59 | public MenuBar(Gui gui) { |
| @@ -343,6 +348,58 @@ public class MenuBar extends JMenuBar { | |||
| 343 | } | 348 | } |
| 344 | 349 | ||
| 345 | /* | 350 | /* |
| 351 | * Collab menu | ||
| 352 | */ | ||
| 353 | { | ||
| 354 | JMenu menu = new JMenu(I18n.translate("menu.collab")); | ||
| 355 | this.add(menu); | ||
| 356 | { | ||
| 357 | JMenuItem item = new JMenuItem(I18n.translate("menu.collab.connect")); | ||
| 358 | menu.add(item); | ||
| 359 | item.addActionListener(event -> { | ||
| 360 | if (this.gui.getController().getClient() != null) { | ||
| 361 | this.gui.getController().disconnectIfConnected(null); | ||
| 362 | return; | ||
| 363 | } | ||
| 364 | ConnectToServerDialog.Result result = ConnectToServerDialog.show(this.gui.getFrame()); | ||
| 365 | if (result == null) { | ||
| 366 | return; | ||
| 367 | } | ||
| 368 | this.gui.getController().disconnectIfConnected(null); | ||
| 369 | try { | ||
| 370 | this.gui.getController().createClient(result.getUsername(), result.getIp(), result.getPort(), result.getPassword()); | ||
| 371 | } catch (IOException e) { | ||
| 372 | JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.connect.error"), JOptionPane.ERROR_MESSAGE); | ||
| 373 | this.gui.getController().disconnectIfConnected(null); | ||
| 374 | } | ||
| 375 | Arrays.fill(result.getPassword(), (char)0); | ||
| 376 | }); | ||
| 377 | this.connectToServerMenu = item; | ||
| 378 | } | ||
| 379 | { | ||
| 380 | JMenuItem item = new JMenuItem(I18n.translate("menu.collab.server.start")); | ||
| 381 | menu.add(item); | ||
| 382 | item.addActionListener(event -> { | ||
| 383 | if (this.gui.getController().getServer() != null) { | ||
| 384 | this.gui.getController().disconnectIfConnected(null); | ||
| 385 | return; | ||
| 386 | } | ||
| 387 | CreateServerDialog.Result result = CreateServerDialog.show(this.gui.getFrame()); | ||
| 388 | if (result == null) { | ||
| 389 | return; | ||
| 390 | } | ||
| 391 | this.gui.getController().disconnectIfConnected(null); | ||
| 392 | try { | ||
| 393 | this.gui.getController().createServer(result.getPort(), result.getPassword()); | ||
| 394 | } catch (IOException e) { | ||
| 395 | JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.server.start.error"), JOptionPane.ERROR_MESSAGE); | ||
| 396 | this.gui.getController().disconnectIfConnected(null); | ||
| 397 | } | ||
| 398 | }); | ||
| 399 | this.startServerMenu = item; | ||
| 400 | } | ||
| 401 | } | ||
| 402 | /* | ||
| 346 | * Help menu | 403 | * Help menu |
| 347 | */ | 404 | */ |
| 348 | { | 405 | { |