Ejemplo n.º 1
0
        public override void DrawMouseAttachments()
        {
            base.DrawMouseAttachments();
            if (ArchitectCategoryTab.InfoRect.Contains(UI.MousePositionOnUIInverted))
            {
                return;
            }
            DesignationDragger dragger = Find.DesignatorManager.Dragger;
            int     num    = ((!dragger.Dragging) ? 1 : dragger.DragCells.Count());
            float   num2   = 0f;
            Vector2 vector = Event.current.mousePosition + DragPriceDrawOffset;
            List <ThingDefCountClass> list = entDef.CostListAdjusted(stuffDef);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                float y = vector.y + num2;
                Widgets.ThingIcon(new Rect(vector.x, y, 27f, 27f), thingDefCountClass.thingDef);
                Rect   rect = new Rect(vector.x + 29f, y, 999f, 29f);
                int    num3 = num * thingDefCountClass.count;
                string text = num3.ToString();
                if (base.Map.resourceCounter.GetCount(thingDefCountClass.thingDef) < num3)
                {
                    GUI.color = Color.red;
                    text     += " (" + "NotEnoughStoredLower".Translate() + ")";
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect, text);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
                num2       += 29f;
            }
        }
Ejemplo n.º 2
0
        public static List <ThingDefCountClass> CostListAdjusted(this BuildableDef entDef, ThingDef stuff, bool errorOnNullStuff = true)
        {
            CostListPair key = new CostListPair(entDef, stuff);

            if (!cachedCosts.TryGetValue(key, out List <ThingDefCountClass> value))
            {
                value = new List <ThingDefCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error("Cannot get AdjustedCostList for " + entDef + " with null Stuff.");
                        ThingDef thingDef = GenStuff.DefaultStuffFor(entDef);
                        return((thingDef == null) ? null : entDef.CostListAdjusted(GenStuff.DefaultStuffFor(entDef)));
                    }
                    if (stuff != null)
                    {
                        num = Mathf.RoundToInt((float)entDef.costStuffCount / stuff.VolumePerUnit);
                        if (num < 1)
                        {
                            num = 1;
                        }
                    }
                    else
                    {
                        num = entDef.costStuffCount;
                    }
                }
                else if (stuff != null)
                {
                    Log.Error("Got AdjustedCostList for " + entDef + " with stuff " + stuff + " but is not MadeFromStuff.");
                }
                bool flag = false;
                if (entDef.costList != null)
                {
                    for (int i = 0; i < entDef.costList.Count; i++)
                    {
                        ThingDefCountClass thingDefCountClass = entDef.costList[i];
                        if (thingDefCountClass.thingDef == stuff)
                        {
                            value.Add(new ThingDefCountClass(thingDefCountClass.thingDef, thingDefCountClass.count + num));
                            flag = true;
                        }
                        else
                        {
                            value.Add(thingDefCountClass);
                        }
                    }
                }
                if (!flag && num > 0)
                {
                    value.Add(new ThingDefCountClass(stuff, num));
                }
                cachedCosts.Add(key, value);
            }
            return(value);
        }