Ejemplo n.º 1
0
        /// <summary>
        /// Shows a confirmation dialog to force update the specified mod(s).
        /// </summary>
        internal void TryUpdateMods(GameObject _)
        {
            var controller = Global.Instance.GetInputManager()?.GetDefaultController();

            // Check for SHIFT - bypass dialog
            if (activeModifiers != null && (activeModifiers.GetValue(controller) is Modifier
                                            modifier) && modifier == Modifier.Shift)
            {
                UpdateMods();
            }
            else
            {
                var modList = new StringBuilder(256);
                // Add up to the limit to avoid making a dialog larger than the screen
                int n = 0;
                foreach (var mod in Mods)
                {
                    modList.AppendFormat(ModUpdateDateStrings.CONFIRM_LINE, mod.Title);
                    n++;
                    // (and N more...)
                    if (n >= ModUpdateDateStrings.MAX_LINES)
                    {
                        modList.AppendFormat(ModUpdateDateStrings.CONFIRM_MORE, Mods.Count -
                                             n);
                        break;
                    }
                }
                PUIElements.ShowConfirmDialog(null, string.Format(ModUpdateDateStrings.
                                                                  CONFIRM_UPDATE, modList.ToString()), UpdateMods, null,
                                              ModUpdateDateStrings.CONFIRM_OK, ModUpdateDateStrings.CONFIRM_CANCEL);
            }
        }
Ejemplo n.º 2
0
        private void SetProbingRadiusUI(int radius)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            PSliderSingle.SetCurrentValue(this.ProbingRadiusSlider, radius);

            StationaryChoreRangeVisualizer choreRangeVisualizer = this.target.GetComponent <StationaryChoreRangeVisualizer>();

            if ((UnityEngine.Object)choreRangeVisualizer == (UnityEngine.Object)null)
            {
                return;
            }

            choreRangeVisualizer.x     = -radius;
            choreRangeVisualizer.width = 2 + 2 * radius;
            Traverse.Create(choreRangeVisualizer).Method("UpdateVisualizers").GetValue();

            if ((UnityEngine.Object) this.ProbingRadiusText == (UnityEngine.Object)null)
            {
                return;
            }

            PUIElements.SetText(this.ProbingRadiusText, radius.ToString("0"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Shows a confirmation dialog to force update the specified mod(s).
        /// </summary>
        internal void TryUpdateMods(GameObject _)
        {
            var controller = Global.Instance.GetInputManager()?.GetDefaultController();
            var modifier   = Modifier.None;

            try {
                modifier = ACTIVE_MODIFIERS.Get(controller);
            } catch (DetourException) { }
            // Check for SHIFT - bypass dialog
            if (modifier == Modifier.Shift)
            {
                UpdateMods();
            }
            else
            {
                var modList = new StringBuilder(256);
                // Add up to the limit to avoid making a dialog larger than the screen
                int n = 0;
                foreach (var mod in Mods)
                {
                    modList.AppendFormat(UISTRINGS.CONFIRM_LINE, mod.Title);
                    n++;
                    // (and N more...)
                    if (n >= ModUpdateDateStrings.MAX_LINES)
                    {
                        modList.AppendFormat(UISTRINGS.CONFIRM_MORE, Mods.Count - n);
                        break;
                    }
                }
                PUIElements.ShowConfirmDialog(null, string.Format(UISTRINGS.CONFIRM_UPDATE,
                                                                  modList.ToString()), UpdateMods, null, UISTRINGS.CONFIRM_OK, UISTRINGS.
                                              CONFIRM_CANCEL);
            }
        }
Ejemplo n.º 4
0
        private void SetButtonStates(bool enabled)
        {
            if (this.FindSweepyButton != null)
            {
                PButton.SetButtonEnabled(this.FindSweepyButton, enabled);
            }

            if (this.ResetSweepyButton != null)
            {
                PButton.SetButtonEnabled(this.ResetSweepyButton, enabled);
            }

            if (!enabled)
            {
                if ((UnityEngine.Object) this.MoveSpeedText != (UnityEngine.Object)null)
                {
                    PUIElements.SetText(this.MoveSpeedText, "N/A");
                }

                StationaryChoreRangeVisualizer choreRangeVisualizer = this.target.GetComponent <StationaryChoreRangeVisualizer>();

                if ((UnityEngine.Object)choreRangeVisualizer != (UnityEngine.Object)null)
                {
                    choreRangeVisualizer.x     = 0;
                    choreRangeVisualizer.width = 0;
                    Traverse.Create(choreRangeVisualizer).Method("UpdateVisualizers").GetValue();
                }

                if ((UnityEngine.Object) this.ProbingRadiusText != (UnityEngine.Object)null)
                {
                    PUIElements.SetText(this.ProbingRadiusText, "N/A");
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Populates the menu with the available destroy modes.
        /// </summary>
        /// <param name="parameters">The modes to show in the menu.</param>
        internal void PopulateMenu(IList <DestroyFilter> parameters)
        {
            int i      = 0;
            var prefab = ToolMenu.Instance.toolParameterMenu.widgetPrefab;

            ClearMenu();
            foreach (var parameter in parameters)
            {
                // Create prefab based on existing Klei menu
                var widgetPrefab = Util.KInstantiateUI(prefab, choiceList, true);
                PUIElements.SetText(widgetPrefab, parameter.Title);
                var toggle   = widgetPrefab.GetComponentInChildren <MultiToggle>();
                var checkbox = toggle?.gameObject;
                if (checkbox != null)
                {
                    // Set initial state, note that ChangeState is only called by SetCheckState
                    // if it appears to be different, but since this executes before the
                    // parent is active it must be set to something different
                    var option = new DestroyMenuOption(parameter, checkbox);
                    PCheckBox.SetCheckState(checkbox, 2);
                    if (i == 0 || SandboxToolsPatches.AdvancedFilterEnabled)
                    {
                        option.State = ToolParameterMenu.ToggleState.On;
                    }
                    options.Add(parameter.ID, option);
                    toggle.onClick += () => OnClick(checkbox);
                }
                else
                {
                    PUtil.LogWarning("Could not find destroy menu checkbox!");
                }
                i++;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Invoked when the dialog is closed.
 /// </summary>
 /// <param name="action">The action key taken.</param>
 private void OnOptionsSelected(string action)
 {
     if (action == "ok")
     {
         // Save changes to mod options
         WriteOptions();
         if (options != null)
         {
             // Check for [RestartRequired]
             string rr = typeof(RestartRequiredAttribute).FullName;
             bool   restartRequired = false;
             foreach (var attr in options.GetType().GetCustomAttributes(true))
             {
                 if (attr.GetType().FullName == rr)
                 {
                     restartRequired = true;
                     break;
                 }
             }
             if (restartRequired)
             {
                 // Prompt user to restart
                 PUIElements.ShowConfirmDialog(null, POptions.RESTART_REQUIRED,
                                               App.instance.Restart, null, POptions.RESTART_OK, POptions.
                                               RESTART_CANCEL);
             }
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Shows the mod actions popup.
        /// </summary>
        /// <param name="button">The options button which invoked this popup.</param>
        /// <param name="index">The mod index in the list that is showing the popup.</param>
        private void ShowPopup(KButton button, int index)
        {
            var mods = Global.Instance.modManager?.mods;
            int n;

            if (mods != null && index >= 0 && index < (n = mods.Count))
            {
                var  mod     = mods[index];
                bool isSteam = mod.label.distribution_platform == Label.DistributionPlatform.
                               Steam;
                RectTransform rt = actionsScreen.rectTransform(), crt = button.rectTransform();
                actionsScreen.Index = index;
                actionsScreen.Mod   = mod;
                // Update usability of each button
                if (buttonFirst != null)
                {
                    buttonFirst.isInteractable = index > 0;
                }
                if (buttonUp != null)
                {
                    buttonUp.isInteractable = index > 0;
                }
                if (buttonDown != null)
                {
                    buttonDown.isInteractable = index < n - 1;
                }
                if (buttonLast != null)
                {
                    buttonLast.isInteractable = index < n - 1;
                }
                if (buttonUnsub != null)
                {
                    buttonUnsub.isInteractable = isSteam;
                }
                if (buttonManage != null)
                {
                    PUIElements.SetToolTip(buttonManage, isSteam ? UI.MODSSCREEN.
                                           BUTTON_SUBSCRIPTION : UI.MODSSCREEN.BUTTON_LOCAL);
                    PUIElements.SetToolTip(buttonManage, mod.manage_tooltip);
                }
                if (buttonModify != null)
                {
                    buttonModify.isInteractable = isSteam;
                }
                actionsScreen.SetActive(true);
                // Resize to the proper size
                LayoutRebuilder.ForceRebuildLayoutImmediate(rt);
                float w = LayoutUtility.GetPreferredWidth(rt), h = LayoutUtility.
                                                                   GetPreferredHeight(rt) * 0.5f, end = crt.offsetMin.x - 1.0f;
                rt.SetParent(crt.parent, false);
                rt.SetAsLastSibling();
                // Move it to the correct place
                rt.anchoredPosition = Vector2.zero;
                rt.anchorMin        = DebugUtils.ANCHOR_MID_LEFT;
                rt.anchorMax        = DebugUtils.ANCHOR_MID_LEFT;
                rt.offsetMin        = new Vector2(end - w, -h);
                rt.offsetMax        = new Vector2(end, h);
                callingButton       = button;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Updates all elements in the specified category.
 /// </summary>
 /// <param name="inv">The inventory of discovered elements.</param>
 /// <param name="category">The category to search.</param>
 /// <param name="overrideName">The name to override the category title</param>
 private void UpdateCategory(WorldInventory inv, Tag category,
                             string overrideName = null)
 {
     if (inv.TryGetDiscoveredResourcesFromTag(category, out HashSet <Tag> found) &&
         found.Count > 0)
     {
         // Attempt to add to type select control
         if (!children.TryGetValue(category, out TypeSelectCategory current))
         {
             current = new TypeSelectCategory(this, category, overrideName);
             children.Add(category, current);
             int        index = 1 + (children.IndexOfKey(category) << 1);
             GameObject header = current.Header, panel = current.ChildPanel;
             // Header goes in even indexes, panel goes in odds
             header.SetParent(childPanel);
             PUIElements.SetAnchors(header, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             header.transform.SetSiblingIndex(index);
             panel.SetParent(childPanel);
             PUIElements.SetAnchors(panel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
             panel.transform.SetSiblingIndex(index + 1);
         }
         foreach (var element in found)
         {
             current.TryAddType(element);
         }
     }
 }
Ejemplo n.º 9
0
		protected override void OnDeactivateTool(InterfaceTool newTool) {
			var menu = ToolMenu.Instance;
			// Unparent but do not dispose
			if (TypeSelect != null)
				PUIElements.SetParent(TypeSelect.RootPanel, null);
			menu.PriorityScreen.Show(false);
			base.OnDeactivateTool(newTool);
		}
Ejemplo n.º 10
0
 /// <summary>
 /// Updates the displayed tool tip and text to match the current item.
 /// </summary>
 private void Update()
 {
     if (label != null)
     {
         var option = options[index];
         PUIElements.SetText(label, option.Title);
         PUIElements.SetToolTip(label, option.ToolTip);
     }
 }
Ejemplo n.º 11
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            // One long linear row
            var panel = new PPanel("MoreModActions")
            {
                BackColor = PUITuning.Colors.DialogDarkBackground, Spacing = 6,
                BackImage = PUITuning.Images.BoxBorder, ImageMode = Image.Type.Sliced,
                Direction = PanelDirection.Horizontal, Margin = new RectOffset(6, 6, 6, 6)
            }.AddChild(MakeButton("MoveToFirst", UI.TOOLTIPS.DNI_TOP,
                                  SpriteRegistry.GetTopIcon(), OnMoveFirst, (obj) =>
                                  buttonFirst = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveUpTen", UI.TOOLTIPS.DNI_UP,
                                 Assets.GetSprite("icon_priority_up_2"), OnMoveUp, (obj) =>
                                 buttonUp = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveDownTen", UI.TOOLTIPS.DNI_DOWN,
                                 Assets.GetSprite("icon_priority_down_2"), OnMoveDown, (obj) =>
                                 buttonDown = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveToLast", UI.TOOLTIPS.DNI_BOTTOM,
                                 SpriteRegistry.GetBottomIcon(), OnMoveLast, (obj) =>
                                 buttonLast = obj.GetComponent <KButton>()))
            .AddChild(new PButton("ManageMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_SUBSCRIPTION, DynamicSize = false,
                OnClick = OnManage, ToolTip = "Manage Mod", Margin = DebugUtils.BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonManage = obj))
            .AddChild(new PButton("UnsubMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_UNSUB, DynamicSize = false,
                OnClick = OnUnsub, ToolTip = UI.TOOLTIPS.DNI_UNSUB, Margin = DebugUtils.
                                                                             BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonUnsub = obj.
                                                                     GetComponent <KButton>()));

#if DEBUG
            panel.AddChild(new PButton("ModifyMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_MODIFY, DynamicSize = false,
                OnClick = OnModify, ToolTip = UI.TOOLTIPS.DNI_MODIFY, Margin = DebugUtils.
                                                                               BUTTON_MARGIN
            }.SetKleiPinkStyle().AddOnRealize((obj) => buttonModify = obj.
                                                                      GetComponent <KButton>()));
#endif
            var actionsObj = panel.AddTo(gameObject);
#if DEBUG
            PButton.SetButtonEnabled(buttonModify.gameObject, false);
#endif
            actionsObj.SetActive(false);
            // Blacklist from auto layout
            actionsObj.AddOrGet <LayoutElement>().ignoreLayout = true;
            PUIElements.SetAnchors(actionsObj, PUIAnchoring.End, PUIAnchoring.Center);
            unsubCaller = new CallResult <RemoteStorageUnsubscribePublishedFileResult_t>(
                OnUnsubComplete);
            actionsScreen = actionsObj.AddComponent <ModActionsScreen>();
            callingButton = null;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Checks the mod config class for the [RestartRequired] attribute, and brings up a
 /// restart dialog if necessary.
 /// </summary>
 private void CheckForRestart()
 {
     if (options != null && options.GetType().
         GetCustomAttribute <RestartRequiredAttribute>() != null)
     {
         // Prompt user to restart
         PUIElements.ShowConfirmDialog(null, PLibStrings.RESTART_REQUIRED,
                                       SaveAndRestart, null, PLibStrings.RESTART_OK, PLibStrings.RESTART_CANCEL);
     }
 }
Ejemplo n.º 13
0
		protected override void OnActivateTool() {
			var menu = ToolMenu.Instance;
			base.OnActivateTool();
			// Update only on tool activation to improve performance
			if (TypeSelect != null) {
				var root = TypeSelect.RootPanel;
				TypeSelect.Update();
				PUIElements.SetParent(root, menu.gameObject);
				root.transform.SetAsFirstSibling();
			}
			menu.PriorityScreen.Show(true);
		}
Ejemplo n.º 14
0
        /// <summary>
        /// Force updates the specified mod(s).
        /// </summary>
        private void UpdateMods()
        {
            var instance = ModUpdateHandler.Instance;

            if (instance.IsUpdating)
            {
                PUIElements.ShowMessageDialog(null, ModUpdateDateStrings.UPDATE_INPROGRESS);
            }
            else
            {
                instance.StartModUpdate(this);
            }
        }
Ejemplo n.º 15
0
        private void SetMovespeedUI(float speed)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            PSliderSingle.SetCurrentValue(this.MoveSpeedSlider, speed);

            if ((UnityEngine.Object) this.MoveSpeedText == (UnityEngine.Object)null)
            {
                return;
            }
            PUIElements.SetText(this.MoveSpeedText, speed.ToString("0.00"));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Builds the "Select Material" window.
        /// </summary>
        /// <param name="menu">The parent window for the window.</param>
        private void CreateSelector(ToolParameterMenu menu)
        {
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }
            Color32 color  = PUITuning.Colors.BackgroundLight;
            var     parent = menu.transform.parent?.gameObject ?? GameScreenManager.Instance.
                             ssOverlayCanvas;

            // Create a single MaterialSelector which is all we need
            typeSelect = Util.KInstantiateUI <MaterialSelector>(infoScreen.
                                                                materialSelectionPanel.MaterialSelectorTemplate, parent);
            var obj = typeSelect.gameObject;

            typeSelect.name = "FilteredClearToolMaterials";
            // Allow scrolling on the material list
            Traverse.Create(typeSelect).SetField("ConsumeMouseScroll", true);
            // Add canvas and renderer
            obj.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
            obj.AddComponent <CanvasRenderer>();
            // Background and hit-test
            var infoBG = infoScreen.transform.Find("BG");

            if (infoBG != null)
            {
                var imgComponent = infoBG.GetComponent <Image>();
                if (imgComponent != null)
                {
                    color = imgComponent.color;
                }
                obj.AddComponent <Image>().color = color;
            }
            obj.AddComponent <GraphicRaycaster>();
            // Resize window to match its contents
            PUIElements.AddSizeFitter(obj);
            typeSelect.ConfigureScreen(sweepRecipe.Ingredients[0], sweepRecipe);
            AddEggsAndFoods();
            var transform = obj.rectTransform();

            // Position
            transform.pivot      = new Vector2(1.0f, 0.0f);
            transform.localScale = Vector3.one;
            transform.SetAsFirstSibling();
            typeSelect.Activate();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Updates the list of available elements.
        /// </summary>
        public void Update(GridFilterableSideScreen screen)
        {
            Console.WriteLine("updating with the storage");
            Storage    storage = screen.storage;
            GameObject target  = screen.target;

            if (storage.storageFilters != null && storage.storageFilters.Count >= 1)
            {
                // check for which ones aren't added already and add them
                foreach (Tag tag in storage.storageFilters)
                {
                    Console.WriteLine($"Should be checking presence of tag {tag.ToString()}");
                    if (!HasElement(tag))
                    {
                        Console.WriteLine($"Attempted to add {tag.ToString()} to the panel");
                        if (children.Count <= 0)
                        {
                            GridFilterableRow firstRow = new GridFilterableRow(this);
                            children.Add(firstRow);
                            PUIElements.SetParent(firstRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(firstRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                        }
                        GridFilterableRow lastRow = children[children.Count - 1];
                        if (lastRow.RowSize >= PER_ROW)
                        {
                            lastRow = new GridFilterableRow(this);
                            PUIElements.SetParent(lastRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(lastRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                            children.Add(lastRow);
                        }
                        GridFilterableSelectableEntity entity = new GridFilterableSelectableEntity(lastRow, tag);
                        lastRow.Children.Add(entity);
                        PUIElements.SetParent(entity.CheckBox, lastRow.ChildPanel);
                        if (PCheckBox.GetCheckState(entity.CheckBox) == PCheckBox.STATE_CHECKED)
                        {
                            // Set to checked
                            PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_CHECKED);
                        }
                    }
                }
            }
            else
            {
                Debug.LogError((object)"If you're filtering, your storage filter should have the filters set on it");
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Applied after OnPrefabInit runs.
 /// </summary>
 internal static void Postfix(MainMenu __instance)
 {
     if (__instance != null)
     {
         var go = __instance.gameObject;
         if (SafeMode)
         {
             PUIElements.ShowConfirmDialog(go, string.Format(ModUpdateDateStrings.
                                                             UI.MODUPDATER.SAFE_MODE, ModVersion.FILE_VERSION, ModVersion.
                                                             BUILD_VERSION), OnOpenGithub, null, ModUpdateDateStrings.UI.
                                           MODUPDATER.SAFE_MODE_GITHUB);
         }
         else if (ModUpdateInfo.Settings?.ShowMainMenuWarning == true)
         {
             go.AddOrGet <MainMenuWarning>();
         }
     }
 }
Ejemplo n.º 19
0
        private void ChangeTextFieldProbingRadius(GameObject _, string radius)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            int  newRadius;
            bool converted = int.TryParse(radius, out newRadius);

            if (converted)
            {
                this.ChangeProbingRadius(null, newRadius);
            }
            else if ((UnityEngine.Object) this.MoveSpeedText != (UnityEngine.Object)null)
            {
                PUIElements.SetText(this.ProbingRadiusText, this.configurator.ProbingRadius.ToString("0"));
            }
        }
Ejemplo n.º 20
0
        private void ChangeTextFieldMovespeed(GameObject _, string speed)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            float newSpeed;
            bool  converted = float.TryParse(speed, out newSpeed);

            if (converted)
            {
                this.ChangeMovespeed(null, newSpeed);
            }
            else if ((UnityEngine.Object) this.MoveSpeedText != (UnityEngine.Object)null)
            {
                PUIElements.SetText(this.MoveSpeedText, this.configurator.MoveSpeed.ToString("0.00"));
            }
        }
Ejemplo n.º 21
0
            /// <summary>
            /// Attempts to add a type to this category.
            /// </summary>
            /// <param name="element">The type to add.</param>
            /// <returns>true if it was added, or false if it already exists.</returns>
            public bool TryAddType(Tag element)
            {
                bool add = !children.ContainsKey(element);

                if (add)
                {
                    var child = new TypeSelectElement(this, element);
                    var cb    = child.CheckBox;
                    // Add the element to the list, then get its index and move it in the panel
                    // to maintain sorted order
                    children.Add(element, child);
                    PUIElements.SetParent(cb, ChildPanel);
                    if (PCheckBox.GetCheckState(cb) == PCheckBox.STATE_CHECKED)
                    {
                        // Set to checked
                        PCheckBox.SetCheckState(cb, PCheckBox.STATE_CHECKED);
                    }
                    cb.transform.SetSiblingIndex(children.IndexOfKey(element));
                }
                return(add);
            }
Ejemplo n.º 22
0
        public override GameObject Build()
        {
            var label = PUIElements.CreateUI(null, base.Name);

            text              = PTextComponent.TextChildHelper(label, PUITuning.Fonts.UILightStyle, ForcedExit.Options.RenderTime(System.DateTime.Now));
            tooltip           = EntityTemplateExtensions.AddOrGet <ToolTip>(label);
            tooltip.OnToolTip = OnToolTip;
            label.SetActive(true);
            var layout = label.AddComponent <RelativeLayoutGroup>();

            layout.Margin = new RectOffset(10, 10, 8, 8);
            ArrangeComponent(layout, text.gameObject, base.TextAlignment);
            if (!DynamicSize)
            {
                layout.LockLayout();
            }
            layout.flexibleWidth  = FlexSize.x;
            layout.flexibleHeight = FlexSize.y;
            DestroyLayoutIfPossible(label);
            InvokeRealize(label);
            return(label);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Checks the mod config class for the [RestartRequired] attribute, and brings up a
 /// restart dialog if necessary.
 /// </summary>
 private void CheckForRestart()
 {
     if (options != null)
     {
         string rr = typeof(RestartRequiredAttribute).FullName;
         bool   restartRequired = false;
         // Check for [RestartRequired]
         foreach (var attr in options.GetType().GetCustomAttributes(true))
         {
             if (attr.GetType().FullName == rr)
             {
                 restartRequired = true;
                 break;
             }
         }
         if (restartRequired)
         {
             // Prompt user to restart
             PUIElements.ShowConfirmDialog(null, PUIStrings.RESTART_REQUIRED,
                                           SaveAndRestart, null, PUIStrings.RESTART_OK, PUIStrings.
                                           RESTART_CANCEL);
         }
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Checks the autosave status on the UI thread.
        /// </summary>
        /// <returns>true if save completed, or false otherwise.</returns>
        public bool CheckSaveStatus()
        {
            var  status = this.status;
            bool done   = false;

            switch (status)
            {
            case SaveStatus.Done:
                done = true;
                break;

            case SaveStatus.Failed:
                // Generic error
                done = true;
                PUIElements.ShowMessageDialog(GameScreenManager.Instance.ssOverlayCanvas.
                                              gameObject, string.Format(STRINGS.UI.CRASHSCREEN.SAVEFAILED,
                                                                        "Autosave failed!"));
                break;

            case SaveStatus.IOError:
                // I/O error, raise a dialog
                done = true;
                PUIElements.ShowMessageDialog(GameScreenManager.Instance.ssOverlayCanvas.
                                              gameObject, string.Format(STRINGS.UI.CRASHSCREEN.SAVEFAILED,
                                                                        "IOException. You may not have enough free space!"));
                break;

            case SaveStatus.InProgress:
                break;

            default:
                // NotStarted, time to throw
                throw new InvalidOperationException("Save not started");
            }
            return(done);
        }
Ejemplo n.º 25
0
 private void OnModifyFailed()
 {
     PUIElements.ShowMessageDialog(parent, string.Format(UI.MODIFYFAILEDDIALOG.TEXT,
                                                         mod.label.title));
     Dispose();
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Shows a dialog when unsubscribing from a mod fails.
 /// </summary>
 private void OnUnsubFailed()
 {
     PUIElements.ShowMessageDialog(gameObject, UI.UNSUBFAILEDDIALOG.TEXT);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Shows the summary text once all mods get updated.
        /// </summary>
        internal void OnComplete()
        {
            bool errors = false, configFail = false;
            int  updated = 0, nominal = 0, n = 0;
            var  resultText = new StringBuilder(512);

            resultText.Append(ModUpdateDateStrings.UPDATE_HEADER);
            Results.Sort();
            foreach (var result in Results)
            {
                // Update cumulative status
                if (result.Status == ModDownloadStatus.ConfigError)
                {
                    configFail = true;
                    updated++;
                }
                else if (result.Status == ModDownloadStatus.OK)
                {
                    updated++;
                }
                else
                {
                    errors = true;
                }
                // Reduce clutter from no-config mods successfully updated
                if (result.Status == ModDownloadStatus.OK && result.ConfigsRestored == 0)
                {
                    nominal++;
                }
                else
                {
                    // Only add the maximum number of lines
                    if (n < ModUpdateDateStrings.MAX_LINES)
                    {
                        AddText(resultText, result);
                    }
                    n++;
                }
            }
            if (n > ModUpdateDateStrings.MAX_LINES)
            {
                // (and N more...)
                resultText.AppendFormat(ModUpdateDateStrings.CONFIRM_MORE, n -
                                        ModUpdateDateStrings.MAX_LINES);
            }
            if (nominal > 0)
            {
                if (Results.Count == 1)
                {
                    // Specify mod that was updated with no errors
                    resultText.AppendFormat(ModUpdateDateStrings.UPDATE_SINGLE, Results[0].
                                            Title);
                }
                else
                {
                    // N other mod(s) were updated with no errors
                    resultText.AppendFormat(nominal == 1 ? ModUpdateDateStrings.UPDATE_REST_1 :
                                            ModUpdateDateStrings.UPDATE_REST, nominal);
                }
            }
            if (updated > 0)
            {
                // Success text
                resultText.AppendFormat(ModUpdateDateStrings.UPDATE_FOOTER_OK, updated > 1 ?
                                        ModUpdateDateStrings.UPDATE_MULTIPLE : ModUpdateDateStrings.UPDATE_ONE);
            }
            if (errors)
            {
                // Error text
                resultText.Append(ModUpdateDateStrings.UPDATE_FOOTER_ERROR);
            }
            if (configFail)
            {
                // Config warning text
                resultText.Append(ModUpdateDateStrings.UPDATE_FOOTER_CONFIG);
            }
            PUIElements.ShowConfirmDialog(null, resultText.ToString(), SaveAndRestart,
                                          null, STRINGS.UI.FRONTEND.MOD_DIALOGS.RESTART.OK, STRINGS.UI.FRONTEND.
                                          MOD_DIALOGS.RESTART.CANCEL);
        }
        /// <summary>
        /// Updates the list of available elements.
        /// </summary>
        public void Update(GameObject target)
        {
            Target = target;
            Storage storage = Target.GetComponent <Storage>();

            if (storage.storageFilters == null || storage.storageFilters.Count < 1)
            {
                PUtil.LogError("If you're filtering, your storage filter should have the filters set on it");
                return;
            }

            HashSet <Tag> containedTags = ContainedTags();
            HashSet <Tag> goalTags      = new HashSet <Tag>(storage.storageFilters.Where(tag => WorldInventory.Instance.IsDiscovered(tag)));

            // if this is not supposed to display the exact same UI elements rebuild the entire UI
            // not the *most* performant way to handle things but trying to perform multiple insertions/deletions into this
            // row system is probably *less* performant
            if (!containedTags.SetEquals(goalTags))
            {
                // clear the UI
                foreach (var row in rows)
                {
                    // null the parent of the entity and disable it
                    foreach (var entity in row.entities)
                    {
                        PUIElements.SetParent(entity.CheckBox, null);
                        entity.CheckBox.SetActive(false);
                        entity.Parent = null;
                    }
                    // clear all the entities from this row
                    row.entities.Clear();
                    // do not null the parent of the row since it will be reused in same spot but do disable it
                    row.ChildPanel.SetActive(false);
                }

                // build the UI with tags in alphabetic order
                List <Tag> goalList = goalTags.ToList();
                goalList.Sort(TagAlphabetComparer.INSTANCE);
                int rowIndex = 0;
                foreach (Tag tag in goalList)
                {
                    // wrap around when rows are full
                    if (rowIndex < rows.Count && rows[rowIndex].RowSize >= PER_ROW)
                    {
                        rowIndex++;
                    }
                    // build new rows as needed
                    if (rows.Count <= rowIndex)
                    {
                        UncategorizedFilterableRow newRow = new UncategorizedFilterableRow(this);
                        rows.Add(newRow);
                        PUIElements.SetParent(newRow.ChildPanel, childPanel);
                        PUIElements.SetAnchors(newRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                    }
                    var row = rows[rowIndex];
                    row.ChildPanel.SetActive(true);
                    // build new entity for tag when it is first encountered
                    if (!entities.ContainsKey(tag))
                    {
                        UncategorizedFilterableEntity newEntity = new UncategorizedFilterableEntity(null, tag, tag.ProperName());
                        if (PCheckBox.GetCheckState(newEntity.CheckBox) == PCheckBox.STATE_CHECKED)
                        {
                            // Set to checked
                            PCheckBox.SetCheckState(newEntity.CheckBox, PCheckBox.STATE_CHECKED);
                        }
                        entities[tag] = newEntity;
                    }
                    var entity = entities[tag];
                    row.entities.Add(entity);
                    PUIElements.SetParent(entity.CheckBox, row.ChildPanel);
                    entity.CheckBox.SetActive(true);
                    entity.Parent = row;
                }
            }

            // with the right elements in the UI it is now necessary to set the properties for each entity correctly based on
            // if they are checked already and if they are present in the world
            UncategorizedFilterable filterable = Target.GetComponent <UncategorizedFilterable>();

            foreach (var row in rows)
            {
                foreach (var entity in row.entities)
                {
                    // set checkbox state
                    if (filterable.AcceptedTags.Contains(entity.ElementTag))
                    {
                        PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_CHECKED);
                    }
                    else
                    {
                        PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_UNCHECKED);
                    }
                    // set active state
                    var button = entity.CheckBox.GetComponentInChildren <KButton>();
                    button.isInteractable = WorldInventory.Instance.GetTotalAmount(entity.ElementTag) > 0.0;
                }
            }
            UpdateFromChildren();
        }
Ejemplo n.º 29
0
 private void OnModifyComplete()
 {
     PUIElements.ShowMessageDialog(parent, string.Format(UI.MODIFYDIALOG.SUCCESS,
                                                         mod.label.title));
     Dispose();
 }