def build(self): menu_props = self.menu_props widgets = [] suff = str(self.joyp_idx + 1) player_lab = Label(text=_('Player') + ' ' + suff, pos=(0, .9), tra_src='Player' + ' ' + suff, tra_tra=_('Player') + ' ' + suff, **menu_props.label_args) buttons_data = [(_('Accelerate'), 'forward' + suff, .5), (_('Brake/Reverse'), 'rear' + suff, .32), (_('Weapon'), 'fire' + suff, .14), (_('Respawn'), 'respawn' + suff, -.04)] for btn_data in buttons_data: widgets += [self._add_lab(btn_data[0], btn_data[2])] widgets += [self._add_btn(self.keys[btn_data[1]], btn_data[2])] l_a = menu_props.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label(text=_('Press the key to record it'), pos=(-.2, -.6), **l_a) self.hint_lab.hide() widgets += [player_lab, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self)
def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb, usr_name, tooltip): GameObject.__init__(self) self.owner = owner lab_args = menu_props.label_args lab_args['scale'] = .046 #lab_args['text_fg'] = menu_props.text_normal_col self.btn = ImgBtn(parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb, extra_args=[usr_name], **menu_props.imgbtn_args) self.btn.bind(ENTER, self.on_enter) self.btn.bind(EXIT, self.on_exit) self.tooltip_btn = Btn(parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None, **menu_props.imgbtn_args) self.tooltip_btn.bind(ENTER, self.on_enter) self.tooltip_btn.bind(EXIT, self.on_exit) self.on_create() self.tooltip = Label(text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset, parent=parent, text_wordwrap=10, text_align=self.tooltip_align, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide()
def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb, usr_name, tooltip): GameObject.__init__(self) self.owner = owner lab_args = menu_props.label_args lab_args['scale'] = .046 #lab_args['text_fg'] = menu_props.text_normal_col self.btn = ImgBtn( parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb, extra_args=[usr_name], **menu_props.imgbtn_args) self.btn.bind(ENTER, self.on_enter) self.btn.bind(EXIT, self.on_exit) self.tooltip_btn = Btn( parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None, **menu_props.imgbtn_args) self.tooltip_btn.bind(ENTER, self.on_enter) self.tooltip_btn.bind(EXIT, self.on_exit) self.on_create() self.tooltip = Label( text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset, parent=parent, text_wordwrap=10, text_align=self.tooltip_align, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide()
def __init__(self, menu_props, room): MatchFrm.__init__(self, menu_props, room) lab_args = menu_props.label_args lab_args['scale'] = .046 self.client_lab = Label( text=_('please wait for the server'), pos=(1.68, .03), parent=self.match_frm, text_wordwrap=36, **lab_args)
def __init__(self, name, parent, menu_props, is_supporter): GameObject.__init__(self) self.menu_props = menu_props self.name = name self.parent = parent lab_args = menu_props.label_args lab_args['scale'] = .046 self.lab = Label(text=name, pos=(0, 0), parent=parent, text_wordwrap=64, text_align=TextNode.A_left, **lab_args) self.supp_btn = None self.set_supporter(is_supporter) self.set_online(True)
def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created match message form') self.chat = None self.msg_frm = Frame( frame_size=(-.02, 3.49, 0, 1.22), frame_col=(.2, .2, .2, .5), pos=(.04, -1.69), parent=base.a2dTopLeft) t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = Text( txt='', pos=(0, 1.16), parent=self.msg_frm, align='left', **t_a) self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = ScrolledFrame( frame_sz=(-.02, 2.46, -.02, 1.02), canvas_sz=(-.02, 2.42, -.02, 1.02), scrollbar_width=.036, frame_col=(1, 1, 1, .0), pos=(.02, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = Text( txt='', pos=(0, .24), parent=self.txt_frm.canvas, align='left', wordwrap=52, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, 2.5, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1.15), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50, text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() self.eng.client.attach(self.on_groupchat_msg)
class UserLabel(GameObject): def __init__(self, name, parent, menu_props, is_supporter): GameObject.__init__(self) self.menu_props = menu_props self.name = name self.parent = parent lab_args = menu_props.label_args lab_args['scale'] = .046 self.lab = Label(text=name, pos=(0, 0), parent=parent, text_wordwrap=64, text_align=TextNode.A_left, **lab_args) self.supp_btn = None self.set_supporter(is_supporter) self.set_online(True) @property def widgets(self): return [self.lab] + ([self.supp_btn] if self.supp_btn else []) def on_enter(self, pos): self.lab['text_fg'] = self.menu_props.text_active_col def on_exit(self, pos): self.lab['text_fg'] = self.menu_props.text_normal_col def set_supporter(self, is_supporter): if is_supporter: self.lab.set_x(.03) self.supp_btn = StaticMPBtn(self.parent, self, self.menu_props, 'assets/images/gui/medal.txo', .01, None, self.name, _('Supporter!')) else: self.lab.set_x(0) if self.supp_btn: self.supp_btn = self.supp_btn.destroy() def set_online(self, val=None): self.is_online = val self.lab.set_alpha_scale(1 if self.is_online else .4) def destroy(self): self.lab.destroy() if self.supp_btn: self.supp_btn.destroy() GameObject.destroy(self)
def __init__(self, menu_props, yorg_srv): GameObject.__init__(self) self.eng.log('create users form') self.ver_check = VersionChecker() self.yorg_srv = yorg_srv self.room_name = None self.labels = [] self.invited_users = [] self.menu_props = menu_props lab_args = menu_props.label_args lab_args['scale'] = .046 self.users_lab = Label( text=_('Current online users'), pos=(-.85, -.02), hpr=(0, 0, -90), parent=base.a2dTopRight, text_align=TextNode.A_right, **lab_args) self.frm = DirectScrolledFrame( frameSize=(-.02, .8, .45, 2.43), canvasSize=(-.02, .76, -.08, 3.8), scrollBarWidth=.036, verticalScroll_relief=FLAT, verticalScroll_frameColor=(.2, .2, .2, .4), verticalScroll_thumb_relief=FLAT, verticalScroll_thumb_frameColor=(.8, .8, .8, .6), verticalScroll_incButton_relief=FLAT, verticalScroll_incButton_frameColor=(.8, .8, .8, .6), verticalScroll_decButton_relief=FLAT, verticalScroll_decButton_frameColor=(.8, .8, .8, .6), horizontalScroll_relief=FLAT, frameColor=(.2, .2, .2, .5), pos=(-.82, 1, -2.44), parent=base.a2dTopRight) self.conn_lab = Label( text='', pos=(.38, 1.5), parent=self.frm, text_wordwrap=10, **lab_args) self.set_connection_label() self.in_match_room = None self.invited = False
def __add_lab(self, txt, txt_tr, pos_z, pos_x=-.1, align=TextNode.ARight, scale=None): l_a = self.menu_props.label_args l_a['scale'] = scale or l_a['scale'] lab = Label(text='', pos=(pos_x, pos_z), text_align=align, tra_src=txt, tra_tra=txt_tr, **l_a) return lab
def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created match message form') self.chat = None self.msg_frm = Frame( frame_size=(-.02, 3.49, 0, 1.22), frame_col=(.2, .2, .2, .5), pos=(.04, -1.69), parent=base.a2dTopLeft) t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = Text( txt='', pos=(0, 1.16), parent=self.msg_frm, align='left', **t_a) self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = ScrolledFrame( frame_sz=(-.02, 2.46, -.02, 1.02), canvas_sz=(-.02, 2.42, -.02, 1.02), scrollbar_width=.036, frame_col=(1, 1, 1, .0), pos=(.02, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = Text( txt='', pos=(0, .24), parent=self.txt_frm.canvas, align='left', wordwrap=52, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, 2.5, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1.15), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50, text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide()
def build(self): sp_cb = lambda: self.notify('on_push_page', 'singleplayer', [self.props]) mp_cb = lambda: self.notify('on_push_page', 'multiplayer', [self.props]) supp_cb = lambda: self.eng.open_browser(self.props.support_url) cred_cb = lambda: self.notify('on_push_page', 'credits') menu_data = [('Single Player', _('Single Player'), sp_cb), ('Multiplayer', _('Multiplayer'), mp_cb), ('Options', _('Options'), self.on_options), ('Support us', _('Support us'), supp_cb), ('Credits', _('Credits'), cred_cb), ('Quit', _('Quit'), lambda: self.notify('on_exit'))] widgets = [ Btn(text='', pos=(0, .64 - i * .23), cmd=menu[2], tra_src=menu_data[i][0], tra_tra=menu_data[i][1], **self.props.gameprops.menu_props.btn_args) for i, menu in enumerate(menu_data) ] logo_img = Img(self.props.title_img, scale=(.64, 1, .64 * (380.0 / 772)), parent=base.a2dTopLeft, pos=(.65, -.32)) widgets += [logo_img] lab_args = self.props.gameprops.menu_props.label_args lab_args['scale'] = .12 lab_args['text_fg'] = self.props.gameprops.menu_props.text_err_col wip_lab = Label(text='', pos=(-.05, -1.58), parent=base.a2dTopRight, text_wordwrap=10, text_align=TextNode.A_right, tra_src='Note: the game is work-in-progress', tra_tra=_('Note: the game is work-in-progress'), **lab_args) self.widgets += [wip_lab] self.add_widgets(widgets) self.set_news() MainPageGui.build(self) if not self.ver_check.is_uptodate(): self.widgets[2]['state'] = DISABLED
class UserLabel(GameObject): def __init__(self, name, parent, menu_props, is_supporter): GameObject.__init__(self) self.menu_props = menu_props self.name = name self.parent = parent lab_args = menu_props.label_args lab_args['scale'] = .046 self.lab = Label(text=name, pos=(0, 0), parent=parent, text_wordwrap=64, text_align=TextNode.A_left, **lab_args) self.supp_btn = None self.set_supporter(is_supporter) self.set_online(True) @property def widgets(self): return [self.lab] + ([self.supp_btn] if self.supp_btn else []) def on_enter(self, pos): self.lab['text_fg'] = self.menu_props.text_active_col def on_exit(self, pos): self.lab['text_fg'] = self.menu_props.text_normal_col def set_supporter(self, is_supporter): if is_supporter: self.lab.set_x(.03) self.supp_btn = StaticMPBtn( self.parent, self, self.menu_props, 'assets/images/gui/medal.txo', .01, None, self.name, _('Supporter!')) else: self.lab.set_x(0) if self.supp_btn: self.supp_btn = self.supp_btn.destroy() def set_online(self, val=None): self.is_online = val self.lab.set_alpha_scale(1 if self.is_online else .4) def destroy(self): self.lab.destroy() if self.supp_btn: self.supp_btn.destroy() GameObject.destroy(self)
def build(self): lab_args = self.menu_props.label_args lab_args['scale'] = .046 self.users_lab = Label(text=_('Current waiting hosting users'), pos=(.02, -.05), parent=base.a2dTopLeft, text_wordwrap=48, text_align=TextNode.A_left, **lab_args) self.frm = ScrolledFrame(frame_sz=(-.02, 3.49, .7, 2.43), canvas_sz=(-.02, 2.56, -.08, 3.8), scrollbar_width=.036, frame_col=(.2, .2, .2, .5), pos=(.04, -2.5), parent='topleft') widgets = [self.users_lab, self.frm] self.add_widgets(widgets) ThanksPageGui.build(self) self.labels = [] self.invited_users = [] self.on_update_hosting()
def build(self): menu_props = self.menu_props widgets = [] suff = str(self.joyp_idx + 1) player_lab = Label( text=_('Player') + ' ' + suff, pos=(0, .9), tra_src='Player' + ' ' + suff, tra_tra=_('Player') + ' ' + suff, **menu_props.label_args) joypad_lab = Label( text=_('Use the joypad when present'), pos=(-.1, .7), text_align=TextNode.ARight, tra_src='Use the joypad when present', tra_tra=_('Use the joypad when present'), text_wordwrap=16, **menu_props.label_args) self.joypad_cb = P3dCheckBtn( pos=(.09, .72), text='', indicator_val=self.joysticks[self.joyp_idx], indicator_frame_col=menu_props.text_active_col, **menu_props.checkbtn_args) buttons_data = [ (_('Accelerate'), 'forward' + suff, .5), (_('Brake/Reverse'), 'rear' + suff, .32), (_('Left'), 'left' + suff, .14), (_('Right'), 'right' + suff, -.04), (_('Weapon'), 'fire' + suff, -.22), (_('Respawn'), 'respawn' + suff, -.38)] for btn_data in buttons_data: widgets += [self._add_lab(btn_data[0], btn_data[2])] widgets += [self._add_btn(self.eng.event.key2desc(self.keys[btn_data[1]]), btn_data[2])] l_a = menu_props.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label( text=_('Press the key to record it'), pos=(-.2, -.6), **l_a) self.hint_lab.hide() widgets += [player_lab, joypad_lab, self.joypad_cb, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self)
def __init__(self, menu_props, room): GameObject.__init__(self) self.eng.log('created match form (init)') self.room = room self.invited_users = [self.eng.client.myid] self.menu_props = menu_props lab_args = menu_props.label_args lab_args['scale'] = .046 self.match_frm = Frame( frame_size=(-.02, 3.49, 0, .45), frame_col=(.2, .2, .2, .5), pos=(.04, -.46), parent=base.a2dTopLeft) usr = [usr for usr in self.eng.client.users if usr.uid == self.eng.client.myid][0] frm = UserFrmMe( self.eng.client.myid, usr.is_supporter, (.1, .38), self.match_frm, self.menu_props, .32) self.forms = [frm] for i in range(0, 8): row, col = i % 4, i // 4 Label( text=str(i + 1) + '.', pos=(.06 + 1.24 * col, .38 - .08 * row), parent=self.match_frm, **lab_args)
class MPBtn(GameObject): tooltip_align = TextNode.A_right tooltip_offset = (.01, 0, -.08) def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb, usr_name, tooltip): GameObject.__init__(self) self.owner = owner lab_args = menu_props.label_args lab_args['scale'] = .046 #lab_args['text_fg'] = menu_props.text_normal_col self.btn = ImgBtn( parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb, extra_args=[usr_name], **menu_props.imgbtn_args) self.btn.bind(ENTER, self.on_enter) self.btn.bind(EXIT, self.on_exit) self.tooltip_btn = Btn( parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None, **menu_props.imgbtn_args) self.tooltip_btn.bind(ENTER, self.on_enter) self.tooltip_btn.bind(EXIT, self.on_exit) self.on_create() self.tooltip = Label( text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset, parent=parent, text_wordwrap=10, text_align=self.tooltip_align, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() def on_create(self): self.btn.hide() self.tooltip_btn.hide() def is_hidden(self): return self.btn.hidden def show(self): if self.btn['state'] == DISABLED: self.tooltip_btn.show() else: self.tooltip_btn.hide() return self.btn.show() def hide(self): self.tooltip_btn.hide() return self.btn.hide() def enable(self): self.tooltip_btn.hide() return self.btn.enable() def disable(self): self.tooltip_btn.show() return self.btn.disable() def on_enter(self, pos): self.owner.on_enter(pos) self.tooltip.show() def on_exit(self, pos): self.owner.on_exit(pos) self.tooltip.hide()
class MPBtn(GameObject): tooltip_align = TextNode.A_right tooltip_offset = (.01, 0, -.08) def __init__(self, parent, owner, menu_props, img_path, msg_btn_x, cb, usr_name, tooltip): GameObject.__init__(self) self.owner = owner lab_args = menu_props.label_args lab_args['scale'] = .046 #lab_args['text_fg'] = menu_props.text_normal_col self.btn = ImgBtn(parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 1), frame_texture=img_path, cmd=cb, extra_args=[usr_name], **menu_props.imgbtn_args) self.btn.bind(ENTER, self.on_enter) self.btn.bind(EXIT, self.on_exit) self.tooltip_btn = Btn(parent=parent, scale=(.024, .024), pos=(msg_btn_x, .01), frame_col=(1, 1, 1, 0), frame_size=(-1, 1, -1, 1), cmd=None, **menu_props.imgbtn_args) self.tooltip_btn.bind(ENTER, self.on_enter) self.tooltip_btn.bind(EXIT, self.on_exit) self.on_create() self.tooltip = Label(text=tooltip, pos=self.btn.get_pos() + self.tooltip_offset, parent=parent, text_wordwrap=10, text_align=self.tooltip_align, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() def on_create(self): self.btn.hide() self.tooltip_btn.hide() def is_hidden(self): return self.btn.hidden def show(self): if self.btn['state'] == DISABLED: self.tooltip_btn.show() else: self.tooltip_btn.hide() return self.btn.show() def hide(self): self.tooltip_btn.hide() return self.btn.hide() def enable(self): self.tooltip_btn.hide() return self.btn.enable() def disable(self): self.tooltip_btn.show() return self.btn.disable() def on_enter(self, pos): self.owner.on_enter(pos) self.tooltip.show() def on_exit(self, pos): self.owner.on_exit(pos) self.tooltip.hide()
class MatchMsgFrm(GameObject): def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created match message form') self.chat = None self.msg_frm = Frame( frame_size=(-.02, 3.49, 0, 1.22), frame_col=(.2, .2, .2, .5), pos=(.04, -1.69), parent=base.a2dTopLeft) t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = Text( txt='', pos=(0, 1.16), parent=self.msg_frm, align='left', **t_a) self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = ScrolledFrame( frame_sz=(-.02, 2.46, -.02, 1.02), canvas_sz=(-.02, 2.42, -.02, 1.02), scrollbar_width=.036, frame_col=(1, 1, 1, .0), pos=(.02, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = Text( txt='', pos=(0, .24), parent=self.txt_frm.canvas, align='left', wordwrap=52, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, 2.5, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1.15), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50, text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() self.eng.client.attach(self.on_groupchat_msg) @property def widgets(self): return [self.msg_frm, self.dst_txt, self.ent, self.txt_frm, self.msg_txt, self.lab_frm, self.tooltip] def on_enter(self, pos): self.tooltip.show() def on_exit(self, pos): self.tooltip.hide() def add_msg_txt(self, msg): self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg txt_height = self.msg_txt.get_np().textNode.getUpperLeft3d()[2] - \ self.msg_txt.get_np().textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) def set_title(self, title): ttitle = self.trunc(title, 160) fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2' if title: if ',' in ttitle: is_muc = True ttitle = ttitle names = ttitle.split(',') names = [name.strip() for name in names] names = [fix_name(name) for name in names] ttitle = ', '.join(names) else: ttitle = fix_name(ttitle) self.dst_txt['text'] = ttitle self.tooltip['text'] = title @staticmethod def trunc(name, lgt): if len(name) > lgt: return name[:lgt] + '...' return name def on_typed_msg(self, val): self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val) self.ent.set('') self.eng.client.send([ 'msg_room', self.eng.client.myid, self.chat.dst, val]) #self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=self.chat.dst, # mtype='groupchat', # mbody=val) self.ent['focus'] = 1 def on_groupchat_msg(self, from_, to, txt): #src = str(JID(msg['mucnick'])) #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2' src = from_ #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare)) self.eng.log('received groupchat message from %s in the chat %s' % (from_, to)) #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body']) str_msg = '\1italic\1' + src + '\2: ' + txt if not self.chat: #self.chat = MUC(str(JID(msg['from']).bare), self.yorg_client) self.chat = MUC(to) self.chat.messages += [str_msg] if self.dst_txt['text'] == '': self.set_chat(self.chat) #elif self.chat.dst == str(JID(msg['from']).bare): elif self.chat.dst == to: self.add_msg_txt(str_msg) def on_presence_available_room(self, uid, room): #room = str(JID(msg['muc']['room']).bare) #nick = str(msg['muc']['nick']) self.eng.log('user %s has logged in the chat %s' % (uid, room)) self.chat.users += [uid] self.set_title(self.chat.title) def on_presence_unavailable_room(self, uid, room_name): room = room_name nick = uid self.eng.log('user %s has left the chat %s' %(nick, room)) if nick in self.chat.users: # it is being removed multiple times when # you remove a user who has accepted self.chat.users.remove(nick) self.set_title(self.chat.title) def on_rm_usr_from_match(self, uid): if uid in self.chat.users: # it is being removed multiple times when # you remove a user who has accepted self.chat.users.remove(uid) self.update_title() def add_groupchat(self, room):#, usr): #self.set_title(usr) if not self.chat: self.chat = MUC(room) self.set_chat(self.chat) def set_chat(self, chat): self.set_title(chat.title) self.msg_txt['text'] = '\n'.join(chat.messages) txt_height = self.msg_txt.get_np().textNode.getUpperLeft3d()[2] - \ self.msg_txt.get_np().textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) self.ent['state'] = NORMAL def update_title(self): self.set_title(self.chat.title) def on_focus(self, val): if self.observers is None: return # it may be called from entries which aren't destroyed yet (i.e. they # are in transition_exit) if val == 'in' and self.ent.text == _('write here your message'): self.ent.set('') self.notify('on_match_msg_focus', val) def destroy(self): self.eng.client.detach(self.on_groupchat_msg) self.eng.log('message form destroyed') #self.msg_frm.destroy() GameObject.destroy(self)
def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created message form') self.chats = [] self.curr_chat = None self.curr_match_room = None self.msg_frm = DirectFrame( frameSize=(-.02, .8, 0, .45), frameColor=(.2, .2, .2, .5), pos=(-.82, 1, .02), parent=base.a2dBottomRight) self.presences_sent = [] self.menu_props = menu_props t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = OnscreenText( text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left, **t_a) self.arrow_btn = ImgBtn( parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42), frame_col=(1, 1, 1, 1), frame_texture='assets/images/gui/arrow.txo', cmd=self.on_arrow, **menu_props.imgbtn_args) self.arrow_btn.disable() self.close_btn = ImgBtn( parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42), frame_col=(1, 1, 1, 1), frame_texture='assets/images/gui/close.txo', cmd=self.on_close, **menu_props.imgbtn_args) self.close_btn.disable() self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = DirectScrolledFrame( frameSize=(-.02, .76, -.02, .28), canvasSize=(-.02, .72, -.02, .28), scrollBarWidth=.036, verticalScroll_relief=FLAT, verticalScroll_frameColor=(.2, .2, .2, .4), verticalScroll_thumb_relief=FLAT, verticalScroll_thumb_frameColor=(.8, .8, .8, .6), verticalScroll_incButton_relief=FLAT, verticalScroll_incButton_frameColor=(.8, .8, .8, .6), verticalScroll_decButton_relief=FLAT, verticalScroll_decButton_frameColor=(.8, .8, .8, .6), horizontalScroll_relief=FLAT, frameColor=(1, 1, 1, 0), pos=(.02, 1, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = OnscreenText( text='', pos=(0, .24), parent=self.txt_frm.getCanvas(), align=TextNode.A_left, wordwrap=14, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, .64, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1, .4), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(.78, 1, -.06), parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8), text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide()
class MessageFrm(GameObject): def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created message form') self.chats = [] self.curr_chat = None self.curr_match_room = None self.msg_frm = DirectFrame( frameSize=(-.02, .8, 0, .45), frameColor=(.2, .2, .2, .5), pos=(-.82, 1, .02), parent=base.a2dBottomRight) self.presences_sent = [] self.menu_props = menu_props t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = OnscreenText( text='', pos=(0, .4), parent=self.msg_frm, align=TextNode.A_left, **t_a) self.arrow_btn = ImgBtn( parent=self.msg_frm, scale=(.024, .024), pos=(.7, 1, .42), frame_col=(1, 1, 1, 1), frame_texture='assets/images/gui/arrow.txo', cmd=self.on_arrow, **menu_props.imgbtn_args) self.arrow_btn.disable() self.close_btn = ImgBtn( parent=self.msg_frm, scale=(.024, .024), pos=(.76, 1, .42), frame_col=(1, 1, 1, 1), frame_texture='assets/images/gui/close.txo', cmd=self.on_close, **menu_props.imgbtn_args) self.close_btn.disable() self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=19.5, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = DirectScrolledFrame( frameSize=(-.02, .76, -.02, .28), canvasSize=(-.02, .72, -.02, .28), scrollBarWidth=.036, verticalScroll_relief=FLAT, verticalScroll_frameColor=(.2, .2, .2, .4), verticalScroll_thumb_relief=FLAT, verticalScroll_thumb_frameColor=(.8, .8, .8, .6), verticalScroll_incButton_relief=FLAT, verticalScroll_incButton_frameColor=(.8, .8, .8, .6), verticalScroll_decButton_relief=FLAT, verticalScroll_decButton_frameColor=(.8, .8, .8, .6), horizontalScroll_relief=FLAT, frameColor=(1, 1, 1, 0), pos=(.02, 1, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = OnscreenText( text='', pos=(0, .24), parent=self.txt_frm.getCanvas(), align=TextNode.A_left, wordwrap=14, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, .64, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1, .4), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(.78, 1, -.06), parent=self.lab_frm, text_wordwrap=16,# text_bg=(.2, .2, .2, .8), text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() def on_enter(self, pos): self.tooltip.show() def on_exit(self, pos): self.tooltip.hide() def show(self): self.msg_frm.show() def hide(self): self.msg_frm.hide() def add_msg_txt(self, msg): self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \ self.msg_txt.textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) def set_title(self, title): ttitle = self.trunc(title, 32) fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2' if title: if ',' in ttitle: is_muc = True ttitle = ttitle names = ttitle.split(',') names = [name.strip() for name in names] names = [fix_name(name) for name in names] ttitle = ', '.join(names) else: ttitle = fix_name(ttitle) self.dst_txt['text'] = ttitle self.tooltip['text'] = title @staticmethod def trunc(name, lgt): if len(name) > lgt: return name[:lgt] + '...' return name def set_chat(self, chat): self.curr_chat = chat self.set_title(chat.title) self.msg_txt['text'] = '\n'.join(chat.messages) txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \ self.msg_txt.textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) if not self.chats: self.close_btn.disable() self.ent['state'] = DISABLED elif len(self.chats) == 1: self.close_btn.enable() self.ent['state'] = NORMAL self.arrow_btn.disable() else: self.close_btn.enable() self.ent['state'] = NORMAL self.arrow_btn.enable() if all(_chat.read for _chat in self.chats): self.arrow_btn['frameTexture'] = 'assets/images/gui/arrow.txo' else: self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo' def on_arrow(self): chat_idx = self.chats.index(self.curr_chat) next_idx = (chat_idx + 1) % len(self.chats) chat = self.chats[next_idx] self.set_title(chat.title) chat.read = True self.set_chat(chat) @property def open_chats(self): return [chat for chat in self.chats if not chat.closed] def on_close(self): if self.curr_chat not in self.open_chats: return curr_idx = self.open_chats.index(self.curr_chat) #self.chats.remove(self.curr_chat) self.curr_chat.closed = True if self.open_chats: self.set_chat(self.open_chats[curr_idx - 1]) else: self.set_chat(Chat('')) self.notify('on_close_all_chats') def on_typed_msg(self, val): self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val) self.ent.set('') #if self.curr_chat.dst not in self.presences_sent and \ # not str(self.curr_chat.dst).startswith('yorg'): # self.eng.xmpp.client.send_presence( # pfrom=self.eng.xmpp.client.boundjid.full, # pto=self.curr_chat.dst) # self.presences_sent += [self.curr_chat.dst] #if str(self.curr_chat.dst).startswith('yorg'): # self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=self.curr_chat.dst, # mtype='groupchat', # mbody=val) #else: # self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=self.curr_chat.dst, # msubject='chat', # mbody=val) if len(self.curr_chat.dst) > 12 and all(char.isdigit() for char in self.curr_chat.dst[-12:]): self.eng.client.send([ 'msg_room', self.eng.client.myid, self.curr_chat.dst, val]) else: self.eng.client.send(['msg', self.eng.client.myid, self.curr_chat.dst, val]) msg = '\1italic\1' + _('you') + '\2: ' + val self.curr_chat.messages += [msg] self.ent['focus'] = 1 def on_msg(self, from_, to, txt): #src = str(JID(msg['from']).bare) #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2' str_msg = '\1italic\1' + from_ + '\2: ' + txt chat = self.__find_chat(from_) if not chat: chat = Chat(from_) self.chats += [chat] chat.messages += [str_msg] if self.dst_txt['text'] == '': self.set_chat(chat) elif self.curr_chat.dst == from_: self.add_msg_txt(str_msg) else: chat.read = False chat.closed = False self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo' def on_groupchat_msg(self, from_, to, txt): #if str(JID(msg['from']).bare) == self.curr_match_room: if to == self.curr_match_room: if self.match_msg_frm: # we're still in the room page self.match_msg_frm.on_groupchat_msg(from_, to, txt) #src = str(JID(msg['mucnick'])) #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2' src = from_ #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare)) self.eng.log('received groupchat message from %s in the chat %s' % (from_, to)) #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body']) str_msg = '\1italic\1' + src + '\2: ' + txt chat = self.curr_chat if not chat: #chat = MUC(str(JID(msg['from']).bare)) chat = MUC(to) self.chats += [chat] chat.messages += [str_msg] if self.dst_txt['text'] == '': self.set_chat(chat) #elif self.curr_chat.dst == str(JID(msg['from']).bare): elif self.curr_chat.dst == to: self.add_msg_txt(str_msg) else: chat.read = False chat.closed = False self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo' def on_presence_available_room(self, uid, room): if room == self.curr_match_room: self.match_msg_frm.on_presence_available_room(uid, room) #room = str(JID(msg['muc']['room']).bare) #nick = str(msg['muc']['nick']) self.eng.log('user %s has logged in the chat %s' %(uid, room)) chat = self.__find_chat(room) chat.users += [uid] if room != self.curr_match_room: if self.curr_chat.dst == room: self.set_title(chat.title) def on_presence_unavailable_room(self, uid, room_name): if self.match_msg_frm and room_name == self.curr_match_room: self.match_msg_frm.on_presence_unavailable_room(uid, room_name) return room = room_name nick = uid self.eng.log('user %s has left the chat %s' %(nick, room)) chat = self.__find_chat(room) if nick == self.eng.client.myid: self.on_close() else: chat.users.remove(nick) if self.curr_chat.dst == room: self.set_title(chat.title) def __find_chat(self, dst): chats = [chat for chat in self.chats if chat.dst == dst] if chats: return chats[0] def add_chat(self, usr): #self.set_title(JID(usr).bare) chat = self.__find_chat(usr) if not chat: chat = Chat(usr) self.chats += [chat] self.set_chat(chat) self.ent['focus'] = 1 def add_groupchat(self, room, usr): self.set_title(usr) chat = self.__find_chat(room) if not chat: chat = MUC(room) self.chats += [chat] chat.users += [usr] self.set_chat(chat) self.add_match_chat(room, usr) def remove_groupchat(self): self.match_msg_frm.detach(self.on_match_msg_focus) self.match_msg_frm = self.match_msg_frm.destroy() def on_focus(self, val): if val and self.ent.get() == _('write here your message'): self.ent.set('') self.notify('on_msg_focus', val) def on_match_msg_focus(self, val): self.notify('on_msg_focus', val) def on_room_back(self): self.curr_match_room = None self.match_msg_frm.destroy() def add_match_chat(self, room, usr): if self.curr_match_room: return self.curr_match_room = room self.match_msg_frm = MatchMsgFrm(self.menu_props) self.match_msg_frm.attach(self.on_match_msg_focus) self.match_msg_frm.add_groupchat(room, usr)
class InputPageGui4(ThanksPageGui): joyp_idx = 3 def __init__(self, mediator, menu_props, joysticks, keys): self.joypad_cb = None self.joysticks = joysticks self.keys = keys self.ibuttons = [] ThanksPageGui.__init__(self, mediator, menu_props) def build(self): menu_props = self.menu_props widgets = [] suff = str(self.joyp_idx + 1) player_lab = Label( text=_('Player') + ' ' + suff, pos=(0, .9), tra_src='Player' + ' ' + suff, tra_tra=_('Player') + ' ' + suff, **menu_props.label_args) joypad_lab = Label( text=_('Use the joypad when present'), pos=(-.1, .7), text_align=TextNode.ARight, tra_src='Use the joypad when present', tra_tra=_('Use the joypad when present'), text_wordwrap=16, **menu_props.label_args) self.joypad_cb = P3dCheckBtn( pos=(.09, .72), text='', indicator_val=self.joysticks[self.joyp_idx], indicator_frame_col=menu_props.text_active_col, **menu_props.checkbtn_args) buttons_data = [ (_('Accelerate'), 'forward' + suff, .5), (_('Brake/Reverse'), 'rear' + suff, .32), (_('Left'), 'left' + suff, .14), (_('Right'), 'right' + suff, -.04), (_('Weapon'), 'fire' + suff, -.22), (_('Respawn'), 'respawn' + suff, -.38)] for btn_data in buttons_data: widgets += [self._add_lab(btn_data[0], btn_data[2])] widgets += [self._add_btn(self.eng.event.key2desc(self.keys[btn_data[1]]), btn_data[2])] l_a = menu_props.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label( text=_('Press the key to record it'), pos=(-.2, -.6), **l_a) self.hint_lab.hide() widgets += [player_lab, joypad_lab, self.joypad_cb, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self) def _add_lab(self, text, pos_z): return Label( text=text, pos=(-.1, pos_z), text_align=TextNode.ARight, **self.menu_props.label_args) def _add_btn(self, text, pos_z): btn = Btn(pos=(.46, pos_z), text=text, cmd=self.start_rec, **self.menu_props.btn_args) btn['extraArgs'] = [btn] self.ibuttons += [btn] return btn def start_rec(self, btn): numbers = [str(n) for n in range(10)] 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]) list(map(acc, self._keys)) def _on_back(self): self.mediator.event.on_back() suff = str(self.joyp_idx + 1) dct = {} dct['keys'] = self.keys dct['keys']['forward' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[0]['text']) dct['keys']['rear' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[1]['text']) dct['keys']['left' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[2]['text']) dct['keys']['right' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[3]['text']) dct['keys']['fire' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[4]['text']) dct['keys']['respawn' + suff] = self.eng.event.desc2key(self.mediator.gui.ibuttons[5]['text']) dct['joystick' + suff] = self.mediator.gui.joypad_cb['indicatorValue'] self.notify('on_back', 'input_page2', [dct]) def rec(self, btn, val): used = self.already_used(val) if used: self.dial = AlreadyUsedDlg(self.menu_props, val, *used) self.dial.attach(self.on_already_dlg) else: btn['text'] = val self.hint_lab.hide() events = list(self.keys.values()) + self._keys list(map(self.mediator.event.ignore, events)) self.enable_navigation([0]) 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 self.eng.event.desc2key(btn['text']) == val: return '1', labels[i] for lab, player in product(labels[:-1], ['2', '3', '4']): if self.eng.event.key2desc(self.keys[lab + player]) == val: return player, lab
def _add_lab(self, text, pos_z): return Label(text=text, pos=(-.1, pos_z), text_align=TextNode.ARight, **self.menu_props.label_args)
class UsersFrm(GameObject): def __init__(self, menu_props, yorg_srv): GameObject.__init__(self) self.eng.log('create users form') self.ver_check = VersionChecker() self.yorg_srv = yorg_srv self.room_name = None self.labels = [] self.invited_users = [] self.menu_props = menu_props lab_args = menu_props.label_args lab_args['scale'] = .046 self.users_lab = Label( text=_('Current online users'), pos=(-.85, -.02), hpr=(0, 0, -90), parent=base.a2dTopRight, text_align=TextNode.A_right, **lab_args) self.frm = DirectScrolledFrame( frameSize=(-.02, .8, .45, 2.43), canvasSize=(-.02, .76, -.08, 3.8), scrollBarWidth=.036, verticalScroll_relief=FLAT, verticalScroll_frameColor=(.2, .2, .2, .4), verticalScroll_thumb_relief=FLAT, verticalScroll_thumb_frameColor=(.8, .8, .8, .6), verticalScroll_incButton_relief=FLAT, verticalScroll_incButton_frameColor=(.8, .8, .8, .6), verticalScroll_decButton_relief=FLAT, verticalScroll_decButton_frameColor=(.8, .8, .8, .6), horizontalScroll_relief=FLAT, frameColor=(.2, .2, .2, .5), pos=(-.82, 1, -2.44), parent=base.a2dTopRight) self.conn_lab = Label( text='', pos=(.38, 1.5), parent=self.frm, text_wordwrap=10, **lab_args) self.set_connection_label() self.in_match_room = None self.invited = False def show(self): self.frm.show() self.users_lab.show() def hide(self): self.frm.hide() self.users_lab.hide() def set_connection_label(self): lab_args = self.menu_props.label_args lab_args['scale'] = .046 txt = '' if not self.ver_check.is_uptodate(): txt = _("Your game isn't up-to-date, please update") elif not self.eng.client.is_server_up: txt = _("Yorg's server isn't running") elif not self.eng.client.authenticated: txt = _("You aren't logged in") (self.conn_lab.show if txt else self.conn_lab.hide)() self.conn_lab['text'] = txt def set_size(self, full=True): if full: self.frm.setPos(-.82, 1, -2.44) self.frm['frameSize'] = (-.02, .8, .45, 2.43) else: self.frm.setPos(-.82, 1, -1.97) self.frm['frameSize'] = (-.02, .8, .45, 1.96) @staticmethod def trunc(name, lgt): if len(name) > lgt: return name[:lgt] + '...' return name def on_users(self): self.set_connection_label() bare_users = [self.trunc(user.uid, 20) for user in self.eng.client.sorted_users] for lab in self.labels[:]: _lab = lab.lab.lab['text'].replace('\1smaller\1', '').replace('\2', '') if _lab not in bare_users: if _lab not in self.eng.client.users: lab.destroy() self.labels.remove(lab) nusers = len(self.eng.client.sorted_users) invite_btn = len(self.invited_users) < 8 invite_btn = invite_btn and not self.in_match_room and not self.invited top = .08 * nusers + .08 self.frm['canvasSize'] = (-.02, .76, 0, top) label_users = [lab.lab.lab['text'] for lab in self.labels] clean = lambda n: n.replace('\1smaller\1', '').replace('\2', '') label_users = list(map(clean, label_users)) for i, user in enumerate(self.eng.client.sorted_users): if self.trunc(user.uid, 20) not in label_users: if self.eng.client.myid != user.uid: lab = UserFrmList( user.uid, user.is_supporter, user.is_playing, (0, 1, top - .08 - .08 * i), self.frm.getCanvas(), self.menu_props) else: lab = UserFrmListMe( user.uid, user.is_supporter, (0, 1, top - .08 - .08 * i), self.frm.getCanvas(), self.menu_props) self.labels += [lab] lab.attach(self.on_invite) lab.attach(self.on_friend) lab.attach(self.on_unfriend) lab.attach(self.on_add_chat) #for i, user in enumerate(self.eng.client.sorted_users): # clean = lambda n: n.replace('\1smaller\1', '').replace('\2', '') # lab = [lab for lab in self.labels # if clean(lab.lab.lab['text']) == self.trunc(user.uid, 20)][0] # enb_val = invite_btn and user.uid not in self.invited_users and not user.is_playing # if hasattr(lab, 'invite_btn'): # inv_btn = lab.invite_btn # if enb_val: inv_btn.tooltip['text'] = _('invite the user to a match') # elif len(self.invited_users) == 8: inv_btn.tooltip['text'] = _("you can't invite more players") # elif self.in_match_room: inv_btn.tooltip['text'] = _("you're already in a match") # elif user.uid in self.invited_users: inv_btn.tooltip['text'] = _("you've already invited this user") # elif user.is_playing: inv_btn.tooltip['text'] = _("the user is already playing a match") # lab.enable_invite_btn(enb_val) # lab.frm.set_z(top - .08 - .08 * i) # lab.lab.set_supporter(user.is_supporter) def on_invite(self, usr): self.notify('on_invite', usr) self.invited_users += [usr.uid] self.on_users() if not self.room_name: time_code = strftime('%y%m%d%H%M%S') self.room_name = self.eng.client.myid + time_code #self.eng.xmpp.client.plugin['xep_0045'].joinMUC( # self.room_name, self.eng.xmpp.client.boundjid.bare, # pfrom=self.eng.xmpp.client.boundjid.full) #cfg = self.eng.xmpp.client.plugin['xep_0045'].getRoomConfig(self.room_name) #values = cfg.get_values() #values['muc#roomconfig_publicroom'] = False #cfg.set_values(values) #self.eng.xmpp.client.plugin['xep_0045'].configureRoom(self.room_name, cfg) self.eng.client.register_rpc('join_room') self.eng.client.join_room(self.room_name) self.eng.log('created room ' + self.room_name) self.eng.client.is_server_active = True #for usr_name in [self.yorg_srv] + \ # [_usr.name_full for _usr in self.eng.xmpp.users if _usr.is_in_yorg]: # self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=usr_name, # mtype='ya2_yorg', # msubject='is_playing', # mbody='1') self.eng.client.register_rpc('invite') ret = self.eng.client.invite(usr.uid, self.room_name) #self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=usr.name_full, # mtype='ya2_yorg', # msubject='invite', # mbody=self.room_name + '\n' + self.eng.server.public_addr + '\n' + self.eng.server.local_addr) if ret == 'ok': self.eng.log('invited ' + str(usr.uid)) self.notify('on_add_groupchat', self.room_name, usr.uid) def on_declined(self, from_): self.eng.log('declined from ' + from_) self.invited_users.remove(from_) self.on_users() def on_add_chat(self, msg): self.notify('on_add_chat', msg) def on_logout(self): list(map(lambda lab: lab.destroy(), self.labels)) self.labels = [] def on_friend(self, usr_name): self.eng.log('send friend to ' + usr_name) self.eng.xmpp.client.send_presence_subscription( usr_name, ptype='subscribe', pfrom=self.eng.xmpp.client.boundjid.full) def on_unfriend(self, usr): self.eng.log('roster ' + str(self.eng.xmpp.client.client_roster)) self.eng.xmpp.client.del_roster_item(usr) self.eng.log('roster ' + str(self.eng.xmpp.client.client_roster)) def destroy(self): self.eng.log('destroyed usersfrm') self.frm = self.frm.destroy() GameObject.destroy(self)
class InputPageGui4Joystick(ThanksPageGui): joyp_idx = 3 def __init__(self, mediator, menu_props, opt_file, keys): self.keys = keys self.opt_file = opt_file self.ibuttons = [] ThanksPageGui.__init__(self, mediator, menu_props) def build(self): menu_props = self.menu_props widgets = [] suff = str(self.joyp_idx + 1) player_lab = Label(text=_('Player') + ' ' + suff, pos=(0, .9), tra_src='Player' + ' ' + suff, tra_tra=_('Player') + ' ' + suff, **menu_props.label_args) buttons_data = [(_('Accelerate'), 'forward' + suff, .5), (_('Brake/Reverse'), 'rear' + suff, .32), (_('Weapon'), 'fire' + suff, .14), (_('Respawn'), 'respawn' + suff, -.04)] for btn_data in buttons_data: widgets += [self._add_lab(btn_data[0], btn_data[2])] widgets += [self._add_btn(self.keys[btn_data[1]], btn_data[2])] l_a = menu_props.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label(text=_('Press the key to record it'), pos=(-.2, -.6), **l_a) self.hint_lab.hide() widgets += [player_lab, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self) def _add_lab(self, text, pos_z): return Label(text=text, pos=(-.1, pos_z), text_align=TextNode.ARight, **self.menu_props.label_args) def _add_btn(self, text, pos_z): btn = Btn(pos=(.46, pos_z), text=text, cmd=self.start_rec, **self.menu_props.btn_args) btn['extraArgs'] = [btn] self.ibuttons += [btn] return btn def start_rec(self, btn): #messenger.toggleVerbose() taskMgr.doMethodLater(.01, self.start_rec_aux, 'start rec aux', [btn]) def start_rec_aux(self, btn): self.eng.joystick_mgr.is_recording = True self._keys = ['joypad%s_b%s' % (self.joyp_idx, i) for i in range(4)] keys = [ 'trigger_l', 'trigger_r', 'shoulder_l', 'shoulder_r', 'stick_l', 'stick_r' ] self._keys += ['joypad%s_%s' % (self.joyp_idx, i) for i in keys] self.hint_lab.show() acc = lambda key: self.mediator.event.accept(key, self.rec, [btn, key]) list(map(acc, self._keys)) def _on_back(self, player=0): self.eng.joystick_mgr.is_recording = False self.mediator.event.on_back() suff = str(self.joyp_idx + 1) dct = self.update_values() self.notify('on_back', 'input_page4', [dct]) def rec(self, btn, val): self.eng.joystick_mgr.is_recording = False used = self.already_used(val) if used: self.dial = AlreadyUsedJoystickDlg(self.menu_props, val, used) self.dial.attach(self.on_already_joystick_dlg) else: btn['text'] = val.split('_', 1)[1:] dct = self.update_values() self.opt_file['settings'] = DctFile.deepupdate( self.opt_file['settings'], dct) self.opt_file.store() #keys = self.opt_file['settings']['joystick'] #nav1 = NavInfoPerPlayer(keys['left1'], keys['right1'], keys['forward1'], # keys['rear1'], keys['fire1']) #nav2 = NavInfoPerPlayer(keys['left2'], keys['right2'], keys['forward2'], # keys['rear2'], keys['fire2']) #nav3 = NavInfoPerPlayer(keys['left3'], keys['right3'], keys['forward3'], # keys['rear3'], keys['fire3']) #nav4 = NavInfoPerPlayer(keys['left4'], keys['right4'], keys['forward4'], # keys['rear4'], keys['fire4']) #nav = NavInfo([nav1, nav2, nav3, nav4]) #self.menu_props.nav = nav self.hint_lab.hide() list(map(self.mediator.event.ignore, self._keys)) self.enable_navigation([0]) def on_already_joystick_dlg(self): self.dial = self.dial.destroy() def already_used(self, val): val = val.split('_', 1)[1:] for lab in ['forward', 'rear', 'fire', 'respawn']: if self.keys[lab + str(self.joyp_idx + 1)] == val: return lab def update_keys(self): self.keys = self.opt_file['settings']['joystick'] def update_values(self): suff = str(self.joyp_idx + 1) dct = {} dct['joystick'] = self.keys dct['joystick']['forward' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[0]['text']) dct['joystick']['rear' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[1]['text']) dct['joystick']['fire' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[2]['text']) dct['joystick']['respawn' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[3]['text']) return dct
class InputPageGui4Keyboard(ThanksPageGui): joyp_idx = 3 def __init__(self, mediator, menu_props, opt_file, keys): self.keys = keys self.opt_file = opt_file self.ibuttons = [] ThanksPageGui.__init__(self, mediator, menu_props) def build(self): menu_props = self.menu_props widgets = [] suff = str(self.joyp_idx + 1) player_lab = Label(text=_('Player') + ' ' + suff, pos=(0, .9), tra_src='Player' + ' ' + suff, tra_tra=_('Player') + ' ' + suff, **menu_props.label_args) buttons_data = [(_('Accelerate'), 'forward' + suff, .5), (_('Brake/Reverse'), 'rear' + suff, .32), (_('Left'), 'left' + suff, .14), (_('Right'), 'right' + suff, -.04), (_('Weapon'), 'fire' + suff, -.22), (_('Respawn'), 'respawn' + suff, -.38)] for btn_data in buttons_data: widgets += [self._add_lab(btn_data[0], btn_data[2])] widgets += [ self._add_btn(self.eng.event.key2desc(self.keys[btn_data[1]]), btn_data[2]) ] l_a = menu_props.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label(text=_('Press the key to record it'), pos=(-.2, -.6), **l_a) self.hint_lab.hide() widgets += [player_lab, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self) def _add_lab(self, text, pos_z): return Label(text=text, pos=(-.1, pos_z), text_align=TextNode.ARight, **self.menu_props.label_args) def _add_btn(self, text, pos_z): btn = Btn(pos=(.46, pos_z), text=text, cmd=self.start_rec, **self.menu_props.btn_args) btn['extraArgs'] = [btn] self.ibuttons += [btn] return btn def start_rec(self, btn): numbers = [str(n) for n in range(10)] 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]) list(map(acc, self._keys)) def _on_back(self, player=0): self.mediator.event.on_back() suff = str(self.joyp_idx + 1) dct = self.update_values() self.notify('on_back', 'input_page4', [dct]) def rec(self, btn, val): used = self.already_used(val) if used: self.dial = AlreadyUsedDlg(self.menu_props, val, *used) self.dial.attach(self.on_already_dlg) else: btn['text'] = val dct = self.update_values() self.opt_file['settings'] = DctFile.deepupdate( self.opt_file['settings'], dct) self.opt_file.store() keys = self.opt_file['settings']['keys'] nav1 = NavInfoPerPlayer(keys['left1'], keys['right1'], keys['forward1'], keys['rear1'], keys['fire1']) nav2 = NavInfoPerPlayer(keys['left2'], keys['right2'], keys['forward2'], keys['rear2'], keys['fire2']) nav3 = NavInfoPerPlayer(keys['left3'], keys['right3'], keys['forward3'], keys['rear3'], keys['fire3']) nav4 = NavInfoPerPlayer(keys['left4'], keys['right4'], keys['forward4'], keys['rear4'], keys['fire4']) nav = NavInfo([nav1, nav2, nav3, nav4]) self.menu_props.nav = nav self.hint_lab.hide() events = list(self.keys.values()) + self._keys list(map(self.mediator.event.ignore, events)) self.enable_navigation([0]) def on_already_dlg(self): self.dial = self.dial.destroy() def already_used(self, val): if self.eng.event.key2desc(self.keys['pause']) == val: return '1', 'pause' labels = [ 'forward', 'rear', 'left', 'right', 'fire', 'respawn', 'pause' ] for lab, player in product(labels[:-1], ['1', '2', '3', '4']): if self.eng.event.key2desc(self.keys[lab + player]) == val: return player, lab def update_keys(self): self.keys = self.opt_file['settings']['keys'] def update_values(self): suff = str(self.joyp_idx + 1) dct = {} dct['keys'] = self.keys dct['keys']['forward' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[0]['text']) dct['keys']['rear' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[1]['text']) dct['keys']['left' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[2]['text']) dct['keys']['right' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[3]['text']) dct['keys']['fire' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[4]['text']) dct['keys']['respawn' + suff] = self.eng.event.desc2key( self.mediator.gui.ibuttons[5]['text']) return dct
class MatchMsgFrm(GameObject): def __init__(self, menu_props): GameObject.__init__(self) self.eng.log('created match message form') self.chat = None self.msg_frm = Frame( frame_size=(-.02, 3.49, 0, 1.22), frame_col=(.2, .2, .2, .5), pos=(.04, -1.69), parent=base.a2dTopLeft) t_a = menu_props.text_args t_a['scale'] = .05 t_a['fg'] = menu_props.text_normal_col self.dst_txt = Text( txt='', pos=(0, 1.16), parent=self.msg_frm, align='left', **t_a) self.ent = Entry( scale=.04, pos=(0, .03), entry_font=menu_props.font, width=86, frame_col=menu_props.btn_col, parent=self.msg_frm, initial_text=_('write here your message'), cmd=self.on_typed_msg, focus_in_cmd=self.on_focus, focus_in_args=['in'], focus_out_cmd=self.on_focus, focus_out_args=['out'], text_fg=menu_props.text_active_col) self.ent['state'] = DISABLED self.txt_frm = ScrolledFrame( frame_sz=(-.02, 2.46, -.02, 1.02), canvas_sz=(-.02, 2.42, -.02, 1.02), scrollbar_width=.036, frame_col=(1, 1, 1, .0), pos=(.02, .11), parent=self.msg_frm) t_a['scale'] = .046 self.msg_txt = Text( txt='', pos=(0, .24), parent=self.txt_frm.canvas, align='left', wordwrap=52, **t_a) lab_args = menu_props.label_args lab_args['scale'] = .046 lab_args['text_fg'] = menu_props.text_normal_col self.lab_frm = Btn( frame_size=(-.02, 2.5, -.01, .05), frame_col=(1, 1, 1, 0), pos=(0, 1.15), parent=self.msg_frm) self.lab_frm.bind(ENTER, self.on_enter) self.lab_frm.bind(EXIT, self.on_exit) self.tooltip = Label( text='', pos=(2.4, -.06), parent=self.lab_frm, text_wordwrap=50, text_align=TextNode.A_right, **lab_args) self.tooltip.set_bin('gui-popup', 10) self.tooltip.hide() @property def widgets(self): return [self.msg_frm, self.dst_txt, self.ent, self.txt_frm, self.msg_txt, self.lab_frm, self.tooltip] def on_enter(self, pos): self.tooltip.show() def on_exit(self, pos): self.tooltip.hide() def add_msg_txt(self, msg): self.msg_txt['text'] += ('\n' if self.msg_txt['text'] else '') + msg txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \ self.msg_txt.textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) def set_title(self, title): ttitle = self.trunc(title, 160) fix_name = lambda name: name if '@' not in name else name.split('@')[0] + '\1smaller\1@' + name.split('@')[1] + '\2' if title: if ',' in ttitle: is_muc = True ttitle = ttitle names = ttitle.split(',') names = [name.strip() for name in names] names = [fix_name(name) for name in names] ttitle = ', '.join(names) else: ttitle = fix_name(ttitle) self.dst_txt['text'] = ttitle self.tooltip['text'] = title @staticmethod def trunc(name, lgt): if len(name) > lgt: return name[:lgt] + '...' return name def on_typed_msg(self, val): #self.add_msg_txt('\1italic\1' + _('you') + '\2: ' + val) self.ent.set('') self.eng.client.send([ 'msg_room', self.eng.client.myid, self.chat.dst, val]) #self.eng.xmpp.client.send_message( # mfrom=self.eng.xmpp.client.boundjid.full, # mto=self.chat.dst, # mtype='groupchat', # mbody=val) self.ent['focus'] = 1 def on_groupchat_msg(self, from_, to, txt): #src = str(JID(msg['mucnick'])) #src = src.split('@')[0] + '\1smaller\1@' + src.split('@')[1] + '\2' src = from_ #self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare)) self.eng.log('received groupchat message from %s in the chat %s' % (from_, to)) #str_msg = '\1italic\1' + src + '\2: ' + str(msg['body']) str_msg = '\1italic\1' + src + '\2: ' + txt if not self.chat: #self.chat = MUC(str(JID(msg['from']).bare), self.yorg_client) self.chat = MUC(to) self.chat.messages += [str_msg] if self.dst_txt['text'] == '': self.set_chat(self.chat) #elif self.chat.dst == str(JID(msg['from']).bare): elif self.chat.dst == to: self.add_msg_txt(str_msg) def on_presence_available_room(self, uid, room): #room = str(JID(msg['muc']['room']).bare) #nick = str(msg['muc']['nick']) self.eng.log('user %s has logged in the chat %s' % (uid, room)) self.chat.users += [uid] self.set_title(self.chat.title) def on_presence_unavailable_room(self, uid, room_name): room = room_name nick = uid self.eng.log('user %s has left the chat %s' %(nick, room)) if nick in self.chat.users: # it is being removed multiple times when # you remove a user who has accepted self.chat.users.remove(nick) self.set_title(self.chat.title) def on_rm_usr_from_match(self, uid): if uid in self.chat.users: # it is being removed multiple times when # you remove a user who has accepted self.chat.users.remove(uid) self.update_title() def add_groupchat(self, room, usr): self.set_title(usr) if not self.chat: self.chat = MUC(room) self.set_chat(self.chat) def set_chat(self, chat): self.set_title(chat.title) self.msg_txt['text'] = '\n'.join(chat.messages) txt_height = self.msg_txt.textNode.getUpperLeft3d()[2] - \ self.msg_txt.textNode.getLowerRight3d()[2] self.txt_frm['canvasSize'] = (-.02, .72, .28 - txt_height, .28) self.ent['state'] = NORMAL def update_title(self): self.set_title(self.chat.title) def on_focus(self, val): if val == 'in' and self.ent.get() == _('write here your message'): self.ent.set('') self.notify('on_match_msg_focus', val) def destroy(self): self.eng.log('message form destroyed') #self.msg_frm.destroy() GameObject.destroy(self)