Skip to content

Commit

Permalink
Merge pull request #365 from marius851000/wan200
Browse files Browse the repository at this point in the history
Ability to import image as static ground object
  • Loading branch information
theCapypara committed Dec 3, 2021
2 parents 8039e3c + 5b1d7e0 commit 2f5200d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
4 changes: 2 additions & 2 deletions skytemple/core/sprite_provider.py
Expand Up @@ -399,7 +399,7 @@ def _retrieve_monster_sprite(self, md_index, direction_id: int) -> Tuple[Image.I
with self._monster_bin as monster_bin:
sprite = self._load_sprite_from_bin_pack(monster_bin, actor_sprite_id)

ani_group = sprite.get_animations_for_group(sprite.anim_groups[0])
ani_group = sprite.anim_groups[0]
frame_id = direction_id - 1 if direction_id > 0 else 0
mfg_id = ani_group[frame_id].frames[0].frame_id

Expand All @@ -416,7 +416,7 @@ def _load_object(self, name, after_load_cb):
async def _load_object__impl(self, name, after_load_cb):
try:
with self._load_sprite_from_rom(f'GROUND/{name}.wan') as sprite:
ani_group = sprite.get_animations_for_group(sprite.anim_groups[0])
ani_group = sprite.anim_groups[0]
frame_id = 0
mfg_id = ani_group[frame_id].frames[0].frame_id

Expand Down
2 changes: 1 addition & 1 deletion skytemple/module/sprite/controller/monster_sprite.py
Expand Up @@ -321,7 +321,7 @@ def _load_frames(self):
with self._monster_bin as monster_bin:
sprite = self._load_sprite_from_bin_pack(monster_bin, self.item_id)

ani_group = sprite.get_animations_for_group(sprite.anim_groups[0])
ani_group = sprite.anim_groups[0]
frame_id = 2
for frame in ani_group[frame_id].frames:
mfg_id = frame.frame_id
Expand Down
37 changes: 34 additions & 3 deletions skytemple/module/sprite/controller/object.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.1 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="main_box">
Expand All @@ -10,8 +10,8 @@
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="xscale">0.800000011920929</property>
<property name="yscale">0.800000011920929</property>
<property name="xscale">0.8000000119209289</property>
<property name="yscale">0.8000000119209289</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down Expand Up @@ -173,6 +173,37 @@ Warning: SkyTemple does not validate the files you import.</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">You can also replace this object with a static sprite.
It needs to have a resolution of less than 512x256px.
It also needs to have less than 16 color, plus (optionally) a transparent "color".
This feature hasn't been thoroughly tested, so you should check that it displays properly in-game,
even if it is correctly displayed by the editor.</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="importimage">
<property name="label" translatable="yes">Import image</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_importimage_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
7 changes: 7 additions & 0 deletions skytemple/module/sprite/controller/object.py
Expand Up @@ -90,3 +90,10 @@ def on_import_clicked(self, *args):
return
self.module.save_object_sprite(self.item_id, sprite)
MainController.reload_view()

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()
27 changes: 27 additions & 0 deletions skytemple/module/sprite/module.py
Expand Up @@ -20,6 +20,7 @@

from gi.repository import Gtk
from gi.repository.Gtk import TreeStore
from PIL import Image

from skytemple.controller.main import MainController
from skytemple.core.abstract_module import AbstractModule
Expand All @@ -36,6 +37,7 @@
from skytemple_files.container.bin_pack.model import BinPack
from skytemple_files.graphics.chara_wan.model import WanFile
from skytemple_files.common.i18n_util import f, _
from skytemple_rust import pmd_wan
if TYPE_CHECKING:
from skytemple.module.gfxcrunch.module import GfxcrunchModule

Expand Down Expand Up @@ -205,6 +207,31 @@ def export_a_sprite__gfxcrunch(self, sprite: bytes):
str(e),
_("Error exporting the sprite.")
)

def import_an_image(self) -> Optional[bytes]:
dialog = Gtk.FileChooserNative.new(
_("Import image file..."),
MainController.window(),
Gtk.FileChooserAction.OPEN,
None, None
)

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

if response == Gtk.ResponseType.ACCEPT:
try:
img = Image.open(fn, 'r')
return pmd_wan.encode_image_to_static_wan_file(img)
except Exception as err:
display_error(
sys.exc_info(),
str(err),
_("Error importing image to object.")
)
return None


def open_spritebot_explanation(self):
webbrowser.open_new_tab('https://docs.google.com/document/d/1EceEEjyeoFwoKXdNj4vpXdoYRWp8CID64e-ZqY954_Q/edit')
Expand Down

0 comments on commit 2f5200d

Please sign in to comment.