예제 #1
0
 private void SelectBeacon(ImGui gui)
 {
     gui.BuildObjectSelectDropDown <EntityBeacon>(Database.allBeacons, DataUtils.DefaultOrdering, sel =>
     {
         if (recipe.modules != null)
         {
             recipe.modules.RecordUndo().beacon = sel;
         }
         contents.Rebuild();
     }, "Select beacon", allowNone: recipe.modules.beacon != null);
 }
예제 #2
0
 private void ChoiceObject <T>(ImGui gui, string text, T[] list, T current, Action <T> select) where T : FactorioObject
 {
     using (gui.EnterRow())
     {
         gui.BuildText(text, topOffset: 0.5f);
         if (gui.BuildFactorioObjectButtonWithText(current))
         {
             gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text);
         }
     }
 }
예제 #3
0
        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.BuildObjectSelectDropDown <EntityBelt>(Database.allBelts, DataUtils.DefaultOrdering, setBelt =>
                        {
                            preferences.RecordUndo(true);
                            preferences.itemUnit = setBelt.beltItemsPerSecond;
                        }, "Select belt", extra: b => DataUtils.FormatAmount(b.beltItemsPerSecond, UnitOfMeasure.PerSecond));
                    }
                }
                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;
                }
            }
        }
예제 #4
0
        private void DrawRecipeModules(ImGui gui, EntityBeacon beacon, ref ModuleEffects effects)
        {
            var remainingModules = recipe.entity?.moduleSlots ?? 0;

            using (var grid = gui.EnterInlineGrid(3f, 1f))
            {
                var list = beacon != null ? recipe.modules.beaconList : recipe.modules.list;
                foreach (var module in list)
                {
                    grid.Next();
                    var evt = gui.BuildFactorioObjectWithEditableAmount(module.module, module.fixedCount, UnitOfMeasure.None, out var newAmount);
                    if (evt == GoodsWithAmountEvent.ButtonClick)
                    {
                        SelectObjectPanel.Select(GetModules(beacon), "Select module", sel =>
                        {
                            if (sel == null)
                            {
                                recipe.modules.RecordUndo().list.Remove(module);
                            }
                            else
                            {
                                module.RecordUndo().module = sel;
                            }
                            gui.Rebuild();
                        }, DataUtils.FavouriteModule, true);
                    }
                    else if (evt == GoodsWithAmountEvent.TextEditing)
                    {
                        var amountInt = MathUtils.Floor(newAmount);
                        if (amountInt < 0)
                        {
                            amountInt = 0;
                        }
                        module.RecordUndo().fixedCount = amountInt;
                    }

                    if (beacon == null)
                    {
                        var count = Math.Min(remainingModules, module.fixedCount > 0 ? module.fixedCount : int.MaxValue);
                        if (count > 0)
                        {
                            effects.AddModules(module.module.module, count);
                            remainingModules -= count;
                        }
                    }
                    else
                    {
                        effects.AddModules(module.module.module, module.fixedCount * beacon.beaconEfficiency);
                    }
                }

                grid.Next();
                if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimalyAlt, size: 2.5f))
                {
                    gui.BuildObjectSelectDropDown(GetModules(beacon), DataUtils.FavouriteModule, sel =>
                    {
                        recipe.modules.RecordUndo();
                        list.Add(new RecipeRowCustomModule(recipe.modules, sel));
                        gui.Rebuild();
                    }, "Select module");
                }
            }
        }