public void EnsureTextureMaxSize(WrappedTextureMaxSize maxTextureSize) { if (maxTextureSize != WrappedTextureMaxSize.DONT_RESIZE) { TextureHelpers.EnsureTexture2DMaxSize(ref texture2D, (int)maxTextureSize); } }
public void Draw(SpriteBatch b) { if (IsEmptyMenu) { return; } //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot foreach (Rectangle LockedSlot in LockedSlotBounds) { b.Draw(Game1.menuTexture, LockedSlot, new Rectangle(64, 896, 64, 64), Color.White); } foreach (Rectangle UnlockedSlot in SlotBounds) { b.Draw(Game1.menuTexture, UnlockedSlot, new Rectangle(128, 128, 64, 64), Color.White); } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { Rectangle Destination = SlotBounds[i]; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } Object CurrentItem = PlaceholderItems[i]; float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); OnItemSlotRendered?.Invoke(this, new ItemSlotRenderedEventArgs(b, Destination, CurrentItem, IsHovered)); } foreach (Rectangle LockedSlot in LockedSlotBounds) { if (HoveredSlot == LockedSlot) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, LockedSlot, Color.White * 0.25f); int BorderThickness = LockedSlot.Width / 16; DrawHelpers.DrawBorder(b, LockedSlot, BorderThickness, HighlightColor); } } }
public void SetMaxTextureSize(int size) { if (!isLoaded) { return; } for (int i = 0; i < gifTextures.Count; i++) { TextureHelpers.EnsureTexture2DMaxSize(ref gifTextures[i].m_texture2d, size); } }
public void Draw(SpriteBatch b) { //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Placeholders.Count) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(128, 128, 64, 64), Color.White); } else if (ShowLockedSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(64, 896, 64, 64), Color.White); } } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Placeholders.Count) { Rectangle Destination = SlotBounds[i]; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; if (ActualContents[i] != null) { ItemBag CurrentItem = ActualContents[i]; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1f, Color.White, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } else { ItemBag CurrentItem = Placeholders[i]; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 0.35f, Color.White * 0.3f, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int type = parameter is string?int.Parse((string)parameter, CultureInfo.InvariantCulture) : 0; switch (type) { case 0: return(TextureHelpers.BuildOptTexture(value as Texture)); case 1: return(TextureHelpers.BuildOptTextureAlpha(value as Texture)); } return(null); }
public void SetMaxTextureSize(MaxSize size) { if (!isLoaded) { return; } if (size == MaxSize.DONT_RESIZE) { return; } int texturesCount = gifTextures.Count; for (int i = 0; i < texturesCount; i++) { TextureHelpers.EnsureTexture2DMaxSize(ref gifTextures[i].m_texture2d, (int)size); } }
private void ReduceTextureSizeIfNeeded(string texturePath, float maxSize) { string finalTexturePath = finalDownloadedPath + texturePath; byte[] image = File.ReadAllBytes(finalTexturePath); var tmpTex = new Texture2D(1, 1); if (!ImageConversion.LoadImage(tmpTex, image)) { return; } float factor = 1.0f; int width = tmpTex.width; int height = tmpTex.height; float maxTextureSize = maxSize; if (width < maxTextureSize && height < maxTextureSize) { return; } if (width >= height) { factor = (float)maxTextureSize / width; } else { factor = (float)maxTextureSize / height; } Texture2D dstTex = TextureHelpers.Resize(tmpTex, (int)(width * factor), (int)(height * factor)); byte[] endTex = ImageConversion.EncodeToPNG(dstTex); UnityEngine.Object.DestroyImmediate(tmpTex); File.WriteAllBytes(finalTexturePath, endTex); AssetDatabase.ImportAsset(finalDownloadedAssetDbPath + texturePath, ImportAssetOptions.ForceUpdate); AssetDatabase.SaveAssets(); }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // overall textures GrassTexture = Content.Load <Texture2D>("Textures/grass"); // resource textures foreach (var restemplate in PlarfGame.Instance.ResourceTemplates) { if (!MiscTextures.ContainsKey(restemplate.Value.Texture) && !string.IsNullOrWhiteSpace(restemplate.Value.Texture)) { using (var stream = VFS.OpenStream(restemplate.Value.Texture)) MiscTextures.Add(restemplate.Value.Texture, TextureHelpers.FromStream(stream, GraphicsDevice)); } } // building textures foreach (var bclass in PlarfGame.Instance.BuildingClasses) { if (!MiscTextures.ContainsKey(bclass.Value.Texture) && !string.IsNullOrWhiteSpace(bclass.Value.Texture)) { using (var stream = VFS.OpenStream(bclass.Value.Texture)) MiscTextures.Add(bclass.Value.Texture, TextureHelpers.FromStream(stream, GraphicsDevice)); } } // actor resources if (!MiscTextures.ContainsKey(PlarfGame.Instance.HumanTemplate.Texture) && !string.IsNullOrWhiteSpace(PlarfGame.Instance.HumanTemplate.Texture)) { using (var stream = VFS.OpenStream(PlarfGame.Instance.HumanTemplate.Texture)) MiscTextures.Add(PlarfGame.Instance.HumanTemplate.Texture, TextureHelpers.FromStream(stream, GraphicsDevice)); } // the line texture LineTexture = new Texture2D(GraphicsDevice, 1, 1); LineTexture.SetData(new Color[] { Color.White }); // fonts DefaultFont = Content.Load <SpriteFont>("Fonts/DefaultFont"); }
public static void ApplyDefaultMaterialProperties(Material material, CharacterMaterialType materialType) { material.shader = Shader.Find("Pegasus/CH/CH_Base"); material.DisableKeyword("_MATERIALTYPE_BODY"); material.EnableKeyword($"_MATERIALTYPE_{materialType.ToKeywordString()}"); material.SetInt("_MaterialType", (int)materialType); material.SetFloat("_OutlineWidth", 0.2f); material.SetColor("_OutlineColor", new Color(0.1f, 0.1f, 0.1f, 1f)); // TODO: Calculate from average texture color material.SetFloat("_OutlineOffset", 0.5f); material.SetColor("_HighlightColor", Color.white); material.SetColor("_AddColor", Color.black); material.SetColor("_Condition", Color.gray); material.SetColor("_Visible", Color.white); material.SetTexture("_ShadowColor", TextureHelpers.GetDefaultTexture("ShadowColor")); material.SetTexture("_MatCap", TextureHelpers.GetDefaultTexture("CH_LightMap")); material.SetTexture("_Kamishitu", TextureHelpers.GetDefaultTexture("Gayousi_loop")); material.SetTexture("_HSVMaskTex", TextureHelpers.GetDefaultTexture("HSVMaskTex")); }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values.Length < 2 || values[0] == DependencyProperty.UnsetValue || values[1] == null) { return(null); } string pal = (string)values[1]; if (pal == "Default") { return(TextureHelpers.BuildOptTexture(values[0] as Texture, TextureHelpers.DefaultPalette)); } else { return(TextureHelpers.BuildOptTexture(values[0] as Texture, int.Parse(pal))); } }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Length < 2 || values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue) { return(null); } OptFile optFile = values[1] as OptFile; if (optFile == null) { return(null); } Texture texture = optFile.Textures.ContainsKey((string)values[0]) ? optFile.Textures[(string)values[0]] : null; return(TextureHelpers.BuildOptTexture(texture)); }
public void Draw(SpriteBatch b) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); DrawHelpers.DrawBox(b, Bounds); // Draw preview image b.Draw(Game1.menuTexture, PreviewDestination, new Rectangle(128, 128, 64, 64), Color.White); ItemBag CurrentBag = HoveredSprite.HasValue ? PreviewBag : Bag; DrawHelpers.DrawItem(b, PreviewDestination, CurrentBag, false, false, 1f, 1f, Color.White, Color.White); // Draw instructional text b.DrawString(InstructionFont, InstructionText, InstructionDestination, Color.Black, 0f, Vector2.Zero, InstructionScale, SpriteEffects.None, 1f); // Draw spritesheet with all icons to choose from DrawHelpers.DrawBorder(b, new Rectangle(TextureDestination.Left - 2, TextureDestination.Top - 2, TextureDestination.Width + 4, TextureDestination.Height + 4), 2, Color.Black); b.Draw(Texture, TextureDestination, new Rectangle(0, 0, TextureWidth, TextureHeight), Color.White); if (HoveredSprite.HasValue) { Rectangle Destination = HoveredSprite.Value.GetOffseted(new Point(TextureDestination.X, TextureDestination.Y)); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Math.Max(2, HoveredSprite.Value.Width / SpriteSize); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } // Draw buttons b.Draw(Game1.menuTexture, DefaultButtonDestination, new Rectangle(128, 128, 64, 64), Color.White); b.DrawString(ButtonFont, DefaultButtonText, DefaultButtonTextDestination, Color.Black, 0f, Vector2.Zero, ButtonFontScale, SpriteEffects.None, 1f); b.Draw(Game1.menuTexture, CloseButtonDestination, new Rectangle(128, 128, 64, 64), Color.White); b.DrawString(ButtonFont, CloseButtonText, CloseButtonTextDestination, Color.Black, 0f, Vector2.Zero, ButtonFontScale, SpriteEffects.None, 1f); if (HoveredButton.HasValue) { Rectangle Destination = HoveredButton.Value; b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Math.Max(2, HoveredButton.Value.Width / 16); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } }
public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null) { if (Solids.Instance.InputService.IsPressed(InputService.ShiftKeys.LeftShift1)) { // return; } if (Texture2D != null) { FloatRectangle?pos = screen.Translate(Position.Value.Move(scrollOffset)); FloatRectangle?translatedClip = screen.Translate(clip); Rectangle?fixedSource = SourceRectangle.Value; (Rectangle position, Rectangle? source)thing = TextureHelpers.GetAdjustedDestAndSourceAfterClip(pos, fixedSource, translatedClip); using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { //spriteBatch.Draw(Texture2D.Value, thing.Item1, thing.Item2, ImageColor.Value * opacity, Rotation.Value, new Vector2(thing.Item1.Width/2f, thing.Item1.Height/2f),SpriteEffects.None,1f); spriteBatch.Draw(Texture2D.Value, pos.Value.ToRectangle, null, ImageColor.Value * opacity); } } }
protected override bool AddToLibrary() { if (storeDefaultTextureInAdvance && !UsesDefaultWrapAndFilterMode()) { if (!library.Contains(idWithDefaultTexSettings)) { // Save default texture asset asset.id = idWithDefaultTexSettings; asset.ConfigureTexture(DEFAULT_WRAP_MODE, DEFAULT_FILTER_MODE, false); if (!library.Add(asset)) { Debug.Log("add to library fail?"); return(false); } } // By always using library.Get() for the default tex we have stored, we increase its references counter, // that will come in handy for removing that default tex when there is no one using it var defaultTexAsset = library.Get(idWithDefaultTexSettings); asset = defaultTexAsset.Clone() as Asset_Texture; asset.dependencyAsset = defaultTexAsset; asset.texture = TextureHelpers.CopyTexture(defaultTexAsset.texture); } asset.id = idWithTexSettings; asset.ConfigureTexture(wrapMode, filterMode, storeTexAsNonReadable); if (!library.Add(asset)) { Debug.Log("add to library fail?"); return(false); } asset = library.Get(asset.id); return(true); }
public sealed override void draw(SpriteBatch b) { try { DrawBox(b, xPositionOnScreen, yPositionOnScreen, width, height); int SeparatorHeight = 24; DrawHorizontalSeparator(b, xPositionOnScreen, InventoryMenu.TopLeftScreenPosition.Y - InventoryMargin - SeparatorHeight / 2, width, SeparatorHeight); InventoryMenu.Draw(b); if (IsLeftSidebarVisible || IsRightSidebarVisible) { if (IsLeftSidebarVisible) { // Draw the deposit/withdraw-all buttons Rectangle ArrowUpIconSourceRect = new Rectangle(421, 459, 12, 12); Rectangle ArrowDownIconSourceRect = new Rectangle(421, 472, 12, 12); int ArrowSize = (int)(ArrowUpIconSourceRect.Width * 1.5 / 32.0 * DepositAllBounds.Width); b.Draw(Game1.menuTexture, DepositAllBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(DepositAllBounds.X + (DepositAllBounds.Width - ArrowSize) / 2, DepositAllBounds.Y + (DepositAllBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowUpIconSourceRect, Color.White); b.Draw(Game1.menuTexture, WithdrawAllBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(WithdrawAllBounds.X + (WithdrawAllBounds.Width - ArrowSize) / 2, WithdrawAllBounds.Y + (WithdrawAllBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowDownIconSourceRect, Color.White); // Draw the autofill togglebutton Rectangle HandIconSourceRect = new Rectangle(32, 0, 10, 10); int HandIconSize = (int)(HandIconSourceRect.Width * 2.0 / 32.0 * AutolootBounds.Width); b.Draw(Game1.menuTexture, AutolootBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(AutolootBounds.X + (AutolootBounds.Width - HandIconSize) / 2, AutolootBounds.Y + (AutolootBounds.Height - HandIconSize) / 2, HandIconSize, HandIconSize), HandIconSourceRect, Color.White); if (Bag is BoundedBag BB) { if (!BB.Autofill) { Rectangle DisabledIconSourceRect = new Rectangle(322, 498, 12, 12); int DisabledIconSize = (int)(DisabledIconSourceRect.Width * 1.5 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - DisabledIconSize - 2, AutolootBounds.Bottom - DisabledIconSize - 2, DisabledIconSize, DisabledIconSize); b.Draw(Game1.mouseCursors, Destination, DisabledIconSourceRect, Color.White); } } else if (Bag is Rucksack RS) { if (!RS.Autofill) { Rectangle DisabledIconSourceRect = new Rectangle(322, 498, 12, 12); int DisabledIconSize = (int)(DisabledIconSourceRect.Width * 1.5 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - DisabledIconSize - 2, AutolootBounds.Bottom - DisabledIconSize - 2, DisabledIconSize, DisabledIconSize); b.Draw(Game1.mouseCursors, Destination, DisabledIconSourceRect, Color.White); } else { if (RS.AutofillPriority == AutofillPriority.Low) { Rectangle LowPriorityIconSourceRect = new Rectangle(421, 472, 12, 12); int LowPriorityIconSize = (int)(LowPriorityIconSourceRect.Width * 1.0 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - LowPriorityIconSize - 2, AutolootBounds.Bottom - LowPriorityIconSize - 2, LowPriorityIconSize, LowPriorityIconSize); b.Draw(Game1.mouseCursors, Destination, LowPriorityIconSourceRect, Color.White); } else if (RS.AutofillPriority == AutofillPriority.High) { Rectangle HighPriorityIconSourceRect = new Rectangle(421, 459, 12, 12); int HighPriorityIconSize = (int)(HighPriorityIconSourceRect.Width * 1.0 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - HighPriorityIconSize - 2, AutolootBounds.Bottom - HighPriorityIconSize - 2, HighPriorityIconSize, HighPriorityIconSize); b.Draw(Game1.mouseCursors, Destination, HighPriorityIconSourceRect, Color.White); } } } } if (IsRightSidebarVisible) { // Draw the help button Rectangle HelpIconSourceRect = new Rectangle(176, 425, 9, 12); int HelpIconWidth = (int)(HelpIconSourceRect.Width * 1.5 / 32.0 * HelpInfoBounds.Width); int HelpIconHeight = (int)(HelpIconSourceRect.Height * 1.5 / 32.0 * HelpInfoBounds.Height); b.Draw(Game1.menuTexture, HelpInfoBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(HelpInfoBounds.X + (HelpInfoBounds.Width - HelpIconWidth) / 2, HelpInfoBounds.Y + (HelpInfoBounds.Height - HelpIconHeight) / 2, HelpIconWidth, HelpIconHeight), HelpIconSourceRect, Color.White); if (Bag.CanCustomizeIcon()) { // Draw the customize icon button Rectangle CustomizeSourceRect = new Rectangle(121, 471, 12, 12); int CustomizeIconWidth = CustomizeIconBounds.Width; int CustomizeIconHeight = CustomizeIconBounds.Height; b.Draw(Game1.mouseCursors, new Rectangle(CustomizeIconBounds.X + (CustomizeIconBounds.Width - CustomizeIconWidth) / 2, CustomizeIconBounds.Y + (CustomizeIconBounds.Height - CustomizeIconHeight) / 2, CustomizeIconWidth, CustomizeIconHeight), CustomizeSourceRect, Color.White); b.Draw(Game1.menuTexture, CustomizeIconBounds, new Rectangle(128, 128, 64, 64), Color.White); } } // Draw a yellow border around the hovered sidebar button if (HoveredButton.HasValue) { Rectangle HoveredBounds = HoveredButtonBounds.Value; Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, HoveredBounds, Color.White * 0.25f); int BorderThickness = HoveredBounds.Width / 16; DrawBorder(b, HoveredBounds, BorderThickness, HighlightColor); } } Content.Draw(b); if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.Draw(b); } else { InventoryMenu.DrawToolTips(b); Content.DrawToolTips(b); // Draw tooltips on the sidebar buttons if ((IsLeftSidebarVisible || IsRightSidebarVisible) && HoveredButton.HasValue) { if (IsLeftSidebarVisible) { string ButtonToolTip = ""; if (HoveredButton.Value == SidebarButton.DepositAll) { ButtonToolTip = ItemBagsMod.Translate("DepositAllToolTip"); } else if (HoveredButton.Value == SidebarButton.WithdrawAll) { ButtonToolTip = ItemBagsMod.Translate("WithdrawAllToolTip"); } else if (HoveredButton.Value == SidebarButton.Autoloot) { if (Bag is BoundedBag BB) { ButtonToolTip = ItemBagsMod.Translate(BB.Autofill ? "AutofillOnToolTip" : "AutofillOffToolTip"); } else if (Bag is Rucksack RS) { string TranslationKey; if (RS.Autofill) { if (RS.AutofillPriority == AutofillPriority.Low) { TranslationKey = "RucksackAutofillLowPriorityToolTip"; } else if (RS.AutofillPriority == AutofillPriority.High) { TranslationKey = "RucksackAutofillHighPriorityToolTip"; } else { throw new NotImplementedException(string.Format("Unrecognized Rucksack AutofillPriority: {0}", RS.AutofillPriority.ToString())); } } else { TranslationKey = "RucksackAutofillOffToolTip"; } ButtonToolTip = ItemBagsMod.Translate(TranslationKey); } } if (!string.IsNullOrEmpty(ButtonToolTip)) { int Margin = 16; Vector2 ToolTipSize = Game1.smallFont.MeasureString(ButtonToolTip); DrawBox(b, HoveredButtonBounds.Value.Right, HoveredButtonBounds.Value.Top, (int)(ToolTipSize.X + Margin * 2), (int)(ToolTipSize.Y + Margin * 2)); b.DrawString(Game1.smallFont, ButtonToolTip, new Vector2(HoveredButtonBounds.Value.Right + Margin, HoveredButtonBounds.Value.Top + Margin), Color.Black); } } if (IsRightSidebarVisible) { string ButtonToolTip = ""; if (HoveredButton.Value == SidebarButton.HelpInfo) { ButtonToolTip = ItemBagsMod.Translate("HelpInfoToolTip"); } else if (HoveredButton.Value == SidebarButton.CustomizeIcon) { ButtonToolTip = ItemBagsMod.Translate("CustomizeIconToolTip"); } if (!string.IsNullOrEmpty(ButtonToolTip)) { int Margin = 16; Vector2 ToolTipSize = Game1.smallFont.MeasureString(ButtonToolTip); DrawBox(b, HoveredButtonBounds.Value.Left - (int)(ToolTipSize.X + Margin * 2), HoveredButtonBounds.Value.Top, (int)(ToolTipSize.X + Margin * 2), (int)(ToolTipSize.Y + Margin * 2)); b.DrawString(Game1.smallFont, ButtonToolTip, new Vector2(HoveredButtonBounds.Value.Left - Margin - ToolTipSize.X, HoveredButtonBounds.Value.Top + Margin), Color.Black); } } } } upperRightCloseButton.draw(b); if (!Game1.options.hardwareCursor && !Game1.options.gamepadControls) { drawMouse(b); } } catch (Exception ex) { ItemBagsMod.ModInstance.Monitor.Log(string.Format("Unhandled error in ItemBagMenu.Draw: {0}", ex.Message), LogLevel.Error); } }
public void Draw(SpriteBatch b) { if (IsJojaMember) { Rectangle BackgroundDestination = new Rectangle(Padding, Padding, RelativeBounds.Width - Padding * 2, RelativeBounds.Height - Padding * 2).GetOffseted(TopLeftScreenPosition); b.Draw(TextureHelpers.JojaCDForm, BackgroundDestination, new Rectangle(0, 0, TextureHelpers.JojaCDForm.Width, TextureHelpers.JojaCDForm.Height - 16), Color.White); string Text = "You Traitor!"; SpriteFont Font = Game1.smallFont; Vector2 TextSize = Font.MeasureString(Text) * 2; int JojaSuxDestinationSize = 128; int BoxPadding = 32; int BoxWidth = Math.Max((int)TextSize.X, JojaSuxDestinationSize) + BoxPadding * 2; int BoxHeight = (int)TextSize.Y + BoxPadding * 2 + JojaSuxDestinationSize - JojaSuxDestinationSize / 8; Rectangle BoxDestination = new Rectangle((RelativeBounds.Width - BoxWidth) / 2, (RelativeBounds.Height - BoxHeight) / 2, BoxWidth, BoxHeight).GetOffseted(TopLeftScreenPosition); DrawHelpers.DrawBox(b, BoxDestination); Vector2 TextDestination = new Vector2(BoxDestination.X + (BoxDestination.Width - TextSize.X) / 2, BoxDestination.Y + BoxPadding); b.DrawString(Font, Text, TextDestination, Color.Black, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f); Rectangle JojaSuxSourcePosition = new Rectangle(258, 640, 32, 32); Rectangle JojaSuxDestination = new Rectangle(BoxDestination.X + (BoxDestination.Width - JojaSuxDestinationSize) / 2, BoxDestination.Bottom - BoxPadding - JojaSuxDestinationSize, JojaSuxDestinationSize, JojaSuxDestinationSize); b.Draw(Game1.mouseCursors, JojaSuxDestination, JojaSuxSourcePosition, Color.White); } else { // Draw room names foreach (KeyValuePair <BundleRoom, Rectangle> RoomHeader in RoomHeaderPositions) { bool IsCompleted = RoomHeader.Key.IsCompleted; Rectangle Position = RoomHeader.Value.GetOffseted(TopLeftScreenPosition); DrawHelpers.DrawBox(b, Position); string Text = RoomHeader.Key.DisplayName; Vector2 Size = RoomHeaderFont.MeasureString(Text) * RoomHeaderScale; b.DrawString(RoomHeaderFont, Text, new Vector2(Position.X + (Position.Width - Size.X) / 2, Position.Y + (Position.Height - Size.Y) / 2), IsCompleted ? Color.Green : Color.Black, 0f, Vector2.Zero, RoomHeaderScale, SpriteEffects.None, 1f); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Position.Right - SlotSize / 6 - CheckMark.Width * CheckMarkScale, Position.Bottom - SlotSize / 6 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } // Draw the backgrounds of each slot foreach (Rectangle LockedSlot in LockedSlotPositions) { b.Draw(Game1.menuTexture, LockedSlot.GetOffseted(TopLeftScreenPosition), new Rectangle(64, 896, 64, 64), Color.White); } foreach (KeyValuePair <BundleItem, Rectangle> ItemSlot in ItemSlotPositions) { Rectangle TexturePosition; if (ItemSlot.Key.IsCompleted) { TexturePosition = SlotDarkBackground; } else { Object Item = ItemPlaceholders[ItemSlot.Key]; if (Item.Stack == 0) { TexturePosition = SlotLightBackground; } else if (Item.Stack == ItemSlot.Key.Quantity) { TexturePosition = SlotDarkBackground; } else { TexturePosition = SlotMediumBackground; } } b.Draw(TextureHelpers.JunimoNoteTexture, ItemSlot.Value.GetOffseted(TopLeftScreenPosition), TexturePosition, Color.White); } foreach (KeyValuePair <BundleTask, Rectangle> TaskHeader in TaskHeaderPositions) { Rectangle TexturePosition = SlotMediumBackground; if (TaskHeader.Key.IsCompleted) { TexturePosition = SlotDarkBackground; } b.Draw(TextureHelpers.JunimoNoteTexture, TaskHeader.Value.GetOffseted(TopLeftScreenPosition), TexturePosition, Color.White); } // Draw the Task headers foreach (KeyValuePair <BundleTask, Rectangle> TaskHeader in TaskHeaderPositions) { bool IsCompleted = TaskHeader.Key.IsCompleted; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = TaskHeader.Key == HoveredBundleTask; if (IsHovered) { Rectangle Destination = TaskHeader.Value.GetOffseted(TopLeftScreenPosition); Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } Rectangle Slot = TaskHeader.Value; Rectangle ScaledSlot = new Rectangle(Slot.X + Slot.Width / 6, Slot.Y + Slot.Height / 6, Slot.Width - Slot.Width / 3, Slot.Height - Slot.Height / 3); Rectangle SourceIconPosition = IsCompleted ? TaskHeader.Key.SpriteSmallIconOpenedPosition : TaskHeader.Key.SpriteSmallIconClosedPosition; b.Draw(TextureHelpers.JunimoNoteTexture, ScaledSlot.GetOffseted(TopLeftScreenPosition), SourceIconPosition, Color.White); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Slot.Right - 1 - CheckMark.Width * CheckMarkScale, Slot.Bottom - 1 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale).GetOffseted(TopLeftScreenPosition); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } // Draw the items of each slot foreach (KeyValuePair <BundleItem, Rectangle> ItemSlot in ItemSlotPositions) { Rectangle Destination = ItemSlot.Value.GetOffseted(TopLeftScreenPosition); Object CurrentItem; if (!ItemPlaceholders.TryGetValue(ItemSlot.Key, out CurrentItem)) { CurrentItem = ItemSlot.Key.ToObject(); } bool IsCompleted = ItemSlot.Key.IsCompleted; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = ItemSlot.Key == HoveredBundleItem; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 || IsCompleted ? Color.White * 0.30f : Color.White; bool DrawQuantity = CurrentItem.Stack > 0 && !IsCompleted && ItemSlot.Key.Quantity > 1; DrawHelpers.DrawItem(b, Destination, CurrentItem, DrawQuantity, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= ItemSlot.Key.Quantity ? Color.Green : Color.White); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Destination.Right - 1 - CheckMark.Width * CheckMarkScale, Destination.Bottom - 1 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } } }
public void Draw(SpriteBatch b) { //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Rucksack.NumSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(128, 128, 64, 64), Color.White); } else if (ShowLockedSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(64, 896, 64, 64), Color.White); } } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { Rectangle Destination = SlotBounds[i]; if (i < PlaceholderItems.Count) { Object CurrentItem = PlaceholderItems[i]; // Apply some visual feedback if the bag has a large grid of items: // If this item was recently added to the bag or had its quantity changed, Draw a thin green border around it for a couple seconds if (Rucksack.NumSlots >= 24 && TempVisualFeedback.TryGetValue(CurrentItem, out DateTime ModifiedTime)) { TimeSpan TotalDuration = TimeSpan.FromSeconds(2.0); TimeSpan Elapsed = DateTime.Now.Subtract(ModifiedTime); if (Elapsed < TotalDuration) { TimeSpan RemainingDuration = TotalDuration.Subtract(Elapsed); float Transparency = Math.Min(1.0f, (float)(RemainingDuration.TotalSeconds / 1.0)); Color HighlightColor = Color.DarkGreen * Transparency; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.40f); int BorderThickness = Math.Max(Destination.Width / 8, 6); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } } // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } else if (Destination == HoveredSlot) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } } // Draw the sidebar buttons if (IsRightSidebarVisible) { // Draw Sort Property icons b.Draw(Game1.menuTexture, SortingPropertyBounds, new Rectangle(128, 128, 64, 64), Color.White); if (Rucksack.SortProperty == SortingProperty.Time) { // Clock icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(410, 501, 9, 9); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Name) { // Alphabetical letter icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(279, 25, 9, 9); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Id) { // Open book icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(146, 447, 11, 10); int IconSize = (int)(SourceRect.Width * 1.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Category) { // Magnifying glass icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(80, 0, 13, 13); int IconSize = (int)(SourceRect.Width * 1.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Quantity) { // Large # '9' icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(537, 136, 7, 8); int IconSize = (int)(SourceRect.Width * 2.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.SingleValue) { // 'G' with golden background icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(408, 476, 9, 11); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.StackValue) { // Big bag of gold icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(397, 1941, 19, 20); int IconSize = (int)(SourceRect.Width * 1.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Similarity) { // Star icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(310, 392, 16, 16); int IconSize = (int)(SourceRect.Width * 1.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } // Draw Sort Order icons b.Draw(Game1.menuTexture, SortingOrderBounds, new Rectangle(128, 128, 64, 64), Color.White); if (Rucksack.SortOrder == SortingOrder.Ascending) { Rectangle ArrowUpIconSourceRect = new Rectangle(421, 459, 12, 12); int ArrowSize = (int)(ArrowUpIconSourceRect.Width * 1.5 / 32.0 * SortingOrderBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingOrderBounds.X + (SortingOrderBounds.Width - ArrowSize) / 2, SortingOrderBounds.Y + (SortingOrderBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowUpIconSourceRect, Color.White); } else if (Rucksack.SortOrder == SortingOrder.Descending) { Rectangle ArrowDownIconSourceRect = new Rectangle(421, 472, 12, 12); int ArrowSize = (int)(ArrowDownIconSourceRect.Width * 1.5 / 32.0 * SortingOrderBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingOrderBounds.X + (SortingOrderBounds.Width - ArrowSize) / 2, SortingOrderBounds.Y + (SortingOrderBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowDownIconSourceRect, Color.White); } // Draw a yellow border around the hovered sidebar button if (HoveredContentsButton.HasValue) { Rectangle HoveredBounds = HoveredContentsButtonBounds.Value; Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, HoveredBounds, Color.White * 0.25f); int BorderThickness = HoveredBounds.Width / 16; DrawHelpers.DrawBorder(b, HoveredBounds, BorderThickness, HighlightColor); } } }
public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null) { if (texture != null) { if (aspectRatio == 0) { aspectRatio = texture.Width / (float)texture.Height; } } if (Texture.HasValue() && (texture == null || loadedTexture != Texture.Value())) { loadedTexture = Texture.Value(); texture = Solids.Instance.AssetLibrary.GetTexture(loadedTexture, true); } Rectangle rect = screen.Translate(ActualPosition).ToRectangle(); //.Move(scrollOffset) if (ScalingMode.Value == ScaleMode.BestFit) { float newWidth = rect.Width; float newHeight = newWidth / aspectRatio; if (newHeight > rect.Height) { newHeight = rect.Height; newWidth = newHeight * aspectRatio; } float xOffset = (rect.Width - newWidth) / 2f; float yOffset = (rect.Height - newHeight) / 2f; rect = new Rectangle((int)(rect.X + xOffset), (int)(rect.Y + yOffset), (int)newWidth, (int)newHeight); } if (ScalingMode.Value == ScaleMode.Fill) { float newWidth = rect.Width; float newHeight = newWidth / aspectRatio; if (newHeight < rect.Height) { newHeight = rect.Height; newWidth = newHeight * aspectRatio; } float xOffset = (rect.Width - newWidth) / 2f; float yOffset = (rect.Height - newHeight) / 2f; rect = new Rectangle((int)(rect.X + xOffset), (int)(rect.Y + yOffset), (int)newWidth, (int)newHeight); } if (ScalingMode.Value == ScaleMode.None) { rect.Width = texture.Width; rect.Height = texture.Height; } if (texture != null) { Color c = Color.White; if (Colorize.HasValue()) { if (Colorize.Value() != null) { c = Colorize.Value().Value; } } using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { if (clip == null) { rect = new Rectangle(rect.X + (int)(rect.Width / 2f), rect.Y + (int)(rect.Height / 2f), rect.Width, rect.Height); spriteBatch.Draw(texture, rect, null, c * opacity, Rotation.Value, new Vector2(texture.Width / 2, texture.Height / 2), SpriteEffects.None, 1f); } else { FloatRectangle?tclip = screen.Translate(clip); Rectangle source = new Rectangle(0, 0, texture.Width, texture.Height); (Rectangle position, Rectangle? source)translator = TextureHelpers.GetAdjustedDestAndSourceAfterClip(new FloatRectangle(rect), source, tclip); using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { spriteBatch.Draw(texture, translator.position, translator.source, c * opacity, Rotation.Value, new Vector2(translator.source.Value.Width / 2f, translator.source.Value.Height / 2f), SpriteEffects.None, 1f); } } } } }
public void Draw(SpriteBatch b) { if (IsEmptyMenu) { return; } //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Orange), Bounds, Color.White); // Draw column headers for (int i = 0; i < ColumnHeaderBounds.Count; i++) { Rectangle Destination = ColumnHeaderBounds[i]; b.Draw(Game1.menuTexture, Destination, new Rectangle(64, 896, 64, 64), Color.White); Rectangle IconDestination = new Rectangle(Destination.X + Destination.Width / 4, Destination.Y + Destination.Height / 4, Destination.Width / 2, Destination.Height / 2); ColumnType Type = (ColumnType)(i % ColumnsPerGroup); if (Type == ColumnType.RowValue) { //Could also use Game1.mouseCursors with SourceSprite = new Rectangle(280, 411, 16, 16); b.Draw(GoldIconTexture, IconDestination, GoldIconSourceRect, Color.White); } else { Rectangle SourceRect = ItemBag.QualityIconTexturePositions[ConvertColumnTypeToObjectQuality(Type)]; b.Draw(Game1.mouseCursors, IconDestination, SourceRect, Color.White); } } // Draw cells foreach (var KVP in SlotBounds) { int ItemId = KVP.Key; foreach (var KVP2 in KVP.Value) { ColumnType ColumnType = KVP2.Key; Rectangle Destination = KVP2.Value; b.Draw(Game1.menuTexture, Destination, new Rectangle(128, 128, 64, 64), Color.White); // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } if (ColumnType != ColumnType.RowValue) { ObjectQuality Quality = ConvertColumnTypeToObjectQuality(ColumnType); Object CurrentItem = Placeholders[ItemId][Quality]; float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); OnItemSlotRendered?.Invoke(this, new ItemSlotRenderedEventArgs(b, Destination, CurrentItem, IsHovered)); } else { // Sum up the value of all different qualities of this item int SummedValue = Placeholders[ItemId].Values.Sum(x => x.Stack * ItemBag.GetSingleItemPrice(x)); int NumDigits = DrawHelpers.GetNumDigits(SummedValue); // Compute width/height of the number float ValueScale; int ValueWidth, ValueHeight, CurrentIteration = 0; do { ValueScale = (2.7f - CurrentIteration * 0.1f) * Destination.Width / (float)BagInventoryMenu.DefaultInventoryIconSize; ValueWidth = (int)DrawHelpers.MeasureNumber(SummedValue, ValueScale); ValueHeight = (int)(DrawHelpers.TinyDigitBaseHeight * ValueScale); CurrentIteration++; } while (ValueWidth > Destination.Width * 1.04); // * 1.04 to let the value extend very slightly outside the bounds of the slot // Draw the number in the center of the slot Vector2 TopLeftPosition = new Vector2(Destination.X + (Destination.Width - ValueWidth) / 2 + 1, Destination.Y + (Destination.Height - ValueHeight) / 2); Color ValueColor = GetValueColor(SummedValue); Utility.drawTinyDigits(SummedValue, b, TopLeftPosition, ValueScale, 0f, ValueColor); } } } }
public static Vector2 DrawFontAsset( SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, string text, Color?fontColor, FloatRectangle?position, float fontSize, float?lineHeight, string fontName, bool pseudoAntiAlias, bool wordWrap, FontJustification justification, float fontMargin, Thickness margin = null, Color?outlineColor = null, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null, int?caretPos = null, bool multiLine = false, Rectangle?scissorRect = null) { if (position == null) { return(Vector2.Zero); } if (string.IsNullOrWhiteSpace(text)) { return(Vector2.Zero); } List <string> textValues = new List <string> { text }; if (multiLine) { textValues = text.ToList(); } if (fontSize == 0) { fontSize = 24; } float lHeight = fontSize * 1.25f; if (lineHeight.HasValue) { lHeight = lineHeight.Value; } float translatedBaseSize = screen.Translate(new Vector2(1f, 1f)).Y; float fontSizeRatio = (translatedBaseSize / 1080f); float translatedFontSize = fontSizeRatio * fontSize; FontFamily fontFamily = Solids.Instance.Fonts.Fonts[fontName]; if (fontFamily == null) { return(Vector2.Zero); } string currentKey = translatedFontSize.ToString() + fontFamily.ToString(); BMFont myFont = fontFamily.GetFont((int)translatedFontSize); Vector2 sizeOfI = myFont.MeasureString("Igj'#" + FontSystem.MDL2Symbols.Download.AsChar()); float translatedWidth = screen.Translate(position).Value.Width; float wordWrapWidth = translatedWidth; if (margin != null) { wordWrapWidth = wordWrapWidth - screen.Translate(new Vector2(margin.Left + margin.Right, 0)).X; position = new FloatRectangle(position.Value.X, position.Value.Y + margin.Top, position.Value.Width, position.Value.Height); } Vector2 size = myFont.MeasureString(text); float scale = translatedFontSize / sizeOfI.Y; if (wordWrap && multiLine) { List <string> lines = textValues.ToList(); textValues = new List <string>(); string reconstructedLine = ""; foreach (string line in lines) { string[] words = line.Split(' '); for (int i = 0; i < words.Length; i++) { string withoutCurrentWord = reconstructedLine; reconstructedLine = reconstructedLine + words[i] + " "; Vector2 wwSize = myFont.MeasureString(reconstructedLine); if (wwSize.X * scale > wordWrapWidth) { textValues.Add(withoutCurrentWord); reconstructedLine = ""; i = i - 1; } } } textValues.Add(reconstructedLine); } float ulHeight = lHeight / translatedBaseSize; Vector2 calcSize = Vector2.Zero; for (int i = 0; i < textValues.Count; i++) { FloatRectangle positionValue = new FloatRectangle(position.Value.X, position.Value.Y + (ulHeight * i), position.Value.Width, ulHeight); FloatRectangle fontPos = new FloatRectangle(positionValue.X, positionValue.Y + fontMargin, positionValue.Width, positionValue.Height - (fontMargin * 2f)); string textValue = textValues[i]; FloatRectangle?tclip = screen.Translate(clip); FloatRectangle positionRectangle = new FloatRectangle(); FloatRectangle translatedPosition = screen.Translate(fontPos).Value; if (tclip.HasValue) { if (translatedPosition.Right < tclip.Value.X || translatedPosition.X > tclip.Value.Right) { return(Vector2.Zero); } } if (string.IsNullOrWhiteSpace(fontName)) { return(Vector2.Zero); } float width = size.X * scale; switch (justification) { case FontJustification.Left: { positionRectangle = new FloatRectangle(translatedPosition.X, translatedPosition.Y, width, translatedPosition.Height); break; } case FontJustification.Right: { positionRectangle = new FloatRectangle(translatedPosition.Right - width, translatedPosition.Y, width, translatedPosition.Height); break; } case FontJustification.Center: { positionRectangle = new FloatRectangle(translatedPosition.X + (translatedPosition.Width / 2f) - (width / 2f), translatedPosition.Y, width, translatedPosition.Height); break; } } if (caretPos != null) { using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch, scissorRect: tclip)) { float actualCarotPos = (width / text.Length) * caretPos.Value; float oppax = (DateTime.Now.Millisecond % 250) / 250f; spriteBatch.DrawLine( new Vector2(positionRectangle.X + actualCarotPos, positionRectangle.Y), new Vector2(positionRectangle.X + actualCarotPos, positionRectangle.Bottom), Color.White * oppax, tclip, 1f); } } Rectangle source = new Rectangle(0, 0, (int)size.X, (int)size.Y); tclip = tclip?.Clamp(scissorRect); (Rectangle position, Rectangle? source)translator = TextureHelpers.GetAdjustedDestAndSourceAfterClip(positionRectangle, source, tclip); Solids.Instance.SpriteBatch.Scissor = tclip.ToRectangle(); Rectangle tmp = Solids.Instance.Bounds; if (tclip.HasValue) { tmp = tclip.Clamp(scissorRect).ToRectangle; } Solids.Instance.SpriteBatch.Scissor = tmp; using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch)) { if ((pseudoAntiAlias || outlineColor.HasValue)) { Color?cl = fontColor * opacity * 0.3f; if (outlineColor.HasValue) { cl = outlineColor.Value * opacity; } for (int y = -1; y <= 1; y = y + 2) { for (int x = -1; x <= 1; x = x + 2) { myFont.DrawText(Solids.Instance.SpriteBatch, translator.position.X + x, translator.position.Y + y, textValue, cl, scale); } } } myFont.DrawText(Solids.Instance.SpriteBatch, translator.position.X, translator.position.Y, textValue, fontColor * opacity, scale); calcSize = new Vector2(position.Value.Width, calcSize.Y + lHeight); } Solids.Instance.SpriteBatch.Scissor = null; } float actHeight = screen.Untranslate(calcSize.Y); if (margin != null) { calcSize.Y = calcSize.Y + margin.Bottom; } return(new Vector2(position.Value.Width, actHeight)); }