Пример #1
0
        protected override PlatformContext CreateContext()
        {
            PlatformContext context;

            if (!File.Exists(DefaultContext))
            {
                File.Copy(@"Content\Maps\default.ctx", DefaultContext);
            }
            context = BinPlatformContextSerializer.Load(DefaultContext);

            context.Camera  = this.Camera;
            context.Enabled = false;
            return(context);
        }
Пример #2
0
        protected override PlatformContext CreateContext()
        {
            PlatformContext context;

            if (File.Exists(PlatformEditorScene.DefaultContext))
            {
                context = BinPlatformContextSerializer.Load(PlatformEditorScene.DefaultContext);
            }
            else
            {
                context = BinPlatformContextSerializer.Load(@"Content\Maps\default.ctx");
            }
            context.Camera = this.Camera;
            return(context);
        }
Пример #3
0
        private void SetUpUI()
        {
            this.currentUI = null;
            if (this.mainMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.mainMenu);
            }
            if (this.contextMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.contextMenu);
            }
            this.mainMenu = new PanelTabs();
            this.mainMenu.SetAnchor(Anchor.Center);
            this.mainMenu.Size    = new Vector2(1400, 1000);
            this.mainMenu.Visible = false;

            // file menu
            var fileMenu    = (this.mainMenu as PanelTabs).AddTab("File", PanelSkin.Default);
            var newMapPanel = new Panel(new Vector2(800, 120), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var newMapWidth = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(200, 100));

            newMapWidth.Value = $"{this.Context.Map.Width}";
            newMapPanel.AddChild(newMapWidth);
            var newMapHeight = new TextInput(false, anchor: Anchor.Center, size: new Vector2(200, 100));

            newMapHeight.Value = $"{this.Context.Map.Height}";
            newMapPanel.AddChild(newMapHeight);
            var newMapButton = new Button("New", anchor: Anchor.CenterRight, size: new Vector2(200, 100));

            newMapButton.OnClick += (e) =>
            {
                int width;
                int height;
                if (!int.TryParse(newMapWidth.Value, out width))
                {
                    return;
                }
                if (!int.TryParse(newMapHeight.Value, out height))
                {
                    return;
                }
                this.Context.Reset();
                this.Context.Map = new TileMap(width, height);
            };
            newMapPanel.AddChild(newMapButton);
            fileMenu.panel.AddChild(newMapPanel);

            var processButton = new Button("Process", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));

            processButton.OnClick += (b) =>
            {
                var processor = new PFPTMapProcessor();
                processor.Process(this.Context.Map);
            };
            fileMenu.panel.AddChild(processButton);

            /*var saveBlockStoreButton = new Button("Save BlockStore", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveBlockStoreButton.OnClick += (b) =>
             * {
             *  this.SaveBlockStore();
             * };
             * fileMenu.panel.AddChild(saveBlockStoreButton);*/

            /*var saveContextButton = new Button("Save context", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveContextButton.OnClick += (b) =>
             * {
             *  BinPlatformContextSerializer.Save("default.ctx", this.Context);
             * };
             * fileMenu.panel.AddChild(saveContextButton);*/

            // 'save map' area
            var savePanel = new Panel(new Vector2(600, 100), skin: PanelSkin.Simple, anchor: Anchor.BottomLeft);

            var filenameInput = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(300, 0));

            filenameInput.Value = DefaultContext;
            savePanel.AddChild(filenameInput);

            var saveButton = new Button("Save", anchor: Anchor.CenterRight, size: new Vector2(200, 0));

            saveButton.OnClick += (b) =>
            {
                var filename = filenameInput.Value.Trim();
                if (string.IsNullOrEmpty(filename))
                {
                    return;
                }
                if (!filename.EndsWith(".ctx", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename           += ".ctx";
                    filenameInput.Value = filename;
                }
                BinPlatformContextSerializer.Save(filenameInput.TextParagraph.Text, this.Context);
            };
            savePanel.AddChild(saveButton);
            fileMenu.panel.AddChild(savePanel);

            // quit button
            var quitButton = new Button("Quit", anchor: Anchor.BottomRight, size: new Vector2(400, 100));

            quitButton.OnClick += (b) =>
            {
                this.SceneEnded = true;
            };
            fileMenu.panel.AddChild(quitButton);

            // tiles menu
            var tilesMenu  = (this.mainMenu as PanelTabs).AddTab("Tiles", PanelSkin.Default);
            var tilePicker = new TilePicker(
                this.Context.BlockStore,
                this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                anchor: Anchor.CenterLeft,
                size: new Vector2(1000, 0));

            tilesMenu.panel.AddChild(tilePicker);
            var tileSettingsPanel = new Panel(new Vector2(300, 0), skin: PanelSkin.Simple, anchor: Anchor.CenterRight);

            tilesMenu.panel.AddChild(tileSettingsPanel);
            tilePicker.OnItemClick += (e, tile) =>
            {
                var curr = new TileStencil();
                curr[0, 0] = tile;
                this.mode  = new TilePlacement(curr, this.lastLayer);
                tileSettingsPanel.ClearChildren();
                var asTile = tile as Tile;
                if (asTile != null)
                {
                    var flagsLabel = new Label("Flags:", anchor: Anchor.AutoInline);
                    tileSettingsPanel.AddChild(flagsLabel);
                    foreach (var flag in EnumHelper.GetValues <TileFlags>())
                    {
                        if (flag == TileFlags.None)
                        {
                            continue;
                        }
                        var checkBox = new CheckBox($"{flag}", anchor: Anchor.AutoCenter);
                        checkBox.Checked        = this.Context.BlockStore[asTile.Id].HasFlag(flag);
                        checkBox.OnValueChange += (entity) =>
                        {
                            var currState = this.Context.BlockStore[asTile.Id];
                            if (checkBox.Checked)
                            {
                                currState |= flag;
                            }
                            else
                            {
                                currState &= ~flag;
                            }
                            this.Context.BlockStore[asTile.Id] = currState;
                        };
                        tileSettingsPanel.AddChild(checkBox);
                    }
                }
            };
            tilePicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...

            // stencil menu
            var stencilMenu   = (this.mainMenu as PanelTabs).AddTab("Stencils", PanelSkin.Default);
            var stencilPicker = new StencilPicker(this.Context.BlockStore, this.stencils);

            stencilPicker.OnStencilClick += (e, stencil) =>
            {
                this.mode = new TilePlacement(stencil, this.lastLayer);
            };
            stencilPicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...
            stencilMenu.panel.AddChild(stencilPicker);

            // materials menu
            var materialsMenu = (this.mainMenu as PanelTabs).AddTab("Materials", PanelSkin.Default);
            var materialList  = new SelectList(new Vector2(400, 300), anchor: Anchor.TopLeft);
            var settingsPanel = new Panel(new Vector2(600, 0), anchor: Anchor.CenterRight, skin: PanelSkin.Simple);

            materialsMenu.panel.AddChild(settingsPanel);

            foreach (var material in EnumHelper.GetValues <MaterialType>())
            {
                if (material != MaterialType.None)
                {
                    materialList.AddItem($"{material}");
                }
            }
            materialList.OnValueChange += (e) =>
            {
                var material = (MaterialType)(materialList.SelectedIndex + 1);
                settingsPanel.ClearChildren();
                var materialTilePicker = new TilePicker(
                    this.Context.BlockStore,
                    this.Context.BlockStore.Materials[material].Select(id => new Tile(id)),
                    size: new Vector2(0, 700),
                    anchor: Anchor.AutoCenter);
                settingsPanel.AddChild(materialTilePicker);
                var deleteTile = new Button("Delete tile", anchor: Anchor.AutoCenter);
                deleteTile.OnClick += (entity) =>
                {
                    var asTile = materialTilePicker.SelectedItem as Tile;
                    if (asTile != null)
                    {
                        materialTilePicker.RemoveSelected();
                        this.Context.BlockStore.Materials[material].Remove(asTile.Id);
                    }
                };
                settingsPanel.AddChild(deleteTile);
                var addTile = new Button("Add tile", anchor: Anchor.AutoCenter);
                addTile.OnClick += (entity) =>
                {
                    var materialNewTilePicker = new TilePicker(
                        this.Context.BlockStore,
                        this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                        size: new Vector2(1000, 900),
                        anchor: Anchor.TopCenter);
                    materialNewTilePicker.OnItemClick += (picker, tile) =>
                    {
                        var asTile = tile as Tile;
                        if (asTile != null)
                        {
                            this.Context.BlockStore.Materials[material].Add(asTile.Id);
                            materialTilePicker.AddItem(tile);
                        }
                        UserInterface.Active.RemoveEntity(materialNewTilePicker);
                    };
                    UserInterface.Active.AddEntity(materialNewTilePicker);
                };
                settingsPanel.AddChild(addTile);
            };
            materialsMenu.panel.AddChild(materialList);

            // lights menu
            var lightsMenu  = (this.mainMenu as PanelTabs).AddTab("Lights", PanelSkin.Default);
            var colourPanel = new Panel(new Vector2(0, 250), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var redLabel    = new Label("Red", anchor: Anchor.AutoCenter);
            var redSlider   = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            redSlider.Value = 255;
            var greenLabel  = new Label("Green", anchor: Anchor.AutoCenter);
            var greenSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            greenSlider.Value = 255;
            var blueLabel  = new Label("Blue", anchor: Anchor.AutoCenter);
            var blueSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            blueSlider.Value = 255;
            colourPanel.AddChild(redLabel);
            colourPanel.AddChild(redSlider);
            colourPanel.AddChild(greenLabel);
            colourPanel.AddChild(greenSlider);
            colourPanel.AddChild(blueLabel);
            colourPanel.AddChild(blueSlider);
            lightsMenu.panel.AddChild(colourPanel);
            var animationPanel    = new Panel(new Vector2(0, 150), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var animationLabel    = new Label("Animation", anchor: Anchor.AutoCenter);
            var animationDropdown = new DropDown(Vector2.Zero, anchor: Anchor.AutoCenter);

            animationDropdown.AddItem("None");
            animationDropdown.AddItem("Candle");
            animationDropdown.SelectedIndex = 0;
            animationPanel.AddChild(animationLabel);
            animationPanel.AddChild(animationDropdown);
            lightsMenu.panel.AddChild(animationPanel);
            var lightTypeDropdown = new DropDown(new Vector2(0, 100), anchor: Anchor.AutoCenter);

            lightTypeDropdown.AddItem("Ambient");
            lightTypeDropdown.AddItem("Specular");
            lightTypeDropdown.SelectedIndex = 0;
            lightsMenu.panel.AddChild(lightTypeDropdown);

            var updateButton = new Button("Set Light", anchor: Anchor.BottomCenter);

            updateButton.OnClick += (e) =>
            {
                var light = new Light();
                switch (animationDropdown.SelectedIndex)
                {
                case 0:
                    light.animation = null;
                    break;

                case 1:
                    light.animation = Light.Candle;
                    break;

                default:
                    light.animation = null;
                    break;
                }
                light.LightType = (Light.Type)lightTypeDropdown.SelectedIndex;
                light.Colour    = new Color(redSlider.Value, greenSlider.Value, blueSlider.Value);
                this.mode       = new LightPlacement(light);
            };
            lightsMenu.panel.AddChild(updateButton);

            // other placeable items
            var otherMenu      = (this.mainMenu as PanelTabs).AddTab("Other", PanelSkin.Default);
            var setSpawnButton = new Button("Set Spawn Locations", anchor: Anchor.AutoCenter);

            setSpawnButton.OnClick += (e) =>
            {
                this.mode = new SpawnPlacement(new Spawn());
            };
            otherMenu.panel.AddChild(setSpawnButton);

            UserInterface.Active.AddEntity(this.mainMenu);
        }