artemis引擎立绘合成工具
-
artemis引擎立绘合成工具
作者: https://github.com/DaiZhongpeng3
源码:import os import wx import winreg from PIL import Image def get_desktop(): key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders') return winreg.QueryValueEx(key, "Desktop")[0] Desktop_path = str(get_desktop()) class EncryptFrame(wx.Frame): def __init__(self): super().__init__(parent=None, id=wx.ID_ANY, title="artemis立绘批量合成", pos=wx.DefaultPosition, size=(600,600) , style=wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.CAPTION ) #窗口不可拉伸且顶置 #self.SetIcon(wx.Icon("ico.ico", wx.BITMAP_TYPE_ICO)) self.Bind(wx.EVT_CLOSE,self.OnClose) self.Centre() panel = wx.Panel(parent=self) global txt1 self.st1 = wx.StaticText(parent=panel, label='请选择表情差分图片放置文件夹:') self.txt1 = wx.TextCtrl(panel) self.choicedirbtn1 = wx.Button(panel, label='选择文件夹') self.Bind(wx.EVT_BUTTON, self.choicedirclick1, self.choicedirbtn1) txt1 = self.txt1 global txt2 self.st2 = wx.StaticText(parent=panel, label='请选择身体差分图片放置文件夹:') self.txt2 = wx.TextCtrl(panel) self.choicedirbtn2 = wx.Button(panel, label='选择文件夹') self.Bind(wx.EVT_BUTTON, self.choicedirclick2, self.choicedirbtn2) txt2 = self.txt2 global txt3 self.st3 = wx.StaticText(parent=panel, label='请选择立绘输出文件夹:') self.txt3 = wx.TextCtrl(panel) self.choicedirbtn3 = wx.Button(panel, label='选择文件夹') self.Bind(wx.EVT_BUTTON, self.choicedirclick3, self.choicedirbtn3) txt3 = self.txt3 startbtn = wx.Button(panel, label='开始合成') self.Bind(wx.EVT_BUTTON, self.startcombine, startbtn) global txt4 downSizer = wx.StaticBoxSizer(wx.StaticBox(panel, wx.ID_ANY, u"状态"), wx.VERTICAL) txt4 = wx.TextCtrl(panel, style=wx.TE_MULTILINE | wx.TE_READONLY) downSizer.Add(txt4, 1, wx.EXPAND | wx.ALL, 5) infortxt = "欢迎使用artemis引擎立绘批量合成工具!\n作者:岱中鹏\n注意事项:\n1.因为立绘文件的特殊性,本程序目前兼容绝大多数利用artemis引擎的解包,但不保证完全可行\n2.一定要注意各文件夹下表情和身体的相对位置,避免因为基本位置错误导致合成错误。" txt4.SetValue(infortxt) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(self.st1,0, wx.CENTER | wx.ALL , border=5) hbox1.Add(self.txt1,1, wx.CENTER | wx.ALL , border=5) hbox1.Add(self.choicedirbtn1,0,wx.CENTER | wx.BOTTOM , border=0) hbox2 = wx.BoxSizer(wx.HORIZONTAL) hbox2.Add(self.st2,0, wx.CENTER | wx.ALL , border=5) hbox2.Add(self.txt2,1, wx.CENTER | wx.ALL , border=5) hbox2.Add(self.choicedirbtn2,0,wx.CENTER | wx.BOTTOM , border=0) hbox3 = wx.BoxSizer(wx.HORIZONTAL) hbox3.Add(self.st3,0, wx.CENTER | wx.ALL , border=5) hbox3.Add(self.txt3,1, wx.CENTER | wx.ALL , border=5) hbox3.Add(self.choicedirbtn3,0,wx.CENTER | wx.BOTTOM , border=0) infortxt = "" txt3.SetValue(infortxt) hbox4 = wx.BoxSizer(wx.HORIZONTAL) hbox4.Add(startbtn,0, wx.CENTER | wx.ALL , border=5) vbox1 = wx.BoxSizer(wx.VERTICAL) vbox1.Add(hbox1,0,wx.ALL | wx.EXPAND,border=5) vbox1.Add(hbox2,0,wx.ALL | wx.EXPAND,border=5) vbox1.Add(hbox3,0,wx.ALL | wx.EXPAND,border=5) vbox1.Add(hbox4,0,wx.ALL | wx.CENTER,border=5) vbox1.Add(downSizer,1,wx.ALL | wx.EXPAND,border=5) panel.SetSizer(vbox1) def choicedirclick1(self,event): dialog = wx.DirDialog(self, "选择文件夹", Desktop_path, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dialog.ShowModal() == wx.ID_OK: self.txt1.SetValue(dialog.GetPath()) dialog.Destroy() def choicedirclick2(self,event): dialog = wx.DirDialog(self, "选择文件夹", Desktop_path, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dialog.ShowModal() == wx.ID_OK: self.txt2.SetValue(dialog.GetPath()) dialog.Destroy() def choicedirclick3(self,event): dialog = wx.DirDialog(self, "选择文件夹", Desktop_path, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dialog.ShowModal() == wx.ID_OK: self.txt3.SetValue(dialog.GetPath()) dialog.Destroy() def startcombine(self,event): if self.txt1.GetValue() == "": wx.MessageBox('请选择表情差分图片放置文件夹。', '错误',wx.OK | wx.ICON_ERROR) if self.txt2.GetValue() == "": wx.MessageBox('请选择身体差分图片放置文件夹。', '错误',wx.OK | wx.ICON_ERROR) if self.txt3.GetValue() == "": wx.MessageBox('请选择立绘输出文件夹。', '错误',wx.OK | wx.ICON_ERROR) else: list1 = os.listdir(txt1.GetValue()) list2 = os.listdir(txt2.GetValue()) txt4.AppendText("\n开始执行操作,请勿终止操作--------------------------------\n表情差分总数:{0}\n身体差分总数:{1}".format(len(list1),len(list2))) for file1 in list2: txt4.AppendText("\n正在合成{0}配套表情--------".format(file1)) dataw1 = "" datas = "" data1 = "" data2 = "" datastop = False with open(txt2.GetValue() + "\\" + file1,"rb") as f: databody = str(f.read(100))[100:150] f.close() for w in databody: if w == ",": datamove = dataw1 break dataw1 += w for i in databody.replace(datamove + ",",""): if i == "," and datastop == False: data1 = datas datastop = True continue if i == "," and datastop: data2 = datas break datas += i datax1 = int(data1) datay1 = int(data2.replace(data1,"")) for file2 in list1: dataw2 = "" datass = "" data3 = "" data4 = "" datastop2 = False with open(txt1.GetValue() + "\\" + file2,"rb") as f: databorw= str(f.read(100))[100:200] f.close() for w in databorw: if w == ",": datamove = dataw2 break dataw2 += w for i in databorw.replace(datamove + ",",""): if i == "," and datastop2 == False: data3 = datass datastop2 = True continue if i == "," and datastop2: data4 = datass break datass += i datax2 = int(data3) datay2 = int(data4.replace(data3,"")) x = datax2 - datax1 y = datay2 - datay1 image1 = Image.open(txt1.GetValue() + "\\" + file2) image2 = Image.open(txt2.GetValue() + "\\" + file1) image2.alpha_composite(image1,(x,y)) image2.save(txt3.GetValue() + "\\" + file1 + file2,"PNG") wx.Yield() txt4.AppendText("\n完成!共计{0}张立绘。----------------------------------------".format(len(list1)*len(list2))) def OnClose(self, event): self.Destroy() event.Skip() if __name__ == "__main__": app = wx.App() frame = EncryptFrame() frame.Show() app.MainLoop()