Example #1
0
 def __init__(self, target, **kwargs):
     super(BattleMenuState, self).__init__(target, **kwargs)
     print('battle menu state here, how ya doin', self, target)
     overlay = App.get_running_app().overlay
     self.move_button = Button(
         text='Move', on_release=lambda dt: self.change(SelectMoveState))
     self.attack_button = Button(
         text='Attack',
         on_release=lambda dt: self.change(SelectAttackState))
     self.wait_button = Button(text='Wait',
                               on_release=lambda dt: self.change(TurnEnd))
     menu = GridLayout(cols=1,
                       size_hint=(None, None),
                       row_force_default=True,
                       row_default_height=40)
     menu.width = dp(100)
     menu.height = menu.minimum_height
     buttons = [self.move_button, self.attack_button, self.wait_button]
     for button in buttons:
         menu.add_widget(button)
     menu.y = dp((Window.height / 2) + (menu.height / 2))
     menu.x = dp(40)
     self.menu = menu
     overlay.add_widget(self.menu)
     self.target.game.set_focus_target(self.target)
    def __init__(self, app, game_controller, user_interaction, *args,
                 **kwargs):
        super().__init__(*args, **kwargs)
        '''
        params:-
            app : Visualliser : Object that has spawned this one
            game_controller : Game assigned to this board
            user_interaction : bool : True if you want the user to be able to interact with the visuals else False
        '''
        self.cols = 2

        board_grid = GridLayout()

        self.app = app
        self.game_controller = game_controller

        # will hold all squares created by below function for later callback
        self.squares = []

        board_map = game_controller.get_map()

        # Makes a vertical board
        board_grid.cols = board_map._size[0]
        board_grid.rows = board_map._size[1] * board_map._size[2]

        # Loops through all map coords
        for z, y, x in loops(range(board_map._size[2]),
                             range(board_map._size[1]),
                             range(board_map._size[0])):

            current = board_map.get_gridpoi(x, y, z)

            temp = Square(app, game_controller, x, y, z)
            temp.update_square(x, y, z, current)
            self.squares.append(temp)

            board_grid.add_widget(temp)

        self.add_widget(board_grid)

        if user_interaction:
            attack_board_ui = GridLayout()
            attack_board_ui.size_hint_x = None
            attack_board_ui.width = 50

            attack_board_ui.cols = len(board_map._get_attack_board_array()[0])
            attack_board_ui.rows = len(board_map._get_attack_board_array())

            for y, x in loops(
                    range(len(board_map._get_attack_board_array())),
                    range(len(board_map._get_attack_board_array()[0]))):

                temp = Square(app, game_controller, x, y, 'AttackBoard')
                attack_board_ui.add_widget(temp)

            self.add_widget(attack_board_ui)
Example #3
0
 def __init__(self, target, **kwargs):
     super(BattleMenuState, self).__init__(target, **kwargs)
     print('battle menu state here, how ya doin', self, target)
     overlay = App.get_running_app().overlay
     self.move_button = Button(text='Move', on_release=lambda dt: self.change(SelectMoveState))
     self.attack_button = Button(text='Attack', on_release=lambda dt: self.change(SelectAttackState))
     self.wait_button = Button(text='Wait', on_release=lambda dt: self.change(TurnEnd))
     menu = GridLayout(cols=1, size_hint=(None, None), row_force_default=True, row_default_height=40)
     menu.width = dp(100)
     menu.height = menu.minimum_height
     buttons = [self.move_button, self.attack_button, self.wait_button]
     for button in buttons:
         menu.add_widget(button)
     menu.y = dp((Window.height / 2) + (menu.height / 2))
     menu.x = dp(40)
     self.menu = menu
     overlay.add_widget(self.menu)
     self.target.game.set_focus_target(self.target)
    def __init__(self, height: int, backCallback: callable, homeCallback: callable, **kwargs):
        super(BottomBar, self).__init__(**kwargs)

        bottomBack = Image()
        bottomBack.color = [0, 0, 0, 1]
        bottomBack.width = Window.size[0]
        bottomBack.height = height
        self.add_widget(bottomBack)

        btnGrid = GridLayout()
        btnGrid.cols = 5
        btnGrid.rows = 1
        btnGrid.width = Window.size[0]
        btnGrid.height = height
        self.add_widget(btnGrid)

        btnBack = Button(text="Back")
        btnBack.bind(on_press=lambda instance: backCallback())
        btnGrid.add_widget(btnBack, 0)

        btnHome = Button(text="Home")
        btnHome.bind(on_press=lambda instance: homeCallback())
        btnGrid.add_widget(btnHome, 1)
    def __init__(self, **kwargs):
        super(FontConstructor, self).__init__(spacing=5, **kwargs)

        self.orientation = 'vertical'
        self.width = 30

        # end of self init

        def initialize_workspace_with_size(rows, cols, matrix=None):
            global frames, buttons, current_frame
            for button_row in buttons:
                for button in button_row:
                    pixels.remove_widget(button)
            pixels.cols = cols
            pixels.rows = rows
            if matrix:
                frames = matrix
            else:
                frames = [np.zeros((rows, cols), dtype=np.uint8)]
            buttons = []
            current_frame = 0
            frame_label.text = f'Frame: {current_frame}'
            for i in range(0, rows):
                button_row = []
                for j in range(0, cols):
                    btn = ToggleButton()
                    button_row.append(btn)
                    btn.row = i
                    btn.column = j
                    btn.bind(on_press=process_matrix_changes)
                    pixels.add_widget(btn)
                buttons.append(button_row)

        def load_callback(instance):
            global frames
            frames = list(np.load(filename_input.text + '.npy'))
            print(frames)
            initialize_workspace_with_size(*frames[0].shape, matrix=frames)
            # print(frames[0].shape)
            update_buttons()

        def save_callback(instance):
            np.save(filename_input.text, frames)
            print(frames)

        def new_file_callback(instance):
            global cols, rows
            cols = int(size_w_input.text)
            rows = int(size_h_input.text)
            initialize_workspace_with_size(rows, cols)
            popup.dismiss()

        content = BoxLayout(orientation='vertical')
        size_holder = BoxLayout(orientation='horizontal', size_hint_max_y=40)
        content.add_widget(size_holder)
        size_label_x = Label(text="Columns:")
        size_holder.add_widget(size_label_x)
        size_w_input = TextInput(text=str(cols),
                                 multiline=False,
                                 size_hint_max_x=40)
        size_holder.add_widget(size_w_input)
        size_label_y = Label(text="Rows:")
        size_holder.add_widget(size_label_y)
        size_h_input = TextInput(text=str(rows),
                                 multiline=False,
                                 size_hint_max_x=40)
        size_holder.add_widget(size_h_input)
        button_holder = BoxLayout(orientation='horizontal', size_hint_max_y=40)
        content.add_widget(button_holder)
        create_button = Button(text='Create', on_press=new_file_callback)
        button_holder.add_widget(create_button)

        popup = Popup(title='Select size',
                      content=content,
                      size_hint=(0.8, 0.5),
                      auto_dismiss=False)

        menu = BoxLayout(orientation='horizontal',
                         size_hint=(1, 0.1),
                         spacing=3)
        self.add_widget(menu)

        new_file_button = Button(text="New file", on_press=popup.open)
        menu.add_widget(new_file_button)

        save_button = Button(text="Save", on_press=save_callback)
        menu.add_widget(save_button)

        load_button = Button(text="Load", on_press=load_callback)
        menu.add_widget(load_button)

        cancel_button = Button(text='Cancel', on_press=popup.dismiss)
        button_holder.add_widget(cancel_button)

        # -----

        pixels = GridLayout(spacing=1)
        pixels.cols = cols
        pixels.rows = rows
        pixels.width = pixels.cols * 2
        self.add_widget(pixels)

        settings = BoxLayout(spacing=2,
                             orientation='horizontal',
                             size_hint=(1, 0.1))
        self.add_widget(settings)

        filename_input = TextInput(text='matrix', multiline=False)
        settings.add_widget(filename_input)

        def update_buttons():
            for i in range(0, rows):
                for j in range(0, cols):
                    if frames[current_frame][i][j] == 1:
                        buttons[i][j].state = 'down'
                    else:
                        buttons[i][j].state = 'normal'

        def add_frame(instance):
            # frames.append(np.zeros((7, 11), dtype=np.uint8))
            frames.append(frames[current_frame].copy())
            next_frame(instance)

        def rem_frame(instance):
            frames.pop(current_frame)

        def next_frame(instance):
            global current_frame
            if current_frame != len(frames) - 1:
                current_frame += 1
                frame_label.text = f'Frame: {current_frame}'
                update_buttons()

        def prev_frame(instance):
            global current_frame
            if current_frame != 0:
                current_frame -= 1
                frame_label.text = f'Frame: {current_frame}'
                update_buttons()

        frame_label = Label(text=f'Frame: {current_frame}')
        settings.add_widget(frame_label)
        prev_frame_button = Button(text='<<',
                                   size_hint_max_x=30,
                                   on_press=prev_frame)
        settings.add_widget(prev_frame_button)
        next_frame_button = Button(text='>>',
                                   size_hint_max_x=30,
                                   on_press=next_frame)
        settings.add_widget(next_frame_button)
        add_frame_button = Button(text='+',
                                  size_hint_max_x=30,
                                  on_press=add_frame)
        settings.add_widget(add_frame_button)
        remove_frame_button = Button(text='-',
                                     size_hint_max_x=30,
                                     on_press=rem_frame)
        settings.add_widget(remove_frame_button)

        def process_matrix_changes(instance):
            if instance.state == 'down':
                frames[current_frame][instance.row][instance.column] = 1
            else:
                frames[current_frame][instance.row][instance.column] = 0

        for i in range(0, rows):
            button_row = []
            for j in range(0, cols):
                btn = ToggleButton()
                button_row.append(btn)
                btn.row = i
                btn.column = j
                btn.bind(on_press=process_matrix_changes)
                pixels.add_widget(btn)
            buttons.append(button_row)

        # ----

        def print_debug(instance):
            print(np.asarray(frames))
            print("------------------")

        def translate_right(instance):
            frames[current_frame] = np.roll(frames[current_frame], 1, axis=1)
            update_buttons()

        def translate_left(instance):
            frames[current_frame] = np.roll(frames[current_frame], -1, axis=1)
            update_buttons()

        def translate_up(instance):
            frames[current_frame] = np.roll(frames[current_frame], -1, axis=0)
            update_buttons()

        def translate_down(instance):
            frames[current_frame] = np.roll(frames[current_frame], 1, axis=0)
            update_buttons()

        # status = BoxLayout(orientation='horizontal', size_hint=(1, 0.1), spacing=1)
        # self.add_widget(status)

        btn_left = Button(text='<-',
                          size_hint_max_x=30,
                          on_press=translate_left)
        settings.add_widget(btn_left)

        btn_right = Button(text='->',
                           size_hint_max_x=30,
                           on_press=translate_right)
        settings.add_widget(btn_right)

        btn_up = Button(text='/\\', size_hint_max_x=30, on_press=translate_up)
        settings.add_widget(btn_up)

        btn_down = Button(text='\/',
                          size_hint_max_x=30,
                          on_press=translate_down)
        settings.add_widget(btn_down)