Exemple #1
0
        private void worldMap_Click(object sender, EventArgs e)
        {
            try
            {
                MouseEventArgs eM = e as MouseEventArgs;
                if (eM.Button == MouseButtons.Left)
                {
                    Point ip = new Point(eM.X, eM.Y);

                    if (Control.ModifierKeys == Keys.Control)
                    {
                        if (selection_Obj != null)
                        {
                            if (cbAutoAlign.Checked)
                            {
                                ip.X = ip.X / 32 * 32;
                                ip.Y = (ip.Y / 32 + 1) * 32;
                                if (selection_Obj.Image.Height < 32)
                                {
                                    ip.Y -= 32 - selection_Obj.Image.Height;
                                }
                            }
                            else
                            {
                                ip.X -= 16;
                                ip.Y += 16;
                            }
                            ip.Y = y_Axis - ip.Y;

                            Objects tmpObj = getObjectsAtPos(ip.X, ip.Y);
                            if (tmpObj != null)
                            {
                                if (tmpObj.getTypeNameById() == selection_Obj.Name && tmpObj.Point == ip)
                                {
                                    return;
                                }
                            }
                            add(ip);
                            if (cbRandomItm.Checked)
                            {
                                Random rnd = new Random();
                                int    r   = rnd.Next(listItm.Count);
                                change_Itm(listItm[r].Name);

                                Bitmap curs = new Bitmap(selection_Obj.Image);
                                if (!isNoItmObj(selection_Obj.Name) && selection_Itm.Image != null)
                                {
                                    using (Graphics g = Graphics.FromImage(curs))
                                    {
                                        Rectangle re = new Rectangle(0, curs.Height - 16, 16, 16);
                                        g.DrawImage((Bitmap)selection_Itm.Image, re);
                                    }
                                }
                                pnMapViewer.Cursor = CustomCursor.CreateCursor(curs, 16, selection_Obj.Image.Height - 16);
                            }
                        }
                    }
                    else if (Control.ModifierKeys == Keys.Shift)
                    {
                        Objects tmpObj = getObjectsAtPos(eM.X, y_Axis - eM.Y);
                        if (tmpObj == null)
                        {
                            return;
                        }
                        worldmap.ListObject.Remove(tmpObj);
                    }
                    else
                    {
                        Objects tmpObj = getObjectsAtPos(eM.X, y_Axis - eM.Y);
                        if (tmpObj == null)
                        {
                            return;
                        }
                        if (currentObj != tmpObj)
                        {
                            currentObj       = tmpObj;
                            this.tbPosX.Text = currentObj.Point.X.ToString();
                            this.tbPosY.Text = currentObj.Point.Y.ToString();
                            this.tbVar1.Text = currentObj.Value_1.ToString();
                            this.tbVar2.Text = currentObj.Value_2.ToString();
                            this.tbVar3.Text = currentObj.Value_3.ToString();
                            change_Obj(currentObj.getTypeNameById());
                            change_Itm(currentObj.getItemNameById());

                            rect.X      = currentObj.Point.X;
                            rect.Y      = y_Axis - currentObj.Point.Y - currentObj.Size.Height;
                            rect.Width  = currentObj.Size.Width;
                            rect.Height = currentObj.Size.Height;
                        }
                    }

                    pb_background.Invalidate();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Nhập số hợp lệ cho các textbox!\n");
            }
        }