Пример #1
0
        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;
        }
Пример #2
0
        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;
            }

            int slot = getSlot(pb);

            pb.Image     = p.Sprite(SAV, CB_BoxSelect.SelectedIndex, slot, parent.Menu_FlagIllegal.Checked);
            pb.BackColor = Color.Transparent;
            pb.Visible   = true;
        }
Пример #3
0
        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.
            pb.Image     = p.Species == 0 ? null : p.Sprite;
            pb.BackColor = Color.Transparent;
        }
Пример #4
0
        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();
        }