예제 #1
0
 private void mapViewPanel_Paint(object sender, PaintEventArgs e)
 {
     if (human != null)
     {
         int humanPathLength = human.path.Length;
         if (humanPathLength > 0)
         {
             HexSet humanHexSet = map.MapState.GetHexSet(human.hexSetIdx);
             for (int i = 0; i < humanPathLength; i++)
             {
                 HexaPos pos = human.path[i];
                 humanHexSet.hexSet.Add(map.GetHex(pos.X, pos.Y));
             }
         }
         else
         {
             if (map.MapState.GetHexSetNum() > 0)
             {
                 HexSet humanHexSet = map.MapState.GetHexSet(human.hexSetIdx);
                 humanHexSet.hexSet.Clear();
             }
         }
     }
     if (mapVisible == true)
     {
         if (mapDrawer != null)
         {
             mapDrawer.Draw(e.Graphics);
         }
     }
 }
예제 #2
0
        private void SimTestForm_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Point mouseClick = new Point(e.X - _mapDrawer.BoardXOffset, e.Y - _mapDrawer.BoardYOffset);
                Hex   clickedHex = _map.FindHexMouseClick(mouseClick);

                //_map.MapState.ActiveHex = clickedHex;

                if (clickedHex != null)
                {
                    if (_human.path.Length == 0)
                    {
                        _human.hexSetIdx = _map.MapState.CreateHexSet();
                    }

                    _human.path.AddPos(new HexaPos(clickedHex.posX, clickedHex.posY));

                    HexSet hexSet = _map.MapState.GetHexSet(_human.hexSetIdx);
                    hexSet.borderColor = Color.Blue;
                    hexSet.hexSet.Add(clickedHex);
                }
            }
            else
            {
                _map.MapState.ActiveHex = null;
            }
            Refresh();
        }
예제 #3
0
        private void MapForm_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (_formState == FormState.ADD_HUMAN_INIT)
                {
                    Point mouseClick = new Point(e.X - _mapDrawer.BoardXOffset, e.Y - _mapDrawer.BoardYOffset);
                    Hex   clickedHex = _map.FindHexMouseClick(mouseClick);

                    if (false == _map.MapState.IsObstacle(clickedHex))
                    {
                        _human.SetInitPos(new HexaPos(clickedHex.posX, clickedHex.posY));

                        _formState = FormState.GENERATING_HUMANPATH;
                        _map.MapState.ActiveHex = clickedHex;

                        _human.hexSetIdx = _map.MapState.CreateHexSet();
                        HexSet hexSet = _map.MapState.GetHexSet(_human.hexSetIdx);
                        hexSet.borderColor = Color.Blue;
                    }
                }
                else if (_formState == FormState.EDIT_OBSTACLE)
                {
                    Point mouseClick = new Point(e.X - _mapDrawer.BoardXOffset, e.Y - _mapDrawer.BoardYOffset);
                    Hex   clickedHex = _map.FindHexMouseClick(mouseClick);

                    _map.MapState.AddObstalce(clickedHex);
                }
            }
            Refresh();
        }
예제 #4
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            HexSet hexSet = _map.MapState.GetHexSet(_human.hexSetIdx);

            if (hexSet != null)
            {
                hexSet.Clear();
            }
            _human.path.Clear();
            Refresh();
        }
예제 #5
0
        private void mapViewPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (this.appMode == MapViewForm.AppMode.PLANNING)
                {
                    if (this.planMode == MapViewForm.PathPlanMode.MIN_DIST)
                    {
                        // pop to choose "complete" or "cancel"
                        this.cmsAddPoint.Show(this.Left + e.X, this.Top + e.Y);
                        this.currentCursorX = e.X;
                        this.currentCursorY = e.Y;
                    }
                    else
                    {
                        Point mouseClick = new Point(e.X - mapDrawer.BoardXOffset, e.Y - mapDrawer.BoardYOffset);
                        Hex   clickedHex = map.FindHexMouseClick(mouseClick);

                        this.startHex          = clickedHex;
                        map.MapState.ActiveHex = clickedHex;
                        Refresh();
                    }
                }
                else if (this.appMode == MapViewForm.AppMode.ADD_HUMAN)
                {
                    Point mouseClick = new Point(e.X - mapDrawer.BoardXOffset, e.Y - mapDrawer.BoardYOffset);
                    Hex   clickedHex = map.FindHexMouseClick(mouseClick);

                    human = new Human(map);
                    human.SetInitPos(new HexaPos(clickedHex.posX, clickedHex.posY));
                    human.hexSetIdx = map.MapState.CreateHexSet();
                    HexSet hexSet = map.MapState.GetHexSet(human.hexSetIdx);
                    hexSet.borderColor = Color.Black;
                }
            }
            Refresh();
        }
예제 #6
0
        private void MapForm_Paint(object sender, PaintEventArgs e)
        {
            this.btnAnimation.Text        = "Show Search Space";
            this.btnHumanPath.Text        = "Generate Human Path";
            this.btnObstacle.Text         = "Edit Obstacles";
            this.btnRobotPath.Enabled     = false;
            this.btnHumanPath.Enabled     = true;
            this.btnAnimation.Enabled     = true;
            this.btnClearObstacle.Enabled = false;
            this.HCtrl.Enabled            = false;

            switch (_formState)
            {
            case FormState.IDLE:
            default:
                break;

            case FormState.EDIT_OBSTACLE:
                this.btnObstacle.Enabled      = true;
                this.btnObstacle.Text         = "Finish Editing Obstacles";
                this.btnClearObstacle.Enabled = true;
                this.btnHumanPath.Enabled     = false;
                this.btnAnimation.Enabled     = false;
                this.btnRobotPath.Enabled     = false;
                break;

            case FormState.ADD_HUMAN_INIT:
                this.btnRobotPath.Enabled = false;
                this.btnHumanPath.Text    = "Finish Human Path";
                this.btnAnimation.Enabled = false;

                break;

            case FormState.GENERATING_HUMANPATH:
                this.btnRobotPath.Enabled = false;
                this.btnHumanPath.Text    = "Finish Human Path";
                this.btnAnimation.Enabled = false;
                this.HCtrl.Enabled        = true;
                break;

            case FormState.HUMANPATH_GENERATED:
                this.btnRobotPath.Enabled = true;
                break;

            case FormState.SHOWING_SEARCHSPACE:
                this.btnAnimation.Text = "Quit";
                break;
            }

            //update textbox
            if (_human != null)
            {
                int humanPathLength = _human.path.Length;

                if (humanPathLength > 0)
                {
                    HexSet humanHexSet = _map.MapState.GetHexSet(_human.hexSetIdx);
                    this.tbHumanPath.Clear();
                    for (int i = 0; i < humanPathLength; i++)
                    {
                        HexaPos pos     = _human.path[i];
                        string  posInfo = i.ToString() + " : " + pos.X.ToString() + " , " + pos.Y.ToString() + "\n";
                        this.tbHumanPath.AppendText(posInfo);
                        humanHexSet.hexSet.Add(_map.GetHex(pos.X, pos.Y));
                    }
                }
                else
                {
                    this.tbHumanPath.Clear();
                    if (_map.MapState.GetHexSetNum() > 0)
                    {
                        HexSet humanHexSet = _map.MapState.GetHexSet(_human.hexSetIdx);
                        humanHexSet.hexSet.Clear();
                    }
                }
            }

            //Draw the graphics/GUI
            foreach (Control c in this.Controls)
            {
                c.Refresh();
            }

            if (_mapDrawer != null)
            {
                _mapDrawer.Draw(e.Graphics);
            }

            //Force the next Paint()
            //this.Invalidate();
        }