Beispiel #1
0
    def make_exit_button(self):  # called by main after setting up camera
        from ursina.prefabs.exit_button import ExitButton
        self.exit_button = ExitButton()

        from ursina import Text
        import time
        self.fps_counter = Text(
            name='fps_counter',
            parent=scene.ui,
            eternal=True,
            position=(.5 * self.aspect_ratio, .47, -999),
            origin=(.8, .5),
            text='60',
            add_to_scene_entities=True,
            # background = True,
            i=0,
        )

        def 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 = update

        self.overlay = Entity(name='overlay',
                              parent=scene.ui,
                              model='quad',
                              scale_x=self.aspect_ratio,
                              color=color.clear,
                              eternal=True,
                              z=-99)
Beispiel #2
0
 def __init__(self):
     super().__init__(model='sphere',
                      texture='skybox',
                      scale=500,
                      double_sided=True)
     Text(
         'Press W, A, S, D to control character and left mouse button to place bomb.',
         origin=(0, -.5),
         y=-.4)
Beispiel #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
Beispiel #4
0
    def text(self, value):
        if type(value) is str:
            if not self.text_entity:
                self.text_entity = Text(
                    parent=self,
                    size=Text.size * 20,
                    position=(-self.origin[0], -self.origin[1], -.1),
                    origin=(0, 0),
                    add_to_scene_entities=False,
                )

            self.text_entity.text = value
            self.text_entity.world_scale = (1, 1, 1)
Beispiel #5
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.phoneme_store = None
     self.voxels = []
     self.correct = False
     self.started = False
     self.update_counter = None
     self.score = 0
     self.difficulty = 3     # lower difficulty is harder
     self.help_text = Text(
         '',
         parent=camera.ui,
         x=-.6,
         y=.35,
         enabled=False
     )
     self.score_text = Text(
         '',
         parent=camera.ui,
         x=.5,
         y=.35,
         enabled=False
     )
     self.player = None
     self.ground = Entity(model='plane', scale=(100, 1, 100), y=-1, color=color.yellow.tint(-.2), texture='white_cube',
                          texture_scale=(100, 100), collider='box', enabled=False)
     self.sky = Entity(model='sphere', texture='sky2.jpg', scale=10000, double_sided=True, color=color.white, enabled=False)
     self.rotated_y = 30
     self.next_block = Entity(parent=camera.ui, rotation=Vec3(10, 30, 30), model='cube', scale=.1, x=.7, y=.2, texture='index')
     self.give_up_button = Button(parent=scene, text='give up', double_sided=True, x=-1, z=ARENA_DEPTH, y=3, on_click=self.give_up, enabled=False, scale_x=2)
     self.reset_text = Text(
         'Press ESC to change words and/or start again.',
         parent=scene,
         x=0, z=ARENA_DEPTH, y=2,
         double_sided=True,
         enabled=False,
         scale=15
     )
Beispiel #6
0
    def layout(self):
        [destroy(c) for c in self.buttons]
        self.buttons = []
        spacing = .05
        longest_word = max(self.options, key=len) + '__'  # padding
        width = Text.get_width(longest_word) / Text.size / 2

        for e in self.options:
            b = Button(parent=self, text=e, name=e, scale_x=width, scale_y=.9)
            b.value = e
            b.highlight_scale = 1
            b.pressed_scale = 1
            self.buttons.append(b)

        grid_layout(self.buttons, spacing=(0.025, 0, 0), origin=(-.5, .5, 0))
Beispiel #7
0
    def __init__(self,
                 button_dict,
                 button_height=1.1,
                 width=.5,
                 font=Text.default_font,
                 **kwargs):
        super().__init__(parent=camera.ui,
                         model='quad',
                         scale=(width, 1),
                         color=Button.color,
                         origin=(-.5, .5),
                         position=(-.25, .45),
                         collider='box')

        self.button_height = button_height
        self.text_entity = Text(parent=self,
                                font=font,
                                origin=(-.5, .5),
                                text='empty',
                                world_scale=20,
                                z=-.1,
                                x=.01,
                                line_height=button_height)
        self.highlight = Entity(parent=self,
                                model='quad',
                                color=color.white33,
                                scale=(1, self.button_height),
                                origin=(-.5, .5),
                                z=-.01,
                                add_to_scene_entities=False)
        self.selection_marker = Entity(parent=self,
                                       model='quad',
                                       color=color.azure,
                                       scale=(1, self.button_height),
                                       origin=(-.5, .5),
                                       z=-.02,
                                       enabled=False,
                                       add_to_scene_entities=False)
        self.button_dict = button_dict

        for key, value in kwargs.items():
            setattr(self, key, value)
Beispiel #8
0
        print("STOP!")
        car_speed = 0

    Steer_Slider.value = steer_value
    Speed_Slider.value = car_speed

    if CONNECTED:
        send(encode_msg(car_speed, steer_value))

    sleep(0.1)


contr_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect_button = GeneralButton("Connect", connect)
help_text = Text(
    "Use W and S to move forward or backwards.\n Use A and D to steer.\n Press [SPACE] to stop immediately",
    origin=(0, 4))

# Camera setup
camera_view = CameraView()


def set_speed():
    car_speed = Speed_Slider.value


def set_steer():
    steer_value = Steer_Slider.value


Steer_Slider = Slider(min=-1.0,
Beispiel #9
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
Beispiel #10
0
        except:
            pass

    def close(self):
        if self.popup:
            self.bg.enabled = False
        self.animate_scale_y(0, duration=.1)
        invoke(setattr, self, 'enabled', False, delay=.2)


if __name__ == '__main__':
    '''
    WindowPanel is an easy way to create UI. It will automatically layout the content.
    '''
    from ursina import Ursina, ButtonGroup
    app = Ursina()
    wp = WindowPanel(
        title='Custom Window',
        content=(
            Text('Name:'),
            InputField(name='name_field'),
            Button(text='Submit', color=color.azure),
            Slider(),
            Slider(),
            ButtonGroup(('test', 'eslk', 'skffk'))
            ),
        )


    app.run()