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, UIFastListRow
        {
            UIFastList list = parent.AddUIComponent <UIFastList>();

            list.m_rowType = typeof(T);
            return(list);
        }
        /// <summary>
        /// Create the building editor panel; 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>
        internal void Setup()
        {
            try
            {
                // Basic setup.
                isVisible        = false;
                canFocus         = true;
                isInteractive    = true;
                width            = LeftWidth + MiddleWidth + RightWidth + (Spacing * 4);
                height           = PanelHeight + TitleHeight + FilterHeight + (Spacing * 2) + BottomMargin;
                relativePosition = new Vector3(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2));
                backgroundSprite = "UnlockingPanel2";

                // Titlebar.
                titleBar = AddUIComponent <UITitleBar>();
                titleBar.Setup();

                // Filter.
                filterBar                  = AddUIComponent <UIBuildingFilter>();
                filterBar.width            = width - (Spacing * 2);
                filterBar.height           = FilterHeight;
                filterBar.relativePosition = new Vector3(Spacing, TitleHeight);

                filterBar.eventFilteringChanged += (c, i) =>
                {
                    if (i == -1)
                    {
                        return;
                    }

                    int   listCount = buildingSelection.rowsData.m_size;
                    float position  = buildingSelection.listPosition;

                    buildingSelection.selectedIndex = -1;

                    buildingSelection.rowsData = GenerateFastList();
                };

                // Set up panels.
                // Left panel - list of buildings.
                UIPanel leftPanel = AddUIComponent <UIPanel>();
                leftPanel.width            = LeftWidth;
                leftPanel.height           = PanelHeight;
                leftPanel.relativePosition = new Vector3(Spacing, TitleHeight + FilterHeight + Spacing);

                // Middle panel - building preview and edit panels.
                UIPanel middlePanel = AddUIComponent <UIPanel>();
                middlePanel.width            = MiddleWidth;
                middlePanel.height           = PanelHeight;
                middlePanel.relativePosition = new Vector3(LeftWidth + (Spacing * 2), TitleHeight + FilterHeight + Spacing);

                previewPanel                  = middlePanel.AddUIComponent <UIPreviewPanel>();
                previewPanel.width            = middlePanel.width;
                previewPanel.height           = (PanelHeight - Spacing) / 2;
                previewPanel.relativePosition = Vector3.zero;
                previewPanel.Setup();

                editPanel                  = middlePanel.AddUIComponent <UIEditPanel>();
                editPanel.width            = middlePanel.width;
                editPanel.height           = (PanelHeight - Spacing) / 2;
                editPanel.relativePosition = new Vector3(0, previewPanel.height + Spacing);
                editPanel.Setup();

                // Right panel - mod calculations.
                UIPanel rightPanel = AddUIComponent <UIPanel>();
                rightPanel.width            = RightWidth;
                rightPanel.height           = PanelHeight;
                rightPanel.relativePosition = new Vector3(LeftWidth + MiddleWidth + (Spacing * 3), TitleHeight + FilterHeight + Spacing);

                modCalcs                  = rightPanel.AddUIComponent <UIModCalcs>();
                modCalcs.width            = RightWidth;
                modCalcs.height           = PanelHeight;
                modCalcs.relativePosition = Vector3.zero;
                modCalcs.Setup();

                // Building selection list.
                buildingSelection = UIFastList.Create <UIBuildingRow>(leftPanel);
                buildingSelection.backgroundSprite  = "UnlockingPanel";
                buildingSelection.width             = leftPanel.width;
                buildingSelection.height            = leftPanel.height;
                buildingSelection.canSelect         = true;
                buildingSelection.rowHeight         = 40;
                buildingSelection.autoHideScrollbar = true;
                buildingSelection.relativePosition  = Vector3.zero;
                buildingSelection.rowsData          = new FastList <object>();
                buildingSelection.selectedIndex     = -1;

                // Set up filterBar to make sure selection filters are properly initialised before calling GenerateFastList.
                filterBar.Setup();

                // Populate the list.
                buildingSelection.rowsData = GenerateFastList();
            }
            catch (Exception e)
            {
                Debugging.LogException(e);
            }
        }