/// <summary>Show the lookup UI for the current target.</summary>
        private void ShowLookup()
        {
            GameHelper.InterceptErrors("looking that up", () =>
            {
                using (ICumulativeLog log = this.GetTaskLog())
                {
                    log.Append("Lookup Anything received a lookup request. ");

                    // validate version
                    string versionError = GameHelper.ValidateGameVersion();
                    if (versionError != null)
                    {
                        GameHelper.ShowErrorMessage(versionError);
                        Log.Error(versionError);
                        return;
                    }

                    // get target
                    ISubject subject = null;
                    if (Game1.activeClickableMenu != null)
                    {
                        log.Append($"Searching the open '{Game1.activeClickableMenu.GetType().Name}' menu... ");
                        subject = this.TargetFactory.GetSubjectFrom(Game1.activeClickableMenu, GameHelper.GetScreenCoordinatesFromCursor());
                    }
                    else
                    {
                        log.Append("Searching the world... ");
                        subject = this.TargetFactory.GetSubjectFrom(Game1.currentLocation, Game1.currentCursorTile, GameHelper.GetScreenCoordinatesFromCursor());
                    }
                    if (subject == null)
                    {
                        log.AppendLine("no target found.");
                        return;
                    }


                    // show lookup UI
                    log.AppendLine($"showing {subject.GetType().Name}::{subject.Type}::{subject.Name}.");
                    this.PreviousMenu         = Game1.activeClickableMenu;
                    Game1.activeClickableMenu = new LookupMenu(subject, this.Metadata);
                }
            });
        }
Beispiel #2
0
 /*********
 ** Private methods
 *********/
 /// <summary>Log an error and warn the user.</summary>
 /// <param name="ex">The exception to handle.</param>
 /// <param name="verb">The verb describing where the error occurred (e.g. "looking that up"). This is displayed on the screen, so it should be simple and avoid characters that might not be available in the sprite font.</param>
 /// <param name="detailedVerb">A more detailed form of <see cref="verb"/> if applicable. This is displayed in the log, so it can be more technical and isn't constrained by the sprite font.</param>
 private static void HandleError(Exception ex, string verb, string detailedVerb = null)
 {
     detailedVerb = detailedVerb ?? verb;
     Log.Error($"[Lookup Anything] Something went wrong {detailedVerb}:{Environment.NewLine}{ex}");
     GameHelper.ShowErrorMessage($"Huh. Something went wrong {verb}. The game error log has the technical details.");
 }