Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed May 26, 2024
2 parents 03fce15 + ae6c955 commit 0819425
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 29 deletions.
80 changes: 68 additions & 12 deletions MarketBoardPlugin/GUI/MarketBoardWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ namespace MarketBoardPlugin.GUI
using System.Threading.Tasks;
using Dalamud.Game.Text;
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.Internal;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services;
using ImGuiNET;
Expand Down Expand Up @@ -61,6 +63,8 @@ public class MarketBoardWindow : Window, IDisposable

private bool advancedSearchMenuOpen;

private bool favoritesOpen;

private float progressPosition;

private string searchString = string.Empty;
Expand Down Expand Up @@ -221,25 +225,45 @@ public override void Draw()
this.UpdateCategoriesAndItems();
}

var defaultButtonColor = ImGui.GetColorU32(ImGuiCol.Button);
var defaultButtonHoveredColor = ImGui.GetColorU32(ImGuiCol.ButtonHovered);

var scale = ImGui.GetIO().FontGlobalScale;

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

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

ImGui.SetNextItemWidth((-32 * ImGui.GetIO().FontGlobalScale) - ImGui.GetStyle().ItemSpacing.X);
ImGui.SetNextItemWidth((-64 * ImGui.GetIO().FontGlobalScale) - (ImGui.GetStyle().ItemSpacing.X * 2));
ImGuiOverrides.InputTextWithHint("##searchString", "Search for item", ref this.searchString, 256);

ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.PushStyleColor(ImGuiCol.Text, this.searchHistoryOpen ? 0xFF0000FF : 0xFFFFFFFF);
ImGui.PushStyleVar(ImGuiStyleVar.ButtonTextAlign, new Vector2(0.5f, 0.5f));

ImGui.SameLine();
ImGui.PushStyleColor(ImGuiCol.Button, this.searchHistoryOpen ? 0xFF5CB85C : defaultButtonColor);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, this.searchHistoryOpen ? 0x885CB85C : defaultButtonHoveredColor);
if (ImGui.Button($"{(char)FontAwesomeIcon.History}", new Vector2(32 * ImGui.GetIO().FontGlobalScale, ImGui.GetItemRectSize().Y)))
{
this.searchHistoryOpen = !this.searchHistoryOpen;
}

ImGui.PopStyleColor();
ImGui.PopStyleColor();

ImGui.SameLine();
ImGui.PushStyleColor(ImGuiCol.Button, this.favoritesOpen ? 0xFF5CB85C : defaultButtonColor);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, this.favoritesOpen ? 0x885CB85C : defaultButtonHoveredColor);
if (ImGui.Button($"{(char)FontAwesomeIcon.Star}", new Vector2(32 * ImGui.GetIO().FontGlobalScale, ImGui.GetItemRectSize().Y)))
{
this.favoritesOpen = !this.favoritesOpen;
}

ImGui.PopStyleColor();
ImGui.PopStyleColor();

ImGui.PopStyleVar();
ImGui.PopFont();

var previousYCursor = ImGui.GetCursorPosY();
Expand Down Expand Up @@ -338,6 +362,25 @@ void SelectClassJob(ClassJob classJob)
}
}
}
else if (this.favoritesOpen)
{
ImGui.Text("Favorites");
ImGui.Separator();
var sheet = MBPlugin.Data.Excel.GetSheet<Item>();
foreach (var id in this.plugin.Config.Favorites.ToArray())
{
var item = sheet.GetRow(id);
if (item == null)
{
continue;
}

if (ImGui.Selectable($"{item.Name}", this.selectedItem == item))
{
this.ChangeSelectedItem(id, true);
}
}
}
else
{
foreach (var category in this.enumerableCategoriesAndItems)
Expand Down Expand Up @@ -390,7 +433,7 @@ void SelectClassJob(ClassJob classJob)
this.ChangeSelectedItem(item.RowId);
}

if (ImGui.BeginPopupContextItem("shoplist" + category.Key.Name + i))
if (ImGui.BeginPopupContextItem("itemContextMenu" + category.Key.Name + i))
{
if (this.selectedItem != null && item != null && this.selectedItem.RowId != item.RowId)
{
Expand All @@ -406,10 +449,15 @@ void SelectClassJob(ClassJob classJob)
this.plugin.ShoppingList.Add(new SavedItem(item, price, itm.WorldName));
}

if (ImGui.Selectable("Add to the favorites"))
{
this.plugin.Config.Favorites.Add(item.RowId);
}

ImGui.EndPopup();
}

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

ImGui.Indent(ImGui.GetTreeNodeToLabelSpacing());
Expand Down Expand Up @@ -1069,13 +1117,21 @@ private void RefreshMarketData()
this.marketData = null;
}

this.marketData = await UniversalisClient
.GetMarketData(
this.selectedItem.RowId,
this.worldList[this.selectedWorld].Item1,
50,
CancellationToken.None)
.ConfigureAwait(false);
try
{
this.marketData = await UniversalisClient
.GetMarketData(
this.selectedItem.RowId,
this.worldList[this.selectedWorld].Item1,
50,
CancellationToken.None)
.ConfigureAwait(false);
}
catch (Exception)
{
MBPlugin.Log.Warning($"Failed to fetch market data for item {this.selectedItem.RowId} from Universalis.");
this.marketData = null;
}

if (cachedItem != null)
{
Expand Down
35 changes: 29 additions & 6 deletions MarketBoardPlugin/Helpers/UniversalisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MarketBoardPlugin.Helpers
{
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -32,15 +33,37 @@ public static async Task<MarketDataResponse> GetMarketData(uint itemId, string w
cancellationToken.ThrowIfCancellationRequested();

using var client = new HttpClient();
var res = await client
.GetStreamAsync(uriBuilder.Uri, cancellationToken)
.ConfigureAwait(false);

Stream res;

try
{
res = await client
.GetStreamAsync(uriBuilder.Uri, cancellationToken)
.ConfigureAwait(false);
}
catch (HttpRequestException)
{
MBPlugin.Log.Warning($"Failed to fetch market data for item {itemId} on world {worldName}.");
return null;
}

cancellationToken.ThrowIfCancellationRequested();

var parsedRes = await JsonSerializer
.DeserializeAsync<MarketDataResponse>(res, cancellationToken: cancellationToken)
.ConfigureAwait(false);
MarketDataResponse parsedRes;

try
{
parsedRes = await JsonSerializer
.DeserializeAsync<MarketDataResponse>(res, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (JsonException)
{
MBPlugin.Log.Warning($"Failed to parse market data for item {itemId} on world {worldName}.");
return null;
}

if (parsedRes != null)
{
parsedRes.FetchTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
Expand Down
5 changes: 5 additions & 0 deletions MarketBoardPlugin/MBPluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ public class MBPluginConfig : IPluginConfiguration
/// Gets or sets a value indicating whether the recent history menu is disabled or not.
/// </summary>
public bool RecentHistoryDisabled { get; set; }

/// <summary>
/// Gets the favorite items.
/// </summary>
public ICollection<uint> Favorites { get; } = new List<uint>();
}
}
11 changes: 6 additions & 5 deletions MarketBoardPlugin/MarketBoardPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
Expand All @@ -11,9 +11,9 @@
<DebugType>PdbOnly</DebugType>
<GenerateFullPaths>true</GenerateFullPaths>
<MSBuildGitHashCommand>git rev-parse --short HEAD</MSBuildGitHashCommand>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<Version>1.4.0</Version>
<AssemblyVersion>1.5.0</AssemblyVersion>
<FileVersion>1.5.0</FileVersion>
<Version>1.5.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 @@ -54,7 +54,8 @@
<PackageReference Include="Dalamud.ContextMenu" Version="1.3.1" />
<PackageReference Include="Dalamud.DrunkenToad" Version="1.8.15" />
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
<PackageReference Include="MSBuildGitHash" Version="2.0.2"
Condition="'$(Configuration)'!='Release'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 0 additions & 6 deletions MarketBoardPlugin/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
},
"MSBuildGitHash": {
"type": "Direct",
"requested": "[2.0.2, )",
"resolved": "2.0.2",
"contentHash": "1gA7vw5Wc4w6/H2IDVFx69LGQndIyTSsBOTL1BO1lAjzyWl6LUi24gtST8Bh5yd/793patMZyO7Ym4Kg19p+VA=="
},
"StyleCop.Analyzers": {
"type": "Direct",
"requested": "[1.2.0-beta.556, )",
Expand Down

0 comments on commit 0819425

Please sign in to comment.