Exemple #1
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            // create a new group heading
            UIHelperBase group = helper.AddGroup("Game Day Timer Settings");

            // add a check box to show/hide the timings
            GameDayTimerConfiguration config = Configuration <GameDayTimerConfiguration> .Load();

            group.AddCheckbox("Show timings", config.PanelIsVisible, (bool isChecked) =>
            {
                // save the visibility in the config file
                GameDayTimerConfiguration.SavePanelIsVisible(isChecked);

                // if there is a panel, show or hide it
                if (Panel != null)
                {
                    Panel.isVisible = isChecked;
                }
            });

            // add a button to reset the panel position
            group.AddButton("Reset Position", () =>
            {
                // save the default position in the config file
                GameDayTimerConfiguration.SavePanelPosition(GameDayTimerPanel.DefaultPanelPositionX, GameDayTimerPanel.DefaultPanelPositionY);

                // if there is a panel, move it to the default position
                if (Panel != null)
                {
                    Panel.MovePanelToPosition(GameDayTimerPanel.DefaultPanelPositionX, GameDayTimerPanel.DefaultPanelPositionY);
                }
            });
        }
        private void GameDayTimerPanel_eventMouseUp(UIComponent component, UIMouseEventParameter eventParam)
        {
            // if dragging, then drag is done, save final panel position
            if (Dragging)
            {
                GameDayTimerConfiguration.SavePanelPosition(relativePosition.x, relativePosition.y);
            }

            // reset dragging flags
            MouseDown = false;
            Dragging  = false;
        }
        /// <summary>
        /// Start is called after the panel is created in Loading
        /// set up and populate the panel
        /// </summary>
        public override void Start()
        {
            // do base processing
            base.Start();

            try
            {
                // set panel properties
                name             = "GameDayTimerPanel";
                width            = 150f;
                height           = 68f;
                backgroundSprite = "MenuPanel2";
                canFocus         = true;
                opacity          = 0.75f;

                // move panel to initial position according to the config
                GameDayTimerConfiguration config = Configuration <GameDayTimerConfiguration> .Load();

                MovePanelToPosition(config.PanelPositionX, config.PanelPositionY);

                // set up mouse event handlers for dragging the panel
                eventMouseDown += GameDayTimerPanel_eventMouseDown;
                eventMouseMove += GameDayTimerPanel_eventMouseMove;
                eventMouseUp   += GameDayTimerPanel_eventMouseUp;

                // set position and size for labels
                const float LabelLeft   = 8f;   // all labels have same left position, but value labels are right justified
                const float LabelTop    = 4f;   // top of topmost labels
                float       LabelWidth  = width - 2 * LabelLeft;
                float       LabelHeight = (height - 2 * LabelTop) / 3f;

                // create label components to show text
                CurrentDayLabel                  = AddUIComponent <UILabel>();
                CurrentDayLabel.name             = "GameDayTimerCurrentDayLabel";
                CurrentDayLabel.text             = "Curr Day";
                CurrentDayLabel.relativePosition = new Vector3(LabelLeft, LabelTop);
                CurrentDayLabel.textAlignment    = UIHorizontalAlignment.Left;
                CurrentDayLabel.autoSize         = false;
                CurrentDayLabel.width            = LabelWidth;
                CurrentDayLabel.height           = LabelHeight;

                PreviousDayLabel                  = AddUIComponent <UILabel>();
                PreviousDayLabel.name             = "GameDayTimerPreviousDayLabel";
                PreviousDayLabel.text             = "Prev Day";
                PreviousDayLabel.relativePosition = new Vector3(LabelLeft, LabelTop + LabelHeight);
                PreviousDayLabel.textAlignment    = UIHorizontalAlignment.Left;
                PreviousDayLabel.autoSize         = false;
                PreviousDayLabel.width            = LabelWidth;
                PreviousDayLabel.height           = LabelHeight;

                FramesPerSecLabel                  = AddUIComponent <UILabel>();
                FramesPerSecLabel.name             = "GameDayTimerFramesPerSecLabel";
                FramesPerSecLabel.text             = "FPS";
                FramesPerSecLabel.relativePosition = new Vector3(LabelLeft, LabelTop + 2 * LabelHeight);
                FramesPerSecLabel.textAlignment    = UIHorizontalAlignment.Left;
                FramesPerSecLabel.autoSize         = false;
                FramesPerSecLabel.width            = LabelWidth;
                FramesPerSecLabel.height           = LabelHeight;

                // create label components to show timing values
                CurrentDayValue                  = AddUIComponent <UILabel>();
                CurrentDayValue.name             = "GameDayTimerCurrentDayValue";
                CurrentDayValue.text             = "";
                CurrentDayValue.relativePosition = CurrentDayLabel.relativePosition;
                CurrentDayValue.textAlignment    = UIHorizontalAlignment.Right;
                CurrentDayValue.autoSize         = false;
                CurrentDayValue.width            = LabelWidth;
                CurrentDayValue.height           = LabelHeight;

                PreviousDayValue                  = AddUIComponent <UILabel>();
                PreviousDayValue.name             = "GameDayTimerPreviousDayValue";
                PreviousDayValue.text             = "";
                PreviousDayValue.relativePosition = PreviousDayLabel.relativePosition;
                PreviousDayValue.textAlignment    = UIHorizontalAlignment.Right;
                PreviousDayValue.autoSize         = false;
                PreviousDayValue.width            = LabelWidth;
                PreviousDayValue.height           = LabelHeight;

                FramesPerSecValue                  = AddUIComponent <UILabel>();
                FramesPerSecValue.name             = "GameDayTimerFramesPerSecValue";
                FramesPerSecValue.text             = "";
                FramesPerSecValue.relativePosition = FramesPerSecLabel.relativePosition;
                FramesPerSecValue.textAlignment    = UIHorizontalAlignment.Right;
                FramesPerSecValue.autoSize         = false;
                FramesPerSecValue.width            = LabelWidth;
                FramesPerSecValue.height           = LabelHeight;

                // initialize timing things
                GDTTotalTimeInDay             = 0;
                GDTPreviousTotalTimeInDayText = "xx";
                GDTPreviousDay      = SimulationManager.instance.m_currentGameTime.Day;
                GDTPreviousSimSpeed = SimulationManager.instance.SelectedSimulationSpeed;
                GDTPreviousRealTime = GetCurrentRealTime();
                FPSPreviousRealTime = GetCurrentRealTime();

                // determine if Real Time mod is enabled
                foreach (PluginInfo mod in Singleton <PluginManager> .instance.GetPluginsInfo())
                {
                    // ignore builtin mods and camera script
                    if (!mod.isBuiltin && !mod.isCameraScript)
                    {
                        // check against the Real Time workshop ID
                        if (mod.publishedFileID.AsUInt64 == 1420955187)
                        {
                            RealTimeModEnabled = mod.isEnabled;
                            break;
                        }
                    }
                }

                if (RealTimeModEnabled)
                {
                    // don't wait for a day change
                    GDTFirstDayChanged = true;
                }
                else
                {
                    // wait for a day change
                    WaitForDayChange();
                }

                // show or hide the panel according to the config
                isVisible = config.PanelIsVisible;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }