Skip to content

Commit

Permalink
Adapt rarity colors and refetch Public API data after language change
Browse files Browse the repository at this point in the history
  • Loading branch information
domialex committed Jan 12, 2020
1 parent 95e2f6a commit b27edea
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 35 deletions.
11 changes: 6 additions & 5 deletions source/Helpers/Input/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static async void TriggerItemFetch()
{
Logger.Log("Hotkey for pricing item triggered.");

Item item = TriggerCopyAction();
Item item = await TriggerCopyAction();
if (item != null)
{
OverlayController.Open();
Expand All @@ -100,11 +100,11 @@ private static async void TriggerItemFetch()
OverlayController.Hide();
}

private static void TriggerItemWiki()
private static async void TriggerItemWiki()
{
Logger.Log("Hotkey for opening wiki triggered.");

var item = TriggerCopyAction();
var item = await TriggerCopyAction();
if (item != null)
{
POEWikiAPI.POEWikiHelper.Open(item);
Expand All @@ -126,7 +126,7 @@ private static void ExitApplication()
Application.Exit();
}

private static Item TriggerCopyAction()
private static async Task<Item> TriggerCopyAction()
{
// Trigger copy action.
SendKeys.SendWait(Input.KeyCommands.COPY);
Expand All @@ -136,7 +136,8 @@ private static Item TriggerCopyAction()
var itemText = ClipboardHelper.GetText();

// Detect the language of the item in the clipboard.
if (!LanguageSettings.FindAndSetLanguageProvider(itemText))
var setLanguageSuccess = await LanguageSettings.FindAndSetLanguageProvider(itemText);
if (!setLanguageSuccess)
{
return null;
}
Expand Down
9 changes: 7 additions & 2 deletions source/Helpers/Localization/LanguageSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using Sidekick.Helpers.POETradeAPI;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sidekick.Helpers.Localization
{
Expand Down Expand Up @@ -33,8 +35,9 @@ public static class LanguageSettings

/// <summary>
/// Every item should start with Rarity in the first line.
/// This will force the TradeClient to refetch the Public API's data if needed.
/// </summary>
public static bool FindAndSetLanguageProvider(string itemDescription)
public static async Task<bool> FindAndSetLanguageProvider(string itemDescription)
{
foreach (var item in RarityToLanguageDictionary)
{
Expand All @@ -45,6 +48,8 @@ public static bool FindAndSetLanguageProvider(string itemDescription)
Logger.Log($"Changed language support to {item.Value}.");
CurrentLanguage = item.Value;
Provider = GetLanguageProvider(item.Value);
TradeClient.Dispose();
return await TradeClient.Initialize();
}

return true;
Expand Down
5 changes: 0 additions & 5 deletions source/Helpers/POETradeAPI/Models/QueryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public QueryRequest(Item item)
};
}

Query.Filters.TypeFilter.Filters.Rarity = new FilterOption()
{
Option = ((EquippableItem)item).Rarity.ToLowerInvariant(),
};

switch (((EquippableItem)item).Influence)
{
case InfluenceType.None:
Expand Down
10 changes: 6 additions & 4 deletions source/Helpers/POETradeAPI/TradeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class TradeClient

public static League SelectedLeague;

public static async void Initialize()
public static async Task<bool> Initialize()
{
if (_jsonSerializerSettings == null)
{
Expand All @@ -42,7 +42,7 @@ public static async void Initialize()

if (IsFetching)
{
return;
return false;
}

IsFetching = true;
Expand All @@ -57,7 +57,7 @@ public static async void Initialize()
Logger.Log("Retrying every minute.");
Dispose();
await Task.Run(Retry);
return;
return false;
}

IsFetching = false;
Expand All @@ -69,6 +69,8 @@ public static async void Initialize()
Logger.Log($"Path of Exile trade data fetched.");
Logger.Log($"Sidekick is ready, press Ctrl+D over an item in-game to use. Press Escape to close overlay.");
TrayIcon.SendNotification("Press Ctrl+D over an item in-game to use. Press Escape to close overlay.", "Sidekick is ready");

return true;
}

private static async void Retry()
Expand All @@ -81,7 +83,7 @@ private static async void Retry()
}
else
{
Initialize();
await Initialize();
}
}

Expand Down
17 changes: 12 additions & 5 deletions source/Helpers/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ public static void Initialize()

public static void PopulateLeagueSelectMenu(List<League> leagues)
{
foreach (League l in leagues)
if(_leagueSelectMenu.DropDownItems.Count > 0)
{
var menuItem = new ToolStripMenuItem(l.Id);
menuItem.Click += (s, e) => { foreach (ToolStripMenuItem t in _leagueSelectMenu.DropDownItems) { t.Checked = false; } };
// TODO: Fix Cross-thread operation not valid after changing language.
return;
}

foreach (var league in leagues)
{
var menuItem = new ToolStripMenuItem(league.Id);
menuItem.Click += (s, e) => { foreach (ToolStripMenuItem x in _leagueSelectMenu.DropDownItems) { x.Checked = false; } };
menuItem.Click += (s, e) => { menuItem.Checked = true; };
menuItem.Click += (s, e) => { TradeClient.SelectedLeague = l; };
menuItem.Click += (s, e) => { TradeClient.SelectedLeague = league; };
_leagueSelectMenu.DropDownItems.Add(menuItem);
}
//select the first league as the default

// Select the first league as the default.
_leagueSelectMenu.DropDownItems[0].PerformClick();
}

Expand Down
2 changes: 1 addition & 1 deletion source/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void Main()
TrayIcon.Initialize();

// Load POE Trade information.
TradeClient.Initialize();
_ = TradeClient.Initialize();

// Keyboard hooks.
EventsHandler.Initialize();
Expand Down
32 changes: 19 additions & 13 deletions source/Windows/Overlay/Converters/RarityToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Sidekick.Helpers.Localization;
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
Expand All @@ -9,20 +10,25 @@ public class RarityToColorConverter : IValueConverter
{
private Color GetRarityColor(string rarity)
{
switch (rarity)
if (rarity == LanguageSettings.Provider.RarityNormal)
{
case "Normal":
return Color.FromRgb(200, 200, 200);
case "Magic":
return Color.FromRgb(136, 136, 255);
case "Rare":
return Color.FromRgb(255, 255, 119);
case "Unique":
return Color.FromRgb(175, 96, 37);
default:
//gem, currency, divination card, quest item, prophecy, relic
return Color.FromRgb(170, 158, 130);
return Color.FromRgb(200, 200, 200);
}
if (rarity == LanguageSettings.Provider.RarityMagic)
{
return Color.FromRgb(136, 136, 255);
}
if (rarity == LanguageSettings.Provider.RarityRare)
{
return Color.FromRgb(255, 255, 119);
}
if (rarity == LanguageSettings.Provider.RarityUnique)
{
return Color.FromRgb(175, 96, 37);
}

// Gem, Currency, Divination Card, Quest Item, Prophecy, Relic, etc.
return Color.FromRgb(170, 158, 130);
}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down

0 comments on commit b27edea

Please sign in to comment.