예제 #1
0
파일: app.py 프로젝트: yyq90/pyxel
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != ".pyxel":
            resource_file += ".pyxel"

        pyxel.init(
            EDITOR_WIDTH,
            EDITOR_HEIGHT,
            caption="Pyxel Editor - {}".format(resource_file),
        )

        try:
            pyxel.load(resource_file)
        except FileNotFoundError:
            pass

        super().__init__(None, 0, 0, pyxel.width, pyxel.height)

        self._resource_file = resource_file
        self._editor_list = [
            ImageEditor(self),
            TileMapEditor(self),
            SoundEditor(self),
            MusicEditor(self),
        ]
        self._editor_button = RadioButton(self, 1, 1, 3, 0, 16, 4, EDITOR_IMAGE)
        self._undo_button = ImageButton(self, 48, 1, 3, 36, 16)
        self._redo_button = ImageButton(self, 57, 1, 3, 45, 16)
        self._save_button = ImageButton(self, 75, 1, 3, 54, 16)
        self.help_message = ""

        self._editor_button.add_event_handler(
            "change", lambda value: self.set_editor(value)
        )
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._undo_button.add_event_handler("press", self.__on_undo_press)
        self._redo_button.add_event_handler("press", self.__on_redo_press)
        self._save_button.add_event_handler("press", self.__on_save_press)
        self._editor_button.add_event_handler(
            "mouse_hover", self.__editor_button_on_mouse_hover
        )
        self._undo_button.add_event_handler(
            "mouse_hover", self.__undo_button_on_mouse_hover
        )
        self._redo_button.add_event_handler(
            "mouse_hover", self.__redo_button_on_mouse_hover
        )
        self._save_button.add_event_handler(
            "mouse_hover", self.__save_button_on_mouse_hover
        )

        self.set_editor(0)

        image_file = os.path.join(os.path.dirname(__file__), "assets", "editor.png")
        pyxel.image(3, system=True).load(0, 16, image_file)

        pyxel.run(self.update_widgets, self.draw_widgets)
예제 #2
0
    def __init__(self, parent):
        super().__init__(parent)

        self._drawing_panel = DrawingPanel(self, is_tilemap_mode=False)
        self._image_panel = ImagePanel(self, is_tilemap_mode=False)
        self._color_picker = ColorPicker(self, 11, 156, 7, with_shadow=False)
        self._tool_button = RadioButton(
            self,
            81,
            161,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 63,
            EDITOR_IMAGE_Y,
            7,
            TOOL_PENCIL,
        )
        self._image_picker = NumberPicker(self, 192, 161, 0,
                                          pyxel.USER_IMAGE_BANK_COUNT - 1, 0)

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
        self.add_event_handler("drop", self.__on_drop)
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._color_picker.add_event_handler(
            "mouse_hover", self.__on_color_picker_mouse_hover)
        self.add_tool_button_help(self._tool_button)
        self.add_number_picker_help(self._image_picker)
예제 #3
0
    def __init__(self, parent):
        super().__init__(parent)

        self._drawing_panel = DrawingPanel(self, is_tilemap_mode=True)
        self._tilemap_panel = TilemapPanel(self)
        self._image_panel = ImagePanel(self, is_tilemap_mode=True)
        self._tilemap_picker = NumberPicker(self, 48, 161, 0,
                                            TILEMAP_BANK_COUNT - 1, 0)
        self._tool_button = RadioButton(self, 81, 161, 3, EDITOR_IMAGE_X + 63,
                                        EDITOR_IMAGE_Y, 7, TOOL_PENCIL)
        self._image_picker = NumberPicker(
            self,
            192,
            161,
            0,
            IMAGE_BANK_COUNT - 2,
            pyxel.tilemap(self._tilemap_picker.value).refimg,
        )

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._tilemap_picker.add_event_handler("change",
                                               self.__on_tilemap_picker_change)
        self._image_picker.add_event_handler("change",
                                             self.__on_image_picker_change)
        self.add_number_picker_help(self._tilemap_picker)
        self.add_number_picker_help(self._image_picker)
        self.add_tool_button_help(self._tool_button)
예제 #4
0
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != ".pyxel":
            resource_file += ".pyxel"

        pyxel.init(
            EDITOR_WIDTH,
            EDITOR_HEIGHT,
            caption="Pyxel Editor - {}".format(resource_file),
        )

        try:
            pyxel.load(resource_file)
        except FileNotFoundError:
            pass

        self._resource_file = resource_file
        self._root_widget = Widget(None, 0, 0, 0, 0)

        self._screen_list = [
            ImageEditor(self._root_widget),
            TileMapEditor(self._root_widget),
            SoundEditor(self._root_widget),
            MusicEditor(self._root_widget),
        ]

        self._screen_button = RadioButton(self._root_widget, 3, 1, 3, 3, 13, 4)
        self._screen_button.add_event_handler(
            "change", lambda value: self.set_screen(value))
        self.set_screen(0)

        self._undo_button = ImageButton(self._root_widget, 48, 1, 3, 48, 13)
        self._undo_button.add_event_handler("press", self.__on_undo_press)

        self._redo_button = ImageButton(self._root_widget, 57, 1, 3, 57, 13)
        self._redo_button.add_event_handler("press", self.__on_redo_press)

        self._save_button = ImageButton(self._root_widget, 75, 1, 3, 75, 13)
        self._save_button.add_event_handler("press", self.__on_save_press)

        pyxel.run(self.update, self.draw)
예제 #5
0
    def __init__(self, parent):
        super().__init__(parent, "image_editor.png")

        self._edit_frame = EditFrame(self, is_tilemap_mode=False)
        self._image_frame = ImageFrame(self, is_tilemap_mode=False)
        self._color_picker = ColorPicker(self, 11, 156)
        self._tool_button = RadioButton(self, 81, 161, 3, 81, 173, 7)
        self._image_number = NumberPicker(self, 192, 161, 0,
                                          RENDERER_IMAGE_COUNT - 2)

        self.color = 7
        self.tool = 1

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
예제 #6
0
파일: image_editor.py 프로젝트: gfeun/pyxel
    def __init__(self, parent):
        super().__init__(parent)

        self._drawing_panel = DrawingPanel(self, is_tilemap_mode=False)
        self._image_panel = ImagePanel(self, is_tilemap_mode=False)
        self._color_picker = ColorPicker(self, 11, 156, 7, with_shadow=False)
        self._tool_button = RadioButton(self, 81, 161, 3, EDITOR_IMAGE_X + 63,
                                        EDITOR_IMAGE_Y, 7, TOOL_PENCIL)
        self._image_picker = NumberPicker(self, 192, 161, 0,
                                          RENDERER_IMAGE_COUNT - 2, 0)

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self.add_tool_button_help(self._tool_button)
        self.add_number_picker_help(self._image_picker)
예제 #7
0
    def __init__(self, parent):
        super().__init__(parent, "tilemap_editor.png")

        self._edit_frame = EditFrame(self, is_tilemap_mode=True)
        self._tilemap_frame = TilemapFrame(self)
        self._select_frame = ImageFrame(self, is_tilemap_mode=True)
        self._tilemap_number = NumberPicker(self, 48, 161, 0,
                                            RENDERER_TILEMAP_COUNT - 1)
        self._tool_button = RadioButton(self, 81, 161, 3, 81, 173, 7)
        self._image_number = NumberPicker(self, 192, 161, 0,
                                          RENDERER_IMAGE_COUNT - 2)

        self.color = 0
        self.tool = 1

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
        self.add_event_handler("update", self.__on_update)
예제 #8
0
    def __init__(self, parent):
        super().__init__(parent)

        self._edit_frame = EditFrame(self, is_tilemap_mode=True)
        self._tilemap_frame = TilemapFrame(self)
        self._image_frame = ImageFrame(self, is_tilemap_mode=True)
        self._tilemap_picker = NumberPicker(self, 48, 161, 0,
                                            RENDERER_TILEMAP_COUNT - 1, 0)
        self._tool_button = RadioButton(self, 81, 161, 3, 63, 16, 7,
                                        TOOL_PENCIL)
        self._image_picker = NumberPicker(self, 192, 161, 0,
                                          RENDERER_IMAGE_COUNT - 2, 0)

        self.add_event_handler("undo", self.__on_undo)
        self.add_event_handler("redo", self.__on_redo)
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self.add_number_picker_help(self._tilemap_picker)
        self.add_number_picker_help(self._image_picker)
        self.add_tool_button_help(self._tool_button)
예제 #9
0
class EditorApp:
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != ".pyxel":
            resource_file += ".pyxel"

        pyxel.init(
            EDITOR_WIDTH,
            EDITOR_HEIGHT,
            caption="Pyxel Editor - {}".format(resource_file),
        )

        try:
            pyxel.load(resource_file)
        except FileNotFoundError:
            pass

        self._resource_file = resource_file
        self._root_widget = Widget(None, 0, 0, 0, 0)

        self._screen_list = [
            ImageEditor(self._root_widget),
            TileMapEditor(self._root_widget),
            SoundEditor(self._root_widget),
            MusicEditor(self._root_widget),
        ]

        self._screen_button = RadioButton(self._root_widget, 3, 1, 3, 3, 13, 4)
        self._screen_button.add_event_handler(
            "change", lambda value: self.set_screen(value))
        self.set_screen(0)

        self._undo_button = ImageButton(self._root_widget, 48, 1, 3, 48, 13)
        self._undo_button.add_event_handler("press", self.__on_undo_press)

        self._redo_button = ImageButton(self._root_widget, 57, 1, 3, 57, 13)
        self._redo_button.add_event_handler("press", self.__on_redo_press)

        self._save_button = ImageButton(self._root_widget, 75, 1, 3, 75, 13)
        self._save_button.add_event_handler("press", self.__on_save_press)

        pyxel.run(self.update, self.draw)

    def set_screen(self, screen):
        self._screen_button.value = screen

        for i, widget in enumerate(self._screen_list):
            widget.is_visible = i == screen

    def update(self):
        if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT):
            screen = self._screen_button.value
            screen_count = len(self._screen_list)

            if pyxel.btnp(pyxel.KEY_LEFT):
                self.set_screen((screen - 1) % screen_count)
            elif pyxel.btnp(pyxel.KEY_RIGHT):
                self.set_screen((screen + 1) % screen_count)

        screen = self._screen_list[self._screen_button.value]
        self._undo_button.is_enabled = screen.can_undo
        self._redo_button.is_enabled = screen.can_redo

        if pyxel.btn(pyxel.KEY_CONTROL):
            if screen.can_undo and pyxel.btnp(pyxel.KEY_S):
                self._save_button.press()
            elif screen.can_undo and pyxel.btnp(pyxel.KEY_Z):
                self._undo_button.press()
            elif screen.can_redo and pyxel.btnp(pyxel.KEY_Y):
                self._redo_button.press()

        Widget.update(self._root_widget)

    def draw(self):
        pyxel.cls(6)
        Widget.draw(self._root_widget)

    def __on_undo_press(self):
        self._screen_list[self._screen_button.value].undo()

    def __on_redo_press(self):
        self._screen_list[self._screen_button.value].redo()

    def __on_save_press(self):
        pyxel.save(self._resource_file)
예제 #10
0
파일: app.py 프로젝트: sacredhotdog/pyxel
class App(Widget):
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != ".pyxel":
            resource_file += ".pyxel"

        pyxel.init(APP_WIDTH,
                   APP_HEIGHT,
                   caption="Pyxel Editor - {}".format(resource_file))

        try:
            pyxel.load(resource_file)
        except FileNotFoundError:
            pass

        super().__init__(None, 0, 0, pyxel.width, pyxel.height)

        self._resource_file = resource_file
        self._editor_list = [
            ImageEditor(self),
            TileMapEditor(self),
            SoundEditor(self),
            MusicEditor(self),
        ]
        self._editor_button = RadioButton(self, 1, 1, 3, EDITOR_IMAGE_X,
                                          EDITOR_IMAGE_Y, 4, 0)
        self._undo_button = ImageButton(self, 48, 1, 3, EDITOR_IMAGE_X + 36,
                                        EDITOR_IMAGE_Y)
        self._redo_button = ImageButton(self, 57, 1, 3, EDITOR_IMAGE_X + 45,
                                        EDITOR_IMAGE_Y)
        self._save_button = ImageButton(self, 75, 1, 3, EDITOR_IMAGE_X + 54,
                                        EDITOR_IMAGE_Y)
        self.help_message = ""

        self._editor_button.add_event_handler(
            "change", lambda value: self.set_editor(value))
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._undo_button.add_event_handler("press",
                                            self.__on_undo_button_press)
        self._undo_button.add_event_handler("repeat",
                                            self.__on_undo_button_press)
        self._redo_button.add_event_handler("press",
                                            self.__on_redo_button_press)
        self._redo_button.add_event_handler("repeat",
                                            self.__on_redo_button_press)
        self._save_button.add_event_handler("press",
                                            self.__on_save_button_press)
        self._editor_button.add_event_handler(
            "mouse_hover", self.__on_editor_button_mouse_hover)
        self._undo_button.add_event_handler("mouse_hover",
                                            self.__on_undo_button_mouse_hover)
        self._redo_button.add_event_handler("mouse_hover",
                                            self.__on_redo_button_mouse_hover)
        self._save_button.add_event_handler("mouse_hover",
                                            self.__on_save_button_mouse_hover)

        self.set_editor(0)

        image_file = os.path.join(os.path.dirname(__file__), "assets",
                                  EDITOR_IMAGE_NAME)
        pyxel.image(3, system=True).load(EDITOR_IMAGE_X, EDITOR_IMAGE_Y,
                                         image_file)

        pyxel.mouse(True)

        pyxel.run(self.update_widgets, self.draw_widgets)

    def set_editor(self, editor):
        self._editor_button.value = editor

        for i, widget in enumerate(self._editor_list):
            widget.is_visible = i == editor

    def __on_update(self):
        if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT):
            editor = self._editor_button.value
            editor_count = len(self._editor_list)

            if pyxel.btnp(pyxel.KEY_LEFT):
                self.set_editor((editor - 1) % editor_count)
            elif pyxel.btnp(pyxel.KEY_RIGHT):
                self.set_editor((editor + 1) % editor_count)

        editor = self._editor_list[self._editor_button.value]
        self._undo_button.is_enabled = editor.can_undo
        self._redo_button.is_enabled = editor.can_redo

        if pyxel.btn(pyxel.KEY_CONTROL):
            if pyxel.btnp(pyxel.KEY_S):
                self._save_button.press()

            if editor.can_undo and pyxel.btnp(pyxel.KEY_Z):
                self._undo_button.press()

            if editor.can_redo and pyxel.btnp(pyxel.KEY_Y):
                self._redo_button.press()

    def __on_draw(self):
        pyxel.cls(WIDGET_BACKGROUND_COLOR)
        pyxel.rect(0, 0, 239, 8, WIDGET_PANEL_COLOR)
        pyxel.line(0, 9, 239, 9, WIDGET_SHADOW_COLOR)

        pyxel.text(93, 2, self.help_message, 13)
        self.help_message = ""

    def __on_undo_button_press(self):
        self._editor_list[self._editor_button.value].undo()

    def __on_redo_button_press(self):
        self._editor_list[self._editor_button.value].redo()

    def __on_save_button_press(self):
        pyxel.save(self._resource_file)

    def __on_editor_button_mouse_hover(self, x, y):
        self.help_message = "EDITOR:ALT+LEFT/RIGHT"

    def __on_undo_button_mouse_hover(self, x, y):
        self.help_message = "UNDO:CTRL+Z"

    def __on_redo_button_mouse_hover(self, x, y):
        self.help_message = "REDO:CTRL+Y"

    def __on_save_button_mouse_hover(self, x, y):
        self.help_message = "SAVE:CTRL+S"
예제 #11
0
파일: app.py 프로젝트: EikiObara/myMaze
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != ".pyxel":
            resource_file += ".pyxel"

        pyxel.init(
            APP_WIDTH, APP_HEIGHT, caption="Pyxel Editor - {}".format(resource_file)
        )
        pyxel.mouse(True)

        try:
            pyxel.load(resource_file)
        except FileNotFoundError:
            pass

        super().__init__(None, 0, 0, pyxel.width, pyxel.height)

        self._resource_file = resource_file
        self._editor_list = [
            ImageEditor(self),
            TileMapEditor(self),
            SoundEditor(self),
            MusicEditor(self),
        ]
        self._editor_button = RadioButton(
            self, 1, 1, 3, EDITOR_IMAGE_X, EDITOR_IMAGE_Y, 4, 0
        )
        self._undo_button = ImageButton(
            self, 48, 1, 3, EDITOR_IMAGE_X + 36, EDITOR_IMAGE_Y
        )
        self._redo_button = ImageButton(
            self, 57, 1, 3, EDITOR_IMAGE_X + 45, EDITOR_IMAGE_Y
        )
        self._save_button = ImageButton(
            self, 75, 1, 3, EDITOR_IMAGE_X + 54, EDITOR_IMAGE_Y
        )
        self.help_message = ""

        self._editor_button.add_event_handler(
            "change", lambda value: self._set_editor(value)
        )
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._undo_button.add_event_handler("press", self.__on_undo_button_press)
        self._undo_button.add_event_handler("repeat", self.__on_undo_button_press)
        self._redo_button.add_event_handler("press", self.__on_redo_button_press)
        self._redo_button.add_event_handler("repeat", self.__on_redo_button_press)
        self._save_button.add_event_handler("press", self.__on_save_button_press)
        self._editor_button.add_event_handler(
            "mouse_hover", self.__on_editor_button_mouse_hover
        )
        self._undo_button.add_event_handler(
            "mouse_hover", self.__on_undo_button_mouse_hover
        )
        self._redo_button.add_event_handler(
            "mouse_hover", self.__on_redo_button_mouse_hover
        )
        self._save_button.add_event_handler(
            "mouse_hover", self.__on_save_button_mouse_hover
        )

        glfw.set_drop_callback(pyxel._app._window, self._drop_callback)
        image_file = os.path.join(
            os.path.dirname(__file__), "assets", EDITOR_IMAGE_NAME
        )
        pyxel.image(3, system=True).load(EDITOR_IMAGE_X, EDITOR_IMAGE_Y, image_file)

        self._set_editor(0)

        pyxel.run(self.update_widgets, self.draw_widgets)
예제 #12
0
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != pyxel.RESOURCE_FILE_EXTENSION:
            resource_file += pyxel.RESOURCE_FILE_EXTENSION

        pyxel.init(
            APP_WIDTH, APP_HEIGHT, caption="Pyxel Editor - {}".format(resource_file)
        )
        pyxel.mouse(True)

        if os.path.exists(resource_file):
            pyxel.load(resource_file)

        if ext == ".pyxel":
            resource_file = root + pyxel.RESOURCE_FILE_EXTENSION

        super().__init__(None, 0, 0, pyxel.width, pyxel.height)

        self._resource_file = resource_file
        self._editor_list = [
            ImageEditor(self),
            TileMapEditor(self),
            SoundEditor(self),
            MusicEditor(self),
        ]
        self._editor_button = RadioButton(
            self,
            1,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X,
            EDITOR_IMAGE_Y,
            4,
            0,
        )
        self._undo_button = ImageButton(
            self,
            48,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 36,
            EDITOR_IMAGE_Y,
        )
        self._redo_button = ImageButton(
            self,
            57,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 45,
            EDITOR_IMAGE_Y,
        )
        self._save_button = ImageButton(
            self,
            75,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 54,
            EDITOR_IMAGE_Y,
        )
        self.help_message = ""

        self._editor_button.add_event_handler(
            "change", lambda value: self._set_editor(value)
        )
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._undo_button.add_event_handler("press", self.__on_undo_button_press)
        self._undo_button.add_event_handler("repeat", self.__on_undo_button_press)
        self._redo_button.add_event_handler("press", self.__on_redo_button_press)
        self._redo_button.add_event_handler("repeat", self.__on_redo_button_press)
        self._save_button.add_event_handler("press", self.__on_save_button_press)
        self._editor_button.add_event_handler(
            "mouse_hover", self.__on_editor_button_mouse_hover
        )
        self._undo_button.add_event_handler(
            "mouse_hover", self.__on_undo_button_mouse_hover
        )
        self._redo_button.add_event_handler(
            "mouse_hover", self.__on_redo_button_mouse_hover
        )
        self._save_button.add_event_handler(
            "mouse_hover", self.__on_save_button_mouse_hover
        )

        image_file = os.path.join(
            os.path.dirname(__file__), "assets", EDITOR_IMAGE_NAME
        )
        pyxel.image(pyxel.IMAGE_BANK_FOR_SYSTEM, system=True).load(
            EDITOR_IMAGE_X, EDITOR_IMAGE_Y, image_file
        )

        self._set_editor(0)

        pyxel.run(self.update_widgets, self.draw_widgets)
예제 #13
0
class App(Widget):
    def __init__(self, resource_file):
        resource_file = os.path.join(os.getcwd(), resource_file)
        root, ext = os.path.splitext(resource_file)
        if ext != pyxel.RESOURCE_FILE_EXTENSION:
            resource_file += pyxel.RESOURCE_FILE_EXTENSION

        pyxel.init(APP_WIDTH,
                   APP_HEIGHT,
                   caption="Pyxel Editor - {}".format(resource_file))
        pyxel.mouse(True)

        if os.path.exists(resource_file):
            pyxel.load(resource_file)

        if ext == ".pyxel":
            resource_file = root + pyxel.RESOURCE_FILE_EXTENSION

        super().__init__(None, 0, 0, pyxel.width, pyxel.height)

        self._resource_file = resource_file
        self._editor_list = [
            ImageEditor(self),
            TileMapEditor(self),
            SoundEditor(self),
            MusicEditor(self),
        ]
        self._editor_button = RadioButton(
            self,
            1,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X,
            EDITOR_IMAGE_Y,
            4,
            0,
        )
        self._undo_button = ImageButton(
            self,
            48,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 36,
            EDITOR_IMAGE_Y,
        )
        self._redo_button = ImageButton(
            self,
            57,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 45,
            EDITOR_IMAGE_Y,
        )
        self._save_button = ImageButton(
            self,
            75,
            1,
            pyxel.IMAGE_BANK_FOR_SYSTEM,
            EDITOR_IMAGE_X + 54,
            EDITOR_IMAGE_Y,
        )
        self.help_message = ""

        self._editor_button.add_event_handler(
            "change", lambda value: self._set_editor(value))
        self.add_event_handler("update", self.__on_update)
        self.add_event_handler("draw", self.__on_draw)
        self._undo_button.add_event_handler("press",
                                            self.__on_undo_button_press)
        self._undo_button.add_event_handler("repeat",
                                            self.__on_undo_button_press)
        self._redo_button.add_event_handler("press",
                                            self.__on_redo_button_press)
        self._redo_button.add_event_handler("repeat",
                                            self.__on_redo_button_press)
        self._save_button.add_event_handler("press",
                                            self.__on_save_button_press)
        self._editor_button.add_event_handler(
            "mouse_hover", self.__on_editor_button_mouse_hover)
        self._undo_button.add_event_handler("mouse_hover",
                                            self.__on_undo_button_mouse_hover)
        self._redo_button.add_event_handler("mouse_hover",
                                            self.__on_redo_button_mouse_hover)
        self._save_button.add_event_handler("mouse_hover",
                                            self.__on_save_button_mouse_hover)

        image_file = os.path.join(os.path.dirname(__file__), "assets",
                                  EDITOR_IMAGE_NAME)
        pyxel.image(pyxel.IMAGE_BANK_FOR_SYSTEM,
                    system=True).load(EDITOR_IMAGE_X, EDITOR_IMAGE_Y,
                                      image_file)

        self._set_editor(0)

        pyxel.run(self.update_widgets, self.draw_widgets)

    def _set_editor(self, editor):
        self._editor_button.value = editor

        for i, widget in enumerate(self._editor_list):
            widget.is_visible = i == editor

    def __on_update(self):
        if pyxel._drop_file:
            ext = os.path.splitext(pyxel._drop_file)[1]

            if ext == pyxel.RESOURCE_FILE_EXTENSION:
                pyxel.stop()

                if pyxel.btn(pyxel.KEY_CONTROL):
                    editor = self._editor_list[self._editor_button.value]
                    editor.reset_history()

                    if isinstance(editor, ImageEditor):
                        pyxel.load(pyxel._drop_file,
                                   tilemap=False,
                                   sound=False,
                                   music=False)
                    elif isinstance(editor, TileMapEditor):
                        pyxel.load(pyxel._drop_file,
                                   image=False,
                                   sound=False,
                                   music=False)
                    elif isinstance(editor, SoundEditor):
                        pyxel.load(pyxel._drop_file,
                                   image=False,
                                   tilemap=False,
                                   music=False)
                    elif isinstance(editor, MusicEditor):
                        pyxel.load(pyxel._drop_file,
                                   image=False,
                                   tilemap=False,
                                   sound=False)
                else:
                    for editor in self._editor_list:
                        editor.reset_history()
                    pyxel.load(pyxel._drop_file)

                pyxel._caption(pyxel._drop_file)
            else:
                self._editor_list[
                    self._editor_button.value].call_event_handler(
                        "drop", pyxel._drop_file)

        if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT):
            editor = self._editor_button.value
            editor_count = len(self._editor_list)

            if pyxel.btnp(pyxel.KEY_LEFT):
                self._set_editor((editor - 1) % editor_count)
            elif pyxel.btnp(pyxel.KEY_RIGHT):
                self._set_editor((editor + 1) % editor_count)

        editor = self._editor_list[self._editor_button.value]
        self._undo_button.is_enabled = editor.can_undo
        self._redo_button.is_enabled = editor.can_redo

        if pyxel.btn(pyxel.KEY_CONTROL):
            if pyxel.btnp(pyxel.KEY_S):
                self._save_button.press()

            if editor.can_undo and pyxel.btnp(pyxel.KEY_Z, WIDGET_HOLD_TIME,
                                              WIDGET_REPEAT_TIME):
                self._undo_button.press()

            if editor.can_redo and pyxel.btnp(pyxel.KEY_Y, WIDGET_HOLD_TIME,
                                              WIDGET_REPEAT_TIME):
                self._redo_button.press()

    def __on_draw(self):
        pyxel.cls(WIDGET_BACKGROUND_COLOR)
        pyxel.rect(0, 0, 240, 9, WIDGET_PANEL_COLOR)
        pyxel.line(0, 9, 239, 9, WIDGET_SHADOW_COLOR)

        pyxel.text(93, 2, self.help_message, 13)
        self.help_message = ""

    def __on_undo_button_press(self):
        self._editor_list[self._editor_button.value].undo()

    def __on_redo_button_press(self):
        self._editor_list[self._editor_button.value].redo()

    def __on_save_button_press(self):
        pyxel.save(self._resource_file)

    def __on_editor_button_mouse_hover(self, x, y):
        self.help_message = "EDITOR:ALT+LEFT/RIGHT"

    def __on_undo_button_mouse_hover(self, x, y):
        self.help_message = "UNDO:CTRL+Z"

    def __on_redo_button_mouse_hover(self, x, y):
        self.help_message = "REDO:CTRL+Y"

    def __on_save_button_mouse_hover(self, x, y):
        self.help_message = "SAVE:CTRL+S"