Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/seotbeo_main'
Browse files Browse the repository at this point in the history
  • Loading branch information
PirateIzzy committed Jan 7, 2025
2 parents 697f837 + 33db1f1 commit fd0b57d
Show file tree
Hide file tree
Showing 23 changed files with 1,199 additions and 347 deletions.
4 changes: 2 additions & 2 deletions WzComparerR2.Avatar/AvatarCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,9 @@ private void CreateBone(Bone root, Tuple<Wz_Node, Wz_Node, int>[] frameNodes, bo
{
continue;
}
if (childNode.Text == "hairShade")
if (linkNode.Text == "hairShade")
{
linkNode = childNode.FindNodeByPath("0");
linkNode = linkNode.FindNodeByPath("0");
if (linkNode == null)
{
continue;
Expand Down
52 changes: 28 additions & 24 deletions WzComparerR2.Avatar/UI/AvatarForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,25 +1466,30 @@ private void btnSaveAsGif_Click(object sender, EventArgs e)
}
else
{
// get default encoder
var config = ImageHandlerConfig.Default;
var encParams = AnimateEncoderFactory.GetEncoderParams(config.GifEncoder.Value);
using var encoder = AnimateEncoderFactory.CreateEncoder(config);
var cap = encoder.Compatibility;

string extensionFilter = string.Join(";", cap.SupportedExtensions.Select(ext => $"*{ext}"));

var dlg = new SaveFileDialog()
{
Title = "Save Avatar",
Filter = string.Format("{0} (*{1})|*{1}|All Files(*.*)|*.*", encParams.FileDescription, encParams.FileExtension),
Filter = string.Format("{0} (*{1})|*{1}|All Files(*.*)|*.*", encoder.Name, extensionFilter),
FileName = string.Format("avatar{0}{1}{2}{3}",
string.IsNullOrEmpty(avatar.ActionName) ? "" : ("_" + avatar.ActionName),
string.IsNullOrEmpty(avatar.EmotionName) ? "" : ("_" + avatar.EmotionName),
string.IsNullOrEmpty(avatar.TamingActionName) ? "" : ("_" + avatar.TamingActionName),
encParams.FileExtension)
cap.DefaultExtension)
};

if (dlg.ShowDialog() != DialogResult.OK)
{
return;
}

string outputFileName = dlg.FileName;
var actPlaying = new[] { bodyPlaying, emoPlaying, tamingPlaying };
var actFrames = new[] { cmbBodyFrame, cmbEmotionFrame, cmbTamingFrame }
.Select((cmb, i) =>
Expand Down Expand Up @@ -1529,7 +1534,7 @@ private void btnSaveAsGif_Click(object sender, EventArgs e)

var gifLayer = new GifLayer();

if (aniCount == 1)
if (aniCount == 1 && !cap.IsFixedFrameRate)
{
int aniActIndex = Array.FindIndex(actPlaying, b => b);
for (int fIdx = 0, fCnt = actFrames[aniActIndex].Length; fIdx < fCnt; fIdx++)
Expand Down Expand Up @@ -1558,8 +1563,8 @@ private void btnSaveAsGif_Click(object sender, EventArgs e)
{
// more than 2 animating action parts, for simplicity, we use fixed frame delay.
actFrames = actFrames.Concat(effectActFrames).ToArray();
var aniLength = actFrames.Max(layer => layer == null ? 0 : layer.Sum(f => f.actionFrame.AbsoluteDelay));
var aniDelay = 30;
int aniLength = actFrames.Max(layer => layer == null ? 0 : layer.Sum(f => f.actionFrame.AbsoluteDelay));
int aniDelay = config.MinDelay;

// pipeline functions
IEnumerable<int> RenderDelay()
Expand Down Expand Up @@ -1658,7 +1663,7 @@ GifFrame ApplyFrame(int[] actionIndices, int delay)
// build pipeline
var step1 = RenderDelay();
var step2 = GetFrameActionIndices(step1);
var step3 = MergeFrames(step2);
var step3 = cap.IsFixedFrameRate ? step2 : MergeFrames(step2);
var step4 = step3.Select(tp => ApplyFrame(tp.Item1, tp.Item2));

// run pipeline
Expand Down Expand Up @@ -1710,27 +1715,24 @@ Brush CreateBackgroundBrush()
}
}

var bgBrush = CreateBackgroundBrush();
using (var enc = AnimateEncoderFactory.CreateEncoder(dlg.FileName, clientRect.Width, clientRect.Height, config))
using var bgBrush = CreateBackgroundBrush();
encoder.Init(outputFileName, clientRect.Width, clientRect.Height);
foreach (IGifFrame gifFrame in gifLayer.Frames)
{
foreach (IGifFrame gifFrame in gifLayer.Frames)
using (var bmp = new Bitmap(clientRect.Width, clientRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (var bmp = new Bitmap(clientRect.Width, clientRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
using (var g = Graphics.FromImage(bmp))
{
using (var g = Graphics.FromImage(bmp))
// draw background
if (bgBrush != null)
{
// draw background
if (bgBrush != null)
{
g.FillRectangle(bgBrush, 0, 0, bmp.Width, bmp.Height);
}
gifFrame.Draw(g, clientRect);
g.FillRectangle(bgBrush, 0, 0, bmp.Width, bmp.Height);
}
enc.AppendFrame(bmp, Math.Max(10, gifFrame.Delay));
gifFrame.Draw(g, clientRect);
}
encoder.AppendFrame(bmp, Math.Max(cap.MinFrameDelay, gifFrame.Delay));
}
}
bgBrush?.Dispose();
}
}

Expand Down Expand Up @@ -2115,7 +2117,8 @@ private void ExportAvatar(object sender, EventArgs e)
}

var config = ImageHandlerConfig.Default;
var encParams = AnimateEncoderFactory.GetEncoderParams(config.GifEncoder.Value);
using var encoder = AnimateEncoderFactory.CreateEncoder(config);
var cap = encoder.Compatibility;

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.Description = "Select a destination folder to export.";
Expand Down Expand Up @@ -2146,14 +2149,15 @@ async Task ExportGif(string actionName)
}
}

string fileName = System.IO.Path.Combine(dlg.SelectedPath, actionName.Replace('\\', '.') + encParams.FileExtension);
string fileName = System.IO.Path.Combine(dlg.SelectedPath, actionName.Replace('\\', '.') + cap.DefaultExtension);

var tasks = new List<Task>();

tasks.Add(Task.Run(() =>
{
GifEncoder enc = AnimateEncoderFactory.CreateEncoder(fileName, gif.GetRect().Width, gif.GetRect().Height, config);
gif.SaveGif(enc, fileName, Color.Transparent);
using var encoder = AnimateEncoderFactory.CreateEncoder(config);
encoder.Init(fileName, gif.GetRect().Width, gif.GetRect().Height);
gif.SaveGif(encoder, fileName, Color.Transparent);
}));

await Task.WhenAll(tasks);
Expand Down
24 changes: 22 additions & 2 deletions WzComparerR2.Common/CharaSim/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public Item()
this.Specs = new Dictionary<ItemSpecType, long>();
this.CoreSpecs = new Dictionary<ItemCoreSpecType, Wz_Node>();
this.AddTooltips = new List<int>();
this.Recipes = new List<int>();
}

public int Level { get; set; }
public int? DamageSkinID { get; set; }
public string ConsumableFrom { get; set; }
public string EndUseDate { get; set; }
public string SamplePath { get; set; }
Expand All @@ -28,6 +30,7 @@ public Item()
public Dictionary<ItemSpecType, long> Specs { get; private set; }
public Dictionary<ItemCoreSpecType, Wz_Node> CoreSpecs { get; private set; }
public List<int> AddTooltips { get; internal set; } // Additional Tooltips
public List<int> Recipes { get; private set; }

public bool Cash
{
Expand Down Expand Up @@ -97,6 +100,10 @@ public static Item CreateFromNode(Wz_Node node, GlobalFindNodeFunction findNode)
item.Level = Convert.ToInt32(subNode.Value);
break;

case "damageSkinID":
item.DamageSkinID = Convert.ToInt32(subNode.Value);
break;

case "consumableFrom":
item.ConsumableFrom = Convert.ToString(subNode.Value);
break;
Expand Down Expand Up @@ -248,8 +255,21 @@ public static Item CreateFromNode(Wz_Node node, GlobalFindNodeFunction findNode)
{
foreach (Wz_Node subNode in specNode.Nodes)
{
ItemSpecType type;
if (Enum.TryParse(subNode.Text, out type))
if (subNode.Text == "recipe")
{
if (subNode.Value == null && subNode.Nodes.Count > 0)
{
foreach (var recipeNode in subNode.Nodes)
{
item.Recipes.Add(recipeNode.GetValue<int>());
}
}
else
{
item.Recipes.Add(subNode.GetValue<int>());
}
}
else if(Enum.TryParse(subNode.Text, out ItemSpecType type))
{
try
{
Expand Down
1 change: 1 addition & 0 deletions WzComparerR2.Common/Controls/FrmProgressDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions WzComparerR2.Common/Controls/FrmProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace WzComparerR2.Controls
{
Expand Down Expand Up @@ -38,5 +39,16 @@ public int ProgressMax
get { return this.progressBarX1.Maximum; }
set { this.progressBarX1.Maximum = value; }
}

public string FullMessage { get; set; }

private void labelX1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Clipboard.SetText(this.FullMessage ?? this.Message);
ToastNotification.Show(this, "클립보드에 복사되었습니다.", 1000, eToastPosition.TopCenter);
}
}
}
}
7 changes: 7 additions & 0 deletions WzComparerR2.Common/Controls/ProgressDialogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace WzComparerR2.Controls
public interface IProgressDialogContext
{
string Message { get; set; }
string FullMessage { get; set; }
int Progress { get; set; }
int ProgressMin { get; set; }
int ProgressMax { get; set; }
Expand Down Expand Up @@ -46,6 +47,12 @@ public string Message
set { this.dialog.Message = value; }
}

public string FullMessage
{
get { return this.dialog.FullMessage; }
set { this.dialog.FullMessage = value; }
}

public int Progress
{
get { return this.dialog.Progress; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,43 @@
using System.Drawing;
using System.Runtime.InteropServices;

namespace WzComparerR2.Common
namespace WzComparerR2.Encoders
{
public class BuildInApngEncoder : GifEncoder
{
public BuildInApngEncoder(string fileName, int width, int height)
: base(fileName, width, height)
public BuildInApngEncoder()
{
var err = apng_init(fileName, width, height, out this.handle);
}

public bool OptimizeEnabled { get; set; }

private IntPtr handle;

public override GifEncoderCompatibility Compatibility => new GifEncoderCompatibility()
{
IsFixedFrameRate = false,
MinFrameDelay = 1,
MaxFrameDelay = 655350,
FrameDelayStep = 1,
AlphaSupportMode = AlphaSupportMode.FullAlpha,
DefaultExtension = ".png",
SupportedExtensions = new[] { ".png" },
};

public override void Init(string fileName, int width, int height)
{
base.Init(fileName, width, height);

var err = apng_init(fileName, width, height, out handle);
if (err != ApngError.Success)
{
throw new Exception($"APNG Error: {err}.");
}
}

private IntPtr handle;

public bool OptimizeEnabled { get; set; }

public override void AppendFrame(IntPtr pBuffer, int delay)
{
var err = apng_append_frame(this.handle, pBuffer, 0, 0, this.Width, this.Height, this.Width * 4, delay, this.OptimizeEnabled);
var err = apng_append_frame(handle, pBuffer, 0, 0, Width, Height, Width * 4, delay, OptimizeEnabled);
if (err != ApngError.Success)
{
throw new Exception($"APNG Error: {err}.");
Expand All @@ -36,8 +52,12 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
apng_write_end(this.handle);
apng_destroy(ref this.handle);
if (handle != IntPtr.Zero)
{
apng_write_end(handle);
apng_destroy(ref handle);
handle = IntPtr.Zero;
}
}
base.Dispose(disposing);
}
Expand All @@ -52,7 +72,7 @@ enum ApngError : int
};

[DllImport("libapng.dll")]
static extern ApngError apng_init([MarshalAs(UnmanagedType.LPWStr)]string fileName, int width, int height, out IntPtr ppEnc);
static extern ApngError apng_init([MarshalAs(UnmanagedType.LPWStr)] string fileName, int width, int height, out IntPtr ppEnc);
[DllImport("libapng.dll")]
static extern ApngError apng_append_frame(IntPtr pEnc, IntPtr pData, int x, int y, int width, int height, int stride, int delay_ms, bool optimize);
[DllImport("libapng.dll")]
Expand Down
Loading

0 comments on commit fd0b57d

Please sign in to comment.