Example #1
0
 public PD_Settings(ModContentPack content) : base(content)
 {
     Settings = GetSettings <SettingsData>();
 }
        /// <summary>
        /// Creates the drillable buttons and returns the bottom location of those buttons.
        /// </summary>
        public static float CreateDrillableButtons(Listing_Standard ls, float buttonHeight, ref TableData tableData, SettingsData settings)
        {
            Rect buttonRow = ls.GetRect(buttonHeight);

            Rect addDrillableBtnRect    = new Rect(buttonRow.x, buttonRow.y, buttonRow.width / 3, buttonRow.height);
            Rect removeDrillableBtnRect = new Rect(addDrillableBtnRect.xMax, addDrillableBtnRect.y, addDrillableBtnRect.width, addDrillableBtnRect.height);
            Rect resetDrillableBtnRect  = new Rect(removeDrillableBtnRect.xMax, addDrillableBtnRect.y, addDrillableBtnRect.width, addDrillableBtnRect.height);

            CreateAndAddDrillableButton(addDrillableBtnRect, ref tableData, settings);
            CreateRemoveDrillableButton(removeDrillableBtnRect, ref tableData, settings);
            CreateResetDrillableButton(resetDrillableBtnRect, ref tableData, settings);

            return(addDrillableBtnRect.yMax);
        }
        private static void CreateRemoveDrillableButton(Rect inRect, ref TableData tableData, SettingsData settings)
        {
            if (!Widgets.ButtonText(inRect, "SEPD_RemoveDrillable".Translate().CapitalizeFirst(), active: settings.Drillables.Any()))
            {
                return;
            }

            Find.WindowStack.Add(new FloatMenu(
                                     settings.Drillables
                                     .Select(kvp => new FloatMenuOption(kvp.Value.ThingDefToDrill.label, () => settings.Drillables.Remove(kvp.Key), kvp.Value.ThingDefToDrill))
                                     .ToList()));
            tableData.Rows.Remove(tableData.Rows.Last());
        }
 private static void CreateResetDrillableButton(Rect inRect, ref TableData tableData, SettingsData settings)
 {
     if (Widgets.ButtonText(inRect, "SEPD_ResetDrillables".Translate().CapitalizeFirst()))
     {
         while (tableData.Rows.Count > 1)
         {
             tableData.Rows.Remove(tableData.Rows.Last());
         }
         settings.ResetDrillableSettings();
     }
 }
 private static void CreateAndAddDrillableButton(Rect inRect, ref TableData tableData, SettingsData settings)
 {
     if (!Widgets.ButtonText(inRect, "SEPD_AddDrillable".Translate().CapitalizeFirst(), active: Mineables.AllMineables.Except(settings.Drillables.Values.Select(d => d.ThingDefToDrill)).Any()))
     {
         return;
     }
     {
         Find.WindowStack.Add(new FloatMenu(
                                  Mineables.AllMineables
                                  .Where(settings.CanItemBeDrilledAccordingToSettings)
                                  .Except(settings.Drillables.Values.Select(d => d.ThingDefToDrill)) // Don't display items that were already added.
                                  .Select(m => new FloatMenuOption(m.label, () => settings.Drillables.Add(m.defName, new DrillData(m.defName, 1000, 1)), m))
                                  .ToList()));
     }
 }