// -------------------------------------------------------------------
        // listBoxRelief_Click
        // -------------------------------------------------------------------

        private void listBoxRelief_Click(object sender, EventArgs e)
        {
            SystemTileset           tileset = (SystemTileset)listBoxTilesets.GetListBox().SelectedItem;
            DialogAddingReliefsList dialog  = new DialogAddingReliefsList("Choose relief", Control.Model.Tilesets, tileset);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Control.Model.Tilesets.Reliefs = dialog.GetListReliefs();
                tileset.Reliefs   = dialog.GetListTileset();
                tileset.ReliefTop = dialog.GetListReliefsTop();
                for (int i = 0; i < listBoxTilesets.GetListBox().Items.Count; i++)
                {
                    SystemTileset cpTileset = (SystemTileset)listBoxTilesets.GetListBox().Items[i];
                    List <int>    list      = new List <int>();
                    for (int j = 0; j < cpTileset.Reliefs.Count; j++)
                    {
                        list.Add(cpTileset.Reliefs[j]);
                    }
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j] > Control.Model.Tilesets.Reliefs.Count)
                        {
                            cpTileset.Reliefs.Remove(list[j]);
                        }
                    }
                }
                SetCommonTilesetList(tileset);
            }
        }
        // -------------------------------------------------------------------
        // textBoxGraphic_SelectedValueChanged
        // -------------------------------------------------------------------

        public void textBoxGraphic_SelectedValueChanged(object sender, EventArgs e)
        {
            SystemTileset tileset = (SystemTileset)listBoxTilesets.GetListBox().SelectedItem;

            tileset.Graphic = textBoxGraphic.Graphic;
            collisionSettings.InitializeParameters(tileset.Collision, tileset.Graphic);
        }
        // -------------------------------------------------------------------
        // listBoxTilesets_SelectedIndexChanged
        // -------------------------------------------------------------------

        public void listBoxTilesets_SelectedIndexChanged(object sender, EventArgs e)
        {
            SystemTileset tileset = (SystemTileset)listBoxTilesets.GetListBox().SelectedItem;

            if (tileset != null)
            {
                textBoxTilesetName.Text = tileset.Name;
                textBoxGraphic.InitializeParameters(tileset.Graphic);
                collisionSettings.InitializeParameters(tileset.Collision, tileset.Graphic);
                SetCommonTilesetList(tileset);
            }
        }
        // -------------------------------------------------------------------
        // AddMountain
        // -------------------------------------------------------------------

        public bool AddMountain(int[] coords, int newId, Mountain newMountain)
        {
            bool modified = false;
            int  height   = WANOK.GetCoordsPixelHeight(coords);

            object[] before = ContainsMountain(height, coords);

            // Remplacing
            if (before == null)
            {
                modified = true;
            }
            else
            {
                int      beforeId       = (int)before[0];
                Mountain beforeMountain = (Mountain)before[1];
                if (beforeId != newId)
                {
                    modified = true;
                }
                Mountains[height].Remove(coords, beforeId, height);
            }

            if (!Mountains.ContainsKey(height))
            {
                Mountains[height] = new Mountains();
            }
            Mountains[height].Add(coords, newId, newMountain, height);

            SystemTileset tileset = MapEditor.GetMapTileset();

            object[] reliefTop = tileset.ReliefTop[tileset.Reliefs.IndexOf(newId)];


            switch ((DrawType)reliefTop[0])
            {
            case DrawType.Floors:
                AddFloor(new int[] { coords[0], coords[1] + newMountain.SquareHeight, coords[2] + newMountain.PixelHeight, coords[3] }, (int[])reliefTop[1]);
                break;

            case DrawType.Autotiles:
                int id = ((int[])reliefTop[1])[0];
                if (id > 0)
                {
                    AddAutotile(new int[] { coords[0], coords[1] + newMountain.SquareHeight, coords[2] + newMountain.PixelHeight, coords[3] }, id, true);
                }
                break;
            }


            return(modified);
        }
Exemplo n.º 5
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------

        public DialogAddingReliefsList(string text, TilesetsDatas model, SystemTileset tileset) : base(text, model, tileset.Reliefs, typeof(SystemRelief))
        {
            Tileset    = tileset;
            ReliefsTop = tileset.CreateReliefTopCopy();
            Model      = model;
            TextBoxVariable.InitializeParameters(new object[] { 0, 0, 1, 1 }, new List <object>(new object[] { Tileset.Graphic }), typeof(DialogTileset), WANOK.GetStringTileset);
            ComboBoxAutotile.Dock = DockStyle.Fill;
            ComboBoxAutotile.FillComboBox(Tileset.Autotiles, Model.GetAutotileById, Model.GetAutotileIndexById, 0);

            // Radios
            Radios[DrawType.None]           = new RadioButton();
            Radios[DrawType.None].Text      = "None";
            Radios[DrawType.Floors]         = new RadioButton();
            Radios[DrawType.Floors].Text    = "Floor";
            Radios[DrawType.Autotiles]      = new RadioButton();
            Radios[DrawType.Autotiles].Text = "Autotile";

            // Fill boxes
            listBoxComplete.GetListBox().SelectedIndexChanged += listBoxComplete_SelectedIndexChanged;
            listBoxComplete.InitializeListParameters(true, WANOK.GetSuperListItem(model.Reliefs.Cast <SuperListItem>().ToList()), null, Type, 1, SystemRelief.MAX_RELIEFS);
            List <SuperListItem> modelTileset = new List <SuperListItem>();

            for (int i = 0; i < tileset.Reliefs.Count; i++)
            {
                modelTileset.Add(model.GetReliefById(tileset.Reliefs[i]));
            }
            listBoxTileset.GetListBox().SelectedIndexChanged += ListBoxTileset_SelectedIndexChanged;
            listBoxTileset.InitializeListParameters(true, modelTileset, null, Type, 0, 0, false);

            // PictureRelief
            PictureBox.SizeMode          = PictureBoxSizeMode.StretchImage;
            PictureBox.InterpolationMode = InterpolationMode.NearestNeighbor;
            PicturePanel.AutoScroll      = true;
            PicturePanel.Dock            = DockStyle.Fill;
            PicturePanel.BackColor       = System.Drawing.Color.FromArgb(227, 227, 227);
            PicturePanel.Controls.Add(PictureBox);

            // Floor Panel
            RadioPanel.Dock        = DockStyle.Fill;
            RadioPanel.RowCount    = 3;
            RadioPanel.ColumnCount = 2;
            RadioPanel.Controls.Add(Radios[DrawType.None], 0, 0);
            RadioPanel.Controls.Add(Radios[DrawType.Floors], 0, 1);
            RadioPanel.Controls.Add(Radios[DrawType.Autotiles], 0, 2);
            RadioPanel.Controls.Add(new Panel(), 1, 0);
            RadioPanel.Controls.Add(TextBoxVariable, 1, 1);
            RadioPanel.Controls.Add(ComboBoxAutotile, 1, 2);
            RadioPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 25));
            RadioPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 29));
            RadioPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 25));
            RadioPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            RadioPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
            FloorPanel.Dock        = DockStyle.Fill;
            FloorPanel.RowCount    = 2;
            FloorPanel.ColumnCount = 1;
            GrowLabel label = new GrowLabel();

            label.Dock = DockStyle.Fill;
            label.Text = "Choose what kind of floor there is on top of a mountains/slopes:";
            FloorPanel.Controls.Add(label, 0, 0);
            FloorPanel.Controls.Add(RadioPanel, 0, 1);
            FloorPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 15));
            FloorPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));

            // Setting layout
            LayoutPanel.Dock        = DockStyle.Fill;
            LayoutPanel.RowCount    = 1;
            LayoutPanel.ColumnCount = 1;
            LayoutPanel.Controls.Add(PicturePanel, 0, 0);
            LayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            PanelOther.Controls.Add(LayoutPanel);
            tableLayoutPanel8.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            tableLayoutPanel8.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            tableLayoutPanel8.Controls.Add(FloorPanel, 0, 1);
            FloorPanel.Visible = listBoxTileset.GetListBox().Items.Count > 0;

            // Events
            textBoxGraphic.GetTextBox().SelectedValueChanged += textBoxGraphic_SelectedValueChanged;
            listBoxComplete.GetListBox().MouseDown           += listBoxComplete_SelectedIndexChanged;
            listBoxComplete.GetButton().Click += listBoxComplete_Click;
            buttonDelete.Click += ButtonDelete_Click;
            Radios[DrawType.None].CheckedChanged      += RadioCheckedNone;
            Radios[DrawType.Floors].CheckedChanged    += RadioCheckedFloor;
            Radios[DrawType.Autotiles].CheckedChanged += RadioCheckedAutotile;
            ComboBoxAutotile.SelectedIndexChanged     += ComboBoxAutotileSelectedIndexChanged;
            buttonAdd.Click += ButtonAdd_Click;
            listBoxComplete.GetListBox().DoubleClick          += ListBoxComplete_DoubleClick;
            TextBoxVariable.GetTextBox().SelectedValueChanged += TextVariable_SelectedValueChanged;
            listBoxTileset.GetListBox().DragDrop  += ListBoxTileset_DragDrop;
            listBoxTileset.GetListBox().MouseDown += ListBoxTileset_SelectedIndexChanged;
        }
Exemplo n.º 6
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------

        public TilesetsDatas()
        {
            TilesetsList = SystemTileset.GetDefaultTilesets();
            Autotiles    = SystemAutotile.GetDefaultAutotiles();
            Reliefs      = SystemRelief.GetDefaultReliefs();
        }
        // -------------------------------------------------------------------
        // HEROES
        // -------------------------------------------------------------------

        #region Heroes



        #endregion

        // -------------------------------------------------------------------
        // TILESETS
        // -------------------------------------------------------------------

        #region Tilesets

        // -------------------------------------------------------------------
        // SetCommonTilesetList
        // -------------------------------------------------------------------

        public void SetCommonTilesetList(SystemTileset tileset)
        {
            listBoxAutotiles.InitializeListParameters(false, Control.Model.Tilesets, Control.Model.Tilesets.Autotiles.Cast <SuperListItem>().ToList(), tileset.Autotiles, typeof(DialogAddingAutotilesList), typeof(SystemAutotile), 1, SystemAutotile.MAX_AUTOTILES, Control.Model.Tilesets.GetAutotileById);
            listBoxRelief.InitializeListParameters(false, Control.Model.Tilesets, Control.Model.Tilesets.Reliefs.Cast <SuperListItem>().ToList(), tileset.Reliefs, typeof(DialogAddingReliefsList), typeof(SystemRelief), 1, SystemRelief.MAX_RELIEFS, Control.Model.Tilesets.GetReliefById);
        }
Exemplo n.º 8
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------

        public Map(GraphicsDevice device, string mapName)
        {
            Device = device;
            Stopwatch sw = new Stopwatch();
            bool      dialogOpened = false, newTemp = false;

            sw.Start();

            // Temp files + mapInfos
            string pathTemp = Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp");

            if (Directory.GetFiles(pathTemp).Length == 0)
            {
                newTemp = true;
                string[] filePaths = Directory.GetFiles(Path.Combine(WANOK.MapsDirectoryPath, mapName));
                foreach (string filePath in filePaths)
                {
                    File.Copy(filePath, Path.Combine(pathTemp, Path.GetFileName(filePath)));
                }
            }

            MapInfos = WANOK.LoadBinaryDatas <MapInfos>(Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp", "infos.map"));
            Events   = WANOK.LoadBinaryDatas <Events>(Path.Combine(WANOK.MapsDirectoryPath, mapName, "temp", "events.map"));
            Saved    = !WANOK.ListMapToSave.Contains(mapName);
            if (newTemp)
            {
                WANOK.CreateCancelMap(MapInfos.RealMapName);
            }

            // Start position
            if (mapName == WANOK.Game.System.StartMapName)
            {
                SetStartInfos(WANOK.Game.System, WANOK.Game.System.StartPosition);
            }

            // Event position
            EventSquare = new Square(Device, MapEditor.TexEventSelectCursor, new int[] { 0, 0, WANOK.BASIC_SQUARE_SIZE, WANOK.BASIC_SQUARE_SIZE });

            // Dispose textures
            if (MapEditor.TexTileset != null)
            {
                MapEditor.TexTileset.Dispose();
                MapEditor.TexTileset = null;
            }
            foreach (int i in MapEditor.TexAutotiles.Keys)
            {
                MapEditor.TexAutotiles[i].Dispose();
            }
            MapEditor.TexAutotiles.Clear();
            foreach (int i in MapEditor.TexReliefs.Keys)
            {
                MapEditor.TexReliefs[i].Dispose();
            }
            MapEditor.TexReliefs.Clear();
            foreach (Texture2D texture in MapEditor.TexCharacters.Values)
            {
                texture.Dispose();
            }
            MapEditor.TexCharacters.Clear();

            // Loading textures
            SystemTileset tileset = WANOK.Game.Tilesets.GetTilesetById(MapInfos.Tileset);

            MapEditor.TexTileset = tileset.Graphic.LoadTexture(device);
            for (int i = 0; i < tileset.Autotiles.Count; i++)
            {
                MapEditor.TexAutotiles[tileset.Autotiles[i]] = MapEditor.GetCharacterTexture(device, WANOK.Game.Tilesets.GetAutotileById(tileset.Autotiles[i]).Graphic.LoadTexture(Device));
            }
            for (int i = 0; i < tileset.Reliefs.Count; i++)
            {
                MapEditor.TexReliefs[tileset.Reliefs[i]] = WANOK.Game.Tilesets.GetReliefById(tileset.Reliefs[i]).Graphic.LoadTexture(Device);
            }
            LoadEventTextures();

            // Grid
            CreateGrid(MapInfos.Width, MapInfos.Height);

            // Map
            Portions       = new Dictionary <int[], GameMapPortion>(new IntArrayComparer());
            EventsPortions = new Dictionary <int[], EventsPortion>(new IntArrayComparer());
            int    count = 0;
            double coef  = (WANOK.PORTION_RADIUS + 1) * (WANOK.PORTION_RADIUS + 1) * 4;

            for (int i = -WANOK.PORTION_RADIUS - 1; i <= WANOK.PORTION_RADIUS + 1; i++)
            {
                for (int j = -WANOK.PORTION_RADIUS - 1; j <= WANOK.PORTION_RADIUS + 1; j++)
                {
                    if (!dialogOpened)
                    {
                        if (sw.ElapsedMilliseconds > 50)
                        {
                            WANOK.StartProgressBar("Loading map infos...", 0);
                            dialogOpened = true;
                        }
                    }
                    else
                    {
                        int v = (int)((count / coef) * 100);
                        if (v <= 100)
                        {
                            WANOK.DialogProgressBar.SetValue(v);
                        }
                    }
                    LoadPortion(i, j, i, j);
                    count++;
                }
            }
            sw.Stop();
            if (dialogOpened)
            {
                WANOK.DisposeProgressBar();
            }
        }