Exemplo n.º 1
0
        public static void Postfix(ref IEnumerable <Gizmo> __result, Building_PlantGrower __instance)
        {
            var list = __result.ToList();

            Priority priority = PriorityTracker.plantBuildingPriorities.TryGetValue(__instance, out PriorityIntHolder intp) ? (Priority)intp.Int : Priority.Normal;

            list.Add(new Command_GrowingPriority((int)priority)
            {
                defaultLabel = $"Priority {priority}",
                defaultDesc  = $"Set this growing zone's priority. Current priority = {priority}",
                icon         = TexCommand.ForbidOff,
                onChanged    = (x) => {
                    var p = PriorityTracker.plantBuildingPriorities;
                    if (p.ContainsKey(__instance))
                    {
                        p[__instance].Int = x;
                    }
                    else
                    {
                        p[__instance] = new PriorityIntHolder(x);
                    }
                }
            });

            __result = list;
        }
Exemplo n.º 2
0
        public Command_GrowingPriority(Priority currentValue)
        {
            var growingZonePriorities   = PriorityTracker.growingZonePriorities;
            var plantBuildingPriorities = PriorityTracker.plantBuildingPriorities;
            var selectedGrowingZones    = new List <Zone_Growing>();
            var selectedPlantGrowers    = new List <Building_PlantGrower>();

            icon = TexCommand.ForbidOff;
            foreach (var obj in Find.Selector.SelectedObjects)
            {
                switch (obj)
                {
                case Zone_Growing zone:
                {
                    selectedGrowingZones.Add(zone);
                    break;
                }

                case Building_PlantGrower building:
                {
                    selectedPlantGrowers.Add(building);
                    break;
                }
                }
            }

            if (selectedPlantGrowers.Count > 0)
            {
                if (selectedPlantGrowers.Count > 1)
                {
                    defaultLabel = "Set priorities";
                    defaultDesc  = "Set priorities for these buildings.";
                }
                else
                {
                    defaultLabel = $"Priority {currentValue}";
                    defaultDesc  = $"Set this buildings priority. Current priority = {currentValue}";
                }

                onChanged = i =>
                {
                    foreach (var selectedPlantGrower in selectedPlantGrowers)
                    {
                        if (plantBuildingPriorities.ContainsKey(selectedPlantGrower))
                        {
                            plantBuildingPriorities[selectedPlantGrower].Int = i;
                        }
                        else
                        {
                            plantBuildingPriorities[selectedPlantGrower] = new PriorityIntHolder(i);
                        }
                    }
                };
                return;
            }

            if (selectedGrowingZones.Count <= 0)
            {
                return;
            }

            if (selectedGrowingZones.Count > 1)
            {
                defaultLabel = "Set priorities";
                defaultDesc  = "Set priorities for these zones.";
            }
            else
            {
                defaultLabel = $"Priority {currentValue}";
                defaultDesc  = $"Set this growing zone's priority. Current priority = {currentValue}";
            }

            onChanged = i =>
            {
                foreach (var selectedGrowingZone in selectedGrowingZones)
                {
                    if (growingZonePriorities.ContainsKey(selectedGrowingZone))
                    {
                        growingZonePriorities[selectedGrowingZone].Int = i;
                    }
                    else
                    {
                        growingZonePriorities[selectedGrowingZone] = new PriorityIntHolder(i);
                    }
                }
            };
        }