Exemplo n.º 1
0
 def __bld_car(self, cars_per_row, row, col):
     t_a = self.menu_args.text_args.copy()
     del t_a['scale']
     gprops = self.props.gameprops
     z_offset = 0 if len(gprops.cars_names) > cars_per_row else .35
     num_car_row = len(gprops.cars_names) - cars_per_row if row == 1 else \
         min(cars_per_row, len(gprops.cars_names))
     x_offset = .4 * (cars_per_row - num_car_row)
     btn = ImgBtn(scale=.32,
                  pos=(-1.4 + col * .64 + x_offset, 1,
                       .4 - z_offset - row * .7),
                  frameColor=(0, 0, 0, 0),
                  image=gprops.car_path %
                  gprops.cars_names[col + row * cars_per_row],
                  command=self.on_car,
                  extraArgs=[gprops.cars_names[col + row * cars_per_row]],
                  **self.menu_args.imgbtn_args)
     widgets = [btn]
     txt = Text(gprops.cars_names[col + row * cars_per_row],
                pos=(-1.4 + col * .64 + x_offset,
                     .64 - z_offset - row * .7),
                scale=.072,
                **t_a)
     name = Text('',
                 pos=(-1.4 + col * .64 + x_offset,
                      .04 - z_offset - row * .7),
                 scale=.046,
                 **t_a)
     btn._name_txt = name
     widgets += [txt, name]
     car_name = gprops.cars_names[col + row * cars_per_row]
     cfg_fpath = gprops.phys_path % car_name
     with open(cfg_fpath) as phys_file:
         cfg = load(phys_file)
     speed = int(round((cfg['max_speed'] / 120.0 - 1) * 100))
     fric = int(round((cfg['friction_slip'][0] / 2.6 - 1) * 100))
     roll = -int(round((cfg['roll_influence'][0] / .21 - 1) * 100))
     sign = lambda x: '\1green\1+\2' if x > 0 else ''
     psign = lambda x, sgn=sign: '+' if x == 0 else sgn(x)
     __col_ = lambda x: '\1green\1%s\2' if x > 0 else '\1red\1%s\2'
     _col_ = lambda x, __col=__col_: __col(x) % x
     pcol = lambda x, _col=_col_: x if x == 0 else _col(x)
     txt_lst = [(_('adherence'), fric, .11), (_('speed'), speed, .27),
                (_('stability'), roll, .19)]
     widgets += map(
         lambda txt_def: self.__add_txt(*txt_def + (
             psign, pcol, col, x_offset, z_offset, row)), txt_lst)
     return widgets
Exemplo n.º 2
0
 def __bld_car(self, cars_per_row, row, col):
     t_a = self.menu_props.text_args.copy()
     del t_a['scale']
     gprops = self.props.gameprops
     z_offset = 0 if len(gprops.cars_names) > cars_per_row else .35
     num_car_row = len(gprops.cars_names) - cars_per_row if row == 1 else \
         min(cars_per_row, len(gprops.cars_names))
     x_offset = .4 * (cars_per_row - num_car_row)
     btn = ImgBtn(
         scale=(.32, .32),
         pos=(-.96 + col * .64 + x_offset, .4 - z_offset - row * .7),
         frame_col=(0, 0, 0, 0),
         img=gprops.car_path % gprops.cars_names[col + row*cars_per_row],
         cmd=self.on_car,
         extra_args=[
             gprops.cars_names[col + row * cars_per_row]],
         **self.menu_props.imgbtn_args)
     widgets = [btn]
     txt = Text(
         gprops.cars_names[col + row * cars_per_row],
         pos=(-.96 + col * .64 + x_offset, .64 - z_offset - row * .7),
         scale=.072, **t_a)
     name = Text(
         '',
         pos=(-.96 + col * .64 + x_offset, .04 - z_offset - row * .7),
         scale=.046, **t_a)
     btn._name_txt = name
     widgets += [txt, name]
     car_name = gprops.cars_names[col + row * cars_per_row]
     cfg_fpath = gprops.phys_path % car_name
     with open(cfg_fpath) as phys_file:
         cfg = load(phys_file)
     speed = int(round((cfg['max_speed'] / 120.0 - 1) * 100))
     fric = int(round((cfg['friction_slip'][0] / 2.6 - 1) * 100))
     roll = -int(round((cfg['roll_influence'][0] / .21 - 1) * 100))
     sign = lambda x: '\1green\1+\2' if x > 0 else ''
     psign = lambda x, sgn=sign: '+' if x == 0 else sgn(x)
     __col_ = lambda x: '\1green\1%s\2' if x > 0 else '\1red\1%s\2'
     _col_ = lambda x, __col=__col_: __col(x) % x
     pcol = lambda x, _col=_col_: x if x == 0 else _col(x)
     txt_lst = [(_('adherence'), fric, .11), (_('speed'), speed, .27),
                (_('stability'), roll, .19)]
     widgets += list(map(lambda txt_def: self.__add_txt(
         *txt_def + (psign, pcol, col, x_offset, z_offset, row)), txt_lst))
     return widgets
Exemplo n.º 3
0
    def build(self, exit_behav):
        self.drv_info = self.props.gameprops.drivers_info
        menu_props = self.menu_props
        widgets = [Text(_('Select the driver'), pos=(0, .8),
                                **menu_props.text_args)]
        t_a = self.menu_props.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your name:'), pos=(-.1, .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, .24), pos=(-.75 + col * .5, .3 - row * .64),
                frame_col=(0, 0, 0, 0),
                img=self.props.gameprops.drivers_img.path % idx,
                cmd=self.on_click, extra_args=[idx],
                **self.menu_props.imgbtn_args)
            name = Text(
                '',
                pos=(-.75 + col * .5, .01 - row * .64),
                scale=.046, **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-2]]
            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 += list(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 += list(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, .4), scale=.28)
        instr_txt = _(
            'If you use the keyboard, press FIRE to edit the field, then '
            "ENTER when you're done")
        instr = Text(instr_txt, pos=(1.4, .6), scale=.042, wordwrap=16, **t_a)
        widgets += [self.sel_drv_img, self.name, instr]
        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_transparent()
        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)
Exemplo n.º 4
0
    def build(self):
        self.drv_info = self.props.gameprops.drivers_info
        menu_props = self.menu_props
        widgets = [Text(_('Select the drivers'), pos=(0, .91),
                                **menu_props.text_args)]
        t_a = self.menu_props.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your names:'), pos=(-.1, .7), 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, .24), pos=(-.75 + col * .5, .1 - row * .64),
                frame_col=(0, 0, 0, 0),
                img=self.props.gameprops.drivers_img.path % idx,
                cmd=self.on_click, extra_args=[idx],
                **self.menu_props.imgbtn_args)
            name = Text(
                '',
                pos=(-.75 + col * .5, -.19 - row * .64),
                scale=.046, **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-2]]
            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'), -.11), (_('speed'), .01),
                       (_('stability'), -.05)]
            widgets += list(map(
                lambda lab_def: self._add_lab(*(lab_def + (row, col))),
                lab_lst))
            txt_lst = [(self.drv_info[idx - 1].adherence, -.11),
                       (self.drv_info[idx - 1].speed, .01),
                       (self.drv_info[idx - 1].stability, -.05)]
            widgets += list(map(
                lambda txt_def: self._add_txt(
                    *txt_def + (psign, pcol, col, row)),
                txt_lst))
        self.sel_drv_img = []
        self.tss = []
        instr_txt = _(
            'If you use the keyboard, press FIRE to edit the field, then '
            "ENTER when you're done. Other players can't move while someone"
            'is writing (since, with keyboards, some letters may be bound to '
            'movements).')
        instr = Text(instr_txt, pos=(1.28, .8), scale=.042, wordwrap=24, **t_a)
        widgets += [self.name, instr]
        for i, car in enumerate(self.mediator.cars):
            self.sel_drv_img += [Img(
                self.props.gameprops.cars_img % car,
                parent=base.a2dBottomLeft, pos=(.3, 1.74 - i * .46), scale=.22)]
            widgets += [self.sel_drv_img[-1]]
            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[-1].set_shader(shader)
            self.sel_drv_img[-1].set_transparent()
            self.tss += [TextureStage('ts')]
            self.tss[-1].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[-1].set_texture(self.tss[-1], tex)
        self.ents = [Entry(
            scale=.06, pos=(0, .8 - .12 * i), entry_font=menu_props.font, width=12,
            frame_col=menu_props.btn_col,
            initial_text=self.props.gameprops.player_name or _('your name'),
            text_fg=menu_props.text_active_col) for i in range(len(self.mediator.cars))]
        self.add_widgets(self.ents)
        self.add_widgets(widgets)
        ThanksPageGui.build(self, exit_behav=False)
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        self.enable_buttons(False)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def build(self):
        self.drv_info = self.props.gameprops.drivers_info
        menu_props = self.menu_props
        widgets = [
            Text(_('Select the drivers'), pos=(0, .91), **menu_props.text_args)
        ]
        t_a = self.menu_props.text_args.copy()
        del t_a['scale']
        self.name = Text(_('Write your names:'),
                         pos=(-.1, .7),
                         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, .24),
                             pos=(-.75 + col * .5, .1 - row * .64),
                             frame_col=(0, 0, 0, 0),
                             img=self.props.gameprops.drivers_img.path % idx,
                             cmd=self.on_click,
                             extra_args=[idx],
                             **self.menu_props.imgbtn_args)
            name = Text('',
                        pos=(-.75 + col * .5, -.19 - row * .64),
                        scale=.046,
                        **t_a)
            drv_btn._name_txt = name
            widgets += [drv_btn, name]
            self.drivers += [widgets[-2]]
            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'), -.11), (_('speed'), .01),
                       (_('stability'), -.05)]
            widgets += list(
                map(lambda lab_def: self._add_lab(*(lab_def + (row, col))),
                    lab_lst))
            txt_lst = [(self.drv_info[idx - 1].adherence, -.11),
                       (self.drv_info[idx - 1].speed, .01),
                       (self.drv_info[idx - 1].stability, -.05)]
            widgets += list(
                map(
                    lambda txt_def: self._add_txt(*txt_def +
                                                  (psign, pcol, col, row)),
                    txt_lst))
        self.sel_drv_img = []
        self.tss = []
        instr_txt = _(
            'If you use the keyboard, press FIRE to edit the field, then '
            "ENTER when you're done. Other players can't move while someone "
            'is writing (since, with keyboards, some letters may be bound to '
            'movements).')
        instr = Text(instr_txt, pos=(1.28, .8), scale=.042, wordwrap=24, **t_a)
        widgets += [self.name, instr]
        for i, car in enumerate(self.mediator.cars):
            self.sel_drv_img += [
                Img(self.props.gameprops.cars_img % car,
                    parent=base.a2dBottomLeft,
                    pos=(.3, 1.74 - i * .46),
                    scale=.22)
            ]
            widgets += [self.sel_drv_img[-1]]
            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[-1].set_shader(shader)
            self.sel_drv_img[-1].set_transparent()
            self.tss += [TextureStage('ts')]
            self.tss[-1].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[-1].set_texture(self.tss[-1], tex)
        all_names = self.props.gameprops.player_names + self.props.gameprops.stored_player_names[
            len(self.props.gameprops.player_names):]
        self.ents = [
            Entry(scale=.06,
                  pos=(0, .8 - .12 * i),
                  entry_font=menu_props.font,
                  width=12,
                  frame_col=menu_props.btn_col,
                  initial_text=all_names[i]
                  if i < len(all_names) else _('your name'),
                  text_fg=menu_props.text_active_col)
            for i in range(len(self.mediator.cars))
        ]
        self.add_widgets(self.ents)
        self.add_widgets(widgets)
        ThanksPageGui.build(self, exit_behav=False)
        self.update_tsk = taskMgr.add(self.update_text, 'update text')
        self.enable_buttons(False)