Ejemplo n.º 1
0
        internal void removeResource(ResourceIcon resourceIcon)
        {
            Resource res = resourceIcon.Tag as Resource;

            pnlMap.Controls.Remove(resourceIcon);
            resourceCoordinates.Remove(res.ID);
            resources.Remove(res.ID);
        }
Ejemplo n.º 2
0
        ///////////////////////
        //pnlMap event handlers
        ///////////////////////

        private void pnlMap_DragEnter(object sender, DragEventArgs e)
        {
            Resource r = new Resource();

            if ((e.Data.GetDataPresent(r.GetType())))
            {
                if (tutorialMode && tutorialStep > 3)
                {
                    return;
                }
                Resource res = (Resource)e.Data.GetData(r.GetType());

                ResourceIcon resIcon = new ResourceIcon(res);

                Point p = pnlMap.PointToClient(new Point(e.X, e.Y));

                Rectangle rect = new Rectangle(
                    p.X - resIcon.Width / 2, p.Y - resIcon.Height / 2,
                    resIcon.Width + 15, resIcon.Height + 15);
                lblCoordinates.Text = p.X + ", " + p.Y;

                bool boom = false;

                foreach (Control ctrl in pnlMap.Controls)
                {
                    if (ctrl.GetType().Equals(resIcon.GetType()))
                    {
                        if (((Resource)ctrl.Tag).ID == res.ID)
                        {
                            continue;
                        }
                        if (rect.IntersectsWith(ctrl.Bounds))
                        {
                            boom = true;
                            break;
                        }
                    }
                }

                lblMessage.Text = "";
                if (boom)
                {
                    lblMessage.Text = "Nemoguće je preklapanje ikonica";
                    e.Effect        = DragDropEffects.None;
                }
                else
                {
                    e.Effect = DragDropEffects.Copy;
                }

                lblCoordinates.Text = p.X + ", " + p.Y;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
Ejemplo n.º 3
0
        internal void moveToPnlResources(ResourceIcon resourceIcon)
        {
            Resource res = resourceIcon.Tag as Resource;

            pnlMap.Controls.Remove(resourceIcon);
            resourceCoordinates.Remove(res.ID);

            Control ctrl = new ResourceControl(resources[res.ID], pnlResources.Controls.Count * 80 + 10);

            pnlResources.Controls.Add(ctrl);
            lblUnmappedResources.Text = "Nemapirani resursi(" + pnlResources.Controls.Count + ")";
        }
Ejemplo n.º 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            off = 10;
            int cnt = 0;

            pnlResources.Controls.Clear();
            foreach (Resource res in resources.Values)
            {
                if (!resourceCoordinates.ContainsKey(res.ID))
                {
                    ResourceControl resControl = new ResourceControl(res, off);
                    pnlResources.Controls.Add(resControl);

                    off += 80;
                    cnt++;
                }
            }
            pnlResources.Refresh();
            lblUnmappedResources.Text = "Nemapirani resursi(" + cnt + ")";

            if (e == null)
            {
                return;
            }

            pnlMap.Controls.Clear();
            foreach (ResourcePosition rpos in resourceCoordinates.Values)
            {
                if (resources.ContainsKey(rpos.ID))
                {
                    ResourceIcon resIcon = new ResourceIcon(resources[rpos.ID]);
                    pnlMap.Controls.Add(resIcon);
                    resIcon.Left = rpos.X;
                    resIcon.Top  = rpos.Y;
                }
                else
                {
                    resourceCoordinates.Remove(rpos.ID);
                }
            }
        }
Ejemplo n.º 5
0
        private void updateMap()
        {
            List <Control>  deletedControls = new List <Control>();
            ResourceIcon    dummyIcon       = new ResourceIcon();
            ResourceControl dummyResCtrl    = new ResourceControl();

            foreach (Control ctrl in pnlMap.Controls)
            {
                if (ctrl.GetType().Equals(dummyIcon.GetType()))
                {
                    ResourceIcon resIcon = (ResourceIcon)ctrl;
                    if (!resources.ContainsKey(((Resource)resIcon.Tag).ID))
                    {
                        deletedControls.Add(ctrl);
                        resourceCoordinates.Remove(((Resource)resIcon.Tag).ID);
                    }
                    else
                    {
                        Resource res = MainForm.resources[((Resource)resIcon.Tag).ID];
                        resIcon.Tag = res;
                        resIcon.UpdateControl();
                    }
                }
            }

            foreach (Control ctrl in deletedControls)
            {
                pnlMap.Controls.Remove(ctrl);
            }

            foreach (string id in addedResources)
            {
                Control ctrl = new ResourceControl(resources[id], pnlResources.Controls.Count * 80 + 10);
                pnlResources.Controls.Add(ctrl);
            }
            addedResources.Clear();
            lblUnmappedResources.Text = "Nemapirani resursi(" + pnlResources.Controls.Count + ")";

            deletedControls.Clear();

            foreach (Control ctrl in pnlResources.Controls)
            {
                if (ctrl.GetType().Equals(dummyResCtrl.GetType()))
                {
                    ResourceControl resCtrl = (ResourceControl)ctrl;
                    if (!resources.ContainsKey(((Resource)resCtrl.Tag).ID))
                    {
                        deletedControls.Add(ctrl);
                    }
                    else
                    {
                        Resource res = MainForm.resources[((Resource)resCtrl.Tag).ID];
                        resCtrl.Tag = res;
                        resCtrl.UpdateControl();
                    }
                }
            }

            if (deletedControls.Count > 0)
            {
                MainForm_Load(this, null);
            }
        }
Ejemplo n.º 6
0
        private void pnlMap_DragDrop(object sender, DragEventArgs e)
        {
            Resource r = new Resource();

            if (e.Data.GetDataPresent(r.GetType()))
            {
                Resource res = (Resource)e.Data.GetData(r.GetType());

                ResourceIcon resIcon = new ResourceIcon(res);
                resIcon.Name = res.ID;

                Point p = pnlMap.PointToClient(new Point(e.X, e.Y));

                foreach (Control ctrl in pnlMap.Controls)
                {
                    if (ctrl.GetType().Equals(resIcon.GetType()))
                    {
                        if (((Resource)resIcon.Tag).ID == ((Resource)((ResourceIcon)ctrl).Tag).ID)
                        {
                            pnlMap.Controls.Remove(ctrl);
                            break;
                        }
                    }
                }

                pnlMap.Controls.Add(resIcon);

                resIcon.Left = p.X - 20;
                resIcon.Top  = p.Y - 20;

                pnlMap.Refresh();

                if (tutorialMode)
                {
                    tutorialStep++;

                    if (tutorialStep == 1)
                    {
                        pbxLeft.SendToBack();
                        resIcon.BackColor = tutorialColor;
                        lblTutorial.Text  = "Pomeri crvenu ikonicu na mapi";
                        pnlResources.Controls.RemoveAt(0);
                        foreach (Control ctrl in pnlResources.Controls)
                        {
                            if (!((Resource)ctrl.Tag).ID.Equals((((Resource)resIcon.Tag).ID)))
                            {
                                ctrl.Top -= 108;
                            }
                        }
                        pbxLeft.Hide();
                    }
                    else if (tutorialStep == 2)
                    {
                        resIcon.BackColor = Color.White;
                        lblTutorial.Text  = "Prevuci crvenu stavku na mapu";
                        pnlResources.Controls[0].BackColor = tutorialColor;
                        pbxLeft.Show();
                    }
                    else if (tutorialStep == 3)
                    {
                        resIcon.BackColor = tutorialColor;
                        lblTutorial.Text  = "Pomeri crvenu ikonicu na mapi";
                        pnlResources.Controls.RemoveAt(0);
                        foreach (Control ctrl in pnlResources.Controls)
                        {
                            if (!((Resource)ctrl.Tag).ID.Equals((((Resource)resIcon.Tag).ID)))
                            {
                                ctrl.Top -= 108;
                            }
                        }
                        pbxLeft.Hide();
                    }
                    else if (tutorialStep == 4)
                    {
                        foreach (Control ctrl in pnlMap.Controls)
                        {
                            if (ctrl.Tag != null && !((Resource)ctrl.Tag).ID.Equals(((Resource)resIcon.Tag).ID))
                            {
                                resIcon = (ResourceIcon)ctrl;
                                break;
                            }
                        }
                        resIcon.BackColor = tutorialColor;
                        lblTutorial.Text  = "Prevuci crvenu ikonicu u kantu";
                        pbxDown.Show();
                    }
                    else if (tutorialStep == 5)
                    {
                        pnlMap.Controls[3].BackColor = tutorialColor;
                        lblTutorial.Text             = "Prevuci crvenu ikonicu na listu nemapiranih resursa";
                        pbxRight.Show();
                    }


                    return;
                }

                if (!resourceCoordinates.ContainsKey(res.ID))
                {
                    resourceCoordinates.Add(res.ID, new ResourcePosition(res, resIcon.Left, resIcon.Top));
                    ////////////////
                    Control sub = null, deleted = null;
                    int     maxTop = 0;

                    foreach (Control ctrl in pnlResources.Controls)
                    {
                        if (ctrl.Tag.Equals(res))
                        {
                            deleted = ctrl;
                            //break;
                        }
                        if (ctrl.Top > maxTop)
                        {
                            sub    = ctrl;
                            maxTop = ctrl.Top;
                        }
                    }

                    if (deleted != null)
                    {
                        //ResourceControl resControl = deleted as ResourceControl;
                        sub.Top = deleted.Top;
                        pnlResources.Controls.Remove(deleted);
                        lblUnmappedResources.Text = "Nemapirani resursi(" + pnlResources.Controls.Count + ")";
                    }
                    /////////////
                    //MainForm_Load(this, null);
                }
                else
                {
                    resourceCoordinates[res.ID].X = resIcon.Left;
                    resourceCoordinates[res.ID].Y = resIcon.Top;
                }
            }
        }