public static void Read(IDeserializer context, out TileStencil stencil) { stencil = new TileStencil(); foreach (var entry in context.ReadList <KeyValuePair <Point, ITile> >("tiles", Read)) { stencil[entry.Key] = entry.Value; } }
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); }
public static void Write(ISerializer context, TileStencil stencil) { context.WriteList("tiles", stencil.Tiles, Write); }
public IEnumerable <TileStencil> CreateStencils() { var stencil = new TileStencil(); stencil.AddRow(0, 500, 501, 502, 503, 504); stencil.AddRow(0, 510, 511, 512, 513, 514); stencil.AddRow(0, 520, 521, 522, 523, 524); stencil.AddRow(1, 531, 532); stencil.AddRow(1, 541, 542, 543); yield return(stencil); stencil = new TileStencil(); stencil.AddRow(2, 497, 498); stencil.AddRow(1, 506, 507, 508, 509); stencil.AddRow(0, 515, 516, 517, 518, 519); stencil.AddRow(0, 525, 526, 527, 528, 529); stencil.AddRow(2, 537, 538); stencil.AddRow(2, 547, 548); stencil.Origin = new Point(2, 5); yield return(stencil); stencil = new TileStencil(); stencil.AddRow(0, 451, 452, 453); stencil.AddRow(0, 461, 462, 463); stencil.AddRow(0, 471, 472); stencil.AddRow(0, 481, 482, 483); yield return(stencil); stencil = new TileStencil(); stencil.AddRow(0, 456, 457); stencil.AddRow(0, 466, 467); stencil.AddRow(0, 476, 477); stencil.AddRow(0, 486, 487, 488); yield return(stencil); // square door with window stencil = new TileStencil(); stencil.AddRow(0, 220, 221); stencil.AddRow(0, 232, 233); yield return(stencil); // square door, no window stencil = new TileStencil(); stencil.AddRow(0, 222, 223); stencil.AddRow(0, 232, 233); yield return(stencil); // square door with hinges stencil = new TileStencil(); stencil.AddRow(0, 242, 243); stencil.AddRow(0, 252, 253); yield return(stencil); // square door - open stencil = new TileStencil(); stencil.AddRow(0, 420, 421); stencil.AddRow(0, 430, 431); yield return(stencil); // round door, window stencil = new TileStencil(); stencil.AddRow(0, 230, 231); stencil.AddRow(0, 234, 235); yield return(stencil); // round door, no window stencil = new TileStencil(); stencil.AddRow(0, 224, 225); stencil.AddRow(0, 234, 235); yield return(stencil); // round door with hinges stencil = new TileStencil(); stencil.AddRow(0, 244, 245); stencil.AddRow(0, 254, 255); yield return(stencil); // round door - open stencil = new TileStencil(); stencil.AddRow(0, 433, 434); stencil.AddRow(0, 443, 444); yield return(stencil); // stone frame door stencil = new TileStencil(); stencil.AddRow(0, 008, 009); stencil.AddRow(0, 018, 019); yield return(stencil); // stone frame bars? stencil = new TileStencil(); stencil.AddRow(0, 015, 016); stencil.AddRow(0, 025, 026); yield return(stencil); // stone frame door - open stencil = new TileStencil(); stencil.AddRow(0, 400, 401); stencil.AddRow(0, 410, 411); yield return(stencil); // green bush (near doors on tilesheet) stencil = new TileStencil(); stencil.AddRow(0, 240, 241); stencil.AddRow(0, 250, 251); yield return(stencil); // rock stencil = new TileStencil(); stencil.AddRow(0, 70, 71); yield return(stencil); // rock stencil = new TileStencil(); stencil.AddRow(0, 75, 76); yield return(stencil); // fence 1 (left) stencil = new TileStencil(); stencil.AddRow(0, 95); stencil.AddRow(0, 105); yield return(stencil); // fence 1 (middle) stencil = new TileStencil(); stencil.AddRow(0, 96); stencil.AddRow(0, 106); yield return(stencil); // fence 1 (right) stencil = new TileStencil(); stencil.AddRow(0, 97); stencil.AddRow(0, 107); yield return(stencil); // fence 2 (left) stencil = new TileStencil(); stencil.AddRow(0, 115); stencil.AddRow(0, 125); yield return(stencil); // fence 2 (middle) stencil = new TileStencil(); stencil.AddRow(0, 116); stencil.AddRow(0, 126); yield return(stencil); // fence 2 (right) stencil = new TileStencil(); stencil.AddRow(0, 117); stencil.AddRow(0, 127); yield return(stencil); // fence 3 (stone - left) stencil = new TileStencil(); stencil.AddRow(0, 310); stencil.AddRow(0, 320); yield return(stencil); // fence 3 (stone - middle) stencil = new TileStencil(); stencil.AddRow(0, 315); stencil.AddRow(0, 325); yield return(stencil); // fence 3 (stone - right) stencil = new TileStencil(); stencil.AddRow(0, 312); stencil.AddRow(0, 322); yield return(stencil); // chimney 1 - left stencil = new TileStencil(); stencil.AddRow(0, 354); stencil.AddRow(0, 364); yield return(stencil); // chimney 1 - right stencil = new TileStencil(); stencil.AddRow(0, 355); stencil.AddRow(0, 365); yield return(stencil); // chimney 2 - left stencil = new TileStencil(); stencil.AddRow(0, 356); stencil.AddRow(0, 366); yield return(stencil); // chimney 2 - right stencil = new TileStencil(); stencil.AddRow(0, 357); stencil.AddRow(0, 367); yield return(stencil); // chimney 3 - left stencil = new TileStencil(); stencil.AddRow(0, 358); stencil.AddRow(0, 368); yield return(stencil); // chimney 3 - right stencil = new TileStencil(); stencil.AddRow(0, 359); stencil.AddRow(0, 369); yield return(stencil); // large crate stencil = new TileStencil(); stencil.AddRow(0, 351); stencil.AddRow(0, 361); yield return(stencil); // NOTE: gothic tiles start at 620 // tombstone 1 stencil = new TileStencil(); stencil.AddRow(0, 624); stencil.AddRow(0, 634); yield return(stencil); // tombstone 2 stencil = new TileStencil(); stencil.AddRow(0, 625); stencil.AddRow(0, 635); yield return(stencil); // tombstone 3 stencil = new TileStencil(); stencil.AddRow(0, 626); stencil.AddRow(0, 636); yield return(stencil); // bookshelf 1 stencil = new TileStencil(); stencil.AddRow(0, 990, 991); stencil.AddRow(0, 1000, 1001); yield return(stencil); // bookshelf 2 stencil = new TileStencil(); stencil.AddRow(0, 994, 995); stencil.AddRow(0, 1004, 1005); yield return(stencil); // bookshelf 3 stencil = new TileStencil(); stencil.AddRow(0, 996, 997); stencil.AddRow(0, 1006, 1007); yield return(stencil); // tree 5 stencil = new TileStencil(); stencil.AddRow(1, 1181, 1182, 1183); stencil.AddRow(1, 1191, 1192, 1193); stencil.AddRow(0, 1200, 1201, 1202, 1203, 1204); stencil.AddRow(1, 1211, 1212, 1213); stencil.AddRow(1, 1221, 1222, 1223, 1224); yield return(stencil); // tree 6 stencil = new TileStencil(); stencil.AddRow(2, 1187, 1188); stencil.AddRow(1, 1196, 1197, 1198, 1199); stencil.AddRow(1, 1206, 1207, 1208, 1209); stencil.AddRow(2, 1217, 1218); stencil.AddRow(0, 1225, 1226, 1227, 1228); yield return(stencil); }