Example #1
0
        /// <summary>
        /// Look for keypress to open GUI.
        /// </summary>
        /// <param name="realTimeDelta"></param>
        /// <param name="simulationTimeDelta"></param>
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            // Has hotkey been pressed?
            if (hotKey != KeyCode.None && Input.GetKey(hotKey))
            {
                // Check modifier keys according to settings.
                bool altPressed   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.AltGr);
                bool ctrlPressed  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                bool shiftPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

                // Modifiers have to *exactly match* settings, e.g. "alt-E" should not trigger on "ctrl-alt-E".
                bool altOkay   = altPressed == hotAlt;
                bool ctrlOkay  = ctrlPressed == hotCtrl;
                bool shiftOkay = shiftPressed == hotShift;

                // Process keystroke.
                if (altOkay && ctrlOkay && shiftOkay)
                {
                    // Cancel if key input is already queued for processing.
                    if (_processed)
                    {
                        return;
                    }

                    _processed = true;

                    try
                    {
                        // Is options panel open?  If so, we ignore this and don't do anything.
                        if (!OptionsPanel.IsOpen)
                        {
                            BuildingDetailsPanel.Open();
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.LogException(e);
                    }
                }
                else
                {
                    // Relevant keys aren't pressed anymore; this keystroke is over, so reset and continue.
                    _processed = false;
                }
            }
            else
            {
                // Relevant keys aren't pressed anymore; this keystroke is over, so reset and continue.
                _processed = false;
            }
        }
        public override void OnLevelLoaded(LoadMode mode)
        {
            // Check to see if a conflicting mod has been detected - if so, alert the user.
            if (conflictingMod)
            {
                UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Realistic Population Revisited", "Original Realistic Population and Consumption Mod mod detected - Realistic Population Revisited is shutting down to protect your game.  Only ONE of these mods can be enabled at the same time; please unsubscribe from the old Realistic Population and Consumption Mod, which is now deprecated!", true);
            }

            // Don't do anything further if mod hasn't activated (conflicting mod detected, or loading into editor instead of game).
            if (!isModEnabled)
            {
                return;
            }

            else if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame)
            {
                if (!isLevelLoaded)
                {
                    isLevelLoaded = true;
                    // Now we can remove people
                    DataStore.allowRemovalOfCitizens = true;
                    Debugging.releaseBuffer();
                    Debugging.Message("successfully applied");
                }
            }

            // Create new XML if one doesn't already exist.
            if (!File.Exists(DataStore.currentFileLocation))
            {
                XMLUtilsWG.WriteToXML();
            }

            // Add button to building info panels.
            BuildingDetailsPanel.AddInfoPanelButton();

            // Check if we need to display update notification.
            if (UpdateNotification.notificationVersion != 2)
            {
                // No update notification "Don't show again" flag found; show the notification.
                UpdateNotification notification = new UpdateNotification();
                notification.Create();
                notification.Show();
            }

            // Set up options panel event handler.
            OptionsPanel.OptionsEventHook();
        }
        /// <summary>
        /// Create the titlebar; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process.
        /// </summary>
        public void Setup()
        {
            // Basic setup.
            width            = parent.width;
            height           = UIBuildingDetails.TitleHeight;
            isVisible        = true;
            canFocus         = true;
            isInteractive    = true;
            relativePosition = Vector3.zero;

            // Make it draggable.
            dragHandle                  = AddUIComponent <UIDragHandle>();
            dragHandle.width            = width - 50;
            dragHandle.height           = height;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.target           = parent;

            // Decorative icon (top-left).
            iconSprite = AddUIComponent <UISprite>();
            iconSprite.relativePosition = new Vector3(10, 5);
            iconSprite.spriteName       = "ToolbarIconZoomOutCity";
            UIUtils.ResizeIcon(iconSprite, new Vector2(30, 30));
            iconSprite.relativePosition = new Vector3(10, 5);

            // Titlebar label.
            titleLabel = AddUIComponent <UILabel>();
            titleLabel.relativePosition = new Vector3(50, 13);
            titleLabel.text             = RealPopMod.ModName;

            // Close button.
            closeButton = AddUIComponent <UIButton>();
            closeButton.relativePosition = new Vector3(width - 35, 2);
            closeButton.normalBgSprite   = "buttonclose";
            closeButton.hoveredBgSprite  = "buttonclosehover";
            closeButton.pressedBgSprite  = "buttonclosepressed";
            closeButton.eventClick      += (component, param) =>
            {
                BuildingDetailsPanel.Close();
            };
        }
        /// <summary>
        /// Adds button to access building details from building info panels.
        /// </summary>
        internal static void AddInfoPanelButton()
        {
            // Get parent panel and apply button.
            ZonedBuildingWorldInfoPanel infoPanel = UIView.library.Get <ZonedBuildingWorldInfoPanel>(typeof(ZonedBuildingWorldInfoPanel).Name);
            UIButton panelButton = UIUtils.CreateButton(infoPanel.component, 133);

            // Basic setup.
            panelButton.height                = 19.5f;
            panelButton.textScale             = 0.65f;
            panelButton.textVerticalAlignment = UIVerticalAlignment.Bottom;
            panelButton.relativePosition      = new UnityEngine.Vector3(infoPanel.component.width - panelButton.width - 10, 120);
            panelButton.text = Translations.Translate("RPR_REALPOP");

            // Just in case other mods are interfering.
            panelButton.Enable();

            // Event handler.
            panelButton.eventClick += (control, clickEvent) =>
            {
                // Select current building in the building details panel and show.
                BuildingDetailsPanel.Open(InstanceManager.GetPrefabInfo(WorldInfoPanel.GetCurrentInstanceID()) as BuildingInfo);
            };
        }