Beispiel #1
0
        public StudioUI(Studio studio, Sequence sequence, Gui gui, Layer gridLayer, Layer uiLayer)
        {
            _gui = gui;

            // create layers
            var studioLayer = Add(new Layer());
            var annotationLayer = studioLayer.Add(new Layer());

            // fullscreen switch

            Add(new KeyBinding(Keys.F1, () => Render.Viewport.IsFullScreen = !Render.Viewport.IsFullScreen));

            // tool bars setup

            var panel = uiLayer.Add(new StackPanel(5) { Padding = new Margin() });
            var horizontalBar = panel.Add(new StackPanel(5) { Padding = new Margin(), Orientation = Orientation.Horizontal });
            //var verticalBar = panel.Add(new StackPanel(5));
            //uiLayer.Add(new BackgroundView(verticalBar));

            // time controls

            var timePanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal });
            uiLayer.Add(new BackgroundView(timePanel));

            // camera
            var cameraMode = Add(new ToolUI());
            cameraMode.Add(new EditorCameraController());

            // editor mode / game mode switch

            var toolMode = new ToggleComponent(v =>
            {
                UI.ToolMode.Set(v);
                Hgl.Time.IsPaused = v;
                gui.Scene.IsFocusable = v;
                uiLayer.IsEnabled = v;
            });

            var pauseButton = timePanel.Add(new ToggleButton(toolMode) { Size = _buttonSize });
            uiLayer.Add(new ToggleButonView(pauseButton, DataPack.Textures.Studio.Pause, DataPack.Textures.Studio.Play));
            //Add(new PropertyRecorder<bool>("toolMode", toolMode));
            Add(new KeyBinding(Keys.Tab, toolMode.Toggle));
            Add(new KeyBinding(Keys.Q, Hgl.Time.TogglePause));

            // next frame

            var nextFrameButton = timePanel.Add(new Button(() => NextFrame(pauseButton)) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(nextFrameButton, DataPack.Textures.Studio.NextFrame));
            Add(new KeyBinding(Keys.E, nextFrameButton));

            // slow motion

            var slowMo = Add(new SlowMotion(pauseButton));
            var slowMoButton = timePanel.Add(new Button(slowMo.Start, slowMo.Stop) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(slowMoButton, DataPack.Textures.Studio.SlowMotion));
            Add(new KeyBinding(Keys.R, slowMoButton));

            // sequence

            var seqPanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal });
            uiLayer.Add(new BackgroundView(seqPanel));

            var previousButton = seqPanel.Add(new Button(sequence.Previous) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(previousButton, DataPack.Textures.Studio.Previous));
            Add(new KeyBinding(Keys.OemMinus, previousButton));

            var nextButton = seqPanel.Add(new Button(sequence.Next) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(nextButton, DataPack.Textures.Studio.Next));
            Add(new KeyBinding(Keys.OemPlus, nextButton));

            var reloadButton = seqPanel.Add(new Button(() => ReloadCurrentScene(sequence)) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(reloadButton, DataPack.Textures.Studio.Reload));
            Add(new KeyBinding(Keys.Back, reloadButton));

            // tool bar

            var toolBar = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal });
            uiLayer.Add(new BackgroundView(toolBar));

            // camera home position

            var homePosition = new Property<Vector2>();
            uiLayer.Add(new PropertyRecorder<Vector2>("homePosition", homePosition));
            uiLayer.Add(new KeyBinding(Keys.End, () => homePosition.Set(Render.Camera.Position)));
            uiLayer.Add(new KeyBinding(Keys.Home, () => Render.Camera.Position = homePosition.Get()));

            // grid

            var grid = new Node
                       {
                           new Grid(Color.White, size: .1f, minZoomLevel: .02f, fullZoomLevel: 9f),
                           new Grid(Color.White, size: 1, minZoomLevel: .008f, fullZoomLevel: .8f),
                           new Grid(Color.White, size: 10, minZoomLevel: .005f, fullZoomLevel: .1f),
                           new Grid(Color.White, size: 100, minZoomLevel: .001f, fullZoomLevel: .01f),
                           new Grid(Color.White, size: 1000, minZoomLevel: .0001f, fullZoomLevel: .001f),
                       };

            var gridSwitch = new ToggleComponent(() => gridLayer.Add(grid), () => gridLayer.Remove(grid));
            var gridControl = toolBar.Add(new ToggleButton(gridSwitch) { Size = _buttonSize });
            Add(gridControl);
            uiLayer.Add(new ToggleButonView(gridControl, DataPack.Textures.Studio.Grid));
            Add(new PropertyRecorder<bool>("gridState", gridControl));
            Add(new KeyBinding(Keys.G, gridControl.Toggle));

            // annotation

            Add(Annotate.Update);
            var annotation = new ToggleComponent(() => annotationLayer.Add(Annotate.Layer), () => annotationLayer.Remove(Annotate.Layer));
            var annotationControl = toolBar.Add((new ToggleButton(annotation) { Size = _buttonSize }));
            Add(annotationControl);
            uiLayer.Add(new ToggleButonView(annotationControl, DataPack.Textures.Studio.Annotate));
            Add(new PropertyRecorder<bool>("showAnnotations", annotationControl));
            Add(new KeyBinding(Keys.V, annotationControl.Toggle));

            // live coding

            var liveCodingSwitch = toolBar.Add(new ToggleButton(true, v => LiveComponent.AutoRecompile = v) { Size = _buttonSize });
            uiLayer.Add(new ToggleButonView(liveCodingSwitch, DataPack.Textures.Studio.LiveCoding));
            Add(new KeyBinding(Keys.L, liveCodingSwitch.Toggle));

            // auto-pause on window lost focus
            /*
            var autoPause = Add(new PauseAuto(pauseButton));
            var autoPauseSwitch = toolBar.Add(new CheckBox(autoPause) { Size = _buttonSize });
            uiLayer.Add(new IconUI.ToggleButon(autoPauseSwitch, DataPack.Textures.Studio.AutoPause));
            Add(new KeyBinding(Keys.OemTilde, autoPauseSwitch.Toggle));
            */

            // serialization

            var savePanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal });
            uiLayer.Add(new BackgroundView(savePanel));

            var saveButton = savePanel.Add(new Button(studio.Serialize) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(saveButton, DataPack.Textures.Studio.Save));
            Add(new KeyBinding(Keys.F6, saveButton));

            var loadButton = savePanel.Add(new Button(studio.Unserialize) { Size = _buttonSize });
            uiLayer.Add(new PressButtonView(loadButton, DataPack.Textures.Studio.Load));
            Add(new KeyBinding(Keys.F7, loadButton));

            // edition tools

            //var polytool = new PolyEditor();
            //UIFocusableControl currentTool;
            //var polyButton = verticalBar.Add(new ToggleButton(v => { if (v) currentTool = polytool; }) { Size = _buttonSize });
            //var toolButtons = new ToggleButtonList { polyButton };

            // tree

            /*var tree = new Tree();
            uiLayer.Add(tree);*/

            // inspector

            _inspector = new Inspector();
            gui.Scene.NodeSelected += _inspector.Inspect;
            //tree.NodeSelected += _inspector.Inspect;
            uiLayer.Add(_inspector);

            // debug

            //Add(new Watch());
            Add(new FpsCounter(DataPack.Fonts.StudioFont));

            // cursor
            _focusCursor = uiLayer.Add(new Cursor(DataPack.Textures.Cursors.Link)
            {
                IsVisible = false,
                Offset = new Vector2(-5, 0)
            });
            gui.InteractionFocusedChanged += SetFocusCursor;
        }
Beispiel #2
0
 private void CreateSequence(Layer layer)
 {
     _sequence = layer.Add(new Sequence { Loop = true });
     Add(new SequenceStateRecorder(_sequence));
 }