コード例 #1
0
            public override void DoWindowContents(Rect inRect) // For a specific DSU
            {
                // for the record, Listing_Standards kind of suck. Convenient enough, but no flexibility
                // TODO when I'm bored: switch to manual, add red background for disabled units
                // Bonus problem with Listing_Standard: nested scrolling windows do not work
                //   well - specifically the ThingFilter UI insisde a Listing_Standard
                // We are able to get around that problem by having our ScrollView be outside
                //   the Listing_S... (instead of using the L_S's .ScrollView) and having the
                //   ThingFilter's UI after the L_S ends.

                // First: Set up a ScrollView:
                // outer window (with room for buttons at bottom:
                Rect s = new Rect(inRect.x, inRect.y, inRect.width, inRect.height - CloseButSize.y - 5f);

                // inner window that has entire content:
                y = y + 200; // this is to ensure the Listing_Standard does not run out of height,
                //                and can fully display everything - giving a proper length 'y' at
                //                its .End() call.
                //          Worst case scenario: y starts as 0, and the L_S gets to a CurHeight of
                //            200, and then updates at 400 the next time.  Because of the way RW's
                //            windows work, this will rapidly converge on a large enough value.
                Rect inner = new Rect(0, 0, s.width - 20, this.y);

                Widgets.BeginScrollView(s, ref DSUScrollPosition, inner);
                // We cannot do the scrollview inside the L_S:
                // l.BeginScrollView(s, ref DSUScrollPosition, ref v); // Does not allow filter UI
                var l = new Listing_Standard();

                l.Begin(inner);
                l.Label(def.label);
                l.GapLine();
                // Much TODO, so wow:
                tmpLabel = l.TextEntryLabeled("LWMDSpDSUlabel".Translate(), tmpLabel);
                string tmpstring = null;

                l.TextFieldNumericLabeled("LWM_DS_maxNumStacks".Translate().CapitalizeFirst() + " "
                                          + "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName, "maxNumStacks",
                                                                                               tmpMaxNumStacks)),
                                          ref tmpMaxNumStacks, ref tmpstring, 0);
                tmpstring = null;
                l.TextFieldNumericLabeled <float>("LWM_DS_maxTotalMass".Translate().CapitalizeFirst() + " " +
                                                  "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName,
                                                                                                     "maxTotalMass", tmpMaxTotalMass).ToString()),
                                                  ref tmpMaxTotalMass, ref tmpstring, 0f);
                tmpstring = null;
                l.TextFieldNumericLabeled <float>("LWM_DS_maxMassOfStoredItem".Translate().CapitalizeFirst() + " " +
                                                  "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName,
                                                                                                     "maxMassStoredItem", tmpMaxMassStoredItem).ToString()),
                                                  ref tmpMaxMassStoredItem, ref tmpstring, 0f);
                l.CheckboxLabeled("LWMDSpDSUshowContents".Translate(), ref tmpShowContents);
                l.GapLine();
                l.EnumRadioButton(ref tmpOverlayType, "LWMDSpDSUoverlay".Translate());
                l.GapLine();
                l.EnumRadioButton(ref tmpStoragePriority, "LWMDSpDSUstoragePriority".Translate());
                l.GapLine();
                l.CheckboxLabeled("LWMDSpDSUchangeFilterQ".Translate(), ref useCustomThingFilter,
                                  "LWMDSpDSUchangeFilterQDesc".Translate());
                y = l.CurHeight;
                l.End();
                if (useCustomThingFilter)
                {
                    if (customThingFilter == null)
                    {
                        customThingFilter = new ThingFilter();
                        customThingFilter.CopyAllowancesFrom(def.building.fixedStorageSettings.filter);
                        Utils.Mess(Utils.DBF.Settings, "Created new filter for " + def.defName + ": " + customThingFilter);
//                        Log.Error("Old filter has: "+def.building.fixedStorageSettings.filter.AllowedDefCount);
//                        Log.Warning("New filter has: "+customThingFilter.AllowedDefCount);
                    }
                    // Since this is outside the L_S, we make our own rectangle and use it:
                    //   Nope: Rect r=l.GetRect(CustomThingFilterHeight); // this fails
                    Rect r = new Rect(20, y, (inner.width - 40) * 3 / 4, CustomThingFilterHeight);
                    y += CustomThingFilterHeight;
                    ThingFilterUI.DoThingFilterConfigWindow(r, thingFilterState, customThingFilter);
                }
                else     // not using custom thing filter:
                {
                    if (customThingFilter != null || tracker.HasDefaultValueFor(this.def.defName, "filter"))
                    {
                        customThingFilter = null;
                        if (tracker.HasDefaultValueFor(this.def.defName, "filter"))
                        {
                            Utils.Mess(Utils.DBF.Settings, "  Removing filter for " + def.defName);
                            def.building.fixedStorageSettings.filter = (ThingFilter)tracker
                                                                       .GetDefaultValue <ThingFilter>(def.defName, "filter", null);
                            tracker.Remove(def.defName, "filter");
                        }
                    }
                }

                // This fails: l.EndScrollView(ref v);
                Widgets.EndScrollView();

                // Cancel button
                var closeRect = new Rect(inRect.width - CloseButSize.x, inRect.height - CloseButSize.y, CloseButSize.x, CloseButSize.y);

                if (Widgets.ButtonText(closeRect, "CancelButton".Translate()))
                {
                    Utils.Mess(Utils.DBF.Settings, "Cancel button selected - no changes made");
                    Close();
                }
                // Accept button - with accompanying logic
                closeRect = new Rect(inRect.width - (2 * CloseButSize.x + 5f), inRect.height - CloseButSize.y, CloseButSize.x, CloseButSize.y);
                if (Widgets.ButtonText(closeRect, "AcceptButton".Translate()))
                {
                    LWM.DeepStorage.Properties props = def.GetCompProperties <Properties>();
                    GUI.FocusControl(null); // unfocus, so that a focused text field may commit its value
                    Utils.Warn(Utils.DBF.Settings, "\"Accept\" button selected: changing values for " + def.defName);
                    tracker.UpdateToNewValue(def.defName, "label", tmpLabel, ref def.label);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxNumStacks", tmpMaxNumStacks, ref props.maxNumberStacks);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxTotalMass", tmpMaxTotalMass, ref props.maxTotalMass);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxMassStoredItem", tmpMaxMassStoredItem, ref props.maxMassOfStoredItem);
                    tracker.UpdateToNewValue(def.defName,
                                             "showContents", tmpShowContents, ref props.showContents);
                    tracker.UpdateToNewValue(def.defName,
                                             "overlayType", tmpOverlayType, ref props.overlayType);
                    StoragePriority tmpSP = def.building.defaultStorageSettings.Priority; // hard to access private field directly
                    tracker.UpdateToNewValue(def.defName, "storagePriority", tmpStoragePriority, ref tmpSP);
                    def.building.defaultStorageSettings.Priority = tmpSP;
                    if (useCustomThingFilter)   // danger ahead - automatically use it, even if stupidly set up
                    {
                        if (!tracker.HasDefaultValueFor(def.defName, "filter"))
                        {
                            Utils.Mess(Utils.DBF.Settings, "Creating default filter record for item " + def.defName);
                            tracker.AddDefaultValue(def.defName, "filter", def.building.fixedStorageSettings.filter);
                        }
                        def.building.fixedStorageSettings.filter = customThingFilter;
                    }
                    else
                    {
                        // restore default filter:
                        if (tracker.HasDefaultValueFor(def.defName, "filter"))
                        {
                            // we need to remove it
                            Utils.Mess(Utils.DBF.Settings, "Removing default filter record for item " + def.defName);
                            def.building.fixedStorageSettings.filter = (ThingFilter)tracker
                                                                       .GetDefaultValue <ThingFilter>(def.defName, "filter", null);
                            tracker.Remove(def.defName, "filter");
                        }
                    }
                    Close();
                }
                // Reset to Defaults
                closeRect = new Rect(inRect.width - (4 * CloseButSize.x + 10f), inRect.height - CloseButSize.y, 2 * CloseButSize.x, CloseButSize.y);
                if (!AreTempVarsDefaults() && Widgets.ButtonText(closeRect, "ResetBinding".Translate()))
                {
                    SetTempVarsToDefaults();
                }
            }
コード例 #2
0
            public override void DoWindowContents(Rect inRect) // For a specific DSU
            {
//                var XXXcontentRect = new Rect(0, 0, inRect.width, inRect.height - (CloseButSize.y + 10f)).ContractedBy(10f);
                // for the record, Listing_Standards kind of suck. Convenient enough, but no flexibility
                // TODO when I'm bored: switch to manual, add red background for disabled units
                var l = new Listing_Standard();
//                l.Begin(new Rect(inRect.x, inRect.y, inRect.width, inRect.height-CloseButSize.y-5f));
                Rect s = new Rect(inRect.x, inRect.y, inRect.width, inRect.height - CloseButSize.y - 5f);
                Rect v = new Rect(inRect.x, inRect.y, inRect.width - 20f, inRect.height - CloseButSize.y - 5f);

                if (useCustomThingFilter)
                {
                    v.height += CustomThingFilterHeight;
                }
                l.BeginScrollView(s, ref DSUScrollPosition, ref v);
//                l.BeginScrollView(
//                l.BeginScrollView(Rect rect, ref Vector2 scrollPosition, ref Rect viewRect)
                l.Label(def.label);
                l.GapLine();
                // Much TODO, so wow:
                tmpLabel = l.TextEntryLabeled("LWMDSpDSUlabel".Translate(), tmpLabel);
                string tmpstring = null;

                l.TextFieldNumericLabeled("LWM_DS_maxNumStacks".Translate().CapitalizeFirst() + " "
                                          + "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName, "maxNumStacks",
                                                                                               tmpMaxNumStacks)),
                                          ref tmpMaxNumStacks, ref tmpstring, 0);
                tmpstring = null;
                l.TextFieldNumericLabeled <float>("LWM_DS_maxTotalMass".Translate().CapitalizeFirst() + " " +
                                                  "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName,
                                                                                                     "maxTotalMass", tmpMaxTotalMass).ToString()),
                                                  ref tmpMaxTotalMass, ref tmpstring, 0f);
                tmpstring = null;
                l.TextFieldNumericLabeled <float>("LWM_DS_maxMassOfStoredItem".Translate().CapitalizeFirst() + " " +
                                                  "LWM_DS_Default".Translate(tracker.GetDefaultValue(def.defName,
                                                                                                     "maxMassStoredItem", tmpMaxMassStoredItem).ToString()),
                                                  ref tmpMaxMassStoredItem, ref tmpstring, 0f);
                l.CheckboxLabeled("LWMDSpDSUshowContents".Translate(), ref tmpShowContents);
                l.GapLine();
                l.EnumRadioButton(ref tmpOverlayType, "LWMDSpDSUoverlay".Translate());
                l.GapLine();
                l.EnumRadioButton(ref tmpStoragePriority, "LWMDSpDSUstoragePriority".Translate());
                l.GapLine();
                l.CheckboxLabeled("LWMDSpDSUchangeFilterQ".Translate(), ref useCustomThingFilter,
                                  "LWMDSpDSUchangeFilterQDesc".Translate());
                if (useCustomThingFilter)
                {
                    if (customThingFilter == null)
                    {
                        customThingFilter = new ThingFilter();
                        customThingFilter.CopyAllowancesFrom(def.building.fixedStorageSettings.filter);
                        Utils.Mess(Utils.DBF.Settings, "Created new filter for " + def.defName + ": " + customThingFilter);
//                        Log.Error("Old filter has: "+def.building.fixedStorageSettings.filter.AllowedDefCount);
//                        Log.Warning("New filter has: "+customThingFilter.AllowedDefCount);
                    }
                    Rect r = l.GetRect(CustomThingFilterHeight);
                    r.width *= 2f / 3f;
                    r.x     += 10f;
                    ThingFilterUI.DoThingFilterConfigWindow(r, ref thingFilterScrollPosition, customThingFilter);
                }
                else     // not using custom thing filter:
                {
                    if (customThingFilter != null || tracker.HasDefaultValueFor(this.def.defName, "filter"))
                    {
                        customThingFilter = null;
                        if (tracker.HasDefaultValueFor(this.def.defName, "filter"))
                        {
                            Utils.Mess(Utils.DBF.Settings, "  Removing filter for " + def.defName);
                            def.building.fixedStorageSettings.filter = (ThingFilter)tracker
                                                                       .GetDefaultValue <ThingFilter>(def.defName, "filter", null);
                            tracker.Remove(def.defName, "filter");
                        }
                    }
                }

/*                if (l.ButtonDebug("Show default values for "+this.def)) {
 *                  foreach (var kv in defaultDSUValues) {
 *
 *                  }
 *              }
 */
//                l.End();
                l.EndScrollView(ref v);

                // Cancel button
                var closeRect = new Rect(inRect.width - CloseButSize.x, inRect.height - CloseButSize.y, CloseButSize.x, CloseButSize.y);

                if (Widgets.ButtonText(closeRect, "CancelButton".Translate()))
                {
                    Utils.Mess(Utils.DBF.Settings, "Cancel button selected - no changes made");
                    Close();
                }
                // Accept button - with accompanying logic
                closeRect = new Rect(inRect.width - (2 * CloseButSize.x + 5f), inRect.height - CloseButSize.y, CloseButSize.x, CloseButSize.y);
                if (Widgets.ButtonText(closeRect, "AcceptButton".Translate()))
                {
                    LWM.DeepStorage.Properties props = def.GetCompProperties <Properties>();
                    GUI.FocusControl(null); // unfocus, so that a focused text field may commit its value
                    Utils.Warn(Utils.DBF.Settings, "\"Accept\" button selected: changing values for " + def.defName);
                    tracker.UpdateToNewValue(def.defName, "label", tmpLabel, ref def.label);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxNumStacks", tmpMaxNumStacks, ref props.maxNumberStacks);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxTotalMass", tmpMaxTotalMass, ref props.maxTotalMass);
                    tracker.UpdateToNewValue(def.defName,
                                             "maxMassStoredItem", tmpMaxMassStoredItem, ref props.maxMassOfStoredItem);
                    tracker.UpdateToNewValue(def.defName,
                                             "showContents", tmpShowContents, ref props.showContents);
                    tracker.UpdateToNewValue(def.defName,
                                             "overlayType", tmpOverlayType, ref props.overlayType);
                    StoragePriority tmpSP = def.building.defaultStorageSettings.Priority; // hard to access private field directly
                    tracker.UpdateToNewValue(def.defName, "storagePriority", tmpStoragePriority, ref tmpSP);
                    def.building.defaultStorageSettings.Priority = tmpSP;
                    if (useCustomThingFilter)   // danger ahead - automatically use it, even if stupidly set up
                    {
                        if (!tracker.HasDefaultValueFor(def.defName, "filter"))
                        {
                            Utils.Mess(Utils.DBF.Settings, "Creating default filter record for item " + def.defName);
                            tracker.AddDefaultValue(def.defName, "filter", def.building.fixedStorageSettings.filter);
                        }
                        def.building.fixedStorageSettings.filter = customThingFilter;
                    }
                    else
                    {
                        // restore default filter:
                        if (tracker.HasDefaultValueFor(def.defName, "filter"))
                        {
                            // we need to remove it
                            Utils.Mess(Utils.DBF.Settings, "Removing default filter record for item " + def.defName);
                            def.building.fixedStorageSettings.filter = (ThingFilter)tracker
                                                                       .GetDefaultValue <ThingFilter>(def.defName, "filter", null);
                            tracker.Remove(def.defName, "filter");
                        }
                    }
                    Close();
                }
                // Reset to Defaults
                closeRect = new Rect(inRect.width - (4 * CloseButSize.x + 10f), inRect.height - CloseButSize.y, 2 * CloseButSize.x, CloseButSize.y);
                if (!AreTempVarsDefaults() && Widgets.ButtonText(closeRect, "ResetBinding".Translate()))
                {
                    SetTempVarsToDefaults();
                }
            }