Skip to content

Commit 4ada615

Browse files
vegershpaass
andauthored
Move the Legacy Summary and Import from clipboard buttons (#261)
The buttons are moved to the main/hamburger menu. The 'left over' plus icon is now used to create a new production tab. --------- Co-authored-by: shpaass <[email protected]>
1 parent ac74c3f commit 4ada615

File tree

9 files changed

+19
-34
lines changed

9 files changed

+19
-34
lines changed

Yafc.UI/ImGui/ImGuiTextInputHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public bool KeyDown(SDL.SDL_Keysym key) {
277277
case SDL.SDL_Scancode.SDL_SCANCODE_END:
278278
SetCaret(int.MaxValue, shift ? selectionAnchor : int.MaxValue);
279279
break;
280-
case SDL.SDL_Scancode.SDL_SCANCODE_V when ctrl && SDL.SDL_HasClipboardText() == SDL.SDL_bool.SDL_TRUE:
280+
case SDL.SDL_Scancode.SDL_SCANCODE_V when ctrl && ImGuiUtils.HasClipboardText():
281281
_ = TextInput(SDL.SDL_GetClipboardText());
282282
break;
283283
case SDL.SDL_Scancode.SDL_SCANCODE_C when ctrl && selectionAnchor != caret:

Yafc.UI/ImGui/ImGuiUtils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public static class ImGuiUtils {
3333
public static readonly Padding DefaultScreenPadding = new Padding(5f, 2f);
3434
public static readonly Padding DefaultIconPadding = new Padding(0.3f);
3535

36+
/// <summary>Returns true when the clipboard holds content</summary>
37+
public static bool HasClipboardText() => SDL.SDL_HasClipboardText() == SDL.SDL_bool.SDL_TRUE;
38+
3639
public static ButtonEvent BuildButton(this ImGui gui, Rect rect, SchemeColor normal, SchemeColor over, SchemeColor down = SchemeColor.None, uint button = SDL.SDL_BUTTON_LEFT) {
3740
if (button == 0) {
3841
button = (uint)InputSystem.Instance.mouseDownButton;

Yafc/Windows/MainScreen.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ private void BuildTabBar(ImGui gui) {
242242
gui.ShowDropDown(gui.lastRect, SettingsDropdown, new Padding(0f, 0f, 0f, 0.5f));
243243
}
244244

245-
if (gui.BuildButton(Icon.Plus)) {
246-
gui.ShowDropDown(gui.lastRect, CreatePageDropdown, new Padding(0f, 0f, 0f, 0.5f));
245+
if (gui.BuildButton(Icon.Plus).WithTooltip(gui, "Create production sheet (Ctrl+" +
246+
ImGuiUtils.ScanToString(SDL.SDL_Scancode.SDL_SCANCODE_T) + ")")) {
247+
248+
ProductionTableView.CreateProductionSheet();
247249
}
248250

249251
gui.allocator = RectAllocator.RightRow;
@@ -312,19 +314,6 @@ public ProjectPage AddProjectPage(string name, FactorioObject? icon, Type conten
312314
return page;
313315
}
314316

315-
private void CreatePageDropdown(ImGui gui) {
316-
foreach (var (type, view) in registeredPageViews) {
317-
view.CreateModelDropdown(gui, type, project);
318-
}
319-
320-
if (SDL.SDL_HasClipboardText() == SDL.SDL_bool.SDL_TRUE) {
321-
gui.AllocateSpacing();
322-
if (gui.BuildContextMenuButton("Import page from clipboard") && gui.CloseDropdown()) {
323-
ProjectPageSettingsPanel.LoadProjectPageFromClipboard();
324-
}
325-
}
326-
}
327-
328317
public void BuildSubHeader(ImGui gui, string text) {
329318
using (gui.EnterGroup(ObjectTooltip.contentPadding)) {
330319
gui.BuildText(text, Font.subheader);
@@ -409,6 +398,10 @@ private void SettingsDropdown(ImGui gui) {
409398
ShowSummaryTab();
410399
}
411400

401+
if (gui.BuildContextMenuButton("Summary (Legacy)") && gui.CloseDropdown()) {
402+
ProjectPageSettingsPanel.Show(null, (name, icon) => Instance.AddProjectPage(name, icon, typeof(ProductionSummary), true, true));
403+
}
404+
412405
if (gui.BuildContextMenuButton("Never Enough Items Explorer", "Ctrl+" + ImGuiUtils.ScanToString(SDL.SDL_Scancode.SDL_SCANCODE_N)) && gui.CloseDropdown()) {
413406
ShowNeie();
414407
}
@@ -417,6 +410,10 @@ private void SettingsDropdown(ImGui gui) {
417410
SelectSingleObjectPanel.Select(Database.objects.explorable, "Open Dependency Explorer", DependencyExplorer.Show);
418411
}
419412

413+
if (gui.BuildContextMenuButton("Import page from clipboard", disabled: !ImGuiUtils.HasClipboardText()) && gui.CloseDropdown()) {
414+
ProjectPageSettingsPanel.LoadProjectPageFromClipboard();
415+
}
416+
420417
BuildSubHeader(gui, "Extra");
421418

422419
if (gui.BuildContextMenuButton("Run Factorio")) {

Yafc/Workspace/AutoPlannerView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ protected override void BuildContent(ImGui gui) {
9797
}
9898
}
9999

100+
/*
100101
public override void CreateModelDropdown(ImGui gui, Type type, Project project) {
101-
/*
102102
if (gui.BuildContextMenuButton("Auto planner (Alpha)"))
103103
{
104104
close = true;
105105
WizardPanel.Show("New auto planner", CreateAutoPlannerWizard);
106106
}
107-
*/
108107
}
108+
*/
109109
}
110110
}

Yafc/Workspace/ProductionSummary/ProductionSummaryView.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,6 @@ public override void Rebuild(bool visualOnly = false) {
311311
base.Rebuild(visualOnly);
312312
}
313313

314-
public override void CreateModelDropdown(ImGui gui, Type type, Project project) {
315-
if (gui.BuildContextMenuButton("Create production summary (Legacy)") && gui.CloseDropdown()) {
316-
ProjectPageSettingsPanel.Show(null, (name, icon) => MainScreen.Instance.AddProjectPage(name, icon, typeof(ProductionSummary), true, true));
317-
}
318-
}
319-
320314
protected override void BuildPageTooltip(ImGui gui, ProductionSummary contents) {
321315

322316
}

Yafc/Workspace/ProductionTable/ProductionTableView.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,6 @@ public static void BuildFavorites(ImGui imgui, FactorioObject? obj, string promp
646646

647647
public override float CalculateWidth() => flatHierarchyBuilder.width;
648648

649-
public override void CreateModelDropdown(ImGui gui, Type type, Project project) {
650-
if (gui.BuildContextMenuButton("Create production sheet", "Ctrl+" + ImGuiUtils.ScanToString(SDL.SDL_Scancode.SDL_SCANCODE_T)) && gui.CloseDropdown()) {
651-
CreateProductionSheet();
652-
}
653-
}
654649
public static void CreateProductionSheet() => ProjectPageSettingsPanel.Show(null, (name, icon) => MainScreen.Instance.AddProjectPage(name, icon, typeof(ProductionTable), true, true));
655650

656651
private static readonly IComparer<Goods> DefaultVariantOrdering = new DataUtils.FactorioObjectComparer<Goods>((x, y) => (y.ApproximateFlow() / MathF.Abs(y.Cost())).CompareTo(x.ApproximateFlow() / MathF.Abs(x.Cost())));

Yafc/Workspace/ProjectPageView.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ protected override void PositionContent(ImGui gui, Rect viewport) {
7171
gui.DrawPanel(viewport, bodyContent);
7272
}
7373

74-
public abstract void CreateModelDropdown(ImGui gui1, Type type, Project project);
75-
7674
public virtual bool ControlKey(SDL.SDL_Scancode code) => false;
7775

7876
public MemoryDrawingSurface GenerateFullPageScreenshot() {

Yafc/Workspace/SummaryView.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,5 @@ public override void SetSearchQuery(SearchQuery query) {
399399
bodyContent.Rebuild();
400400
scrollArea.Rebuild();
401401
}
402-
403-
public override void CreateModelDropdown(ImGui gui, Type type, Project project) {
404-
}
405402
}
406403
}

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Date:
2828
- Add 'Produce it as a spent fuel' recipe selection.
2929
- You can now open projects from a Windows context-menu. If the project was not opened before, then Yafc uses
3030
the launch-settings from the most-recently opened project.
31+
- Move the Legacy Summary and Import from clipboard buttons to the main/hamburger menu.
3132
Bugfixes:
3233
- Several fixes to the legacy summary page, including a regression in 0.8.1.
3334
- Crafters with no enery_source no longer make Yafc refuse to solve the page.

0 commit comments

Comments
 (0)