Beispiel #1
0
        public static void Prefix(Thing __instance, out Building_MassStorageUnit __state)
        {
            __state = null;
            IntVec3 pos = __instance.Position;

            if (__instance.def.category == ThingCategory.Item && pos.IsValid && __instance.Map != null)
            {
                __state = pos.GetFirst <Building_MassStorageUnit>(__instance.Map);
            }
        }
Beispiel #2
0
        protected override void FillTab()
        {
            Text.Font = GameFont.Small;
            var curY  = 0f;
            var frame = new Rect(10f, 10f, size.x - 10f, size.y - 10f);

            GUI.BeginGroup(frame);
            Widgets.ListSeparator(ref curY, frame.width, labelKey.Translate());
            curY += 5f;

            // Sniper: t.Label also contains the count (Rice x20) do we want that?
            // Rider: This new search method is REALLLYYYYYY FAST
            // This is meant to stop a possible spam call of the Fuzzy Search
            if (itemsToShow == null || searchQuery != oldSearchQuery || SelectedMassStorageUnit.StoredItemsCount != itemsToShow.Count || oldSelectedMassStorageUnit == null || oldSelectedMassStorageUnit != SelectedMassStorageUnit)
            {
                itemsToShow = new List <Thing>(from Thing t in SelectedMassStorageUnit.StoredItems
                                               where string.IsNullOrEmpty(searchQuery) || t.Label.ToLower().NormalizedFuzzyStrength(searchQuery.ToLower()) <
                                               FuzzySearch.Strength.Strong
                                               orderby t.Label descending
                                               select t);
                oldSearchQuery = searchQuery;
            }
            oldSelectedMassStorageUnit = SelectedMassStorageUnit;

            var text        = SelectedMassStorageUnit.GetITabString(itemsToShow.Count);
            var MainTabText = new Rect(8f, curY, frame.width - 16f, Text.CalcHeight(text, frame.width - 16f));

            Widgets.Label(MainTabText, text);
            curY       += MainTabText.height;
            searchQuery = Widgets.TextField(new Rect(frame.x, curY, MainTabText.width - 16f, 25f),
                                            oldSearchQuery);
            curY += 28f;

            GUI.color = Color.white;
            var outRect  = new Rect(0f, curY, frame.width, frame.height - curY);
            var viewRect = new Rect(0f, 0f, outRect.width - 16f, scrollViewHeight);

            // Scrollview Start
            Widgets.BeginScrollView(outRect, ref scrollPos, viewRect);
            curY = 0f;
            if (itemsToShow.Count < 1)
            {
                Widgets.Label(viewRect, "PRFItemsTabLabel_Empty".Translate());
                curY += 22f;
            }

            // Iterate backwards to compensate for removing elements from enumerable
            // Learned this is an issue with List-like structures in AP CS 1A

            List <Pawn> pawns = SelectedMassStorageUnit.Map.mapPawns.FreeColonists;


            //Do it once as they are all on the same spot in the DSU
            //Even if is where to have multible sport's that way should work I think
            pawnCanReach_Touch_Deadly  = pawns.Where(p => p.CanReach(SelectedMassStorageUnit, PathEndMode.ClosestTouch, Danger.Deadly)).ToList();
            pawnCanReach_Oncell_Deadly = pawns.Where(p => p.CanReach(SelectedMassStorageUnit, PathEndMode.OnCell, Danger.Deadly)).ToList();



            for (var i = itemsToShow.Count - 1; i >= 0; i--)
            {
                //Check if we need to display it
                if (!itemIsVisible(curY, outRect.height, scrollPos.y))
                {
                    curY += 28;
                    continue;
                }

                Thing thing = itemsToShow[i];

                //Construct cache
                if (!canBeConsumedby.ContainsKey(thing))
                {
                    canBeConsumedby.Add(thing, pawns.Where(p => p.RaceProps.CanEverEat(thing) == true).ToList());
                }
                if (!thing_MaxHitPoints.ContainsKey(thing))
                {
                    thing_MaxHitPoints.Add(thing, thing.MaxHitPoints);
                }
                if (!thingIconCache.ContainsKey(thing))
                {
                    Color   color;
                    Texture texture = CommonGUIFunctions.GetThingTextue(new Rect(4f, curY, 28f, 28f), thing, out color);

                    thingIconCache.Add(thing, new thingIconTextureData(texture, color));
                }

                DrawThingRow(ref curY, viewRect.width, thing, pawns);
            }
            if (Event.current.type == EventType.Layout)
            {
                scrollViewHeight = curY + 30f;
            }
            //Scrollview End
            Widgets.EndScrollView();
            GUI.EndGroup();
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Beispiel #3
0
 public Dialog_RenameMassStorageUnit(Building_MassStorageUnit building)
 {
     this.building = building;
     curName       = building.uniqueName ?? building.LabelNoCount;
 }
Beispiel #4
0
 public static void Postfix(Thing __instance, Building_MassStorageUnit __state)
 {
     __state?.Notify_LostThing(__instance);
 }