Misc tweaks

allow cute charm static encounters
ignore user-entry control types
This commit is contained in:
Kurt 2017-10-01 21:25:23 -07:00
parent c28575aad7
commit b23658dee1
3 changed files with 77 additions and 68 deletions

View File

@ -682,16 +682,18 @@ public static bool IsCompatible4(this PIDType val, IEncounterable encounter, PKM
switch (encounter)
{
case EncounterStatic s:
if (s == Encounters4.SpikyEaredPichu // nonshiny forced nature
|| s.Location == 233 && s.Gift) // Pokewalker
if (s == Encounters4.SpikyEaredPichu || s.Location == 233 && s.Gift) // Pokewalker
return val == PIDType.Pokewalker;
return s.Shiny == true ? val == PIDType.ChainShiny : val == PIDType.Method_1;
if (s.Shiny == true)
return val == PIDType.ChainShiny;
if (val == PIDType.CuteCharm)
return true;
return val == PIDType.Method_1;
case EncounterSlot sl:
if (val == PIDType.Method_1)
return true;
if (val == PIDType.CuteCharm)
// Cute charm does not work with swarms pokemon
return sl.Type != SlotType.Swarm;
return sl.Type != SlotType.Swarm; // Cute Charm does not work with Swarm
if (val != PIDType.ChainShiny)
return false;
// Chain shiny with poke radar is only possible in DPPt in tall grass, safari zone do not allow pokeradar
@ -700,7 +702,7 @@ public static bool IsCompatible4(this PIDType val, IEncounterable encounter, PKM
return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Encounters4.SafariZoneLocation_4.Contains(sl.Location);
case PGT _: // manaphy
return IsG4ManaphyPIDValid(val, pkm);
default:
default: // eggs
return val == PIDType.None;
}
}

View File

@ -28,19 +28,12 @@ public static Bitmap ChangeOpacity(Image img, double trans)
if (img.PixelFormat.HasFlag(PixelFormat.Indexed))
return (Bitmap)img;
Bitmap bmp = (Bitmap)img.Clone();
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
IntPtr ptr = bmpData.Scan0;
var bmp = (Bitmap)img.Clone();
GetBitmapData(bmp, out BitmapData bmpData, out IntPtr ptr, out byte[] data);
int len = bmp.Width * bmp.Height * 4;
byte[] data = new byte[len];
Marshal.Copy(ptr, data, 0, len);
for (int i = 0; i < data.Length; i += 4)
data[i + 3] = (byte)(data[i + 3] * trans);
Marshal.Copy(data, 0, ptr, len);
Marshal.Copy(ptr, data, 0, data.Length);
SetAllTransparencyTo(data, trans);
Marshal.Copy(data, 0, ptr, data.Length);
bmp.UnlockBits(bmpData);
return bmp;
@ -52,27 +45,12 @@ public static Bitmap ChangeAllColorTo(Image img, Color c)
if (img.PixelFormat.HasFlag(PixelFormat.Indexed))
return (Bitmap)img;
Bitmap bmp = (Bitmap)img.Clone();
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
IntPtr ptr = bmpData.Scan0;
var bmp = (Bitmap)img.Clone();
GetBitmapData(bmp, out BitmapData bmpData, out IntPtr ptr, out byte[] data);
int len = bmp.Width * bmp.Height * 4;
byte[] data = new byte[len];
Marshal.Copy(ptr, data, 0, len);
byte R = c.R;
byte G = c.G;
byte B = c.B;
for (int i = 0; i < data.Length; i += 4)
if (data[i + 3] != 0)
{
data[i + 0] = B;
data[i + 1] = G;
data[i + 2] = R;
}
Marshal.Copy(data, 0, ptr, len);
Marshal.Copy(ptr, data, 0, data.Length);
SetAllColorTo(data, c);
Marshal.Copy(data, 0, ptr, data.Length);
bmp.UnlockBits(bmpData);
return bmp;
@ -84,28 +62,52 @@ public static Bitmap ToGrayscale(Image img)
if (img.PixelFormat.HasFlag(PixelFormat.Indexed))
return (Bitmap)img;
Bitmap bmp = (Bitmap)img.Clone();
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
IntPtr ptr = bmpData.Scan0;
var bmp = (Bitmap)img.Clone();
GetBitmapData(bmp, out BitmapData bmpData, out IntPtr ptr, out byte[] data);
int len = bmp.Width * bmp.Height * 4;
byte[] data = new byte[len];
Marshal.Copy(ptr, data, 0, len);
for (int i = 0; i < data.Length; i += 4)
if (data[i + 3] != 0)
{
byte greyS = (byte)((0.3 * data[i + 2] + 0.59 * data[i + 1] + 0.11 * data[i + 0]) / 3);
data[i + 0] = greyS;
data[i + 1] = greyS;
data[i + 2] = greyS;
}
Marshal.Copy(data, 0, ptr, len);
Marshal.Copy(ptr, data, 0, data.Length);
SetAllColorToGrayScale(data);
Marshal.Copy(data, 0, ptr, data.Length);
bmp.UnlockBits(bmpData);
return bmp;
}
private static void GetBitmapData(Bitmap bmp, out BitmapData bmpData, out IntPtr ptr, out byte[] data)
{
bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
ptr = bmpData.Scan0;
data = new byte[bmp.Width * bmp.Height * 4];
}
private static void SetAllTransparencyTo(byte[] data, double trans)
{
for (int i = 0; i < data.Length; i += 4)
data[i + 3] = (byte)(data[i + 3] * trans);
}
private static void SetAllColorTo(byte[] data, Color c)
{
byte R = c.R;
byte G = c.G;
byte B = c.B;
for (int i = 0; i < data.Length; i += 4)
{
if (data[i + 3] == 0)
continue;
data[i + 0] = B;
data[i + 1] = G;
data[i + 2] = R;
}
}
private static void SetAllColorToGrayScale(byte[] data)
{
for (int i = 0; i < data.Length; i += 4)
{
if (data[i + 3] == 0)
continue;
byte greyS = (byte)((0.3 * data[i + 2] + 0.59 * data[i + 1] + 0.11 * data[i + 0]) / 3);
data[i + 0] = greyS;
data[i + 1] = greyS;
data[i + 2] = greyS;
}
}
}
}

View File

@ -122,12 +122,16 @@ private static void TranslateForm(Control form, IEnumerable<string> stringdata)
default:
if (string.IsNullOrWhiteSpace(z.Name))
break;
yield return new KeyValuePair<string, object>(z.Name, z);
if (z.ContextMenuStrip != null) // control has attached menustrip
foreach (var pair in GetToolStripMenuItems(z.ContextMenuStrip))
yield return pair;
if (z is ComboBox || z is TextBox || z is MaskedTextBox || z is LinkLabel)
break; // undesirable to modify, ignore
if (!string.IsNullOrWhiteSpace(z.Text))
yield return new KeyValuePair<string, object>(z.Name, z);
break;
}
}
@ -149,8 +153,9 @@ private static void TranslateForm(Control form, IEnumerable<string> stringdata)
{
foreach (var i in menu.Items.OfType<ToolStripMenuItem>())
{
yield return new KeyValuePair<string, object>(i.Name, i);
foreach (var sub in GetToolsStripDropDownItems(i))
if (!string.IsNullOrWhiteSpace(i.Text))
yield return new KeyValuePair<string, object>(i.Name, i);
foreach (var sub in GetToolsStripDropDownItems(i).Where(z => !string.IsNullOrWhiteSpace(z.Text)))
yield return new KeyValuePair<string, object>(sub.Name, sub);
}
}
@ -284,10 +289,13 @@ public static bool OpenSAVPKMDialog(string[] Extensions, out string path)
if (Directory.Exists(pathCache))
cgse = Path.Combine(pathCache);
if (!PathUtilWindows.DetectSaveFile(out path, cgse) && !string.IsNullOrEmpty(path))
{
Error(path); // `path` contains the error message
path = null;
}
if (path != null)
{ ofd.FileName = path; }
ofd.FileName = path;
if (ofd.ShowDialog() != DialogResult.OK)
return false;
@ -322,7 +330,7 @@ public static bool SavePKMDialog(PKM pk)
if (File.Exists(path))
{
// File already exists, save a .bak
string bakpath = path + ".bak";
string bakpath = $"{path}.bak";
if (!File.Exists(bakpath))
{
byte[] backupfile = File.ReadAllBytes(path);
@ -407,12 +415,9 @@ public static bool SaveMGDialog(MysteryGift gift)
if (File.Exists(path))
{
// File already exists, save a .bak
string bakpath = path + ".bak";
string bakpath = $"{path}.bak";
if (!File.Exists(bakpath))
{
byte[] backupfile = File.ReadAllBytes(path);
File.WriteAllBytes(bakpath, backupfile);
}
File.Move(path, bakpath);
}
File.WriteAllBytes(path, gift.Data);