mirror of
https://github.com/OMGeeky/ItemChecklist.git
synced 2025-12-28 23:36:09 +01:00
v0.6.1, Fix #10 add completion bar to ingame ui
This commit is contained in:
@@ -18,7 +18,7 @@ namespace ItemChecklist
|
||||
[Header("Automatic Settings")]
|
||||
// non-player specific stuff:
|
||||
|
||||
[DefaultValue(typeof(Vector2), "475, 350")]
|
||||
[DefaultValue(typeof(Vector2), "475, 370")]
|
||||
[Range(0f, 1920f)]
|
||||
[Label("Item Checklist Size")]
|
||||
[Tooltip("Size of the Item Checklist UI. This will automatically save, no need to adjust")]
|
||||
|
||||
@@ -18,6 +18,7 @@ using Terraria.UI;
|
||||
using UIItemSlot = ItemChecklist.UIElements.UIItemSlot;
|
||||
using Steamworks;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ItemChecklist
|
||||
{
|
||||
@@ -37,6 +38,7 @@ namespace ItemChecklist
|
||||
internal NewUITextBox itemDescriptionFilter;
|
||||
internal SharedUI sharedUI;
|
||||
public UIGrid checklistGrid;
|
||||
public UICollectionBar collectionBar;
|
||||
//public static SortModes sortMode = SortModes.TerrariaSort;
|
||||
|
||||
float spacing = 8f;
|
||||
@@ -80,7 +82,7 @@ namespace ItemChecklist
|
||||
mainPanel.Width.Set(475f, 0f); // + 30
|
||||
mainPanel.MinWidth.Set(415f, 0f);
|
||||
mainPanel.MaxWidth.Set(884f, 0f);
|
||||
mainPanel.Height.Set(350, 0f);
|
||||
mainPanel.Height.Set(370, 0f);
|
||||
mainPanel.MinHeight.Set(263, 0f);
|
||||
mainPanel.MaxHeight.Set(1000, 0f);
|
||||
//mainPanel.BackgroundColor = Color.LightBlue;
|
||||
@@ -187,19 +189,26 @@ namespace ItemChecklist
|
||||
checklistGrid.alternateSort = ItemGridSort;
|
||||
checklistGrid.Top.Pixels = top;
|
||||
checklistGrid.Width.Set(-25f, 1f);
|
||||
checklistGrid.Height.Set(-top, 1f);
|
||||
checklistGrid.Height.Set(-top - 24, 1f);
|
||||
checklistGrid.ListPadding = 2f;
|
||||
checklistPanel.Append(checklistGrid);
|
||||
|
||||
FixedUIScrollbar checklistListScrollbar = new FixedUIScrollbar();
|
||||
checklistListScrollbar.SetView(100f, 1000f);
|
||||
checklistListScrollbar.Top.Pixels = top;
|
||||
checklistListScrollbar.Height.Set(-top, 1f);
|
||||
checklistListScrollbar.Height.Set(-top - 24, 1f);
|
||||
checklistListScrollbar.HAlign = 1f;
|
||||
checklistPanel.Append(checklistListScrollbar);
|
||||
checklistGrid.SetScrollbar(checklistListScrollbar);
|
||||
|
||||
// Checklistlist populated when the panel is shown: UpdateCheckboxes()
|
||||
collectionBar = new UICollectionBar() {
|
||||
Width = new StyleDimension(0f, 1f),
|
||||
Height = new StyleDimension(15f, 0f),
|
||||
VAlign = 1f,
|
||||
};
|
||||
|
||||
checklistPanel.Append(collectionBar);
|
||||
|
||||
Append(mainPanel);
|
||||
|
||||
@@ -338,6 +347,7 @@ namespace ItemChecklist
|
||||
if (!updateNeeded) { return; }
|
||||
updateNeeded = false;
|
||||
checklistGrid.Clear();
|
||||
collectionBar.RecalculateBars();
|
||||
|
||||
if (buttonsHaveDummyTextures)
|
||||
{
|
||||
|
||||
130
UIElements/UICollectionBar.cs
Normal file
130
UIElements/UICollectionBar.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria.UI;
|
||||
using Terraria.GameContent.Bestiary;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria.GameContent;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
// Adapted from Terraria.ModLoader.UI.UIBestiaryBar
|
||||
class UICollectionBar : UIElement
|
||||
{
|
||||
private class UICollectionBarItem
|
||||
{
|
||||
internal readonly string Tooltop;
|
||||
internal readonly int EntryCount;
|
||||
internal readonly int CompletedCount;
|
||||
internal readonly Color DrawColor;
|
||||
|
||||
public UICollectionBarItem(string tooltop, int entryCount, int completedCount, Color drawColor) {
|
||||
Tooltop = tooltop;
|
||||
EntryCount = entryCount;
|
||||
CompletedCount = completedCount;
|
||||
DrawColor = drawColor;
|
||||
}
|
||||
}
|
||||
|
||||
private List<UICollectionBarItem> collectionBarItems;
|
||||
|
||||
public UICollectionBar() {
|
||||
collectionBarItems = new List<UICollectionBarItem>();
|
||||
|
||||
RecalculateBars();
|
||||
}
|
||||
|
||||
private readonly Color[] _colors = {
|
||||
new Color(232, 76, 61),//red
|
||||
new Color(155, 88, 181),//purple
|
||||
new Color(27, 188, 155),//aqua
|
||||
new Color(243, 156, 17),//orange
|
||||
new Color(45, 204, 112),//green
|
||||
new Color(241, 196, 15),//yellow
|
||||
};
|
||||
|
||||
public void RecalculateBars() {
|
||||
collectionBarItems.Clear();
|
||||
if (Main.gameMenu)
|
||||
return;
|
||||
|
||||
var ItemChecklistPlayer = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>();
|
||||
|
||||
//Add the bestiary total to the bar
|
||||
int total = ItemChecklistPlayer.totalItemsToFind;
|
||||
int totalCollected = ItemChecklistPlayer.totalItemsFound;
|
||||
collectionBarItems.Add(new UICollectionBarItem($"Total: {totalCollected}/{total} ({(float)totalCollected / total * 100f:N2}% Collected)", total, totalCollected, Main.OurFavoriteColor));
|
||||
|
||||
var data = ItemChecklistPlayer.foundItem.Zip(ContentSamples.ItemsByType.Values);
|
||||
//.GroupBy(x=>x.Second.ModItem?.Mod.Name ?? "Terraria").ToDictionary(y=>y., x=>x);
|
||||
var items = data.Where(x => x.Second.ModItem == null).ToList();
|
||||
|
||||
//Add Terraria's item entries
|
||||
int collected = items.Count(x => x.First);
|
||||
collectionBarItems.Add(new UICollectionBarItem($"Terraria: {collected}/{items.Count} ({(float)collected / items.Count * 100f:N2}% Collected)", items.Count, collected, _colors[0]));
|
||||
|
||||
//Add the mod's item entries
|
||||
for (int i = 0; i < ModLoader.Mods.Length; i++) {
|
||||
items = data.Where(x => x.Second.ModItem?.Mod == ModLoader.Mods[i]).ToList();
|
||||
if (!items.Any()) // No Items added by mod.
|
||||
continue;
|
||||
collected = items.Count(x => x.First);
|
||||
collectionBarItems.Add(new UICollectionBarItem($"{ModLoader.Mods[i].DisplayName}: {collected}/{items.Count} ({(float)collected / items.Count * 100f:N2}% Collected)", items.Count, collected, _colors[i % _colors.Length]));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch sb) {
|
||||
int xOffset = 0;
|
||||
var rectangle = GetDimensions().ToRectangle();
|
||||
const int bottomHeight = 3; //The height of the total completion bar
|
||||
rectangle.Height -= bottomHeight;
|
||||
|
||||
bool drawHover = false;
|
||||
UICollectionBarItem hoverData = null;
|
||||
var ItemChecklistPlayer = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>();
|
||||
|
||||
//Draw the mod progress bars
|
||||
for (int i = 1; i < collectionBarItems.Count; i++) {
|
||||
var barData = collectionBarItems[i];
|
||||
|
||||
int offset = (int)(rectangle.Width * (barData.EntryCount / (float)ItemChecklistPlayer.totalItemsToFind));
|
||||
if (i == collectionBarItems.Count - 1) {
|
||||
offset = rectangle.Width - xOffset;
|
||||
}
|
||||
int width = (int)(offset * (barData.CompletedCount / (float)barData.EntryCount));
|
||||
|
||||
var drawArea = new Rectangle(rectangle.X + xOffset, rectangle.Y, width, rectangle.Height);
|
||||
var outlineArea = new Rectangle(rectangle.X + xOffset, rectangle.Y, offset, rectangle.Height);
|
||||
xOffset += offset;
|
||||
|
||||
sb.Draw(TextureAssets.MagicPixel.Value, outlineArea, barData.DrawColor * 0.3f);
|
||||
sb.Draw(TextureAssets.MagicPixel.Value, drawArea, barData.DrawColor);
|
||||
|
||||
if (!drawHover && outlineArea.Contains(new Point(Main.mouseX, Main.mouseY))) {
|
||||
drawHover = true;
|
||||
hoverData = barData;
|
||||
}
|
||||
}
|
||||
//Draw the bottom progress bar
|
||||
var bottomData = collectionBarItems[0];
|
||||
int bottomWidth = (int)(rectangle.Width * (bottomData.CompletedCount / (float)bottomData.EntryCount));
|
||||
var bottomDrawArea = new Rectangle(rectangle.X, rectangle.Bottom, bottomWidth, bottomHeight);
|
||||
var bottomOutlineArea = new Rectangle(rectangle.X, rectangle.Bottom, rectangle.Width, bottomHeight);
|
||||
|
||||
sb.Draw(TextureAssets.MagicPixel.Value, bottomOutlineArea, bottomData.DrawColor * 0.3f);
|
||||
sb.Draw(TextureAssets.MagicPixel.Value, bottomDrawArea, bottomData.DrawColor);
|
||||
|
||||
if (!drawHover && bottomOutlineArea.Contains(new Point(Main.mouseX, Main.mouseY))) {
|
||||
drawHover = true;
|
||||
hoverData = bottomData;
|
||||
}
|
||||
|
||||
if (drawHover && hoverData != null) {
|
||||
Main.instance.MouseText(hoverData.Tooltop, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user