예제 #1
0
        /// <summary>
        /// Adds the actions button to the row prefab to reconstruct it faster.
        /// </summary>
        /// <param name="rowPrefab">The prefab to modify.</param>
        internal static void ConfigureRowPrefab(GameObject rowPrefab)
        {
            var refs    = rowPrefab.AddOrGet <HierarchyReferences>();
            var newRefs = ListPool <ElementReference, ModDebugRegistry> .Allocate();

            // Create new button
            var buttonObj = new PButton(REF_MORE)
            {
                SpriteSize  = SPRITE_SIZE, Sprite = Assets.GetSprite("icon_gear"),
                DynamicSize = false
            }.SetKleiPinkStyle().AddTo(rowPrefab);

            // Add to references
            if (refs.references != null)
            {
                newRefs.AddRange(refs.references);
            }
            newRefs.Add(new ElementReference()
            {
                Name = REF_MORE, behaviour = buttonObj.GetComponent <KButton>()
            });
            refs.references = newRefs.ToArray();
            newRefs.Recycle();
            // Hide the Manage button
            var manage = refs.GetReference <KButton>("ManageButton");

            if (manage != null)
            {
                manage.gameObject.SetActive(false);
            }
        }
예제 #2
0
        protected override void OnPrefabInit()
        {
            var menu        = ToolMenu.Instance.toolParameterMenu;
            var baseContent = menu.content;

            base.OnPrefabInit();
            content = Util.KInstantiateUI(baseContent, baseContent.GetParent(), false);
            var transform = content.transform;

            // Add buttons to the chooser
            choiceList = transform.GetChild(1)?.gameObject;
            if (SandboxToolsPatches.AdvancedFilterEnabled)
            {
                // Selects all options
                var allButton = new PButton {
                    Text = "All", OnClick = (_) => SetAll(ToolParameterMenu.ToggleState.On)
                }.SetKleiPinkStyle();
                // Deselects all options
                var noneButton = new PButton {
                    Text = "None", OnClick = (_) => SetAll(ToolParameterMenu.ToggleState.Off)
                };
                new PRelativePanel {
                    BackColor = PUITuning.Colors.ButtonPinkStyle.inactiveColor
                }.AddChild(allButton).AddChild(noneButton).SetLeftEdge(allButton,
                                                                       fraction: 0.0f).SetRightEdge(allButton, fraction: 0.5f).SetLeftEdge(
                    noneButton, toRight: allButton).SetRightEdge(noneButton, fraction: 1.0f).
                AddTo(content, -1);
            }
            transform.SetAsFirstSibling();
            HideMenu();
        }
예제 #3
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");
                }
            }
        }
예제 #4
0
        private void Btn_Click(object sender, EventArgs e)
        {
            PButton btn = sender as PButton;

            this.LoadTableOrder(btn.TableID);
            CurrentTable        = TableRepo.FindBy(btn.TableID);
            lbCurrentTable.Text = CurrentTable.Name;
        }
예제 #5
0
        /// <summary>
        /// Fills in the mod info screen, assuming that infoAttr is non-null.
        /// </summary>
        /// <param name="dialog">The dialog to populate.</param>
        private void AddModInfoScreen(PDialog dialog)
        {
            string image = displayInfo.Image;
            var    body  = dialog.Body;

            // Try to load the mod image sprite if possible
            if (modImage == null && !string.IsNullOrEmpty(image))
            {
                string rootDir = PUtil.GetModPath(optionsType.Assembly);
                modImage = PUIUtils.LoadSpriteFile(rootDir == null ? image : Path.Combine(
                                                       rootDir, image));
            }
            var websiteButton = new PButton("ModSite")
            {
                Text    = PLibStrings.MOD_HOMEPAGE, ToolTip = PLibStrings.TOOLTIP_HOMEPAGE,
                OnClick = VisitModHomepage, Margin = PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle();
            var versionLabel = new PLabel("ModVersion")
            {
                Text      = displayInfo.Version, ToolTip = PLibStrings.TOOLTIP_VERSION,
                TextStyle = PUITuning.Fonts.UILightStyle, Margin = new RectOffset(0, 0,
                                                                                  OUTER_MARGIN, 0)
            };
            // Find mod URL
            string modURL = displayInfo.URL;

            if (modImage != null)
            {
                // 2 rows and 1 column
                if (optionCategories.Count > 0)
                {
                    body.Direction = PanelDirection.Horizontal;
                }
                var infoPanel = new PPanel("ModInfo")
                {
                    FlexSize  = Vector2.up, Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter
                }.AddChild(new PLabel("ModImage")
                {
                    SpriteSize = MOD_IMAGE_SIZE, TextAlignment = TextAnchor.UpperLeft,
                    Margin     = new RectOffset(0, OUTER_MARGIN, 0, OUTER_MARGIN),
                    Sprite     = modImage
                });
                if (!string.IsNullOrEmpty(modURL))
                {
                    infoPanel.AddChild(websiteButton);
                }
                body.AddChild(infoPanel.AddChild(versionLabel));
            }
            else
            {
                if (!string.IsNullOrEmpty(modURL))
                {
                    body.AddChild(websiteButton);
                }
                body.AddChild(versionLabel);
            }
        }
예제 #6
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;
        }
예제 #7
0
        /// <summary>
        /// Adds a tooltip to a Steam mod showing its update status.
        /// </summary>
        /// <param name="tooltip">The tooltip under construction.</param>
        /// <param name="modUpdate">The mod update executor which can update this mod.</param>
        /// <param name="localDate">The local last update date.</param>
        /// <param name="updButton">The button to be used for updating this mod.</param>
        /// <returns>The status of the Steam mod.</returns>
        private static ModStatus AddSteamUpdate(StringBuilder tooltip, ModToUpdate modUpdate,
                                                System.DateTime localDate, PButton updButton)
        {
            var steamDate = modUpdate.LastSteamUpdate;
            var updated   = ModStatus.Disabled;

            if (steamDate > System.DateTime.MinValue)
            {
                // Generate tooltip for mod's current date and last Steam update
                var ours       = ModUpdateInfo.FindModInConfig(modUpdate.SteamID.m_PublishedFileId);
                var ourDate    = System.DateTime.MinValue;
                var globalDate = modUpdate.LastSteamUpdate;
                // Do we have a better estimate?
                if (ours != null)
                {
                    ourDate = new System.DateTime(ours.LastUpdated, DateTimeKind.Utc);
                }
                // Allow some time for download delays etc
                if (localDate.AddMinutes(UPDATE_JITTER) >= globalDate)
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_UPDATED);
                    updated = ModStatus.UpToDate;
                }
                else if (ourDate.AddMinutes(UPDATE_JITTER) >= globalDate)
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_UPDATED_BYUS);
                    localDate = ourDate;
                    updated   = ModStatus.UpToDateLocal;
                }
                else
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_OUTDATED);
                    updated = ModStatus.Outdated;
                }
                // AppendLine appends platform specific separator
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.LOCAL_UPDATE, localDate.
                                     ToLocalTime());
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.STEAM_UPDATE, globalDate.
                                     ToLocalTime());
                updButton.OnClick = new ModUpdateTask(modUpdate).TryUpdateMods;
            }
            else
            {
                // Steam update could not be determined
                tooltip.AppendFormat(ModUpdateDateStrings.LOCAL_UPDATE, localDate.
                                     ToLocalTime());
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.STEAM_UPDATE_UNKNOWN);
            }
            return(updated);
        }
예제 #8
0
        /// <summary>
        /// Makes a button with the specified name, icon, and action.
        /// </summary>
        /// <param name="name">The button name.</param>
        /// <param name="tooltip">The button tool tip.</param>
        /// <param name="sprite">The button sprite.</param>
        /// <param name="action">The method to invoke on click.</param>
        /// <param name="onRealize">The method to invoke on realize.</param>
        /// <returns>A button with that icon.</returns>
        private PButton MakeButton(string name, string tooltip, Sprite sprite, PUIDelegates.
                                   OnButtonPressed action, PUIDelegates.OnRealize onRealize)
        {
            var button = new PButton(name)
            {
                SpriteSize = ModDialogs.SPRITE_SIZE, Sprite = sprite, DynamicSize = false,
                OnClick    = action, ToolTip = tooltip, Margin = DebugUtils.BUTTON_MARGIN
            }.SetKleiPinkStyle();

            button.OnRealize += onRealize;
            return(button);
        }
예제 #9
0
        private PButton createButton(Table table)
        {
            PButton btn = new PButton();

            btn.Text    = table.Name.Trim();
            btn.TableID = table.Id;
            btn.Order   = OrderRepo.FindByTable(table.Id);
            btn.Visible = true;
            btn.Left    = 20;
            btn.Click  += Btn_Click;

            return(btn);
        }
예제 #10
0
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="modEntry">The entry in the mod menu.</param>
        /// <param name="outdated">The mods which are out of date.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                Traverse modEntry)
        {
            int index       = modEntry.GetField <int>("mod_index");
            var rowInstance = modEntry.GetField <RectTransform>("rect_transform")?.gameObject;
            var mods        = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 3), updated != ModStatus.
                                         Disabled);
            }
        }
예제 #11
0
        public NotepadControl()
        {
            descriptionField = DescriptionArea();

            // this button does nothing but it enable to deselect the textarea and to valide the input without closing the sidescreen
            PButton validationButton = new PButton("button")
            {
                Sprite     = PUITuning.Images.Checked,
                SpriteSize = new Vector2(25, 30),
            };

            PLabel descriptionLabel = new PLabel("description label")
            {
                Text          = "Description",
                TextAlignment = TextAnchor.MiddleCenter,
            };


            PPanel panel = new PPanel("Text panel")
            {
                Direction = PanelDirection.Vertical,
                Alignment = TextAnchor.UpperLeft,
                Spacing   = ROW_SPACING,
                FlexSize  = Vector2.one,
            };

            panel.AddChild(descriptionLabel);
            panel.AddChild(descriptionField);
            panel.AddChild(validationButton);


            PPanel root = new PPanel("NotepadSideScreen")
            {
                Direction = PanelDirection.Vertical,
                Margin    = OUTER_MARGIN,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 0,
                BackColor = PUITuning.Colors.BackgroundLight,
                FlexSize  = Vector2.one,
            };

            root.AddChild(panel);
            RootPanel = root.SetKleiBlueColor().Build();
        }
예제 #12
0
        /// <summary>
        /// Adds a tooltip to a Steam mod showing its update status.
        /// </summary>
        /// <param name="tooltip">The tooltip under construction.</param>
        /// <param name="modUpdate">The mod update executor which can update this mod.</param>
        /// <param name="localDate">The local last update date.</param>
        /// <param name="updButton">The button to be used for updating this mod.</param>
        /// <param name="autoUpdate">Whether automatic updates are enabled.</param>
        /// <returns>The status of the Steam mod.</returns>
        private static ModStatus AddSteamUpdate(StringBuilder tooltip, ModToUpdate modUpdate,
                                                System.DateTime localDate, PButton updButton, bool autoUpdate)
        {
            var steamDate = modUpdate.LastSteamUpdate;
            var updated   = GetModStatus(modUpdate, ref localDate);

            // Generate tooltip for mod's current date and last Steam update
            switch (updated)
            {
            case ModStatus.UpToDate:
                tooltip.Append(UISTRINGS.MOD_UPDATED);
                break;

            case ModStatus.UpToDateLocal:
                tooltip.Append(UISTRINGS.MOD_UPDATED_BYUS);
                break;

            case ModStatus.Outdated:
                tooltip.Append(autoUpdate ? UISTRINGS.MOD_ERR_UPDATE : UISTRINGS.MOD_OUTDATED);
                break;

            default:
                break;
            }
            // AppendLine appends platform specific separator
            tooltip.Append("\n");
            tooltip.AppendFormat(cultureInfo, UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime());
            tooltip.Append("\n");
            if (updated == ModStatus.Disabled)
            {
                tooltip.AppendFormat(UISTRINGS.STEAM_UPDATE_UNKNOWN);
            }
            else
            {
                tooltip.AppendFormat(cultureInfo, UISTRINGS.STEAM_UPDATE, steamDate.
                                     ToLocalTime());
                updButton.OnClick = new ModUpdateTask(modUpdate).TryUpdateMods;
            }
            return(updated);
        }
예제 #13
0
        public GH_Project_Attributes(GH_Project_Component owner) : base(owner)
        {
            _checkboxPanelHeight = 2 * CHECKBOXHEIGHT + 3 * CHECKBOXPANELPADDING;
            _buttonPanelHeight   = BUTTONSIZE + 2 * BUTTONPANELPADDING;

            _topLabelString      = owner.Name;
            _topLabelStringWidth = GH_FontServer.StringWidth(_topLabelString, GH_FontServer.LargeAdjusted);

            _calcBtn = new PButton("Calculate", owner.PrepareCalculation);

            _cbStream           = new PCheckBox("Stream dat", owner.ToggleStream, owner.StreamContent);
            _cbSilent           = new PCheckBox("Silent calculation", owner.ToggleSilent, owner.SilentCalc);
            _cbStream.IsEnabled = true;
            _cbSilent.IsEnabled = true;

            _btnOpenExplorer = new PButton(owner.IconOpenExplorer, owner.OpenPath);
            _btnTeddy        = new PButton(owner.IconTeddy, owner.OpenTeddy);
            _btnAnimator     = new PButton(owner.IconAnimator, owner.OpenAnimator);
            _btnGraphic      = new PButton(owner.IconGraphic, owner.OpenGraphic);
            _btnResult       = new PButton(owner.IconResult, owner.OpenResult);
            _btnReport       = new PButton(owner.IconReport, owner.OpenReport);
        }
예제 #14
0
        protected override void OnPrefabInit()
        {
            base.OnPrefabInit();

            GameObject baseContent         = ToolMenu.Instance.toolParameterMenu.content;
            GameObject baseWidgetContainer = ToolMenu.Instance.toolParameterMenu.widgetContainer;

            content = Util.KInstantiateUI(baseContent, baseContent.transform.parent.gameObject);
            content.transform.GetChild(1).gameObject.SetActive(false);

            var buttonsPanel = new PRelativePanel {
                BackColor = PUITuning.Colors.ButtonPinkStyle.inactiveColor
            };

            var allButton = new PButton
            {
                Text    = "All",
                OnClick = (_) => SetAll(ToolParameterMenu.ToggleState.On)
            }.SetKleiPinkStyle();

            var noneButton = new PButton {
                Text = "None"
            };

            noneButton.OnClick += source => {
                Instance.SetAll(ToolParameterMenu.ToggleState.Off);
            };

            PCheckBox syncCheckBox = new PCheckBox {
                Text = "Auto. Sync"
            };

            syncCheckBox.SetKleiPinkStyle();
            syncCheckBox.OnRealize += realized => {
                syncMultiToggle = realized.GetComponent <MultiToggle>();
            };
            syncCheckBox.OnChecked += (source, state) => {
                if (state == PCheckBox.STATE_UNCHECKED)
                {
                    syncMultiToggle.ChangeState(PCheckBox.STATE_CHECKED);
                }

                else if (state == PCheckBox.STATE_CHECKED)
                {
                    syncMultiToggle.ChangeState(PCheckBox.STATE_UNCHECKED);
                }

                OnSyncChanged?.Invoke(syncMultiToggle.CurrentState == PCheckBox.STATE_CHECKED);
            };

            buttonsPanel.AddChild(allButton);
            buttonsPanel.SetLeftEdge(allButton, 0)
            .SetRightEdge(allButton, 0.25F);

            buttonsPanel.AddChild(noneButton);
            buttonsPanel.SetLeftEdge(noneButton, 0.25F)
            .SetRightEdge(noneButton, 0.5F);

            buttonsPanel.AddChild(syncCheckBox);
            buttonsPanel.SetLeftEdge(syncCheckBox, 0.5F)
            .SetRightEdge(syncCheckBox, 1F);

            widgetContainer = Util.KInstantiateUI(baseWidgetContainer, content, true);
            buttonsPanel.AddTo(content, 3);

            content.SetActive(false);
        }
예제 #15
0
        protected override void OnPrefabInit()
        {
            Color      backColour = new Color(0.998f, 0.998f, 0.998f);
            RectOffset rectOffset = new RectOffset(8, 8, 8, 8);

            PPanel moveTitle_panel = new PPanel("MovespeedTitleRow");

            moveTitle_panel.BackColor = backColour;
            moveTitle_panel.Alignment = TextAnchor.MiddleCenter;
            moveTitle_panel.Direction = PanelDirection.Horizontal;
            moveTitle_panel.Spacing   = 10;
            moveTitle_panel.Margin    = rectOffset;
            moveTitle_panel.FlexSize  = Vector2.right;
            PLabel moveTitle_label = new PLabel("MovespeedTitleLabel");

            moveTitle_label.TextAlignment = TextAnchor.MiddleRight;
            moveTitle_label.Text          = SweepyStrings.MoveSpeedTitleName;
            moveTitle_label.ToolTip       = SweepyStrings.MoveSpeedTitleTooltip;
            moveTitle_label.TextStyle     = PUITuning.Fonts.TextDarkStyle;
            PTextField moveTitle_textField = new PTextField("MovespeedSliderTextField")
            {
                Text      = SweepyConfigChecker.BaseMovementSpeed.ToString("0.00"),
                MaxLength = 10,
            };

            moveTitle_textField.OnTextChanged = this.ChangeTextFieldMovespeed;
            moveTitle_textField.OnRealize    += (PUIDelegates.OnRealize)(obj => this.MoveSpeedText = obj);

            PPanel moveTitle_components = moveTitle_panel.AddChild((IUIComponent)moveTitle_label);

            moveTitle_components = moveTitle_panel.AddChild((IUIComponent)moveTitle_textField);
            moveTitle_components.AddTo(this.gameObject, -2);

            PPanel moveSlider_panel = new PPanel("MovespeedSliderRow");

            moveSlider_panel.BackColor = backColour;
            moveSlider_panel.ImageMode = Image.Type.Sliced;
            moveSlider_panel.Alignment = TextAnchor.MiddleCenter;
            moveSlider_panel.Direction = PanelDirection.Horizontal;
            moveSlider_panel.Spacing   = 10;
            moveSlider_panel.Margin    = new RectOffset(8, 8, 6, 32);
            moveSlider_panel.FlexSize  = Vector2.right;

            PLabel moveSliderMin_label = new PLabel("MovespeedSliderMinLabel");

            moveSliderMin_label.Text      = Mathf.RoundToInt(SweepyConfigChecker.MinSpeedSliderValue).ToString();
            moveSliderMin_label.TextStyle = PUITuning.Fonts.TextDarkStyle;

            PPanel moveSlider_components = moveSlider_panel.AddChild((IUIComponent)moveSliderMin_label);

            PSliderSingle moveSpeedSlider = new PSliderSingle("Movespeed")
            {
                Direction       = Slider.Direction.LeftToRight,
                HandleColor     = PUITuning.Colors.ButtonPinkStyle,
                HandleSize      = 16.0f,
                InitialValue    = SweepyConfigChecker.BaseMovementSpeed,
                IntegersOnly    = false,
                MaxValue        = SweepyConfigChecker.MaxSpeedSliderValue,
                MinValue        = SweepyConfigChecker.MinSpeedSliderValue,
                PreferredLength = 140.0f,
                TrackSize       = 16.0f,
            };

            moveSpeedSlider.OnRealize     += (PUIDelegates.OnRealize)(obj => this.MoveSpeedSlider = obj);
            moveSpeedSlider.OnValueChanged = ChangeMovespeed;
            moveSlider_components.AddChild(moveSpeedSlider);

            PLabel moveSliderMax_label = new PLabel("MovespeedSliderMaxLabel");

            moveSliderMax_label.Text      = Mathf.RoundToInt(SweepyConfigChecker.MaxSpeedSliderValue).ToString();
            moveSliderMax_label.TextStyle = PUITuning.Fonts.TextDarkStyle;
            moveSlider_components.AddChild(moveSliderMax_label);

            moveSlider_components.AddTo(this.gameObject, -2);



            PPanel probingTitle_panel = new PPanel("ProbingRadiusTitleRow");

            probingTitle_panel.BackColor = backColour;
            probingTitle_panel.Alignment = TextAnchor.MiddleCenter;
            probingTitle_panel.Direction = PanelDirection.Horizontal;
            probingTitle_panel.Spacing   = 10;
            probingTitle_panel.Margin    = rectOffset;
            probingTitle_panel.FlexSize  = Vector2.right;
            PLabel probingTitle_label = new PLabel("ProbingRadiusTitleLabel");

            probingTitle_label.TextAlignment = TextAnchor.MiddleRight;
            probingTitle_label.Text          = SweepyStrings.ProbingRadiusTitleName;
            probingTitle_label.ToolTip       = SweepyStrings.ProbingRadiusTitleTooltip;
            probingTitle_label.TextStyle     = PUITuning.Fonts.TextDarkStyle;
            PTextField probingTitle_TextField = new PTextField("ProbingSliderTextField")
            {
                Text      = SweepyConfigChecker.BaseProbingRadius.ToString("0"),
                MaxLength = 8,
            };

            probingTitle_TextField.OnTextChanged = this.ChangeTextFieldProbingRadius;
            probingTitle_TextField.OnRealize    += (PUIDelegates.OnRealize)(obj => this.ProbingRadiusText = obj);

            PPanel probingTitle_components = probingTitle_panel.AddChild((IUIComponent)probingTitle_label);

            probingTitle_components = probingTitle_panel.AddChild((IUIComponent)probingTitle_TextField);
            probingTitle_components.AddTo(this.gameObject, -2);

            PPanel probingSlider_panel = new PPanel("ProbingRadiusSliderRow");

            probingSlider_panel.BackColor = backColour;
            probingSlider_panel.ImageMode = Image.Type.Sliced;
            probingSlider_panel.Alignment = TextAnchor.MiddleCenter;
            probingSlider_panel.Direction = PanelDirection.Horizontal;
            probingSlider_panel.Spacing   = 10;
            probingSlider_panel.Margin    = new RectOffset(8, 8, 6, 32);
            probingSlider_panel.FlexSize  = Vector2.right;

            PLabel probingSliderMin_label = new PLabel("ProbingSliderMinLabel");

            probingSliderMin_label.Text      = Mathf.RoundToInt(SweepyConfigChecker.MinProbingSliderValue).ToString();
            probingSliderMin_label.TextStyle = PUITuning.Fonts.TextDarkStyle;

            PPanel probingSlider_components = probingSlider_panel.AddChild((IUIComponent)probingSliderMin_label);

            PSliderSingle probingSpeedSlider = new PSliderSingle("Probing Radius")
            {
                Direction       = Slider.Direction.LeftToRight,
                HandleColor     = PUITuning.Colors.ButtonPinkStyle,
                HandleSize      = 16.0f,
                InitialValue    = SweepyConfigChecker.BaseProbingRadius,
                IntegersOnly    = true,
                MaxValue        = SweepyConfigChecker.MaxProbingSliderValue,
                MinValue        = SweepyConfigChecker.MinProbingSliderValue,
                PreferredLength = 140.0f,
                TrackSize       = 16.0f,
            };

            probingSpeedSlider.OnRealize     += (PUIDelegates.OnRealize)(obj => this.ProbingRadiusSlider = obj);
            probingSpeedSlider.OnValueChanged = ChangeProbingRadius;
            probingSlider_components.AddChild(probingSpeedSlider);

            PLabel probingSliderMax_label = new PLabel("ProbingSliderMaxLabel");

            probingSliderMax_label.Text      = Mathf.RoundToInt(SweepyConfigChecker.MaxProbingSliderValue).ToString();
            probingSliderMax_label.TextStyle = PUITuning.Fonts.TextDarkStyle;
            probingSlider_components.AddChild(probingSliderMax_label);

            probingSlider_components.AddTo(this.gameObject, -2);



            PPanel bottomRow_panel = new PPanel("BottomRow");

            bottomRow_panel.BackColor = backColour;
            bottomRow_panel.Alignment = TextAnchor.MiddleCenter;
            bottomRow_panel.Direction = PanelDirection.Horizontal;
            bottomRow_panel.Margin    = rectOffset;
            bottomRow_panel.Spacing   = 10;

            PButton findButton = new PButton();

            findButton.Color      = PUITuning.Colors.ButtonBlueStyle;
            findButton.Margin     = new RectOffset(16, 16, 8, 8);
            findButton.TextStyle  = PUITuning.Fonts.TextLightStyle;
            findButton.OnClick    = new PUIDelegates.OnButtonPressed(this.FindSweepyBot);
            findButton.Text       = SweepyStrings.FindSweepyButtonText;
            findButton.ToolTip    = SweepyStrings.FindSweepyButtonTooltip;
            findButton.OnRealize += (PUIDelegates.OnRealize)(obj => this.FindSweepyButton = obj);

            PButton resetButton = new PButton();

            resetButton.Color      = PUITuning.Colors.ButtonBlueStyle;
            resetButton.Margin     = new RectOffset(16, 16, 8, 8);
            resetButton.TextStyle  = PUITuning.Fonts.TextLightStyle;
            resetButton.OnClick    = new PUIDelegates.OnButtonPressed(this.ResetSweepyBot);
            resetButton.Text       = SweepyStrings.ResetSweepyButtonText;
            resetButton.ToolTip    = SweepyStrings.ResetSweepyButtonTooltip;
            resetButton.OnRealize += (PUIDelegates.OnRealize)(obj => this.ResetSweepyButton = obj);

            bottomRow_panel.AddChild(findButton);
            bottomRow_panel.AddChild(resetButton);
            bottomRow_panel.AddTo(this.gameObject, -2);


            this.ContentContainer = this.gameObject;
            base.OnPrefabInit();
            this.SetTarget(this.target.gameObject);
        }
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="outdated">The mods which are out of date.</param>
        /// <param name="modEntry">The entry in the mod menu.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                object modEntry)
        {
            int index    = -1;
            var type     = modEntry.GetType();
            var indexVal = type.GetFieldSafe("mod_index", false)?.GetValue(modEntry);

            if (indexVal is int intVal)
            {
                index = intVal;
            }
            var rowInstance = (type.GetFieldSafe("rect_transform", false)?.GetValue(
                                   modEntry) as RectTransform)?.gameObject;
            var mods = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                // Format DateTime to the current Klei culture (otherwise it uses
                // CurrentCulture which defaults to the Steam culture)
                if (cultureInfo == null)
                {
                    var langCode = Localization.GetLocale()?.Code;
                    if (string.IsNullOrEmpty(langCode))
                    {
                        langCode = Localization.GetCurrentLanguageCode();
                    }
                    if (string.IsNullOrEmpty(langCode))
                    {
                        cultureInfo = CultureInfo.CurrentCulture;
                    }
                    else
                    {
                        cultureInfo = new CultureInfo(langCode);
                    }
                }
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(cultureInfo, UISTRINGS.LOCAL_UPDATE, localDate.
                                         ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 4), updated != ModStatus.
                                         Disabled);
            }
        }
예제 #17
0
        private void BuildPanel()
        {
            if (ContentContainer != null)
            {
                Destroy(ContentContainer);
                ContentContainer = null;
            }

            var margin     = new RectOffset(8, 8, 8, 8);
            var baseLayout = gameObject.GetComponent <BoxLayoutGroup>();

            if (baseLayout != null)
            {
                baseLayout.Params = new BoxLayoutParams()
                {
                    Margin    = margin,
                    Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter,
                    Spacing   = 8
                };
            }

            var mainPanel = new PPanel();

            var mainRow = new PPanel("Toggle Lock")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            var lockBtn = new PButton("LockButton")
            {
                Text = "Lock"
            };

            lockBtn.SetKleiBlueStyle();
            lockBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Locked);
            };

            var unlockBtn = new PButton("UnlockButton")
            {
                Text = "Auto"
            };

            unlockBtn.SetKleiBlueStyle();
            unlockBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Auto);
            };

            var openBtn = new PButton("OpenButton")
            {
                Text = "Open"
            };

            openBtn.SetKleiBlueStyle();
            openBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Open);
            };

            mainRow.AddChild(lockBtn);
            mainRow.AddChild(unlockBtn);
            mainRow.AddChild(openBtn);
            mainPanel.AddChild(mainRow);
            ContentContainer = mainPanel.Build();
            ContentContainer.SetParent(gameObject);
        }