Example #1
0
 def collide(self, tile, direction, commit=True):
     if commit and isinstance(tile, Sprite):
         if direction == Direction.UP:
             tile.velocity[1] = 3
             Sequence(Func(self.load_toggle), 1, Func(self.load_toggle)).start()
             return False
         return True
     return False
Example #2
0
 def input(key):
     if key == 'space':
         bl.button_dict = {
             'one': None,
             'two': default,
             'tree': Func(test, 3, 4),
             'four': Func(test, b=3, a=4),
         }
Example #3
0
    def make_editor_gui(self):     # called by main after setting up camera and application.development_mode
        from ursina import camera, Text, Button, ButtonList, Func, Tooltip
        import time

        self.editor_ui = Entity(parent=camera.ui, eternal=True, enabled=bool(application.development_mode))
        self.exit_button = Button(parent=self.editor_ui, eternal=True, ignore_paused=True, origin=(.5, .5),
            position=self.top_right, z=-999, scale=(.05, .025), color=color.red.tint(-.2), text='x', on_click=application.quit)
        self.exit_button.enabled = self.borderless


        def _exit_button_input(key):
            from ursina import held_keys, mouse
            if held_keys['shift'] and key == 'q' and not mouse.right:
                self.exit_button.on_click()
        self.exit_button.input = _exit_button_input

        self.fps_counter = Text(parent=self.editor_ui, eternal=True, position=(.5*self.aspect_ratio, .47, -999), origin=(.8,.5), text='60', ignore=False, i=0)

        def _fps_counter_update():
            if self.fps_counter.i > 60:
                self.fps_counter.text = str(int(1//time.dt))
                self.fps_counter.i = 0
            self.fps_counter.i += 1
        self.fps_counter.update = _fps_counter_update


        import webbrowser
        self.cog_menu = ButtonList({
            # 'Build' : Func(print, ' '),
            'API Reference' : Func(webbrowser.open, 'https://www.ursinaengine.org/cheat_sheet_dark.html'),
            'Asset Store' : Func(webbrowser.open, 'https://itch.io/tools/tag-ursina'),
            # 'Open Scene Editor' : Func(print, ' '),
            'Change Render Mode <gray>[F10]<default>' : self.next_render_mode,
            'Reset Render Mode <gray>[F9]<default>' : Func(setattr, self, 'render_mode', 'default'),
            'Reload Models <gray>[F7]<default>' : application.hot_reloader.reload_models,
            'Reload Textures <gray>[F6]<default>' : application.hot_reloader.reload_textures,
            'Reload Code <gray>[F5]<default>' : application.hot_reloader.reload_code,
        },
            width=.35,
            x=.62,
            enabled=False,
            eternal=True
        )
        self.cog_menu.on_click = Func(setattr, self.cog_menu, 'enabled', False)
        self.cog_menu.y = -.5 + self.cog_menu.scale_y
        self.cog_menu.scale *= .75
        self.cog_menu.text_entity.x += .025
        self.cog_menu.highlight.color = color.azure
        self.cog_button = Button(parent=self.editor_ui, eternal=True, model='circle', scale=.015, origin=(1,-1), position=self.bottom_right)
        info_text ='''This menu is not enabled in builds <gray>(unless you set application.development to be not False).'''
        self.cog_menu.info = Button(parent=self.cog_menu, model='quad', text='<gray>?', scale=.1, x=1, y=.01, origin=(.5,-.5), tooltip=Tooltip(info_text, scale=.75, origin=(-.5,-.5)))
        self.cog_menu.info.text_entity.scale *= .75
        def _toggle_cog_menu():
            self.cog_menu.enabled = not self.cog_menu.enabled
        self.cog_button.on_click = _toggle_cog_menu
Example #4
0
 def collide(self, tile, direction, commit=True):
     if commit and 'Player' in str(
             type(tile)
     ) and held_keys['s'] and not TeleporterTile.teleported[self.type.char]:
         Sequence(Func(self.set_teleported, True), teleporter_delay,
                  Func(self.set_teleported, False)).start()
         self.controller.player.position = [
             i for i in teleporter_locations[self.type.char]
             if i != self.position
         ][0]
     return False
Example #5
0
    def __init__(self,
                 texture,
                 animations,
                 tileset_size=[4, 1],
                 fps=12,
                 model='quad',
                 autoplay=True,
                 **kwargs):
        kwargs['model'] = model
        kwargs['texture'] = texture
        kwargs['tileset_size'] = tileset_size
        super().__init__(**kwargs)

        self.animations = animations  # should be a dict

        for key, value in self.animations.items():
            start_coord, end_coord = value
            s = Sequence(loop=True)

            for y in range(start_coord[1], end_coord[1] + 1):
                for x in range(start_coord[0], end_coord[0] + 1):
                    s.extend([
                        Func(setattr, self, 'tile_coordinate', (x, y)),
                        Wait(1 / fps)
                    ])
            self.animations[key] = s
Example #6
0
    def make_editor_gui(
        self
    ):  # called by main after setting up camera and application.development_mode
        from ursina import camera, Text, Button, ButtonList, Func
        import time

        if not application.development_mode:
            return
        self.editor_ui = Entity(parent=camera.ui, eternal=True)
        self.exit_button = Button(parent=self.editor_ui,
                                  eternal=True,
                                  origin=(.5, .5),
                                  position=self.top_right,
                                  z=-999,
                                  scale=(.05, .025),
                                  color=color.red.tint(-.2),
                                  text='x',
                                  on_click=application.quit)

        def _exit_button_input(key):
            from ursina import held_keys, mouse
            if held_keys['shift'] and key == 'q' and not mouse.right:
                self.exit_button.on_click()

        self.exit_button.input = _exit_button_input

        self.fps_counter = Text(parent=self.editor_ui,
                                eternal=True,
                                position=(.5 * self.aspect_ratio, .47, -999),
                                origin=(.8, .5),
                                text='60',
                                ignore=False,
                                i=0)

        def _fps_counter_update():
            if self.fps_counter.i > 60:
                self.fps_counter.text = str(int(1 // time.dt))
                self.fps_counter.i = 0
            self.fps_counter.i += 1

        self.fps_counter.update = _fps_counter_update

        import webbrowser
        self.cog_menu = ButtonList(
            {
                # 'Build' : Func(print, ' '),
                'Asset Store':
                Func(webbrowser.open, "https://itch.io/tools/tag-ursina"),
                # 'Open Scene Editor' : Func(print, ' '),
                'Reload Textures [F6]':
                application.hot_reloader.reload_textures,
                'Reload Models [F7]':
                application.hot_reloader.reload_models,
                'Reload Code [F5]':
                application.hot_reloader.reload_code,
            },
            width=.3,
            x=.64,
            enabled=False,
            eternal=True)
        self.cog_menu.on_click = Func(setattr, self.cog_menu, 'enabled', False)
        self.cog_menu.y = -.5 + self.cog_menu.scale_y
        self.cog_menu.scale *= .75
        self.cog_menu.text_entity.x += .025
        self.cog_menu.highlight.color = color.azure
        self.cog_button = Button(parent=self.editor_ui,
                                 eternal=True,
                                 model='circle',
                                 scale=.015,
                                 origin=(1, -1),
                                 position=self.bottom_right)

        def _toggle_cog_menu():
            self.cog_menu.enabled = not self.cog_menu.enabled

        self.cog_button.on_click = _toggle_cog_menu
Example #7
0
    def update(self):
        self.highlight.enabled = mouse.hovered_entity == self
        if mouse.hovered_entity == self:
            y = floor(-mouse.point.y * len(self.button_dict))
            self.highlight.y = -y / len(self.button_dict)

    def on_disable(self):
        self.selection_marker.enabled = False


if __name__ == '__main__':
    from ursina import Ursina, Func
    app = Ursina()

    default = Func(print, 'not yet implemented')

    def test(a=1, b=2):
        print('------:', a, b)

    button_dict = {}
    for i in range(6, 20):
        button_dict[f'button {i}'] = Func(print, i)

    bl = ButtonList(button_dict, font='VeraMono.ttf')

    def input(key):
        if key == 'space':
            bl.button_dict = {
                'one': None,
                'two': default,