Exemplo n.º 1
0
def test_style_returns_property_for_ui_elements():
    style = UIStyle({
        'flatbutton': {
            'normal_color': arcade.color.RED
        },
        'ghostflatbutton': {
            'normal_color': arcade.color.BLUE
        },
    })
    flat = UIFlatButton('Love snakes.', 100, 100, 100, 30, style=style)
    ghost = UIGhostFlatButton('Love snakes.', 100, 100, 100, 30, style=style)

    assert flat.style_attr('normal_color') == arcade.color.RED
    assert ghost.style_attr('normal_color') == arcade.color.BLUE
Exemplo n.º 2
0
    def setup(self):
        self.ui_manager.purge_ui_elements()

        self.ui_manager.add_ui_element(
            UILabel(
                text='Username:'******'username'))
        self.ui_manager.add_ui_element(
            UIFlatButton(text='Login',
                         center_x=650,
                         center_y=self.window.height // 2,
                         width=200,
                         height=40,
                         id='submit_button'))

        self.ui_manager.add_ui_element(
            UILabel(text='',
                    center_x=self.window.width // 2,
                    center_y=self.window.height // 2 - 100,
                    width=600,
                    height=40,
                    id='login_message'))
    def on_show_view(self):
        arcade.set_background_color(arcade.color.BLACK)
        self.ui_manager.purge_ui_elements()

        self.ui_manager.add_ui_element(
            UILabel(
                text='Username:'******'username'))
        self.ui_manager.add_ui_element(
            UIFlatButton(text='Login',
                         center_x=650,
                         center_y=self.window.height // 2,
                         width=200,
                         height=40,
                         id='submit_button'))

        self.ui_manager.add_ui_element(
            UILabel(text='',
                    center_x=self.window.width // 2,
                    center_y=self.window.height // 2 - 100,
                    width=600,
                    height=40,
                    id='login_message'))
Exemplo n.º 4
0
 def button(num, name):
     offset_y = half_panel_height - (BUTTON_HEIGHT + BUTTON_MARGIN) * num
     b = UIFlatButton(
         name,
         center_x=half_width,
         center_y=half_height + offset_y,
         width=BUTTON_WIDTH,
         height=BUTTON_HEIGHT,
     )
     style(b)
     self.ui_manager.add_ui_element(b)
     return b
Exemplo n.º 5
0
    def on_show_view(self):
        arcade.set_background_color(arcade.color.BLACK)
        self.ui_manager.purge_ui_elements()

        flat = UIFlatButton('Hello world',
                            center_x=200,
                            center_y=self.window.height // 2,
                            width=200,
                            height=40)
        flat.set_style_attrs(font_color=arcade.color.WHITE,
                             font_color_hover=arcade.color.WHITE,
                             font_color_press=arcade.color.WHITE,
                             bg_color=(51, 139, 57),
                             bg_color_hover=(51, 139, 57),
                             bg_color_press=(28, 71, 32),
                             border_color=(51, 139, 57),
                             border_color_hover=arcade.color.WHITE,
                             border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(flat)

        # creates a new class, which will match the id
        UIStyle.default_style().set_class_attrs(
            'right_button',
            font_color=arcade.color.WHITE,
            font_color_hover=arcade.color.WHITE,
            font_color_press=arcade.color.WHITE,
            bg_color=(135, 21, 25),
            bg_color_hover=(135, 21, 25),
            bg_color_press=(122, 21, 24),
            border_color=(135, 21, 25),
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(
            UIGhostFlatButton('Hello world',
                              center_x=600,
                              center_y=self.window.height // 2,
                              width=200,
                              height=40,
                              id='right_button'))
Exemplo n.º 6
0
    def setup(self):
        self.background_img = arcade.load_texture(C.RESOURCES +
                                                  'Backgrounds/Menu.png')
        self.ui_manager.purge_ui_elements()

        start = UIFlatButton('PLAY', self.window.width // 2,
                             self.window.height // 2 - 115, 200, 125)

        start.set_style_attrs(font_color=arcade.color.WHITE,
                              font_color_hover=arcade.color.WHITE,
                              font_color_press=arcade.color.WHITE,
                              bg_color=arcade.color.GREEN,
                              bg_color_hover=(0, 150, 0),
                              bg_color_press=arcade.color.DARK_GREEN,
                              border_color_hover=arcade.color.WHITE,
                              border_color=arcade.color.GREEN,
                              border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(start)

        @start.event('on_click')
        def play():
            self.state.update_state()
Exemplo n.º 7
0
    def on_show_view(self):
        arcade.set_background_color(arcade.color.BLACK)
        self.ui_manager.purge_ui_elements()

        self.ui_manager.add_ui_element(
            UIFlatButton('Hello world',
                         center_x=200,
                         center_y=self.window.height // 2,
                         width=200,
                         height=40))

        self.ui_manager.add_ui_element(
            UIGhostFlatButton('Hello world',
                              center_x=600,
                              center_y=self.window.height // 2,
                              width=200,
                              height=40))
Exemplo n.º 8
0
    def on_show_view(self):
        arcade.set_background_color(arcade.color.BLACK)
        self.ui_manager.purge_ui_elements()

        self.ui_manager.add_ui_element(
            UILabel(
                text='Username:'******'username')
        self.ui_manager.add_ui_element(input_box)

        submit_button = UIFlatButton(text='Login',
                                     center_x=650,
                                     center_y=self.window.height // 2,
                                     width=200,
                                     height=40,
                                     id='submit_button')
        self.ui_manager.add_ui_element(submit_button)

        self.ui_manager.add_ui_element(
            UILabel(text='',
                    center_x=self.window.width // 2,
                    center_y=self.window.height // 2 - 100,
                    width=600,
                    height=40,
                    id='login_message'))

        @input_box.event('on_enter')
        @submit_button.event('on_click')
        def submit():
            username_input = cast(UIInputBox,
                                  self.ui_manager.find_by_id('username'))
            username = username_input.text

            login_message: UILabel = cast(
                UILabel, self.ui_manager.find_by_id('login_message'))
            login_message.text = f'Welcome {username}, you are my first player.'
Exemplo n.º 9
0
    def setup(self):
        self.ui_manager.purge_ui_elements()
        self.ui_manager.add_ui_element(UIFlatButton(
            'Hello world',
            center_x=200,
            center_y=self.window.height // 2,
            width=200,
            height=40
        ))

        self.ui_manager.add_ui_element(UIGhostFlatButton(
            'Hello world',
            center_x=600,
            center_y=self.window.height // 2,
            width=200,
            height=40
        ))
Exemplo n.º 10
0
    def setup(self):
        try:
            file = open(resource_path('data/settings.info'), 'rb')
            info = pickle.load(file)
            self.level_stats = info[0]
            self.music = info[1]
            self.sounds = info[2]
        except FileNotFoundError:
            self.level_stats = generator_data.GeneratorData()

        arcade.set_background_color(arcade.color.BLACK)
        if self.level_stats.seed:
            text = str(self.level_stats.seed)
        else:
            text = 'Enter Seed'
        seed_box = UIInputBox(100, C.SCREEN_HEIGHT - 100, 150, 40, text,
                              'seed_box')

        self.ui_manager.add_ui_element(seed_box)

        @seed_box.event('on_enter')
        def set_seed():
            self.level_stats.seed = self.ui_manager.find_by_id('seed_box').text

        self.create_input_box_mv(
            'mv_chance_box',
            str(int(self.level_stats.mv_chance * 100)) + '%',
            'Value must be between 0 and 100%',
            [475, C.SCREEN_HEIGHT - 100, 500, 40], self.level_stats)

        self.create_input_box_mv(
            'mv_chance_x',
            str(int(self.level_stats.mv_chance_x * 100)) + '%',
            'Value must be between 0 and 100%',
            [475, C.SCREEN_HEIGHT - 300, 500, 40], self.level_stats)

        self.create_input_box_mv(
            'mv_chance_y',
            str(int(self.level_stats.mv_chance_y * 100)) + '%',
            'Value must be between 0 and 100%',
            [475, C.SCREEN_HEIGHT - 500, 500, 40], self.level_stats)

        if self.level_stats.mv_chance_xy:
            text = 'True'
        else:
            text = 'False'
        mv_allowed_xy = UIFlatButton(text,
                                     300,
                                     C.SCREEN_HEIGHT - 700,
                                     width=150,
                                     height=50,
                                     id='mv_allowed_xy')
        mv_allowed_xy.set_style_attrs(border_color_hover=arcade.color.WHITE,
                                      border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(mv_allowed_xy)

        @mv_allowed_xy.event('on_click')
        def switch():
            button = self.ui_manager.find_by_id('mv_allowed_xy')
            if button.text == 'True':
                button.text = 'False'
                output = False
            else:
                button.text = 'True'
                output = True
            button.render()
            self.level_stats.mv_chance_xy = output

        max_gap = UIInputBox(975, C.SCREEN_HEIGHT - 100, 400, 40,
                             str(self.level_stats.max_gap), 'max_gap')

        self.ui_manager.add_ui_element(max_gap)

        @max_gap.event('on_enter')
        def update_gap():
            text_box = self.ui_manager.find_by_id('max_gap')
            try:
                gap = int(text_box.text)
                if not 30 < gap:
                    arcade.play_sound(
                        arcade.load_sound(resource_path('sounds/erro.mp3')),
                        0.05)
                    text_box.text = 'Must be over 30'
                    gap = 160
            except ValueError:
                arcade.play_sound(
                    arcade.load_sound(resource_path('sounds/erro.mp3')), 0.05)
                text_box.text = 'Must be an integer'
                gap = 160

            self.level_stats.max_gap = gap

        max_height = UIInputBox(975, C.SCREEN_HEIGHT - 300, 400, 40,
                                str(self.level_stats.max_height), 'max_height')

        self.ui_manager.add_ui_element(max_height)

        @max_height.event('on_enter')
        def update_height():
            text_box = self.ui_manager.find_by_id('max_height')
            try:
                height = int(text_box.text)
                if not 1500 < height:
                    arcade.play_sound(
                        arcade.load_sound(resource_path('sounds/erro.mp3')),
                        0.05)
                    text_box.text = 'Must be over 1500'
                    height = 2500
            except ValueError:
                arcade.play_sound(
                    arcade.load_sound(resource_path('sounds/erro.mp3')), 0.05)
                text_box.text = 'Must be an integer'
                height = 2500

            self.level_stats.max_height = height

        max_platforms = UIInputBox(975, C.SCREEN_HEIGHT - 500, 400, 40,
                                   str(self.level_stats.pl_num),
                                   'max_platforms')

        self.ui_manager.add_ui_element(max_platforms)

        @max_platforms.event('on_enter')
        def update_platforms():
            text_box = self.ui_manager.find_by_id('max_platforms')
            try:
                length = int(text_box.text)
                if not 0 < length:
                    arcade.play_sound(
                        arcade.load_sound(resource_path('sounds/erro.mp3')),
                        0.05)
                    text_box.text = 'Must be over 0'
                    length = 10
            except ValueError:
                arcade.play_sound(
                    arcade.load_sound(resource_path('sounds/erro.mp3')), 0.05)
                text_box.text = 'Must be an integer'
                length = 10

            self.level_stats.pl_num = length

        return_to_menu = UIFlatButton('BACK', 1400, 100, 150, 50, id='return')

        return_to_menu.set_style_attrs(border_color_hover=arcade.color.WHITE,
                                       border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(return_to_menu)

        @return_to_menu.event('on_click')
        def return_to_menu():
            pickle_out = open(resource_path('data/settings.info'), 'wb')
            pickle.dump((self.level_stats, self.music, self.sounds),
                        pickle_out)
            pickle_out.close()
            self.ui_manager.purge_ui_elements()
            self.window.show_view(MainMenu(self.window))

        if self.music:
            text = 'True'
        else:
            text = 'False'
        music = UIFlatButton(text, 850, 200, width=150, height=50, id='music')
        music.set_style_attrs(border_color_hover=arcade.color.WHITE,
                              border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(music)

        @music.event('on_click')
        def switch():
            button = self.ui_manager.find_by_id('music')
            if button.text == 'True':
                button.text = 'False'
                output = False
            else:
                button.text = 'True'
                output = True
            button.render()
            self.music = output

        if self.sounds:
            text = 'True'
        else:
            text = 'False'
        sounds = UIFlatButton(text,
                              1100,
                              200,
                              width=150,
                              height=50,
                              id='sounds')
        sounds.set_style_attrs(border_color_hover=arcade.color.WHITE,
                               border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(sounds)

        @sounds.event('on_click')
        def switch():
            button = self.ui_manager.find_by_id('sounds')
            if button.text == 'True':
                button.text = 'False'
                output = False
            else:
                button.text = 'True'
                output = True
            button.render()
            self.sounds = output
Exemplo n.º 11
0
    def setup(self):
        try:
            file = open(resource_path('data/settings.info'), 'rb')
            info = pickle.load(file)
            self.custom_settings = info[0]
            self.music = info[1]
            self.sounds = info[2]
        except FileNotFoundError:
            self.custom_settings = generator_data.GeneratorData()

        self.level_manager = LevelManager(generator_data.level_list)
        arcade.set_background_color(arcade.color.BLACK)
        if self.music:
            self.play_song()
        self.ui_manager.purge_ui_elements()
        self.window.set_viewport(0, C.SCREEN_WIDTH, 0, C.SCREEN_HEIGHT)
        play_button = PlayButton(self.window, self.ui_manager,
                                 self.level_manager, 'PLAY',
                                 self.window.width // 2, 500, 200, 50)
        play_button.set_style_attrs(font_color=arcade.color.BLACK,
                                    font_color_hover=arcade.color.BLACK,
                                    font_color_press=arcade.color.BLACK,
                                    bg_color=arcade.color.GREEN,
                                    bg_color_hover=(0, 150, 0),
                                    bg_color_press=arcade.color.DARK_GREEN,
                                    border_color=arcade.color.GREEN,
                                    border_color_hover=arcade.color.WHITE,
                                    border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(play_button)

        play_button_endless = PlayButtonEndless(self.window, self.ui_manager,
                                                'PLAY ENDLESS',
                                                self.window.width // 2, 700,
                                                300, 70)
        play_button_endless.set_style_attrs(
            font_color=arcade.color.WHITE,
            bg_color=arcade.color.BLACK,
            border_color=arcade.color.BLACK,
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(play_button_endless)

        play_button_custom = UIFlatButton('PLAY CUSTOM',
                                          self.window.width // 2, 600, 250, 50)
        play_button_custom.set_style_attrs(
            font_color=arcade.color.BLACK,
            font_color_hover=arcade.color.BLACK,
            font_color_press=arcade.color.BLACK,
            bg_color=arcade.color.GREEN,
            bg_color_hover=(0, 150, 0),
            bg_color_press=arcade.color.DARK_GREEN,
            border_color=arcade.color.GREEN,
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(play_button_custom)

        @play_button_custom.event('on_click')
        def play():
            click_sound()
            self.ui_manager.purge_ui_elements()
            self.window.show_view(Game(self.custom_settings))

        level_button = LevelMenuButton(self.window, self.ui_manager,
                                       self.level_manager, 'LEVEL MENU',
                                       self.window.width // 2, 400, 200, 50)
        level_button.set_style_attrs(font_color=arcade.color.BLACK,
                                     font_color_hover=arcade.color.BLACK,
                                     font_color_press=arcade.color.BLACK,
                                     bg_color=arcade.color.BLUE,
                                     bg_color_hover=(0, 0, 150),
                                     bg_color_press=arcade.color.DARK_BLUE,
                                     border_color=arcade.color.BLUE,
                                     border_color_hover=arcade.color.WHITE,
                                     border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(level_button)

        options_button = OptionsMenuButton(self.window, self.ui_manager,
                                           'OPTIONS', self.window.width // 2,
                                           300, 200, 50)
        options_button.set_style_attrs(font_color=arcade.color.BLACK,
                                       font_color_hover=arcade.color.BLACK,
                                       font_color_press=arcade.color.BLACK,
                                       bg_color=arcade.color.BLUE,
                                       bg_color_hover=(0, 0, 150),
                                       bg_color_press=arcade.color.DARK_BLUE,
                                       border_color=arcade.color.BLUE,
                                       border_color_hover=arcade.color.WHITE,
                                       border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(options_button)

        exit_button = ExitButton('EXIT', self.window.width // 2, 200, 200, 50)
        exit_button.set_style_attrs(font_color=arcade.color.BLACK,
                                    font_color_hover=arcade.color.BLACK,
                                    font_color_press=arcade.color.BLACK,
                                    bg_color=arcade.color.RED,
                                    bg_color_hover=(150, 0, 0),
                                    bg_color_press=arcade.color.DARK_RED,
                                    border_color=arcade.color.RED,
                                    border_color_hover=arcade.color.WHITE,
                                    border_color_press=arcade.color.WHITE)

        self.ui_manager.add_ui_element(exit_button)

        self.ui_manager.add_ui_element(
            UILabel('Created by FalconFX9 for the timathon challenge',
                    C.SCREEN_WIDTH // 2, 100))
Exemplo n.º 12
0
def test_ui_element_uses_default_style():
    button = UIFlatButton('Love snakes.', 100, 100, 100, 30)

    assert button._style == UIStyle.default_style()