Example #1
0
        public override void Start()
        {
            base.Start();

            backgroundSprite = "UnlockingPanel2";
            isVisible        = false;
            canFocus         = true;
            isInteractive    = true;
            clipChildren     = true;
            width            = 600;
            height           = 200;
            relativePosition = new Vector3(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2));

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.title      = "Advanced Vehicle Options - Warning";
            m_title.iconSprite = "IconCitizenVehicle";
            m_title.isModal    = true;

            // Icon
            m_warningIcon            = AddUIComponent <UISprite>();
            m_warningIcon.size       = new Vector2(90, 90);
            m_warningIcon.spriteName = "IconWarning";

            // Message
            m_messageLabel          = AddUIComponent <UILabel>();
            m_messageLabel.wordWrap = true;

            // Ok
            m_ok      = UIUtils.CreateButton(this);
            m_ok.text = "OK";

            m_ok.eventClick += (c, p) =>
            {
                UIView.PopModal();
                Hide();
            };

            message = m_message;

            isVisible = true;
        }
        /*public override void OnDestroy()
         * {
         *  base.OnDestroy();
         *
         *  DebugUtils.Log("Destroying UIMainPanel");
         *
         *  if (m_button != null) GameObject.Destroy(m_button.gameObject);
         *  GameObject.Destroy(m_optionPanel.gameObject);
         * }*/

        private void SetupControls()
        {
            float offset = 40f;

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.iconSprite = "InfoIconTrafficCongestion";
            m_title.title      = "Advanced Vehicle Options " + ModInfo.version;

            // Category DropDown
            UILabel label = AddUIComponent <UILabel>();

            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = new Vector3(10f, offset);
            label.text             = "Category :";

            m_category       = UIUtils.CreateDropDown(this);
            m_category.width = 150;

            for (int i = 0; i < categoryList.Length; i++)
            {
                m_category.AddItem(categoryList[i]);
            }

            m_category.selectedIndex    = 0;
            m_category.tooltip          = "Select a category to display\nTip: Use the mouse wheel to switch between categories faster";
            m_category.relativePosition = label.relativePosition + new Vector3(75f, 0f);

            m_category.eventSelectedIndexChanged += (c, t) =>
            {
                m_category.enabled = false;
                PopulateList();
                m_category.enabled = true;
            };

            // Search
            m_search                  = UIUtils.CreateTextField(this);
            m_search.width            = 145f;
            m_search.height           = 30f;
            m_search.padding          = new RectOffset(6, 6, 6, 6);
            m_search.tooltip          = "Type the name of a vehicle type";
            m_search.relativePosition = new Vector3(WIDTHLEFT - m_search.width, offset);

            m_search.eventTextChanged += (c, t) => PopulateList();

            label                  = AddUIComponent <UILabel>();
            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = m_search.relativePosition - new Vector3(60f, 0f);
            label.text             = "Search :";

            // FastList
            m_fastList = UIFastList.Create <UIVehicleItem>(this);
            m_fastList.backgroundSprite = "UnlockingPanel";
            m_fastList.width            = WIDTHLEFT - 5;
            m_fastList.height           = height - offset - 110;
            m_fastList.canSelect        = true;
            m_fastList.relativePosition = new Vector3(5, offset + 35);

            // Configuration file buttons
            UILabel configLabel = this.AddUIComponent <UILabel>();

            configLabel.text             = "Configuration file:";
            configLabel.textScale        = 0.8f;
            configLabel.relativePosition = new Vector3(10, height - 60);

            m_import                  = UIUtils.CreateButton(this);
            m_import.text             = "Import";
            m_import.tooltip          = "Import the configuration";
            m_import.relativePosition = new Vector3(10, height - 40);

            m_export                  = UIUtils.CreateButton(this);
            m_export.text             = "Export";
            m_export.tooltip          = "Export the configuration";
            m_export.relativePosition = new Vector3(105, height - 40);

            // Preview
            UIPanel panel = AddUIComponent <UIPanel>();

            panel.backgroundSprite = "GenericPanel";
            panel.width            = WIDTHRIGHT - 10;
            panel.height           = HEIGHT - 420;
            panel.relativePosition = new Vector3(WIDTHLEFT + 5, offset);

            m_preview                  = panel.AddUIComponent <UITextureSprite>();
            m_preview.size             = panel.size;
            m_preview.relativePosition = Vector3.zero;

            m_previewRenderer      = gameObject.AddComponent <PreviewRenderer>();
            m_previewRenderer.size = m_preview.size * 2; // Twice the size for anti-aliasing

            m_preview.texture = m_previewRenderer.texture;

            // Follow
            if (m_cameraController != null)
            {
                m_followVehicle                  = AddUIComponent <UISprite>();
                m_followVehicle.spriteName       = "LocationMarkerFocused";
                m_followVehicle.width            = m_followVehicle.spriteInfo.width;
                m_followVehicle.height           = m_followVehicle.spriteInfo.height;
                m_followVehicle.tooltip          = "Click here to cycle through the existing vehicles of that type";
                m_followVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_followVehicle.width - 5, panel.relativePosition.y + 5);

                m_followVehicle.eventClick += (c, p) => FollowNextVehicle();
            }

            // Option panel
            m_optionPanel = AddUIComponent <UIOptionPanel>();
            m_optionPanel.relativePosition = new Vector3(WIDTHLEFT, height - 370);

            // Event handlers
            m_fastList.eventSelectedIndexChanged  += OnSelectedItemChanged;
            m_optionPanel.eventEnableCheckChanged += OnEnableStateChanged;
            m_import.eventClick += (c, t) =>
            {
                DefaultOptions.RestoreAll();
                AdvancedVehicleOptionsUID.ImportConfig();
                optionList = AdvancedVehicleOptionsUID.config.options;
            };
            m_export.eventClick += (c, t) => AdvancedVehicleOptionsUID.ExportConfig();

            panel.eventMouseDown += (c, p) =>
            {
                eventMouseMove += RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseUp += (c, p) =>
            {
                eventMouseMove -= RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseWheel += (c, p) =>
            {
                m_previewRenderer.zoom -= Mathf.Sign(p.wheelDelta) * 0.25f;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };
        }
Example #3
0
        internal void SetupControls()
        {
            float offset = 40f;

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.iconSprite = "InfoIconTrafficCongestion";
            m_title.title      = AVOMod.ModName + " " + AVOMod.Version;

            // Category DropDown
            UILabel label = AddUIComponent <UILabel>();

            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = new Vector3(10f, offset);
            label.text             = Translations.Translate("AVO_MOD_MP56");

            m_category       = UIUtils.CreateDropDown(this);
            m_category.width = 175;

            for (int i = 0; i < categoryList.Length; i++)
            {
                m_category.AddItem(categoryList[i]);
            }

            m_category.selectedIndex    = 0;
            m_category.tooltip          = Translations.Translate("AVO_MOD_MP39");
            m_category.relativePosition = label.relativePosition + new Vector3(75f, 0f);

            m_category.eventSelectedIndexChanged += (c, t) =>
            {
                m_category.enabled = false;
                PopulateList();
                m_category.enabled = true;
            };

            // Search
            m_search                  = UIUtils.CreateTextField(this);
            m_search.width            = 145f;
            m_search.height           = 30f;
            m_search.padding          = new RectOffset(6, 6, 6, 6);
            m_search.tooltip          = Translations.Translate("AVO_MOD_MP40");
            m_search.relativePosition = new Vector3(WIDTHLEFT - m_search.width, offset);

            m_search.eventTextChanged += (c, t) => PopulateList();

            label                  = AddUIComponent <UILabel>();
            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = m_search.relativePosition - new Vector3(60f, 0f);
            label.text             = Translations.Translate("AVO_MOD_MP55");

            // FastList
            m_fastList = UIFastList.Create <UIVehicleItem>(this);
            m_fastList.backgroundSprite = "UnlockingPanel";
            m_fastList.width            = WIDTHLEFT - 5;
            m_fastList.height           = height - offset - 110;
            m_fastList.canSelect        = true;
            m_fastList.relativePosition = new Vector3(5, offset + 35);

            // Configuration file buttons
            UILabel configLabel = this.AddUIComponent <UILabel>();

            configLabel.text             = Translations.Translate("AVO_MOD_MP41");
            configLabel.textScale        = 0.8f;
            configLabel.relativePosition = new Vector3(16, height - 65);

            m_import                  = UIUtils.CreateButton(this);
            m_import.text             = Translations.Translate("AVO_MOD_MP42");
            m_import.width            = 80;
            m_import.tooltip          = Translations.Translate("AVO_MOD_MP43");
            m_import.relativePosition = new Vector3(10, height - 45);

            m_export                  = UIUtils.CreateButton(this);
            m_export.text             = Translations.Translate("AVO_MOD_MP44");
            m_export.width            = 80;
            m_export.tooltip          = Translations.Translate("AVO_MOD_MP45");
            m_export.relativePosition = new Vector3(95, height - 45);

            m_resetall                  = UIUtils.CreateButton(this);
            m_resetall.text             = Translations.Translate("AVO_MOD_MP46");
            m_resetall.width            = 80;
            m_resetall.tooltip          = Translations.Translate("AVO_MOD_MP47");
            m_resetall.relativePosition = new Vector3(180, height - 45);

            m_autosave                  = AddUIComponent <UILabel>();
            m_autosave.textScale        = 0.6f;
            m_autosave.text             = Translations.Translate("AVO_MOD_MP48");
            m_autosave.relativePosition = new Vector3(275, height - 40);
            m_autosave.autoSize         = true;
            m_autosave.textAlignment    = UIHorizontalAlignment.Center;
            m_autosave.textColor        = Color.green;
            m_autosave.tooltip          = Translations.Translate("AVO_MOD_MP49");
            m_autosave.isVisible        = AdvancedVehicleOptions.AutoSaveVehicleConfig;

            // Preview
            UIPanel panel = AddUIComponent <UIPanel>();

            panel.backgroundSprite = "GenericPanel";
            panel.width            = WIDTHRIGHT - 10;
            panel.height           = HEIGHT - 420;
            panel.relativePosition = new Vector3(WIDTHLEFT + 5, offset);

            m_preview                  = panel.AddUIComponent <UITextureSprite>();
            m_preview.size             = panel.size;
            m_preview.relativePosition = Vector3.zero;

            m_previewRenderer      = gameObject.AddComponent <PreviewRenderer>();
            m_previewRenderer.size = m_preview.size * 2; // Twice the size for anti-aliasing

            m_preview.texture = m_previewRenderer.texture;

            // Follow a vehicle
            if (m_cameraController != null)
            {
                m_followVehicle                  = AddUIComponent <UISprite>();
                m_followVehicle.spriteName       = "LocationMarkerFocused";
                m_followVehicle.width            = m_followVehicle.spriteInfo.width;
                m_followVehicle.height           = m_followVehicle.spriteInfo.height;
                m_followVehicle.tooltip          = Translations.Translate("AVO_MOD_MP50");
                m_followVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_followVehicle.width - 5, panel.relativePosition.y + 5);

                m_followVehicle.eventClick += (c, p) => FollowNextVehicle();
            }

            //Remove the followed vehicle
            {
                m_removeVehicle = AddUIComponent <UISprite>();
                m_removeVehicle.Hide();
                m_removeVehicle.spriteName       = "IconPolicyOldTown";
                m_removeVehicle.width            = m_removeVehicle.spriteInfo.width - 12;
                m_removeVehicle.height           = m_removeVehicle.spriteInfo.height - 12;
                m_removeVehicle.tooltip          = Translations.Translate("AVO_MOD_MP51");
                m_removeVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_removeVehicle.width - 33, panel.relativePosition.y + 7);

                m_removeVehicle.eventClick += (c, p) => RemoveThisVehicle();
            }

            // Option panel
            m_optionPanel = AddUIComponent <UIOptionPanel>();
            m_optionPanel.relativePosition = new Vector3(WIDTHLEFT, height - 370);

            // Event handlers
            m_fastList.eventSelectedIndexChanged  += OnSelectedItemChanged;
            m_optionPanel.eventEnableCheckChanged += OnEnableStateChanged;

            m_import.eventClick += (c, t) =>
            {
                DefaultOptions.RestoreAll();
                AdvancedVehicleOptions.ImportVehicleDataConfig();
                optionList = AdvancedVehicleOptions.config.options;
            };

            m_export.eventClick += (c, t) => AdvancedVehicleOptions.ExportVehicleDataConfig(true);

            m_resetall.eventClick += (c, t) =>
            {
                ConfirmPanel.ShowModal(Translations.Translate("AVO_MOD_MP52"), Translations.Translate("AVO_MOD_MP53"), (comp, ret) =>
                {
                    if (ret != 1)
                    {
                        return;
                    }

                    DefaultOptions.RestoreAll();
                    AdvancedVehicleOptions.ResetVehicleDataConfig();
                    optionList = AdvancedVehicleOptions.config.options;

                    ExceptionPanel resetpanel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                    resetpanel.SetMessage("Advanced Vehicle Options", Translations.Translate("AVO_MOD_MP54"), false);
                });
            };

            panel.eventMouseDown += (c, p) =>
            {
                eventMouseMove += RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseUp += (c, p) =>
            {
                eventMouseMove -= RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseWheel += (c, p) =>
            {
                m_previewRenderer.zoom -= Mathf.Sign(p.wheelDelta) * 0.25f;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };
        }
        private void SetupControls()
        {
            float offset = 40f;

            //Beta Testing Timestamp
            //DateTime now = DateTime.Now;
            //m_title.title = "Advanced Vehicle Options " + ModInfo.version + " " + now;

            // Title Bar
            m_title            = AddUIComponent <UITitleBar>();
            m_title.iconSprite = "InfoIconTrafficCongestion";
            m_title.title      = "Advanced Vehicle Options " + ModInfo.version;

            // Category DropDown
            UILabel label = AddUIComponent <UILabel>();

            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = new Vector3(10f, offset);
            label.text             = "Category :";

            m_category       = UIUtils.CreateDropDown(this);
            m_category.width = 175;

            for (int i = 0; i < categoryList.Length; i++)
            {
                m_category.AddItem(categoryList[i]);
            }

            m_category.selectedIndex    = 0;
            m_category.tooltip          = "Select a category to display\nTip: Use the mouse wheel to switch between categories faster";
            m_category.relativePosition = label.relativePosition + new Vector3(75f, 0f);

            m_category.eventSelectedIndexChanged += (c, t) =>
            {
                m_category.enabled = false;
                PopulateList();
                m_category.enabled = true;
            };

            // Search
            m_search                  = UIUtils.CreateTextField(this);
            m_search.width            = 145f;
            m_search.height           = 30f;
            m_search.padding          = new RectOffset(6, 6, 6, 6);
            m_search.tooltip          = "Type the name of a vehicle type";
            m_search.relativePosition = new Vector3(WIDTHLEFT - m_search.width, offset);

            m_search.eventTextChanged += (c, t) => PopulateList();

            label                  = AddUIComponent <UILabel>();
            label.textScale        = 0.8f;
            label.padding          = new RectOffset(0, 0, 8, 0);
            label.relativePosition = m_search.relativePosition - new Vector3(60f, 0f);
            label.text             = "Search :";

            // FastList
            m_fastList = UIFastList.Create <UIVehicleItem>(this);
            m_fastList.backgroundSprite = "UnlockingPanel";
            m_fastList.width            = WIDTHLEFT - 5;
            m_fastList.height           = height - offset - 110;
            m_fastList.canSelect        = true;
            m_fastList.relativePosition = new Vector3(5, offset + 35);

            // Configuration file buttons
            UILabel configLabel = this.AddUIComponent <UILabel>();

            configLabel.text             = "Actions for Vehicle Configuration:";
            configLabel.textScale        = 0.8f;
            configLabel.relativePosition = new Vector3(16, height - 65);

            m_import                  = UIUtils.CreateButton(this);
            m_import.text             = "Import";
            m_import.width            = 80;
            m_import.tooltip          = "Import the configuration";
            m_import.relativePosition = new Vector3(10, height - 45);

            m_export                  = UIUtils.CreateButton(this);
            m_export.text             = "Export";
            m_export.width            = 80;
            m_export.tooltip          = "Export the configuration";
            m_export.relativePosition = new Vector3(95, height - 45);

            m_resetall                  = UIUtils.CreateButton(this);
            m_resetall.text             = "Reset all";
            m_resetall.width            = 80;
            m_resetall.tooltip          = "Reset full configuration";
            m_resetall.relativePosition = new Vector3(180, height - 45);

            // Preview
            UIPanel panel = AddUIComponent <UIPanel>();

            panel.backgroundSprite = "GenericPanel";
            panel.width            = WIDTHRIGHT - 10;
            panel.height           = HEIGHT - 420;
            panel.relativePosition = new Vector3(WIDTHLEFT + 5, offset);

            m_preview                  = panel.AddUIComponent <UITextureSprite>();
            m_preview.size             = panel.size;
            m_preview.relativePosition = Vector3.zero;

            m_previewRenderer      = gameObject.AddComponent <PreviewRenderer>();
            m_previewRenderer.size = m_preview.size * 2; // Twice the size for anti-aliasing

            m_preview.texture = m_previewRenderer.texture;

            // Follow a vehicle
            if (m_cameraController != null)
            {
                m_followVehicle                  = AddUIComponent <UISprite>();
                m_followVehicle.spriteName       = "LocationMarkerFocused";
                m_followVehicle.width            = m_followVehicle.spriteInfo.width;
                m_followVehicle.height           = m_followVehicle.spriteInfo.height;
                m_followVehicle.tooltip          = "Click here to cycle through the existing vehicles of that type.\nHold Shift Key down for zooming directly to vehicle.";
                m_followVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_followVehicle.width - 5, panel.relativePosition.y + 5);

                m_followVehicle.eventClick += (c, p) => FollowNextVehicle();
            }

            //Remove the followed vehicle
            {
                m_removeVehicle = AddUIComponent <UISprite>();
                m_removeVehicle.Hide();
                m_removeVehicle.spriteName       = "IconPolicyOldTown";
                m_removeVehicle.width            = m_removeVehicle.spriteInfo.width - 12;
                m_removeVehicle.height           = m_removeVehicle.spriteInfo.height - 12;
                m_removeVehicle.tooltip          = "Click here to remove the selected vehicle.";
                m_removeVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_removeVehicle.width - 33, panel.relativePosition.y + 7);

                m_removeVehicle.eventClick += (c, p) => RemoveThisVehicle();
            }

            // Option panel
            m_optionPanel = AddUIComponent <UIOptionPanel>();
            m_optionPanel.relativePosition = new Vector3(WIDTHLEFT, height - 370);

            // Event handlers
            m_fastList.eventSelectedIndexChanged  += OnSelectedItemChanged;
            m_optionPanel.eventEnableCheckChanged += OnEnableStateChanged;
            m_import.eventClick += (c, t) =>
            {
                DefaultOptions.RestoreAll();
                AdvancedVehicleOptionsUID.ImportConfig();
                optionList = AdvancedVehicleOptionsUID.config.options;
            };
            m_export.eventClick += (c, t) => AdvancedVehicleOptionsUID.ExportConfig();

            m_resetall.eventClick += (c, t) =>
            {
                ConfirmPanel.ShowModal("Confirm Reset Configuration", "Customized settings for all vehicles will be reset.\n\n" +
                                       "Proceed with Configuration reset ?", (comp, ret) =>
                {
                    if (ret != 1)
                    {
                        return;
                    }

                    DefaultOptions.RestoreAll();
                    AdvancedVehicleOptionsUID.ResetConfig();
                    optionList = AdvancedVehicleOptionsUID.config.options;

                    ExceptionPanel resetpanel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                    resetpanel.SetMessage("Advanced Vehicle Options", "All vehicle configuration and customized settings\n" +
                                          "have been reset to the Game Defaults.", false);
                });
            };

            panel.eventMouseDown += (c, p) =>
            {
                eventMouseMove += RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseUp += (c, p) =>
            {
                eventMouseMove -= RotateCamera;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };

            panel.eventMouseWheel += (c, p) =>
            {
                m_previewRenderer.zoom -= Mathf.Sign(p.wheelDelta) * 0.25f;
                if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations)
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor);
                }
                else
                {
                    m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab);
                }
            };
        }