Commit f7a1b92e authored by Agrigor's avatar Agrigor

Conditions for Enabling of the start button implemented correctly

parent bf202ccd
......@@ -19,6 +19,7 @@ from PyQt4.uic import *
PORT = 50000
IP = "127.0.0.1"
PLAYERS_MAX = 4
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~ CLASS DEFINITION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -94,6 +95,11 @@ class StartGUI:
self.socketCreated = socketCreated
self.players = players
self.players_ready = [False] * PLAYERS_MAX
self.playerInputs = [self.__UI_Start.I_NamePlayer1,
self.__UI_Start.I_NamePlayer2,
self.__UI_Start.I_NamePlayer3,
self.__UI_Start.I_NamePlayer4]
self.__UI_Start.connect(self.__UI_Start.I_Connect, SIGNAL("clicked()"), self.connect)
self.__UI_Start.connect(self.__UI_Start.I_Start, SIGNAL("clicked()"), self.start)
......@@ -106,29 +112,27 @@ class StartGUI:
self.__UI_Start.show()
def name_player_changed(self, name):
sender = self.__UI_Start.sender()
self.__UI_Start.O_Msg.setText(str(sender.text()))
# TODO
if len(str(sender.text())) > 1:
for i in range(len(self.playerInputs)):
if i + 1 > int(self.__UI_Start.O_NumberOfPlayers.text()) or len(self.playerInputs[i].text()) > 1:
self.players_ready[i] = True
else:
self.players_ready[i] = False
if all(self.players_ready):
self.__UI_Start.I_Start.setDisabled(False)
else:
self.__UI_Start.I_Start.setDisabled(True)
def show_names_input_field(self, number):
number -= 1
playerInputs = [self.__UI_Start.I_NamePlayer1,
self.__UI_Start.I_NamePlayer2,
self.__UI_Start.I_NamePlayer3,
self.__UI_Start.I_NamePlayer4]
for i in range(len(playerInputs)):
for i in range(len(self.playerInputs)):
if i <= number and self.socketCreated:
playerInputs[i].setDisabled(False)
self.playerInputs[i].setDisabled(False)
else:
playerInputs[i].setDisabled(True)
self.playerInputs[i].setDisabled(True)
if number >= 1:
self.__UI_Start.O_Msg.setText(str(number + 1) + " Players")
self.show_msg(str(number + 1) + " Players")
else:
self.__UI_Start.O_Msg.setText("1 Player")
self.show_msg("1 Player")
def start(self):
namesOfPlayers = [str(self.__UI_Start.I_NamePlayer1.text()),
......@@ -144,13 +148,17 @@ class StartGUI:
self.UDP.create_client_socket()
self.socketCreated = True
self.__UI_Start.I_Connect.setDisabled(True)
self.__UI_Start.O_Msg.setText("Connected")
self.__UI_Start.I_IPAdress.setDisabled(True)
self.show_msg("Connected")
self.__UI_Start.I_NumberOfPlayers.setDisabled(False)
self.__UI_Start.I_NamePlayer1.setDisabled(False)
else:
self.__UI_Start.O_Msg.setText("No valid IP-address")
self.show_msg("No valid IP-address")
self.socketCreated = False
def show_msg(self, msg):
self.__UI_Start.O_Msg.setText(msg)
def cleanup(self):
if self.socketCreated:
self.UDP.cleanup()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment