Пример #1
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            var btnDown = e.Button == MouseButton.Left;

            if (!ClientRectangle.Contains(e.Position) && !btnDown)
            {
                _holding = null;
                return;
            }
            if (!btnDown || _holding == null)
            {
                return;
            }

            if (_trashEntity != null && _trashEntity.MouseOver)
            {
                _elementEntities.Remove(_holding);
            }

            if (GetTopElementAtPoint(new PointF(_holding.X, _holding.Y), _holding) is ElementEntity ee)
            {
                var products = ElementRegistry.GetProducts(ee.Element, _holding.Element);

                var max = ElementEntity.ElementIconSize / 2;

                foreach (var product in products)
                {
                    if (product == null)
                    {
                        continue;
                    }

                    var middleX = (_holding.X + ee.X) / 2;
                    var middleY = (_holding.Y + ee.Y) / 2;

                    _elementEntities.Remove(_holding);
                    _elementEntities.Remove(ee);

                    middleX += max - (float)_rand.NextDouble() * max * 2;
                    middleY += max - (float)_rand.NextDouble() * max * 2;

                    LearnElement(product);

                    SpawnElementEntity(middleX, middleY, product);
                }

                if (products.Length > 0)
                {
                    if (_learntElements.Count == ElementRegistry.GetTotalCount())
                    {
                        _toastQueue.Add(new AchievementToast("That's it!", "You know everything!", TextureManager.GetOrRegister("obsidian"), this));
                    }
                }
            }

            _holding = null;
        }
Пример #2
0
        private ElementEntity GetTopElementAtPoint(PointF p, ElementEntity except = null)
        {
            for (var index = _elementEntities.Count - 1; index >= 0; index--)
            {
                var entity = _elementEntities[index];

                if (entity != except && entity.IsMouseOver(p))
                {
                    return(entity);
                }
            }

            return(null);
        }
Пример #3
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (e.Button != MouseButton.Left || _holding != null || !ClientRectangle.Contains(e.Position))
            {
                return;
            }

            if (_inventoryGui != null && _inventoryGui.IsShown())
            {
                var picked = _inventoryGui.PickElement(e.X, e.Y);

                if (picked != null)
                {
                    _holding     = new ElementEntity(e.X, e.Y, picked);
                    _clickOffset = new PointF();

                    _elementEntities.Add(_holding);
                }

                return;
            }

            //double click, clone double clicked item
            if (_clicks >= 1)
            {
                _clicks = 0;
                _doubleClickTimer.Stop();

                if (GetTopElementAtPoint(e.Position) is ElementEntity entity && _lastClicked == entity)
                {
                    _clickOffset = new PointF();
                    _holding     = new ElementEntity(e.X, e.Y, entity.Element);

                    _elementEntities.Add(_holding);
                }
                if (_lastClicked == null)
                {
                    AddBaseElements(e.Position);
                }

                return;
            }

            _clicks++;

            _doubleClickTimer.Interval = _doubleClickTimer.Interval = SystemInformation.DoubleClickTime / 2;
            _doubleClickTimer.Start();

            if (_elementEntities.Count > 0 && GetTopElementAtPoint(e.Position) is ElementEntity top)
            {
                _clickOffset = new PointF(top.X - e.X, top.Y - e.Y);

                _lastClicked = _holding = top;

                _elementEntities.Remove(_holding);
                _elementEntities.Add(_holding);
            }
            else
            {
                _lastClicked = null;
            }
        }