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

Add a tab showing the production summary #38

Merged
merged 15 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add checkbox to only show goods with 'issues' (and fix width calculat…
…ion of table)
  • Loading branch information
veger committed Feb 27, 2024
commit 13040de0af6558b07fa72e81c0d2d09400083362
22 changes: 19 additions & 3 deletions YAFC/Workspace/SummaryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public override void BuildElement(ImGui gui, ProjectPage page) {
}

var table = page.content as ProductionTable;
using var grid = gui.EnterInlineGrid(ElementWidth, 1f);
using var grid = gui.EnterInlineGrid(ElementWidth, ElementSpacing);
foreach (KeyValuePair<string, GoodDetails> entry in view.allGoods) {
float amountAvailable = YAFCRounding((entry.Value.totalProvided > 0 ? entry.Value.totalProvided : 0) + entry.Value.extraProduced);
float amountNeeded = YAFCRounding((entry.Value.totalProvided < 0 ? -entry.Value.totalProvided : 0) + entry.Value.totalNeeded);
if (Math.Abs(amountAvailable - amountNeeded) < Epsilon || amountNeeded == 0) {
if (view.model.showOnlyIssues && (Math.Abs(amountAvailable - amountNeeded) < Epsilon || amountNeeded == 0)) {
continue;
}

Expand Down Expand Up @@ -87,6 +87,7 @@ static private void DrawRequestProduct(ImGui gui, ProductionTableFlow flow, bool

static readonly float Epsilon = 1e-5f;
static readonly float ElementWidth = 3;
static readonly float ElementSpacing = 1;
struct GoodDetails {
public float totalProvided;
public float totalNeeded;
Expand Down Expand Up @@ -142,6 +143,11 @@ protected override void BuildHeader(ImGui gui) {
}

protected override void BuildContent(ImGui gui) {
if (gui.BuildCheckBox("Only show issues", model.showOnlyIssues, out bool newValue)) {
model.showOnlyIssues = newValue;
Recalculate();
}

scrollArea.Build(gui);
}

Expand Down Expand Up @@ -191,7 +197,17 @@ private void Recalculate(bool visualOnly) {
}
}

goodsColumn.width = allGoods.Count * ElementWidth;
int count = 0;
foreach (KeyValuePair<string, GoodDetails> entry in allGoods) {
float amountAvailable = YAFCRounding((entry.Value.totalProvided > 0 ? entry.Value.totalProvided : 0) + entry.Value.extraProduced);
float amountNeeded = YAFCRounding((entry.Value.totalProvided < 0 ? -entry.Value.totalProvided : 0) + entry.Value.totalNeeded);
if (model != null && model.showOnlyIssues && (Math.Abs(amountAvailable - amountNeeded) < Epsilon || amountNeeded == 0)) {
continue;
}
count++;
}

goodsColumn.width = count * (ElementWidth + ElementSpacing);

Rebuild(visualOnly);
scrollArea.RebuildContents();
Expand Down
2 changes: 2 additions & 0 deletions YAFCmodel/Model/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace YAFC.Model {
public class Summary : ProjectPageContents {

public bool showOnlyIssues { get; set; }

public Summary(ModelObject page) : base(page) { }

public override async Task<string> Solve(ProjectPage page) {
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 0.6.2
Date: soon(tm)
Changes:
- Add summary view
- Checkbox to show only goods with 'issues': different consuming/producing amounts

----------------------------------------------------------------------------------------------------------------------
Version: 0.6.1
Expand Down