예제 #1
0
        public PaintToolsUI(CheatSheet mod)
        {
            categories.Clear();
            this.view          = new PaintToolsView();
            this.mod           = mod;
            this.CanMove       = true;
            base.Width         = this.view.Width + this.spacing * 2f;
            base.Height        = 35f + this.view.Height + this.spacing * 2f;
            this.view.Position = new Vector2(this.spacing, 55f);
            this.AddChild(this.view);

            Texture2D texture = mod.GetTexture("UI/closeButton");
            UIImage   uIImage = new UIImage(texture);

            uIImage.Anchor       = AnchorPosition.TopRight;
            uIImage.Position     = new Vector2(base.Width - this.spacing, this.spacing);
            uIImage.onLeftClick += new EventHandler(this.bClose_onLeftClick);
            this.AddChild(uIImage);

            var snaptexture = mod.GetTexture("UI/Snap");

            btnSnap = new UIImageListButton(
                (new ImageList(mod.GetTexture("UI/Snap"), 28, 28)).listTexture,
                new List <object>()
            {
                SnapType.TopLeft, SnapType.TopCenter, SnapType.TopRight,
                SnapType.LeftCenter, SnapType.Center, SnapType.RightCenter,
                SnapType.BottomLeft, SnapType.BottomCenter, SnapType.BottomRight,
            },
                new List <string>()
            {
                CSText("SnapTopLeft"), CSText("SnapTopCenter"), CSText("SnapTopRight"),
                CSText("SnapLeftCenter"), CSText("SnapCenter"), CSText("SnapRightCenter"),
                CSText("SnapBottomLeft"), CSText("SnapBottomCenter"), CSText("SnapBottomRight"),
            },
                4);
            btnSnap.onLeftClick  += (a, b) => btnSnap.NextIamge();
            btnSnap.onRightClick += (a, b) => btnSnap.PrevIamge();
            btnSnap.Position      = new Vector2(this.spacing, this.spacing);
            this.AddChild(btnSnap);

            var position = btnSnap.Position;

            uIImage              = new UIImage(Main.itemTexture[ItemID.TrashCan]);
            position             = position.Offset(btnSnap.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => view.RemoveSelectedItem();
            uIImage.Tooltip      = CSText("DeleteSelection");
            this.AddChild(uIImage);

            uIImage              = new UIImage(Main.itemTexture[ItemID.AlphabetStatueI]);
            position             = position.Offset(uIImage.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => PaintToolsEx.Import(this.view);
            uIImage.Tooltip      = CSText("ImportData");
            this.AddChild(uIImage);

            uIImage              = new UIImage(Main.itemTexture[ItemID.AlphabetStatueE]);
            position             = position.Offset(uIImage.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => PaintToolsEx.Export(this.view);
            uIImage.Tooltip      = CSText("ExportData");
            this.AddChild(uIImage);

            uIImage              = new UIImage(Main.itemTexture[ItemID.AlphabetStatueW]);
            position             = position.Offset(uIImage.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => PaintToolsEx.OnlineImport(this.view);
            uIImage.Tooltip      = "Load Online Schematics Database";
            this.AddChild(uIImage);

            infoPanel                 = new UIView();
            position                  = position.Offset(uIImage.Width + this.spacing, 0);
            infoPanel.Position        = position;
            infoPanel.Y               = 6;
            infoPanel.Width           = 210;
            infoPanel.Height          = 44;
            infoPanel.ForegroundColor = Color.Thistle;
            AddChild(infoPanel);

            infoMessage          = new UILabel("Message Here");
            infoMessage.Scale    = 0.35f;
            infoMessage.Position = new Vector2(30, 10);
            infoPanel.AddChild(infoMessage);

            upVoteButton              = new UIImage(CheatSheet.instance.GetTexture("UI/VoteUp"));
            upVoteButton.Position     = new Vector2(0, 0);
            upVoteButton.onLeftClick += (a, b) => Vote(true);
            upVoteButton.Tooltip      = "Vote Up";
            infoPanel.AddChild(upVoteButton);

            downVoteButton              = new UIImage(CheatSheet.instance.GetTexture("UI/VoteDown"));
            downVoteButton.Position     = new Vector2(0, 24);
            downVoteButton.onLeftClick += (a, b) => Vote(false);
            downVoteButton.Tooltip      = "Vote Down";
            infoPanel.AddChild(downVoteButton);

            infoPanel.Visible = false;

            submitPanel          = new UIView();
            submitPanel.Position = position;
            submitPanel.Y        = 6;
            submitPanel.Width    = 210;
            submitPanel.Height   = 44;
            AddChild(submitPanel);

            submitLabel          = new UILabel("Submit Name:");
            submitLabel.Scale    = 0.35f;
            submitLabel.Position = new Vector2(0, 0);
            submitPanel.AddChild(submitLabel);

            submitInput          = new UITextbox();
            submitInput.Position = new Vector2(0, 20);
            submitInput.Width    = 200;
            submitPanel.AddChild(submitInput);

            submitButton              = new UIImage(Terraria.Graphics.TextureManager.Load("Images/UI/ButtonCloudActive"));
            submitButton.Position     = new Vector2(178, -2);
            submitButton.onLeftClick += (a, b) => Submit();
            submitButton.Tooltip      = "Submit to Schematics Browser";
            submitPanel.AddChild(submitButton);

            submitPanel.Visible = false;
        }
예제 #2
0
        public void Update2()
        {
            Player player = Main.LocalPlayer;

            if (selected && (EyeDropperActive || StampToolActive))
            {
                //			player.mouseInterface = true;
                //			player.showItemIcon = true;
                if (EyeDropperActive)
                {
                    //		Main.LocalPlayer.showItemIconText = "Click to select pallete";
                    player.showItemIcon2 = ItemID.EmptyDropper;
                    if (leftMouseDown)
                    {
                        Point point = (Main.MouseWorld).ToTileCoordinates();
                        //Point point = (Main.MouseWorld + (brushSize % 2 == 0 ? Vector2.One * 8 : Vector2.Zero)).ToTileCoordinates();
                        //point.X -= brushSize / 2;
                        //point.Y -= brushSize / 2;
                        if (startTileX == -1)
                        {
                            startTileX     = point.X;
                            startTileY     = point.Y;
                            lastMouseTileX = -1;
                            lastMouseTileY = -1;
                        }

                        //if (lastMouseTileX != point.X && lastMouseTileY != point.Y)
                        {
                            //for (int x = 0; x < brushSize; x++)
                            //{
                            //	for (int y = 0; y < brushSize; y++)
                            //	{
                            //		if (WorldGen.InWorld(x + point.X, y + point.Y))
                            //		{
                            //			Tile target = Framing.GetTileSafely(x + point.X, y + point.Y);
                            //			BrushTiles[x, y].CopyFrom(target);
                            //			//	Main.NewText("{x}, {y}");
                            //		}
                            //	}
                            //}
                            lastMouseTileX = point.X;
                            lastMouseTileY = point.Y;
                        }
                    }
                    if (justLeftMouseDown)
                    {
                        if (startTileX != -1 && startTileY != -1 && lastMouseTileX != -1 && lastMouseTileY != -1)
                        {
                            Vector2 upperLeft  = new Vector2(Math.Min(startTileX, lastMouseTileX), Math.Min(startTileY, lastMouseTileY));
                            Vector2 lowerRight = new Vector2(Math.Max(startTileX, lastMouseTileX), Math.Max(startTileY, lastMouseTileY));

                            int minX = (int)upperLeft.X;
                            int maxX = (int)lowerRight.X + 1;
                            int minY = (int)upperLeft.Y;
                            int maxY = (int)lowerRight.Y + 1;

                            //ErrorLogger.Log(string.Format("JustDown2 {0} {1} {2} {3}", minX, minY, maxX, maxY));

                            StampTiles = new Tile[maxX - minX, maxY - minY];

                            for (int i = 0; i < maxX - minX; i++)
                            {
                                for (int j = 0; j < maxY - minY; j++)
                                {
                                    StampTiles[i, j] = new Tile();
                                }
                            }

                            for (int x = minX; x < maxX; x++)
                            {
                                for (int y = minY; y < maxY; y++)
                                {
                                    if (WorldGen.InWorld(x, y))
                                    //if (WorldGen.InWorld(x + point.X, y + point.Y))
                                    {
                                        Tile target = Framing.GetTileSafely(x, y);
                                        StampTiles[x - minX, y - minY].CopyFrom(target);
                                        //	Main.NewText("{x}, {y}");
                                    }
                                }
                            }
                            //Main.NewText("EyeDropper: width height" + (maxX - minX) + " " + (maxY - minY));
                            CheatSheet.instance.paintToolsUI.AddSlot(PaintToolsEx.GetStampInfo(StampTiles));
                        }
                        //Main.NewText("EyeDropper: x,y,min max " + minX + " " + maxX + " " + minY + " " + maxY);

                        startTileX        = -1;
                        startTileY        = -1;
                        lastMouseTileX    = -1;
                        lastMouseTileY    = -1;
                        justLeftMouseDown = false;
                    }
                }
                if (StampToolActive)
                {
                    player.showItemIcon2 = ItemID.Paintbrush;
                    //		Main.LocalPlayer.showItemIconText = "Click to paint";
                    if (leftMouseDown && stampInfo != null)
                    {
                        int width  = StampTiles.GetLength(0);
                        int height = StampTiles.GetLength(1);
                        //Vector2 brushsize = new Vector2(width, height);
                        //Vector2 evenOffset = Vector2.Zero;
                        //if (width % 2 == 0)
                        //{
                        //	evenOffset.X = 1;
                        //}
                        //if (height % 2 == 0)
                        //{
                        //	evenOffset.Y = 1;
                        //}
                        //Point point = (Main.MouseWorld + evenOffset * 8).ToTileCoordinates();
                        ////Point point = (Main.MouseWorld + (brushSize % 2 == 0 ? Vector2.One * 8 : Vector2.Zero)).ToTileCoordinates();
                        //point.X -= width / 2;
                        //point.Y -= height / 2;
                        ////Vector2 vector = new Vector2(point.X, point.Y) * 16f;
                        ////vector -= Main.screenPosition;
                        ////if (Main.LocalPlayer.gravDir == -1f)
                        ////{
                        ////	vector.Y = (float)Main.screenHeight - vector.Y - 16f;
                        ////}

                        Point point = Snap.GetSnapPosition(CheatSheet.instance.paintToolsUI.SnapType, width, height, constrainToAxis, constrainedX, constrainedY, true).ToPoint();

                        if (startTileX == -1)
                        {
                            startTileX     = point.X;
                            startTileY     = point.Y;
                            lastMouseTileX = -1;
                            lastMouseTileY = -1;
                        }

                        if (Main.keyState.IsKeyDown(Keys.LeftShift))
                        {
                            constrainToAxis = true;
                            if (constrainedStartX == -1 && constrainedStartY == -1)
                            {
                                constrainedStartX = point.X;
                                constrainedStartY = point.Y;
                            }

                            if (constrainedX == -1 && constrainedY == -1)
                            {
                                if (constrainedStartX != point.X)
                                {
                                    constrainedY = point.Y;
                                }
                                else if (constrainedStartY != point.Y)
                                {
                                    constrainedX = point.X;
                                }
                            }
                            if (constrainedX != -1)
                            {
                                point.X = constrainedX;
                            }
                            if (constrainedY != -1)
                            {
                                point.Y = constrainedY;
                            }
                        }
                        else
                        {
                            constrainToAxis   = false;
                            constrainedX      = -1;
                            constrainedY      = -1;
                            constrainedStartX = -1;
                            constrainedStartY = -1;
                        }

                        if (lastMouseTileX != point.X || lastMouseTileY != point.Y)
                        {
                            //Main.NewText("StartTileX " + startTileX);
                            for (int x = 0; x < width; x++)
                            {
                                for (int y = 0; y < height; y++)
                                {
                                    if (WorldGen.InWorld(x + point.X, y + point.Y) && StampTiles[x, y] != null)
                                    {
                                        Tile target  = Framing.GetTileSafely(x + point.X, y + point.Y);
                                        int  cycledX = ((x + point.X - startTileX) % width + width) % width;
                                        int  cycledY = ((y + point.Y - startTileY) % height + height) % height;
                                        if (TransparentSelectionEnabled)                                         // What about just walls?
                                        {
                                            if (StampTiles[cycledX, cycledY].active())
                                            {
                                                target.CopyFrom(StampTiles[cycledX, cycledY]);
                                            }
                                        }
                                        else
                                        {
                                            target.CopyFrom(StampTiles[cycledX, cycledY]);
                                        }
                                    }
                                }
                            }
                            if (Main.netMode == 1)
                            {
                                NetMessage.SendTileSquare(-1, point.X + width / 2, point.Y + height / 2, Math.Max(width, height));
                            }
                        }
                    }
                    else
                    {
                        startTileX        = -1;
                        startTileY        = -1;
                        constrainToAxis   = false;
                        constrainedX      = -1;
                        constrainedY      = -1;
                        constrainedStartX = -1;
                        constrainedStartY = -1;
                    }
                }
                Main.LocalPlayer.showItemIcon = true;
            }

            DoSlideMovement();

            base.CenterXAxisToParentCenter();
            base.Update();
        }
예제 #3
0
 private void Submit()
 {
     if (PaintToolsSlot.CurrentSelect == null)
     {
         return;
     }
     if (PaintToolsSlot.CurrentSelect.browserID == -1)
     {
         Main.NewText("Already submitted.");
         return;
     }
     if (PaintToolsSlot.CurrentSelect.browserID != 0)
     {
         return;
     }
     if (submitWait)
     {
         Main.NewText("Be patient.");
         return;
     }
     try
     {
         using (WebClient client = new WebClient())
         {
             var    steamIDMethodInfo = typeof(Main).Assembly.GetType("Terraria.ModLoader.ModLoader").GetProperty("SteamID64", BindingFlags.Static | BindingFlags.NonPublic);
             string steamid64         = (string)steamIDMethodInfo.GetValue(null, null);
             string base64tiles       = PaintToolsEx.SaveTilesToBase64(PaintToolsSlot.CurrentSelect.stampInfo.Tiles);
             if (string.IsNullOrEmpty(base64tiles))
             {
                 Main.NewText("Oops, base64tiles is bad.");
             }
             else if (string.IsNullOrEmpty(submitInput.Text))
             {
                 Main.NewText("Please name your creation.");
             }
             else if (base64tiles.Length > 5000)
             {
                 Main.NewText("Selection too big for now.");
             }
             else
             {
                 submitWait = true;
                 var values = new NameValueCollection
                 {
                     { "version", CheatSheet.instance.Version.ToString() },
                     { "steamid64", steamid64 },
                     { "name", submitInput.Text },
                     { "tiledata", base64tiles },
                 };
                 PaintToolsSlot.CurrentSelect.browserID = -1;
                 CheatSheet.instance.paintToolsUI.submitPanel.Visible = false;
                 client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(SubmitComplete);
                 client.UploadValuesAsync(submiturl, "POST", values);
             }
         }
     }
     catch
     {
         Main.NewText("Schematics Server problem 5");
         submitWait = false;
     }
 }
예제 #4
0
        public PaintToolsUI(Mod mod)
        {
            categories.Clear();
            this.view          = new PaintToolsView();
            this.mod           = mod;
            this.CanMove       = true;
            base.Width         = this.view.Width + this.spacing * 2f;
            base.Height        = 35f + this.view.Height + this.spacing * 2f;
            this.view.Position = new Vector2(this.spacing, 55f);
            this.AddChild(this.view);

            Texture2D texture = mod.GetTexture("UI/closeButton");
            UIImage   uIImage = new UIImage(texture);

            uIImage.Anchor       = AnchorPosition.TopRight;
            uIImage.Position     = new Vector2(base.Width - this.spacing, this.spacing);
            uIImage.onLeftClick += new EventHandler(this.bClose_onLeftClick);
            this.AddChild(uIImage);

            var snaptexture = mod.GetTexture("UI/Snap");

            btnSnap = new UIImageListButton(
                (new ImageList(mod.GetTexture("UI/Snap"), 28, 28)).listTexture,
                new List <object>()
            {
                SnapType.TopLeft, SnapType.TopCenter, SnapType.TopRight,
                SnapType.LeftCenter, SnapType.Center, SnapType.RightCenter,
                SnapType.BottomLeft, SnapType.BottomCenter, SnapType.BottomRight,
            },
                new List <string>()
            {
                CSText("SnapTopLeft"), CSText("SnapTopCenter"), CSText("SnapTopRight"),
                CSText("SnapLeftCenter"), CSText("SnapCenter"), CSText("SnapRightCenter"),
                CSText("SnapBottomLeft"), CSText("SnapBottomCenter"), CSText("SnapBottomRight"),
            },
                4);
            btnSnap.onLeftClick  += (a, b) => btnSnap.NextIamge();
            btnSnap.onRightClick += (a, b) => btnSnap.PrevIamge();
            btnSnap.Position      = new Vector2(this.spacing, this.spacing);
            this.AddChild(btnSnap);

            var position = btnSnap.Position;

            uIImage              = new UIImage(Main.itemTexture[ItemID.TrashCan]);
            position             = position.Offset(btnSnap.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => view.RemoveSelectedItem();
            uIImage.Tooltip      = CSText("DeleteSelection");
            this.AddChild(uIImage);

            uIImage              = new UIImage(Main.itemTexture[ItemID.AlphabetStatueI]);
            position             = position.Offset(uIImage.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => PaintToolsEx.Import(this.view);
            uIImage.Tooltip      = CSText("ImportData");
            this.AddChild(uIImage);

            uIImage              = new UIImage(Main.itemTexture[ItemID.AlphabetStatueE]);
            position             = position.Offset(uIImage.Width + this.spacing, 0);
            uIImage.Position     = position;
            uIImage.onLeftClick += (a, b) => PaintToolsEx.Export(this.view);
            uIImage.Tooltip      = CSText("ExportData");
            this.AddChild(uIImage);
        }