def build(self): menu_args = self.menu_args widgets = [] self.ibuttons = [] joypad_lab = Label(text=_('Use the joypad when present'), pos=(-.3, 1, .8), text_align=TextNode.ARight, tra_src='Use the joypad when present', tra_tra=_('Use the joypad when present'), **menu_args.label_args) self.joypad_cb = PandaCheckBtn( pos=(-.11, 1, .82), text='', indicatorValue=self.joystick, indicator_frameColor=menu_args.text_active, **menu_args.checkbtn_args) if not JoystickMgr.has_support(): self.joypad_cb['state'] = DISABLED buttons_data = [(_('Accelerate'), 'forward', .6), (_('Brake/Reverse'), 'rear', .42), (_('Left'), 'left', .24), (_('Right'), 'right', .06), (_('Weapon'), 'fire', -.12), (_('Respawn'), 'respawn', -.28), (_('Pause'), 'pause', -.46)] 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_args.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label(text=_('Press the key to record it'), pos=(-.2, 1, -.6), **l_a) self.hint_lab.hide() widgets += [joypad_lab, self.joypad_cb, self.hint_lab] self.add_widgets(widgets) ThanksPageGui.build(self)
def __add_lab(self, txt, txt_tr, pos_z, pos_x=-.3, align=TextNode.ARight, scale=None): l_a = self.menu_args.label_args l_a['scale'] = scale or l_a['scale'] lab = Label(text='', pos=(pos_x, 1, pos_z), text_align=align, tra_src=txt, tra_tra=txt_tr, **l_a) return lab
def build(self): sp_cb = lambda: self.notify('on_push_page', 'singleplayer', [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), ('Options', _('Options'), self.on_options), ('Support us', _('Support us'), supp_cb), ('Credits', _('Credits'), cred_cb), ('Not up-to-date', self.get_label(), self.on_loginout), ('Quit', _('Quit'), lambda: self.notify('on_exit'))] widgets = [ Btn(text='', pos=(0, 1, .64 - i * .23), command=menu[2], tra_src=menu_data[i][0], tra_tra=menu_data[i][1], **self.props.gameprops.menu_args.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, 1, -.32)) widgets += [logo_img] lab_args = self.props.gameprops.menu_args.label_args lab_args['scale'] = .12 lab_args['text_fg'] = self.props.gameprops.menu_args.text_err wip_lab = Label(text='', pos=(.05, 1, -.76), parent=base.a2dTopLeft, text_wordwrap=10, text_align=TextNode.A_left, 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[5]['state'] = DISABLED
def __add_lab(self, text, pos_z): return Label(text=text, pos=(-.3, 1, pos_z), text_align=TextNode.ARight, **self.menu_args.label_args)
class InputPageGui(ThanksPageGui): def __init__(self, mediator, menu_args, joystick, keys): self.joypad_cb = None self.joystick = joystick self.keys = keys ThanksPageGui.__init__(self, mediator, menu_args) def build(self): menu_args = self.menu_args widgets = [] self.ibuttons = [] joypad_lab = Label(text=_('Use the joypad when present'), pos=(-.3, 1, .8), text_align=TextNode.ARight, tra_src='Use the joypad when present', tra_tra=_('Use the joypad when present'), **menu_args.label_args) self.joypad_cb = PandaCheckBtn( pos=(-.11, 1, .82), text='', indicatorValue=self.joystick, indicator_frameColor=menu_args.text_active, **menu_args.checkbtn_args) if not JoystickMgr.has_support(): self.joypad_cb['state'] = DISABLED buttons_data = [(_('Accelerate'), 'forward', .6), (_('Brake/Reverse'), 'rear', .42), (_('Left'), 'left', .24), (_('Right'), 'right', .06), (_('Weapon'), 'fire', -.12), (_('Respawn'), 'respawn', -.28), (_('Pause'), 'pause', -.46)] 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_args.label_args.copy() l_a['scale'] = .065 self.hint_lab = Label(text=_('Press the key to record it'), pos=(-.2, 1, -.6), **l_a) self.hint_lab.hide() widgets += [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=(-.3, 1, pos_z), text_align=TextNode.ARight, **self.menu_args.label_args) def __add_btn(self, text, pos_z): btn = Btn(pos=(.26, 1, pos_z), text=text, command=self.start_rec, **self.menu_args.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]) map(acc, self.keys) def _on_back(self): self.mediator.event.on_back() dct = {} dct['keys'] = { 'forward': self.mediator.gui.ibuttons[0]['text'], 'rear': self.mediator.gui.ibuttons[1]['text'], 'left': self.mediator.gui.ibuttons[2]['text'], 'right': self.mediator.gui.ibuttons[3]['text'], 'fire': self.mediator.gui.ibuttons[4]['text'], 'respawn': self.mediator.gui.ibuttons[5]['text'], 'pause': self.mediator.gui.ibuttons[6]['text'] } dct['joystick'] = self.mediator.gui.joypad_cb['indicatorValue'] self.notify('on_back', 'input_page', [dct]) def rec(self, btn, val): btn['text'] = val self.hint_lab.hide() map(self.mediator.event.ignore, self.keys)
def build(self): sp_cb = lambda: self.notify('on_push_page', 'singleplayer', [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), ('Options', _('Options'), self.on_options), ('Support us', _('Support us'), supp_cb), ('Credits', _('Credits'), cred_cb), ('Not up-to-date', self.get_label(), self.on_loginout), ('Quit', _('Quit'), lambda: self.notify('on_exit'))] widgets = [ Btn(text='', pos=(0, 1, .64 - i * .23), command=menu[2], tra_src=menu_data[i][0], tra_tra=menu_data[i][1], **self.props.gameprops.menu_args.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, 1, -.32)) widgets += [logo_img] lab_args = self.props.gameprops.menu_args.label_args lab_args['scale'] = .12 lab_args['text_fg'] = self.props.gameprops.menu_args.text_err wip_lab = Label(text='', pos=(.05, 1, -.76), parent=base.a2dTopLeft, text_wordwrap=10, text_align=TextNode.A_left, 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[5]['state'] = DISABLED try: sock = socket(AF_INET, SOCK_DGRAM) sock.connect(('ya2.it', 8080)) local_addr = sock.getsockname()[0] igdc = IGDClient(local_addr, edebug=True) prots = ['TCP', 'UDP'] try: map(lambda prot: igdc.DeletePortMapping(9099, prot), prots) except (TypeError, ExpatError, UPNPError) as e: print e import traceback traceback.print_exc() map(lambda prot: igdc.AddPortMapping(local_addr, 9099, prot, 9099), prots) self.eng.upnp = True except (TypeError, timeout, ExpatError, gaierror) as e: print e import traceback traceback.print_exc() self.eng.upnp = False