private void BuildUnitPerTime(ImGui gui, bool fluid, ProjectPreferences preferences)
        {
            var unit    = fluid ? preferences.fluidUnit : preferences.itemUnit;
            var newUnit = unit;

            if (gui.BuildRadioButton("Simple Amount" + preferences.GetPerTimeUnit().suffix, unit == 0f))
            {
                newUnit = 0f;
            }
            using (gui.EnterRow())
            {
                if (gui.BuildRadioButton("Custom: 1 unit equals", unit != 0f))
                {
                    newUnit = 1f;
                }
                gui.AllocateSpacing();
                gui.allocator = RectAllocator.RightRow;
                if (!fluid)
                {
                    if (gui.BuildButton("Set from belt"))
                    {
                        gui.ShowDropDown((ImGui dropGui, ref bool closed) =>
                        {
                            closed = dropGui.BuildInlineObejctListAndButton <Entity>(Database.entities.all.Where(x => x.beltItemsPerSecond > 0f).ToArray(), DataUtils.DefaultOrdering, setBelt =>
                            {
                                preferences.RecordUndo(true);
                                preferences.itemUnit = setBelt.beltItemsPerSecond;
                            }, "Select belt", extra: b => DataUtils.FormatAmount(b.beltItemsPerSecond, UnitOfMeasure.PerSecond));
                            gui.Rebuild();
                        });
                    }
                }
                gui.BuildText("per second");
                if (gui.BuildTextInput(DataUtils.FormatAmount(unit, UnitOfMeasure.None), out var updated, null, Icon.None, true) &&
                    DataUtils.TryParseAmount(updated, out var parsed, UnitOfMeasure.None))
                {
                    newUnit = parsed;
                }
            }
            gui.AllocateSpacing(1f);

            if (newUnit != unit)
            {
                preferences.RecordUndo(true);
                if (fluid)
                {
                    preferences.fluidUnit = newUnit;
                }
                else
                {
                    preferences.itemUnit = newUnit;
                }
            }
        }
Exemple #2
0
        private void BuildRecipeEntity(ImGui gui, RecipeRow recipe)
        {
            if (recipe.isOverviewMode)
            {
                return;
            }
            if (gui.BuildFactorioObjectWithAmount(recipe.entity, (float)(recipe.recipesPerSecond * recipe.parameters.recipeTime), UnitOfMeasure.None) && recipe.recipe.crafters.Count > 0)
            {
                gui.ShowDropDown(((ImGui dropGui, ref bool closed) =>
                {
                    closed = dropGui.BuildInlineObejctListAndButton(recipe.recipe.crafters, DataUtils.FavouriteCrafter, sel =>
                    {
                        DataUtils.FavouriteCrafter.AddToFavourite(sel);
                        if (recipe.entity == sel)
                        {
                            return;
                        }
                        recipe.RecordUndo().entity = sel;
                        if (!sel.energy.fuels.Contains(recipe.fuel))
                        {
                            recipe.fuel = recipe.entity.energy.fuels.AutoSelect(DataUtils.FavouriteFuel);
                        }
                    }, "Select crafting entity");
                }));
            }

            gui.AllocateSpacing(0.5f);
            BuildGoodsIcon(gui, recipe.fuel, (float)(recipe.parameters.fuelUsagePerSecondPerRecipe * recipe.recipesPerSecond), ProductDropdownType.Fuel, recipe,
                           recipe.linkRoot);
        }
Exemple #3
0
        private void BuildBeltInserterInfo(ImGui gui, float amount, float buildingCount, ref bool closed)
        {
            var prefs    = Project.current.preferences;
            var belt     = prefs.defaultBelt;
            var inserter = prefs.defaultInserter;

            if (belt == null || inserter == null)
            {
                return;
            }

            var beltCount            = amount / belt.beltItemsPerSecond;
            var buildingsPerHalfBelt = belt.beltItemsPerSecond * buildingCount / (amount * 2f);
            var click = false;

            using (gui.EnterRow())
            {
                click |= gui.BuildFactorioObjectButton(belt);
                gui.BuildText(DataUtils.FormatAmount(beltCount, UnitOfMeasure.None));
                if (buildingsPerHalfBelt > 0f)
                {
                    gui.BuildText("(Buildings per half belt: " + DataUtils.FormatAmount(buildingsPerHalfBelt, UnitOfMeasure.None) + ")");
                }
            }

            using (gui.EnterRow())
            {
                var capacity     = prefs.inserterCapacity;
                var inserterBase = inserter.inserterSwingTime * amount / capacity;
                click |= gui.BuildFactorioObjectButton(inserter);
                var text = DataUtils.FormatAmount(inserterBase, UnitOfMeasure.None);
                if (buildingCount > 1)
                {
                    text += " (" + DataUtils.FormatAmount(inserterBase / buildingCount, UnitOfMeasure.None) + "/building)";
                }
                gui.BuildText(text);
                if (capacity > 1)
                {
                    var withBeltSwingTime = inserter.inserterSwingTime + 2f * (capacity - 1.5f) / belt.beltItemsPerSecond;
                    var inserterToBelt    = amount * withBeltSwingTime / capacity;
                    click |= gui.BuildFactorioObjectButton(belt);
                    gui.AllocateSpacing(-1.5f);
                    click |= gui.BuildFactorioObjectButton(inserter);
                    text   = DataUtils.FormatAmount(inserterToBelt, UnitOfMeasure.None, "~");
                    if (buildingCount > 1)
                    {
                        text += " (" + DataUtils.FormatAmount(inserterToBelt / buildingCount, UnitOfMeasure.None) + "/b)";
                    }
                    gui.BuildText(text);
                }
            }

            if (click)
            {
                PreferencesScreen.Show();
                closed = true;
            }
        }
 protected override void BuildContent(ImGui gui)
 {
     if (model == null)
     {
         return;
     }
     BuildSummary(gui, model);
     gui.AllocateSpacing();
     flatHierarchyBuilder.Build(gui);
     gui.SetMinWidth(flatHierarchyBuilder.width);
 }
 public override void Build(ImGui gui)
 {
     gui.spacing = 1f;
     BuildHeader(gui, "Milestones");
     gui.BuildText("Please select objects that you already have access to:");
     gui.AllocateSpacing(2f);
     MilestonesWidget.Instance.Build(gui);
     gui.AllocateSpacing(2f);
     gui.BuildText("For your convinience, YAFC will show objects you DON'T have access to based on this selection", wrap: true);
     gui.BuildText("These are called 'Milestones'. By default all science packs are added as milestones, but this does not have to be this way! " +
                   "You can define your own milestones: Any item, recipe, entity or technology may be added as a milestone. For example you can add advanced " +
                   "electronic circuits as a milestone, and YAFC will display everything that is locked behind those circuits", wrap: true);
     using (gui.EnterRow())
     {
         if (gui.BuildButton("Edit milestones", SchemeColor.Grey))
         {
             MilestonesEditor.Show();
         }
         if (gui.RemainingRow().BuildButton("Done"))
         {
             Close();
         }
     }
 }
        public override void Build(ImGui gui)
        {
            BuildHeader(gui, "Units of measure");
            gui.BuildText("Unit of time:", Font.subheader);
            var prefs = Project.current.preferences;

            using (gui.EnterRow())
            {
                if (gui.BuildRadioButton("Second", prefs.time == 1))
                {
                    prefs.RecordUndo(true).time = 1;
                }
                if (gui.BuildRadioButton("Minute", prefs.time == 60))
                {
                    prefs.RecordUndo(true).time = 60;
                }
                if (gui.BuildRadioButton("Hour", prefs.time == 3600))
                {
                    prefs.RecordUndo(true).time = 3600;
                }
                if (gui.BuildRadioButton("Custom", prefs.time != 1 && prefs.time != 60 && prefs.time != 3600))
                {
                    prefs.RecordUndo(true).time = 0;
                }
                if (gui.BuildTextInput(prefs.time.ToString(), out var newTime, null, delayed: true) && int.TryParse(newTime, out var parsed))
                {
                    prefs.RecordUndo(true).time = parsed;
                }
            }
            gui.AllocateSpacing(1f);
            gui.BuildText("Item production/consumption:", Font.subheader);
            BuildUnitPerTime(gui, false, prefs);
            gui.BuildText("Fluid production/consumption:", Font.subheader);
            BuildUnitPerTime(gui, true, prefs);
            if (gui.BuildButton("Done"))
            {
                Close();
            }
            if (prefs.justChanged)
            {
                MainScreen.Instance.RebuildProjectView();
            }
        }
Exemple #7
0
 public override void Build(ImGui gui)
 {
     BuildHeader(gui, title);
     if (message != null)
     {
         gui.BuildText(message, wrap: true);
     }
     gui.AllocateSpacing(2f);
     using (gui.EnterRow(allocator: RectAllocator.RightRow))
     {
         if (gui.BuildButton(yes))
         {
             CloseWithResult(true);
         }
         if (no != null && gui.BuildButton(no, SchemeColor.Grey))
         {
             CloseWithResult(false);
         }
     }
 }
        public override void Build(ImGui gui)
        {
            BuildHeader(gui, "Module customisation");
            if (recipe.modules == null)
            {
                if (gui.BuildButton("Enable custom modules"))
                {
                    recipe.RecordUndo().modules = new CustomModules(recipe);
                }
            }
            else
            {
                gui.BuildText("Internal modules:", Font.subheader);
                gui.BuildText("Leave zero amount to fill the remainings slots");
                DrawRecipeModules(gui, null);
                gui.BuildText("Beacon modules:", Font.subheader);
                if (recipe.modules.beacon == null)
                {
                    gui.BuildText("Use default parameters");
                    if (gui.BuildButton("Override beacons as well"))
                    {
                        gui.ShowDropDown(SelectBeacon);
                    }
                }
                else
                {
                    if (gui.BuildFactorioObjectButtonWithText(recipe.modules.beacon))
                    {
                        gui.ShowDropDown(SelectBeacon);
                    }
                    gui.BuildText("Input the amount of modules, not the amount of beacons. Single beacon can hold " + recipe.modules.beacon.moduleSlots + " modules.", wrap: true);
                    DrawRecipeModules(gui, recipe.modules.beacon);
                }
            }

            gui.AllocateSpacing(3f);
            if (gui.BuildButton("Done"))
            {
                Close();
            }
        }
Exemple #9
0
        private void BuildRecipeEntity(ImGui gui, RecipeRow recipe)
        {
            if (recipe.isOverviewMode)
            {
                return;
            }
            bool clicked;

            if (recipe.fixedBuildings > 0)
            {
                var evt = gui.BuildFactorioObjectWithEditableAmount(recipe.entity, recipe.fixedBuildings, UnitOfMeasure.None, out var newAmount);
                if (evt == GoodsWithAmountEvent.TextEditing)
                {
                    recipe.RecordUndo().fixedBuildings = newAmount;
                }
                clicked = evt == GoodsWithAmountEvent.ButtonClick;
            }
            else
            {
                clicked = gui.BuildFactorioObjectWithAmount(recipe.entity, recipe.buildingCount, UnitOfMeasure.None) && recipe.recipe.crafters.Count > 0;
            }


            if (clicked)
            {
                ShowEntityDropPown(gui, recipe);
            }

            gui.AllocateSpacing(0.5f);
            if (recipe.fuel != Database.voidEnergy)
            {
                BuildGoodsIcon(gui, recipe.fuel, recipe.links.fuel, (float)(recipe.parameters.fuelUsagePerSecondPerRecipe * recipe.recipesPerSecond), ProductDropdownType.Fuel, recipe, recipe.linkRoot);
            }
            else
            {
                if (recipe.recipe == Database.electricityGeneration && recipe.entity.factorioType == "solar-panel")
                {
                    BuildSolarPanelAccumulatorView(gui, recipe);
                }
            }
        }
        private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
        {
            var textcolor  = SchemeColor.BackgroundText;
            var bgColor    = SchemeColor.Background;
            var isBuilding = gui.isBuilding;
            var recipe     = entry.recipe;
            var waste      = recipe.RecipeWaste();

            if (isBuilding)
            {
                if (entry.entryStatus == EntryStatus.NotAccessible)
                {
                    bgColor   = SchemeColor.None;
                    textcolor = SchemeColor.BackgroundTextFaint;
                }
                else if (entry.flow > 0f)
                {
                    bgColor   = SchemeColor.Secondary;
                    textcolor = SchemeColor.SecondaryText;
                }
                else if (waste > 0.95f)
                {
                    bgColor   = SchemeColor.Error;
                    textcolor = SchemeColor.ErrorText;
                }
            }
            using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textcolor))
            {
                using (gui.EnterFixedPositioning(4f, 0f, default))
                {
                    gui.allocator = RectAllocator.Stretch;
                    gui.spacing   = 0f;
                    gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained);
                    gui.BuildText(DataUtils.FormatAmount(recipe.Cost(), UnitOfMeasure.None, "¥"), align: RectAlignment.Middle);
                }
                gui.AllocateSpacing();
                gui.allocator = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign;
                gui.BuildText(recipe.locName, wrap: true);
                if (recipe.ingredients.Length + recipe.products.Length <= 8)
                {
                    using (gui.EnterRow())
                    {
                        DrawIngredients(gui, entry.recipe);
                        gui.allocator = RectAllocator.RightRow;
                        DrawProducts(gui, entry.recipe);
                        if (recipe.products.Length < 3 && recipe.ingredients.Length < 5)
                        {
                            gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f);
                        }
                        else if (recipe.products.Length < 3)
                        {
                            gui.allocator = RectAllocator.RemainigRow;
                        }
                        gui.BuildIcon(Icon.ArrowRight, 3f);
                    }
                }
                else
                {
                    using (gui.EnterRow())
                        DrawIngredients(gui, entry.recipe);

                    using (gui.EnterRow())
                    {
                        gui.BuildIcon(Icon.ArrowDownRight, 3f);
                        gui.allocator = RectAllocator.RightRow;
                        DrawProducts(gui, entry.recipe);
                    }
                }
                var importance = CostAnalysis.Instance.GetBuildingAmount(recipe, entry.recipeFlow);
                if (importance != null)
                {
                    gui.BuildText(importance, wrap: true);
                }
            }

            if (isBuilding)
            {
                var rect = gui.lastRect;
                if (entry.flow > 0f)
                {
                    var percentFlow = MathUtils.Clamp(entry.flow / currentFlow, 0f, 1f);
                    rect.Width *= percentFlow;
                    gui.DrawRectangle(rect, SchemeColor.Primary);
                }
                else if (waste <= 0f)
                {
                    bgColor = SchemeColor.Secondary;
                }
                else
                {
                    rect.Width *= (1f - entry.recipe.RecipeWaste());
                    gui.DrawRectangle(rect, SchemeColor.Secondary);
                }
                gui.DrawRectangle(gui.lastRect, bgColor);
            }
        }
        public override void Build(ImGui gui)
        {
            BuildHeader(gui, "Module customisation");
            if (recipe.modules == null)
            {
                if (gui.BuildButton("Enable custom modules"))
                {
                    recipe.RecordUndo().modules = new CustomModules(recipe);
                }
            }
            else
            {
                var effects = new ModuleEffects();
                if (recipe.entity?.moduleSlots > 0)
                {
                    gui.BuildText("Internal modules:", Font.subheader);
                    gui.BuildText("Leave zero amount to fill the remainings slots");
                    DrawRecipeModules(gui, null, ref effects);
                }
                else
                {
                    gui.BuildText("This building doesn't have module slots, but can be affected by beacons");
                }
                gui.BuildText("Beacon modules:", Font.subheader);
                if (recipe.modules.beacon == null)
                {
                    gui.BuildText("Use default parameters");
                    if (gui.BuildButton("Override beacons as well"))
                    {
                        SelectBeacon(gui);
                    }
                    var defaultFiller = recipe.GetModuleFiller();
                    if (defaultFiller != null && defaultFiller.beacon != null && defaultFiller.beaconModule != null)
                    {
                        effects.AddModules(defaultFiller.beaconModule.module, defaultFiller.beacon.beaconEfficiency * defaultFiller.beacon.moduleSlots * defaultFiller.beaconsPerBuilding);
                    }
                }
                else
                {
                    if (gui.BuildFactorioObjectButtonWithText(recipe.modules.beacon))
                    {
                        SelectBeacon(gui);
                    }
                    gui.BuildText("Input the amount of modules, not the amount of beacons. Single beacon can hold " + recipe.modules.beacon.moduleSlots + " modules.", wrap: true);
                    DrawRecipeModules(gui, recipe.modules.beacon, ref effects);
                }

                gui.BuildText("Current effects:", Font.subheader);
                gui.BuildText("Productivity bonus: " + DataUtils.FormatAmount(effects.productivity, UnitOfMeasure.Percent));
                gui.BuildText("Speed bonus: " + DataUtils.FormatAmount(effects.speedMod, UnitOfMeasure.Percent) + " (Crafting speed: " + DataUtils.FormatAmount((recipe.entity?.craftingSpeed ?? 1f) * (1f + effects.speedMod), UnitOfMeasure.None) + ")");
                var energyUsageLine = "Energy usage: " + DataUtils.FormatAmount(effects.energyUsageMod, UnitOfMeasure.Percent);
                if (!recipe.recipe.flags.HasFlagAny(RecipeFlags.UsesFluidTemperature | RecipeFlags.ScaleProductionWithPower) && recipe.entity != null)
                {
                    energyUsageLine += " (" + DataUtils.FormatAmount(effects.energyUsageMod * recipe.entity.power / recipe.entity.energy.effectivity, UnitOfMeasure.Megawatt) + " per building)";
                }
                gui.BuildText(energyUsageLine);
            }

            gui.AllocateSpacing(3f);
            using (gui.EnterRow(allocator: RectAllocator.RightRow))
            {
                if (gui.BuildButton("Done"))
                {
                    Close();
                }
                if (recipe.modules != null && gui.BuildButton("Copy settings", SchemeColor.Grey))
                {
                    if (copiedModuleSettings == null)
                    {
                        MessageBox.Show("Info", "Use ctrl+click on module slot to paste settings", "Ok");
                    }
                    copiedModuleSettings = JsonUtils.SaveToJson(recipe.modules);
                }
                gui.allocator = RectAllocator.LeftRow;
                if (recipe.modules != null && gui.BuildRedButton("Remove module customisation") == ImGuiUtils.Event.Click)
                {
                    recipe.RecordUndo().modules = null;
                    Close();
                }
            }
        }
Exemple #12
0
        protected override void BuildContent(ImGui gui)
        {
            if (model == null)
            {
                return;
            }
            var elementsPerRow = MathUtils.Floor((flatHierarchyBuilder.width - 2f) / 4f);

            gui.spacing = 1f;
            var pad = new Padding(1f, 0.2f);

            using (gui.EnterGroup(pad))
            {
                gui.BuildText("Desired products and amounts:");
                using (var grid = gui.EnterInlineGrid(3f, 1f, elementsPerRow))
                {
                    foreach (var link in model.links)
                    {
                        if (link.amount != 0f)
                        {
                            grid.Next();
                            DrawDesiredProduct(gui, link);
                        }
                    }

                    grid.Next();
                    if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimalyAlt, size: 2.5f))
                    {
                        SelectObjectPanel.Select(Database.goods.all, "Add desired product", product =>
                        {
                            if (model.linkMap.TryGetValue(product, out var existing))
                            {
                                if (existing.amount != 0)
                                {
                                    return;
                                }
                                existing.RecordUndo().amount = 1f;
                            }
                            else
                            {
                                model.RecordUndo().links.Add(new ProductionLink(model, product)
                                {
                                    amount = 1f
                                });
                            }
                        });
                    }
                }
            }
            if (gui.isBuilding)
            {
                gui.DrawRectangle(gui.lastRect, SchemeColor.Background, RectangleBorder.Thin);
            }

            if (model.flow.Length > 0 && model.flow[0].amount < -1e-5f)
            {
                using (gui.EnterGroup(pad))
                {
                    gui.BuildText("Summary ingredients:");
                    var grid = gui.EnterInlineGrid(3f, 1f, elementsPerRow);
                    BuildTableIngredients(gui, model, model, ref grid);
                    grid.Dispose();
                }
                if (gui.isBuilding)
                {
                    gui.DrawRectangle(gui.lastRect, SchemeColor.Background, RectangleBorder.Thin);
                }
            }

            if (model.flow.Length > 0 && model.flow[model.flow.Length - 1].amount > 1e-5f)
            {
                using (gui.EnterGroup(pad))
                {
                    gui.BuildText("Extra products:");
                    var grid = gui.EnterInlineGrid(3f, 1f, elementsPerRow);
                    BuildTableProducts(gui, model, model, ref grid);
                    grid.Dispose();
                }
                if (gui.isBuilding)
                {
                    gui.DrawRectangle(gui.lastRect, SchemeColor.Background, RectangleBorder.Thin);
                }
            }
            gui.AllocateSpacing();
            flatHierarchyBuilder.Build(gui);
            gui.SetMinWidth(flatHierarchyBuilder.width);
        }
Exemple #13
0
        public override void Build(ImGui gui)
        {
            BuildHeader(gui, "Module autofill parameters");
            BuildSimple(gui, modules);
            if (gui.BuildCheckBox("Fill modules in miners", modules.fillMiners, out var newFill))
            {
                modules.RecordUndo().fillMiners = newFill;
            }
            gui.AllocateSpacing();
            gui.BuildText("Filler module:", Font.subheader);
            gui.BuildText("Use this module when aufofill doesn't add anything (for example when productivity modules doesn't fit)", wrap: true);
            if (gui.BuildFactorioObjectButtonWithText(modules.fillerModule))
            {
                SelectObjectPanel.Select(Database.allModules, "Select filler module", select => { modules.RecordUndo().fillerModule = select; }, true);
            }

            gui.AllocateSpacing();
            gui.BuildText("Beacons & beacon modules:", Font.subheader);
            if (gui.BuildFactorioObjectButtonWithText(modules.beacon))
            {
                SelectObjectPanel.Select(Database.allBeacons, "Select beacon", select =>
                {
                    modules.RecordUndo();
                    modules.beacon = select;
                    if (modules.beaconModule != null && (modules.beacon == null || !modules.beacon.CanAcceptModule(modules.beaconModule.module)))
                    {
                        modules.beaconModule = null;
                    }
                    gui.Rebuild();
                }, true);
            }

            if (gui.BuildFactorioObjectButtonWithText(modules.beaconModule))
            {
                SelectObjectPanel.Select(Database.allModules.Where(x => modules.beacon?.CanAcceptModule(x.module) ?? false), "Select module for beacon", select => { modules.RecordUndo().beaconModule = select; }, true);
            }

            using (gui.EnterRow())
            {
                gui.BuildText("Beacons per building: ");
                if (gui.BuildTextInput(modules.beaconsPerBuilding.ToString(), out var newText, null, Icon.None, true, new Padding(0.5f, 0f)) &&
                    int.TryParse(newText, out var newAmount) && newAmount > 0)
                {
                    modules.RecordUndo().beaconsPerBuilding = newAmount;
                }
            }
            gui.BuildText("Please note that beacons themself are not part of the calculation", wrap: true);

            using (gui.EnterRow())
            {
                gui.BuildText("Mining productivity bonus (project-wide setting): ");
                if (gui.BuildTextInput(DataUtils.FormatAmount(Project.current.settings.miningProductivity, UnitOfMeasure.Percent), out var newText, null, Icon.None, true, new Padding(0.5f, 0f)) &&
                    DataUtils.TryParseAmount(newText, out var newAmount, UnitOfMeasure.Percent))
                {
                    Project.current.settings.RecordUndo().miningProductivity = newAmount;
                }
            }

            if (gui.BuildButton("Done"))
            {
                Close();
            }
        }
Exemple #14
0
        protected override void BuildContents(ImGui gui)
        {
            gui.allocator = RectAllocator.Center;
            gui.BuildText("Yet Another Factorio Calculator", Font.header, align: RectAlignment.Middle);
            gui.BuildText("Copyright 2020 ShadowTheAge", align: RectAlignment.Middle);
            gui.allocator = RectAllocator.LeftAlign;
            gui.AllocateSpacing(1.5f);
            gui.BuildText("This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.", wrap: true);
            gui.BuildText("This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.", wrap: true);
            using (gui.EnterRow(0.3f))
            {
                gui.BuildText("Full license text:");
                BuildLink(gui, "https://gnu.org/licenses/gpl-3.0.html");
            }
            using (gui.EnterRow(0.3f))
            {
                gui.BuildText("Github YAFC page and documentation:");
                BuildLink(gui, "https://github.com/ShadowTheAge/yafc");
            }
            gui.AllocateSpacing(1.5f);
            gui.BuildText("Free and open-source third-party libraries used:", Font.subheader);
            BuildLink(gui, "https://dotnet.microsoft.com/", "Microsoft .NET core and libraries");
            using (gui.EnterRow(0.3f))
            {
                BuildLink(gui, "https://libsdl.org/index.php", "Simple DirectMedia Layer 2.0");
                gui.BuildText("and");
                BuildLink(gui, "https://github.com/flibitijibibo/SDL2-CS", "SDL2-CS");
            }
            using (gui.EnterRow(0.3f))
            {
                gui.BuildText("Libraries for SDL2:");
                BuildLink(gui, "http://libpng.org/pub/png/libpng.html", "libpng,");
                BuildLink(gui, "http://libjpeg.sourceforge.net/", "libjpeg,");
                BuildLink(gui, "https://freetype.org", "libfreetype");
                gui.BuildText("and");
                BuildLink(gui, "https://zlib.net/", "zlib");
            }
            using (gui.EnterRow(0.3f))
            {
                gui.BuildText("Google");
                BuildLink(gui, "https://developers.google.com/optimization", "OR-Tools,");
                BuildLink(gui, "https://fonts.google.com/specimen/Roboto", "Roboto font family");
                gui.BuildText("and");
                BuildLink(gui, "https://material.io/resources/icons", "Material Design Icon collection");
            }

            using (gui.EnterRow(0.3f))
            {
                BuildLink(gui, "https://lua.org/", "Lua 5.2");
                gui.BuildText("plus");
                BuildLink(gui, "https://github.com/pkulchenko/serpent", "Serpent library");
                gui.BuildText("and small bits from");
                BuildLink(gui, "https://github.com/NLua", "NLua");
            }

            using (gui.EnterRow(0.3f))
            {
                BuildLink(gui, "https://wiki.factorio.com/", "Documentation on Factorio Wiki");
                gui.BuildText("and");
                BuildLink(gui, "https://lua-api.factorio.com/latest/", "Factorio API reference");
            }

            gui.AllocateSpacing(1.5f);
            gui.allocator = RectAllocator.Center;
            gui.BuildText("Factorio name, content and materials are trademarks and copyrights of Wube Software");
            BuildLink(gui, "https://factorio.com/");
        }
        public override void Build(ImGui gui)
        {
            BuildHeader(gui, "Preferences");
            gui.BuildText("Unit of time:", Font.subheader);
            var prefs = Project.current.preferences;

            using (gui.EnterRow())
            {
                if (gui.BuildRadioButton("Second", prefs.time == 1))
                {
                    prefs.RecordUndo(true).time = 1;
                }
                if (gui.BuildRadioButton("Minute", prefs.time == 60))
                {
                    prefs.RecordUndo(true).time = 60;
                }
                if (gui.BuildRadioButton("Hour", prefs.time == 3600))
                {
                    prefs.RecordUndo(true).time = 3600;
                }
                if (gui.BuildRadioButton("Custom", prefs.time != 1 && prefs.time != 60 && prefs.time != 3600))
                {
                    prefs.RecordUndo(true).time = 0;
                }
                if (gui.BuildTextInput(prefs.time.ToString(), out var newTime, null, delayed: true) && int.TryParse(newTime, out var parsed))
                {
                    prefs.RecordUndo(true).time = parsed;
                }
            }
            gui.AllocateSpacing(1f);
            gui.BuildText("Item production/consumption:", Font.subheader);
            BuildUnitPerTime(gui, false, prefs);
            gui.BuildText("Fluid production/consumption:", Font.subheader);
            BuildUnitPerTime(gui, true, prefs);

            ChoiceObject(gui, "Default belt:", Database.allBelts, prefs.defaultBelt, s =>
            {
                prefs.RecordUndo().defaultBelt = s;
                gui.Rebuild();
            });
            ChoiceObject(gui, "Default inserter:", Database.allInserters, prefs.defaultInserter, s =>
            {
                prefs.RecordUndo().defaultInserter = s;
                gui.Rebuild();
            });

            using (gui.EnterRow())
            {
                gui.BuildText("Inserter capacity:", topOffset: 0.5f);
                if (gui.BuildTextInput(prefs.inserterCapacity.ToString(), out var newText2, null, Icon.None, true) && int.TryParse(newText2, out var capacity2))
                {
                    prefs.RecordUndo().inserterCapacity = capacity2;
                }
            }

            if (gui.BuildButton("Done"))
            {
                Close();
            }
            if (prefs.justChanged)
            {
                MainScreen.Instance.RebuildProjectView();
            }
        }
Exemple #16
0
        private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
        {
            var textcolor  = SchemeColor.BackgroundText;
            var bgColor    = SchemeColor.Background;
            var isBuilding = gui.isBuilding;
            var recipe     = entry.recipe;
            var waste      = recipe.RecipeWaste(atCurrentMilestones);

            if (isBuilding)
            {
                if (entry.entryStatus == EntryStatus.NotAccessible)
                {
                    bgColor   = SchemeColor.None;
                    textcolor = SchemeColor.BackgroundTextFaint;
                }
                else if (entry.flow > 0f)
                {
                    bgColor   = SchemeColor.Secondary;
                    textcolor = SchemeColor.SecondaryText;
                }
            }
            using (gui.EnterGroup(new Padding(0.5f), production ? RectAllocator.LeftRow : RectAllocator.RightRow, textcolor))
            {
                using (gui.EnterFixedPositioning(4f, 0f, default))
                {
                    gui.allocator = RectAllocator.Stretch;
                    gui.BuildFactorioObjectButton(entry.recipe, 4f, MilestoneDisplay.Contained);
                    using (gui.EnterRow())
                    {
                        gui.BuildIcon(Icon.Time);
                        gui.BuildText(DataUtils.FormatAmount(entry.recipe.time, UnitOfMeasure.Second), align: RectAlignment.Middle);
                    }
                    var bh = CostAnalysis.Instance.GetBuildingHours(recipe, entry.recipeFlow);
                    if (bh > 20)
                    {
                        gui.BuildText(DataUtils.FormatAmount(bh, UnitOfMeasure.None, suffix: "bh"), align: RectAlignment.Middle);
                        if (gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Grey) == ImGuiUtils.Event.MouseOver)
                        {
                            gui.ShowTooltip(g => g.BuildText("Building-hours.\nAmount of building-hours required for all researches", wrap: true));
                        }
                    }
                }
                gui.AllocateSpacing();
                gui.allocator = production ? RectAllocator.LeftAlign : RectAllocator.RightAlign;
                gui.BuildText(recipe.locName, wrap: true);
                if (recipe.ingredients.Length + recipe.products.Length <= 8)
                {
                    using (gui.EnterRow())
                    {
                        DrawIngredients(gui, entry.recipe);
                        gui.allocator = RectAllocator.RightRow;
                        DrawProducts(gui, entry.recipe);
                        if (recipe.products.Length < 3 && recipe.ingredients.Length < 5)
                        {
                            gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f);
                        }
                        else if (recipe.products.Length < 3)
                        {
                            gui.allocator = RectAllocator.RemainigRow;
                        }
                        gui.BuildIcon(Icon.ArrowRight, 3f);
                    }
                }
                else
                {
                    using (gui.EnterRow())
                        DrawIngredients(gui, entry.recipe);

                    using (gui.EnterRow())
                    {
                        gui.BuildIcon(Icon.ArrowDownRight, 3f);
                        gui.allocator = RectAllocator.RightRow;
                        DrawProducts(gui, entry.recipe);
                    }
                }
            }

            if (isBuilding)
            {
                var rect = gui.lastRect;
                if (entry.flow > 0f)
                {
                    var percentFlow = MathUtils.Clamp(entry.flow / currentFlow, 0f, 1f);
                    rect.Width *= percentFlow;
                    gui.DrawRectangle(rect, SchemeColor.Primary);
                }
                else if (waste <= 0f)
                {
                    bgColor = SchemeColor.Secondary;
                }
                else
                {
                    rect.Width *= (1f - waste);
                    gui.DrawRectangle(rect, SchemeColor.Secondary);
                }
                gui.DrawRectangle(gui.lastRect, bgColor);
            }
        }