Ejemplo n.º 1
0
        public static NetworkMenu ToolbarMenu(ButtonPressCallbackData data, bool error = false, bool?selectAll = null)
        {
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("MoveItemsToCrate", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            try
            {
                if (error)
                {
                    menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("invalidNumber"), UnityEngine.Color.red)));
                }

                List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();
                headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Numberofitems"))), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new InputField("Crate.NumberOfItems"), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.MoveItemsToCrateFromToolbar", new LabelData(_localizationHelper.GetLocalizationKey("MoveItemsToCrate"))), 333));
                menu.Items.Add(new HorizontalRow(headerItems));
                menu.Items.Add(new Line(UnityEngine.Color.black));

                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.MainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"))), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));

                bool selected = false;

                if (selectAll == true)
                {
                    selected = true;
                }
                else if (selectAll == false)
                {
                    selected = false;
                }

                if (selected)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.SelectNoneInCrateToolbar", new LabelData(_localizationHelper.GetLocalizationKey("SelectNone"))), 250));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.SelectAllInCrateToolbar", new LabelData(_localizationHelper.GetLocalizationKey("SelectAll"))), 250));
                }

                menu.Items.Add(new HorizontalRow(items));
                menu.Items.Add(new Line(UnityEngine.Color.black));
                var invRef = data.Player.Inventory;

                foreach (var itemKvp in invRef.Items)
                {
                    if (itemKvp.Type != ColonyBuiltIn.ItemTypes.AIR.Id)
                    {
                        items = new List <ValueTuple <IItem, int> >();
                        items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(itemKvp.Type), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ItemId.GetItemId(itemKvp.Type), UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Toolbar", data.Player) + ": " + itemKvp.Amount.ToString())), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Toggle(new LabelData(_localizationHelper.LocalizeOrDefault("Select", data.Player)), "Crate." + itemKvp.Type + ".ItemSelected"), 250));

                        if (selectAll == null)
                        {
                            menu.LocalStorage.TryGetAs("Crate." + itemKvp.Type + ".ItemSelected", out selected);
                        }

                        menu.LocalStorage.SetAs("Crate." + itemKvp.Type + ".ItemSelected", selected);
                        menu.Items.Add(new HorizontalRow(items));
                    }
                }
            }
            catch (Exception ex)
            {
                CivLogger.LogError(ex);
            }

            return(menu);
        }
Ejemplo n.º 2
0
        public void OnTimedUpdate()
        {
            try
            {
                foreach (var job in PorterJobSettings.PorterJobs)
                {
                    var settings = job.Settings as PorterJobSettings;

                    if (settings.CurrentGoal.TryGetValue(job, out var goal) &&
                        job != null &&
                        job.Owner != null &&
                        StorageFactory.CrateLocations.TryGetValue(job.Owner, out var crateLocations))
                    {
                        if (goal is CrateToStockpikeGoal cts)
                        {
                            cts.ClosestLocations = job.Position.SortClosestPositions(crateLocations.Keys);
                        }
                        else if (goal is StockpikeToCrateGoal stc)
                        {
                            stc.ClosestLocations = job.Position.SortClosestPositions(crateLocations.Keys);
                        }
                    }
                }

                int retry = 0;

                while (retry < 3)
                {
                    ItemsNeeded.Clear();

                    foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values)
                    {
                        if (colony != null && StorageFactory.CrateLocations.TryGetValue(colony, out var dict))
                        {
                            foreach (var crate in dict.Keys)
                            {
                                foreach (var request in StorageFactory.CrateRequests)
                                {
                                    var needed = request.GetItemsNeeded(crate);

                                    foreach (var need in needed)
                                    {
                                        if (!ItemsNeeded.TryGetValue(crate, out var items))
                                        {
                                            items = new Dictionary <ushort, StoredItem>();
                                            ItemsNeeded[crate] = items;
                                        }

                                        if (items.TryGetValue(need.Key, out var storedItem))
                                        {
                                            storedItem.Add(needed.Count);
                                        }
                                        else
                                        {
                                            items[need.Key] = need.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    retry = int.MaxValue;
                }
            }
            catch (Exception ex)
            {
                CivLogger.LogError(ex);
            }
        }