Exemplo n.º 1
0
        /// <inheritdoc cref="Window.PreClose"/>
        public override void PreClose()
        {
            base.PreClose();

            Store_ItemEditor.UpdateStoreItemList();
            Store_IncidentEditor.UpdatePriceSheet();
            Toolkit.Mod.WriteSettings();

            Task.Run(
                async() =>
            {
                switch (TkSettings.DumpStyle)
                {
                case "SingleFile":
                    await Data.SaveLegacyShopAsync(Paths.LegacyShopDumpFilePath);

                    return;

                case "MultiFile":
                    await Data.SaveTraitsAsync(Paths.TraitFilePath);
                    await Data.SavePawnKindsAsync(Paths.PawnKindFilePath);

                    return;
                }

                await Data.SaveItemDataAsync(Paths.ItemDataFilePath);
                await Data.SaveEventDataAsync(Paths.EventDataFilePath);
            }
                )
            .ConfigureAwait(false);
        }
        private void GetTradeables(bool save = true)
        {
            if (save && cachedTradeables.Count > 0)
            {
                Store_ItemEditor.UpdateStoreItems(cachedTradeables, tradeablesPrices);
            }

            lastSearch = searchQuery;

            cachedTradeables = new List <ThingDef>();

            string searchShort = string.Join("", searchQuery.Split(' ')).ToLower();

            Helper.Log("Finding tradeables");

            IEnumerable <ThingDef> tradeableitems = from t in DefDatabase <ThingDef> .AllDefs
                                                    where (t.tradeability.TraderCanSell() || ThingSetMakerUtility.CanGenerate(t)) &&
                                                    (t.building == null || t.Minifiable || ToolkitSettings.MinifiableBuildings) &&
                                                    (t.FirstThingCategory != null || t.race != null) &&
                                                    (t.BaseMarketValue > 0) &&
                                                    (searchQuery == "" ||
                                                     (
                                                         t.defName.ToLower().Contains(searchShort) ||
                                                         string.Join("", t.label.Split(' ')).ToLower().Contains(searchShort) ||
                                                         t.defName.ToLower() == searchShort ||
                                                         string.Join("", t.label.Split(' ')).ToLower() == searchShort ||
                                                         (
                                                             (t.race != null &&
                                                              t.race.Animal &&
                                                              (t.race.ToString().ToLower().Contains(searchQuery) ||
                                                               t.race.ToString().ToLower() == searchQuery ||
                                                               "animal".Contains(searchQuery) ||
                                                               searchQuery == "animal")
                                                             )
                                                             ||
                                                             (t.race == null &&
                                                              (t.FirstThingCategory == null ||
                                                               string.Join("", t.FirstThingCategory.LabelCap.RawText.Split(' ')).ToLower().Contains(searchShort) ||
                                                               t.FirstThingCategory.LabelCap.RawText.ToLower() == searchShort)
                                                             )
                                                         )
                                                     )
                                                    ) &&
                                                    t.defName != "Human"
                                                    orderby t.LabelCap.RawText
                                                    select t;

            foreach (ThingDef item in tradeableitems)
            {
                if (item.BaseMarketValue > 0f)
                {
                    cachedTradeables.Add(item);
                }
            }

            GetTradeablesPrices();
        }
        private void GetTradeables(bool save = true)
        {
            if (save && cachedTradeables.Count > 0)
            {
                Store_ItemEditor.UpdateStoreItems(cachedTradeables, tradeablesPrices);
            }

            lastSearch = searchQuery;

            cachedTradeables = new List <ThingDef>();

            string searchShort = string.Join("", searchQuery.Split(' ')).ToLower();

            IEnumerable <ThingDef> tradeableitems = from t in DefDatabase <ThingDef> .AllDefs
                                                    where (t.tradeability.TraderCanSell() || ThingSetMakerUtility.CanGenerate(t)) &&
                                                    (t.building == null || t.Minifiable || ToolkitSettings.MinifiableBuildings) &&
                                                    (t.FirstThingCategory != null) &&
                                                    (t.BaseMarketValue > 0) &&
                                                    (searchQuery == "" ||
                                                     (
                                                         t.defName.ToLower().Contains(searchShort) ||
                                                         string.Join("", t.label.Split(' ')).ToLower().Contains(searchShort) ||
                                                         t.defName.ToLower() == searchShort ||
                                                         string.Join("", t.label.Split(' ')).ToLower() == searchShort ||
                                                         (
                                                             t.FirstThingCategory == null ||
                                                             string.Join("", t.FirstThingCategory.LabelCap.Split(' ')).ToLower().Contains(searchShort) ||
                                                             t.FirstThingCategory.LabelCap.ToLower() == searchShort
                                                         )
                                                     )
                                                    )
                                                    orderby t.LabelCap
                                                    select t;

            foreach (ThingDef item in tradeableitems)
            {
                // item needs to be worth money, also not an animal
                if (item.BaseMarketValue > 0f && item.race == null)
                {
                    cachedTradeables.Add(item);
                }
            }

            GetTradeablesPrices();
        }
Exemplo n.º 4
0
 public override void PostClose()
 {
     Store_ItemEditor.UpdateStoreItems(cachedTradeables, tradeablesPrices);
 }
Exemplo n.º 5
0
        public override void DoWindowContents(Rect inRect)
        {
            if (searchQuery != lastSearch)
            {
                GetTradeables();
            }


            GUI.BeginGroup(inRect);
            Rect     rect2 = new Rect(inRect.width - 590f, 0f, 590f, 58f);
            GameFont old   = Text.Font;

            Text.Font = GameFont.Medium;
            Widgets.Label(rect2, "Store Items");
            Text.Font = old;

            Rect searchBar = new Rect(0f, 30f, 300f, 26f);

            searchQuery = Widgets.TextEntryLabeled(searchBar, "Search:", searchQuery);

            Rect resetButton = new Rect(inRect.width - 150f, 0f, 100f, 26f);

            if (Widgets.ButtonText(resetButton, "Reset Items"))
            {
                Store_ItemEditor.ResetItemsToDefault();
            }

            Rect sortLabel  = new Rect(inRect.width - 470f, 32f, 100f, 24f);
            Rect sortButton = new Rect(inRect.width - 370f, 28f, 100f, 28f);

            Color defaultColor = GUI.color;

            GUI.color = ColorLibrary.Grey;
            Widgets.Label(sortLabel, "Sort items by:");
            GUI.color = defaultColor;

            if (Widgets.ButtonText(sortButton, "category"))
            {
                if (ascending)
                {
                    ascending        = false;
                    cachedTradeables = cachedTradeables.OrderBy(s => s.FirstThingCategory.LabelCap).ToList();
                }
                else
                {
                    ascending        = true;
                    cachedTradeables = cachedTradeables.OrderByDescending(s => s.FirstThingCategory.LabelCap).ToList();
                }

                GetTradeablesPrices();
            }

            sortButton.x += 110f;

            if (Widgets.ButtonText(sortButton, "price"))
            {
                if (ascending)
                {
                    ascending        = false;
                    cachedTradeables = cachedTradeables.OrderBy(s => s.BaseMarketValue).ToList();
                }
                else
                {
                    ascending        = true;
                    cachedTradeables = cachedTradeables.OrderByDescending(s => s.BaseMarketValue).ToList();
                }

                GetTradeablesPrices();
            }

            sortButton.x += 110f;

            if (Widgets.ButtonText(sortButton, "name"))
            {
                if (ascending)
                {
                    ascending        = false;
                    cachedTradeables = cachedTradeables.OrderBy(s => s.LabelCap).ToList();
                }
                else
                {
                    ascending        = true;
                    cachedTradeables = cachedTradeables.OrderByDescending(s => s.LabelCap).ToList();
                }

                GetTradeablesPrices();
            }

            Rect mainRect = new Rect(0f, 58f, inRect.width, inRect.height - 58f - 38f - 20f);

            this.FillMainRect(mainRect);

            GUI.EndGroup();
        }