Update ANIMEditor and SkinANIM struct

- add |(pipe) operator overload and simplefied Anim Templates
This commit is contained in:
miku-666
2022-08-21 15:33:10 +02:00
parent b75c8a9509
commit 29550a33fa
2 changed files with 87 additions and 40 deletions

View File

@@ -9,51 +9,53 @@ namespace PckStudio.Classes.Utils
[Flags]
public enum eANIM_EFFECTS : int
{
STATIC_ARMS = 1 << 0,
ZOMBIE_ARMS = 1 << 1,
STATIC_LEGS = 1 << 2,
BAD_SANTA = 1 << 3,
NONE = 0, // 0x00
STATIC_ARMS = 1 << 0, // 0x01
ZOMBIE_ARMS = 1 << 1, // 0x02
STATIC_LEGS = 1 << 2, // 0x04
BAD_SANTA = 1 << 3, // 0x08
unk_BIT4 = 1 << 4, // Whatever effect this is should be a simple one as it's existed for a while
SYNCED_LEGS = 1 << 5,
SYNCED_ARMS = 1 << 6,
STATUE_OF_LIBERTY = 1 << 7,
// Whatever effect this is should be a simple one as it's existed for a while
unk_BIT4 = 1 << 4, // 0x10
SYNCED_LEGS = 1 << 5, // 0x20
SYNCED_ARMS = 1 << 6, // 0x40
STATUE_OF_LIBERTY = 1 << 7, // 0x80
ALL_ARMOR_DISABLED = 1 << 8,
HEAD_BOBBING_DISABLED = 1 << 9,
HEAD_DISABLED = 1 << 10,
RIGHT_ARM_DISABLED = 1 << 11,
ALL_ARMOR_DISABLED = 1 << 8, // 0x100
HEAD_BOBBING_DISABLED = 1 << 9, // 0x200
HEAD_DISABLED = 1 << 10, // 0x400
RIGHT_ARM_DISABLED = 1 << 11, // 0x800
LEFT_ARM_DISABLED = 1 << 12,
BODY_DISABLED = 1 << 13,
RIGHT_LEG_DISABLED = 1 << 14,
LEFT_LEG_DISABLED = 1 << 15,
LEFT_ARM_DISABLED = 1 << 12, // 0x1000
BODY_DISABLED = 1 << 13, // 0x2000
RIGHT_LEG_DISABLED = 1 << 14, // 0x4000
LEFT_LEG_DISABLED = 1 << 15, // 0x8000
HEAD_OVERLAY_DISABLED = 1 << 16,
DO_BACKWARDS_CROUCH = 1 << 17,
RESOLUTION_64x64 = 1 << 18,
SLIM_MODEL = 1 << 19,
HEAD_OVERLAY_DISABLED = 1 << 16, // 0x10000
DO_BACKWARDS_CROUCH = 1 << 17, // 0x20000
RESOLUTION_64x64 = 1 << 18, // 0x40000
SLIM_MODEL = 1 << 19, // 0x80000
LEFT_ARM_OVERLAY_DISABLED = 1 << 20,
RIGHT_ARM_OVERLAY_DISABLED = 1 << 21,
LEFT_LEG_OVERLAY_DISABLED = 1 << 22,
RIGHT_LEG_OVERLAY_DISABLED = 1 << 23,
LEFT_ARM_OVERLAY_DISABLED = 1 << 20, // 0x100000
RIGHT_ARM_OVERLAY_DISABLED = 1 << 21, // 0x200000
LEFT_LEG_OVERLAY_DISABLED = 1 << 22, // 0x400000
RIGHT_LEG_OVERLAY_DISABLED = 1 << 23, // 0x800000
BODY_OVERLAY_DISABLED = 1 << 24,
FORCE_HEAD_ARMOR = 1 << 25,
FORCE_RIGHT_ARM_ARMOR = 1 << 26,
FORCE_LEFT_ARM_ARMOR = 1 << 27,
BODY_OVERLAY_DISABLED = 1 << 24, // 0x1000000
FORCE_HEAD_ARMOR = 1 << 25, // 0x2000000
FORCE_RIGHT_ARM_ARMOR = 1 << 26, // 0x4000000
FORCE_LEFT_ARM_ARMOR = 1 << 27, // 0x8000000
FORCE_BODY_ARMOR = 1 << 28,
FORCE_RIGHT_LEG_ARMOR = 1 << 29,
FORCE_LEFT_LEG_ARMOR = 1 << 30,
DINNERBONE = 1 << 31,
}
FORCE_BODY_ARMOR = 1 << 28, // 0x10000000
FORCE_RIGHT_LEG_ARMOR = 1 << 29, // 0x20000000
FORCE_LEFT_LEG_ARMOR = 1 << 30, // 0x40000000
DINNERBONE = 1 << 31, // 0x80000000
}
internal struct SkinANIM
public struct SkinANIM
{
eANIM_EFFECTS _ANIM = 0;
static readonly Regex animRegex = new Regex(@"^0x[0-9a-f]{1,8}\b", RegexOptions.IgnoreCase);
public static readonly Regex animRegex = new Regex(@"^0x[0-9a-f]{1,8}\b", RegexOptions.IgnoreCase);
public SkinANIM(string anim)
{
@@ -72,11 +74,15 @@ namespace PckStudio.Classes.Utils
public static eANIM_EFFECTS Parse(string anim)
=> IsValidANIM(anim)
? (eANIM_EFFECTS)Convert.ToInt32(anim, 16)
: 0;
: eANIM_EFFECTS.NONE;
public void SetANIM(int anim) => SetANIM((eANIM_EFFECTS)anim);
public void SetANIM(eANIM_EFFECTS anim) => _ANIM = anim;
public static SkinANIM operator |(SkinANIM a, SkinANIM b) => new SkinANIM(a._ANIM | b._ANIM);
public static SkinANIM operator |(SkinANIM a, eANIM_EFFECTS anim) => new SkinANIM(a._ANIM | anim);
public static implicit operator SkinANIM(eANIM_EFFECTS anim) => new SkinANIM(anim);
/// <summary>
/// Sets the desired flag in the bitfield
/// </summary>

View File

@@ -15,6 +15,7 @@ namespace PckStudio.Forms.Utilities.Skins
public partial class ANIMEditor : MetroFramework.Forms.MetroForm
{
public bool saved = false;
readonly SkinANIM initialANIM;
public string outANIM => animValue.Text;
SkinANIM anim = new SkinANIM();
@@ -69,8 +70,9 @@ namespace PckStudio.Forms.Utilities.Skins
DialogResult = DialogResult.Abort;
Close();
}
anim = new SkinANIM(ANIM);
initialANIM = anim = new SkinANIM(ANIM);
#region Event definitions, since the designer can't parse lambda experessions
bobbingCheckBox.CheckedChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.HEAD_BOBBING_DISABLED); };
bodyCheckBox.CheckedChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.BODY_DISABLED); };
bodyOCheckBox.CheckedChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.BODY_OVERLAY_DISABLED); };
@@ -117,8 +119,8 @@ namespace PckStudio.Forms.Utilities.Skins
leftArmorCheckBox.EnabledChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.FORCE_LEFT_ARM_ARMOR); };
rightLeggingCheckBox.EnabledChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.FORCE_RIGHT_LEG_ARMOR); };
leftLeggingCheckBox.EnabledChanged += (sender, EventArgs) => { flagChanged(sender, EventArgs, eANIM_EFFECTS.FORCE_LEFT_LEG_ARMOR); };
processCheckBoxes();
#endregion
processCheckBoxes();
}
private void closeButton_Click(object sender, EventArgs e)
@@ -228,5 +230,44 @@ namespace PckStudio.Forms.Utilities.Skins
skin.Save(saveFileDialog.FileName);
}
private void resetButton_Click(object sender, EventArgs e)
{
anim = initialANIM;
processCheckBoxes();
}
static Dictionary<string, eANIM_EFFECTS> Templates = new Dictionary<string, eANIM_EFFECTS>()
{
{ "Steve (64x32)", eANIM_EFFECTS.NONE },
{ "Steve (64x64)", eANIM_EFFECTS.RESOLUTION_64x64 },
{ "Alex (64x64)", eANIM_EFFECTS.SLIM_MODEL },
{ "Zombie Skins", eANIM_EFFECTS.ZOMBIE_ARMS },
{ "Cetacean Skins", eANIM_EFFECTS.SYNCED_ARMS | eANIM_EFFECTS.SYNCED_LEGS },
{ "Ski Skins", eANIM_EFFECTS.SYNCED_ARMS | eANIM_EFFECTS.STATIC_LEGS },
{ "Ghost Skins", eANIM_EFFECTS.STATIC_LEGS | eANIM_EFFECTS.ZOMBIE_ARMS },
{ "Medusa (Greek Myth.)", eANIM_EFFECTS.SYNCED_LEGS },
{ "Librarian (Halo)", eANIM_EFFECTS.STATIC_LEGS },
{ "Grim Reaper (Halloween)", eANIM_EFFECTS.STATIC_LEGS | eANIM_EFFECTS.STATIC_ARMS }
};
private void templateButton_Click(object sender, EventArgs e)
{
// Recycling the AddCategory popup to handle the ANIM templates (:
// diag.Category will be the ANIM codes
var diag = new Additional_Popups.Audio.addCategory(Templates.Keys.ToArray());
diag.label2.Text = "Presets";
diag.button1.Text = "Load";
if (diag.ShowDialog() != DialogResult.OK) return;
var templateANIM = Templates[diag.Category];
DialogResult prompt = MessageBox.Show(this, "Would you like to add this preset's effects to your current ANIM? Otherwise all of your effects will be cleared. Either choice can be undone by pressing \"Restore ANIM\".", "", MessageBoxButtons.YesNo);
if (prompt == DialogResult.Yes) anim |= templateANIM;
else anim = templateANIM;
SkinANIM backup = anim;
processCheckBoxes();
anim = backup;
}
}
}