Exemple #1
0
 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
Exemple #2
0
    def build(self, exit_behav):
        self.drv_info = self.props.gameprops.drivers_info
        menu_args = self.menu_args
        widgets = [Text(_('Select the driver'), pos=(-.2, .8),
                                **menu_args.text_args)]
        t_a = self.menu_args.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your name:'), pos=(-.3, .6), scale=.06,
                            align='right', wordwrap=128, **t_a)
        self.drivers = []
        for row, col in product(range(2), range(4)):
            idx = col + row * 4
            drv_btn = ImgBtn(
                scale=.24, pos=(-.95 + col * .5, 1, .3 - row * .64),
                frameColor=(0, 0, 0, 0),
                image=self.props.gameprops.drivers_img.path % idx,
                command=self.on_click, extraArgs=[idx],
                **self.menu_args.imgbtn_args)
            name = Text(
                '',
                pos=(-.95 + col * .5, .01 - row * .64),
                scale=.046, **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-1]]
            sign = lambda pos_x: '\1green\1+\2' if pos_x > 0 else ''
            psign = lambda pos_x, sgn=sign: '+' if pos_x == 0 else sgn(pos_x)

            def ppcol(x):
                return '\1green\1%s\2' % x if x > 0 else '\1red\1%s\2' % x
            pcol = lambda x: x if x == 0 else ppcol(x)
            lab_lst = [(_('adherence'), .09), (_('speed'), .21),
                       (_('stability'), .15)]
            widgets += map(
                lambda lab_def: self.__add_lab(*(lab_def + (row, col))),
                lab_lst)
            txt_lst = [(self.drv_info[idx - 1].adherence, .09),
                       (self.drv_info[idx - 1].speed, .21),
                       (self.drv_info[idx - 1].stability, .15)]
            widgets += map(
                lambda txt_def: self.__add_txt(
                    *txt_def + (psign, pcol, col, row)),
                txt_lst)
        self.sel_drv_img = Img(
            self.props.gameprops.cars_img % self.mediator.car,
            parent=base.a2dBottomLeft, pos=(.3, 1, .4), scale=.28)
        widgets += [self.sel_drv_img, self.name]
        self.add_widgets(widgets)
        ffilterpath = self.eng.curr_path + 'yyagl/assets/shaders/filter.vert'
        with open(ffilterpath) as ffilter:
            vert = ffilter.read()
        shader = load_shader(vert, frag)
        if shader:
            self.sel_drv_img.set_shader(shader)
        self.sel_drv_img.set_transparency(True)
        self.t_s = TextureStage('ts')
        self.t_s.set_mode(TextureStage.MDecal)
        empty_img = PNMImage(1, 1)
        empty_img.add_alpha()
        empty_img.alpha_fill(0)
        tex = Texture()
        tex.load(empty_img)
        self.sel_drv_img.set_texture(self.t_s, tex)
        ThanksPageGui.build(self, exit_behav=exit_behav)
Exemple #3
0
class DriverPageGui(ThanksPageGui):

    def __init__(self, mediator, driverpage_props):
        self.props = driverpage_props
        self.sel_drv_img = None
        self.driver = None
        ThanksPageGui.__init__(self, mediator, driverpage_props.gameprops.menu_args)

    def build(self, exit_behav):
        self.drv_info = self.props.gameprops.drivers_info
        menu_args = self.menu_args
        widgets = [Text(_('Select the driver'), pos=(-.2, .8),
                                **menu_args.text_args)]
        t_a = self.menu_args.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your name:'), pos=(-.3, .6), scale=.06,
                            align='right', wordwrap=128, **t_a)
        self.drivers = []
        for row, col in product(range(2), range(4)):
            idx = col + row * 4
            drv_btn = ImgBtn(
                scale=.24, pos=(-.95 + col * .5, 1, .3 - row * .64),
                frameColor=(0, 0, 0, 0),
                image=self.props.gameprops.drivers_img.path % idx,
                command=self.on_click, extraArgs=[idx],
                **self.menu_args.imgbtn_args)
            name = Text(
                '',
                pos=(-.95 + col * .5, .01 - row * .64),
                scale=.046, **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-1]]
            sign = lambda pos_x: '\1green\1+\2' if pos_x > 0 else ''
            psign = lambda pos_x, sgn=sign: '+' if pos_x == 0 else sgn(pos_x)

            def ppcol(x):
                return '\1green\1%s\2' % x if x > 0 else '\1red\1%s\2' % x
            pcol = lambda x: x if x == 0 else ppcol(x)
            lab_lst = [(_('adherence'), .09), (_('speed'), .21),
                       (_('stability'), .15)]
            widgets += map(
                lambda lab_def: self.__add_lab(*(lab_def + (row, col))),
                lab_lst)
            txt_lst = [(self.drv_info[idx - 1].adherence, .09),
                       (self.drv_info[idx - 1].speed, .21),
                       (self.drv_info[idx - 1].stability, .15)]
            widgets += map(
                lambda txt_def: self.__add_txt(
                    *txt_def + (psign, pcol, col, row)),
                txt_lst)
        self.sel_drv_img = Img(
            self.props.gameprops.cars_img % self.mediator.car,
            parent=base.a2dBottomLeft, pos=(.3, 1, .4), scale=.28)
        widgets += [self.sel_drv_img, self.name]
        self.add_widgets(widgets)
        ffilterpath = self.eng.curr_path + 'yyagl/assets/shaders/filter.vert'
        with open(ffilterpath) as ffilter:
            vert = ffilter.read()
        shader = load_shader(vert, frag)
        if shader:
            self.sel_drv_img.set_shader(shader)
        self.sel_drv_img.set_transparency(True)
        self.t_s = TextureStage('ts')
        self.t_s.set_mode(TextureStage.MDecal)
        empty_img = PNMImage(1, 1)
        empty_img.add_alpha()
        empty_img.alpha_fill(0)
        tex = Texture()
        tex.load(empty_img)
        self.sel_drv_img.set_texture(self.t_s, tex)
        ThanksPageGui.build(self, exit_behav=exit_behav)

    def __add_lab(self, txt, pos_z, row, col):
        t_a = self.menu_args.text_args.copy()
        del t_a['scale']
        return Text(
            txt + ':', pos=(-1.15 + col * .5, pos_z - row * .64),
            scale=.046, align='left', **t_a)

    def __add_txt(self, val, pos_z, psign, pcol, col, row):
        t_a = self.menu_args.text_args.copy()
        del t_a['scale']
        return Text(
            '%s%s%%' % (psign(val), pcol(val)),
            pos=(-.75 + col * .5, pos_z - row * .64), scale=.052,
            align='right', **t_a)

    def enable_buttons(self, enable):
        [(drv.enable if enable else drv.disable)() for drv in self.drivers]

    def on_click(self, i):
        self.eng.log('selected driver ' + str(i))
        gprops = self.props.gameprops
        txt_path = gprops.drivers_img.path_sel
        self.sel_drv_img.set_texture(self.t_s, loader.loadTexture(txt_path % i))
        self.widgets[-1]['state'] = DISABLED
        self.enable_buttons(False)
        taskMgr.remove(self.update_tsk)
        cars = gprops.cars_names[:]
        car_idx = cars.index(self.mediator.car)
        cars.remove(self.mediator.car)
        shuffle(cars)
        drv_idx = range(8)
        drv_idx.remove(i)
        shuffle(drv_idx)
        prev_drv = gprops.drivers_info[car_idx]
        gprops.drivers_info[car_idx] = gprops.drivers_info[i]
        gprops.drivers_info[car_idx].img_idx = i
        nname = self.this_name()
        gprops.drivers_info[car_idx].name = nname
        gprops.drivers_info[i] = prev_drv
        self.eng.log('drivers: ' + str(gprops.drivers_info))
        self.notify('on_driver_selected', self.ent.get(), self.mediator.track,
                    self.mediator.car)

    def _buttons(self, idx):
        return [btn for btn in self.buttons if btn['extraArgs'] == [idx]]

    def destroy(self):
        self.sel_drv_img = None
        PageGui.destroy(self)
Exemple #4
0
 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