Skip to content

Commit

Permalink
Merge branch 'release/1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed Nov 14, 2024
2 parents 4864123 + 9b73c57 commit 7b42881
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 75 deletions.
15 changes: 5 additions & 10 deletions MarketBoardPlugin/Extensions/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MarketBoardPlugin.Extensions
{
using Lumina.Excel.GeneratedSheets;
using Lumina.Excel.Sheets;

/// <summary>
/// <see cref="ClassJobCategory"/> and <see cref="ClassJob"/> extensions.
Expand All @@ -18,21 +18,16 @@ public static class ClassExtensions
/// <param name="classJob">A <see cref="ClassJob"/>.</param>
/// <returns>
/// True if contained or classJob is null.
/// False if not contained or classJobCategory is null.
/// False if not contained.
/// </returns>
public static bool HasClass(this ClassJobCategory classJobCategory, ClassJob classJob)
public static bool HasClass(this ClassJobCategory classJobCategory, ClassJob? classJob)
{
if (classJobCategory == null)
{
return false;
}

if (classJob == null)
if (!classJob.HasValue)
{
return true;
}

return classJob.RowId switch
return classJob.Value.RowId switch
{
0 => classJobCategory.ADV,
1 => classJobCategory.GLA,
Expand Down
2 changes: 1 addition & 1 deletion MarketBoardPlugin/GUI/MarketBoardShoppingListWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void Draw()
int k = 0;
foreach (var item in this.Plugin.ShoppingList)
{
ImGui.Text(item.SourceItem.Name);
ImGui.Text(item.SourceItem.Name.ExtractText());
ImGui.NextColumn();
if (this.Plugin.Config.PriceIconShown)
{
Expand Down
100 changes: 54 additions & 46 deletions MarketBoardPlugin/GUI/MarketBoardWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ namespace MarketBoardPlugin.GUI
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using Dalamud.Utility;
using ImGuiNET;
using ImPlotNET;
using Lumina.Excel.GeneratedSheets;
using Lumina.Excel.Sheets;
using MarketBoardPlugin.Extensions;
using MarketBoardPlugin.Helpers;
using MarketBoardPlugin.Models.ShoppingList;
Expand Down Expand Up @@ -75,17 +76,17 @@ public class MarketBoardWindow : Window, IDisposable
private string searchString = string.Empty;
private string lastSearchString = string.Empty;

private ClassJob lastSelectedClassJob;
private ClassJob? lastSelectedClassJob;

private int lvlmin;
private int lastlvlmin;
private int lvlmax = 100;
private int lastlvlmax = 100;
private int itemCategory;
private int lastItemCategory;
private Item selectedItem;
private Item? selectedItem;

private ClassJob selectedClassJob;
private ClassJob? selectedClassJob;

private bool hQOnly;

Expand Down Expand Up @@ -226,7 +227,7 @@ public override void Draw()
if (this.searchString != this.lastSearchString || this.itemCategory != this.lastItemCategory
|| this.lastlvlmin != this.lvlmin
|| this.lastlvlmax != this.lvlmax
|| this.lastSelectedClassJob != this.selectedClassJob)
|| this.lastSelectedClassJob?.RowId != this.selectedClassJob?.RowId)
{
this.UpdateCategoriesAndItems();
}
Expand Down Expand Up @@ -302,12 +303,12 @@ public override void Draw()
ImGui.SameLine();
if (ImGui.BeginCombo(
"###ClassJobCombo",
this.selectedClassJob == null ? "All Classes" : this.selectedClassJob.Abbreviation))
this.selectedClassJob == null ? "All Classes" : this.selectedClassJob?.Abbreviation.ExtractText()))
{
void SelectClassJob(ClassJob classJob)
void SelectClassJob(ClassJob? classJob)
{
var selected = this.selectedClassJob == classJob;
if (ImGui.Selectable(classJob == null ? "All Classes" : classJob.Abbreviation, selected))
var selected = this.selectedClassJob?.RowId == classJob?.RowId;
if (ImGui.Selectable(classJob == null ? "All Classes" : classJob?.Abbreviation.ExtractText(), selected))
{
this.selectedClassJob = classJob;
}
Expand Down Expand Up @@ -356,13 +357,13 @@ void SelectClassJob(ClassJob classJob)
var sheet = this.plugin.DataManager.Excel.GetSheet<Item>();
foreach (var id in this.plugin.Config.History.ToArray())
{
var item = sheet.GetRow(id);
if (item == null)
var item = sheet.GetRowOrDefault(id);
if (!item.HasValue)
{
continue;
}

if (ImGui.Selectable($"{item.Name}", this.selectedItem == item))
if (ImGui.Selectable($"{item.Value.Name.ExtractText()}", this.selectedItem?.RowId == id))
{
this.ChangeSelectedItem(id, true);
}
Expand All @@ -375,35 +376,37 @@ void SelectClassJob(ClassJob classJob)
var sheet = this.plugin.DataManager.Excel.GetSheet<Item>();
foreach (var id in this.plugin.Config.Favorites.ToArray())
{
var item = sheet.GetRow(id);
if (item == null)
var item = sheet.GetRowOrDefault(id);
if (!item.HasValue)
{
continue;
}

if (ImGui.Selectable($"{item.Name}", this.selectedItem == item))
var itemName = item.Value.Name.ExtractText();

if (ImGui.Selectable($"{itemName}", this.selectedItem?.RowId == id))
{
this.ChangeSelectedItem(id, true);
}

if (ImGui.BeginPopupContextItem($"itemContextMenu{item.Name}"))
if (ImGui.BeginPopupContextItem($"itemContextMenu{itemName}"))
{
if (ImGui.Selectable("Remove from the favorites"))
{
this.plugin.Config.Favorites.Remove(item.RowId);
this.plugin.Config.Favorites.Remove(item.Value.RowId);
}

ImGui.EndPopup();
}

ImGui.OpenPopupOnItemClick($"itemContextMenu{item.Name}", ImGuiPopupFlags.MouseButtonRight);
ImGui.OpenPopupOnItemClick($"itemContextMenu{itemName}", ImGuiPopupFlags.MouseButtonRight);
}
}
else
{
foreach (var category in this.enumerableCategoriesAndItems)
{
if (ImGui.TreeNode(category.Key.Name + "##cat" + category.Key.RowId))
if (ImGui.TreeNode(category.Key.Name.ExtractText() + "##cat" + category.Key.RowId))
{
ImGui.Unindent(ImGui.GetTreeNodeToLabelSpacing());

Expand Down Expand Up @@ -444,16 +447,16 @@ void SelectClassJob(ClassJob classJob)
nodeFlags |= ImGuiTreeNodeFlags.Selected;
}

ImGui.TreeNodeEx(item.Name + "##item" + item.RowId, nodeFlags);
ImGui.TreeNodeEx(item.Name.ExtractText() + "##item" + item.RowId, nodeFlags);

if (ImGui.IsItemClicked())
{
this.ChangeSelectedItem(item.RowId);
}

if (ImGui.BeginPopupContextItem("itemContextMenu" + category.Key.Name + i))
if (ImGui.BeginPopupContextItem("itemContextMenu" + category.Key.Name.ExtractText() + i))
{
if (this.selectedItem != null && item != null && this.selectedItem.RowId != item.RowId)
if (this.selectedItem != null && this.selectedItem?.RowId != item.RowId)
{
this.ChangeSelectedItem(item.RowId);
}
Expand All @@ -475,7 +478,7 @@ void SelectClassJob(ClassJob classJob)
ImGui.EndPopup();
}

ImGui.OpenPopupOnItemClick("itemContextMenu" + category.Key.Name + i, ImGuiPopupFlags.MouseButtonRight);
ImGui.OpenPopupOnItemClick("itemContextMenu" + category.Key.Name.ExtractText() + i, ImGuiPopupFlags.MouseButtonRight);
}

ImGui.Indent(ImGui.GetTreeNodeToLabelSpacing());
Expand Down Expand Up @@ -525,7 +528,7 @@ void SelectClassJob(ClassJob classJob)
{
var couldGetIcon = this.plugin.TextureProvider.GetFromGameIcon(new GameIconLookup
{
IconId = this.selectedItem.Icon,
IconId = this.selectedItem.Value.Icon,
}).TryGetWrap(out var selectedItemIcon, out _);

using (selectedItemIcon)
Expand All @@ -535,7 +538,7 @@ void SelectClassJob(ClassJob classJob)
if (ImGui.ImageButton(selectedItemIcon.ImGuiHandle, new Vector2(40, 40)))
{
ImGui.LogToClipboard();
ImGui.LogText(this.selectedItem.Name);
ImGui.LogText(this.selectedItem?.Name.ExtractText());
ImGui.LogFinish();
}
}
Expand All @@ -548,7 +551,7 @@ void SelectClassJob(ClassJob classJob)
this.titleFontHandle.Push();
ImGui.SameLine();
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (ImGui.GetFontSize() / 2.0f) + (20 * scale));
ImGui.Text(this.selectedItem?.Name);
ImGui.Text(this.selectedItem?.Name.ExtractText());
ImGui.SameLine(ImGui.GetContentRegionAvail().X - (250 * scale));
ImGui.SetCursorPosY(0);
this.titleFontHandle.Pop();
Expand Down Expand Up @@ -844,7 +847,7 @@ void SelectClassJob(ClassJob classJob)
var universalisUrl = "https://universalis.app";
if (this.selectedItem != null)
{
universalisUrl += $"/market/{this.selectedItem.RowId}";
universalisUrl += $"/market/{this.selectedItem.Value.RowId}";
}

Utilities.OpenBrowser(universalisUrl);
Expand Down Expand Up @@ -899,7 +902,7 @@ internal void ChangeSelectedItem(uint itemId, bool noHistory = false)
{
this.selectedItem = this.items.Single(i => i.RowId == itemId);

var iconId = this.selectedItem.Icon;
var iconId = this.selectedItem.Value.Icon;

this.RefreshMarketData();
if (!noHistory)
Expand Down Expand Up @@ -992,7 +995,7 @@ private void UpdateCategoriesAndItems()
kv.Key,
kv.Value
.Where(i =>
i.Name.ToString().ToUpperInvariant().Contains(this.searchString.ToUpperInvariant(), StringComparison.InvariantCulture))
i.Name.ExtractText().ToUpperInvariant().Contains(this.searchString.ToUpperInvariant(), StringComparison.InvariantCulture))
.Where(i => i.LevelEquip >= this.lvlmin && i.LevelEquip <= this.lvlmax)
.Where(i => i.ClassJobCategory.Value.HasClass(this.selectedClassJob))
.ToList()))
Expand Down Expand Up @@ -1036,7 +1039,7 @@ private Dictionary<ItemSearchCategory, List<Item>> SortCategoriesAndItems()
continue;
}

sortedCategoriesDict.Add(c, this.items.Where(i => i.ItemSearchCategory.Row == c.RowId).OrderBy(i => ConvertItemNameToSortableFormat(i.Name.ToString())).ToList());
sortedCategoriesDict.Add(c, this.items.Where(i => i.ItemSearchCategory.RowId == c.RowId).OrderBy(i => ConvertItemNameToSortableFormat(i.Name.ExtractText())).ToList());
}

return sortedCategoriesDict;
Expand All @@ -1058,23 +1061,23 @@ private void HandleFrameworkUpdateEvent(IFramework framework)
return;
}

var currentDc = localPlayer.CurrentWorld.GameData.DataCenter;
var currentDc = localPlayer.CurrentWorld.Value.DataCenter;
var dcWorlds = this.plugin.DataManager.GetExcelSheet<World>()
.Where(w => w.DataCenter.Row == currentDc.Row && w.IsPublic)
.OrderBy(w => w.Name.ToString())
.Where(w => w.DataCenter.RowId == currentDc.RowId && w.IsPublic)
.OrderBy(w => w.Name.ExtractText())
.Select(w =>
{
string displayName = w.Name;
string displayName = w.Name.ExtractText();
if (localPlayer.CurrentWorld.Id == w.RowId)
if (localPlayer.CurrentWorld.Value.RowId == w.RowId)
{
displayName += $" {SeIconChar.Hyadelyn.ToChar()}";
}
return (w.Name.ToString(), displayName);
return (w.Name.ExtractText(), displayName);
});

var regionName = localPlayer.CurrentWorld.GameData.DataCenter.Value.Region switch
var regionName = localPlayer.CurrentWorld.Value.DataCenter.Value.Region switch
{
1 => "Japan",
2 => "North-America",
Expand All @@ -1085,7 +1088,7 @@ private void HandleFrameworkUpdateEvent(IFramework framework)

this.worldList.Clear();
this.worldList.Add((regionName, $"Cross-DC {SeIconChar.CrossWorld.ToChar()}"));
this.worldList.Add((currentDc.Value?.Name, $"Cross-World {SeIconChar.CrossWorld.ToChar()}"));
this.worldList.Add((currentDc.Value.Name.ExtractText(), $"Cross-World {SeIconChar.CrossWorld.ToChar()}"));
this.worldList.AddRange(dcWorlds);

if (this.plugin.Config.CrossDataCenter)
Expand All @@ -1098,7 +1101,7 @@ private void HandleFrameworkUpdateEvent(IFramework framework)
}
else
{
this.selectedWorld = this.worldList.FindIndex(w => w.Item1 == localPlayer.CurrentWorld.GameData.Name);
this.selectedWorld = this.worldList.FindIndex(w => w.Item1 == localPlayer.CurrentWorld.Value.Name);
}

if (this.worldList.Count > 1)
Expand Down Expand Up @@ -1128,9 +1131,9 @@ private void HandleHoveredItemChange(object sender, ulong itemId)
return;
}

var item = this.plugin.DataManager.Excel.GetSheet<Item>().GetRow((uint)itemId % 500000);
var item = this.plugin.DataManager.Excel.GetSheet<Item>().GetRowOrDefault((uint)itemId % 500000);

if (item != null && this.enumerableCategoriesAndItems != null && this.sortedCategoriesAndItems.Any(i => i.Value != null && i.Value.Any(k => k.ToString() == item.ToString())))
if (item != null && this.enumerableCategoriesAndItems != null && this.sortedCategoriesAndItems.Any(i => i.Value != null && i.Value.Any(k => k.RowId == item.Value.RowId)))
{
this.itemBeingHovered = itemId;
}
Expand All @@ -1142,6 +1145,11 @@ private void HandleHoveredItemChange(object sender, ulong itemId)

private void RefreshMarketData()
{
if (!this.selectedItem.HasValue)
{
return;
}

this.marketData = null;

if (this.currentRefreshTask?.Status != TaskStatus.RanToCompletion)
Expand All @@ -1156,7 +1164,7 @@ private void RefreshMarketData()
this.currentRefreshTask = Task.Run(
async () =>
{
var cachedItem = this.marketDataCache.GetValueOrDefault(this.selectedItem.RowId);
var cachedItem = this.marketDataCache.GetValueOrDefault(this.selectedItem.Value.RowId);
if (
cachedItem != default(MarketDataResponse)
&& DateTimeOffset.Now.ToUnixTimeMilliseconds() - cachedItem.FetchTimestamp < this.plugin.Config.ItemRefreshTimeout)
Expand All @@ -1165,13 +1173,13 @@ private void RefreshMarketData()
return;
}
this.marketDataCache.Remove(this.selectedItem.RowId);
this.marketDataCache.Remove(this.selectedItem.Value.RowId);
try
{
this.marketData = await this.plugin.UniversalisClient
.GetMarketData(
this.selectedItem.RowId,
this.selectedItem.Value.RowId,
this.worldList[this.selectedWorld].Item1,
this.plugin.Config.ListingCount,
this.plugin.Config.HistoryCount,
Expand All @@ -1180,7 +1188,7 @@ private void RefreshMarketData()
}
catch (AggregateException ae)
{
this.plugin.Log.Warning(ae, $"Failed to fetch market data for item {this.selectedItem.RowId} from Universalis.");
this.plugin.Log.Warning(ae, $"Failed to fetch market data for item {this.selectedItem.Value.RowId} from Universalis.");
foreach (var ex in ae.InnerExceptions)
{
Expand All @@ -1192,7 +1200,7 @@ private void RefreshMarketData()
if (this.marketData != null)
{
this.marketDataCache.Add(this.selectedItem.RowId, this.marketData);
this.marketDataCache.Add(this.selectedItem.Value.RowId, this.marketData);
}
},
this.currentRefreshCancellationTokenSource.Token);
Expand Down
2 changes: 1 addition & 1 deletion MarketBoardPlugin/MBPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace MarketBoardPlugin
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using Lumina.Excel.GeneratedSheets;
using Lumina.Excel.Sheets;

using MarketBoardPlugin.GUI;
using MarketBoardPlugin.Helpers;
Expand Down
Loading

0 comments on commit 7b42881

Please sign in to comment.