protected override void DrawSelf(SpriteBatch spriteBatch) { // Drawing is being really weird, todo base.DrawSelf(spriteBatch); Texture2D texture = Main.buffTexture[Buff]; Vector2 position = GetDimensions().Position() + texture.Size() * (1f - 1f) / 2f; // Straight outta UIImage spriteBatch.Draw(texture, new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height), new Rectangle(0, 0, texture.Width, texture.Height), Disabled ? Color.DarkGray : Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f ); IEndlessBuffGridHolder parent = Parent as IEndlessBuffGridHolder; bool alwaysHighlight = (parent != null && parent.GetSelectedBuffHolder().Buff == Buff); if (ContainsPoint(Main.MouseScreen) || alwaysHighlight) { if (Main.mouseLeft && Main.mouseLeftRelease) { if (Parent is IEndlessBuffGridHolder grid) { grid.HandleBuffEntryClick(this); } } if (Main.mouseRight && Main.mouseRightRelease) { if (Parent is UIEndlessBuffGrid grid) { if (grid.GetSelectedBuffHolder().Buff == Buff) { Disabled = !Disabled; EndlessPotionPlayer player = Main.LocalPlayer.GetModPlayer <EndlessPotionPlayer>(); if (Disabled) { player.DisabledBuffs.Add(Buff); } else { player.DisabledBuffs.Remove(Buff); } } } } texture = PboneUtils.Textures.UI.BuffTogglerInventoryButton_MouseOver; position -= new Vector2(2); spriteBatch.Draw(texture, new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height), new Rectangle(0, 0, texture.Width, texture.Height), alwaysHighlight ? Color.White : Color.White * 0.33f, 0f, Vector2.Zero, SpriteEffects.None, 0f ); } }
public void DoEndlessBuffs(Player player) { EndlessPotionPlayer mPlayer = player.GetModPlayer <EndlessPotionPlayer>(); IEnumerable <DictionaryEntry> CastDict(IDictionary dictionary) { foreach (DictionaryEntry entry in dictionary) { yield return(entry); } } IEnumerable <object> CastList(IList list) { foreach (object item in list) { yield return(item); } } object lib = GetLibrary(player); if (lib != null) { Dictionary <string, object> books = CastDict((IDictionary)BooksField.GetValue(lib)) .ToDictionary(x => (string)x.Key, x => x.Value); foreach (object page in books.Values .Select(book => CastList((IList)PagesField.GetValue(book)).ToList()) .SelectMany(pages => pages)) { if (ItemsField.GetValue(page) is Item[] items) { mPlayer.ItemsToCountForEndlessBuffs.AddRange(CollectionHelper.FromArray(items, "Inventory")); } } } mPlayer.ExtensibleInventoryItemsStart = mPlayer.ItemsToCountForEndlessBuffs.Count - 1; }
public void Rebuild(UISearchBar mySearchBar, int rowAmount) { RemoveAllChildren(); EndlessPotionPlayer player = Main.LocalPlayer.GetModPlayer <EndlessPotionPlayer>(); string searchText = mySearchBar.IsEmpty ? "" : mySearchBar.Text; int counter = 0; Vector2 nextPosition = new Vector2(8); foreach (KeyValuePair <int, EndlessBuffSource> kvp in player.EndlessBuffSources) { string buffName = buffName = Lang.GetBuffName(kvp.Value.Item.buffType); string[] words = buffName.Split(' '); if (words.Any((s) => mySearchBar.IsEmpty ? true : s.StartsWith(searchText, StringComparison.OrdinalIgnoreCase))) { UIEndlessBuffEntry element = new UIEndlessBuffEntry(kvp.Key, kvp.Value); element.Left.Set(nextPosition.X, 0f); element.Top.Set(nextPosition.Y, 0f); if (player.DisabledBuffs.Contains(kvp.Key)) { element.Disabled = true; } nextPosition.X += 2 + 32; // 2 = padding, 32 = buff texture size if (counter > 0 && counter % rowAmount == 0) { nextPosition.X = 8; nextPosition.Y += 2 + 32; } Append(element); element.Parent = this; // Had to add this so the game doesn't bend over and die just because I ask it to properly work counter++; } } }