Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement contextual icons with clickable actions #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 42 additions & 6 deletions UI/Controls/CategoryContextMenuStripItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,25 @@ private void BuildCategoryMenu() {
private void AddAchievementContext(int achievementId) {
if (achievementId < 0) return;

PathingModule.Instance.Gw2ApiManager.Gw2ApiClient.V2.Achievements.GetAsync(achievementId).ContinueWith((achievementTask) => {
this.BasicTooltipText = $"[Achievement]\r\n\r\n {DrawUtil.WrapText(GameService.Content.DefaultFont14, achievementTask.Result.Description, 300)}\r\n\r\n{DrawUtil.WrapText(GameService.Content.DefaultFont14, achievementTask.Result.Requirement, 300)}";
}, TaskContinuationOptions.NotOnFaulted);

_contexts.Add((PathingModule.Instance.ContentsManager.GetTexture(@"png/context/155062.png"), "", () => { }));
_contexts.Add((PathingModule.Instance.ContentsManager.GetTexture(@"png/context/102365.png"), "", () => { }));
// Add the icon showing this marker is tied to an achievement
_contexts.Add((PathingModule.Instance.ContentsManager.GetTexture(@"png/context/155062.png"), "", null));

// Add the link to the wiki
_contexts.Add((
PathingModule.Instance.ContentsManager.GetTexture(@"png/context/102365.png"),
"Click to open wiki",
new Action(() => {
PathingModule.Instance.Gw2ApiManager.Gw2ApiClient.V2.Achievements.GetAsync(achievementId).ContinueWith(
(achievementTask) => {
String safeAchievementName = System.Uri.EscapeDataString(achievementTask.Result.Name);
String url = "https://wiki.guildwars2.com/index.php?title=Special%3ASearch&go=Go&search=" + safeAchievementName;

System.Diagnostics.Process.Start(url);
},
TaskContinuationOptions.NotOnFaulted
);
})
));
}

private void DetectAndBuildContexts() {
Expand All @@ -74,6 +87,8 @@ private void DetectAndBuildContexts() {

if (achievementId < 0) return;

AddAchievementContext(achievementId);

this.Tooltip = new Tooltip(new AchievementTooltipView(achievementId));

if (_packState.UserConfiguration.PackAllowMarkersToAutomaticallyHide.Value) {
Expand All @@ -96,6 +111,27 @@ protected override void OnCheckedChanged(CheckChangedEvent e) {
base.OnCheckedChanged(e);
}

protected override void OnLeftMouseButtonReleased(MouseEventArgs e)
{
// Check for context clicks before delegating to base
// Click area on context icons is extended to full height (ignore upper/lower bounds)
int clickDistanceFromRight = AbsoluteBounds.Right - e.MousePosition.X;
int contextIndex = _contexts.Count - (clickDistanceFromRight - 1) / 18;

// If we're within a valid context, run its action and exit
if (contextIndex >= 0 && contextIndex < _contexts.Count) {
// null actions indicate clickthrough
Action action = _contexts[contextIndex].Item3;
if (action != null) {
action();
return;
}
}

// If we haven't returned out, delegate to base
base.OnLeftMouseButtonReleased(e);
}

protected override void OnClick(MouseEventArgs e) {
if (base.CanCheck) {
// If CTRL is held down when clicked, uncheck all adjacent menu items except for this one.
Expand Down