예제 #1
0
        protected virtual void InitLayoutSelections()
        {
            btnLayouts.ClearMenu();

            // Add the allowed layouts to choose from to the menu.
            int totalLayouts = Enum.GetValues(typeof(GUIFacadeControl.Layout)).Length;

            for (int i = 0; i < totalLayouts; i++)
            {
                string layoutName = Enum.GetName(typeof(GUIFacadeControl.Layout), i);
                GUIFacadeControl.Layout layout = GetLayoutNumber(layoutName);
                if (AllowLayout(layout))
                {
                    if (!facadeLayout.IsNullLayout(layout))
                    {
                        btnLayouts.AddItem(GUIFacadeControl.GetLayoutLocalizedName(layout), (int)layout);
                    }
                }
            }

            // Have the menu select the currently selected layout.
            btnLayouts.SetSelectedItemByValue((int)CurrentLayout);
        }
        protected virtual void OnShowLayouts()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(792); // Layouts menu
            int dlgItems     = 0;
            int totalLayouts = Enum.GetValues(typeof(GUIFacadeControl.Layout)).Length;

            bool[] allowedLayouts = new bool[totalLayouts];
            for (int i = 0; i < totalLayouts; i++)
            {
                string layoutName = Enum.GetName(typeof(GUIFacadeControl.Layout), i);
                GUIFacadeControl.Layout layout = GetLayoutNumber(layoutName);
                if (AllowLayout(layout))
                {
                    if (!facadeLayout.IsNullLayout(layout))
                    {
                        dlg.Add(GUIFacadeControl.GetLayoutLocalizedName(layout));
                        dlgItems++;
                        allowedLayouts[i] = true;
                    }
                }
            }
            dlg.SelectedLabel = -1;
            for (int i = 0; i <= (int)CurrentLayout; i++)
            {
                if (allowedLayouts[i])
                {
                    dlg.SelectedLabel++;
                }
            }
            if (dlg.SelectedLabel >= dlgItems)
            {
                dlg.SelectedLabel = dlgItems;
            }

            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            int iSelectedLayout   = dlg.SelectedLabel;
            int allowedItemsFound = -1;

            for (int i = 0; i < allowedLayouts.Length; i++)
            {
                if (allowedLayouts[i])
                {
                    iSelectedLayout = i;
                    allowedItemsFound++;
                    if (allowedItemsFound == dlg.SelectedLabel)
                    {
                        break;
                    }
                }
            }
            CurrentLayout = (Layout)iSelectedLayout;
            SwitchLayout();

            UpdateButtonStates();
        }