Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 98 additions & 9 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private List<CurrencyExchangeCurrencyPickerCurrencyOption>
private bool _currencyExchangeItemsCacheInitialized;
private DateTime _nextCurrencyItemsRefreshUtc = DateTime.MinValue;
private int _currencyItemsVersion;
private int _lastExclusionsRevision;

private readonly List<CurrencyExchangeCurrencyPickerCurrencyOption>
_displayItemsCache = [];
Expand Down Expand Up @@ -176,8 +177,19 @@ private List<CurrencyExchangeCurrencyPickerCurrencyOption>

var now = DateTime.UtcNow;

if (_currencyExchangeItemsCacheInitialized &&
now < _nextCurrencyItemsRefreshUtc)
/*
* An exclusion added or removed in either editor has to show up
* on the next frame rather than whenever the refresh interval
* happens to elapse.
*/
if (_lastExclusionsRevision != Settings.ExclusionsRevision)
{
_lastExclusionsRevision = Settings.ExclusionsRevision;
_nextCurrencyItemsRefreshUtc = DateTime.MinValue;
_displayItemsSourceVersion = -1;
}
else if (_currencyExchangeItemsCacheInitialized &&
now < _nextCurrencyItemsRefreshUtc)
{
return _currencyExchangeItemsCache;
}
Expand Down Expand Up @@ -301,6 +313,31 @@ private void DrawOwnedItemsUi(
return;
}

if (ImGui.BeginTabBar("SellMyShitTabs"))
{
if (ImGui.BeginTabItem("Owned Items"))
{
DrawOwnedItemsTab(ownedItems);

ImGui.EndTabItem();
}

if (ImGui.BeginTabItem("Exclusions"))
{
DrawExclusionsTab();

ImGui.EndTabItem();
}

ImGui.EndTabBar();
}

ImGui.End();
}

private void DrawOwnedItemsTab(
List<CurrencyExchangeCurrencyPickerCurrencyOption> ownedItems)
{
DrawFilterControls();

var filteredItems =
Expand All @@ -311,23 +348,46 @@ private void DrawOwnedItemsUi(

ImGui.Separator();

var childSize = new NumVector2(
Settings.WindowWidth.Value,
Settings.WindowHeight.Value);

if (ImGui.BeginChild(
"CurrencyOwnedItemsChild",
childSize,
GetTabChildSize(),
ImGuiChildFlags.None,
ImGuiWindowFlags.None))
{
DrawOwnedItemsTable(filteredItems);
}

ImGui.EndChild();
ImGui.End();
}

/*
* The editor itself lives in Settings so the plugin menu and this tab
* render the same list and the same input buffer.
*/
private void DrawExclusionsTab()
{
ImGui.Text(
$"Excluded: {Settings.ExcludedCurrencyCount}");

ImGui.Separator();

if (ImGui.BeginChild(
"CurrencyExclusionsChild",
GetTabChildSize(),
ImGuiChildFlags.None,
ImGuiWindowFlags.None))
{
Settings.DrawExcludedCurrenciesEditor();
}

ImGui.EndChild();
}

private NumVector2 GetTabChildSize() =>
new(
Settings.WindowWidth.Value,
Settings.WindowHeight.Value);

private void DrawFilterControls()
{
ImGui.InputText(
Expand Down Expand Up @@ -428,10 +488,16 @@ private unsafe void DrawOwnedItemsTable(
"Owned", ownedTableFlags
);

/*
* Sized explicitly: auto-fit measures the widest cell drawn, so a
* clipped Sell + X pair can settle into a column too narrow to
* ever show the X again.
*/
ImGui.TableSetupColumn(
"Action",
ImGuiTableColumnFlags.WidthFixed |
ImGuiTableColumnFlags.NoSort);
ImGuiTableColumnFlags.NoSort,
GetActionColumnWidth());

// ImGui erzeugt die klickbaren Header und Sortierpfeile.
ImGui.TableHeadersRow();
Expand Down Expand Up @@ -491,6 +557,18 @@ private unsafe void ApplyImGuiTableSorting()

sortSpecs.SpecsDirty = false;
}
private static float GetActionColumnWidth()
{
var style =
ImGui.GetStyle();

return ImGui.CalcTextSize("Sell").X +
ImGui.CalcTextSize("X").X +
style.FramePadding.X * 4 +
style.ItemSpacing.X +
style.CellPadding.X * 2;
}

private static float GetSortHeaderWidth(string label)
{
var textWidth =
Expand Down Expand Up @@ -534,6 +612,17 @@ private void DrawOwnedItemRow(

if (ImGui.Button($"Sell##{index}"))
StartSellSequence(item);

ImGui.SameLine();

var itemName =
GetItemName(item);

if (ImGui.Button($"X##Exclude{index}"))
Settings.AddExcludedCurrency(itemName);

if (ImGui.IsItemHovered())
ImGui.SetTooltip($"Exclude {itemName}");
}

private int CompareItems(
Expand Down
75 changes: 53 additions & 22 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Settings()
101,
InterfaceGroupId)]
public RangeNode<int> WindowWidth { get; set; } =
new(520, 300, 1200);
new(660, 300, 1600);

[Menu(
"Window height",
Expand Down Expand Up @@ -360,6 +360,19 @@ public Settings()
public TextNode ExcludedCurrenciesJson { get; set; } =
new(DefaultExcludedCurrenciesJson);

/*
* Bumped on every change to the list, from either editor, so the
* owned-items window can drop its caches and redraw immediately.
*/
[Newtonsoft.Json.JsonIgnore]
[HideInReflection]
public int ExclusionsRevision { get; private set; }

[Newtonsoft.Json.JsonIgnore]
[HideInReflection]
public int ExcludedCurrencyCount =>
GetExcludedCurrencies().Count;

public bool IsCurrencyExcluded(string currencyName)
{
if (string.IsNullOrWhiteSpace(currencyName))
Expand All @@ -372,7 +385,42 @@ public bool IsCurrencyExcluded(string currencyName)
StringComparison.OrdinalIgnoreCase));
}

private void DrawExcludedCurrenciesEditor()
/// <summary>
/// Adds a currency to the exclusion list. Returns false when the name
/// is blank or already excluded.
/// </summary>
public bool AddExcludedCurrency(string currencyName)
{
var value = currencyName?.Trim();

if (string.IsNullOrWhiteSpace(value))
return false;

var excludedCurrencies =
GetExcludedCurrencies();

var alreadyExists =
excludedCurrencies.Any(existing =>
string.Equals(
existing?.Trim(),
value,
StringComparison.OrdinalIgnoreCase));

if (alreadyExists)
return false;

excludedCurrencies.Add(value);
SaveExcludedCurrencies();

return true;
}

/*
* Rendered both by the settings menu CustomNode and by the
* Exclusions tab of the owned-items window. ImGui ids are scoped per
* window, so the two copies never collide.
*/
public void DrawExcludedCurrenciesEditor()
{
var excludedCurrencies = GetExcludedCurrencies();

Expand Down Expand Up @@ -444,26 +492,7 @@ private void DrawExcludedCurrenciesEditor()

private void AddExcludedCurrency()
{
var value = _newExcludedCurrency?.Trim();

if (string.IsNullOrWhiteSpace(value))
return;

var excludedCurrencies =
GetExcludedCurrencies();

var alreadyExists =
excludedCurrencies.Any(existing =>
string.Equals(
existing?.Trim(),
value,
StringComparison.OrdinalIgnoreCase));

if (!alreadyExists)
{
excludedCurrencies.Add(value);
SaveExcludedCurrencies();
}
AddExcludedCurrency(_newExcludedCurrency);

_newExcludedCurrency = string.Empty;
}
Expand Down Expand Up @@ -521,6 +550,8 @@ private void SaveExcludedCurrencies()
{
_excludedCurrencies ??= [];

ExclusionsRevision++;

var serialized =
JsonConvert.SerializeObject(
_excludedCurrencies);
Expand Down