Beispiel #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (txt_name.Text == "")
            {
                MessageBox.Show("Object name cannot be empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            StreamWriter stm_wr = new StreamWriter(editor_handle.project_default_dir + "\\Game-Objects\\" + txt_name.Text + ".obj");

            stm_wr.WriteLine("Name: @" + txt_name.Text);
            stm_wr.WriteLine("Image: @" + "Game-Resouces\\" + Path.GetFileName(txt_image.Text));
            stm_wr.WriteLine("Text: @" + txt_text.Text);
            stm_wr.WriteLine("Tag: " + txt_tag.Text);

            stm_wr.WriteLine("Scripts: ");

            for (int cntr = 0; cntr < lb_scripts.Items.Count; cntr++)
            {
                stm_wr.Write("@Game-Scripts\\" + Path.GetFileName(lb_scripts.Items[cntr].ToString()) + "@ ");
            }

            stm_wr.Write(";");
            stm_wr.WriteLine("");

            stm_wr.WriteLine("Static: " + cb_static.Checked);
            stm_wr.WriteLine("Physics: " + cb_physics.Checked);
            stm_wr.WriteLine("RigidBody: " + cb_rigid_body.Checked);
            stm_wr.WriteLine("Collider: " + cb_collider.Checked);

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

            Editor.GameObject newObject;

            newObject.object_name = txt_name.Text;
            newObject.object_img  = (File.Exists(txt_image.Text)) ? Image.FromFile(txt_image.Text) : null;
            newObject.path        = txt_image.Text;
            newObject.scripts     = new List <string>();

            for (int cntr = 0; cntr < lb_scripts.Items.Count; cntr++)
            {
                newObject.scripts.Add((string)lb_scripts.Items[cntr]);
            }

            newObject.object_text     = txt_text.Text;
            newObject.object_tag      = int.Parse("0" + txt_tag.Text);
            newObject.isStatic        = cb_static.Checked;
            newObject.object_physics  = cb_physics.Checked;
            newObject.object_rigid    = cb_rigid_body.Checked;
            newObject.object_collider = cb_collider.Checked;

            for (int cnt = 0; cnt < editor_handle.gameObject_list.Count; cnt++)
            {
                if (editor_handle.gameObject_list[cnt].object_name == sel_name)
                {
                    for (int cntr = 0; cntr < editor_handle.gameObjectScene_list.Count; cntr++)
                    {
                        if (editor_handle.gameObjectScene_list[cntr].mainObject.object_name == sel_name)
                        {
                            Editor.GameObject_Scene handle = editor_handle.gameObjectScene_list[cntr];

                            handle.mainObject = newObject;
                            handle.Initialize();

                            editor_handle.gameObjectScene_list[cntr] = handle;
                        }
                    }

                    editor_handle.gameObject_list[cnt] = newObject;
                    break;
                }
            }
        }
Beispiel #2
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            if (txt_instance_name.Text == "")
            {
                MessageBox.Show("Instance name cannot be empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lb_object.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a object!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txt_depth.Text == "")
            {
                MessageBox.Show("Please provide a depth!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            foreach (Editor.GameObject_Scene obj in editor_handle.gameObjectScene_list)
            {
                if (obj.instance_name == txt_instance_name.Text)
                {
                    MessageBox.Show("The instance is already declared!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            Editor.GameObject_Scene game_object = new Editor.GameObject_Scene();

            game_object.instance_name    = txt_instance_name.Text;
            game_object.position_x       = int.Parse(txt_position_x.Text);
            game_object.position_y       = int.Parse(txt_position_y.Text);
            game_object.depth            = int.Parse(txt_depth.Text);
            game_object.position_scene_x = game_object.position_x + editor_handle.cam_x;
            game_object.position_scene_y = game_object.position_y + editor_handle.cam_y;
            game_object.mainObject       = editor_handle.gameObject_list[lb_object.SelectedIndex];
            game_object.Initialize();

            editor_handle.gameObjectScene_list.Add(game_object);

            editor_handle.sortedArray = new  Editor.DrawableGameObject[editor_handle.gameObjectScene_list.Count];

            for (int cnt = 0; cnt < editor_handle.gameObjectScene_list.Count; cnt++)
            {
                editor_handle.sortedArray[cnt].depth = editor_handle.gameObjectScene_list[cnt].depth;
                editor_handle.sortedArray[cnt].index = cnt;
            }

            while (!editor_handle.checkSorted(editor_handle.sortedArray))
            {
                editor_handle.sortElements(editor_handle.sortedArray);
            }

            editor_handle.addGameObject(game_object.instance_name);

            editor_handle.reloadFileTree();

            this.Close();
        }