def on_import_attack_clicked(self, w: Gtk.MenuToolButton): sprite = self.module.import_a_sprite() if sprite is None: return self.module.save_monster_attack_sprite(self.item_id, sprite, raw=True) self._mark_as_modified_cb() MainController.reload_view()
def on_btn_apply_size_clicked(self, *args): try: width = int(self.builder.get_object('settings_width').get_text()) height = int(self.builder.get_object('settings_height').get_text()) if width == 0 or height == 0: # 0x0 rooms are allowed to be consistent with the fact that they exist width = height = 0 assert width >= 0 and height >= 0 except (ValueError, AssertionError): display_error( sys.exc_info(), "Width and height must be numbers >= 0.", "Invalid values." ) return confirm = True if width < self.floor.width or height < self.floor.height: md = SkyTempleMessageDialog( MainController.window(), Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, f"You are about to reduce the size of the room. This will delete tiles. Do you want to continue?", title="Warning!" ) response = md.run() md.destroy() confirm = response == Gtk.ResponseType.YES if confirm: self.floor.resize(width, height) self.module.mark_fixed_floor_as_modified(self.floor_id) MainController.reload_view()
def on_btn_import_clicked(self, *args): md = SkyTempleMessageDialog(MainController.window(), Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, _("To import select the XML file in the DTEF tileset package. If it " "is still zipped, unzip it first."), title="SkyTemple") md.run() md.destroy() dialog = Gtk.FileChooserNative.new( _("Import dungeon tileset..."), MainController.window(), Gtk.FileChooserAction.OPEN, None, None ) filter = Gtk.FileFilter() filter.set_name(_("DTEF XML document (*.dtef.xml)")) filter.add_pattern("*.dtef.xml") dialog.add_filter(filter) add_dialog_xml_filter(dialog) response = dialog.run() fn = dialog.get_filename() dialog.destroy() if response == Gtk.ResponseType.ACCEPT: try: dirname = os.path.dirname(fn) fn_xml = fn fn_var0 = os.path.join(dirname, VAR0_FN) fn_var1 = os.path.join(dirname, VAR1_FN) fn_var2 = os.path.join(dirname, VAR2_FN) dtef_importer = ExplorersDtefImporter(self.dma, self.dpc, self.dpci, self.dpl, self.dpla) dtef_importer.do_import( dirname, fn_xml, fn_var0, fn_var1, fn_var2 ) md = SkyTempleMessageDialog(MainController.window(), Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, _("The tileset was successfully imported."), title=_("Success!"), is_success=True) md.run() md.destroy() self.mark_as_modified() MainController.reload_view() except BaseException as e: display_error( sys.exc_info(), str(e), _("Error importing the tileset.") )
def do_import(self, item_id: int, cb=lambda: None): is_zip = self._zip_is_active() dialog = Gtk.FileChooserNative.new( _("Import spritesheet..."), MainController.window(), Gtk.FileChooserAction.SELECT_FOLDER if not is_zip else Gtk.FileChooserAction.OPEN, None, None) if is_zip: self._add_zip_filter_to_dialog(dialog) response = dialog.run() fn = dialog.get_filename() dialog.destroy() if response == Gtk.ResponseType.ACCEPT: try: wan = FileType.WAN.CHARA.import_sheets(fn) if not is_zip \ else FileType.WAN.CHARA.import_sheets_from_zip(fn) monster, ground, attack = FileType.WAN.CHARA.split_wan(wan) md = SkyTempleMessageDialog( MainController.window(), Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, _("The spritesheet was successfully imported."), title=_("Success!"), is_success=True) md.run() md.destroy() self.module.save_monster_monster_sprite(item_id, monster) self.module.save_monster_ground_sprite(item_id, ground) self.module.save_monster_attack_sprite(item_id, attack) # Shadow size if not is_zip: tree = ElementTree.parse(os.path.join( fn, 'AnimData.xml')).getroot() else: with ZipFile(fn, 'r') as ZipObj: tree = ElementTree.fromstring( ZipObj.read('AnimData.xml')) self._set_shadow_size_cb(int( tree.find('ShadowSize').text)) # type: ignore cb() self._mark_as_modified_cb() MainController.reload_view() except BaseException as e: display_error(sys.exc_info(), str(e), _("Error importing the spritesheet."))
def on_btn_import_clicked(self, *args): save_diag = Gtk.FileChooserNative.new(_("Import Pokémon from..."), SkyTempleMainController.window(), Gtk.FileChooserAction.OPEN, None, None) add_dialog_xml_filter(save_diag) response = save_diag.run() fn = save_diag.get_filename() save_diag.destroy() if response == Gtk.ResponseType.ACCEPT: self.module.import_from_xml([self.entry.md_index], ElementTree.parse(fn).getroot()) SkyTempleMainController.reload_view()
def on_btn_import_clicked(self, *args): md = SkyTempleMessageDialog( MainController.window(), Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, f"Import is done from a CSV file with the following specifications:\n" f"- Has to contain all strings in order, one per row\n" f"- Strings may be quoted with: \" and escaped with doube-quotes." ) md.run() md.destroy() save_diag = Gtk.FileChooserNative.new( "Import strings from...", MainController.window(), Gtk.FileChooserAction.OPEN, 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: try: with open_utf8(fn) as csv_file: csv_reader = csv.reader(csv_file) strings = [] for row in csv_reader: if len(row) > 0: strings.append(row[0]) if len(self._str.strings) != len(strings): raise ValueError(f"The CSV file must contain exactly {len(self._str.strings)} strings, has {len(strings)}.") self._str.strings = strings self.module.mark_as_modified(self.filename) MainController.reload_view() except BaseException as err: display_error( sys.exc_info(), str(err), "Error exporting the strings." )
def do_import(self, item_id: int, cb=lambda: None): dialog = Gtk.FileChooserNative.new("Import spritesheet...", MainController.window(), Gtk.FileChooserAction.SELECT_FOLDER, None, None) response = dialog.run() fn = dialog.get_filename() dialog.destroy() if response == Gtk.ResponseType.ACCEPT: try: wan = FileType.WAN.CHARA.import_sheets(fn) monster, ground, attack = FileType.WAN.CHARA.split_wan(wan) md = SkyTempleMessageDialog( MainController.window(), Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "The spritesheet was successfully imported.", title="Success!", is_success=True) md.run() md.destroy() self.module.save_monster_monster_sprite(item_id, monster) self.module.save_monster_ground_sprite(item_id, ground) self.module.save_monster_attack_sprite(item_id, attack) # Shadow size tree = ElementTree.parse(os.path.join(fn, 'AnimData.xml')) self._set_shadow_size_cb( int(tree.getroot().find('ShadowSize').text)) cb() self._mark_as_modified_cb() MainController.reload_view() except BaseException as e: display_error(sys.exc_info(), str(e), "Error importing the spritesheet.")
def on_importimage_clicked(self, *args): sprite = self.module.import_an_image() if sprite is None: return self.module.save_object_sprite(self.item_id, sprite) MainController.reload_view()