示例#1
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            clearProject();
            XmlReader xr = XmlReader.Create("savedata.txt");
            string tempName = "";

            Debug.WriteUnitTest("Loading XML");
            while (xr.Read())
            {
                // Retrieve dialogue layers
                if (xr.NodeType == XmlNodeType.Element && xr.Name == "layer")
                {
                    if (tempName != xr.Name) { Debug.WriteUnitSubtest("Loading Dialog layers"); tempName = xr.Name; }

                    if (xr.HasAttributes)
                    {
                        Debug.WriteLine(xr.GetAttribute(0));
                        comboBox1.Items.Add(xr.GetAttribute(0));
                    }
                }

                // Load objects
                if (xr.NodeType == XmlNodeType.Element && xr.Name == "object")
                {
                    if (tempName != xr.Name) { Debug.WriteUnitSubtest("Loading objects"); tempName = xr.Name; }

                    if (xr.HasAttributes)
                    {
                        Dialog d = new Dialog();

                        // Create dialog
                        for (int i = 0; i < xr.AttributeCount; i++)
                        {
                            Debug.WriteLine(xr.GetAttribute(i));
                            if (i == 0) { d.Caption = xr.GetAttribute(i); }
                            if (i == 1) { d.Depth = Convert.ToInt32(xr.GetAttribute(i)); }
                            if (i == 2) { d.DialogueStart = Convert.ToBoolean(xr.GetAttribute(i)); }
                            if (i == 3) { d.Id = Convert.ToInt32(xr.GetAttribute(i)); Globalization.tempID = d.Id; }
                            if (i == 4) { d.nextDialogID = Convert.ToInt32(xr.GetAttribute(i)); }

                            if (i == 5)
                            {
                                List<int> output = deserializaceStructure(xr.GetAttribute(i));
                                d.Position = new Point(output[0], output[1]);
                            }
                            if (i == 6)
                            {
                                List<int> output = deserializaceStructure(xr.GetAttribute(i));
                                d.Size = new Size(output[0], output[1]);
                            }
                            if (i == 7) { d.Text = xr.GetAttribute(i); }
                        }

                        dialogList.Add(d);
                    }
                }
                // Unit testing
                if (xr.NodeType == XmlNodeType.Element)
                {
                    tempName = xr.Name;
                }
            }

            // Set dialogs connections
            foreach (Dialog d in dialogList)
            {
                if (d.nextDialogID != -1)
                {
                    d.nextDialog = dialogList.Find(i => i.Id == d.nextDialogID);
                }
            }

            comboBox1.SelectedIndex = 0;
            xr.Close();

            Debug.WriteUnitTest("Loading XML Completed");
        }
示例#2
0
        private Dialog getNextDialog(Dialog d, int priority = 0)
        {
            Dialog output = null;

            if (priority == 0)
            {
                if (d.nextDialog != null) { output = d.nextDialog; }
                else if (d.nextConditionDialog != null) { output = d.nextConditionDialog; }
                else if (d.nextActionDialog != null) { output = d.nextActionDialog; }
                else if (d.nextDialogBranch != null) { output = d.nextDialogBranch; }
            }
            else if (priority == 1)
            {
                if (d.nextDialogBranch != null) { output = d.nextDialogBranch; }
                else if (d.nextDialog != null) { output = d.nextDialog; }
                else if (d.nextConditionDialog != null) { output = d.nextConditionDialog; }
                else if (d.nextActionDialog != null) { output = d.nextActionDialog; }
            }

            return output;
        }
示例#3
0
        // Attach wires
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            // Select dialog
            if (e.Button == MouseButtons.Right)
            {
                foreach (Dialog dialog in dialogList)
                {
                    // If we hover over the dialog
                    if (dialog.Depth == comboBox1.SelectedIndex)
                    {
                        //In case of message
                        if (dialog.Type == Dialog.state.message)
                        {
                            // Attach dialog to dialog
                            if (dialog.Position.X + 256 - 16 > e.X && dialog.Position.Y + 64 - 16 > e.Y && dialog.Position.X + 256 - 16 < e.X + 32 && dialog.Position.Y + 64 - 16 < e.Y + 32)
                            {
                                if (selectedSlotType == -1 || selectedSlotType == 0) { if (selectedDialog.nextConditionDialog != dialog && selectedDialog.nextConditionDialog != null) { selectedDialog.nextConditionDialog.messageAttachedWire = -1; } selectedDialog.nextDialog = dialog; }
                            }

                            // Attach condition true / false to back slot
                            if (dialog.Position.X > e.X && dialog.Position.Y + 96 - 8 > e.Y && dialog.Position.X < e.X + 16 && dialog.Position.Y + 96 - 8 < e.Y + 40)
                            {
                                if (selectedSlotType == 1) { if (selectedDialog.nextDialogBranch != dialog && selectedDialog.nextDialogBranch != null) { selectedDialog.nextDialogBranch.messageAttachedWire = -1; } selectedDialog.nextDialogBranch = dialog; }
                                else if (selectedSlotType == 2) { if (selectedDialog.nextConditionDialog != dialog && selectedDialog.nextConditionDialog != null) { selectedDialog.nextConditionDialog.messageAttachedWire = -1; } selectedDialog.nextConditionDialog = dialog; }
                            }
                        }

                        // Actions
                        if (dialog.Type == Dialog.state.action)
                        {
                            // Attach dialog to dialog
                            if (dialog.Position.X + 112 > e.X && dialog.Position.Y + 64 - 16 > e.Y && dialog.Position.X + 112 < e.X + 32 && dialog.Position.Y + 64 - 16 < e.Y + 32)
                            {
                                if (selectedSlotType == -1 || selectedSlotType == 0) { if (selectedDialog.nextActionDialog != dialog && selectedDialog.nextActionDialog != null) { selectedDialog.nextActionDialog.messageAttachedWire = -1; } selectedDialog.nextActionDialog = dialog; }
                            }

                            // Attach condition true / false to back slot
                            if (dialog.Position.X > e.X && dialog.Position.Y + 96 - 8 > e.Y && dialog.Position.X < e.X + 16 && dialog.Position.Y + 96 - 8 < e.Y + 40)
                            {
                                if (selectedSlotType == 1) { if (selectedDialog.nextDialogBranch != dialog && selectedDialog.nextDialogBranch != null) { selectedDialog.nextDialogBranch.messageAttachedWire = -1; } selectedDialog.nextDialogBranch = dialog; }
                                else if (selectedSlotType == 2) { if (selectedDialog.nextConditionDialog != dialog && selectedDialog.nextConditionDialog != null) { selectedDialog.nextConditionDialog.messageAttachedWire = -1; } selectedDialog.nextConditionDialog = dialog; }
                            }
                        }

                        // Conditions
                        if (dialog.Type == Dialog.state.condition)
                        {
                            if (dialog.Position.X + 48 > e.X && dialog.Position.Y + 64 > e.Y && dialog.Position.X + 48 < e.X + 32 && dialog.Position.Y + 64 < e.Y + 32)
                            {
                                if (selectedSlotType == -1 || selectedSlotType == 0) { selectedDialog.nextConditionDialog = dialog; }
                                else if (selectedSlotType == 1) { selectedDialog.nextDialogBranch = dialog; MessageBox.Show("1"); }
                                else if (selectedSlotType == 2) { selectedDialog.nextConditionDialog = dialog; MessageBox.Show(""); }
                            }
                        }
                    }
                }
            }

            selectedDialog = null;
            drawSelected = false;
            selectedDialogForMove = null;
        }
示例#4
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            mouseDownPosition = e.Location;

            // Select dialog and move it
            if (e.Button == MouseButtons.Right)
            {
                foreach (Dialog dialog in dialogList)
                {
                    if (dialog.Depth == comboBox1.SelectedIndex)
                    {
                        // Messages && branches
                        if (dialog.Type == Dialog.state.message || dialog.Type == Dialog.state.branch)
                        {
                            if (dialog.Position.X + 256 - 16 > e.X && dialog.Position.Y + 64 - 16 > e.Y && dialog.Position.X + 256 - 16 < e.X + 32 && dialog.Position.Y + 64 - 16 < e.Y + 32)
                            {
                                selectedDialog = dialog;
                                selectedSlotType = -1;
                            }
                            else if (dialog.Position.X + 256 > e.X && dialog.Position.Y + 128 > e.Y && dialog.Position.X + 256 < e.X + 256 && dialog.Position.Y + 128 < e.Y + 128)
                            {
                                if (selectedDialog == null && !drawSelected) { selectedDialogForMove = dialog; selectedSlotType = -1; }
                            }
                        }

                        // Conditions
                        if (dialog.Type == Dialog.state.condition)
                        {
                            if (dialog.Position.X + 116 > e.X && dialog.Position.Y + 64 - 24 > e.Y && dialog.Position.X + 116 < e.X + 32 && dialog.Position.Y + 64 - 24 < e.Y + 32)
                            {
                                // True slot
                                selectedDialog = dialog;
                                selectedSlotType = 1;
                            }
                            else if (dialog.Position.X + 116 > e.X && dialog.Position.Y + 96 - 8 > e.Y && dialog.Position.X + 116 < e.X + 32 && dialog.Position.Y + 96 - 8 < e.Y + 32)
                            {
                                // False slot
                                selectedDialog = dialog;
                                selectedSlotType = 2;
                            }
                            else if (dialog.Position.X + 48 > e.X && dialog.Position.Y + 64 > e.Y && dialog.Position.X + 48 < e.X + 32 && dialog.Position.Y + 64 < e.Y + 32)
                            {
                                // Input slot
                                selectedDialog = dialog;
                                selectedSlotType = 0;
                            }
                            else if (dialog.Position.X + 128 > e.X && dialog.Position.Y + 96 > e.Y && dialog.Position.X + 128 < e.X + 128 && dialog.Position.Y + 96 < e.Y + 96)
                            {
                                if (selectedDialog == null && !drawSelected) { selectedDialogForMove = dialog; }
                            }
                        }

                        // Actions
                        if (dialog.Type == Dialog.state.action)
                        {
                            if (dialog.Position.X + 112 > e.X && dialog.Position.Y + 64 - 16 > e.Y && dialog.Position.X + 112 < e.X + 32 && dialog.Position.Y + 64 - 16 < e.Y + 32)
                            {
                                // Input slot
                                selectedDialog = dialog;
                                selectedSlotType = 0;

                            }
                            else if (dialog.Position.X + 128 > e.X && dialog.Position.Y + 96 > e.Y && dialog.Position.X + 128 < e.X + 128 && dialog.Position.Y + 96 < e.Y + 96)
                            {
                                if (selectedDialog == null && !drawSelected) { selectedDialogForMove = dialog; }
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (MathF.placeFree(this, new Point(e.X, e.Y), comboBox1.SelectedIndex))
                {
                    Dialog d = new Dialog(new Point(e.X - (int)(128 * zoom) - cameraPosition.X, e.Y - (int)(64 * zoom) - cameraPosition.Y), dialogSize, "Test DIALOG ", "", comboBox1.SelectedIndex, Dialog.state.message, this);
                    d.Caption += d.Id.ToString();
                    d.Update(this);
                    dialogList.Add(d);
                }
                else
                {
                    editableDialog = MathF.instancePosition(this, new Point(e.X, e.Y));

                    if (editableDialog != null)
                    {
                        textBoxCaption.Text = editableDialog.Caption;
                        textBoxText.Text = editableDialog.Text;

                        if (editableDialog.Type == Dialog.state.condition)
                        {
                            textBoxText.Enabled = false;
                        }
                        else { textBoxText.Enabled = true; }
                    }
                }
            }

            if (e.Button == MouseButtons.Right)
            {
                if (mouseDownPosition == e.Location)
                {
                    contextMenuStrip1.Show(Cursor.Position);
                }
            }

            // Rotate item
            if (e.Button == MouseButtons.Middle)
            {
                if (mouseDownPosition == e.Location)
                {
                    if (editableDialog != null)
                    {
                        editableDialog.Rotation += 90;
                    }
                }
            }
        }
示例#6
0
        private void writeBranchTrue(Dialog d, int cl)
        {
            bool w = true;
            Dialog cdd = getNextDialog(d, 1);
            int complexLevel = cl;
            while (w)
            {
                if (cdd != null)
                {
                    if (d.Type == Dialog.state.condition)
                    {
                        for (int i = 0; i < complexLevel; i++)
                        {
                            Debug.Write(" ");
                        }
                        Debug.WriteLine("else");
                        for (int i = 0; i < complexLevel; i++)
                        {
                            Debug.Write(" ");
                        }
                        Debug.WriteLine("{");
                        bracketsToAdd++;

                        complexLevel++;

                        if (cdd.Type != Dialog.state.condition)
                        {
                            Debug.WriteLine("statement" + cdd.Id);
                        }

                        writeBranch(cdd, complexLevel);
                        w = false;
                    }

                    cdd = getNextDialog(d, 1);
                }

                if (cdd == null) { for (int i = 0; i < 1; i++) { Debug.WriteLine("}"); } w = false; }
            }
        }