port can now be changed
This commit is contained in:
parent
8b296f6965
commit
58287a0649
5 changed files with 41 additions and 7 deletions
|
@ -35,6 +35,35 @@ class RoomCreate(Scene):
|
||||||
from source.gui.scene import MainMenu
|
from source.gui.scene import MainMenu
|
||||||
self.back.add_listener("on_click_release", lambda *_: self.window.set_scene(MainMenu))
|
self.back.add_listener("on_click_release", lambda *_: self.window.set_scene(MainMenu))
|
||||||
|
|
||||||
|
# Port
|
||||||
|
|
||||||
|
self.add_widget(
|
||||||
|
widget.Text,
|
||||||
|
|
||||||
|
x=0.1, y=0.65,
|
||||||
|
|
||||||
|
anchor_x="center", anchor_y="center",
|
||||||
|
|
||||||
|
text="Port",
|
||||||
|
|
||||||
|
batch=self.batch_label
|
||||||
|
)
|
||||||
|
|
||||||
|
self.input_port = self.add_widget(
|
||||||
|
widget.Input,
|
||||||
|
|
||||||
|
x=0.2, y=0.60, width=0.15, height=0.1,
|
||||||
|
|
||||||
|
style=texture.Input.Style1,
|
||||||
|
|
||||||
|
regex=r"\d{1,5}",
|
||||||
|
|
||||||
|
label_text="52321",
|
||||||
|
|
||||||
|
background_batch=self.batch_input_background,
|
||||||
|
label_batch=self.batch_label
|
||||||
|
)
|
||||||
|
|
||||||
# Username
|
# Username
|
||||||
|
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
|
@ -264,6 +293,8 @@ class RoomCreate(Scene):
|
||||||
self.start.add_listener("on_click_release", lambda *_: self.confirm())
|
self.start.add_listener("on_click_release", lambda *_: self.confirm())
|
||||||
|
|
||||||
def confirm(self):
|
def confirm(self):
|
||||||
|
port = int(self.input_port.text)
|
||||||
|
|
||||||
settings = PacketSettings(
|
settings = PacketSettings(
|
||||||
username=self.input_username.text,
|
username=self.input_username.text,
|
||||||
grid_width=int(self.input_width.text),
|
grid_width=int(self.input_width.text),
|
||||||
|
@ -272,7 +303,7 @@ class RoomCreate(Scene):
|
||||||
boats_length=[size for size, quantity in self.boat_size_amount.items() for _ in range(quantity)]
|
boats_length=[size for size, quantity in self.boat_size_amount.items() for _ in range(quantity)]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.window.set_scene(RoomHost, settings=settings)
|
self.window.set_scene(RoomHost, port=port, settings=settings)
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
self.batch_input_background.draw()
|
self.batch_input_background.draw()
|
||||||
|
|
|
@ -14,11 +14,11 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
class RoomHost(Scene):
|
class RoomHost(Scene):
|
||||||
def __init__(self, window: "Window", settings: "PacketSettings", **kwargs):
|
def __init__(self, window: "Window", port: int, settings: "PacketSettings", **kwargs):
|
||||||
super().__init__(window, **kwargs)
|
super().__init__(window, **kwargs)
|
||||||
|
|
||||||
self.ip_address: str = "127.0.0.1"
|
self.ip_address: str = "127.0.0.1"
|
||||||
self.port: int = 52321
|
self.port: int = port
|
||||||
|
|
||||||
self.batch_button_background = pyglet.graphics.Batch()
|
self.batch_button_background = pyglet.graphics.Batch()
|
||||||
self.batch_label = pyglet.graphics.Batch()
|
self.batch_label = pyglet.graphics.Batch()
|
||||||
|
@ -59,7 +59,7 @@ class RoomHost(Scene):
|
||||||
batch=self.batch_label
|
batch=self.batch_label
|
||||||
)
|
)
|
||||||
|
|
||||||
self.thread_network = network.Host(window=self.window, daemon=True, settings=settings)
|
self.thread_network = network.Host(window=self.window, daemon=True, port=self.port, settings=settings)
|
||||||
self.thread_network.start()
|
self.thread_network.start()
|
||||||
|
|
||||||
self._refresh_ip_text()
|
self._refresh_ip_text()
|
||||||
|
|
|
@ -66,7 +66,9 @@ class RoomJoin(Scene):
|
||||||
widget.Input,
|
widget.Input,
|
||||||
x=0.53, y=0.45, width=0.07, height=0.1,
|
x=0.53, y=0.45, width=0.07, height=0.1,
|
||||||
|
|
||||||
regex=r"\d{0,5}",
|
regex=r"\d{1,5}",
|
||||||
|
|
||||||
|
label_text="52321",
|
||||||
|
|
||||||
style=texture.Input.Style1,
|
style=texture.Input.Style1,
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ class RoomJoin(Scene):
|
||||||
network.Client(
|
network.Client(
|
||||||
window=self.window,
|
window=self.window,
|
||||||
ip_address=self.entry_ip.text,
|
ip_address=self.entry_ip.text,
|
||||||
|
port=int(self.entry_port.text),
|
||||||
daemon=True,
|
daemon=True,
|
||||||
username=self.entry_username.text
|
username=self.entry_username.text
|
||||||
).start()
|
).start()
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Client(StoppableThread):
|
||||||
The thread executed on the person who join a room.
|
The thread executed on the person who join a room.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, window: "Window", username: str, ip_address: str, port: int = 52321, **kw):
|
def __init__(self, window: "Window", username: str, ip_address: str, port: int, **kw):
|
||||||
super().__init__(**kw)
|
super().__init__(**kw)
|
||||||
|
|
||||||
self.window = window
|
self.window = window
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Host(StoppableThread):
|
||||||
The thread executed on the person who create a room.
|
The thread executed on the person who create a room.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, window: "Window", settings: "PacketSettings", port: int = 52321, **kw):
|
def __init__(self, window: "Window", port: int, settings: "PacketSettings", **kw):
|
||||||
super().__init__(**kw)
|
super().__init__(**kw)
|
||||||
|
|
||||||
self.window = window
|
self.window = window
|
||||||
|
|
Loading…
Reference in a new issue