Ejemplo n.º 1
0
        /// <summary>
        /// Called when the user has started to drag out a connector, thus creating a new connection.
        /// </summary>
        public ConnectionViewModel ConnectionDragStarted(ConnectorViewModel draggedOutConnector, Point curDragPoint)
        {
            if (draggedOutConnector.AttachedConnections.Count > 0)
            {
                Debug.Assert(draggedOutConnector.AttachedConnections.Count == 1);
                //
                // There is an existing connection attached to the connector that has been dragged out.
                // Remove the existing connection from the view-model.
                //
                DlgModel.Network.Connections.Remove(draggedOutConnector.AttachedConnections[0]);
            }

            //
            // Create a new connection to add to the view-model.
            //
            var connection = new ConnectionViewModel(_cmdExec, draggedOutConnector.DialogueChoice)
            {
                //
                // Link the source connector to the connector that was dragged out.
                //
                SourceConnector = draggedOutConnector,

                //
                // Set the position of destination connector to the current position of the mouse cursor.
                //
                DestConnectorHotspot = curDragPoint
            };

            //
            // Add the new connection to the view-model.
            //
            DlgModel.Network.Connections.Add(connection);

            return(connection);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called as the user continues to drag the connection.
 /// </summary>
 public void ConnectionDragging(ConnectionViewModel connection, Point curDragPoint)
 {
     //
     // Update the destination connection hotspot while the user is dragging the connection.
     //
     connection.DestConnectorHotspot = curDragPoint;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the user has finished dragging out the new connection.
        /// </summary>
        public void ConnectionDragCompleted(ConnectionViewModel newConnection, ConnectorViewModel connectorDraggedOut, ConnectorViewModel connectorDraggedOver)
        {
            if (connectorDraggedOver == null ||
                connectorDraggedOut.IsChoice == connectorDraggedOver.IsChoice ||
                connectorDraggedOut.ParentNode == connectorDraggedOver.ParentNode)
            {
                //
                // The connection was unsuccessful.
                // Maybe the user dragged it out and dropped it in empty space.
                //
                DlgModel.Network.Connections.Remove(newConnection);
                return;
            }

            //
            // Finalize the connection by attaching it to the connector
            // that the user dropped the connection on.
            //
            newConnection.DestConnector = connectorDraggedOver;
        }
Ejemplo n.º 4
0
        public NetworkViewModel(CommandExecutor cmdExe, Dialogue dialogue)
        {
            _dialogue = dialogue;
            _cmdExec = cmdExe;

            if (_dialogue == null)
            {
                Debug.Assert(false);
                return;
            }

            var entryToModel = new Dictionary<DialogueEntry, NodeViewModel>();

            for (int i = 0; i < _dialogue.NumEntries; ++i)
            {
                DialogueEntry entry = _dialogue.Entry(i);
                if (entry != null)
                {
                    var model = new NodeViewModel(cmdExe, entry, _dialogue, this);
                    Nodes.Add(model);

                    entryToModel.Add(entry, model);
                }
            }

            for (int i = 0; i < _dialogue.NumChoices; ++i)
            {
                DialogueChoice choice = _dialogue.Choice(i);
                if (choice != null)
                {
                    var connection = new ConnectionViewModel(cmdExe, choice);
                    Connections.Add(connection);

                    if (choice.SourceEntry != null && choice.DestinationEntry != null)
                    {
                        NodeViewModel srcNode = entryToModel[choice.SourceEntry];
                        foreach (ConnectorViewModel connector in srcNode.OutgoingConnectors)
                        {
                            if (connector.DialogueChoice.Equals(choice))
                            {
                                connection.SourceConnector = connector;
                                break;
                            }
                        }

                        NodeViewModel dstNode = entryToModel[choice.DestinationEntry];
                        connection.DestConnector = dstNode.IncomingConnector;
                    }
                }
            }

            for (int i = 0; i < _dialogue.NumParticipants; ++i)
            {
                Participant participant = _dialogue.Participant(i);
                if (participant != null)
                {
                    var model = new ParticipantViewModel(cmdExe, participant, _dialogue);
                    Participants.Add(model);
                }
            }
        }
Ejemplo n.º 5
0
 public SetChoiceDestUndoableCommand(ConnectorViewModel destConnector, ConnectionViewModel connection, DialogueChoice choice)
 {
     _destConnector = destConnector;
     _connection    = connection;
     _choice        = choice;
 }