private void ShowTileCategory(Grid host, ComboBox comboBox)
        {
            string category = (string)comboBox.SelectedItem;

            this.ActiveCategory = category;
            ListBox lb = new ListBox()
            {
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch
            };
            List <Tile> tiles = TileStore.GetTilesInCategory(category);

            foreach (Tile tile in tiles)
            {
                ListBoxItem lbi = new ListBoxItem();
                StackPanel  sp  = new StackPanel()
                {
                    Orientation = System.Windows.Controls.Orientation.Horizontal
                };
                sp.Children.Add(new Image()
                {
                    Source = tile.Image, Margin = new Thickness(0, 0, 10, 0)
                });
                sp.Children.Add(new TextBlock()
                {
                    Text = tile.Name
                });
                lbi.Content = sp;
                lb.Items.Add(lbi);
            }
            lb.SelectionChanged += new SelectionChangedEventHandler(lb_SelectionChanged);
            host.Children.Add(lb);
        }
 private void InitializeTileCategoryPickerChoices()
 {
     foreach (string category in TileStore.GetSortedCategories())
     {
         this.tile_category_picker.Items.Add(category);
     }
     this.tile_category_picker.SelectionChanged += new SelectionChangedEventHandler(tile_category_picker_SelectionChanged);
 }
        void lb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox lb       = (ListBox)sender;
            string  category = this.ActiveCategory;

            if (!string.IsNullOrEmpty(category))
            {
                List <Tile> tiles = TileStore.GetTilesInCategory(category);
                int         index = lb.SelectedIndex;
                if (index >= 0)
                {
                    this.ActiveTile = tiles[index];
                }
            }
        }
        private void RefreshTileSwatches()
        {
            this.tile_swatches.Children.Clear();
            string category = (this.tile_category_picker.SelectedValue ?? "").ToString();

            if (category.Length > 0)
            {
                foreach (Tile t in TileStore.GetSortedTilesForCategory(category))
                {
                    TileSwatch ts = new TileSwatch(t);
                    ts.UpdateSelectionVisual();
                    this.tile_swatches.Children.Add(ts);
                }
            }
        }
 public MainWindow()
 {
     instance = this;
     InitializeComponent();
     TileStore.Initialize();
     try
     {
         this.InitializeTileCategoryPickerChoices();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
     this.InitializeLayerPicker(0);
     this.tile_category_picker.SelectedIndex = 0;
     this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
     this.layer_picker.SelectionChanged += new SelectionChangedEventHandler(layer_picker_SelectionChanged);
     this.AddMenuHandlers();
 }
Пример #6
0
        public MapParser(string path)
        {
            string[] rawLines = System.IO.File.ReadAllLines(path);
            Dictionary <string, string> rawValues = new Dictionary <string, string>();
            string activeKey = null;

            foreach (string line in rawLines)
            {
                string trimmedLine = line.Trim();
                if (trimmedLine.Length > 0)
                {
                    if (line[0] == '#')
                    {
                        activeKey = null;
                        if (line.Contains(':'))
                        {
                            string[]      parts        = line.Split(':');
                            string        key          = parts[0].Trim().ToLower();
                            List <string> valueBuilder = new List <string>();
                            for (int i = 1; i < parts.Length; ++i)
                            {
                                valueBuilder.Add(parts[i]);
                            }
                            string value = string.Join(":", valueBuilder);
                            rawValues[key] = value;
                        }
                        else
                        {
                            activeKey = line.Substring(1);
                        }
                    }
                    else
                    {
                        if (rawValues.ContainsKey(activeKey))
                        {
                            rawValues[activeKey] += "\n" + line.Trim();
                        }
                        else
                        {
                            rawValues[activeKey] = line.Trim();
                        }
                    }
                }
            }

            string[] tileIds = rawValues["tiles"].Split('\n');
            this.Height = tileIds.Length;
            this.Width  = tileIds[0].Length;
            this.Tiles  = new Tile[this.Width, this.Height];
            string id;

            for (int y = 0; y < this.Height; ++y)
            {
                for (int x = 0; x < this.Width; ++x)
                {
                    id = tileIds[y][x] + "";
                    if (id == ".")
                    {
                        id = "";
                    }
                    if (id.Length > 0)
                    {
                        this.Tiles[x, y] = TileStore.GetTile(id);
                    }
                }
            }
        }
Пример #7
0
        private bool ParseTiles()
        {
            this.layers = this.InitializeLayers(this.Width, this.Height, true);

            foreach (string layer in "A B C D E F Stairs".Split(' '))
            {
                string layerName = "Layer" + layer;
                if (this.values.ContainsKey(layerName))
                {
                    string[] spots = this.values[layerName].Trim().Split(',');
                    if (spots.Length != this.Width * this.Height)
                    {
                        System.Windows.MessageBox.Show(layerName + " didn't have the correct number of tiles in it");
                        return(false);
                    }
                    else
                    {
                        int index = 0;
                        foreach (string spot in spots)
                        {
                            // Base BaseAdorn BaseDetail Doodad DoodadAdorn Excessive
                            string[] tiles = spot.Split('|');
                            if (tiles.Length != 6)
                            {
                                System.Windows.MessageBox.Show(layerName + " has a tile without the correct number of ids in the stack");
                                return(false);
                            }
                            else
                            {
                                for (int i = 0; i < 6; ++i)
                                {
                                    string name = "";
                                    switch (i)
                                    {
                                    case 0: name = "Base"; break;

                                    case 1: name = "BaseAdorn"; break;

                                    case 2: name = "BaseDetail"; break;

                                    case 3: name = "Doodad"; break;

                                    case 4: name = "DoodadAdorn"; break;

                                    case 5: name = "Excessive"; break;

                                    default: break;
                                    }

                                    string tileId = tiles[i].Trim();
                                    Tile   t      = null;
                                    if (tileId != "")
                                    {
                                        t = TileStore.Get(tileId);
                                    }
                                    this.layers[layer][name][index] = t;
                                }
                            }
                            ++index;
                        }
                    }
                }
            }

            return(true);
        }
Пример #8
0
        public Level(string name, bool overwrite)
        {
            this.Name    = name;
            this.IsDirty = false;
            string filepath = "data/levels/" + name + ".txt";

            if (overwrite && FileStuff.Exists(filepath))
            {
                System.Windows.MessageBox.Show("Warning: a level with this name already exists. Saving this level will overwrite that level.");
            }

            string contents = overwrite ? "" : FileStuff.ReadFile(filepath);

            foreach (string line in contents.Split('\n'))
            {
                string formattedLine = line.Trim();
                if (formattedLine.Length > 0 && formattedLine[0] == '#')
                {
                    string[] parts = formattedLine.Substring(1).Split(':');
                    if (parts.Length > 1)
                    {
                        string key   = parts[0];
                        string value = parts[1];
                        for (int i = 2; i < parts.Length; ++i)
                        {
                            value += ":" + parts[i];
                        }
                        this.values[key] = value;
                    }
                }
            }

            int  width     = 12;
            int  height    = 12;
            bool loadTiles =
                this.values.ContainsKey("width") &&
                this.values.ContainsKey("height") &&
                int.TryParse(this.values["width"], out width) &&
                int.TryParse(this.values["height"], out height) &&
                this.values.ContainsKey("tiles");

            this.Width  = width;
            this.Height = height;

            this.Grid = new List <Tile> [width * height];
            if (loadTiles)
            {
                string[] rawTileColumns = this.values["tiles"].Split(',');

                for (int i = 0; i < width * height; ++i)
                {
                    List <Tile> tileStack     = new List <Tile>();
                    string[]    rawTileColumn = rawTileColumns[i].Split('|');
                    if (rawTileColumn.Length > 0 && rawTileColumn[0].Length > 0)
                    {
                        foreach (string rawTileCell in rawTileColumn)
                        {
                            tileStack.Add(TileStore.GetTile(rawTileCell));
                        }
                    }
                    this.Grid[i] = tileStack;
                }
            }
            else
            {
                for (int i = 0; i < width * height; ++i)
                {
                    this.Grid[i] = new List <Tile>();
                }
            }
        }
Пример #9
0
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     this.palette.ItemsSource = TileStore.GetTiles();
 }