Пример #1
0
        private ProgressView BuildProgressView(IEnumerable <Pair <IGuiFrame> > progressSteps, IGuiStyle progressLabelStyle)
        {
            IGuiFrame mainFrame = mMainWindow.SelectSingleElement <IGuiFrame>("MainFrame");

            if (mainFrame == null)
            {
                throw new Exception("Cannot find the navigation frame at 'NewRoomDialog/MainFrame'");
            }

            IGuiFrame navigationFrame = mainFrame.SelectSingleElement <IGuiFrame>("NavigationFrame");

            if (navigationFrame == null)
            {
                throw new Exception("Cannot find the navigation frame at 'NewRoomDialog/MainFrame/NavigationFrame'");
            }

            IGuiFrame viewFrame = mainFrame.SelectSingleElement <IGuiFrame>("ViewFrame");

            if (viewFrame == null)
            {
                throw new Exception("Cannot find the view frame at 'NewRoomDialog/MainFrame/ViewFrame'");
            }

            IGuiFrame toolFrame = viewFrame.SelectSingleElement <IGuiFrame>("ToolFrame");

            if (toolFrame == null)
            {
                throw new Exception("Cannot find the tool frame at 'NewRoomDialog/MainFrame/ViewFrame/ToolFrame'");
            }

            IGuiFrame topLetterbox = viewFrame.SelectSingleElement <IGuiFrame>("LetterboxTop");

            if (topLetterbox == null)
            {
                throw new Exception("Cannot find the tool frame at 'NewRoomDialog/MainFrame/ViewFrame/LetterboxTop'");
            }

            IGuiFrame bottomLetterbox = viewFrame.SelectSingleElement <IGuiFrame>("LetterboxBottom");

            if (topLetterbox == null)
            {
                throw new Exception("Cannot find the tool frame at 'NewRoomDialog/MainFrame/ViewFrame/LetterboxBottom'");
            }

            if (viewFrame.GuiSize is ProceduralSize)
            {
                // The view frame's size covers the screen except for the NavigationFrame's area
                ((ProceduralSize)viewFrame.GuiSize).SizeFunc = delegate(IGuiElement element)
                {
                    Vector2 size = element.Parent.Size;
                    size.x -= navigationFrame.Size.x;
                    return(size);
                };
            }

            if (toolFrame.GuiSize is ProceduralSize)
            {
                // The tool frame's size is the largest frame that will fit in the ViewFrame while
                // still being the same aspect ratio as the screen.
                ((ProceduralSize)toolFrame.GuiSize).SizeFunc = delegate(IGuiElement element)
                {
                    float   aspectRatio = (float)Screen.width / (float)Screen.height;
                    Vector2 size        = viewFrame.Size;
                    size.y = size.x / aspectRatio;
                    return(size);
                };
            }

            foreach (IGuiElement child in viewFrame.Children)
            {
                if ((child is IGuiFrame))
                {
                    IGuiFrame frame = (IGuiFrame)child;

                    if (frame.GuiSize is ProceduralSize)
                    {
                        if (frame.Name == "LetterboxTop" || frame.Name == "LetterboxBottom")
                        {
                            // The letterbox sizes are 1/2 of the size difference between the
                            // tool frame and the view frame
                            ((ProceduralSize)frame.GuiSize).SizeFunc = delegate(IGuiElement element)
                            {
                                Vector2 size = viewFrame.Size;
                                size.y = (size.y - toolFrame.Size.y) * 0.5f;
                                return(size);
                            };
                        }
                    }
                }
            }

            IGuiPosition toolFramePosition = viewFrame.GetChildGuiPosition(toolFrame);

            if (toolFramePosition is ProceduralPosition)
            {
                ((ProceduralPosition)toolFramePosition).PositionFunc = delegate(IGuiElement element)
                {
                    return(new Vector2(0.0f, topLetterbox.Size.y));
                };
            }

            ProgressView result = new ProgressView
                                  (
                "NewRoomDialogProgressView",
                new FillParent(),
                navigationFrame,
                mainFrame.GetChildGuiPosition(navigationFrame),
                progressLabelStyle,
                viewFrame,
                mainFrame.GetChildGuiPosition(viewFrame)
                                  );

            mainFrame.ClearChildWidgets();
            mainFrame.AddChildWidget(result, new FillParent());

            IGuiPosition topLetterboxPosition    = viewFrame.GetChildGuiPosition(topLetterbox);
            IGuiPosition bottomLetterboxPosition = viewFrame.GetChildGuiPosition(bottomLetterbox);

            foreach (Pair <IGuiFrame> progressStep in progressSteps)
            {
                IGuiFrame newContextFrame = new GuiFrame(progressStep.First.Name.Replace("Main", ""), new FillParent());

                newContextFrame.AddChildWidget(topLetterbox, topLetterboxPosition);
                newContextFrame.AddChildWidget(progressStep.First, toolFramePosition);
                newContextFrame.AddChildWidget(bottomLetterbox, bottomLetterboxPosition);

                result.AddStep(newContextFrame.Name, newContextFrame, progressStep.Second);
            }
            return(result);
        }