Skip to content

Commit

Permalink
feat(UI-UX): Qality of life feature
Browse files Browse the repository at this point in the history
- Larger playfield now below player info
- Menu button to get back on config screen for local multiplayer
- error message when a profile is created with a name already in use
- binding of enter key in profile creation
- correct focus on creating and editing a profile
  • Loading branch information
HOOK-Hawkins committed Mar 17, 2024
1 parent b5970dd commit a3f9723
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion UI/field_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _display_widgets(self):
self.heading.grid(row=0, column=0, columnspan=3)
self.player[0].grid(row=1, column=0)
self.player[1].grid(row=1, column=2)
self.gamefield.grid(sticky=tk.N+tk.S+tk.E+tk.W, row=2, column=1)
self.gamefield.grid(sticky=tk.N+tk.S+tk.E+tk.W, row=2, column=0, columnspan=3)
if(hasattr(self, 'chat')):
self.columnconfigure(3, weight=1)
self.chat.grid(sticky=tk.N+tk.S+tk.E+tk.W, row=1, column=3, rowspan=3)
Expand Down
6 changes: 6 additions & 0 deletions UI/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _create_widgets(self):
self.drpPlayer2 = tk.OptionMenu(self, self.varPlayer2, *[o.display_name for o in self.master.players])
self.btnnew = tk.Button(self, text='New Profile', command=lambda *args: self.master.show(NewProfile, return_to=LocalProfileSelection))
self.btnStart = tk.Button(self, text='Start', command=lambda *args: self._start_game())
self.btnMenu = tk.Button(self, text='Menu', command=lambda: self.master.show_menu())

def _display_widgets(self):
self.columnconfigure([0, 6], weight=1)
Expand All @@ -118,6 +119,7 @@ def _display_widgets(self):
self.drpPlayer2.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=3, row=4, columnspan=2)
self.btnnew.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=2, row=5)
self.btnStart.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=4, row=5, columnspan=2)
self.btnMenu.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=5, row=1)

def _start_game(self):
if(self.varPlayer1.get() == 'Select' or self.varPlayer2.get() == 'Select' or self.varPlayer1.get() == self.varPlayer2.get()):
Expand All @@ -142,6 +144,7 @@ def __init__(self, master):
super().__init__(master)
self._create_widgets()
self._display_widgets()
self.master.master.network_events['lobby/connect'] = self._lobby_connect

def _create_widgets(self):
self.frame = tk.Frame(self)
Expand Down Expand Up @@ -177,6 +180,9 @@ def _connect(self):
root = self.master.master
root.out_queue = {root.players[root.player].uuid: Queue()}
root.network_client = client_thread(root, in_queue=list(root.out_queue.values())[0], out_queue=root.in_queue, player=root.players[root.player], ip=self.etrAddress.get())

def _lobby_connect(self, queue):
root = self.master.master
root.show(Join, local_players=[root.players[root.player].uuid])

class Multiplayer(base_frame):
Expand Down
11 changes: 11 additions & 0 deletions UI/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .field_frame import Field
from Server.player import Player
from Client.profile_save import Profile as ProfileIO
from .messages import messages

class NewProfile(base_frame):
def __init__(self, master, *args, **kwargs):
Expand All @@ -16,6 +17,7 @@ def __init__(self, master, *args, **kwargs):
self.id = kwargs.pop('id', None)
self._create_widgets()
self._display_widgets()
self.etrName.focus_set()

def _create_widgets(self):
task = 'Edit' if self.edit else 'Create'
Expand All @@ -25,6 +27,7 @@ def _create_widgets(self):
self.etrName.val = self.master.players[self.master.player].display_name if self.edit else ''
self.btnCreate = tk.Button(self, text=f'{task} profile', command=lambda *args: self._create())
self.btnMenu = tk.Button(self, text='Menu', command=lambda: self.master.show_menu())
self.master.bind('<Return>', lambda *args: self._enter())

def _display_widgets(self):
self.columnconfigure([0, 10], weight=1)
Expand All @@ -45,7 +48,15 @@ def _display_widgets(self):
self.btnCreate.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=6, row=8, columnspan=3)
self.btnMenu.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=9, row=1)

def _enter(self):
if(self.focus_get() == self.etrName.widget):
self._create()

def _create(self):
if(self.etrName.val in [p.display_name for p in self.master.players]):
msg = messages(type='info', message='This name is already in use.\nPlease select a differnt name!')
msg.display()
return
if(self.edit):
for i, player in enumerate(self.master.players):
if player.uuid == self.master.players[self.master.player].uuid:
Expand Down

0 comments on commit a3f9723

Please sign in to comment.