internal static void QuestLogPatch(QuestLog __instance, int ___questPage, List <List <IQuest> > ___pages, int ___currentPage, IQuest ____shownQuest, List <string> ____objectiveText)
        {
            try
            {
                bool   isCPressed = MainClass.Config.PrimaryInfoKey.JustPressed();
                int    x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
                string toSpeak = " ", extra = "";

                if (___questPage == -1)
                {
                    #region Quest Lists
                    if (!firstTimeInIndividualQuest)
                    {
                        firstTimeInIndividualQuest = true;
                    }

                    for (int i = 0; i < __instance.questLogButtons.Count; i++)
                    {
                        if (___pages.Count() > 0 && ___pages[___currentPage].Count() > i)
                        {
                            if (!__instance.questLogButtons[i].containsPoint(x, y))
                            {
                                continue;
                            }

                            string name     = ___pages[___currentPage][i].GetName();
                            int    daysLeft = ___pages[___currentPage][i].GetDaysLeft();
                            toSpeak = $"{name}";

                            if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete())
                            {
                                toSpeak += $"\t\n {daysLeft} days left";
                            }

                            toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : "";
                            break;
                        }
                    }

                    if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y))
                    {
                        toSpeak = "Previous page button";
                    }
                    else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y))
                    {
                        toSpeak = "Next page button";
                    }
                    else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y))
                    {
                        toSpeak = "Close menu button";
                    }

                    if (questLogQuery != toSpeak)
                    {
                        questLogQuery = toSpeak;
                        MainClass.ScreenReader.Say(toSpeak, true);
                    }
                    #endregion
                }
                else
                {
                    #region Individual quest
                    bool   containsReward = __instance.HasReward() || __instance.HasMoneyReward();
                    string description    = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128);
                    string title          = ____shownQuest.GetName();

                    if (firstTimeInIndividualQuest || (isCPressed && !isNarratingQuestInfo))
                    {
                        if (firstTimeInIndividualQuest)
                        {
                            toSpeak = "Back button";
                        }

                        if (____shownQuest.ShouldDisplayAsComplete())
                        {
                            #region Quest completed menu

                            extra = $"Quest: {title} Completed!";

                            if (__instance.HasMoneyReward())
                            {
                                extra += $"you recieved {____shownQuest.GetMoneyReward()}g";
                            }

                            #endregion
                        }
                        else
                        {
                            #region Quest in-complete menu
                            extra = $"Title: {title}. \t\n Description: {description}";

                            for (int j = 0; j < ____objectiveText.Count; j++)
                            {
                                string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont);
                                if (____shownQuest != null && ____shownQuest is SpecialOrder)
                                {
                                    OrderObjective order_objective = ((SpecialOrder)____shownQuest).objectives[j];
                                    if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress())
                                    {
                                        parsed_text += "\n\t" + order_objective.GetCount() + " of " + order_objective.GetMaxCount() + " completed";
                                    }
                                }

                                extra += $"\t\nOrder {j + 1}: {parsed_text} \t\n";
                            }

                            if (____shownQuest != null)
                            {
                                int daysLeft = ____shownQuest.GetDaysLeft();

                                if (daysLeft > 0)
                                {
                                    extra += $"\t\n{daysLeft} days left.";
                                }
                            }
                            #endregion
                        }

                        isNarratingQuestInfo = true;
                        Task.Delay(200).ContinueWith(_ => { isNarratingQuestInfo = false; });
                        questLogQuery = " ";
                    }

                    if (!firstTimeInIndividualQuest)
                    {
                        if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y))
                        {
                            toSpeak = (___currentPage > 0) ? "Previous page button" : "Back button";
                        }
                        else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y))
                        {
                            toSpeak = "Next page button";
                        }
                        else if (__instance.cancelQuestButton != null && __instance.cancelQuestButton.visible && __instance.cancelQuestButton.containsPoint(x, y))
                        {
                            toSpeak = "Cancel quest button";
                        }
                        else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y))
                        {
                            toSpeak = "Close menu button";
                        }
                        else if (containsReward && __instance.rewardBox.containsPoint(x, y))
                        {
                            toSpeak = "Left click to collect reward";
                        }
                    }

                    if (firstTimeInIndividualQuest || (questLogQuery != toSpeak))
                    {
                        questLogQuery = toSpeak;
                        MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true);

                        if (firstTimeInIndividualQuest)
                        {
                            firstTimeInIndividualQuest = false;
                        }
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
            }
        }
Example #2
0
 public override void draw(SpriteBatch b)
 {
     b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f);
     SpriteText.drawStringWithScrollCenteredAt(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:QuestLog.cs.11373"), xPositionOnScreen + base.width / 2, yPositionOnScreen - 64);
     IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), xPositionOnScreen, yPositionOnScreen, base.width, height, Color.White, 4f);
     if (questPage == -1)
     {
         for (int k = 0; k < questLogButtons.Count; k++)
         {
             if (pages.Count() > 0 && pages[currentPage].Count() > k)
             {
                 IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(384, 396, 15, 15), questLogButtons[k].bounds.X, questLogButtons[k].bounds.Y, questLogButtons[k].bounds.Width, questLogButtons[k].bounds.Height, questLogButtons[k].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY()) ? Color.Wheat : Color.White, 4f, drawShadow: false);
                 if (pages[currentPage][k].ShouldDisplayAsNew() || pages[currentPage][k].ShouldDisplayAsComplete())
                 {
                     Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2(questLogButtons[k].bounds.X + 64 + 4, questLogButtons[k].bounds.Y + 44), new Rectangle(pages[currentPage][k].ShouldDisplayAsComplete() ? 341 : 317, 410, 23, 9), Color.White, 0f, new Vector2(11f, 4f), 4f + Game1.dialogueButtonScale * 10f / 250f, flipped: false, 0.99f);
                 }
                 else
                 {
                     Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2(questLogButtons[k].bounds.X + 32, questLogButtons[k].bounds.Y + 28), pages[currentPage][k].IsTimedQuest() ? new Rectangle(410, 501, 9, 9) : new Rectangle(395 + (pages[currentPage][k].IsTimedQuest() ? 3 : 0), 497, 3, 8), Color.White, 0f, Vector2.Zero, 4f, flipped: false, 0.99f);
                 }
                 pages[currentPage][k].IsTimedQuest();
                 SpriteText.drawString(b, pages[currentPage][k].GetName(), questLogButtons[k].bounds.X + 128 + 4, questLogButtons[k].bounds.Y + 20);
             }
         }
     }
     else
     {
         SpriteText.drawStringHorizontallyCenteredAt(b, _shownQuest.GetName(), xPositionOnScreen + base.width / 2 + ((_shownQuest.IsTimedQuest() && _shownQuest.GetDaysLeft() > 0) ? (Math.Max(32, SpriteText.getWidthOfString(_shownQuest.GetName()) / 3) - 32) : 0), yPositionOnScreen + 32);
         if (_shownQuest.IsTimedQuest() && _shownQuest.GetDaysLeft() > 0)
         {
             Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2(xPositionOnScreen + 32, yPositionOnScreen + 48 - 8), new Rectangle(410, 501, 9, 9), Color.White, 0f, Vector2.Zero, 4f, flipped: false, 0.99f);
             Utility.drawTextWithShadow(b, Game1.parseText((pages[currentPage][questPage].GetDaysLeft() > 1) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:QuestLog.cs.11374", pages[currentPage][questPage].GetDaysLeft()) : Game1.content.LoadString("Strings\\StringsFromCSFiles:Quest_FinalDay"), Game1.dialogueFont, base.width - 128), Game1.dialogueFont, new Vector2(xPositionOnScreen + 80, yPositionOnScreen + 48 - 8), Game1.textColor);
         }
         string    description         = Game1.parseText(_shownQuest.GetDescription(), Game1.dialogueFont, base.width - 128);
         Rectangle cached_scissor_rect = b.GraphicsDevice.ScissorRectangle;
         Vector2   description_size    = Game1.dialogueFont.MeasureString(description);
         Rectangle scissor_rect        = default(Rectangle);
         scissor_rect.X      = xPositionOnScreen + 32;
         scissor_rect.Y      = yPositionOnScreen + 96;
         scissor_rect.Height = yPositionOnScreen + height - 32 - scissor_rect.Y;
         scissor_rect.Width  = base.width - 64;
         _scissorRectHeight  = scissor_rect.Height;
         scissor_rect        = Utility.ConstrainScissorRectToScreen(scissor_rect);
         b.End();
         b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, new RasterizerState
         {
             ScissorTestEnable = true
         });
         Game1.graphics.GraphicsDevice.ScissorRectangle = scissor_rect;
         Utility.drawTextWithShadow(b, description, Game1.dialogueFont, new Vector2(xPositionOnScreen + 64, (float)yPositionOnScreen - scrollAmount + 96f), Game1.textColor);
         float yPos = (float)(yPositionOnScreen + 96) + description_size.Y + 32f - scrollAmount;
         if (_shownQuest.ShouldDisplayAsComplete())
         {
             b.End();
             b.GraphicsDevice.ScissorRectangle = cached_scissor_rect;
             b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
             SpriteText.drawString(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:QuestLog.cs.11376"), xPositionOnScreen + 32 + 4, rewardBox.bounds.Y + 21 + 4);
             rewardBox.draw(b);
             if (HasMoneyReward())
             {
                 b.Draw(Game1.mouseCursors, new Vector2(rewardBox.bounds.X + 16, (float)(rewardBox.bounds.Y + 16) - Game1.dialogueButtonScale / 2f), new Rectangle(280, 410, 16, 16), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 1f);
                 SpriteText.drawString(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:LoadGameMenu.cs.11020", _shownQuest.GetMoneyReward()), xPositionOnScreen + 448, rewardBox.bounds.Y + 21 + 4);
             }
         }
         else
         {
             for (int j = 0; j < _objectiveText.Count; j++)
             {
                 if (_shownQuest != null)
                 {
                     _ = (_shownQuest is SpecialOrder);
                 }
                 string parsed_text         = Game1.parseText(_objectiveText[j], width: base.width - 192, whichFont: Game1.dialogueFont);
                 bool   display_as_complete = false;
                 if (_shownQuest != null && _shownQuest is SpecialOrder)
                 {
                     display_as_complete = (_shownQuest as SpecialOrder).objectives[j].IsComplete();
                 }
                 if (!display_as_complete)
                 {
                     Utility.drawWithShadow(b, Game1.mouseCursors, new Vector2((float)(xPositionOnScreen + 96) + 8f * Game1.dialogueButtonScale / 10f, yPos), new Rectangle(412, 495, 5, 4), Color.White, (float)Math.PI / 2f, Vector2.Zero);
                 }
                 Color text_color = Color.DarkBlue;
                 if (display_as_complete)
                 {
                     text_color = Game1.unselectedOptionColor;
                 }
                 Utility.drawTextWithShadow(b, parsed_text, Game1.dialogueFont, new Vector2(xPositionOnScreen + 128, yPos - 8f), text_color);
                 yPos += Game1.dialogueFont.MeasureString(parsed_text).Y;
                 if (_shownQuest != null && _shownQuest is SpecialOrder)
                 {
                     OrderObjective order_objective = (_shownQuest as SpecialOrder).objectives[j];
                     if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress())
                     {
                         Color dark_bar_color = Color.DarkRed;
                         Color bar_color      = Color.Red;
                         if (order_objective.GetCount() >= order_objective.GetMaxCount())
                         {
                             bar_color      = Color.LimeGreen;
                             dark_bar_color = Color.Green;
                         }
                         int       inset = 64;
                         int       objective_count_draw_width = 160;
                         int       notches = 4;
                         Rectangle bar_background_source  = new Rectangle(0, 224, 47, 12);
                         Rectangle bar_notch_source       = new Rectangle(47, 224, 1, 12);
                         int       bar_horizontal_padding = 3;
                         int       bar_vertical_padding   = 3;
                         int       slice_width            = 5;
                         string    objective_count_text   = order_objective.GetCount() + "/" + order_objective.GetMaxCount();
                         int       max_text_width         = (int)Game1.dialogueFont.MeasureString(order_objective.GetMaxCount() + "/" + order_objective.GetMaxCount()).X;
                         int       count_text_width       = (int)Game1.dialogueFont.MeasureString(objective_count_text).X;
                         int       text_draw_position     = xPositionOnScreen + base.width - inset - count_text_width;
                         int       max_text_draw_position = xPositionOnScreen + base.width - inset - max_text_width;
                         Utility.drawTextWithShadow(b, objective_count_text, Game1.dialogueFont, new Vector2(text_draw_position, yPos), Color.DarkBlue);
                         Rectangle bar_draw_position = new Rectangle(xPositionOnScreen + inset, (int)yPos, base.width - inset * 2 - objective_count_draw_width, bar_background_source.Height * 4);
                         if (bar_draw_position.Right > max_text_draw_position - 16)
                         {
                             int adjustment = bar_draw_position.Right - (max_text_draw_position - 16);
                             bar_draw_position.Width -= adjustment;
                         }
                         b.Draw(Game1.mouseCursors2, new Rectangle(bar_draw_position.X, bar_draw_position.Y, slice_width * 4, bar_draw_position.Height), new Rectangle(bar_background_source.X, bar_background_source.Y, slice_width, bar_background_source.Height), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.5f);
                         b.Draw(Game1.mouseCursors2, new Rectangle(bar_draw_position.X + slice_width * 4, bar_draw_position.Y, bar_draw_position.Width - 2 * slice_width * 4, bar_draw_position.Height), new Rectangle(bar_background_source.X + slice_width, bar_background_source.Y, bar_background_source.Width - 2 * slice_width, bar_background_source.Height), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.5f);
                         b.Draw(Game1.mouseCursors2, new Rectangle(bar_draw_position.Right - slice_width * 4, bar_draw_position.Y, slice_width * 4, bar_draw_position.Height), new Rectangle(bar_background_source.Right - slice_width, bar_background_source.Y, slice_width, bar_background_source.Height), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.5f);
                         float quest_progress = (float)order_objective.GetCount() / (float)order_objective.GetMaxCount();
                         if (order_objective.GetMaxCount() < notches)
                         {
                             notches = order_objective.GetMaxCount();
                         }
                         bar_draw_position.X     += 4 * bar_horizontal_padding;
                         bar_draw_position.Width -= 4 * bar_horizontal_padding * 2;
                         for (int i = 1; i < notches; i++)
                         {
                             b.Draw(Game1.mouseCursors2, new Vector2((float)bar_draw_position.X + (float)bar_draw_position.Width * ((float)i / (float)notches), bar_draw_position.Y), bar_notch_source, Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.5f);
                         }
                         bar_draw_position.Y      += 4 * bar_vertical_padding;
                         bar_draw_position.Height -= 4 * bar_vertical_padding * 2;
                         Rectangle rect = new Rectangle(bar_draw_position.X, bar_draw_position.Y, (int)((float)bar_draw_position.Width * quest_progress) - 4, bar_draw_position.Height);
                         b.Draw(Game1.staminaRect, rect, null, bar_color, 0f, Vector2.Zero, SpriteEffects.None, (float)rect.Y / 10000f);
                         rect.X     = rect.Right;
                         rect.Width = 4;
                         b.Draw(Game1.staminaRect, rect, null, dark_bar_color, 0f, Vector2.Zero, SpriteEffects.None, (float)rect.Y / 10000f);
                         yPos += (float)((bar_background_source.Height + 4) * 4);
                     }
                 }
                 _contentHeight = yPos + scrollAmount - (float)scissor_rect.Y;
             }
             b.End();
             b.GraphicsDevice.ScissorRectangle = cached_scissor_rect;
             b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
             if (_shownQuest.CanBeCancelled())
             {
                 cancelQuestButton.draw(b);
             }
             if (NeedsScroll())
             {
                 if (scrollAmount > 0f)
                 {
                     b.Draw(Game1.staminaRect, new Rectangle(scissor_rect.X, scissor_rect.Top, scissor_rect.Width, 4), Color.Black * 0.15f);
                 }
                 if (scrollAmount < _contentHeight - _scissorRectHeight)
                 {
                     b.Draw(Game1.staminaRect, new Rectangle(scissor_rect.X, scissor_rect.Bottom - 4, scissor_rect.Width, 4), Color.Black * 0.15f);
                 }
             }
         }
     }
     if (NeedsScroll())
     {
         upArrow.draw(b);
         downArrow.draw(b);
         scrollBar.draw(b);
     }
     if (currentPage < pages.Count - 1 && questPage == -1)
     {
         forwardButton.draw(b);
     }
     if (currentPage > 0 || questPage != -1)
     {
         backButton.draw(b);
     }
     base.draw(b);
     Game1.mouseCursorTransparency = 1f;
     drawMouse(b);
     if (hoverText.Length > 0)
     {
         IClickableMenu.drawHoverText(b, hoverText, Game1.dialogueFont);
     }
 }