Beispiel #1
0
        /// <summary>
        /// Called by the game when level loading is complete.
        /// </summary>
        /// <param name="mode">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnLevelLoaded(LoadMode mode)
        {
            // Check to see that Harmony 2 was properly loaded.
            if (!harmonyLoaded)
            {
                // Harmony 2 wasn't loaded; display warning notification and exit.
                ListMessageBox harmonyBox = MessageBoxBase.ShowModal <ListMessageBox>();

                // Key text items.
                harmonyBox.AddParas(Translations.Translate("ERR_HAR0"), Translations.Translate("ABLC_ERR_HAR"), Translations.Translate("ABLC_ERR_FAT"), Translations.Translate("ERR_HAR1"));

                // List of dot points.
                harmonyBox.AddList(Translations.Translate("ERR_HAR2"), Translations.Translate("ERR_HAR3"));

                // Closing para.
                harmonyBox.AddParas(Translations.Translate("MES_PAGE"));

                // Exit.
                return;
            }

            // Check to see if a conflicting mod has been detected.
            if (conflictingMod)
            {
                // Mod conflict detected - display warning notification and exit.
                ListMessageBox modConflictBox = MessageBoxBase.ShowModal <ListMessageBox>();

                // Key text items.
                modConflictBox.AddParas(Translations.Translate("ERR_CON0"), Translations.Translate("ABLC_ERR_FAT"), Translations.Translate("ABLC_ERR_CON0"), Translations.Translate("ERR_CON1"));

                // Add conflicting mod name(s).
                modConflictBox.AddList(ModUtils.conflictingModNames.ToArray());

                // Closing para.
                modConflictBox.AddParas(Translations.Translate("ABLC_ERR_CON1"));

                // Exit.
                return;
            }

            // Load mod if it's enabled.
            if (isModEnabled)
            {
                // Check for Ploppable RICO Revisited.
                ModUtils.RICOReflection();

                // Hook info panel events.
                DistrictPanelManager.Hook();
                BuildingPanelManager.Hook();

                // Add building info panel button.
                BuildingPanelManager.AddInfoPanelButton();
            }
        }
        /// <summary>
        /// Handles a change in target building from the WorldInfoPanel.
        /// Sets the panel button state according to whether or not this building is 'levellable' and communicates changes to the ABLC panel.
        /// </summary>
        internal static void TargetChanged()
        {
            // Get current WorldInfoPanel building instance and determine maximum building level.
            if (LevelUtils.GetMaxLevel(WorldInfoPanel.GetCurrentInstanceID().Building) == 1)
            {
                // Only one building level - not a 'levellable' building, so disable the ABLC button and update the tooltip accordingly.
                panelButton.Disable();
                panelButton.tooltip = Translations.Translate("ABLC_BUT_DIS");
            }
            else
            {
                // Multiple levels available - enable the ABLC button and update the tooltip accordingly.
                panelButton.Enable();
                panelButton.tooltip = Translations.Translate("ABLC_NAME");
            }

            // Communicate target change to the panel (if it's currently instantiated).
            Panel?.BuildingChanged();
        }
Beispiel #3
0
        /// <summary>
        /// Called by the game when the mod options panel is setup.
        /// </summary>
        public void OnSettingsUI(UIHelperBase helper)
        {
            // Language options.
            UIHelperBase languageGroup    = helper.AddGroup(Translations.Translate("TRN_CHOICE"));
            UIDropDown   languageDropDown = (UIDropDown)languageGroup.AddDropdown(Translations.Translate("TRN_CHOICE"), Translations.LanguageList, Translations.Index, (value) => { Translations.Index = value; ABLCSettingsFile.SaveSettings(); });

            languageDropDown.autoSize = false;
            languageDropDown.width    = 270f;

            // Panel options.
            UIHelperBase panelGroup     = helper.AddGroup(Translations.Translate("ABLC_OPT_PNL"));
            UICheckBox   onRightCheck   = (UICheckBox)panelGroup.AddCheckbox(Translations.Translate("ABLC_OPT_RT"), ModSettings.onRight, (value) => { ModSettings.onRight = value; ABLCSettingsFile.SaveSettings(); });
            UICheckBox   showPanelCheck = (UICheckBox)panelGroup.AddCheckbox(Translations.Translate("ABLC_OPT_SHO"), ModSettings.showPanel, (value) => { ModSettings.showPanel = value; ABLCSettingsFile.SaveSettings(); });

            // Gameplay options.
            UIHelperBase gameGroup        = helper.AddGroup(Translations.Translate("ABLC_OPT_PLY"));
            UICheckBox   abandonHistCheck = (UICheckBox)gameGroup.AddCheckbox(Translations.Translate("ABLC_OPT_HNA"), ModSettings.noAbandonHistorical, (value) => { ModSettings.noAbandonHistorical = value; ABLCSettingsFile.SaveSettings(); });
            UICheckBox   abandonAnyCheck  = (UICheckBox)gameGroup.AddCheckbox(Translations.Translate("ABLC_OPT_ANA"), ModSettings.noAbandonAny, (value) => { ModSettings.noAbandonAny = value; if (value)
                                                                                                                                                             {
                                                                                                                                                                 abandonHistCheck.isChecked = true;
                                                                                                                                                             }
                                                                                                                                                             ABLCSettingsFile.SaveSettings(); });
            UICheckBox loadLevelCheck = (UICheckBox)gameGroup.AddCheckbox(Translations.Translate("ABLC_OPT_CLL"), ModSettings.loadLevelCheck, (value) => { ModSettings.loadLevelCheck = value; ABLCSettingsFile.SaveSettings(); });
        }
        /// <summary>
        /// Adds an ABLC button to a building info panel to open the ABLC panel for that building.
        /// The button will be added to the right of the panel with a small margin from the panel edge, at the relative Y position specified.
        /// </summary>
        internal static void AddInfoPanelButton()
        {
            BuildingWorldInfoPanel infoPanel = UIView.library.Get <ZonedBuildingWorldInfoPanel>(typeof(ZonedBuildingWorldInfoPanel).Name);

            panelButton = infoPanel.component.AddUIComponent <UIButton>();

            // Basic button setup.
            panelButton.atlas            = Textures.ABLCButtonSprites;
            panelButton.size             = new Vector2(36, 36);
            panelButton.normalFgSprite   = "normal";
            panelButton.focusedFgSprite  = "hovered";
            panelButton.hoveredFgSprite  = "hovered";
            panelButton.pressedFgSprite  = "pressed";
            panelButton.disabledFgSprite = "disabled";
            panelButton.name             = "ABLCbutton";
            panelButton.tooltip          = Translations.Translate("ABLC_NAME");

            // Find ProblemsPanel relative position to position button.
            // We'll use 40f as a default relative Y in case something doesn't work.
            UIComponent problemsPanel;
            float       relativeY = 40f;

            // Player info panels have wrappers, zoned ones don't.
            UIComponent wrapper = infoPanel.Find("Wrapper");

            if (wrapper == null)
            {
                problemsPanel = infoPanel.Find("ProblemsPanel");
            }
            else
            {
                problemsPanel = wrapper.Find("ProblemsPanel");
            }

            try
            {
                // Position button vertically in the middle of the problems panel.  If wrapper panel exists, we need to add its offset as well.
                relativeY = (wrapper == null ? 0 : wrapper.relativePosition.y) + problemsPanel.relativePosition.y + ((problemsPanel.height - 36) / 2);
            }
            catch
            {
                // Don't really care; just use default relative Y.
                Logging.Message("couldn't find ProblemsPanel relative position");
            }

            // Set position.
            panelButton.AlignTo(infoPanel.component, UIAlignAnchor.TopRight);
            panelButton.relativePosition += new Vector3(-62f, relativeY, 0f);

            // Event handler.
            panelButton.eventClick += (control, clickEvent) =>
            {
                // Toggle panel visibility.
                if (uiGameObject == null)
                {
                    Create();
                }
                else
                {
                    Close();
                }

                // Manually unfocus control, otherwise it can stay focused until next UI event (looks untidy).
                control.Unfocus();
            };
        }
Beispiel #5
0
        /// <summary>
        /// Performs initial setup for the panel; we don't use Start() as that's not sufficiently reliable (race conditions), and is not needed with the dynamic create/destroy process.
        /// </summary>
        internal override void Setup(Transform parentTransform)
        {
            try
            {
                base.Setup(parentTransform);

                // Extend height and add 'clear all building settings' button.
                height += 40f;
                UIButton clearBuildingsButton = UIControls.AddButton(this, Margin, height - 40f, Translations.Translate("ABLC_CLR_BLD"), this.width - (Margin * 2), tooltip: Translations.Translate("ABLC_CLR_BLD_TIP"));
                clearBuildingsButton.eventClicked += ClearBuildings;

                // Add category labels.
                UILabel resLabel  = AddLabel(Translations.Translate("ABLC_CAT_RES"), Margin, 50f, hAlign: UIHorizontalAlignment.Left);
                UILabel workLabel = AddLabel(Translations.Translate("ABLC_CAT_WRK"), Margin, 140f, hAlign: UIHorizontalAlignment.Left);

                // Add workplace min and max dropdowns.
                minWorkLevelDropDown       = UIControls.AddLabelledDropDown(this, width - Margin - MenuWidth, 160f, Translations.Translate("ABLC_LVL_MIN"), 60f, accomodateLabel: false, tooltip: Translations.Translate("ABLC_CAT_WMN_TIP"));
                minWorkLevelDropDown.items = new string[] { "1", "2", "3" };

                maxWorkLevelDropDown       = UIControls.AddLabelledDropDown(this, width - Margin - MenuWidth, 190f, Translations.Translate("ABLC_LVL_MAX"), 60f, accomodateLabel: false, tooltip: Translations.Translate("ABLC_CAT_WMX_TIP"));
                maxWorkLevelDropDown.items = new string[] { "1", "2", "3" };

                // Add random level checkbox.
                randomSpawnCheck = UIControls.LabelledCheckBox(this, 20f, 235f, Translations.Translate("ABLC_RAN_SPN"), tooltip: Translations.Translate("ABLC_RAN_SPN_TIP"));

                // Set initial district.
                DistrictChanged();

                // Add event handlers.

                minLevelDropDown.eventSelectedIndexChanged += (control, index) =>
                {
                    // Don't do anything if events are disabled.
                    if (!disableEvents)
                    {
                        DistrictsABLC.minResLevel[targetID] = (byte)index;

                        // If the minimum level is now greater than the maximum level, increase the maximum to match the minimum.
                        if (index > maxLevelDropDown.selectedIndex)
                        {
                            maxLevelDropDown.selectedIndex = index;
                        }
                    }
                };

                maxLevelDropDown.eventSelectedIndexChanged += (control, index) =>
                {
                    // Don't do anything if events are disabled.
                    if (!disableEvents)
                    {
                        DistrictsABLC.maxResLevel[targetID] = (byte)index;

                        // If the maximum level is now less than the minimum level, reduce the minimum to match the maximum.
                        if (index < minLevelDropDown.selectedIndex)
                        {
                            minLevelDropDown.selectedIndex = index;
                        }
                    }
                };

                minWorkLevelDropDown.eventSelectedIndexChanged += (control, index) =>
                {
                    // Don't do anything if events are disabled.
                    if (!disableEvents)
                    {
                        DistrictsABLC.minWorkLevel[targetID] = (byte)index;

                        // If the minimum level is now greater than the maximum level, increase the maximum to match the minimum.
                        if (index > maxWorkLevelDropDown.selectedIndex)
                        {
                            maxWorkLevelDropDown.selectedIndex = index;
                        }
                    }
                };

                maxWorkLevelDropDown.eventSelectedIndexChanged += (control, index) =>
                {
                    // Don't do anything if events are disabled.
                    if (!disableEvents)
                    {
                        DistrictsABLC.maxWorkLevel[targetID] = (byte)index;

                        // If the maximum level is now less than the minimum level, reduce the minimum to match the maximum.
                        if (index < minWorkLevelDropDown.selectedIndex)
                        {
                            minWorkLevelDropDown.selectedIndex = index;
                        }
                    }
                };

                randomSpawnCheck.eventCheckChanged += (control, isChecked) =>
                {
                    // Don't do anything if events are disabled.
                    if (!disableEvents)
                    {
                        // XOR relevant flag to toggle.
                        DistrictsABLC.flags[targetID] ^= (byte)DistrictFlags.randomSpawnLevels;
                    }
                };

                upgradeButton.eventClicked += (control, clickEvent) =>
                {
                    LevelDistrict(targetID, true);
                };

                downgradeButton.eventClicked += (control, clickEvent) =>
                {
                    LevelDistrict(targetID, false);
                };
            }
            catch (Exception e)
            {
                Logging.LogException(e, "exception setting up district panel");
            }
        }
        /// <summary>
        /// Performs initial setup for the panel; we don't use Start() as that's not sufficiently reliable (race conditions), and is not needed with the dynamic create/destroy process.
        /// </summary>
        internal virtual void Setup(Transform parentTransform)
        {
            try
            {
                // Hide while we're setting up.
                isVisible = false;

                // Basic setup.
                autoLayout       = false;
                backgroundSprite = "MenuPanel2";
                opacity          = 0.95f;
                isVisible        = true;
                canFocus         = true;
                isInteractive    = true;
                size             = new Vector3(220f, PanelHeight);

                // Set parent transform to game's district info panel.
                transform.parent = parentTransform;

                // Set position according to setting.
                if (ModSettings.onRight)
                {
                    // On right of info panel.
                    relativePosition = new Vector2(parent.width + 10f, 0f);
                }
                else
                {
                    // On left of info panel.
                    relativePosition = new Vector2(-(width + 10f), 0f);
                }

                // Decorative icon (top-left).
                UISprite iconSprite = AddUIComponent <UISprite>();
                iconSprite.relativePosition = new Vector2(0f, 0f);
                iconSprite.height           = 36f;
                iconSprite.width            = 36f;
                iconSprite.atlas            = Textures.ABLCButtonSprites;
                iconSprite.spriteName       = "normal";

                // Category labels
                nameLabel = AddLabel("", 0f, 27f, 0.6f);
                UILabel titleLabel = AddLabel(Translations.Translate("ABLC_SHORT"), 0f, Margin, 1.0f);

                // Level dropdowns.
                minLevelDropDown       = UIControls.AddLabelledDropDown(this, width - Margin - MenuWidth, 70f, Translations.Translate("ABLC_LVL_MIN"), 60f, accomodateLabel: false, tooltip: MinLevelTip);
                minLevelDropDown.items = new string[] { "1", "2", "3", "4", "5" };

                maxLevelDropDown       = UIControls.AddLabelledDropDown(this, width - Margin - MenuWidth, 100f, Translations.Translate("ABLC_LVL_MAX"), 60f, accomodateLabel: false, tooltip: MaxLevelTip);
                maxLevelDropDown.items = new string[] { "1", "2", "3", "4", "5" };

                // Apply button.
                upgradeButton = UIControls.AddButton(this, Margin, PanelHeight - 80f, Translations.Translate("ABLC_TRIG_UP"), this.width - (Margin * 2), tooltip: UpgradeTip);

                // Add 'downgrade' button.
                downgradeButton = UIControls.AddButton(this, Margin, PanelHeight - 40f, Translations.Translate("ABLC_TRIG_DWN"), this.width - (Margin * 2), tooltip: DowngradeTip);
            }
            catch (Exception e)
            {
                Logging.LogException(e, "exception setting up panel base");
            }
        }