public void Initialize(AbstractAsset asset)
        {
            if (asset is not AudioAsset audioAsset)
            {
                return;
            }

            AudioName.Content       = audioAsset.AssetName;
            DefaultLoudness.Content = audioAsset.PresentInDefaultLoudness ? audioAsset.DefaultLoudness.ToString(CultureInfo.InvariantCulture) : "N/A (Defaults to 1)";

            FileName.Content     = File.Exists(audioAsset.EditorPath) ? Path.GetFileName(audioAsset.EditorPath) : GuiUtils.FileNotFound;
            FileLoudness.Content = audioAsset.Loudness.ToString(CultureInfo.InvariantCulture);

            bool startPaused = !Autoplay.IsChecked ?? true;

            SongSet(audioAsset.EditorPath, (float)Pitch.Value, startPaused);

            if (Song == null)
            {
                return;
            }

            ToggleImage.Source = ((Image)Resources[startPaused ? "PlayImage" : "PauseImage"]).Source;

            Seek.Maximum = Song.PlayLength;
            Seek.Value   = 0;

            SeekText.Content  = $"{EditorUtils.ToTimeString((int)Song.PlayPosition)} / {EditorUtils.ToTimeString((int)Song.PlayLength)}";
            PitchText.Content = $"x {Song.PlaybackSpeed:0.00}";
        }
Esempio n. 2
0
        /// <summary>
        /// Loads in an asset file and saves the checksum
        /// </summary>
        private void addAssetData(AbstractAsset abstractAsset)
        {
            AssetInfo newAsset = new AssetInfo(abstractAsset.Filename, abstractAsset.Checksum);

            if (_assetList.Contains(newAsset) == false)
            {
                _assetList.Add(newAsset);
            }
        }
        public AssetRowControl(AbstractAsset asset, AssetType assetType, bool isEven, string openDialogFilter)
        {
            InitializeComponent();

            OpenDialogFilter = openDialogFilter;

            Asset              = asset;
            AssetType          = assetType;
            TextBlockTags.Text = string.Join(_tagSeparator, asset.Tags);

            Color colorEditEven = EditorUtils.FromRgbTuple(assetType.GetColor()) * 0.25f;
            Color colorEditOdd  = colorEditEven * 0.5f;
            Color colorInfoEven = colorEditOdd;
            Color colorInfoOdd  = colorEditOdd * 0.5f;

            _brushInfoEven = new SolidColorBrush(colorInfoEven);
            _brushInfoOdd  = new SolidColorBrush(colorInfoOdd);
            _brushEditEven = new SolidColorBrush(colorEditEven);
            _brushEditOdd  = new SolidColorBrush(colorEditOdd);

            UpdateGui();

            Panel.SetZIndex(RectangleInfo, -1);
            Grid.SetColumnSpan(RectangleInfo, 3);
            Grid.SetRowSpan(RectangleInfo, 2);

            Panel.SetZIndex(RectangleEdit, -1);
            Grid.SetColumn(RectangleEdit, 3);
            Grid.SetColumnSpan(RectangleEdit, 4);
            Grid.SetRowSpan(RectangleEdit, 2);

            UpdateBackgroundRectangleColors(isEven);

            Data.Children.Add(RectangleInfo);
            Data.Children.Add(RectangleEdit);

            TextBlockAssetName.Text = Asset.AssetName;

            if (Asset is ShaderAsset shaderAsset)
            {
                _shaderAsset = shaderAsset;
                BrowseButtonFragmentShader.Visibility        = Visibility.Visible;
                RemovePathButtonFragmentShader.Visibility    = Visibility.Visible;
                TextBlockEditorPathFragmentShader.Visibility = Visibility.Visible;
                RowDefinitionFragmentShader.Height           = new GridLength(24);
                Grid.SetRowSpan(TextBlockTags, 2);
            }

            if (Asset is AudioAsset audioAsset)
            {
                _audioAsset = audioAsset;
                ColumnDefinitionLoudness.Width = new GridLength(96);
                TextBoxLoudness.Visibility     = Visibility.Visible;
            }
        }
        public void UpdateAssetTabControls(List <UserAsset> userAssets)
        {
            foreach (AssetRowControl rowControl in RowControls)
            {
                AbstractAsset asset     = rowControl.Asset;
                UserAsset?    userAsset = userAssets.Find(a => a.AssetName == asset.AssetName && a.AssetType == asset.AssetType);
                if (userAsset != null)
                {
                    asset.ImportValuesFromUserAsset(userAsset);

                    rowControl.UpdateGui();
                }
            }
        }
        public void Initialize(AbstractAsset asset)
        {
            if (asset is not ModelAsset modelAsset)
            {
                return;
            }

            TextureName.Content        = modelAsset.AssetName;
            DefaultVertexCount.Content = modelAsset.DefaultVertexCount.ToString(CultureInfo.InvariantCulture);
            DefaultIndexCount.Content  = modelAsset.DefaultIndexCount.ToString(CultureInfo.InvariantCulture);

            bool isPathValid = File.Exists(modelAsset.EditorPath);

            FileName.Content = isPathValid ? Path.GetFileName(modelAsset.EditorPath) : GuiUtils.FileNotFound;

            if (isPathValid)
            {
                string[] lines = File.ReadAllLines(modelAsset.EditorPath);
                int      v     = 0;
                int      vt    = 0;
                int      vn    = 0;
                int      f     = 0;
                foreach (string line in lines)
                {
                    switch (line.Split(' ')[0])
                    {
                    case "v": v++; break;

                    case "vt": vt++; break;

                    case "vn": vn++; break;

                    case "f": f++; break;
                    }
                }

                FileVertexCount.Content = new[] { v, vt, vn }.Max().ToString(CultureInfo.InvariantCulture);
                FileIndexCount.Content  = f.ToString(CultureInfo.InvariantCulture);

                // TODO: Open in OBJ Viewer
            }
            else
            {
                FileVertexCount.Content = "N/A";
                FileIndexCount.Content  = "N/A";
            }
        }
Esempio n. 6
0
        public void Initialize(AbstractAsset asset)
        {
            ModelBindingName.Content = asset.AssetName;

            bool isPathValid = File.Exists(asset.EditorPath);

            FileName.Content = isPathValid ? Path.GetFileName(asset.EditorPath) : GuiUtils.FileNotFound;

            if (isPathValid)
            {
                PreviewTextBox.Text = File.ReadAllText(asset.EditorPath);
            }
            else
            {
                PreviewTextBox.Text = string.Empty;
            }
        }
        public void Initialize(AbstractAsset asset)
        {
            if (asset is not ParticleAsset particleAsset)
            {
                return;
            }

            ParticleName.Content = particleAsset.AssetName;

            bool isPathValid = File.Exists(particleAsset.EditorPath);

            FileName.Content = isPathValid ? Path.GetFileName(particleAsset.EditorPath) : GuiUtils.FileNotFound;

            if (isPathValid)
            {
                byte[]        bytes = File.ReadAllBytes(particleAsset.EditorPath);
                string        hex   = BitConverter.ToString(bytes).Replace("-", string.Empty, StringComparison.InvariantCulture);
                StringBuilder sb    = new StringBuilder();
                for (int i = 0; i < hex.Length; i++)
                {
                    if (i != 0)
                    {
                        if (i % 96 == 0)
                        {
                            sb.Append('\n');
                        }
                        else if (i % 8 == 0)
                        {
                            sb.Append(' ');
                        }
                    }

                    sb.Append(hex[i]);
                }

                PreviewTextBox.Text = sb.ToString();
            }
            else
            {
                PreviewTextBox.Text = string.Empty;
            }
        }
Esempio n. 8
0
        public void Initialize(AbstractAsset asset)
        {
            if (asset is not ShaderAsset shaderAsset)
            {
                return;
            }

            ShaderName.Content = shaderAsset.AssetName;

            bool isVertexPathValid   = File.Exists(shaderAsset.EditorPath);
            bool isFragmentPathValid = File.Exists(shaderAsset.EditorPathFragmentShader);

            VertexFileName.Content   = isVertexPathValid ? Path.GetFileName(shaderAsset.EditorPath) : GuiUtils.FileNotFound;
            FragmentFileName.Content = isFragmentPathValid ? Path.GetFileName(shaderAsset.EditorPathFragmentShader) : GuiUtils.FileNotFound;

            PreviewVertexTextBox.Inlines.Clear();
            PreviewFragmentTextBox.Inlines.Clear();

            if (isVertexPathValid)
            {
                string vertexCode = SanitizeCode(File.ReadAllText(shaderAsset.EditorPath));
                foreach (Piece piece in GlslParser.Instance.Parse(vertexCode))
                {
                    PreviewVertexTextBox.Inlines.Add(new Run(piece.Code)
                    {
                        Foreground = new SolidColorBrush(TranslateColor(GlslParser.Instance.CodeStyle.HighlightColors[piece.Type]))
                    });
                }
            }

            if (isFragmentPathValid)
            {
                string fragmentCode = SanitizeCode(File.ReadAllText(shaderAsset.EditorPathFragmentShader));
                foreach (Piece piece in GlslParser.Instance.Parse(fragmentCode))
                {
                    PreviewFragmentTextBox.Inlines.Add(new Run(piece.Code)
                    {
                        Foreground = new SolidColorBrush(TranslateColor(GlslParser.Instance.CodeStyle.HighlightColors[piece.Type]))
                    });
                }
            }
        }
Esempio n. 9
0
        public void Initialize(AbstractAsset asset)
        {
            if (asset is not TextureAsset textureAsset)
            {
                return;
            }

            TextureName.Content       = textureAsset.AssetName;
            DefaultDimensions.Content = $"{textureAsset.DefaultDimensions.X}x{textureAsset.DefaultDimensions.Y}";
            DefaultMipmaps.Content    = TextureAsset.GetMipmapCount(textureAsset.DefaultDimensions.X, textureAsset.DefaultDimensions.Y).ToString(CultureInfo.InvariantCulture);

            bool isPathValid = File.Exists(textureAsset.EditorPath);

            FileName.Content = isPathValid ? Path.GetFileName(textureAsset.EditorPath) : GuiUtils.FileNotFound;

            if (isPathValid)
            {
                using (SdImage image = SdImage.FromFile(textureAsset.EditorPath))
                {
                    FileDimensions.Content = $"{image.Width}x{image.Height}";
                    FileMipmaps.Content    = TextureAsset.GetMipmapCount(image.Width, image.Height).ToString(CultureInfo.InvariantCulture);
                }

                using FileStream imageFileStream = new FileStream(textureAsset.EditorPath, FileMode.Open, FileAccess.Read);
                MemoryStream imageCopyStream = new MemoryStream();
                imageFileStream.CopyTo(imageCopyStream);
                BitmapImage src = new BitmapImage();
                src.BeginInit();
                src.StreamSource = imageCopyStream;
                src.EndInit();
                PreviewImage.Source = src;
            }
            else
            {
                PreviewImage.Source    = null;
                FileDimensions.Content = "N/A";
                FileMipmaps.Content    = "N/A";
            }
        }
        private void OpenMod_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = _modFileFilter
            };

            dialog.OpenModsRootFolder();

            bool?openResult = dialog.ShowDialog();

            if (!openResult.HasValue || !openResult.Value)
            {
                return;
            }

            List <UserAsset> userAssets = ModFileUtils.GetAssetsFromModFilePath(dialog.FileName);

            if (userAssets.Count == 0)
            {
                return;
            }

            foreach (AssetTabControl assetTabControl in App.Instance.MainWindow !.AssetTabControls)
            {
                foreach (AssetRowControl rowHandler in assetTabControl.RowControls)
                {
                    AbstractAsset asset     = rowHandler.Asset;
                    UserAsset?    userAsset = userAssets.Find(a => a.AssetName == asset.AssetName && a.AssetType == asset.AssetType);
                    if (userAsset != null)
                    {
                        asset.ImportValuesFromUserAsset(userAsset);

                        rowHandler.UpdateGui();
                    }
                }
            }
        }
 public void SelectAsset(AbstractAsset asset)
 => SelectedAsset = asset;