Exemple #1
0
        // Mouse down
        void EditBlueprintSocketsGraphics_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Hit test scraps
            BlueprintScrap target = null;

            for (int i = 0; i < _blueprint.scraps.Count; i++)
            {
                if (_blueprint.scraps[i].hitTest(_mouse - offset))
                {
                    target = _blueprint.scraps[i];
                    break;
                }
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (_view.selectedScrap == null)
                {
                    // Select scrap
                    _view.selectedScrap = target;
                }
                else
                {
                    // Place selected scrap
                    _view.selectedScrap = null;
                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (_view.socketTargetA == null)
                {
                    // Set first socket target
                    _view.socketTargetA = target;
                }
                else
                {
                    // Create socket on first target
                    Vector2         relativePoint = target.currentCraftPosition - _view.socketTargetA.currentCraftPosition;
                    BlueprintSocket firstSocket   = new BlueprintSocket(_view.socketTargetA, target, relativePoint);
                    _blueprint.sockets.Add(firstSocket);

                    // Create socket on second target
                    BlueprintSocket secondSocket = new BlueprintSocket(target, _view.socketTargetA, -relativePoint);
                    _blueprint.sockets.Add(secondSocket);

                    // Set opposing sockets
                    firstSocket.opposingSocket  = secondSocket;
                    secondSocket.opposingSocket = firstSocket;

                    // Form connection
                    _view.socketTargetA.connectScrap(target);
                    target.connectScrap(_view.socketTargetA);

                    // Clear socket target
                    _view.socketTargetA = null;
                }
            }
        }
Exemple #2
0
        public EditBlueprintScrapShape(BlueprintView view, BlueprintScrap scrap)
        {
            _view = view;
            //_textureCenter = new Vector2(_texture.Width, _texture.Height) / 2;
            _scrap  = scrap;
            _points = new List <Vector2>(_scrap.points);

            InitializeComponent();

            // Set scrap texture
            editBlueprintScrapShapeGraphics.setTexture(scrap.scrapTextureUID);
        }
        // createBlueprintScrap
        public BlueprintScrap createBlueprintScrap(Blueprint blueprint, string uid)
        {
            // Check unsaved resources
            if (isUnsavedResourceUsed(uid))
            {
                System.Windows.Forms.MessageBox.Show(String.Format("An unsaved resource with the uid [{0}] already exists.", uid), "Blueprint Error", System.Windows.Forms.MessageBoxButtons.OK);
                return(null);
            }

            BlueprintScrap scrap = new BlueprintScrap(uid);

            blueprint.scraps.Add(scrap);
            return(scrap);
        }
        // removeBlueprintScrap
        public void removeBlueprintScrap(EditorBlueprint blueprint, string uid)
        {
            BlueprintScrap scrapToRemove = null;

            foreach (BlueprintScrap scrap in blueprint.scraps)
            {
                if (scrap.uid == uid)
                {
                    scrapToRemove = scrap;
                    break;
                }
            }

            System.Diagnostics.Debug.Assert(scrapToRemove != null);

            blueprint.scraps.Remove(scrapToRemove);
        }
        // Add blueprint scrap
        private void addScrapButton_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.Assert(selectedBlueprint != null);

            CreateResourceView createResourceView = new CreateResourceView();

            if (createResourceView.ShowDialog() == DialogResult.OK)
            {
                BlueprintScrap scrap = _controller.createBlueprintScrap(selectedBlueprint, createResourceView.uid);
                scrapList.RefreshItems();

                if (scrap != null)
                {
                    selectBlueprintScrap(scrap);
                }
            }
        }
        // initializeBlueprint
        public EditorBlueprint initializeBlueprint(XElement data)
        {
            // Create scraps
            List <BlueprintScrap> scraps = new List <BlueprintScrap>();

            foreach (XElement childData in data.Elements("BlueprintScrap"))
            {
                scraps.Add(new EditorBlueprintScrap(childData));
            }

            // Create sockets
            List <BlueprintSocket> sockets = new List <BlueprintSocket>();

            foreach (XElement childData in data.Elements("Socket"))
            {
                // Find associated scraps
                BlueprintScrap scrapA = (from scrap in scraps
                                         where scrap.uid == childData.Attribute("scrap_a_uid").Value
                                         select scrap).First();
                BlueprintScrap scrapB = (from scrap in scraps
                                         where scrap.uid == childData.Attribute("scrap_b_uid").Value
                                         select scrap).First();

                sockets.Add(new BlueprintSocket(childData, scrapA, scrapB));
            }

            // Assign opposing sockets
            foreach (BlueprintSocket socket in sockets)
            {
                // Select the socket where this socket's scrapA is the other socket's scrapB
                socket.opposingSocket = (from oSocket in sockets
                                         where oSocket.scrapB == socket.scrapA
                                         select oSocket).First();

                System.Diagnostics.Debug.Assert(socket.opposingSocket != null);
            }

            // Create blueprint
            return(new EditorBlueprint(data, scraps, sockets));
        }
 // selectBlueprintScrap
 public void selectBlueprintScrap(BlueprintScrap scrap)
 {
     scrapList.SelectedIndex = selectedBlueprint.scraps.IndexOf(scrap);
 }