private void getSlotFiller(int offset, PictureBox pb) { if (SAV.getData(offset, SAV.SIZE_STORED).SequenceEqual(new byte[SAV.SIZE_STORED])) { // 00s present in slot. pb.Image = null; pb.BackColor = Color.Transparent; return; } PKM p = SAV.getStoredSlot(offset); if (!p.Valid) // Invalid { // Bad Egg present in slot. pb.Image = null; pb.BackColor = Color.Red; return; } // Something stored in slot. Only display if species is valid. var sprite = p.Species != 0 ? p.Sprite : null; int slot = getSlot(pb); bool locked = slot < 30 && SAV.getIsSlotLocked(CB_BoxSelect.SelectedIndex, slot); bool team = slot < 30 && SAV.getIsTeamSet(CB_BoxSelect.SelectedIndex, slot); if (locked) { sprite = Util.LayerImage(sprite, Properties.Resources.locked, 26, 0, 1); } else if (team) { sprite = Util.LayerImage(sprite, Properties.Resources.team, 21, 0, 1); } pb.Image = sprite; pb.BackColor = Color.Transparent; }
private void getQuickFiller(PictureBox pb, PKM pk) { var sprite = pk.Species != 0 ? pk.Sprite : null; int slot = getSlot(pb); bool locked = slot < 30 && SAV.getIsSlotLocked(CB_BoxSelect.SelectedIndex, slot); if (locked) { sprite = Util.LayerImage(sprite, Properties.Resources.locked, 5, 0, 1); } pb.Image = sprite; if (pb.BackColor == Color.Red) { pb.BackColor = Color.Transparent; } }
private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { DragInfo.Destination.Parent = this; DragInfo.Destination.Slot = getSlot(sender); DragInfo.Destination.Offset = getPKXOffset(DragInfo.Destination.Slot); DragInfo.Destination.Box = CB_BoxSelect.SelectedIndex; // Check for In-Dropped files (PKX,SAV,ETC) string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (Directory.Exists(files[0])) { return; } if (SAV.getIsSlotLocked(DragInfo.Destination.Box, DragInfo.Destination.Slot)) { DragInfo.Destination.Slot = -1; // Invalidate WinFormsUtil.Alert("Unable to set to locked slot."); return; } if (DragInfo.Source.Offset < 0) // file { if (files.Length <= 0) { return; } string file = files[0]; FileInfo fi = new FileInfo(file); if (!PKX.getIsPKM(fi.Length) && !MysteryGift.getIsMysteryGift(fi.Length)) { return; } byte[] data = File.ReadAllBytes(file); MysteryGift mg = MysteryGift.getMysteryGift(data, fi.Extension); PKM temp = mg != null?mg.convertToPKM(SAV) : PKMConverter.getPKMfromBytes(data, prefer: SAV.Generation); string c; PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); if (pk == null) { WinFormsUtil.Error(c); Console.WriteLine(c); return; } string[] errata = SAV.IsPKMCompatible(pk); if (errata.Length > 0) { string concat = string.Join(Environment.NewLine, errata); if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, concat, "Continue?")) { Console.WriteLine(c); Console.WriteLine(concat); return; } } DragInfo.SetPKM(pk, false); getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pk); Console.WriteLine(c); } else { PKM pkz = DragInfo.GetPKM(true); if (!DragInfo.Source.IsValid) { } // not overwritable, do nothing else if (ModifierKeys == Keys.Alt && DragInfo.Destination.IsValid) // overwrite { // Clear from slot if (DragInfo.SameBox) { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], SAV.BlankPKM); // picturebox } DragInfo.SetPKM(SAV.BlankPKM, true); } else if (ModifierKeys != Keys.Control && DragInfo.Destination.IsValid) // move { // Load data from destination PKM pk = ((PictureBox)sender).Image != null ? DragInfo.GetPKM(false) : SAV.BlankPKM; // Set destination pokemon image to source picture box if (DragInfo.SameBox) { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pk); } // Set destination pokemon data to source slot DragInfo.SetPKM(pk, true); } else if (DragInfo.SameBox) // clone { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pkz); } // Copy from temp to destination slot. DragInfo.SetPKM(pkz, false); getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pkz); e.Effect = DragDropEffects.Link; Cursor = DefaultCursor; } if (DragInfo.Source.IsParty || DragInfo.Destination.IsParty) { parent.setParty(); } if (DragInfo.Source.Parent == null) // another instance or file { parent.notifyBoxViewerRefresh(); DragInfo.Reset(); } }
private void pbBoxSlot_MouseMove(object sender, MouseEventArgs e) { if (DragInfo.DragDropInProgress) { return; } if (!DragInfo.LeftMouseIsDown) { return; } // The goal is to create a temporary PKX file for the underlying Pokemon // and use that file to perform a drag drop operation. // Abort if there is no Pokemon in the given slot. PictureBox pb = (PictureBox)sender; if (pb.Image == null) { return; } int slot = getSlot(pb); int box = slot >= 30 ? -1 : CB_BoxSelect.SelectedIndex; if (SAV.getIsSlotLocked(box, slot)) { return; } // Set flag to prevent re-entering. DragInfo.DragDropInProgress = true; DragInfo.Source.Parent = this; DragInfo.Source.Slot = slot; DragInfo.Source.Box = box; DragInfo.Source.Offset = getPKXOffset(DragInfo.Source.Slot); // Prepare Data DragInfo.Source.Data = SAV.getData(DragInfo.Source.Offset, SAV.SIZE_STORED); // Make a new file name based off the PID byte[] dragdata = SAV.decryptPKM(DragInfo.Source.Data); Array.Resize(ref dragdata, SAV.SIZE_STORED); PKM pkx = SAV.getPKM(dragdata); string filename = pkx.FileName; // Make File string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename)); try { File.WriteAllBytes(newfile, dragdata); var img = (Bitmap)pb.Image; DragInfo.Cursor = Cursor.Current = new Cursor(img.GetHicon()); pb.Image = null; pb.BackgroundImage = Resources.slotDrag; // Thread Blocks on DoDragDrop DragInfo.CurrentPath = newfile; DragDropEffects result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); if (!DragInfo.Source.IsValid || result != DragDropEffects.Link) // not dropped to another box slot, restore img { pb.Image = img; } else // refresh image { getQuickFiller(pb, SAV.getStoredSlot(DragInfo.Source.Offset)); } pb.BackgroundImage = null; if (DragInfo.SameBox && DragInfo.Destination.IsValid) { if (SAV.getIsTeamSet(box, DragInfo.Destination.Slot) ^ SAV.getIsTeamSet(box, DragInfo.Source.Slot)) { getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], SAV.getStoredSlot(DragInfo.Destination.Offset)); } else { SlotPictureBoxes[DragInfo.Destination.Slot].Image = img; } } } catch (Exception x) { WinFormsUtil.Error("Drag & Drop Error", x); } parent.notifyBoxViewerRefresh(); DragInfo.Reset(); Cursor = DefaultCursor; // Browser apps need time to load data since the file isn't moved to a location on the user's local storage. // Tested 10ms -> too quick, 100ms was fine. 500ms should be safe? new Thread(() => { Thread.Sleep(500); if (File.Exists(newfile) && DragInfo.CurrentPath == null) { File.Delete(newfile); } }).Start(); }