internal static void LoadUserConfig() { // Load global user settings into memory UserConfig GlobalUserConfig = UserConfig.Load(ModInstance.Helper.Data); #if DEBUG //GlobalUserConfig = null; // Force full refresh of config file for testing purposes #endif if (GlobalUserConfig == null || GlobalUserConfig.CreatedByVersion < CurrentVersion) { if (GlobalUserConfig == null) { GlobalUserConfig = new UserConfig(); } GlobalUserConfig.CreatedByVersion = CurrentVersion; ModInstance.Helper.Data.WriteJsonFile(UserConfig.DefaultFilename, GlobalUserConfig); } UserConfig = GlobalUserConfig; }
internal static UserConfig Load(IDataHelper DataHelper) { UserConfig Config = DataHelper.ReadJsonFile <UserConfig>(DefaultFilename); if (Config != null) { if (Config.CombineKeyNames == null || !Config.CombineKeyNames.Any()) { Config.CombineKeyNames = new List <string>() { SButton.LeftControl.ToString(), SButton.RightControl.ToString() } } ; if (Config.ProcessingModeExclusions == null) { Config.ProcessingModeExclusions = new List <string>(); } } return(Config); } }
private void Display_RenderedWorld(object sender, RenderedWorldEventArgs e) { if (Game1.activeClickableMenu == null) { GameLocation CurrentLocation = Game1.player.currentLocation; bool IsHoveringPlacedObject = CurrentLocation.Objects.TryGetValue(HoveredTile, out SObject HoveredObject); if (IsHoveringPlacedObject) { if (UserConfig.DrawToolTip) { // Draw a tooltip that shows how many of the machine were combined, and its total combined processing power // Such as: "Quantity: 5\nPower: 465%" if (HoveredObject.TryGetCombinedQuantity(out int CombinedQuantity)) { float UIScaleFactor = Game1.options.zoomLevel / Game1.options.uiScale; SpriteFont DefaultFont = Game1.dialogueFont; int Padding = 25; int MarginBetweenColumns = 10; int MarginBetweenRows = 5; float LabelTextScale = 0.75f; float ValueTextScale = 1.0f; List <string> RowHeaders = new List <string>() { Helper.Translation.Get("ToolTipQuantityLabel"), Helper.Translation.Get("ToolTipPowerLabel") }; List <Vector2> RowHeaderSizes = RowHeaders.Select(x => DefaultFont.MeasureString(x) * LabelTextScale).ToList(); double ProcessingPower = UserConfig.ComputeProcessingPower(CombinedQuantity) * 100.0; string FormattedProcessingPower = string.Format("{0}%", ProcessingPower.ToString("#.#")); List <string> RowValues = new List <string>() { CombinedQuantity.ToString(), FormattedProcessingPower }; List <Vector2> RowValueSizes = RowValues.Select(x => DrawHelpers.MeasureStringWithSpecialNumbers(x, ValueTextScale, 0.0f)).ToList(); // Measure the tooltip List <int> RowHeights = new List <int>(); for (int i = 0; i < RowHeaders.Count; i++) { RowHeights.Add((int)Math.Max(RowHeaderSizes[i].Y, RowValueSizes[i].Y)); } List <int> ColumnWidths = new List <int> { (int)RowHeaderSizes.Max(x => x.X), (int)RowValueSizes.Max(x => x.X) }; int ToolTipTopWidth = Padding + ColumnWidths.Sum() + (ColumnWidths.Count - 1) * MarginBetweenColumns + Padding; int ToolTipHeight = Padding + RowHeights.Sum() + (RowHeights.Count - 1) * MarginBetweenRows + Padding; Point ToolTipTopleft = DrawHelpers.GetTopleftPosition(new Point(ToolTipTopWidth, ToolTipHeight), new Point((int)((MouseScreenPosition.X + UserConfig.ToolTipOffset.X) / UIScaleFactor), (int)((MouseScreenPosition.Y + UserConfig.ToolTipOffset.Y) / UIScaleFactor)), 100); // Draw tooltip background DrawHelpers.DrawBox(e.SpriteBatch, new Rectangle(ToolTipTopleft.X, ToolTipTopleft.Y, ToolTipTopWidth, ToolTipHeight)); // Draw each row's header and value int CurrentY = ToolTipTopleft.Y + Padding; for (int i = 0; i < RowHeights.Count; i++) { int CurrentRowHeight = RowHeights[i]; // Draw the row header Vector2 RowHeaderPosition = new Vector2( ToolTipTopleft.X + Padding + ColumnWidths[0] - RowHeaderSizes[i].X, CurrentY + (RowHeights[i] - RowHeaderSizes[i].Y) / 2.0f ); e.SpriteBatch.DrawString(DefaultFont, RowHeaders[i], RowHeaderPosition, Color.Black, 0.0f, Vector2.Zero, LabelTextScale, SpriteEffects.None, 1.0f); // Draw the row value Vector2 RowValuePosition = new Vector2( ToolTipTopleft.X + Padding + ColumnWidths[0] + MarginBetweenColumns, CurrentY + (RowHeights[i] - RowValueSizes[i].Y) / 2.0f ); DrawHelpers.DrawStringWithSpecialNumbers(e.SpriteBatch, RowValuePosition, RowValues[i], ValueTextScale, Color.White); CurrentY += CurrentRowHeight + MarginBetweenRows; } } } } } }
private void Display_RenderedWorld(object sender, RenderedWorldEventArgs e) { if (Game1.activeClickableMenu == null) { GameLocation CurrentLocation = Game1.player.currentLocation; bool IsHoveringPlacedObject = CurrentLocation.Objects.TryGetValue(HoveredTile, out SObject HoveredObject); if (IsHoveringPlacedObject) { if (UserConfig.DrawToolTip) { // Draw a tooltip that shows how many of the machine were combined, and its total combined processing power // Such as: "Quantity: 5\nPower: 465%" if (HoveredObject.TryGetCombinedQuantity(out int CombinedQuantity)) { Cask Cask = HoveredObject as Cask; bool IsCask = Cask != null; CrabPot CrabPot = HoveredObject as CrabPot; bool IsCrabPot = CrabPot != null; bool IsScarecrow = HoveredObject.IsScarecrow(); bool HasHeldObject = HoveredObject.heldObject?.Value != null; float UIScaleFactor = Game1.options.zoomLevel / Game1.options.uiScale; SpriteFont DefaultFont = Game1.dialogueFont; int Padding = 25; int MarginBetweenColumns = 10; int MarginBetweenRows = 5; float LabelTextScale = 0.75f; float ValueTextScale = 1.0f; bool ShowDurationInfo = UserConfig.ToolTipShowDuration && UserConfig.ShouldModifyProcessingSpeed(HoveredObject); bool ShowQuantityInfo = UserConfig.ToolTipShowQuantity && UserConfig.ShouldModifyInputsAndOutputs(HoveredObject); // Compute row headers List <string> RowHeaders = new List <string>() { Helper.Translation.Get("ToolTipQuantityLabel"), Helper.Translation.Get("ToolTipPowerLabel") }; if (ShowDurationInfo) { if (IsCask) { //RowHeaders.Add(Helper.Translation.Get("ToolTipCaskAgingRateLabel")); if (HasHeldObject) { RowHeaders.Add(Helper.Translation.Get("ToolTipCaskDaysUntilIridiumLabel")); } } else if (IsCrabPot) { RowHeaders.Add(Helper.Translation.Get("ToolTipCrabPotProcessingIntervalLabel")); } else { if (HasHeldObject) { RowHeaders.Add(Helper.Translation.Get("ToolTipMinutesRemainingLabel")); } } } if (ShowQuantityInfo) { if (HasHeldObject && HoveredObject.HasModifiedOutput()) { RowHeaders.Add(Helper.Translation.Get("ToolTipProducedQuantityLabel")); } } if (IsScarecrow) { RowHeaders.Add(Helper.Translation.Get("ToolTipScarecrowRadiusLabel")); } List <Vector2> RowHeaderSizes = RowHeaders.Select(x => DefaultFont.MeasureString(x) * LabelTextScale).ToList(); double ProcessingPower = UserConfig.ComputeProcessingPower(CombinedQuantity) * 100.0; string FormattedProcessingPower = string.Format("{0}%", ProcessingPower.ToString("0.#")); // Compute row values List <string> RowValues = new List <string>() { CombinedQuantity.ToString(), FormattedProcessingPower }; if (ShowDurationInfo) { if (IsCask) { //RowValues.Add(Cask.agingRate.Value.ToString("0.##")); if (HasHeldObject) { RowValues.Add(Math.Ceiling(Cask.daysToMature.Value / Cask.agingRate.Value).ToString("0.##")); } } else if (IsCrabPot) { CrabPot.TryGetProcessingInterval(out double Power, out double IntervalHours, out int IntervalMinutes); RowValues.Add(IntervalMinutes.ToString()); } else { if (HasHeldObject) { RowValues.Add(HoveredObject.MinutesUntilReady.ToString("0.##")); } } } if (ShowQuantityInfo) { if (HasHeldObject && HoveredObject.HasModifiedOutput()) { RowValues.Add(HoveredObject.heldObject.Value.Stack.ToString()); } } if (IsScarecrow) { // Subtract 1 because the game internally counts the scarecrow's occupied tile as part of its radius, but users usually would be confused by that // So a typical user expects radius=8 for a regular scarecrow, even though the game does its calculations with radius=9 int OriginalRadius = HoveredObject.GetScarecrowBaseRadius() - 1; int AlteredRadius = HoveredObject.GetScarecrowRadius() - 1; //RowValues.Add(string.Format("{0}-->{1}", OriginalRadius, AlteredRadius)); RowValues.Add(AlteredRadius.ToString()); } List <Vector2> RowValueSizes = RowValues.Select(x => DrawHelpers.MeasureStringWithSpecialNumbers(x, ValueTextScale, 0.0f)).ToList(); // Measure the tooltip List <int> RowHeights = new List <int>(); for (int i = 0; i < RowHeaders.Count; i++) { RowHeights.Add((int)Math.Max(RowHeaderSizes[i].Y, RowValueSizes[i].Y)); } List <int> ColumnWidths = new List <int> { (int)RowHeaderSizes.Max(x => x.X), (int)RowValueSizes.Max(x => x.X) }; int ToolTipTopWidth = Padding + ColumnWidths.Sum() + (ColumnWidths.Count - 1) * MarginBetweenColumns + Padding; int ToolTipHeight = Padding + RowHeights.Sum() + (RowHeights.Count - 1) * MarginBetweenRows + Padding; Point ToolTipTopleft = DrawHelpers.GetTopleftPosition(new Point(ToolTipTopWidth, ToolTipHeight), new Point((int)((MouseScreenPosition.X + UserConfig.ToolTipOffset.X) / UIScaleFactor), (int)((MouseScreenPosition.Y + UserConfig.ToolTipOffset.Y) / UIScaleFactor)), 100); // Draw tooltip background DrawHelpers.DrawBox(e.SpriteBatch, new Rectangle(ToolTipTopleft.X, ToolTipTopleft.Y, ToolTipTopWidth, ToolTipHeight)); // Draw each row's header and value int CurrentY = ToolTipTopleft.Y + Padding; for (int i = 0; i < RowHeights.Count; i++) { int CurrentRowHeight = RowHeights[i]; // Draw the row header Vector2 RowHeaderPosition = new Vector2( ToolTipTopleft.X + Padding + ColumnWidths[0] - RowHeaderSizes[i].X, CurrentY + (RowHeights[i] - RowHeaderSizes[i].Y) / 2.0f ); e.SpriteBatch.DrawString(DefaultFont, RowHeaders[i], RowHeaderPosition, Color.Black, 0.0f, Vector2.Zero, LabelTextScale, SpriteEffects.None, 1.0f); // Draw the row value Vector2 RowValuePosition = new Vector2( ToolTipTopleft.X + Padding + ColumnWidths[0] + MarginBetweenColumns, CurrentY + (RowHeights[i] - RowValueSizes[i].Y) / 2.0f ); DrawHelpers.DrawStringWithSpecialNumbers(e.SpriteBatch, RowValuePosition, RowValues[i], ValueTextScale, Color.White); CurrentY += CurrentRowHeight + MarginBetweenRows; } } } } } }