public new DialogResult ShowDialog(IWin32Window owner) { _bresParent = null; _origTEX0 = null; _origPLT0 = null; _origREFT = null; _origTPL = null; _origTPLPlt = null; _paletteData = _textureData = null; DialogResult = DialogResult.Cancel; try { return base.ShowDialog(owner); } //catch (Exception x) { MessageBox.Show(x.ToString()); return DialogResult.Cancel; } finally { DisposeImages(); } }
public void EncodeSource() { TextureConverter format = TextureConverter.Get((WiiPixelFormat)cboFormat.SelectedItem); if (format.IsIndexed) { if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); } else { if ((format.RawFormat == WiiPixelFormat.CMPR) && (_cmprBuffer != null)) { if (_origTEX0 != null || _bresParent != null) _textureData = ((CMPR)format).EncodeTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origREFT != null || _reftParent != null) _textureData = ((CMPR)format).EncodeREFTTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origTPL != null || _tplParent != null) _textureData = ((CMPR)format).EncodeTPLTextureCached(_source, (int)numLOD.Value, _cmprBuffer); } else if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTEX0Texture(_source, (int)numLOD.Value); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTexture(_source, (int)numLOD.Value, WiiPaletteFormat.IA8); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTexture(_source, (int)numLOD.Value); } if (_bresParent != null) { _origTEX0 = _bresParent.CreateResource<TEX0Node>(Path.GetFileNameWithoutExtension(_imageSource)); if (_paletteData != null) { _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } _origTEX0.ReplaceRaw(_textureData); } else if (_tplParent != null) { _origTPL = new TPLTextureNode() { Name = "Texture" }; _tplParent.AddChild(_origTPL); _origTPL.ReplaceRaw(_textureData); if (_paletteData != null) { _origTPLPlt = new TPLPaletteNode() { Name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } else if (_reftParent != null) { _reftParent.AddChild(_origREFT = new REFTEntryNode() { Name = Path.GetFileNameWithoutExtension(_imageSource) }); _origREFT.ReplaceRaw(_textureData); } else if (_origTEX0 != null) { if (_origPLT0 != null) { if (_paletteData != null) _origPLT0.ReplaceRaw(_paletteData); else { _origPLT0.Remove(); _origPLT0.Dispose(); } } else if (_paletteData != null) { if ((_origTEX0.Parent == null) || (_origTEX0.Parent.Parent == null)) { _paletteData.Dispose(); _paletteData = null; } else { _bresParent = _origTEX0.Parent.Parent as BRESNode; _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } } _origTEX0.ReplaceRaw(_textureData); } else if (_origREFT != null) _origREFT.ReplaceRaw(_textureData); else if (_origTPL != null) { _origTPL.ReplaceRaw(_textureData); if (_origTPLPlt != null) { if (_paletteData != null) { _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } else { _origTPLPlt.Remove(); _origTPLPlt.Dispose(); } } else if (_paletteData != null) { if (_origTPL.Parent == null) { _paletteData.Dispose(); _paletteData = null; } else { _origTPLPlt = new TPLPaletteNode() { _name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } } }