Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Draw() [1/2]

static void Terraria.UI.ItemSlot.Draw ( SpriteBatch spriteBatch,
Item[] inv,
int context,
int slot,
Vector2 position,
Color lightColor = default(Color) )
inlinestatic

Definition at line 1784 of file ItemSlot.cs.

1785 {
1786 Player player = Main.player[Main.myPlayer];
1787 Item item = inv[slot];
1788 float inventoryScale = Main.inventoryScale;
1789 Color color = Color.White;
1790 if (lightColor != Color.Transparent)
1791 {
1792 color = lightColor;
1793 }
1794 bool flag = false;
1795 int num = 0;
1796 int gamepadPointForSlot = GetGamepadPointForSlot(inv, context, slot);
1798 {
1799 flag = UILinkPointNavigator.CurrentPoint == gamepadPointForSlot;
1801 {
1802 flag = false;
1803 }
1804 if (context == 0)
1805 {
1806 num = player.DpadRadial.GetDrawMode(slot);
1807 if (num > 0 && !PlayerInput.CurrentProfile.UsingDpadHotbar())
1808 {
1809 num = 0;
1810 }
1811 }
1812 }
1814 Color color2 = Main.inventoryBack;
1815 bool flag2 = false;
1816 bool highlightThingsForMouse = PlayerInput.SettingsForUI.HighlightThingsForMouse;
1817 if (item.type > 0 && item.stack > 0 && item.favorited && context != 13 && context != 21 && context != 22 && context != 14)
1818 {
1820 if (context == 32)
1821 {
1823 }
1824 }
1825 else if (item.type > 0 && item.stack > 0 && Options.HighlightNewItems && item.newAndShiny && context != 13 && context != 21 && context != 14 && context != 22)
1826 {
1828 float num2 = (float)(int)Main.mouseTextColor / 255f;
1829 num2 = num2 * 0.2f + 0.8f;
1830 color2 = color2.MultiplyRGBA(new Color(num2, num2, num2));
1831 }
1832 else if (!highlightThingsForMouse && item.type > 0 && item.stack > 0 && num != 0 && context != 13 && context != 21 && context != 22)
1833 {
1835 float num3 = (float)(int)Main.mouseTextColor / 255f;
1836 num3 = num3 * 0.2f + 0.8f;
1837 color2 = ((num != 1) ? color2.MultiplyRGBA(new Color(num3 / 2f, num3, num3 / 2f)) : color2.MultiplyRGBA(new Color(num3, num3 / 2f, num3 / 2f)));
1838 }
1839 else if (context == 0 && slot < 10)
1840 {
1842 }
1843 else
1844 {
1845 switch (context)
1846 {
1847 case 28:
1849 color2 = Color.White;
1850 break;
1851 case 16:
1852 case 17:
1853 case 18:
1854 case 19:
1855 case 20:
1857 break;
1858 case 8:
1859 case 10:
1861 color2 = GetColorByLoadout(slot, context);
1862 break;
1863 case 23:
1864 case 24:
1865 case 26:
1867 break;
1868 case 9:
1869 case 11:
1871 color2 = GetColorByLoadout(slot, context);
1872 break;
1873 case 25:
1874 case 27:
1875 case 33:
1877 break;
1878 case 12:
1880 color2 = GetColorByLoadout(slot, context);
1881 break;
1882 case 3:
1884 break;
1885 case 4:
1886 case 32:
1888 break;
1889 case 5:
1890 case 7:
1892 break;
1893 case 6:
1895 break;
1896 case 13:
1897 {
1898 byte b = 200;
1899 if (slot == Main.player[Main.myPlayer].selectedItem)
1900 {
1902 b = byte.MaxValue;
1903 }
1904 color2 = new Color(b, b, b, b);
1905 break;
1906 }
1907 case 14:
1908 case 21:
1909 flag2 = true;
1910 break;
1911 case 15:
1913 break;
1914 case 29:
1915 color2 = new Color(53, 69, 127, 255);
1917 break;
1918 case 30:
1919 flag2 = !flag;
1920 break;
1921 case 22:
1924 {
1927 float num4 = (float)(int)color2.A / 255f;
1928 num4 = ((!(num4 < 0.7f)) ? 1f : Utils.GetLerpValue(0f, 0.7f, num4, clamped: true));
1929 color2 = Color.White * num4;
1930 }
1931 break;
1932 }
1933 }
1934 if ((context == 0 || context == 2) && inventoryGlowTime[slot] > 0 && !inv[slot].favorited && !inv[slot].IsAir)
1935 {
1936 float num5 = Main.invAlpha / 255f;
1937 Color value2 = new Color(63, 65, 151, 255) * num5;
1938 Color value3 = Main.hslToRgb(inventoryGlowHue[slot], 1f, 0.5f) * num5;
1939 float num6 = (float)inventoryGlowTime[slot] / 300f;
1940 num6 *= num6;
1941 color2 = Color.Lerp(value2, value3, num6 / 2f);
1943 }
1944 if ((context == 4 || context == 32 || context == 3) && inventoryGlowTimeChest[slot] > 0 && !inv[slot].favorited && !inv[slot].IsAir)
1945 {
1946 float num7 = Main.invAlpha / 255f;
1947 Color value4 = new Color(130, 62, 102, 255) * num7;
1948 if (context == 3)
1949 {
1950 value4 = new Color(104, 52, 52, 255) * num7;
1951 }
1952 Color value5 = Main.hslToRgb(inventoryGlowHueChest[slot], 1f, 0.5f) * num7;
1953 float num8 = (float)inventoryGlowTimeChest[slot] / 300f;
1954 num8 *= num8;
1955 color2 = Color.Lerp(value4, value5, num8 / 2f);
1957 }
1958 if (flag)
1959 {
1961 color2 = Color.White;
1962 if (item.favorited)
1963 {
1965 }
1966 }
1967 if (context == 28 && Main.MouseScreen.Between(position, position + value.Size() * inventoryScale) && !player.mouseInterface)
1968 {
1970 color2 = Color.White;
1971 }
1972 if (!flag2)
1973 {
1974 spriteBatch.Draw(value, position, null, color2, 0f, default(Vector2), inventoryScale, SpriteEffects.None, 0f);
1975 }
1976 int num9 = -1;
1977 switch (context)
1978 {
1979 case 8:
1980 case 23:
1981 if (slot == 0)
1982 {
1983 num9 = 0;
1984 }
1985 if (slot == 1)
1986 {
1987 num9 = 6;
1988 }
1989 if (slot == 2)
1990 {
1991 num9 = 12;
1992 }
1993 break;
1994 case 26:
1995 num9 = 0;
1996 break;
1997 case 9:
1998 if (slot == 10)
1999 {
2000 num9 = 3;
2001 }
2002 if (slot == 11)
2003 {
2004 num9 = 9;
2005 }
2006 if (slot == 12)
2007 {
2008 num9 = 15;
2009 }
2010 break;
2011 case 10:
2012 case 24:
2013 num9 = 11;
2014 break;
2015 case 11:
2016 num9 = 2;
2017 break;
2018 case 12:
2019 case 25:
2020 case 27:
2021 case 33:
2022 num9 = 1;
2023 break;
2024 case 16:
2025 num9 = 4;
2026 break;
2027 case 17:
2028 num9 = 13;
2029 break;
2030 case 19:
2031 num9 = 10;
2032 break;
2033 case 18:
2034 num9 = 7;
2035 break;
2036 case 20:
2037 num9 = 17;
2038 break;
2039 }
2040 if ((item.type <= 0 || item.stack <= 0) && num9 != -1)
2041 {
2042 Texture2D value6 = TextureAssets.Extra[54].Value;
2043 Rectangle rectangle = value6.Frame(3, 6, num9 % 3, num9 / 3);
2044 rectangle.Width -= 2;
2045 rectangle.Height -= 2;
2046 spriteBatch.Draw(value6, position + value.Size() / 2f * inventoryScale, rectangle, Color.White * 0.35f, 0f, rectangle.Size() / 2f, inventoryScale, SpriteEffects.None, 0f);
2047 }
2048 Vector2 vector = value.Size() * inventoryScale;
2049 if (item.type > 0 && item.stack > 0)
2050 {
2051 float scale = DrawItemIcon(item, context, spriteBatch, position + vector / 2f, inventoryScale, 32f, color);
2052 if (ItemID.Sets.TrapSigned[item.type])
2053 {
2054 spriteBatch.Draw(TextureAssets.Wire.Value, position + new Vector2(40f, 40f) * inventoryScale, new Rectangle(4, 58, 8, 8), color, 0f, new Vector2(4f), 1f, SpriteEffects.None, 0f);
2055 }
2057 {
2058 Vector2 vector2 = new Vector2(-4f, -4f) * inventoryScale;
2059 Texture2D value7 = TextureAssets.Extra[258].Value;
2060 Rectangle rectangle2 = value7.Frame();
2061 spriteBatch.Draw(value7, position + vector2 + new Vector2(40f, 40f) * inventoryScale, rectangle2, color, 0f, rectangle2.Size() / 2f, 1f, SpriteEffects.None, 0f);
2062 }
2063 if (item.type == 5324 || item.type == 5329 || item.type == 5330)
2064 {
2065 Vector2 vector3 = new Vector2(2f, -6f) * inventoryScale;
2066 switch (item.type)
2067 {
2068 case 5324:
2069 {
2070 Texture2D value10 = TextureAssets.Extra[257].Value;
2071 Rectangle rectangle5 = value10.Frame(3, 1, 2);
2072 spriteBatch.Draw(value10, position + vector3 + new Vector2(40f, 40f) * inventoryScale, rectangle5, color, 0f, rectangle5.Size() / 2f, 1f, SpriteEffects.None, 0f);
2073 break;
2074 }
2075 case 5329:
2076 {
2077 Texture2D value9 = TextureAssets.Extra[257].Value;
2078 Rectangle rectangle4 = value9.Frame(3, 1, 1);
2079 spriteBatch.Draw(value9, position + vector3 + new Vector2(40f, 40f) * inventoryScale, rectangle4, color, 0f, rectangle4.Size() / 2f, 1f, SpriteEffects.None, 0f);
2080 break;
2081 }
2082 case 5330:
2083 {
2084 Texture2D value8 = TextureAssets.Extra[257].Value;
2085 Rectangle rectangle3 = value8.Frame(3);
2086 spriteBatch.Draw(value8, position + vector3 + new Vector2(40f, 40f) * inventoryScale, rectangle3, color, 0f, rectangle3.Size() / 2f, 1f, SpriteEffects.None, 0f);
2087 break;
2088 }
2089 }
2090 }
2091 if (item.stack > 1)
2092 {
2093 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, item.stack.ToString(), position + new Vector2(10f, 26f) * inventoryScale, color, 0f, Vector2.Zero, new Vector2(inventoryScale), -1f, inventoryScale);
2094 }
2095 int num10 = -1;
2096 if (context == 13)
2097 {
2098 if (item.DD2Summon)
2099 {
2100 for (int i = 0; i < 58; i++)
2101 {
2102 if (inv[i].type == 3822)
2103 {
2104 num10 += inv[i].stack;
2105 }
2106 }
2107 if (num10 >= 0)
2108 {
2109 num10++;
2110 }
2111 }
2112 if (item.useAmmo > 0)
2113 {
2114 int useAmmo = item.useAmmo;
2115 num10 = 0;
2116 for (int j = 0; j < 58; j++)
2117 {
2118 if (inv[j].ammo == useAmmo)
2119 {
2120 num10 += inv[j].stack;
2121 }
2122 }
2123 }
2124 if (item.fishingPole > 0)
2125 {
2126 num10 = 0;
2127 for (int k = 0; k < 58; k++)
2128 {
2129 if (inv[k].bait > 0)
2130 {
2131 num10 += inv[k].stack;
2132 }
2133 }
2134 }
2135 if (item.tileWand > 0)
2136 {
2137 int tileWand = item.tileWand;
2138 num10 = 0;
2139 for (int l = 0; l < 58; l++)
2140 {
2141 if (inv[l].type == tileWand)
2142 {
2143 num10 += inv[l].stack;
2144 }
2145 }
2146 }
2147 if (item.type == 509 || item.type == 851 || item.type == 850 || item.type == 3612 || item.type == 3625 || item.type == 3611)
2148 {
2149 num10 = 0;
2150 for (int m = 0; m < 58; m++)
2151 {
2152 if (inv[m].type == 530)
2153 {
2154 num10 += inv[m].stack;
2155 }
2156 }
2157 }
2158 }
2159 if (num10 != -1)
2160 {
2161 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, num10.ToString(), position + new Vector2(8f, 30f) * inventoryScale, color, 0f, Vector2.Zero, new Vector2(inventoryScale * 0.8f), -1f, inventoryScale);
2162 }
2163 if (context == 13)
2164 {
2165 string text = string.Concat(slot + 1);
2166 if (text == "10")
2167 {
2168 text = "0";
2169 }
2170 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, text, position + new Vector2(8f, 4f) * inventoryScale, color, 0f, Vector2.Zero, new Vector2(inventoryScale), -1f, inventoryScale);
2171 }
2172 if (context == 13 && item.potion)
2173 {
2174 Vector2 position2 = position + value.Size() * inventoryScale / 2f - TextureAssets.Cd.Value.Size() * inventoryScale / 2f;
2175 Color color3 = item.GetAlpha(color) * ((float)player.potionDelay / (float)player.potionDelayTime);
2176 spriteBatch.Draw(TextureAssets.Cd.Value, position2, null, color3, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
2177 }
2178 if ((context == 10 || context == 18) && item.expertOnly && !Main.expertMode)
2179 {
2180 Vector2 position3 = position + value.Size() * inventoryScale / 2f - TextureAssets.Cd.Value.Size() * inventoryScale / 2f;
2181 Color white = Color.White;
2182 spriteBatch.Draw(TextureAssets.Cd.Value, position3, null, white, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
2183 }
2184 }
2185 else if (context == 6)
2186 {
2187 Texture2D value11 = TextureAssets.Trash.Value;
2188 Vector2 position4 = position + value.Size() * inventoryScale / 2f - value11.Size() * inventoryScale / 2f;
2189 spriteBatch.Draw(value11, position4, null, new Color(100, 100, 100, 100), 0f, default(Vector2), inventoryScale, SpriteEffects.None, 0f);
2190 }
2191 if (context == 0 && slot < 10)
2192 {
2193 float num11 = inventoryScale;
2194 string text2 = string.Concat(slot + 1);
2195 if (text2 == "10")
2196 {
2197 text2 = "0";
2198 }
2199 Color baseColor = Main.inventoryBack;
2200 int num12 = 0;
2201 if (Main.player[Main.myPlayer].selectedItem == slot)
2202 {
2203 baseColor = Color.White;
2204 baseColor.A = 200;
2205 num12 -= 2;
2206 num11 *= 1.4f;
2207 }
2208 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, text2, position + new Vector2(6f, 4 + num12) * inventoryScale, baseColor, 0f, Vector2.Zero, new Vector2(inventoryScale), -1f, inventoryScale);
2209 }
2210 if (gamepadPointForSlot != -1)
2211 {
2212 UILinkPointNavigator.SetPosition(gamepadPointForSlot, position + vector * 0.75f);
2213 }
2214 }
void Draw(Texture2D texture, Vector2 position, Color color)
static Asset< DynamicSpriteFont > ItemStack
Definition FontAssets.cs:8
static Asset< Texture2D > InventoryBack13
static Asset< Texture2D > InventoryBack7
static Asset< Texture2D > InventoryBack8
static Asset< Texture2D > InventoryBack9
static Asset< Texture2D > InventoryBack
static Asset< Texture2D > Cd
static Asset< Texture2D > InventoryBack5
static Asset< Texture2D > Trash
static Asset< Texture2D > InventoryBack4
static Asset< Texture2D > InventoryBack14
static Asset< Texture2D > InventoryBack6
static Asset< Texture2D > InventoryBack18
static Asset< Texture2D >[] Extra
static Asset< Texture2D > InventoryBack3
static Asset< Texture2D > InventoryBack19
static Asset< Texture2D > Wire
static Asset< Texture2D > InventoryBack15
static Asset< Texture2D > InventoryBack17
static Asset< Texture2D > InventoryBack12
static Asset< Texture2D > InventoryBack2
static Asset< Texture2D > InventoryBack10
static PlayerInputProfile CurrentProfile
static bool[] TrapSigned
Definition ItemID.cs:1040
static bool[] DrawUnsafeIndicator
Definition ItemID.cs:59
static Vector2 DrawColorCodedStringWithShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, float rotation, Vector2 origin, Vector2 baseScale, out int hoveredSnippet, float maxWidth=-1f, float spread=2f)
static void SetPosition(int ID, Vector2 Position)
static float[] inventoryGlowHueChest
Definition ItemSlot.cs:141
static Color GetColorByLoadout(int slot, int context)
Definition ItemSlot.cs:2216
static float DrawItemIcon(Item item, int context, SpriteBatch spriteBatch, Vector2 screenPositionForItemCenter, float scale, float sizeLimit, Color environmentColor)
Definition ItemSlot.cs:2273
static int[] inventoryGlowTime
Definition ItemSlot.cs:139
static int[] inventoryGlowTimeChest
Definition ItemSlot.cs:143
static bool DrawGoldBGForCraftingMaterial
Definition ItemSlot.cs:127
static float[] inventoryGlowHue
Definition ItemSlot.cs:137
static int GetGamepadPointForSlot(Item[] inv, int context, int slot)
Definition ItemSlot.cs:2333
static Color Transparent
Definition Color.cs:76
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491

References Terraria.GameContent.TextureAssets.Cd, Microsoft.Xna.Framework.Graphics.Color, Terraria.GameInput.PlayerInput.CurrentProfile, Terraria.Player.DpadRadial, Microsoft.Xna.Framework.Graphics.SpriteBatch.Draw(), Terraria.UI.Chat.ChatManager.DrawColorCodedStringWithShadow(), Terraria.UI.ItemSlot.DrawGoldBGForCraftingMaterial, Terraria.UI.ItemSlot.DrawItemIcon(), Terraria.ID.ItemID.Sets.DrawUnsafeIndicator, Terraria.Main.expertMode, Terraria.GameContent.TextureAssets.Extra, Terraria.Item.favorited, Terraria.UI.ItemSlot.GetColorByLoadout(), Terraria.Player.SelectionRadial.GetDrawMode(), Terraria.UI.ItemSlot.GetGamepadPointForSlot(), Terraria.Utils.GetLerpValue(), Terraria.UI.ItemSlot.Options.HighlightNewItems, Terraria.GameInput.PlayerInput.SettingsForUI.HighlightThingsForMouse, Terraria.Main.hslToRgb(), Terraria.GameContent.TextureAssets.InventoryBack, Terraria.Main.inventoryBack, Terraria.GameContent.TextureAssets.InventoryBack10, Terraria.GameContent.TextureAssets.InventoryBack12, Terraria.GameContent.TextureAssets.InventoryBack13, Terraria.GameContent.TextureAssets.InventoryBack14, Terraria.GameContent.TextureAssets.InventoryBack15, Terraria.GameContent.TextureAssets.InventoryBack17, Terraria.GameContent.TextureAssets.InventoryBack18, Terraria.GameContent.TextureAssets.InventoryBack19, Terraria.GameContent.TextureAssets.InventoryBack2, Terraria.GameContent.TextureAssets.InventoryBack3, Terraria.GameContent.TextureAssets.InventoryBack4, Terraria.GameContent.TextureAssets.InventoryBack5, Terraria.GameContent.TextureAssets.InventoryBack6, Terraria.GameContent.TextureAssets.InventoryBack7, Terraria.GameContent.TextureAssets.InventoryBack8, Terraria.GameContent.TextureAssets.InventoryBack9, Terraria.UI.ItemSlot.inventoryGlowHue, Terraria.UI.ItemSlot.inventoryGlowHueChest, Terraria.UI.ItemSlot.inventoryGlowTime, Terraria.UI.ItemSlot.inventoryGlowTimeChest, Terraria.Main.inventoryScale, Terraria.Item.IsAir, System.item, Terraria.GameContent.FontAssets.ItemStack, Microsoft.Xna.Framework.Color.Lerp(), Terraria.Player.mouseInterface, Terraria.Main.MouseScreen, Terraria.Main.myPlayer, Terraria.Main.player, Terraria.Player.potionDelay, Terraria.Player.potionDelayTime, Terraria.GameInput.PlayerInput.SettingsForUI.PreventHighlightsForGamepad, Terraria.UI.Gamepad.UILinkPointNavigator.SetPosition(), Terraria.Item.stack, System.text, Microsoft.Xna.Framework.Color.Transparent, Terraria.ID.ItemID.Sets.TrapSigned, Terraria.GameContent.TextureAssets.Trash, System.type, Terraria.GameInput.PlayerInput.UsingGamepadUI, System.value, Microsoft.Xna.Framework.Graphics.Vector2, Microsoft.Xna.Framework.Color.White, Terraria.GameContent.TextureAssets.Wire, and Microsoft.Xna.Framework.Vector2.Zero.