Exemplo n.º 1
0
        private void menuItem_LoadNavigation_Click(object sender, EventArgs e)
        {
            OpenFileDialog open_file_dlg = new OpenFileDialog();

            open_file_dlg.InitialDirectory = editor_handle.project_default_dir + "\\Game-Navigation";

            open_file_dlg.ShowDialog();

            if (open_file_dlg.FileName == "")
            {
                return;
            }

            if (Path.GetExtension(open_file_dlg.FileName) == ".nav" || Path.GetExtension(open_file_dlg.FileName) == "nav")
            {
                cur_file = open_file_dlg.FileName;
                readNavigationFile(open_file_dlg.FileName);
            }
            else
            {
                MessageBox.Show("File format invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            camX = camY = 0;
            selected_nav_point = null;
            reloadGameObjects();
        }
Exemplo n.º 2
0
        void shortmenu_createPoint_Click(object sender, EventArgs e)
        {
            selected_nav_point = new NavigationPoint();

            selected_nav_point.position_x = mouseX;
            selected_nav_point.position_y = mouseY;

            NavigationPoint cur_point = navigation_start;

            while (cur_point != null)
            {
                if (cur_point.next_handle == null)
                {
                    break;
                }
                cur_point = cur_point.next_handle;
            }

            if (cur_point == null)
            {
                navigation_start = selected_nav_point;
            }
            else
            {
                cur_point.next_handle = selected_nav_point;
            }
        }
Exemplo n.º 3
0
 private void shortmenu_selectPoint_Click(object sender, EventArgs e)
 {
     if (lb_points.SelectedIndex != -1)
     {
         selected_nav_point = pointAt(lb_points.SelectedIndex);
     }
 }
Exemplo n.º 4
0
 private void menuItem_NewNavigation_Click(object sender, EventArgs e)
 {
     navigation_start   = null;
     selected_nav_point = null;
     reloadGameObjects();
     loadPointList();
     camX     = camY = 0;
     cur_file = "new_file";
     editor_handle.reloadFileTree();
 }
Exemplo n.º 5
0
 private void menuItem_DeleteNavigation_Click(object sender, EventArgs e)
 {
     if (File.Exists(cur_file))
     {
         File.Delete(cur_file);
     }
     selected_nav_point = null;
     navigation_start   = null;
     cur_file           = "new_file";
     editor_handle.reloadFileTree();
 }
Exemplo n.º 6
0
        void canvas_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.Black);

            for (int y = 0; y < canvas.Height; y += 40)
            {
                for (int x = 0; x < canvas.Width; x += 40)
                {
                    e.Graphics.DrawLine(new Pen(Brushes.Gray), new Point(x, 0), new Point(x, canvas.Height));
                    e.Graphics.DrawLine(new Pen(Brushes.Gray), new Point(0, y), new Point(canvas.Width, y));
                }
            }

            for (int cnt = 0; cnt < editor_handle.sortedArray.Length; cnt++)
            {
                int cntr = editor_handle.sortedArray[cnt].index;

                if (gameObject_list[cntr].mainObject.object_img != null)
                {
                    e.Graphics.DrawImage(new Bitmap(gameObject_list[cntr].mainObject.object_img, new Size(gameObject_list[cntr].mainObject.object_img.Width, gameObject_list[cntr].mainObject.object_img.Height)), new Point(gameObject_list[cntr].position_scene_x, gameObject_list[cntr].position_scene_y));
                }
                else if (gameObject_list[cntr].mainObject.object_text != "")
                {
                    e.Graphics.DrawString(gameObject_list[cntr].mainObject.object_text, new Font("Verdana", 12), Brushes.White, new Point(gameObject_list[cntr].position_scene_x, gameObject_list[cntr].position_scene_y));
                }
            }

            if (navigation_start != null)
            {
                NavigationPoint cur_point = navigation_start;
                Color           start_col = Color.Green;

                while (cur_point != null)
                {
                    e.Graphics.DrawEllipse(new Pen(start_col), new Rectangle(cur_point.scene_x + 10, cur_point.scene_y + 10, 20, 20));

                    if (cur_point.next_handle != null)
                    {
                        e.Graphics.DrawLine(new Pen(Color.Red), new Point(cur_point.scene_x + 20, cur_point.scene_y + 20), new Point(cur_point.next_handle.scene_x + 20, cur_point.next_handle.scene_y + 20));

                        cur_point = cur_point.next_handle;
                    }
                    else
                    {
                        break;
                    }

                    if (start_col == Color.Green)
                    {
                        start_col = Color.Yellow;
                    }
                }
            }
        }
Exemplo n.º 7
0
        void shortmenu_deletePoint_Click(object sender, EventArgs e)
        {
            NavigationPoint cur_point  = navigation_start;
            NavigationPoint cur_parent = null;
            bool            isDeleted  = false;

            while (cur_point != null)
            {
                if (!isDeleted)
                {
                    if (cur_point == selected_nav_point)
                    {
                        isDeleted = true;

                        if (cur_point.next_handle != null)
                        {
                            cur_point.position_x = cur_point.next_handle.position_x;
                            cur_point.position_y = cur_point.next_handle.position_y;
                            cur_point.scene_x    = cur_point.next_handle.scene_x;
                            cur_point.scene_y    = cur_point.next_handle.scene_y;
                        }
                    }
                    else
                    {
                        cur_parent = cur_point;
                    }

                    cur_point = cur_point.next_handle;
                }
                else
                {
                    if (cur_point.next_handle != null)
                    {
                        cur_point.position_x = cur_point.next_handle.position_x;
                        cur_point.position_y = cur_point.next_handle.position_y;
                        cur_point.scene_x    = cur_point.next_handle.scene_x;
                        cur_point.scene_y    = cur_point.next_handle.scene_y;
                        cur_parent           = cur_point;
                    }

                    cur_point = cur_point.next_handle;
                }
            }

            if (cur_parent != null)
            {
                cur_parent.next_handle = null;
            }

            loadPointList();

            selected_nav_point = null;
        }
Exemplo n.º 8
0
        void NavigationEditor_KeyDown(object sender, KeyEventArgs e)
        {
            NavigationPoint nav_point = navigation_start;

            if (e.KeyCode == Keys.Up)
            {
                while (nav_point != null)
                {
                    nav_point.scene_y += 5;

                    nav_point = nav_point.next_handle;
                }

                camY -= 5;
            }
            else if (e.KeyCode == Keys.Down)
            {
                while (nav_point != null)
                {
                    nav_point.scene_y -= 5;

                    nav_point = nav_point.next_handle;
                }

                camY += 5;
            }
            else if (e.KeyCode == Keys.Left)
            {
                while (nav_point != null)
                {
                    nav_point.scene_x += 5;

                    nav_point = nav_point.next_handle;
                }

                camX -= 5;
            }
            else if (e.KeyCode == Keys.Right)
            {
                while (nav_point != null)
                {
                    nav_point.scene_x -= 5;

                    nav_point = nav_point.next_handle;
                }

                camX += 5;
            }
        }
Exemplo n.º 9
0
        private NavigationPoint pointAt(int count)
        {
            NavigationPoint cur_point = navigation_start;
            int             cnt       = 0;

            while (cur_point != null)
            {
                if (cnt == count)
                {
                    return(cur_point);
                }

                cnt++;
                cur_point = cur_point.next_handle;
            }

            return(null);
        }
Exemplo n.º 10
0
        private void menuItem_SaveNavigation_Click(object sender, EventArgs e)
        {
            if (cur_file == "")
            {
                return;
            }
            else if (cur_file == "new_file")
            {
                SaveFileDialog save_file_dlg = new SaveFileDialog();

                save_file_dlg.InitialDirectory = editor_handle.project_default_dir + "\\Game-Navigation";

                save_file_dlg.ShowDialog();

                if (save_file_dlg.FileName != "")
                {
                    cur_file = save_file_dlg.FileName;
                }
                else
                {
                    return;
                }
            }

            StreamWriter    stm_wr    = new StreamWriter(cur_file);
            NavigationPoint nav_point = navigation_start;

            while (nav_point != null)
            {
                stm_wr.WriteLine(nav_point.position_x + "," + nav_point.position_y);

                nav_point = nav_point.next_handle;
            }


            stm_wr.Flush();
            stm_wr.Close();

            editor_handle.reloadFileTree();
        }
Exemplo n.º 11
0
        private void btn_moveUp_Click(object sender, EventArgs e)
        {
            NavigationPoint nav_point = navigation_start;

            while (nav_point != null)
            {
                nav_point.scene_y += 5;

                nav_point = nav_point.next_handle;
            }

            for (int cnt = 0; cnt < gameObject_list.Count; cnt++)
            {
                Editor.GameObject_Scene gameObject = gameObject_list[cnt];

                gameObject.position_scene_y += 5;

                gameObject_list[cnt] = gameObject;
            }

            camY -= 5;
        }
Exemplo n.º 12
0
        private void loadPointList()
        {
            lb_points.Items.Clear();

            NavigationPoint nav_point = navigation_start;
            bool            isFirst   = true;

            while (nav_point != null)
            {
                if (isFirst)
                {
                    lb_points.Items.Add("Point X : " + nav_point.position_x + " Y : " + nav_point.position_y + " - First Point");
                    isFirst = false;
                }
                else
                {
                    lb_points.Items.Add("Point X : " + nav_point.position_x + " Y : " + nav_point.position_y);
                }

                nav_point = nav_point.next_handle;
            }
        }
Exemplo n.º 13
0
        void canvas_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (selected_nav_point != null)
                {
                    selected_nav_point = null;
                    return;
                }

                NavigationPoint nav_point = navigation_start;

                while (nav_point != null)
                {
                    if (nav_point.position_x + 20 > mouseX && nav_point.position_x < mouseX && nav_point.position_y + 20 > mouseY && nav_point.position_y < mouseY)
                    {
                        selected_nav_point = nav_point;
                        return;
                    }

                    nav_point = nav_point.next_handle;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                ContextMenu short_menu = new ContextMenu();

                if (selected_nav_point != null)
                {
                    short_menu.MenuItems.AddRange(new MenuItem[] { shortmenu_deselectPoint, shortmenu_deletePoint });
                }
                else
                {
                    short_menu.MenuItems.AddRange(new MenuItem[] { shortmenu_createPoint });
                }

                this.canvas.ContextMenu = short_menu;
            }
        }
Exemplo n.º 14
0
        private void readNavigationFile(string path)
        {
            StreamReader  stm_rd     = new StreamReader(path);
            List <string> token_list = new List <string>();

            while (!stm_rd.EndOfStream)
            {
                string cur_line  = stm_rd.ReadLine();
                string cur_token = "";

                foreach (char ch in cur_line)
                {
                    if (ch == ',')
                    {
                        if (cur_token != "")
                        {
                            token_list.Add(cur_token);
                        }

                        cur_token = "";
                    }
                    else
                    {
                        cur_token += ch;
                    }
                }


                if (cur_token != "")
                {
                    token_list.Add(cur_token);
                }
            }

            stm_rd.Close();

            navigation_start = new NavigationPoint();
            NavigationPoint cur_point  = navigation_start;
            string          cur_action = "";
            bool            isStart    = false;

            foreach (string str in token_list)
            {
                if (cur_action == "")
                {
                    if (isStart)
                    {
                        cur_point.next_handle = new NavigationPoint();
                        cur_point             = cur_point.next_handle;
                    }

                    cur_point.position_x = int.Parse(str);
                    cur_point.scene_x    = cur_point.position_x;
                    cur_action           = "get_posy";
                }
                else
                {
                    if (cur_action == "get_posy")
                    {
                        cur_point.position_y = int.Parse(str);
                        cur_point.scene_y    = cur_point.position_y;
                        cur_action           = "";
                    }
                }

                isStart = true;
            }

            loadPointList();
        }
Exemplo n.º 15
0
 void shortmenu_deselectPoint_Click(object sender, EventArgs e)
 {
     selected_nav_point = null;
 }