Skip to content

Commit

Permalink
feat: Add a preference for number of milestones per tooltip line.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaleStan committed Nov 19, 2024
1 parent eed15ca commit fa3f9fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Yafc.Model/Model/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ public class ProjectPreferences(Project owner) : ModelObject<Project>(owner) {
/// The scale to use when drawing icons that have information stored in their background color, stored as a ratio from 0 to 1.
/// </summary>
public float iconScale { get; set; } = .9f;
/// <summary>The maximum number of milestone icons in each line when drawing tooltip headers.</summary>
public int maxMilestonesPerTooltipLine { get; set; } = 28;
public bool showMilestoneOnInaccessible { get; set; } = true;

protected internal override void AfterDeserialize() {
Expand Down
6 changes: 3 additions & 3 deletions Yafc/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ private void BuildHeader(ImGui gui) {
}

// All rows except the last will show at least 22 milestones.
// If displaying 23-28 items per row reduces the number of rows, squish the milestones together slightly.
const int maxItemsPerRow = 28;
// If displaying more items per row (up to the user's limit) reduces the number of rows, squish the milestones together slightly.
int maxItemsPerRow = Project.current.preferences.maxMilestonesPerTooltipLine;
const int minItemsPerRow = 22;
int rows = (milestoneCount + maxItemsPerRow - 1) / maxItemsPerRow;
int itemsPerRow = Math.Max((milestoneCount + rows - 1) / rows, minItemsPerRow);
// 22.5 is the width of the available area of the tooltip. The original code used spacings from -1 (100% overlap) to 0
// (no overlap). We now allow spacings of -0.196 (19.6% overlap) to 0.023 (2.3% stretch).
// (no overlap). At the default max of 28 per row, we allow spacings of -0.196 (19.6% overlap) to 0.023 (2.3% stretch).
float spacing = 22.5f / itemsPerRow - 1f;

using var milestones = Milestones.Instance.currentMilestones.AsEnumerable().GetEnumerator();
Expand Down
14 changes: 14 additions & 0 deletions Yafc/Windows/PreferencesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ private static void DrawGeneral(ImGui gui) {
}
}

// Don't show this preference if it isn't relevant.
// (Takes ~3ms for pY, which would concern me in the regular UI, but should be fine here.)
if (Database.objects.all.Any(o => Milestones.Instance.GetMilestoneResult(o).PopCount() > 22)) {
string overlapMessage = "Some tooltips may want to show multiple rows of milestones. Increasing this number will draw fewer lines in some tooltips, by forcing the milestones to overlap.\n\n"
+ "Minimum: 22\nDefault: 28";
using (gui.EnterRowWithHelpIcon(overlapMessage)) {
gui.BuildText("Maximum milestones per line in tooltips:", topOffset: 0.5f);
if (gui.BuildIntegerInput(preferences.maxMilestonesPerTooltipLine, out int newIntValue) && newIntValue >= 22) {
preferences.RecordUndo().maxMilestonesPerTooltipLine = newIntValue;
gui.Rebuild();
}
}
}

using (gui.EnterRow()) {
gui.BuildText("Reactor layout:", topOffset: 0.5f);
if (gui.BuildTextInput(settings.reactorSizeX + "x" + settings.reactorSizeY, out string newSize, null, delayed: true)) {
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Date:
- Add dependency information for tree and resource spawns, fluid pumping, and asteroid mining.
- (SA) Locations (except nauvis) are now part of the default milestone list.
- Milestone overlays can be displayed on inaccessible objects.
- With 22+ milestones, tooltip headers don't draw them unnecessarily overlapped, and can use multiple lines.
Internal changes:
- Dependency and automation analysis allows more ORs, e.g. "(spawner and capture-ammo) or item-to-place".
----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit fa3f9fe

Please sign in to comment.