Commit a9343d84 authored by Agrigor's avatar Agrigor

New Main_GUI, new dialog structure, new Change_Name dialog, new Change_Points...

New Main_GUI, new dialog structure, new Change_Name dialog, new Change_Points dialog and a lot of other improvements
parent 42e0ebb2
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Names</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="name_player_1"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_player_4">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="name_player_3">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_player_1">
<property name="text">
<string>Player 1</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_player_2">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_player_3">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="name_player_2">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="name_player_4">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>name_player_1</tabstop>
<tabstop>name_player_2</tabstop>
<tabstop>name_player_3</tabstop>
<tabstop>name_player_4</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Points</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="label_player_4">
<property name="text">
<string>Player 4</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_player_1">
<property name="text">
<string>Player 1</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_player_2">
<property name="text">
<string>Player 2</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_player_3">
<property name="text">
<string>Player 3</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="points_player_1">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="points_player_2">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="points_player_3">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="points_player_4">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="maximum">
<number>9900</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>points_player_1</tabstop>
<tabstop>points_player_2</tabstop>
<tabstop>points_player_3</tabstop>
<tabstop>points_player_4</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
This diff is collapsed.
......@@ -2,32 +2,23 @@
<ui version="4.0">
<class>StartGUI</class>
<widget class="QDialog" name="StartGUI">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>339</width>
<height>299</height>
<width>300</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>339</width>
<height>299</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>339</width>
<height>299</height>
</size>
</property>
<property name="windowTitle">
<string>Hacker Jeopardy</string>
</property>
......@@ -52,17 +43,20 @@
<string>IPv4-Adresse</string>
</property>
<property name="text">
<string/>
<string>127.0.0.1</string>
</property>
<property name="maxLength">
<number>32767</number>
</property>
<property name="cursorPosition">
<number>0</number>
<number>9</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="placeholderText">
<string>127.0.0.1</string>
</property>
</widget>
</item>
</layout>
......@@ -172,18 +166,18 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="I_Start">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Start Game</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="I_Start">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Start Game</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
......@@ -214,7 +208,6 @@
<tabstop>I_NamePlayer2</tabstop>
<tabstop>I_NamePlayer3</tabstop>
<tabstop>I_NamePlayer4</tabstop>
<tabstop>I_Start</tabstop>
</tabstops>
<resources/>
<connections>
......
......@@ -62,47 +62,50 @@ class Player:
class GUI:
def __init__(self):
self.app = QApplication(sys.argv)
self.start = StartGUI()
sys.exit(self.app.exec_())
self.start = MainGUI()
sys.exit(self.app.exec())
class StartGUI(QDialog):
def __init__(self):
def __init__(self, socket, players, UI_Main):
QDialog.__init__(self)
self.UI_Start = loadUi("GUIs/start.ui", self)
self.players = [Player() for i in range(PLAYERS_MAX)]
self.player_name_entered = [False] * PLAYERS_MAX
self.socket = socket
self.players = players
self.UI_Main = UI_Main
self.playerNameEntered = [False] * PLAYERS_MAX
self.playerNameInputs = [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_server)
self.UI_Start.connect(self.UI_Start.I_Connect, SIGNAL("clicked()"), self.connectServer)
self.UI_Start.connect(self.UI_Start.I_Start, SIGNAL("clicked()"), self.start)
self.UI_Start.connect(self.UI_Start.I_NumberOfPlayers, SIGNAL("valueChanged(int)"), self.show_names_input_field)
self.UI_Start.connect(self.UI_Start.I_NamePlayer1, SIGNAL("textChanged(QString)"), self.name_player_changed)
self.UI_Start.connect(self.UI_Start.I_NamePlayer2, SIGNAL("textChanged(QString)"), self.name_player_changed)
self.UI_Start.connect(self.UI_Start.I_NamePlayer3, SIGNAL("textChanged(QString)"), self.name_player_changed)
self.UI_Start.connect(self.UI_Start.I_NamePlayer4, SIGNAL("textChanged(QString)"), self.name_player_changed)
self.UI_Start.connect(self.UI_Start.I_NumberOfPlayers, SIGNAL("valueChanged(int)"), self.showNamesInputField)
self.UI_Start.connect(self.UI_Start.I_NamePlayer1, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer2, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer3, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.UI_Start.connect(self.UI_Start.I_NamePlayer4, SIGNAL("textChanged(QString)"), self.namePlayerChanged)
self.killSocket = True
self.UI_Start.show()
def connect_server(self):
self.socket = Comunication(str(self.UI_Start.I_IPAdress.text()), PORT)
def connectServer(self):
self.socket.ip = str(self.UI_Start.I_IPAdress.text())
if self.socket.check_ip():
self.socket.create_client_socket()
self.UI_Start.I_Connect.setDisabled(True)
self.UI_Start.I_IPAdress.setDisabled(True)
self.show_msg("Connected")
self.showMsg("Connected")
self.UI_Start.I_NumberOfPlayers.setDisabled(False)
self.UI_Start.I_NamePlayer1.setDisabled(False)
else:
self.show_msg("No valid IP-address")
self.showMsg("No valid IP-address")
def show_names_input_field(self, number):
def showNamesInputField(self, number):
number -= 1
for i in range(len(self.playerNameInputs)):
if i <= number:
......@@ -110,17 +113,18 @@ class StartGUI(QDialog):
else:
self.playerNameInputs[i].setDisabled(True)
if number >= 1:
self.show_msg(str(number + 1) + " Players")
self.showMsg(str(number + 1) + " Players")
else:
self.show_msg("1 Player")
self.showMsg("1 Player")
def name_player_changed(self, name):
def namePlayerChanged(self, name):
for i in range(len(self.playerNameInputs)):
if i + 1 > int(self.UI_Start.O_NumberOfPlayers.text()) or len(self.playerNameInputs[i].text()) > 1:
self.player_name_entered[i] = True
if i + 1 > int(self.UI_Start.O_NumberOfPlayers.text()) or len(self.playerNameInputs[i].text()) > 0:
self.playerNameEntered[i] = True
else:
self.player_name_entered[i] = False
if all(self.player_name_entered):
self.playerNameEntered[i] = False
if all(self.playerNameEntered):
self.UI_Start.I_Start.setDisabled(False)
else:
self.UI_Start.I_Start.setDisabled(True)
......@@ -130,13 +134,51 @@ class StartGUI(QDialog):
str(self.UI_Start.I_NamePlayer2.text()),
str(self.UI_Start.I_NamePlayer3.text()),
str(self.UI_Start.I_NamePlayer4.text())]
for i in range(0, int(self.UI_Start.O_NumberOfPlayers.text())):
for i in range(PLAYERS_MAX):
self.players[i].name = namesOfPlayers[i]
self.main = MainGUI(self.socket, self.players)
self.players[i].points = 0
self.killSocket = False
self.setupPlayersView()
self.UI_Start.close()
def show_msg(self, msg):
def setupPlayersView(self):
if self.players[0].name:
self.UI_Main.Name_P1.setVisible(True)
self.UI_Main.Name_P1.setText(self.players[0].name)
self.UI_Main.Points_P1.setVisible(True)
self.UI_Main.Points_P1.display(self.players[0].points)
else:
self.UI_Main.Name_P1.setVisible(False)
self.UI_Main.Points_P1.setVisible(False)
if self.players[1].name:
self.UI_Main.Name_P2.setVisible(True)
self.UI_Main.Name_P2.setText(self.players[1].name)
self.UI_Main.Points_P2.setVisible(True)
self.UI_Main.Points_P2.display(self.players[1].points)
else:
self.UI_Main.Name_P2.setVisible(False)
self.UI_Main.Points_P2.setVisible(False)
if self.players[2].name:
self.UI_Main.Name_P3.setVisible(True)
self.UI_Main.Name_P3.setText(self.players[2].name)
self.UI_Main.Points_P3.setVisible(True)
self.UI_Main.Points_P3.display(self.players[2].points)
else:
self.UI_Main.Name_P3.setVisible(False)
self.UI_Main.Points_P3.setVisible(False)
if self.players[3].name:
self.UI_Main.Name_P4.setVisible(True)
self.UI_Main.Name_P4.setText(self.players[3].name)
self.UI_Main.Points_P4.setVisible(True)
self.UI_Main.Points_P4.display(self.players[3].points)
else:
self.UI_Main.Name_P4.setVisible(False)
self.UI_Main.Points_P4.setVisible(False)
def showMsg(self, msg):
self.UI_Start.O_Msg.setText(msg)
def closeEvent(self, event):
......@@ -147,38 +189,124 @@ class StartGUI(QDialog):
pass
class MainGUI(QMainWindow):
def __init__(self, socket, players):
QMainWindow.__init__(self)
self.UI_Main = loadUi("GUIs/main.ui", self)
class ChangeNamesGUI(QDialog):
def __init__(self, players, UI_Main):
QDialog.__init__(self)
self.players = players
self.UI_Main = UI_Main
self.UI_ChangeNames = loadUi("GUIs/change_names.ui")
self.UI_ChangeNames.buttonBox.accepted.connect(self.accept)
self.UI_ChangeNames.buttonBox.rejected.connect(self.reject)
if self.players[0].name:
self.UI_ChangeNames.name_player_1.setDisabled(False)
self.UI_ChangeNames.name_player_1.setText(self.players[0].name)
else:
self.UI_ChangeNames.name_player_1.setDisabled(True)
if self.players[1].name:
self.UI_ChangeNames.name_player_2.setDisabled(False)
self.UI_ChangeNames.name_player_2.setText(self.players[1].name)
else:
self.UI_ChangeNames.name_player_2.setDisabled(True)
if self.players[2].name:
self.UI_ChangeNames.name_player_3.setDisabled(False)
self.UI_ChangeNames.name_player_3.setText(self.players[2].name)
else:
self.UI_ChangeNames.name_player_3.setDisabled(True)
if self.players[3].name:
self.UI_ChangeNames.name_player_4.setDisabled(False)
self.UI_ChangeNames.name_player_4.setText(self.players[3].name)
else:
self.UI_ChangeNames.name_player_4.setDisabled(True)
self.socket = socket
self.UI_ChangeNames.show()
def accept(self):
self.players[0].name = self.UI_ChangeNames.name_player_1.text()
self.players[1].name = self.UI_ChangeNames.name_player_2.text()
self.players[2].name = self.UI_ChangeNames.name_player_3.text()
self.players[3].name = self.UI_ChangeNames.name_player_4.text()
self.UI_Main.Name_P1.setText(self.players[0].name)
self.UI_Main.Name_P2.setText(self.players[1].name)
self.UI_Main.Name_P3.setText(self.players[2].name)
self.UI_Main.Name_P4.setText(self.players[3].name)
def reject(self):
pass
class ChangePointsGUI(QDialog):
def __init__(self, players, UI_Main):
QDialog.__init__(self)
self.players = players
self.UI_Main = UI_Main
self.UI_ChangePoints = loadUi("GUIs/change_points.ui")
self.UI_ChangePoints.buttonBox.accepted.connect(self.accept)
self.UI_ChangePoints.buttonBox.rejected.connect(self.reject)
if self.players[0].name:
self.UI_ChangePoints.points_player_1.setDisabled(False)
self.UI_ChangePoints.points_player_1.setValue(self.players[0].points)
else:
self.UI_ChangePoints.points_player_1.setDisabled(True)
if self.players[1].name:
self.UI_ChangePoints.points_player_2.setDisabled(False)
self.UI_ChangePoints.points_player_2.setValue(self.players[1].points)
else:
self.UI_ChangePoints.points_player_2.setDisabled(True)
if self.players[2].name:
self.UI_ChangePoints.points_player_3.setDisabled(False)
self.UI_ChangePoints.points_player_3.setValue(self.players[2].points)
else:
self.UI_ChangePoints.points_player_3.setDisabled(True)
if self.players[3].name:
self.UI_ChangePoints.points_player_4.setDisabled(False)
self.UI_ChangePoints.points_player_4.setValue(self.players[3].points)
else:
self.UI_ChangePoints.points_player_4.setDisabled(True)
self.UI_ChangePoints.show()
def accept(self):
self.players[0].points = self.UI_ChangePoints.points_player_1.value()
self.players[1].points = self.UI_ChangePoints.points_player_2.value()
self.players[2].points = self.UI_ChangePoints.points_player_3.value()
self.players[3].points = self.UI_ChangePoints.points_player_4.value()
self.UI_Main.Points_P1.display(self.players[0].points)
self.UI_Main.Points_P2.display(self.players[1].points)
self.UI_Main.Points_P3.display(self.players[2