Permalink
Browse files

prevent duplicate keys

  • Loading branch information...
cflavio committed Oct 10, 2018
1 parent 05c068f commit c9113e1e588e0d354b456f2834fcf553d659304e
Showing with 56 additions and 4 deletions.
  1. +39 −0 menu/already_dlg.py
  2. +17 −3 menu/inputpage.py
  3. +0 −1 project.py
View
@@ -0,0 +1,39 @@
from direct.gui.DirectDialog import OkDialog
from direct.gui.DirectGuiGlobals import FLAT
from yyagl.observer import Subject
from yyagl.gameobject import GameObject
class AlreadyUsedDlg(GameObject, Subject):
def __init__(self, menu_args, key, player, cmd):
Subject.__init__(self)
GameObject.__init__(self)
msg = _('The key %s is already used by player %s for %s.' % (
key, player, cmd))
self.dialog = OkDialog(
text=msg,
text_wordwrap=16,
text_fg=menu_args.text_active,
text_font=menu_args.font,
pad=(.03, .03),
topPad=0,
midPad=.01,
relief=FLAT,
frameColor=(.8, .8, .8, .9),
button_relief=FLAT,
button_frameColor=(.2, .2, .2, .2),
button_text_fg=menu_args.text_active,
button_text_font=menu_args.font,
command=self.on_btn)
self.eng.log('created dialog ' + self.dialog['text'])
def on_btn(self, val):
self.eng.log('already used')
self.notify('on_already_dlg')
def destroy(self):
self.eng.log('destroyed dialog ' + self.dialog['text'])
self.dialog = self.dialog.destroy()
Subject.destroy(self)
GameObject.destroy(self)
View
@@ -7,6 +7,7 @@
from yyagl.engine.joystick import JoystickMgr
from yyagl.gameobject import GameObject
from .thankspage import ThanksPageGui
from .already_dlg import AlreadyUsedDlg
class InputPageGui2(ThanksPageGui):
@@ -76,14 +77,14 @@ def _add_btn(self, text, pos_z):
def start_rec(self, btn):
numbers = [str(n) for n in range(10)]
self.keys = list(ascii_lowercase) + numbers + [
self._keys = list(ascii_lowercase) + numbers + [
'backspace', 'insert', 'home', 'page_up', 'num_lock', 'tab',
'delete', 'end', 'page_down', 'caps_lock', 'enter', 'arrow_left',
'arrow_up', 'arrow_down', 'arrow_right', 'lshift', 'rshift',
'lcontrol', 'lalt', 'space', 'ralt', 'rcontrol']
self.hint_lab.show()
acc = lambda key: self.mediator.event.accept(key, self.rec, [btn, key])
map(acc, self.keys)
map(acc, self._keys)
def _on_back(self):
self.mediator.event.on_back()
@@ -100,10 +101,23 @@ def _on_back(self):
self.notify('on_back', 'input_page2', [dct])
def rec(self, btn, val):
btn['text'] = val
used = self.already_used(val)
if used:
self.dial = AlreadyUsedDlg(self.menu_args, val, *used)
self.dial.attach(self.on_already_dlg)
else: btn['text'] = val
self.hint_lab.hide()
map(self.mediator.event.ignore, self.keys)
def on_already_dlg(self): self.dial = self.dial.destroy()
def already_used(self, val):
labels = ['forward', 'rear', 'left', 'right', 'fire', 'respawn', 'pause']
for i, btn in enumerate(self.mediator.gui.ibuttons):
if btn['text'] == val: return '1', labels[i]
for lab in labels[:-1]:
if self.keys[lab + '2'] == val: return '2', lab
class InputPageGui1(InputPageGui2):
View
@@ -4,7 +4,6 @@
# TODO LIST =====
# 0.11 (local multiplayer)
# prevent duplicate keys
# use raw keys as default ones
# supporting up to four players

0 comments on commit c9113e1

Please sign in to comment.