public void RedrawImages()
        {
            var dimg = (UIImage)this.GetComponentByPath("DragImage");

            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 5; i++)
                {
                    var n     = (i + j * 5).ToString();
                    var imgn2 = (UIImage)this.GetComponentByPath("Window 2\\" + n);
                    imgn2.SourceImage = dimg.SourceImage;
                }
            }

            for (int i = 0; i < 5; i++)
            {
                var n1      = (i).ToString();
                var imgn1   = (UIImage)this.GetComponentByPath("Window 1\\" + n1);
                var impath1 = InvUtils.getImagePath(SimulationApp.PlayerInv, i);
                //if(impath1 != null && impath1 != "") {
                //	imgn1.SourceImage = ReferenceUtility.MakeReference<Component_Image>(impath1);
                //} else {
                imgn1.SourceImage = dimg.SourceImage;
                //}
            }
        }
        private void mouseDown(NeoAxis.UIControl sender, NeoAxis.EMouseButtons button)
        {
            if (!drag)
            {
                drag       = true;
                dragparent = (UIWindow)sender.Parent;
                windFrom   = dragparent.Name;
                indxFrom   = sender.Name;
                ScreenMessages.Add("windFrom = " + windFrom + ", indxFrom = " + indxFrom);
                var imagePath = InvUtils.getImagePath(SimulationApp.PlayerInv, int.Parse(indxFrom));
                showdimg((UIImage)sender, true, imagePath);


                dragsx = MousePosition.X;
                dragsy = MousePosition.Y;
                dragox = dragsx - ((UIImage)sender).GetScreenPosition().X;
                dragoy = dragsy - ((UIImage)sender).GetScreenPosition().Y;

                //ScreenMessages.Add("MouseDown " + dragsx + ", " + dragsy + ", " + sender.GetPathFromRoot());
            }
            else
            {
                indxTo = sender.Name;
                windTo = sender.Parent?.Name;
                ScreenMessages.Add("windTo = " + windTo + ", indxTo = " + indxTo);

                if (windFrom == "Window 1" && windTo == "Window 1" && indxFrom != "" && indxTo != "")
                {
                    /*var prevName = SimulationApp.PlayerInv.items[int.Parse(indxFrom)].Name;
                     * var prevcur = SimulationApp.PlayerInv.items[int.Parse(indxFrom)].Current;
                     * var res1 = InvUtils.GetItems(SimulationApp.PlayerInv, SimulationApp.PlayerInv.items[int.Parse(indxFrom)].Name, int.Parse(indxFrom), SimulationApp.PlayerInv.items[int.Parse(indxFrom)].Current);
                     * if(res1 >= 0) {
                     *      var res2 = InvUtils.AddItems(SimulationApp.PlayerInv, prevName, int.Parse(indxTo), prevcur);
                     * }*/
                    var res = InvUtils.tryMoveItems(SimulationApp.PlayerInv, int.Parse(indxFrom), int.Parse(indxTo));
                    if (res >= 0)
                    {
                        var res1 = InvUtils.MoveItems(SimulationApp.PlayerInv, int.Parse(indxFrom), int.Parse(indxTo));
                    }
                }

                windFrom = "";
                windTo   = "";
                indxFrom = "";
                indxTo   = "";

                showdimg((UIImage)sender, false, "");
                dragparent = null;
                drag       = false;
                RedrawImages();
                //ScreenMessages.Add("MouseDown1" + ", " + sender.GetPathFromRoot());
            }
        }
Esempio n. 3
0
        public void CalcInitialItems()
        {
            if (CalcInitialItemsDone)
            {
                return;
            }
            CalcInitialItemsDone = true;
            int indx = 0;

            foreach (var item in InitialItems)
            {
                String[] itemParams = InvUtils.splitStr(item);
                items.Add(new InvItem(itemParams[0], indx, int.Parse(itemParams[1]), CellMaxItems));
                LastIndex = indx;
                indx      = indx + 1;
            }
            log(this.Name + " CalcInitialItems done");
        }
        public void showdimg(NeoAxis.UIImage img, bool show, String imagePath)
        {
            var dimg = (UIImage)this.GetComponentByPath("DragImage");

            if (show)
            {
                dragimg          = img;
                dimg.Margin      = cpos;
                dimg.SourceImage = ReferenceUtility.MakeReference <Component_Image>(imagePath);
                dimg.Enabled     = true;
                //ScreenMessages.Add("showdimg true, " + img?.GetPathFromRoot());
            }
            else
            {
                dragimg     = null;
                dimg.Margin = cpos;
                var imagePath1 = InvUtils.getImagePath(SimulationApp.PlayerInv, "Empty");
                dimg.SourceImage = ReferenceUtility.MakeReference <Component_Image>(imagePath1);
                dimg.Enabled     = false;
                //ScreenMessages.Add("showdimg false, " + img?.GetPathFromRoot());
            }
        }
        protected override void OnEnabledInSimulation()
        {
            var dimg = (UIImage)this.GetComponentByPath("DragImage");

            cpos = dimg.Margin.Value;

            var img1 = (UIImage)(this.GetComponentByPath("Window 1\\0"));

            img1.MouseDown += Image_MouseDown1;
            img1.MouseUp   += Image_MouseUp1;
            img1.MouseMove += Image_MouseMove1;
            var impath = InvUtils.getImagePath(SimulationApp.PlayerInv, 0);

            if (impath != null && impath != "")
            {
                img1.SourceImage = ReferenceUtility.MakeReference <Component_Image>(impath);
            }
            else
            {
                img1.SourceImage = dimg.SourceImage;
            }


            var img2 = (UIImage)(this.GetComponentByPath("Window 2\\0"));

            img2.MouseDown += Image_MouseDown2;
            img2.MouseUp   += Image_MouseUp2;
            img2.MouseMove += Image_MouseMove2;

            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (!((i == 0) && (j == 0)))
                    {
                        var imgn2 = (UIImage)img2.Clone();
                        imgn2.Name    = (i + j * 5).ToString();
                        imgn2.Enabled = true;
                        var pos1 = img2.Margin.Value;
                        pos1.Left         = pos1.Left + i * (img2.Size.Value.X + 10);
                        pos1.Top          = pos1.Top + j * (img2.Size.Value.Y + 10);
                        imgn2.Margin      = pos1;
                        imgn2.MouseDown  += Image_MouseDown2;
                        imgn2.MouseUp    += Image_MouseUp2;
                        imgn2.MouseMove  += Image_MouseMove2;
                        imgn2.SourceImage = dimg.SourceImage;
                        img2.Parent.AddComponent(imgn2);
                    }
                }
            }

            for (int i = 1; i < 5; i++)
            {
                var imgn1 = (UIImage)img1.Clone();
                imgn1.Name    = (i).ToString();
                imgn1.Enabled = true;
                var pos = img1.Margin.Value;
                pos.Left         = pos.Left + i * (img1.Size.Value.X + 10);
                imgn1.Margin     = pos;
                imgn1.MouseDown += Image_MouseDown1;
                imgn1.MouseUp   += Image_MouseUp1;
                imgn1.MouseMove += Image_MouseMove1;

                var impath1 = InvUtils.getImagePath(SimulationApp.PlayerInv, i);
                if (impath1 != null && impath1 != "")
                {
                    imgn1.SourceImage = ReferenceUtility.MakeReference <Component_Image>(impath1);
                }
                else
                {
                    imgn1.SourceImage = dimg.SourceImage;
                }
                img1.Parent.AddComponent(imgn1);
            }



            base.OnEnabledInSimulation();
        }