Example #1
0
        private void Slot_OnNextPage(UIEditor.UILib.Events.UIMouseEvent e, UIElement sender)
        {
            UISlotNode slot = (UISlotNode)sender;
            var        rect = slot.AdjustedRectangleScreen;

            MainState.RecipeGraph.Canvas.ChangePage(slot.Slot.ItemType, slot.Page + 1, rect.TopLeft() + rect.Size() * slot.Pivot);
        }
Example #2
0
 private void Slot_OnClick(UIEditor.UILib.Events.UIMouseEvent e, UIElement sender)
 {
     if (_lastSelected != null)
     {
         _removeTag(_lastSelected);
     }
     _lastSelected = (UISlotNode)sender;
     _addTag(_lastSelected);
 }
Example #3
0
 private void _addTag(UISlotNode node)
 {
     while (node != null)
     {
         node.InPath          = true;
         node.Slot.IsSelected = true;
         node = node.SlotParent;
     }
 }
Example #4
0
 private void _removeTag(UISlotNode node)
 {
     while (node != null)
     {
         node.InPath          = false;
         node.Slot.IsSelected = false;
         node = node.SlotParent;
     }
 }
Example #5
0
        private void _dfsDraw(SpriteBatch sb, UISlotNode node)
        {
            if (node.SlotChildren.Count == 0)
            {
                return;
            }
            var   tex   = RecipeGraph.Instance.GetTexture("Images/White");
            var   first = node.SlotChildren.FirstOrDefault();
            float Ydis  = (first.Position.Y - node.Position.Y) / 2;
            bool  flag  = node.InPath;

            if (node.SlotChildren.Count > 1)
            {
                sb.Draw(tex, node.Position,
                        null, Color.White, 0f, new Vector2(0.5f, 0f), new Vector2(LineWidth, Ydis), SpriteEffects.None, 0f);
                var last = node.SlotChildren.LastOrDefault();
                sb.Draw(tex, new Vector2(first.Position.X - LineWidth / 2, first.Position.Y - Ydis),
                        null, Color.White, 0f, new Vector2(0f, 0.5f), new Vector2(last.Position.X - first.Position.X + LineWidth, LineWidth), SpriteEffects.None, 0f);
                foreach (var child in node.SlotChildren)
                {
                    //Vector2 dif = child.Position - node.Position;
                    sb.Draw(tex, new Vector2(child.Position.X, child.Position.Y - Ydis),
                            null, Color.White, 0f, new Vector2(0.5f, 0f), new Vector2(LineWidth, Ydis), SpriteEffects.None, 0f);
                    // sb.Draw(Main.magicPixel, node.Position, new Rectangle(0, 0, 1, 1), Color.White, dif.ToRotation(), new Vector2(0, 0.5f), new Vector2(dif.Length(), 2f), SpriteEffects.None, 0f);
                    _dfsDraw(sb, child);
                }
                foreach (var child in node.SlotChildren)
                {
                    if (flag && child.InPath)
                    {
                        int s = child.Position.X < node.Position.X ? -1 : 1;
                        sb.Draw(tex, node.Position,
                                null, PathColor, 0f, new Vector2(0.5f, 0f), new Vector2(LineWidth, Ydis), SpriteEffects.None, 0f);
                        sb.Draw(tex, new Vector2(node.Position.X - LineWidth / 2 * s, first.Position.Y - Ydis),
                                null, PathColor, 0f, new Vector2(0f, 0.5f), new Vector2(child.Position.X - node.Position.X + LineWidth * s, LineWidth), SpriteEffects.None, 0f);
                        sb.Draw(tex, new Vector2(child.Position.X, child.Position.Y - Ydis),
                                null, PathColor, 0f, new Vector2(0.5f, 0f), new Vector2(LineWidth, Ydis), SpriteEffects.None, 0f);
                        break;
                    }
                }
            }
            else
            {
                sb.Draw(tex, node.Position,
                        null, (flag && first.InPath) ? PathColor : Color.White, 0f, new Vector2(0.5f, 0f), new Vector2(3, first.Position.Y - node.Position.Y), SpriteEffects.None, 0f);
                _dfsDraw(sb, first);
            }
        }
Example #6
0
        public UISlotNode(int type, UISlotNode parent, int page, int maxPage) : base()
        {
            SlotParent   = parent;
            InPath       = false;
            MaxPage      = maxPage;
            Page         = page;
            SlotChildren = new List <UISlotNode>();
            Slot         = new UIItemSlot()
            {
                ItemType    = type,
                ItemStack   = 1,
                AnchorPoint = new Vector2(0.5f, 0.5f),
            };

            _label = new UILabel()
            {
                Text        = $"{Page}/{MaxPage}",
                Pivot       = new Vector2(0.5f, 1f),
                AnchorPoint = new Vector2(0.5f, 1f),
                IsActive    = MaxPage > 0,
                NoEvent     = true,
                Scale       = new Vector2(0.9f, 0.9f),
            };
            AppendChild(Slot);
            AppendChild(_label);
            if (maxPage > 1)
            {
                var buttonL = new UIImageButton()
                {
                    Texture     = RecipeGraph.Instance.GetTexture("Images/ArrowSmallLeft"),
                    Pivot       = new Vector2(0, 0.5f),
                    AnchorPoint = new Vector2(0, 0.5f),
                    Scale       = new Vector2(0.5f, 1f),
                };
                buttonL.OnClick += ButtonL_OnClick;
                AppendChild(buttonL);
                var buttonR = new UIImageButton()
                {
                    Texture     = RecipeGraph.Instance.GetTexture("Images/ArrowSmallRight"),
                    Pivot       = new Vector2(1, 0.5f),
                    AnchorPoint = new Vector2(1, 0.5f),
                    Scale       = new Vector2(0.5f, 1f),
                };
                buttonR.OnClick += ButtonR_OnClick;
                AppendChild(buttonR);
            }
        }
Example #7
0
        internal void ResetTree(int type, int childtype = 0)
        {
            _offspringTree = RecipeGraph.Instance.Graph.FindOffspring(type);
            Main.NewText(childtype);
            if (childtype != 0)
            {
                _offspringTree.TryFindPage(type, childtype);
            }
            var size = _offspringTree.Calculate();

            _treeMap.SizeFactor = new Vector2(0, 0);
            Vector2 realSize = new Vector2(Math.Max(Width, size.X), Math.Max(Height, size.Y));

            _treeMap.Size        = realSize;
            _treeMap.AnchorPoint = new Vector2(0.5f, 0f);
            _treeMap.Pivot       = new Vector2(0.5f, 0f);
            _treeMap.Position    = new Vector2(0, 0);
            _treeMap.Children.Clear();
            var        slots      = _offspringTree.GetSlots();
            UISlotNode targetnode = null;

            if (childtype != 0)
            {
                foreach (var slot in slots)
                {
                    if (slot.Slot.ItemType == childtype)
                    {
                        targetnode = slot;
                        break;
                    }
                }
            }
            _treeMap.AddNodes(slots);
            if (targetnode != null)
            {
                targetnode.MouseLeftClick(new UIMouseEvent(this, new TimeSpan(), new Vector2()));
            }
            _scale = 0;
            float s = (float)Math.Exp(_scale);

            _treeMap.Scale = new Vector2(s, s);
        }