context: using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Input;
  using System;
  namespace Terraria
  {
  	public static class IngameOptions
  	{
  		public const int width = 670;
  		public const int height = 480;
  		public static float[] leftScale = new float[]
  		{
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f
  		};
  		public static float[] rightScale = new float[]
  		{
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f,
  			0.7f
  		};
  		public static int leftHover = -1;
  		public static int rightHover = -1;
  		public static int oldLeftHover = -1;
  		public static int oldRightHover = -1;
  		public static int rightLock = -1;
  		public static bool inBar = false;
  		public static bool notBar = false;
  		public static bool noSound = false;
  		public static int category = 0;
  		public static Vector2 valuePosition = Vector2.Zero;
  		public static void Open()
  		{
  			Main.playerInventory = false;
  			Main.editChest = false;
  			Main.npcChatText = "";
  			Main.PlaySound(10, -1, -1, 1);
  			Main.ingameOptionsWindow = true;
  			IngameOptions.category = 0;
  			for (int i = 0; i < IngameOptions.leftScale.Length; i++)
  			{
  				IngameOptions.leftScale[i] = 0f;
  			}
  		}
  		public static void Close()
  		{
  			if (Main.setKey != -1)
  			{
  				return;
  			}
  			Main.SaveSettings();
  			Main.ingameOptionsWindow = false;
  			Main.PlaySound(11, -1, -1, 1);
  			Recipe.FindRecipes();
  			Main.playerInventory = true;
  		}
  		public static void Draw(Main mainInstance, SpriteBatch sb)
  		{
  			if (Main.player[Main.myPlayer].dead && !Main.player[Main.myPlayer].ghost)
  			{
  				Main.setKey = -1;
  				IngameOptions.Close();
  				Main.playerInventory = false;
  				return;
  			}
  			new Vector2((float)Main.mouseX, (float)Main.mouseY);
  			bool flag = Main.mouseLeft && Main.mouseLeftRelease;
  			Vector2 value = new Vector2((float)Main.screenWidth, (float)Main.screenHeight);
  			Vector2 value2 = new Vector2(670f, 480f);
  			Vector2 value3 = value / 2f - value2 / 2f;
  			int num = 20;
  			Utils.DrawInvBG(sb, value3.X - (float)num, value3.Y - (float)num, value2.X + (float)(num * 2), value2.Y + (float)(num * 2), new Color(33, 15, 91, 255) * 0.685f);
  			if (new Rectangle((int)value3.X - num, (int)value3.Y - num, (int)value2.X + num * 2, (int)value2.Y + num * 2).Contains(new Point(Main.mouseX, Main.mouseY)))
  			{
  				Main.player[Main.myPlayer].mouseInterface = true;
  			}
  			Utils.DrawInvBG(sb, value3.X + (float)(num / 2), value3.Y + (float)(num * 5 / 2), value2.X / 2f - (float)num, value2.Y - (float)(num * 3), default(Color));
  			Utils.DrawInvBG(sb, value3.X + value2.X / 2f + (float)num, value3.Y + (float)(num * 5 / 2), value2.X / 2f - (float)(num * 3 / 2), value2.Y - (float)(num * 3), default(Color));
  			Utils.DrawBorderString(sb, "Settings Menu", value3 + value2 * new Vector2(0.5f, 0f), Color.White, 1f, 0.5f, 0f, -1);
  			float num2 = 0.7f;
  			float num3 = 0.8f;
  			float num4 = 0.01f;
  			if (IngameOptions.oldLeftHover != IngameOptions.leftHover && IngameOptions.leftHover != -1)
  			{
  				Main.PlaySound(12, -1, -1, 1);
  			}
  			if (IngameOptions.oldRightHover != IngameOptions.rightHover && IngameOptions.rightHover != -1)
  			{
  				Main.PlaySound(12, -1, -1, 1);
  			}
  			if (flag && IngameOptions.rightHover != -1 && !IngameOptions.noSound)
  			{
  				Main.PlaySound(12, -1, -1, 1);
  			}
  			IngameOptions.oldLeftHover = IngameOptions.leftHover;
  			IngameOptions.oldRightHover = IngameOptions.rightHover;
  			IngameOptions.noSound = false;
  			int num5 = 5;
  			Vector2 anchor = new Vector2(value3.X + value2.X / 4f, value3.Y + (float)(num * 5 / 2));
  			Vector2 offset = new Vector2(0f, value2.Y - (float)(num * 3)) / (float)(num5 + 1);
  			for (int i = 0; i < 6; i++)
  			{
  				if (IngameOptions.leftHover == i || i == IngameOptions.category)
  				{
  					IngameOptions.leftScale[i] += num4;
  				}
  				else
  				{
  					IngameOptions.leftScale[i] -= num4;
  				}
  				if (IngameOptions.leftScale[i] < num2)
  				{
  					IngameOptions.leftScale[i] = num2;
  				}
  				if (IngameOptions.leftScale[i] > num3)
  				{
  					IngameOptions.leftScale[i] = num3;
  				}
  			}
  			IngameOptions.leftHover = -1;
  			int num6 = IngameOptions.category;
  			if (IngameOptions.DrawLeftSide(sb, Lang.menu[114], 0, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 0;
  				if (flag)
  				{
  					IngameOptions.category = 0;
  					Main.PlaySound(10, -1, -1, 1);
  				}
  			}
  			if (IngameOptions.DrawLeftSide(sb, Lang.menu[63], 1, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 1;
  				if (flag)
  				{
  					IngameOptions.category = 1;
  					Main.PlaySound(10, -1, -1, 1);
  				}
  			}
  			if (IngameOptions.DrawLeftSide(sb, Lang.menu[66], 2, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 2;
  				if (flag)
  				{
  					IngameOptions.category = 2;
  					Main.PlaySound(10, -1, -1, 1);
  				}
  			}
  			if (IngameOptions.DrawLeftSide(sb, Lang.menu[115], 3, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 3;
  				if (flag)
  				{
  					IngameOptions.category = 3;
  					Main.PlaySound(10, -1, -1, 1);
  				}
  			}
  			if (IngameOptions.DrawLeftSide(sb, Lang.menu[118], 4, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 4;
  				if (flag)
  				{
  					IngameOptions.Close();
  				}
  			}
  			if (IngameOptions.DrawLeftSide(sb, Lang.inter[35], 5, anchor, offset, IngameOptions.leftScale, 0.7f, 0.8f, 0.01f))
  			{
  				IngameOptions.leftHover = 5;
  				if (flag)
  				{
  					IngameOptions.Close();
  					Main.menuMode = 10;
  					WorldGen.SaveAndQuit();
  				}
  			}
  			if (num6 != IngameOptions.category)
  			{
  				for (int j = 0; j < IngameOptions.rightScale.Length; j++)
  				{
  					IngameOptions.rightScale[j] = 0f;
  				}
  			}
  			int num7 = 0;
  			switch (IngameOptions.category)
  			{
  			case 0:
  				num7 = 7;
  				num2 = 1f;
  				num3 = 1.001f;
  				num4 = 0.001f;
  				break;
  			case 1:
  				num7 = 8;
  				num2 = 1f;
  				num3 = 1.001f;
  				num4 = 0.001f;
  				break;
  			case 2:
  				num7 = 14;
  				num2 = 0.8f;
  				num3 = 0.801f;
  				num4 = 0.001f;
  				break;
  			case 3:
  				num7 = 7;
  				num2 = 0.8f;
  				num3 = 0.801f;
  				num4 = 0.001f;
  				break;
  			}
  			Vector2 anchor2 = new Vector2(value3.X + value2.X * 3f / 4f, value3.Y + (float)(num * 5 / 2));
  			Vector2 offset2 = new Vector2(0f, value2.Y - (float)(num * 3)) / (float)(num7 + 1);
  			for (int k = 0; k < 14; k++)
  			{
  				if (IngameOptions.rightLock == k || (IngameOptions.rightHover == k && IngameOptions.rightLock == -1))
  				{
  					IngameOptions.rightScale[k] += num4;
  				}
  				else
  				{
  					IngameOptions.rightScale[k] -= num4;
  				}
  				if (IngameOptions.rightScale[k] < num2)
  				{
  					IngameOptions.rightScale[k] = num2;
  				}
  				if (IngameOptions.rightScale[k] > num3)
  				{
  					IngameOptions.rightScale[k] = num3;
  				}
  			}
  			IngameOptions.inBar = false;
  			IngameOptions.rightHover = -1;
  			if (!Main.mouseLeft)
  			{
  				IngameOptions.rightLock = -1;
  			}
  			if (IngameOptions.rightLock == -1)
  			{
  				IngameOptions.notBar = false;
  			}
  			if (IngameOptions.category == 0)
  			{
  				int num8 = 0;
  				anchor2.X -= 70f;
  				if (IngameOptions.DrawRightSide(sb, string.Concat(new object[]
  				{
  					Lang.menu[99],
  					" ",
  					Math.Round((double)(Main.musicVolume * 100f)),
  					"%"
  				}), num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.noSound = true;
  					IngameOptions.rightHover = num8;
  				}
  				IngameOptions.valuePosition.X = value3.X + value2.X - (float)(num / 2) - 20f;
  				IngameOptions.valuePosition.Y = IngameOptions.valuePosition.Y - 3f;
  				float musicVolume = IngameOptions.DrawValueBar(sb, 0.75f, Main.musicVolume);
  				if ((IngameOptions.inBar || IngameOptions.rightLock == num8) && !IngameOptions.notBar)
  				{
  					IngameOptions.rightHover = num8;
  					if (Main.mouseLeft && IngameOptions.rightLock == num8)
  					{
  						Main.musicVolume = musicVolume;
  					}
  				}
  				if ((float)Main.mouseX > value3.X + value2.X * 2f / 3f + (float)num && (float)Main.mouseX < IngameOptions.valuePosition.X + 3.75f && (float)Main.mouseY > IngameOptions.valuePosition.Y - 10f && (float)Main.mouseY <= IngameOptions.valuePosition.Y + 10f)
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num8;
  				}
  				num8++;
  				if (IngameOptions.DrawRightSide(sb, string.Concat(new object[]
  				{
  					Lang.menu[98],
  					" ",
  					Math.Round((double)(Main.soundVolume * 100f)),
  					"%"
  				}), num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num8;
  				}
  				IngameOptions.valuePosition.X = value3.X + value2.X - (float)(num / 2) - 20f;
  				IngameOptions.valuePosition.Y = IngameOptions.valuePosition.Y - 3f;
  				float soundVolume = IngameOptions.DrawValueBar(sb, 0.75f, Main.soundVolume);
  				if ((IngameOptions.inBar || IngameOptions.rightLock == num8) && !IngameOptions.notBar)
  				{
  					IngameOptions.rightHover = num8;
  					if (Main.mouseLeft && IngameOptions.rightLock == num8)
  					{
  						Main.soundVolume = soundVolume;
  						IngameOptions.noSound = true;
  					}
  				}
  				if ((float)Main.mouseX > value3.X + value2.X * 2f / 3f + (float)num && (float)Main.mouseX < IngameOptions.valuePosition.X + 3.75f && (float)Main.mouseY > IngameOptions.valuePosition.Y - 10f && (float)Main.mouseY <= IngameOptions.valuePosition.Y + 10f)
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num8;
  				}
  				num8++;
  				if (IngameOptions.DrawRightSide(sb, string.Concat(new object[]
  				{
  					Lang.menu[119],
  					" ",
  					Math.Round((double)(Main.ambientVolume * 100f)),
  					"%"
  				}), num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num8;
  				}
  				IngameOptions.valuePosition.X = value3.X + value2.X - (float)(num / 2) - 20f;
  				IngameOptions.valuePosition.Y = IngameOptions.valuePosition.Y - 3f;
  				float ambientVolume = IngameOptions.DrawValueBar(sb, 0.75f, Main.ambientVolume);
  				if ((IngameOptions.inBar || IngameOptions.rightLock == num8) && !IngameOptions.notBar)
  				{
  					IngameOptions.rightHover = num8;
  					if (Main.mouseLeft && IngameOptions.rightLock == num8)
  					{
  						Main.ambientVolume = ambientVolume;
  						IngameOptions.noSound = true;
  					}
  				}
  				if ((float)Main.mouseX > value3.X + value2.X * 2f / 3f + (float)num && (float)Main.mouseX < IngameOptions.valuePosition.X + 3.75f && (float)Main.mouseY > IngameOptions.valuePosition.Y - 10f && (float)Main.mouseY <= IngameOptions.valuePosition.Y + 10f)
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num8;
  				}
  				num8++;
  				anchor2.X += 70f;
  				if (IngameOptions.DrawRightSide(sb, Main.autoSave ? Lang.menu[67] : Lang.menu[68], num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num8;
  					if (flag)
  					{
  						Main.autoSave = !Main.autoSave;
  					}
  				}
  				num8++;
  				if (IngameOptions.DrawRightSide(sb, Main.autoPause ? Lang.menu[69] : Lang.menu[70], num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num8;
  					if (flag)
  					{
  						Main.autoPause = !Main.autoPause;
  					}
  				}
  				num8++;
  				if (IngameOptions.DrawRightSide(sb, Main.showItemText ? Lang.menu[71] : Lang.menu[72], num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num8;
  					if (flag)
  					{
  						Main.showItemText = !Main.showItemText;
  					}
  				}
  				num8++;
  				if (IngameOptions.DrawRightSide(sb, Main.cSmartToggle ? Lang.menu[121] : Lang.menu[122], num8, anchor2, offset2, IngameOptions.rightScale[num8], (IngameOptions.rightScale[num8] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num8;
  					if (flag)
  					{
  						Main.cSmartToggle = !Main.cSmartToggle;
  					}
  				}
  				num8++;
  			}
  			if (IngameOptions.category == 1)
  			{
  				int num9 = 0;
  				if (IngameOptions.DrawRightSide(sb, Main.graphics.IsFullScreen ? Lang.menu[49] : Lang.menu[50], num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num9;
  					if (flag)
  					{
  						Main.graphics.ToggleFullScreen();
  					}
  				}
  				num9++;
  				if (IngameOptions.DrawRightSide(sb, string.Concat(new object[]
  				{
  					Lang.menu[51],
  					": ",
  					Main.graphics.PreferredBackBufferWidth,
  					"x",
  					Main.graphics.PreferredBackBufferHeight
  				}), num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num9;
  					if (flag)
  					{
  						int num10 = 0;
  						for (int l = 0; l < Main.numDisplayModes; l++)
  						{
  							if (Main.displayWidth[l] == Main.graphics.PreferredBackBufferWidth && Main.displayHeight[l] == Main.graphics.PreferredBackBufferHeight)
  							{
  								num10 = l;
  								break;
  							}
  						}
  						num10++;
  						if (num10 >= Main.numDisplayModes)
  						{
  							num10 = 0;
  						}
  						Main.graphics.PreferredBackBufferWidth = Main.displayWidth[num10];
  						Main.graphics.PreferredBackBufferHeight = Main.displayHeight[num10];
  					}
  				}
  				num9++;
  				anchor2.X -= 70f;
  				if (IngameOptions.DrawRightSide(sb, string.Concat(new object[]
  				{
  					Lang.menu[52],
  					": ",
  					Main.bgScroll,
  					"%"
  				}), num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.noSound = true;
  					IngameOptions.rightHover = num9;
  				}
  				IngameOptions.valuePosition.X = value3.X + value2.X - (float)(num / 2) - 20f;
  				IngameOptions.valuePosition.Y = IngameOptions.valuePosition.Y - 3f;
  				float num11 = IngameOptions.DrawValueBar(sb, 0.75f, (float)Main.bgScroll / 100f);
  				if ((IngameOptions.inBar || IngameOptions.rightLock == num9) && !IngameOptions.notBar)
  				{
  					IngameOptions.rightHover = num9;
  					if (Main.mouseLeft && IngameOptions.rightLock == num9)
  					{
  						Main.bgScroll = (int)(num11 * 100f);
  						Main.caveParrallax = 1f - (float)Main.bgScroll / 500f;
  					}
  				}
  				if ((float)Main.mouseX > value3.X + value2.X * 2f / 3f + (float)num && (float)Main.mouseX < IngameOptions.valuePosition.X + 3.75f && (float)Main.mouseY > IngameOptions.valuePosition.Y - 10f && (float)Main.mouseY <= IngameOptions.valuePosition.Y + 10f)
  				{
  					if (IngameOptions.rightLock == -1)
  					{
  						IngameOptions.notBar = true;
  					}
  					IngameOptions.rightHover = num9;
  				}
  				num9++;
  				anchor2.X += 70f;
  				if (IngameOptions.DrawRightSide(sb, Main.fixedTiming ? Lang.menu[53] : Lang.menu[54], num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num9;
  					if (flag)
  					{
  						Main.fixedTiming = !Main.fixedTiming;
  					}
  				}
  				num9++;
  				if (IngameOptions.DrawRightSide(sb, Lang.menu[55 + Lighting.lightMode], num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num9;
  					if (flag)
  					{
  						Lighting.NextLightMode();
  					}
  				}
  				num9++;
  				if (IngameOptions.DrawRightSide(sb, Lang.menu[116] + " " + ((Lighting.LightingThreads > 0) ? string.Concat(Lighting.LightingThreads + 1) : Lang.menu[117]), num9, anchor2, offset2, IngameOptions.rightScale[num9], (IngameOptions.rightScale[num9] - num2) / (num3 - num2), default(Color)))
  				{
  					IngameOptions.rightHover = num9;
  					if (flag)
  					{
  						Lighting.LightingThreads++;
  
gt: 						if (Lighting.LightingThreads > Environment.ProcessorCount - 1)