Exemple #1
0
        /// <summary>
        /// Use this to create the UIFastList.
        /// Do NOT use AddUIComponent.
        /// I had to do that way because MonoBehaviors classes cannot be generic
        /// </summary>
        /// <typeparam name="T">The type of the row UI component</typeparam>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static UIFastList Create <T>(UIComponent parent)
            where T : UIPanel, IUIFastListRow
        {
            UIFastList list = parent.AddUIComponent <UIFastList>();

            list.m_rowType = typeof(T);
            return(list);
        }
Exemple #2
0
        /*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();
                AdvancedVehicleOptions.ImportConfig();
                optionList = AdvancedVehicleOptions.config.options;
            };
            m_export.eventClick += (c, t) => AdvancedVehicleOptions.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);
                }
            };
        }