Added second player to initial form

This commit is contained in:
lieght
2025-09-17 20:31:50 +02:00
parent 032d388f4f
commit 5eb6e8ea37
4 changed files with 77 additions and 60 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.toop.UI.GameSelectorWindow">
<grid id="27dc6" binding="mainMenu" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainMenu" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -23,7 +23,7 @@
</component>
<vspacer id="4e05c">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="1d2f1" class="javax.swing.JLabel">
@@ -42,7 +42,7 @@
<text value="Welcome to ISY games selector!"/>
</properties>
</component>
<component id="5cc82" class="javax.swing.JTextField" binding="ipTextField">
<component id="5cc82" class="javax.swing.JTextField" binding="name2TextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
@@ -52,62 +52,14 @@
<text value=""/>
</properties>
</component>
<component id="26a0" class="javax.swing.JTextField" binding="portTextField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="3abc3" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Port:"/>
</properties>
</component>
<component id="514db" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="IP:"/>
</properties>
</component>
<hspacer id="27f2a">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="a2f0" class="javax.swing.JButton" binding="connectButton" default-binding="true">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Connect"/>
</properties>
</component>
<component id="4214e" class="javax.swing.JComboBox" binding="gameSelectorBox">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="43a89" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Select game:"/>
</properties>
</component>
<component id="3874e" class="javax.swing.JLabel" binding="fillAllFields">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
@@ -116,6 +68,70 @@
<visible value="false"/>
</properties>
</component>
<component id="a2f0" class="javax.swing.JButton" binding="connectButton" default-binding="true">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Connect"/>
</properties>
</component>
<component id="6a4c6" class="javax.swing.JTextField" binding="ipTextField">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="4214e" class="javax.swing.JComboBox" binding="gameSelectorBox">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="4225c" class="javax.swing.JTextField" binding="portTextField">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="43a89" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Select game:"/>
</properties>
</component>
<component id="3abc3" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Port:"/>
</properties>
</component>
<component id="514db" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="IP:"/>
</properties>
</component>
<component id="5723c" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Name 2:"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@@ -4,7 +4,6 @@ import org.toop.eventbus.GlobalEventBus;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -13,6 +12,7 @@ import java.util.concurrent.ExecutionException;
public class GameSelectorWindow extends JFrame {
private JPanel mainMenu;
private JTextField nameTextField;
private JTextField name2TextField;
private JTextField ipTextField;
private JTextField portTextField;
private JButton connectButton;
@@ -40,7 +40,8 @@ public class GameSelectorWindow extends JFrame {
private void init() {
connectButton.addActionListener((ActionEvent e) -> {
if( !nameTextField.getText().isEmpty() &&
!ipTextField.getText().isEmpty() &&
!name2TextField.getText().isEmpty() &&
!ipTextField.getText().isEmpty() &&
!portTextField.getText().isEmpty()) {
CompletableFuture<String> serverIdFuture = new CompletableFuture<>();
@@ -73,7 +74,7 @@ public class GameSelectorWindow extends JFrame {
GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest( // TODO: Make this happen through commands send through the connection, instead of an event.
serverId,
nameTextField.getText(),
"P",
name2TextField.getText(),
ticTacToeGame
));
String ticTacToeGameId;
@@ -91,7 +92,7 @@ public class GameSelectorWindow extends JFrame {
frame.add(ttt.getTTTPanel());
frame.revalidate();
frame.repaint();
}else{
} else {
fillAllFields.setVisible(true);
}
});

View File

@@ -34,10 +34,10 @@ public class TcpServer implements Runnable {
protected final ExecutorService connectionExecutor = Executors.newCachedThreadPool();
// Shared queues for subclasses / consumers
public final BlockingQueue<String> receivedQueue = new LinkedBlockingQueue<>(); // unbounded; you may choose bounded
public final BlockingQueue<String> receivedQueue = new LinkedBlockingQueue<>();
public final BlockingQueue<String> sendQueue = new LinkedBlockingQueue<>();
// (Optional) if you want to associate sockets -> player ids
// Association for sockets -> player ids
public final Map<Socket, String> knownPlayers = new ConcurrentHashMap<>();
public final Map<String, String> playersGames = new ConcurrentHashMap<>();
@@ -157,7 +157,7 @@ public class TcpServer implements Runnable {
}
};
// Submit tasks - they will run on the shared connectionExecutor
// Input and Output mappings
connectionExecutor.submit(inputTask);
connectionExecutor.submit(outputTask);