Exemplo n.º 1
0
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (settables == null)
            {
                settables = new List <IPlantToGrowSettable>();
            }
            if (!settables.Contains(settable))
            {
                settables.Add(settable);
            }
            tmpAvailablePlants.Clear();
            foreach (ThingDef item in PlantUtility.ValidPlantTypesForGrowers(settables))
            {
                if (IsPlantAvailable(item, settable.Map))
                {
                    tmpAvailablePlants.Add(item);
                }
            }
            tmpAvailablePlants.SortBy((ThingDef x) => 0f - GetPlantListPriority(x), (ThingDef x) => x.label);
            for (int i = 0; i < tmpAvailablePlants.Count; i++)
            {
                ThingDef plantDef = tmpAvailablePlants[i];
                string   text     = plantDef.LabelCap;
                if (plantDef.plant.sowMinSkill > 0)
                {
                    text = text + (string)(" (" + "MinSkill".Translate() + ": ") + plantDef.plant.sowMinSkill + ")";
                }
                list.Add(new FloatMenuOption(text, delegate
                {
                    string s = tutorTag + "-" + plantDef.defName;
                    if (TutorSystem.AllowAction(s))
                    {
                        bool flag = true;
                        for (int j = 0; j < settables.Count; j++)
                        {
                            settables[j].SetPlantDefToGrow(plantDef);
                            if (flag && plantDef.plant.interferesWithRoof)
                            {
                                foreach (IntVec3 cell in settables[j].Cells)
                                {
                                    if (cell.Roofed(settables[j].Map))
                                    {
                                        Messages.Message("MessagePlantIncompatibleWithRoof".Translate(Find.ActiveLanguageWorker.Pluralize(plantDef.LabelCap)), MessageTypeDefOf.CautionInput, historical: false);
                                        flag = false;
                                        break;
                                    }
                                }
                            }
                        }
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                        WarnAsAppropriate(plantDef);
                        TutorSystem.Notify_Event(s);
                    }
                }, plantDef, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, plantDef)));
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Exemplo n.º 2
0
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (this.settables == null)
            {
                this.settables = new List <IPlantToGrowSettable>();
            }
            if (!this.settables.Contains(this.settable))
            {
                this.settables.Add(this.settable);
            }
            Command_SetPlantToGrow.tmpAvailablePlants.Clear();
            foreach (ThingDef current in PlantUtility.ValidPlantTypesForGrowers(this.settables))
            {
                if (this.IsPlantAvailable(current, this.settable.Map))
                {
                    Command_SetPlantToGrow.tmpAvailablePlants.Add(current);
                }
            }
            Command_SetPlantToGrow.tmpAvailablePlants.SortBy((ThingDef x) => - this.GetPlantListPriority(x), (ThingDef x) => x.label);
            for (int i = 0; i < Command_SetPlantToGrow.tmpAvailablePlants.Count; i++)
            {
                ThingDef plantDef = Command_SetPlantToGrow.tmpAvailablePlants[i];
                string   text     = plantDef.LabelCap;
                if (plantDef.plant.sowMinSkill > 0)
                {
                    string text2 = text;
                    text = string.Concat(new object[]
                    {
                        text2,
                        " (",
                        "MinSkill".Translate(),
                        ": ",
                        plantDef.plant.sowMinSkill,
                        ")"
                    });
                }
                list.Add(new FloatMenuOption(text, delegate
                {
                    string s = this.tutorTag + "-" + plantDef.defName;
                    if (!TutorSystem.AllowAction(s))
                    {
                        return;
                    }
                    bool flag = true;
                    for (int j = 0; j < this.settables.Count; j++)
                    {
                        this.settables[j].SetPlantDefToGrow(plantDef);
                        if (flag && plantDef.plant.interferesWithRoof)
                        {
                            foreach (IntVec3 current2 in this.settables[j].Cells)
                            {
                                if (current2.Roofed(this.settables[j].Map))
                                {
                                    Messages.Message("MessagePlantIncompatibleWithRoof".Translate(Find.ActiveLanguageWorker.Pluralize(plantDef.LabelCap, -1)), MessageTypeDefOf.CautionInput, false);
                                    flag = false;
                                    break;
                                }
                            }
                        }
                    }
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                    this.WarnAsAppropriate(plantDef);
                    TutorSystem.Notify_Event(s);
                }, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, plantDef), null));
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }