示例#1
0
    def on_men_map_export_activate(self):
        dialog: Gtk.Dialog = self.parent.builder.get_object(
            'dialog_map_export')
        dialog.set_attached_to(MainController.window())
        dialog.set_transient_for(MainController.window())

        resp = dialog.run()
        dialog.hide()
        if resp == ResponseType.OK:
            dialog = Gtk.FileChooserNative.new(_("Export PNG of map..."),
                                               MainController.window(),
                                               Gtk.FileChooserAction.SAVE,
                                               None, None)

            response = dialog.run()
            fn = dialog.get_filename()
            fn = add_extension_if_missing(fn, 'png')
            dialog.destroy()

            if response == Gtk.ResponseType.ACCEPT:
                if TYPE_CHECKING:
                    from skytemple.module.dungeon_graphics.controller.dungeon_bg import DungeonBgController
                    assert isinstance(self.parent, DungeonBgController)
                img = self.parent.dbg.to_pil(self.parent.dpc, self.parent.dpci,
                                             self.parent.dpl.palettes)
                img.save(fn)
示例#2
0
    def on_stats_export_clicked(self, *args):
        assert self._level_bin_entry is not None
        dialog = Gtk.FileChooserNative.new(_("Save CSV..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.SAVE, None,
                                           None)

        self._add_dialog_file_filters(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'csv')
            try:
                rows: List[List[Any]] = [[
                    CSV_LEVEL, CSV_EXP_POINTS, CSV_HP, CSV_ATK, CSV_SP_ATK,
                    CSV_DEF, CSV_SP_DEF
                ]]
                for i, level in enumerate(self._level_bin_entry.levels):
                    rows.append([
                        i + 1, level.experience_required, level.hp_growth,
                        level.attack_growth, level.special_attack_growth,
                        level.defense_growth, level.special_defense_growth
                    ])
                with open_utf8(fn, 'w', newline='') as file:
                    writer = csv.writer(file)
                    writer.writerows(rows)
            except BaseException as err:
                display_error(sys.exc_info(), str(err),
                              _("Error saving the CSV."))
示例#3
0
    def on_men_map_export_gif_activate(self):
        dialog = Gtk.FileChooserNative.new(_("Save GIF of map..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.SAVE, None,
                                           None)

        add_dialog_gif_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        duration = 1000
        non_none_bpas = [b for b in self.parent.bpas if b is not None]
        if len(non_none_bpas) > 0:
            # Assuming the game runs 60 FPS.
            duration = round(1000 / 60 *
                             non_none_bpas[0].frame_info[0].duration_per_frame)

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'gif')
            frames = self.parent.bma.to_pil(self.parent.bpc, self.parent.bpl,
                                            self.parent.bpas, False, False)
            frames[0].save(fn,
                           save_all=True,
                           append_images=frames[1:],
                           duration=duration,
                           loop=0,
                           optimize=False)
示例#4
0
    def on_men_tiles_layer1_export_activate(self):
        dialog: Gtk.Dialog = self.parent.builder.get_object(
            'dialog_tiles_export')
        dialog.set_attached_to(MainController.window())
        dialog.set_transient_for(MainController.window())

        resp = dialog.run()
        dialog.hide()
        if resp == Gtk.ResponseType.OK:
            dialog = Gtk.FileChooserNative.new(_("Export PNG of tiles..."),
                                               MainController.window(),
                                               Gtk.FileChooserAction.SAVE,
                                               None, None)

            add_dialog_png_filter(dialog)

            response = dialog.run()
            fn = dialog.get_filename()
            fn = add_extension_if_missing(fn, 'png')
            dialog.destroy()

            if response == Gtk.ResponseType.ACCEPT:
                try:
                    self.parent.dpci.tiles_to_pil(self.parent.dpl.palettes,
                                                  16).save(fn)
                except BaseException as err:
                    display_error(sys.exc_info(), str(err),
                                  _("Error exporting the tileset."))
示例#5
0
    def on_btn_export_clicked(self, *args):
        md = SkyTempleMessageDialog(
            MainController.window(), Gtk.DialogFlags.MODAL,
            Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
            _("Export is done to a CSV file with the following specifications:\n"
              "- Contains all strings in order, one per row\n"
              "- Strings may be quoted with: \" and escaped with double quotes."
              ))
        md.run()
        md.destroy()

        save_diag = Gtk.FileChooserNative.new(_("Export strings as..."),
                                              MainController.window(),
                                              Gtk.FileChooserAction.SAVE, None,
                                              None)

        add_dialog_csv_filter(save_diag)
        response = save_diag.run()
        fn = save_diag.get_filename()
        save_diag.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'csv')
            with open_utf8(fn, 'w') as result_file:
                wr = csv.writer(result_file)
                wr.writerows([[x] for x in self._str.strings])
示例#6
0
    def on_export_clicked(self, w: Gtk.MenuToolButton):
        self.img.palettes = make_palette_colors_unique(self.img.palettes)
        md = SkyTempleMessageDialog(
            MainController.window(),
            Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK,
            _("This will export the currently selected image with the currently selected palette. "
              "The image file itself contains all palettes, you can choose to import the edited palettes on import."),
            title=_("Export Images")
        )
        md.run()
        md.destroy()
        dialog = Gtk.FileChooserNative.new(
            _("Export current image to folder..."),
            MainController.window(),
            Gtk.FileChooserAction.SAVE,
            _('_Save'), None
        )

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            self.img.to_pil(self.image_idx, self.palette_idx).save(fn)
示例#7
0
    def on_spritebot_export_activate(self, *args):
        dialog = Gtk.FileChooserNative.new(
            _("Export portrait as PNG sheet..."), MainController.window(),
            Gtk.FileChooserAction.SAVE, None, None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = dialog.get_filename()
            fn = add_extension_if_missing(fn, 'png')
            SpriteBotSheet.create(self.kao, self.item_id).save(fn)
示例#8
0
    def on_export_icon_clicked(self, *args):
        dialog = FileChooserNative.new(_("Export game icon as PNG..."),
                                       SkyTempleMainController.window(),
                                       FileChooserAction.SAVE, None, None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            self.icon_banner.icon.to_pil().save(fn)
示例#9
0
    def on_export_clicked(self, w: Gtk.MenuToolButton):
        dialog = Gtk.FileChooserNative.new(_("Export image as PNG..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.SAVE,
                                           _("_Save"), None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            self.module.get_cart_removed_data().save(fn)
示例#10
0
    def import_a_sprite__wan(self) -> Optional[bytes]:
        dialog = Gtk.FileChooserNative.new(_("Import WAN sprite..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.OPEN, None,
                                           None)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'wan')
            with open(fn, 'rb') as f:
                return f.read()
        return None
示例#11
0
    def on_export_clicked(self, *args):
        cb_store: Gtk.ListStore = self.builder.get_object('cb_weather_store')
        cb: Gtk.ComboBoxText = self.builder.get_object('cb_weather')
        v: int = cb_store[cb.get_active_iter()][0]

        dialog = Gtk.FileChooserNative.new(
            _("Export current colormap as PNG..."), MainController.window(),
            Gtk.FileChooserAction.SAVE, "_Save", None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            self.colvec.to_pil(v).save(fn)
示例#12
0
    def export_a_sprite__wan(self, sprite: bytes):
        dialog = Gtk.FileChooserNative.new(_("Export WAN sprite..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.SAVE, None,
                                           None)
        filter = Gtk.FileFilter()
        filter.set_name(_("WAN sprite (*.wan)"))
        filter.add_pattern("*.wan")
        dialog.add_filter(filter)

        response = dialog.run()
        fn = dialog.get_filename()

        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'wan')
            with open(fn, 'wb') as f:
                f.write(sprite)
示例#13
0
    def on_save_as_button_clicked(self, wdg):
        project = RomProject.get_current()
        if project is None:
            return

        dialog = Gtk.FileChooserNative.new(_("Save As..."), self._window,
                                           Gtk.FileChooserAction.SAVE, None,
                                           None)
        dialog.set_filename(project.filename)

        add_dialog_file_filters(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'nds')
            project.filename = fn
            self._save(True)
            project.get_rom_module().update_filename()
            self._update_recent_files(fn)
示例#14
0
    def on_export_clicked(self, w: Gtk.MenuToolButton):
        dialog = Gtk.FileChooserNative.new(_("Export image as PNG..."),
                                           MainController.window(),
                                           Gtk.FileChooserAction.SAVE,
                                           _("_Save"), None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            if self.wte.has_image():
                self.wte.to_pil_canvas(
                    int(
                        self.builder.get_object(
                            'wte_palette_variant').get_text())).save(
                                fn)  # type: ignore
            else:
                self.wte.to_pil_palette().save(fn)
示例#15
0
    def _export_tiles(self, layer):
        dialog: Gtk.Dialog = self.parent.builder.get_object(
            'dialog_tiles_export')
        dialog.set_attached_to(MainController.window())
        dialog.set_transient_for(MainController.window())

        resp = dialog.run()
        dialog.hide()
        if resp == ResponseType.OK:
            dialog = Gtk.FileChooserNative.new(_("Export PNG of tiles..."),
                                               MainController.window(),
                                               Gtk.FileChooserAction.SAVE,
                                               None, None)

            add_dialog_png_filter(dialog)

            response = dialog.run()
            fn = dialog.get_filename()
            dialog.destroy()

            if response == Gtk.ResponseType.ACCEPT:
                fn = add_extension_if_missing(fn, 'png')
                self.parent.bpc.tiles_to_pil(layer, self.parent.bpl.palettes,
                                             20).save(fn)