diff --git a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs index 1d71098f..99cb4972 100644 --- a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs +++ b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs @@ -56,6 +56,8 @@ namespace PckStudio.Forms.Editor private readonly List _tiles; private AtlasTile _selectedTile; + // the "parent" tile for tiles that share name; i.e. parts of water_flow + private AtlasTile dataTile; private sealed class AtlasTile { internal readonly int Index; @@ -137,18 +139,20 @@ namespace PckStudio.Forms.Editor if (_tiles is null || !_tiles.IndexInRange(index) || (_selectedTile = _tiles[index]) is null) return; - if(string.IsNullOrEmpty(_selectedTile.Tile.DisplayName)) - { - // changes the selected tile to the base flowing tile (carries all properties over) - Matt - _selectedTile = _tiles.Find(t => t.Tile.InternalName == _selectedTile.Tile.InternalName); - } + dataTile = _selectedTile; - tileNameLabel.Text = $"{_selectedTile.Tile.DisplayName}"; + if (string.IsNullOrEmpty(dataTile.Tile.DisplayName)) + { + dataTile = _tiles.Find(t => t.Tile.InternalName == _selectedTile.Tile.InternalName); + } + + selectTilePictureBox.Image = dataTile.Texture; + tileNameLabel.Text = $"{dataTile.Tile.DisplayName}"; selectTilePictureBox.BlendColor = GetBlendColor(); selectTilePictureBox.UseBlendColor = applyColorMaskToolStripMenuItem.Checked; bool hasAnimation = - _pckFile.TryGetValue($"res/textures/{_atlasType}/{_selectedTile.Tile.InternalName}.png", PckFileType.TextureFile, out var animationFile); + _pckFile.TryGetValue($"res/textures/{_atlasType}/{dataTile.Tile.InternalName}.png", PckFileType.TextureFile, out var animationFile); animationButton.Text = hasAnimation ? "Edit Animation" : "Create Animation"; replaceButton.Enabled = !hasAnimation; @@ -158,16 +162,24 @@ namespace PckStudio.Forms.Editor { var animation = AnimationHelper.GetAnimationFromFile(animationFile); selectTilePictureBox.Start(animation); - return; } - if (variantComboBox.Enabled = variantLabel.Visible = variantComboBox.Visible = _selectedTile.Tile.HasColourEntry && _selectedTile.Tile.ColourEntry.Variants.Length > 1) + if (variantComboBox.Enabled = variantLabel.Visible = variantComboBox.Visible = + dataTile.Tile.HasColourEntry && dataTile.Tile.ColourEntry.Variants.Length > 1) { - variantComboBox.Items.AddRange(_selectedTile.Tile.ColourEntry.Variants); - variantComboBox.SelectedItem = _selectedTile.Tile.ColourEntry.DefaultName; + variantComboBox.Items.AddRange(dataTile.Tile.ColourEntry.Variants); + variantComboBox.SelectedItem = dataTile.Tile.ColourEntry.DefaultName; + } + else if(variantComboBox.Enabled = variantLabel.Visible = variantComboBox.Visible = + dataTile.Tile.HasColourEntry && dataTile.Tile.ColourEntry.IsWaterColour && _colourTable.WaterColors.Count > 0) + { + foreach (var col in _colourTable.WaterColors) + { + variantComboBox.Items.Add(col.Name); + } + + variantComboBox.SelectedItem = _colourTable.WaterColors[0].Name; } - - selectTilePictureBox.Image = _selectedTile.Texture; } private static int GetSelectedImageIndex( @@ -291,18 +303,21 @@ namespace PckStudio.Forms.Editor private Color GetBlendColor() { - if (_selectedTile.Tile.HasColourEntry && _selectedTile.Tile.ColourEntry is not null) - return FindBlendColorByKey(_selectedTile.Tile.ColourEntry.DefaultName); + if (dataTile.Tile.HasColourEntry && dataTile.Tile.ColourEntry is not null) + { + var col = FindBlendColorByKey(dataTile.Tile.ColourEntry.DefaultName); + return col; + } return Color.White; } private Color FindBlendColorByKey(string colorKey) { if (_colourTable is not null && - _selectedTile.Tile.HasColourEntry && - _selectedTile.Tile.ColourEntry is not null) + dataTile.Tile.HasColourEntry && + dataTile.Tile.ColourEntry is not null) { - if (_selectedTile.Tile.ColourEntry.IsWaterColour && + if (dataTile.Tile.ColourEntry.IsWaterColour && _colourTable.WaterColors.FirstOrDefault(entry => entry.Name == colorKey) is ColorContainer.WaterColor waterColor) { return waterColor.SurfaceColor; @@ -408,6 +423,8 @@ namespace PckStudio.Forms.Editor } AnimationHelper.SaveAnimationToFile(file, animation); + // so animations can automatically update upon saving + SelectedIndex = _selectedTile.Index; } private void extractTileToolStripMenuItem_Click(object sender, EventArgs e) @@ -425,13 +442,20 @@ namespace PckStudio.Forms.Editor private void variantComboBox_SelectedIndexChanged(object sender, EventArgs e) { - if (_selectedTile.Tile.ColourEntry is not null && - _selectedTile.Tile.ColourEntry.Variants.IndexInRange(variantComboBox.SelectedIndex)) + if (dataTile.Tile.ColourEntry is not null && + dataTile.Tile.ColourEntry.Variants.IndexInRange(variantComboBox.SelectedIndex)) { - string colorKey = _selectedTile.Tile.ColourEntry.Variants[variantComboBox.SelectedIndex]; + string colorKey = dataTile.Tile.ColourEntry.IsWaterColour ? variantComboBox.SelectedValue.ToString() : dataTile.Tile.ColourEntry.Variants[variantComboBox.SelectedIndex]; selectTilePictureBox.BlendColor = FindBlendColorByKey(colorKey); - selectTilePictureBox.Image = _selectedTile.Texture; + selectTilePictureBox.Image = dataTile.Texture; } + else if(dataTile.Tile.ColourEntry is not null && + dataTile.Tile.ColourEntry.IsWaterColour) + { + string colorKey = variantComboBox.GetItemText(variantComboBox.SelectedItem); + selectTilePictureBox.BlendColor = FindBlendColorByKey(colorKey); + selectTilePictureBox.Image = dataTile.Texture; + } } private void applyColorMaskToolStripMenuItem_CheckedChanged(object sender, EventArgs e)