Пример #1
0
        public static float getCuMWorth(this Backstory bs, bool includeSkillGainWorth = true)
        {
            if (bs == null)
            {
                return(0);
            }
            float total = 0, BC = QOLMod.getBaseCost();

            if (includeSkillGainWorth)
            {
                foreach (KeyValuePair <SkillDef, int> p in bs.skillGainsResolved)
                {
                    total += BC * (float)p.Value;
                }
            }
            WorkTags           disabledWorkTags = bs.workDisables;
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;

            foreach (WorkTypeDef wtd in allDefsListForReading)
            {
                if ((wtd.workTags & disabledWorkTags) != WorkTags.None)
                {
                    total += -2 * BC;
                }
            }
            return(total);
        }
Пример #2
0
        static public void registerAll()
        {
            Assembly.GetExecutingAssembly().GetTypes().Do(delegate(Type type) {
                List <HarmonyMethod> harmonyMethods = type.GetHarmonyMethods();
                if (harmonyMethods != null && harmonyMethods.Count <HarmonyMethod>() > 0)
                {
                    HarmonyPatchNamespace nsAttr;
                    if (type.TryGetAttribute(out nsAttr))
                    {
                        nsAttr.register();
                    }
                }
            });
            QOLModSettings settings = QOLMod.getSettings();

            if (settings.forbiddenPatchNamespaces.NullOrEmpty())
            {
                settings.forbiddenPatchNamespaces = new List <string>();
            }
            foreach (KeyValuePair <string, HarmonyPatchNamespaceProperties> p in namespaces)
            {
                if (settings.forbiddenPatchNamespaces.Contains(p.Key))
                {
                    p.Value.active = false;
                }
            }
        }
Пример #3
0
 public static float getCuMWorth(this SkillRecord sr)
 {
     if (sr == null || sr.TotallyDisabled)
     {
         return(0);
     }
     return(sr.Level * QOLMod.getBaseCost() + sr.passion.getCuMWorth());
 }
Пример #4
0
 public static float getCuMWorth(this Trait t, bool removal = false)
 {
     if (t == null)
     {
         return(0);
     }
     return(QOLMod.getTraitCost(t, removal) * QOLMod.getBaseCost());
 }
Пример #5
0
        static HarmonyBootstrap()
        {
            var harmony = HarmonyInstance.Create("RIMMSqol");

            //harmony.PatchAll(Assembly.GetExecutingAssembly());
            QOLMod.ApplySettings();

            HarmonyPatchNamespace.registerAll();
            Dictionary <string, HarmonyPatchNamespaceProperties> namespaces = HarmonyPatchNamespace.namespaces;

            StringBuilder sb = new StringBuilder();

            try {
                Assembly.GetExecutingAssembly().GetTypes().Do(delegate(Type type) {
                    List <HarmonyMethod> harmonyMethods = type.GetHarmonyMethods();
                    if (harmonyMethods != null && harmonyMethods.Count <HarmonyMethod>() > 0)
                    {
                        bool allowPatch;
                        HarmonyPatchNamespace nsAttr;
                        if (type.TryGetAttribute(out nsAttr))
                        {
                            HarmonyPatchNamespaceProperties props;
                            if (namespaces.TryGetValue(nsAttr.id, out props))
                            {
                                allowPatch = props.active;
                            }
                            else
                            {
                                Log.Error("Found no configuration for existing patch namespace \"" + nsAttr.id + "\". Ensure the namespaces are initialized!");
                                allowPatch = false;
                            }
                        }
                        else
                        {
                            allowPatch = true;
                            nsAttr     = null;
                        }
                        if (allowPatch)
                        {
                            sb.AppendLine("Allow patch: " + type.Namespace + ":" + type.Name + (nsAttr != null ? "[" + nsAttr.id + "]" : ""));
                            HarmonyMethod attributes = HarmonyMethod.Merge(harmonyMethods);
                            new PatchProcessor(harmony, type, attributes).Patch();
                        }
                        else
                        {
                            sb.AppendLine("Deny patch: " + type.Namespace + ":" + type.Name + (nsAttr != null ? "[" + nsAttr.id + "]" : ""));
                        }
                    }
                });
            } finally {
                Log.Message(sb.ToString());
            }
        }
Пример #6
0
        public static float getCuMWorth(this Passion p)
        {
            switch (p)
            {
            case Passion.None: return(0);

            case Passion.Minor: return(QOLMod.getBaseCost() * 2);

            case Passion.Major: return(QOLMod.getBaseCost() * 3);
            }
            Log.Error("Unknown Passion type while calculation upgrade cost!");
            return(0);
        }
Пример #7
0
 public int cost()
 {
     if (cachedCost < 0)
     {
         cachedCost = 0;
         List <Thing> l = createProducts();
         foreach (Thing t in l)
         {
             cachedCost += t.MarketValue * colony.TraderKind.PriceTypeFor(t.def, TradeAction.PlayerBuys).PriceMultiplier();
         }
     }
     return(Mathf.FloorToInt(cachedCost * QOLMod.getRemnantOrderPriceFactor()));
 }
Пример #8
0
        public QOLMod(ModContentPack content) : base(content)
        {
            settings = GetSettings <QOLModSettings>();
            flow     = null;
            //minimalistic pawn that is used to generate tooltips
            dummyPawn        = new Pawn();
            dummyPawn.gender = Gender.Male;
            dummyPawn.Name   = new NameSingle("Malte");

            singleton = this;
            System.Reflection.FieldInfo fi = typeof(Text).GetField("lineHeights", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            lineHeights       = (float[])fi.GetValue(null);
            tmpTextGUIContent = new GUIContent();
        }
Пример #9
0
        public static float getCuMWorth(this Pawn_RecordsTracker tracker)
        {
            if (tracker == null)
            {
                return(0);
            }
            float points = 0;

            foreach (RecordDef d in DefDatabase <RecordDef> .AllDefsListForReading)
            {
                points += tracker.GetValue(d) * QOLMod.getCuMRecordFactor(d);
            }
            return(points);
        }
Пример #10
0
        public static float getCuMWorth(this Pawn p)
        {
            if (p == null)
            {
                return(0);
            }
            float points = 0, BC = QOLMod.getBaseCost();;

            points += getCuMWorth(p.records);
            foreach (Trait t in p.story.traits.allTraits)
            {
                points += t.getCuMWorth();
            }
            foreach (Backstory bs in p.story.AllBackstories)
            {
                points += bs.getCuMWorth(false);
            }
            foreach (SkillRecord sr in p.skills.skills)
            {
                points += sr.getCuMWorth();
            }
            return(points);
        }
Пример #11
0
 static bool Prepare()
 {
     QOLMod.addApplySettingsListener(mod => stopTamenessDecay = QOLMod.stopTamenessDecay());
     stopTamenessDecay = QOLMod.stopTamenessDecay();
     return(true);
 }
Пример #12
0
        protected override void DoListingItems()
        {
            foreach (T d in items)
            {
                try {
                    string label = labelResolver(d);
                    if (FilterAllows(label, d))
                    {
                        Rect   r = this.listing.GetRect(0);
                        bool   wasCapped;
                        string labelToRender = label;
                        string labelCapped;
                        if (iconResolver != null)
                        {
                            labelCapped = QOLMod.CapString(labelToRender, r.width - 32f, "...", out wasCapped, Text.Font);
                            if (this.listing.ButtonImageText(labelCapped, iconResolver(d), 32f, 32f))
                            {
                                if (onSelect(d))
                                {
                                    Find.WindowStack.TryRemove(this, true);
                                }
                            }
                        }
                        else
                        {
                            labelCapped = QOLMod.CapString(labelToRender, r.width, "...", out wasCapped, Text.Font);
                            if (this.listing.ButtonText(labelCapped, null))
                            {
                                if (onSelect(d))
                                {
                                    Find.WindowStack.TryRemove(this, true);
                                }
                            }
                        }
                        Rect rShifted = this.listing.GetRect(0);
                        if (Math.Abs(rShifted.x - r.x) > 0.0001f)
                        {
                            //new column so we need to shift the rect from bottom to next columns top position.
                            r.x      = rShifted.x;
                            r.y      = 0;
                            r.height = rShifted.y;
                        }
                        else
                        {
                            r.height = rShifted.y - r.y;
                        }

                        if ((tooltipProducer != null || wasCapped) && Mouse.IsOver(r))
                        {
                            if (tooltipProducer == null)
                            {
                                TooltipHandler.TipRegion(r, () => labelToRender, 1);
                            }
                            else
                            {
                                string tooltip = tooltipProducer(d);
                                if (wasCapped)
                                {
                                    if (!tooltip.NullOrEmpty())
                                    {
                                        TooltipHandler.TipRegion(r, () => labelToRender + " | " + tooltip, 1);
                                    }
                                    else
                                    {
                                        TooltipHandler.TipRegion(r, () => labelToRender, 1);
                                    }
                                }
                                else if (!tooltip.NullOrEmpty())
                                {
                                    TooltipHandler.TipRegion(r, () => tooltip, 1);
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                    Log.Message("Exception while rendering item: " + d + " " + ex);
                }
            }
        }
Пример #13
0
        public override void DoWindowContents(UnityEngine.Rect inRect)
        {
            Rect outRect = filterModel.DoFilterWindowContent(inRect);

            items = filterModel.Sort(items);
            Rect rect = new Rect(0f, 0f, totalOptionsWidth > 0 ? totalOptionsWidth : outRect.width - 16f, outRect.height - QOLMod.HorizontalScrollbarHeight());

            Widgets.BeginScrollView(outRect, ref this.scrollPosition, rect, true);
            this.listing             = new Listing_Standard();
            this.listing.ColumnWidth = (outRect.width - 16f - 51f) / ((float)numOfColumns);
            this.listing.Begin(rect);
            this.DoListingItems();
            //we determine the correct width after rendering, basically dragging one frame behind in favor of rendering a layout frame.
            Rect rectFinal = this.listing.GetRect(0);

            this.listing.End();
            totalOptionsWidth = rectFinal.x + rectFinal.width + Listing.ColumnSpacing;
            Widgets.EndScrollView();
        }
Пример #14
0
        public void TryOpenComms(Pawn negotiator)
        {
            if (!this.CanTradeNow)
            {
                return;
            }
            ModelPlaceOrder modelPlaceOrder = new ModelPlaceOrder(this);

            //maybe a grid or a dialog featuring my own flow components.
            Dictionary <string, PageRenderer> pages = new Dictionary <string, PageRenderer>();

            pages.Add("menu", new PageRenderer((f => GetCallLabel()), null, null)
                      .AddChild(new RowLayoutRenderer()
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ButtonTextRenderer("Trade", (f => Find.WindowStack.Add(new Dialog_Trade(negotiator, this)))))
                                          //Placing an order requires selecting stuff for the item to make(could be a stuff category or fixed ingredients) more complicated things have filters
                                          //Maybe using the workbench interface to define the possible materials? But then we need to pick from storage etc.. simulating the whole chain.
                                          //Only allow recipes with category item.
                                          .AddChild(new ButtonTextRenderer("Place order", (f => { modelPlaceOrder.resources = ColonyThingsWillingToBuy(negotiator); f.navigate("placeOrder"); })))
                                          //.AddChild(new ButtonTextRenderer("Claim order", (f => f.navigate("statistics"))))
                                          .AddChild(new ButtonTextRenderer("Statistics", (f => f.navigate("statistics"))))
                                          .AddChild(new ButtonTextRenderer("Rename colony", (f => f.navigate("renameColony"))))
                                          .AddChild(new ButtonTextRenderer("Remove colony", (f => Find.WindowStack.Add(new Dialog_MessageBox("This is irreversible! Are you sure?", "Remove", delegate {
                Find.WorldObjects.Remove(this);
                //TODO When removing a colony we have the option to remove the housed pawns for good(including their relations) or we keep them around.
            }, "Cancel", null, "Remove Remnant Colony", true)))))
                                          )));

            pages.Add("statistics", new PageRenderer((f => "Statistics"), null, () => "menu")
                      .AddChild(new RowLayoutRenderer()
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Inhabitants")))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ListRenderer(pawnNames, 200f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 5)
                                                    .AddChild(new LabelRenderer((f => ((string)((IterationItem)f.pageScope["curItem"]).curItem)), 200f))))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Max skill levels")))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ListRenderer(maxSkillLevels, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 5)
                                                    .AddChild(new LabelRenderer((f => ((SkillLevel)((IterationItem)f.pageScope["curItem"]).curItem).def.label), 200f))
                                                    .AddChild(new LabelRenderer((f => ((SkillLevel)((IterationItem)f.pageScope["curItem"]).curItem).level.ToString()), 200f))))));

            pages.Add("renameColony", new PageRenderer((f => "Rename colony"), null, () => "menu")
                      .AddChild(new RowLayoutRenderer()
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Name", 200f))
                                          .AddChild(new EditTextRenderer((f => settlementName), (f, v) => settlementName = v, 200f)))
                                ));

            pages.Add("placeOrder", new PageRenderer((f => "Place order"), null, () => "menu")
                      .AddChild(new RowLayoutRenderer()
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Recipe", 200f))
                                          .AddChild(new ButtonTextRenderer(f => modelPlaceOrder.recipe == null ? "Choose" : modelPlaceOrder.recipe.label,
                                                                           f => Find.WindowStack.Add(
                                                                               new Dialog_Select <RecipeDef>(def => { modelPlaceOrder.recipe = def; return(true); },
                                                                                                             DefDatabase <RecipeDef> .AllDefsListForReading
                                                                                                             //only recipes that produce something and only recipes that can be crafted with the tradeable resources(e.g. chunks arent launchable and cannot be used)
                                                                                                             .Where(d => !d.products.NullOrEmpty() /*&&modelPlaceOrder.HasIngredients(d)*/)
                                                                                                             .OrderBy(d => d.label),
                                                                                                             d => d.label)
                                                                               ), GameFont.Small, 200f)))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Ingredient", 200f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))
                                          .AddChild(new LabelRenderer("Amount", 100f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))
                                          .AddChild(new LabelRenderer("In Stock", 100f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter)))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ListRenderer(modelPlaceOrder.ingredients, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 5)
                                                    .AddChild(new ButtonTextRenderer(f => ((Pair <ThingDef, IngredientCount>)((IterationItem)f.pageScope["curItem"]).curItem).Key.label,
                                                                                     (f => { f.pageScope["selectItem"] = ((IterationItem)f.pageScope["curItem"]).curItem; Find.WindowStack.Add(new Dialog_SelectDef <ThingDef>(def => {
                    ((Pair <ThingDef, IngredientCount>)f.pageScope["selectItem"]).Key = def; modelPlaceOrder.updateStuff(); return(true);
                }, ((Pair <ThingDef, IngredientCount>)f.pageScope["selectItem"]).Value.filter.AllowedThingDefs)); }), GameFont.Small, 200f))
                                                    .AddChild(new LabelRenderer((f => {
                Pair <ThingDef, IngredientCount> p = ((Pair <ThingDef, IngredientCount>)((IterationItem)f.pageScope["curItem"]).curItem);
                return(p.Value.CountRequiredOfFor(p.Key, modelPlaceOrder.recipe).ToString());
            }), 100f, GameFont.Small, UnityEngine.TextAnchor.MiddleRight))
                                                    .AddChild(new LabelRenderer((f => modelPlaceOrder.stockCount(((Pair <ThingDef, IngredientCount>)((IterationItem)f.pageScope["curItem"]).curItem).Key).ToString()), 100f, GameFont.Small, UnityEngine.TextAnchor.MiddleRight))))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Quality", 100f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))
                                          .AddChild(new LabelRenderer("Material", 150f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))
                                          .AddChild(new LabelRenderer("Product", 150f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter)))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ListRenderer(modelPlaceOrder.products, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 5)
                                                    .AddChild(new HideRenderer(f => !((ProductConfig)((IterationItem)f.pageScope["curItem"]).curItem).HasQuality(),
                                                                               new ButtonTextRenderer(f => ((ProductConfig)((IterationItem)f.pageScope["curItem"]).curItem).quality.GetLabel(),
                                                                                                      (f => { f.pageScope["selectItem"] = ((IterationItem)f.pageScope["curItem"]).curItem; Find.WindowStack.Add(new Dialog_Select <QualityCategory>(q => {
                    ((ProductConfig)f.pageScope["selectItem"]).quality = q; modelPlaceOrder.updateStuff(); return(true);
                }, modelPlaceOrder.allowedQualityCategories, d => Enum.GetName(typeof(QualityCategory), d))); }), GameFont.Small, 100f)))

                                                    .AddChild(new LabelRenderer(f => { ThingDef stuff = ((ProductConfig)((IterationItem)f.pageScope["curItem"]).curItem).stuff; return(stuff != null ? stuff.label : ""); }, 150f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))

                                                    .AddChild(new LabelRenderer((f => {
                ProductConfig p = ((ProductConfig)((IterationItem)f.pageScope["curItem"]).curItem);
                return(p.countClass.thingDef.label + (p.countClass.count > 1 ? "(" + p.countClass.count.ToString() + ")" : ""));
            }), 150f, GameFont.Small, UnityEngine.TextAnchor.MiddleCenter))))
                                //Display the currency count from the stock
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new LabelRenderer("Cost", 200f))
                                          .AddChild(new LabelRenderer(f => ((ModelPlaceOrder)f.flowScope["model"]).cost().ToString() + " (" + modelPlaceOrder.stockCount(ThingDefOf.Silver) + ")", 200f)))
                                .AddChild(new ColumnLayoutRenderer()
                                          .AddChild(new ButtonTextRenderer("Buy", f => modelPlaceOrder.buy(negotiator), GameFont.Small, 400f)))
                                ));
            //A Button to place the order


            Flow flow = new Flow(pages, "menu"); Enum.GetValues(typeof(QualityCategory));

            flow.flowScope["model"] = modelPlaceOrder;

            Find.WindowStack.Add(new Dialog_Flow(flow));
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.BuildOrbitalTradeBeacon, OpportunityType.Critical);
            TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.TradeGoodsMustBeNearBeacon);
        }
Пример #15
0
 public static bool Prepare()
 {
     QOLMod.addApplySettingsListener(mod => useFixedNumericTextfields = QOLMod.useFixedNumericTextfields());
     useFixedNumericTextfields = QOLMod.useFixedNumericTextfields();
     return(true);
 }
Пример #16
0
        protected PageRenderer editPage(SettingsProperties props, string backPage, Dictionary <string, PageRenderer> pages, Action <Flow> onBackHandler = null)
        {
            RowLayoutRenderer rows = new RowLayoutRenderer();
            List <ISettingsFieldProperties> fis = props.fields;

            foreach (ISettingsFieldProperties p in fis)
            {
                if (!p.isList && p.isSelectable)
                {
                    ISettingsFieldPropertiesSelectSingle pSelect = (ISettingsFieldPropertiesSelectSingle)p;
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(pSelect.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new ButtonTextRenderer(f => pSelect.labelProducer(((ISettingsInstance)f.flowScope["edit"]).get <object>(p.id)),
                                                                   f => Find.WindowStack.Add(new Dialog_Select <object>(pSelect.onSelectItem(f), pSelect.selectableItems(f), pSelect.labelProducer)),
                                                                   GameFont.Small, 200f)));
                }
                else if (p.type == typeof(bool))
                {
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new CheckboxRenderer(f => ((ISettingsInstance)f.flowScope["edit"]).get <bool>(p.id), (f, v) => ((ISettingsInstance)f.flowScope["edit"]).set(p.id, v))));
                }
                else if (p.type == typeof(int))
                {
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new EditNumericRenderer <int>(f => ((ISettingsInstance)f.flowScope["edit"]).get <int>(p.id), (f, v) => ((ISettingsInstance)f.flowScope["edit"]).set(p.id, v),
                                                                          200f, ((ISettingsFieldPropertiesPrimitiveInt)p).minValue, ((ISettingsFieldPropertiesPrimitiveInt)p).maxValue)));
                }
                else if (p.type == typeof(float))
                {
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new EditNumericRenderer <float>(f => ((ISettingsInstance)f.flowScope["edit"]).get <float>(p.id), (f, v) => ((ISettingsInstance)f.flowScope["edit"]).set(p.id, v),
                                                                            200f, ((ISettingsFieldPropertiesPrimitiveFloat)p).minValue, ((ISettingsFieldPropertiesPrimitiveFloat)p).maxValue)));
                }
                else if (p.type == typeof(string))
                {
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new EditTextRenderer(f => ((ISettingsInstance)f.flowScope["edit"]).get <string>(p.id), (f, v) => ((ISettingsInstance)f.flowScope["edit"]).set(p.id, v),
                                                                 200f, ((ISettingsFieldPropertiesPrimitiveString)p).maxNumOfChars, ((ISettingsFieldPropertiesPrimitiveString)p).inputValidator)));
                }
                else if (p.type == typeof(Color))
                {
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 200f).attachTooltip(p.labelTooltip))
                                  .AddChild(new EditColorRenderer(f => ((ISettingsInstance)f.flowScope["edit"]).get <Color>(p.id),
                                                                  (f, c) => ((ISettingsInstance)f.flowScope["edit"]).set <Color>(p.id, c),
                                                                  200f)));
                }
                else if (p.isList && ((ISettingsFieldPropertiesList)p).isListSettings)
                {
                    SettingsFieldPropertiesListSettings pList = (SettingsFieldPropertiesListSettings)p;
                    SettingsProperties props2         = SettingsStorage.getSettingsProperties(pList.idEnclosedSettings);
                    string             deepEditPageId = backPage + "edit" + pList.id + props2.id;
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 400f, GameFont.Small, TextAnchor.MiddleCenter).attachTooltip(p.labelTooltip)));
                    rows.AddChild(new ListRenderer(f => {
                        List <SettingsInstance> lst = ((ISettingsInstance)f.flowScope["edit"]).get <List <SettingsInstance> >(pList.id);
                        //avoiding nullpointer if the default value for a list is null or if a save state didnt contain the list
                        if (lst == null)
                        {
                            lst = new List <SettingsInstance>();
                            ((ISettingsInstance)f.flowScope["edit"]).set <List <SettingsInstance> >(pList.id, lst);
                        }
                        return(lst);
                    }, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 3)

                                  .AddChild(new ButtonTextRenderer(f => ((ISettingsInstance)((IterationItem)f.pageScope["curItem"]).curItem).getLabel(),
                                                                   f => {
                        f.flowScope["edit"] = ((IterationItem)f.pageScope["curItem"]).curItem;
                        f.navigate(deepEditPageId);
                    }, GameFont.Small, pList.isRemovalAllowed ? 380f : 400f))
                                  .AddChild(pList.isRemovalAllowed ? new ButtonTextRenderer("-", f => {
                        ISettingsInstance setting = (ISettingsInstance)f.flowScope["edit"];
                        SettingsInstance lstItem  = (SettingsInstance)((IterationItem)f.pageScope["curItem"]).curItem;
                        f.addPostRenderCallback(fl => {
                            if (setting.get <List <SettingsInstance> >(p.id).Remove(lstItem))
                            {
                                setting.markAsChanged();
                            }
                        });
                    }, GameFont.Small, 20f) : null));
                    rows.AddChild(pList.isAddingAllowed ? new ColumnLayoutRenderer()
                                  .AddChild(new ButtonTextRenderer("+",
                                                                   f => {
                        SettingsInstance newItem = (SettingsInstance)pList.createNewEntry();
                        if (newItem != null)
                        {
                            ((ISettingsInstance)f.flowScope["edit"]).get <List <SettingsInstance> >(p.id).Add(newItem);
                            newItem.attach(((ISettingsInstance)f.flowScope["edit"]));
                            ((ISettingsInstance)f.flowScope["edit"]).markAsChanged();
                        }
                    },
                                                                   GameFont.Small, 400f)) : null);
                    pages.Add(deepEditPageId, editPage(props2, "edit" + props.id, pages, f => { f.flowScope["edit"] = ((ISettingsInstance)f.flowScope["edit"]).getParentObject(); }));
                }
                else if (p.isList && ((ISettingsFieldPropertiesList)p).isListPrimitive)
                {
                    SettingsFieldPropertiesListPrimitive pList = (SettingsFieldPropertiesListPrimitive)p;
                    Type listItemType = pList.type.GetGenericArguments()[0];
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 400f, GameFont.Small, TextAnchor.MiddleCenter).attachTooltip(p.labelTooltip)));
                    ListRenderer lstRenderer = new ListRenderer(f => {
                        IList lst = ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id);
                        //avoiding nullpointer if the default value for a list is null or if a save state didnt contain the list
                        if (lst == null)
                        {
                            lst = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(listItemType), null);
                            ((ISettingsInstance)f.flowScope["edit"]).set <IList>(pList.id, lst);
                        }
                        return(lst);
                    }, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 3);

                    float editRendererWidth;
                    if (pList.listLabelProducer != null)
                    {
                        lstRenderer.AddChild(new LabelRenderer(f => pList.listLabelProducer((ISettingsInstance)f.flowScope["edit"], f), 200f));
                        editRendererWidth = 200f;
                    }
                    else
                    {
                        editRendererWidth = 400f;
                    }
                    //Currently no min max etc for the list item type
                    if (listItemType == typeof(float))
                    {
                        lstRenderer.AddChild(new EditNumericRenderer <float>(f => (float)((IterationItem)f.pageScope["curItem"]).curItem,
                                                                             (f, v) => { ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id)[((IterationItem)f.pageScope["curItem"]).index] = v; ((ISettingsInstance)f.flowScope["edit"]).markAsChanged(); },
                                                                             editRendererWidth /*,((ISettingsFieldPropertiesPrimitiveFloat)p).minValue,((ISettingsFieldPropertiesPrimitiveFloat)p).maxValue*/));
                    }
                    else if (listItemType == typeof(int))
                    {
                        lstRenderer.AddChild(new EditNumericRenderer <int>(f => (int)((IterationItem)f.pageScope["curItem"]).curItem,
                                                                           (f, v) => { ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id)[((IterationItem)f.pageScope["curItem"]).index] = v; ((ISettingsInstance)f.flowScope["edit"]).markAsChanged(); },
                                                                           editRendererWidth /*,((ISettingsFieldPropertiesPrimitiveInt)p).minValue,((ISettingsFieldPropertiesPrimitiveInt)p).maxValue*/));
                    }
                    else if (listItemType == typeof(bool))
                    {
                        lstRenderer.AddChild(new CheckboxRenderer(f => (bool)((IterationItem)f.pageScope["curItem"]).curItem,
                                                                  (f, v) => { ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id)[((IterationItem)f.pageScope["curItem"]).index] = v; ((ISettingsInstance)f.flowScope["edit"]).markAsChanged(); }));
                    }
                    else if (listItemType == typeof(string))
                    {
                        lstRenderer.AddChild(new EditTextRenderer(f => (string)((IterationItem)f.pageScope["curItem"]).curItem,
                                                                  (f, v) => { ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id)[((IterationItem)f.pageScope["curItem"]).index] = v; ((ISettingsInstance)f.flowScope["edit"]).markAsChanged(); },
                                                                  editRendererWidth /*,((ISettingsFieldPropertiesPrimitiveString)p).maxNumOfChars,((ISettingsFieldPropertiesPrimitiveString)p).inputValidator*/));
                    }
                    rows.AddChild(lstRenderer);
                }
                else if (p.isList && ((ISettingsFieldPropertiesList)p).isSelectable)
                {
                    SettingsFieldPropertiesListSelectable pList = (SettingsFieldPropertiesListSelectable)p;
                    Type listItemType = pList.type.GetGenericArguments()[0];
                    rows.AddChild(new ColumnLayoutRenderer()
                                  .AddChild(new LabelRenderer(p.label, 400f, GameFont.Small, TextAnchor.MiddleCenter).attachTooltip(p.labelTooltip)));
                    ListRenderer lstRenderer = new ListRenderer(f => {
                        IList lst = ((ISettingsInstance)f.flowScope["edit"]).get <IList>(pList.id);
                        //avoiding nullpointer if the default value for a list is null or if a save state didnt contain the list
                        if (lst == null)
                        {
                            lst = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(listItemType), null);
                            ((ISettingsInstance)f.flowScope["edit"]).set <IList>(pList.id, lst);
                        }
                        return(lst);
                    }, 400f + QOLMod.VerticalScrollbarWidth(), QOLMod.LineHeight(GameFont.Small) * 3);

                    lstRenderer.AddChild(new ButtonTextRenderer(f => pList.labelProducer(((IterationItem)f.pageScope["curItem"]).curItem),
                                                                f => Find.WindowStack.Add(new Dialog_Select <object>(pList.onSelectItem(f), pList.selectableItems(f), pList.labelProducer, null, pList.tooltipProducer)),
                                                                GameFont.Small, pList.isRemovalAllowed ? 380f : 400f));
                    if (pList.tooltipProducer != null)
                    {
                        lstRenderer.childs[0].attachTooltip(f => pList.tooltipProducer(((IterationItem)f.pageScope["curItem"]).curItem));
                    }
                    lstRenderer.AddChild(pList.isRemovalAllowed ? new ButtonTextRenderer("-", f => {
                        ISettingsInstance setting = (ISettingsInstance)f.flowScope["edit"];
                        object lstItem            = ((IterationItem)f.pageScope["curItem"]).curItem;
                        f.addPostRenderCallback(fl => {
                            IList lst = setting.get <IList>(p.id);
                            if (lst.Contains(lstItem))
                            {
                                lst.Remove(lstItem);
                                setting.markAsChanged();
                            }
                        });
                    },
                                                                                         GameFont.Small, 20f):null);

                    rows.AddChild(lstRenderer);

                    rows.AddChild(pList.isAddingAllowed ? new ColumnLayoutRenderer()
                                  .AddChild(new ButtonTextRenderer("+",
                                                                   f => {
                        object newItem = pList.createNewEntry();
                        if (newItem != null)
                        {
                            ISettingsInstance currentSettings = ((ISettingsInstance)f.flowScope["edit"]);
                            IList lst = currentSettings.get <IList>(p.id);
                            f.addPostRenderCallback(fl => {
                                lst.Add(newItem);
                                if (pList.isSettings)
                                {
                                    ((ISettingsInstance)newItem).attach(currentSettings);
                                }
                                currentSettings.markAsChanged();
                            });
                        }
                    },
                                                                   GameFont.Small, 400f)) : null);
                }
            }

            return(new PageRenderer(((ISettingsVisualizationEdit)props.visualization).getEditPageTitle, null, () => backPage, onBackHandler).AddChild(new VerticalScrollViewRenderer().AddChild(rows)));
        }
Пример #17
0
 static bool Prefix(TaleDef def, params object[] args)
 {
     //Prevent the recording of birth if both parents are animals to prevent unnecessary tales that keep global pawns from being garbage collected if they are used as art.
     return(!QOLMod.preventAnimalFamilies() || def != TaleDefOf.GaveBirth || args == null || args.Length < 1 || !IsAnimal(args[0] as Pawn) || args.Length < 2 || !IsAnimal(args[1] as Pawn));
 }
Пример #18
0
 static bool Prefix(PawnRelationDef def, Pawn otherPawn)
 {
     //Prevent the association of an animal parent to prevent the sprawling animal family trees.
     return(!QOLMod.preventAnimalFamilies() || def != PawnRelationDefOf.Parent || otherPawn.RaceProps == null || !otherPawn.RaceProps.Animal);
 }
Пример #19
0
        protected void settlementChanged(Settlement settlement)
        {
            if (settlement == null)
            {
                return;
            }

            //grab items for trade stock from settlement
            stock = new ThingOwner <Thing>(this);
            foreach (StockGenerator generator in TraderKind.stockGenerators)
            {
                IEnumerable <Thing> things = generator.GenerateThings(settlement.Tile);
                foreach (Thing t in things)
                {
                    GiveSoldThingToTrader(t, t.stackCount, null);
                }
            }
            //grab name from settlement
            if (settlement != null)
            {
                this.settlementName = settlement.TraderName;
            }
            else
            {
                this.settlementName = "unknown";
            }
            //A non null list of pawns from the settlement that we evaluate as workforce
            List <Pawn> pawnsToInspect = new List <Pawn>();

            pawnsToInspect.AddRange(settlement.Map.mapPawns.FreeColonistsSpawned);

            //grab the highest skill levels from the pawns in the settlement for each skill.
            maxSkillLevels = new List <SkillLevel>();
            foreach (SkillDef skillDef in DefDatabase <SkillDef> .AllDefsListForReading)
            {
                SkillLevel skr = buildDefaultMaxSkillLevel(skillDef);
                maxSkillLevels.Add(skr);
                foreach (Pawn p in pawnsToInspect)
                {
                    skr.level = Math.Max(skr.level, p.skills.GetSkill(skillDef).Level);
                }
            }

            //Names from the workers
            this.pawnNames = (from Pawn p in pawnsToInspect select p.Name.ToStringFull).ToList();

            //collect the CuM points for the pawns and add them to the pool
            float BC     = QOLMod.getBaseCost();
            float points = 0;

            foreach (Pawn p in pawnsToInspect)
            {
                points += p.getCuMWorth();
            }
            Current.Game.GetComponent <QOLModGameComponent>().pooledPoints += points * QOLMod.getCumPointRemnantsToPoolConversionFactor();

            foreach (Action <Settlement> a in onSettlementChanged)
            {
                a(settlement);
            }
        }