Terraria.UI.ChestUI.RenameChest C# (CSharp) Method

RenameChest() public static method

public static RenameChest ( ) : void
return void
        public static void RenameChest()
        {
            Player player = Main.player[Main.myPlayer];
            if (!Main.editChest)
            {
                Main.npcChatText = Main.chest[player.chest].name;
                if ((int)Main.tile[player.chestX, player.chestY].type == 21)
                    Main.defaultChestName = Lang.chestType[(int)Main.tile[player.chestX, player.chestY].frameX / 36];
                if ((int)Main.tile[player.chestX, player.chestY].type == 88)
                    Main.defaultChestName = Lang.dresserType[(int)Main.tile[player.chestX, player.chestY].frameX / 54];
                if (Main.npcChatText == "")
                    Main.npcChatText = Main.defaultChestName;
                Main.editChest = true;
                Main.clrInput();
            }
            else
            {
                Main.PlaySound(12, -1, -1, 1);
                Main.editChest = false;
                int index = player.chest;
                if (Main.npcChatText == Main.defaultChestName)
                    Main.npcChatText = "";
                if (!(Main.chest[index].name != Main.npcChatText))
                    return;
                Main.chest[index].name = Main.npcChatText;
                if (Main.netMode != 1)
                    return;
                player.editedChestName = true;
            }
        }

Usage Example

Ejemplo n.º 1
0
        private static void DrawButton(SpriteBatch spriteBatch, int ID, int X, int Y)
        {
            Player player = Main.player[Main.myPlayer];

            if (ID == 4 && player.chest < -1 || ID == 5 && !Main.editChest)
            {
                ChestUI.UpdateHover(ID, false);
            }
            else
            {
                Y += ID * 26;
                float  num  = ChestUI.ButtonScale[ID];
                string text = "";
                switch (ID)
                {
                case 0:
                    text = Lang.inter[29];
                    break;

                case 1:
                    text = Lang.inter[30];
                    break;

                case 2:
                    text = Lang.inter[31];
                    break;

                case 3:
                    text = Lang.inter[82];
                    break;

                case 4:
                    text = Lang.inter[Main.editChest ? 47 : 61];
                    break;

                case 5:
                    text = Lang.inter[63];
                    break;
                }
                Vector2 vector2   = Main.fontMouseText.MeasureString(text);
                Color   color     = new Color((int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor) * num;
                Color   baseColor = Color.White * 0.97f * (float)(1.0 - ((double)byte.MaxValue - (double)Main.mouseTextColor) / (double)byte.MaxValue * 0.5);
                baseColor.A = byte.MaxValue;
                X          += (int)((double)vector2.X * (double)num / 2.0);
                ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, text, new Vector2((float)X, (float)Y), baseColor, 0.0f, vector2 / 2f, new Vector2(num), -1f, 1.5f);
                vector2 *= num;
                if (!Utils.FloatIntersect((float)Main.mouseX, (float)Main.mouseY, 0.0f, 0.0f, (float)X - vector2.X / 2f, (float)Y - vector2.Y / 2f, vector2.X, vector2.Y))
                {
                    ChestUI.UpdateHover(ID, false);
                }
                else
                {
                    ChestUI.UpdateHover(ID, true);
                    player.mouseInterface = true;
                    if (!Main.mouseLeft || !Main.mouseLeftRelease)
                    {
                        return;
                    }
                    switch (ID)
                    {
                    case 0:
                        ChestUI.LootAll();
                        break;

                    case 1:
                        ChestUI.DepositAll();
                        break;

                    case 2:
                        ChestUI.QuickStack();
                        break;

                    case 3:
                        ChestUI.Restock();
                        break;

                    case 4:
                        ChestUI.RenameChest();
                        break;

                    case 5:
                        ChestUI.RenameChestCancel();
                        break;
                    }
                    Recipe.FindRecipes();
                }
            }
        }