Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed May 25, 2024
2 parents 08aa4ee + f59dac9 commit 03fce15
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 112 deletions.
173 changes: 84 additions & 89 deletions MarketBoardPlugin/GUI/MarketBoardWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace MarketBoardPlugin.GUI
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Game.Text;
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using ImGuiNET;
using ImPlotNET;
using Lumina.Excel.GeneratedSheets;
using MarketBoardPlugin.Extensions;
using MarketBoardPlugin.Helpers;
Expand All @@ -47,6 +47,10 @@ public class MarketBoardWindow : Window, IDisposable

private readonly List<ClassJob> classJobs;

private readonly IFontHandle defaultFontHandle;

private readonly IFontHandle titleFontHandle;

private Dictionary<ItemSearchCategory, List<Item>> sortedCategoriesAndItems;

private bool isDisposed;
Expand Down Expand Up @@ -95,8 +99,6 @@ public class MarketBoardWindow : Window, IDisposable

private int selectedHistory = -1;

private ImFontPtr fontPtr;

private bool hasListingsHQColumnWidthBeenSet;

private bool hasHistoryHQColumnWidthBeenSet;
Expand Down Expand Up @@ -140,10 +142,32 @@ public MarketBoardWindow(MBPlugin plugin)

MBPlugin.Framework.Update += this.HandleFrameworkUpdateEvent;
MBPlugin.GameGui.HoveredItemChanged += this.HandleHoveredItemChange;
MBPlugin.PluginInterface.UiBuilder.BuildFonts += this.HandleBuildFonts;

this.defaultFontHandle = MBPlugin.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e =>
e.OnPreBuild(toolkit =>
toolkit.AddFontFromStream(
this.GetType().Assembly.GetManifestResourceStream("MarketBoardPlugin.Resources.NotoSans-Medium-NNBSP.otf"),
new SafeFontConfig()
{
SizePx = UiBuilder.DefaultFontSizePx,
GlyphRanges = FontAtlasBuildToolkitUtilities.ToGlyphRange(char.ConvertFromUtf32(0x202F)),
MergeFont = toolkit.AddDalamudDefaultFont(-1),
},
false,
"NNBSP")));

this.titleFontHandle = MBPlugin.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e =>
e.OnPreBuild(toolkit =>
toolkit.AddDalamudDefaultFont(MBPlugin.PluginInterface.UiBuilder.DefaultFontSpec.SizePx * 1.5f)));

MBPlugin.PluginInterface.UiBuilder.RebuildFonts();

var imPlotStylePtr = ImPlot.GetStyle();

imPlotStylePtr.Use24HourClock = DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains('H', StringComparison.InvariantCulture);
imPlotStylePtr.UseISO8601 = DateTimeFormatInfo.CurrentInfo.ShortDatePattern != "M/d/yyyy";
imPlotStylePtr.UseLocalTime = true;

#if DEBUG
this.worldList.Add(("Chaos", "Chaos"));
this.worldList.Add(("Moogle", "Moogle"));
Expand Down Expand Up @@ -199,6 +223,8 @@ public override void Draw()

var scale = ImGui.GetIO().FontGlobalScale;

using var fontDispose = this.defaultFontHandle.Push();

// Item List Column Setup
ImGui.BeginChild("itemListColumn", new Vector2(267, 0) * scale, true);

Expand Down Expand Up @@ -445,13 +471,13 @@ void SelectClassJob(ClassJob classJob)
ImGui.SetCursorPos(new Vector2(40, 40));
}

ImGui.PushFont(this.fontPtr);
this.titleFontHandle.Push();
ImGui.SameLine();
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (ImGui.GetFontSize() / 2.0f) + (19 * scale));
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (ImGui.GetFontSize() / 2.0f) + (20 * scale));
ImGui.Text(this.selectedItem?.Name);
ImGui.SameLine(ImGui.GetContentRegionAvail().X - (250 * scale));
ImGui.SetCursorPosY(0);
ImGui.PopFont();
this.titleFontHandle.Pop();
ImGui.BeginGroup();
ImGui.SetNextItemWidth(250 * scale);
if (ImGui.BeginCombo("##worldCombo", this.selectedWorld > -1 ? this.worldList[this.selectedWorld].Item2 : string.Empty))
Expand Down Expand Up @@ -500,18 +526,18 @@ void SelectClassJob(ClassJob classJob)
{
if (ImGui.BeginTabItem("Market Data##marketDataTab"))
{
ImGui.PushFont(this.fontPtr);
this.titleFontHandle.Push();
int usedTile = this.plugin.Config.RecentHistoryDisabled ? 1 : 2;
var tableHeight = (ImGui.GetContentRegionAvail().Y / usedTile) - (ImGui.GetTextLineHeightWithSpacing() * 2);
ImGui.Text("Current listings (Includes 5%% GST)");
ImGui.PopFont();
this.titleFontHandle.Pop();

ImGui.BeginChild("currentListings", new Vector2(0.0f, tableHeight));
ImGui.Columns(5, "currentListingsColumns");

if (!this.hasListingsHQColumnWidthBeenSet)
{
ImGui.SetColumnWidth(0, 30.0f);
ImGui.SetColumnWidth(0, ImGui.GetTextLineHeightWithSpacing() * 1.5f);
this.hasListingsHQColumnWidthBeenSet = true;
}

Expand Down Expand Up @@ -585,16 +611,16 @@ void SelectClassJob(ClassJob classJob)
{
ImGui.Separator();

ImGui.PushFont(this.fontPtr);
this.titleFontHandle.Push();
ImGui.Text("Recent history");
ImGui.PopFont();
this.titleFontHandle.Pop();

ImGui.BeginChild("recentHistory", new Vector2(0.0f, tableHeight));
ImGui.Columns(6, "recentHistoryColumns");

if (!this.hasHistoryHQColumnWidthBeenSet)
{
ImGui.SetColumnWidth(0, 30.0f);
ImGui.SetColumnWidth(0, ImGui.GetTextLineHeightWithSpacing() * 1.5f);
this.hasHistoryHQColumnWidthBeenSet = true;
}

Expand Down Expand Up @@ -669,66 +695,58 @@ void SelectClassJob(ClassJob classJob)
ImGui.Separator();
if (ImGui.BeginTabItem("Charts##chartsTab"))
{
this.titleFontHandle.Push();
var tableHeight = (ImGui.GetContentRegionAvail().Y / 2) - (ImGui.GetTextLineHeightWithSpacing() * 2);
var marketDataRecentHistory = this.marketData?.RecentHistory
.GroupBy(h => DateTimeOffset.FromUnixTimeSeconds(h.Timestamp).LocalDateTime.Date)
.Select(g => (Date: g.Key, PriceAvg: (float)g.Average(h => h.PricePerUnit),
QtySum: (float)g.Sum(h => h.Quantity)))
.ToList();
this.titleFontHandle.Pop();

if (marketDataRecentHistory != null && marketDataRecentHistory.Count > 0)
if (this.marketData?.RecentHistory != null && this.marketData?.RecentHistory.Count > 0)
{
for (var day = marketDataRecentHistory.Min(h => h.Date);
day <= marketDataRecentHistory.Max(h => h.Date);
day = day.AddDays(1))
this.titleFontHandle.Push();
ImGui.Text("Price variations (per unit)");
this.titleFontHandle.Pop();

if (ImPlot.BeginPlot("##pricePlot", new Vector2(-1, tableHeight)))
{
if (!marketDataRecentHistory.Exists(h => h.Date == day))
var now = DateTimeOffset.Now;
var x = new List<long>();
var y = new List<long>();

foreach (var historyEntry in this.marketData?.RecentHistory)
{
marketDataRecentHistory.Add((day, 0, 0));
x.Add(historyEntry.Timestamp);
y.Add(historyEntry.PricePerUnit);
}
}

marketDataRecentHistory = marketDataRecentHistory
.OrderBy(h => h.Date)
.ToList();

ImGui.PushFont(this.fontPtr);
ImGui.Text("Price variations (per unit)");
ImGui.PopFont();

var pricePlotValues = marketDataRecentHistory
.Select(h => h.PriceAvg)
.ToArray();
ImGui.SetNextItemWidth(-1);
ImGui.PlotLines(
"##pricePlot",
ref pricePlotValues[0],
pricePlotValues.Length,
0,
null,
float.MaxValue,
float.MaxValue,
new Vector2(0, tableHeight));
ImPlot.SetupAxesLimits(now.AddDays(-7).ToUnixTimeSeconds(), now.ToUnixTimeSeconds(), 0, y.Max(), ImPlotCond.Always);
ImPlot.SetupAxisScale(ImAxis.X1, ImPlotScale.Time);
ImPlot.SetNextMarkerStyle(ImPlotMarker.Circle);
ImPlot.PlotLine("Price", ref x.ToArray()[0], ref y.ToArray()[0], x.Count);
ImPlot.EndPlot();
}

ImGui.Separator();

ImGui.PushFont(this.fontPtr);
this.titleFontHandle.Push();
ImGui.Text("Traded volumes");
ImGui.PopFont();

var qtyPlotValues = marketDataRecentHistory
.Select(h => h.QtySum)
.ToArray();
ImGui.SetNextItemWidth(-1);
ImGui.PlotHistogram(
"##qtyPlot",
ref qtyPlotValues[0],
qtyPlotValues.Length,
0,
null,
float.MaxValue,
float.MaxValue,
new Vector2(0, tableHeight));
this.titleFontHandle.Pop();

if (ImPlot.BeginPlot("##qtyPlot", new Vector2(-1, tableHeight)))
{
var now = DateTimeOffset.Now;
var x = new List<long>();
var y = new List<long>();

foreach (var historyEntry in this.marketData?.RecentHistory)
{
x.Add(historyEntry.Timestamp);
y.Add(historyEntry.Quantity);
}

ImPlot.SetupAxesLimits(now.AddDays(-7).ToUnixTimeSeconds(), now.ToUnixTimeSeconds(), 0, y.Max(), ImPlotCond.Always);
ImPlot.SetupAxisScale(ImAxis.X1, ImPlotScale.Time);
ImPlot.PlotBars("Quantities", ref x.ToArray()[0], ref y.ToArray()[0], x.Count, 3600);
ImPlot.EndPlot();
}
}

ImGui.EndTabItem();
Expand Down Expand Up @@ -814,8 +832,9 @@ protected virtual void Dispose(bool disposing)
{
MBPlugin.Framework.Update -= this.HandleFrameworkUpdateEvent;
MBPlugin.GameGui.HoveredItemChanged -= this.HandleHoveredItemChange;
MBPlugin.PluginInterface.UiBuilder.BuildFonts -= this.HandleBuildFonts;
this.selectedItemIcon?.Dispose();
this.defaultFontHandle?.Dispose();
this.titleFontHandle?.Dispose();
}

this.isDisposed = true;
Expand Down Expand Up @@ -930,31 +949,6 @@ private Dictionary<ItemSearchCategory, List<Item>> SortCategoriesAndItems()
}
}

private unsafe void HandleBuildFonts()
{
var fontPath = Path.Combine(MBPlugin.PluginInterface.DalamudAssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf");
this.fontPtr = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, 24.0f);

ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
fontConfig.MergeMode = true;
fontConfig.NativePtr->DstFont = UiBuilder.DefaultFont.NativePtr;

var fontRangeHandle = GCHandle.Alloc(
new ushort[]
{
0x202F,
0x202F,
0,
},
GCHandleType.Pinned);

var otherPath = Path.Combine(MBPlugin.PluginInterface.AssemblyLocation.DirectoryName, "Resources", "NotoSans-Medium.otf");
ImGui.GetIO().Fonts.AddFontFromFileTTF(otherPath, 17.0f, fontConfig, fontRangeHandle.AddrOfPinnedObject());

fontConfig.Destroy();
fontRangeHandle.Free();
}

private void HandleFrameworkUpdateEvent(IFramework framework)
{
if (MBPlugin.ClientState.LocalContentId != 0 && this.playerId != MBPlugin.ClientState.LocalContentId)
Expand Down Expand Up @@ -1074,6 +1068,7 @@ private void RefreshMarketData()

this.marketData = null;
}

this.marketData = await UniversalisClient
.GetMarketData(
this.selectedItem.RowId,
Expand Down
20 changes: 11 additions & 9 deletions MarketBoardPlugin/MarketBoardPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<AssemblyName>MarketBoardPlugin</AssemblyName>
<Authors>Florian "fmauNeko" Maunier</Authors>
<OutputType>Library</OutputType>
Expand All @@ -11,9 +11,9 @@
<DebugType>PdbOnly</DebugType>
<GenerateFullPaths>true</GenerateFullPaths>
<MSBuildGitHashCommand>git rev-parse --short HEAD</MSBuildGitHashCommand>
<AssemblyVersion>1.3.4</AssemblyVersion>
<FileVersion>1.3.4</FileVersion>
<Version>1.3.4</Version>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<Version>1.4.0</Version>
<Company>Florian Maunier</Company>
<Description>Market board plugin for Dalamud.</Description>
<Copyright>Copyright (c) Florian Maunier. All rights reserved.</Copyright>
Expand Down Expand Up @@ -43,9 +43,11 @@

<ItemGroup>
<None Include="./MarketBoardPlugin.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="Resources\NotoSans-Medium.otf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Content Remove="Resources/NotoSans-Medium-NNBSP.otf" />
<EmbeddedResource Include="Resources/NotoSans-Medium-NNBSP.otf" />
</ItemGroup>

<ItemGroup>
Expand All @@ -56,7 +58,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down Expand Up @@ -94,4 +96,4 @@
<ProjectReference Include="..\OtterGui\OtterGui.csproj" />
</ItemGroup>

</Project>
</Project>
Binary file not shown.
Binary file removed MarketBoardPlugin/Resources/NotoSans-Medium.otf
Binary file not shown.
Loading

0 comments on commit 03fce15

Please sign in to comment.