private void setupCurrency()
        {
            if (isCurrency)
            {
                currencyTextLabel.HorizontalAlignment = HorizontalAlignment.Right;

                if (Guid.TryParse(Vendor.currency, out var curGuid) && GameAssetManager.TryGetAsset <GameCurrencyAsset>(curGuid, out var asset))
                {
                    currencyIcons.Visibility = Visibility.Visible;

                    foreach (var entry in asset.entries.OrderBy(d => d.Value))
                    {
                        Grid eG = new Grid();

                        Image eIcon = new Image()
                        {
                            Width  = 32,
                            Height = 32,
                            Margin = new Thickness(2.5)
                        };

                        if (Guid.TryParse(entry.ItemGUID, out var itemGuid) && GameAssetManager.TryGetAsset <GameItemAsset>(itemGuid, out var itemAsset))
                        {
                            eIcon.Source = ThumbnailManager.CreateThumbnail(itemAsset.ImagePath);
                        }

                        Label eL = new Label()
                        {
                            VerticalAlignment   = VerticalAlignment.Bottom,
                            HorizontalAlignment = HorizontalAlignment.Center
                        };

                        TextBlock eT = new TextBlock()
                        {
                            TextAlignment = TextAlignment.Center,
                            Text          = entry.Value.ToString()
                        };

                        eL.Content = eT;

                        eG.Children.Add(eIcon);
                        eG.Children.Add(eL);

                        currencyIcons.Children.Add(eG);
                    }
                }
            }
            else
            {
                currencyIcons.Visibility = Visibility.Collapsed;
                currencyTextLabel.HorizontalAlignment = HorizontalAlignment.Center;
            }
        }
Exemple #2
0
 public bool UpdateIcon(out BitmapImage image)
 {
     if (ID > 0 && GameAssetManager.TryGetAsset <GameItemAsset>(ID, out var asset))
     {
         image = ThumbnailManager.CreateThumbnail(asset.ImagePath);
         return(true);
     }
     else
     {
         image = default;
         return(false);
     }
 }
Exemple #3
0
        void SetupAssets()
        {
            ClearList();

            IEnumerable <GameAsset> assets = GameAssetManager.GetAllAssets(assetType);

            IEnumerable <GameAsset> orderedAssets;

            switch (orderMode)
            {
            case EOrderByMode.ID_A:
                orderedAssets = assets.OrderBy(d => d.origin).ThenBy(d => d.GUIDOverID ? (object)d.guid : (object)d.id);
                break;

            case EOrderByMode.ID_D:
                orderedAssets = assets.OrderBy(d => d.origin).ThenByDescending(d => d.GUIDOverID ? (object)d.guid : (object)d.id);
                break;

            case EOrderByMode.Name_A:
                orderedAssets = assets.OrderBy(d => d.origin).ThenBy(d =>
                {
                    if (d is IHasNameOverride nameOverride)
                    {
                        return(nameOverride.NameOverride);
                    }
                    else
                    {
                        return(d.name);
                    }
                });
                break;

            case EOrderByMode.Name_D:
                orderedAssets = assets.OrderBy(d => d.origin).ThenByDescending(d =>
                {
                    if (d is IHasNameOverride nameOverride)
                    {
                        return(nameOverride.NameOverride);
                    }
                    else
                    {
                        return(d.name);
                    }
                });
                break;

            default:
                orderedAssets = assets;
                break;
            }

            if (typeof(ICreatable).IsAssignableFrom(assetType))
            {
                addEntryButton.Visibility = Visibility.Visible;

                addEntryButton.Command = new BaseCommand(() =>
                {
                    GameAsset createdA = (GameAsset)Activator.CreateInstance(assetType);

                    if (createdA is ICreatable createable)
                    {
                        createable.OnCreate();
                    }

                    Reorder();
                });
            }
            else
            {
                addEntryButton.Visibility = Visibility.Collapsed;
            }

            foreach (var asset in orderedAssets)
            {
                Grid g = new Grid()
                {
                    Margin = new Thickness(5),
                    Tag    = asset
                };

                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });

                TextBlock tb = new TextBlock();
                Label     l  = new Label()
                {
                    Content           = tb,
                    VerticalAlignment = VerticalAlignment.Center
                };
                TextBlock tbid = new TextBlock();
                Label     lid  = new Label()
                {
                    Content           = tbid,
                    VerticalAlignment = VerticalAlignment.Center,
                    MaxWidth          = 69
                };

                if (asset is IHasNameOverride gda)
                {
                    markup.Markup(tb, gda.NameOverride);
                }
                else
                {
                    markup.Markup(tb, asset.name);
                }

                if (asset.GUIDOverID)
                {
                    tbid.Text    = asset.guid.ToString("N");
                    tbid.ToolTip = tbid.Text;
                }
                else
                {
                    tbid.Text = asset.id.ToString();
                }

                g.Children.Add(l);
                g.Children.Add(lid);

                Grid editableGrid = new Grid()
                {
                    HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(5)
                };
                Grid deletableGrid = new Grid()
                {
                    HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(5)
                };

                g.Children.Add(editableGrid);
                g.Children.Add(deletableGrid);

                if (asset is IEditable editable)
                {
                    Button editButton = new Button()
                    {
                        ToolTip = LocalizationManager.Current.Interface["AssetPicker_Editable_Edit_ToolTip"]
                    };

                    editButton.Content = new PackIconMaterial()
                    {
                        Kind       = PackIconMaterialKind.Pencil,
                        Foreground = Application.Current.Resources["AccentColor"] as System.Windows.Media.Brush,
                        Width      = 16,
                        Height     = 16
                    };

                    editButton.Command = new BaseCommand(() =>
                    {
                        editable.Edit(this);

                        if (asset is IHasNameOverride gda1)
                        {
                            markup.Markup(tb, gda1.NameOverride);
                        }
                        else
                        {
                            markup.Markup(tb, asset.name);
                        }

                        if (asset.GUIDOverID)
                        {
                            tbid.Text    = asset.guid.ToString("N");
                            tbid.ToolTip = tbid.Text;
                        }
                        else
                        {
                            tbid.Text = asset.id.ToString();
                        }
                    });

                    editableGrid.Children.Add(editButton);
                }

                if (asset is IDeletable deletable)
                {
                    Button deleteButton = new Button()
                    {
                        ToolTip = LocalizationManager.Current.Interface["AssetPicker_Deletable_Delete_ToolTip"]
                    };

                    deleteButton.Content = new PackIconMaterial()
                    {
                        Kind       = PackIconMaterialKind.TrashCan,
                        Foreground = Application.Current.Resources["AccentColor"] as System.Windows.Media.Brush,
                        Width      = 16,
                        Height     = 16
                    };

                    deleteButton.Command = new BaseCommand(() =>
                    {
                        deletable.OnDelete();

                        Reorder();
                    });

                    deletableGrid.Children.Add(deleteButton);
                }

                if (asset is IHasIcon hasIcon)
                {
                    Image icon = new Image()
                    {
                        Source            = ThumbnailManager.CreateThumbnail(hasIcon.ImagePath),
                        Width             = 32,
                        Height            = 32,
                        Margin            = new Thickness(1),
                        VerticalAlignment = VerticalAlignment.Center
                    };

                    g.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    g.Children.Add(icon);

                    Grid.SetColumn(icon, 0);
                    Grid.SetColumn(lid, 1);
                    Grid.SetColumn(l, 2);
                    Grid.SetColumn(editableGrid, 3);
                    Grid.SetColumn(deletableGrid, 4);
                }
                else if (asset is IHasThumbnail hasThumbnail)
                {
                    Image icon = new Image()
                    {
                        Source            = hasThumbnail.Thumbnail,
                        Width             = 32,
                        Height            = 32,
                        Margin            = new Thickness(1),
                        VerticalAlignment = VerticalAlignment.Center
                    };

                    g.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    g.Children.Add(icon);

                    Grid.SetColumn(icon, 0);
                    Grid.SetColumn(lid, 1);
                    Grid.SetColumn(l, 2);
                    Grid.SetColumn(editableGrid, 3);
                    Grid.SetColumn(deletableGrid, 4);
                }
                else if (asset is IHasAnimatedThumbnail hasAnimatedThumbnail)
                {
                    var thumbs = hasAnimatedThumbnail.Thumbnails.ToList();

                    if (thumbs.Count > 0)
                    {
                        Image icon = new Image()
                        {
                            Source            = thumbs.First(),
                            Width             = 32,
                            Height            = 32,
                            Margin            = new Thickness(1),
                            VerticalAlignment = VerticalAlignment.Center
                        };

                        DispatcherTimer dt = new DispatcherTimer()
                        {
                            Interval = new TimeSpan(0, 0, 3)
                        };
                        int last = 0;
                        dt.Tick += (sender, e) =>
                        {
                            last++;
                            if (last >= thumbs.Count)
                            {
                                last = 0;
                            }

                            icon.Source = thumbs[last];
                        };
                        dt.Start();

                        g.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                        g.Children.Add(icon);

                        Grid.SetColumn(icon, 0);
                        Grid.SetColumn(lid, 1);
                        Grid.SetColumn(l, 2);
                        Grid.SetColumn(editableGrid, 3);
                        Grid.SetColumn(deletableGrid, 4);
                    }
                    else
                    {
                        Grid.SetColumn(lid, 0);
                        Grid.SetColumn(l, 1);
                        Grid.SetColumn(editableGrid, 2);
                        Grid.SetColumn(deletableGrid, 3);
                    }
                }
                else
                {
                    tpbarGrid.ColumnDefinitions[0].Width = new GridLength(0);
                    Grid.SetColumn(lid, 0);
                    Grid.SetColumn(l, 1);
                    Grid.SetColumn(editableGrid, 2);
                    Grid.SetColumn(deletableGrid, 3);
                }

                if (asset is IHasToolTip hasToolTip)
                {
                    g.ToolTip = hasToolTip.ToolTipContent;
                }
                else if (asset is IHasTextToolTip hasTextToolTip)
                {
                    var sp = new StackPanel()
                    {
                        Orientation = Orientation.Vertical
                    };

                    void addLabel(string text)
                    {
                        sp.Children.Add(new Label()
                        {
                            Content = new TextBlock()
                            {
                                Text = text,
                                VerticalAlignment   = VerticalAlignment.Center,
                                HorizontalAlignment = HorizontalAlignment.Left,
                                TextAlignment       = TextAlignment.Left
                            },
                            VerticalAlignment   = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Margin = new Thickness(5)
                        });
                    }

                    foreach (var line in hasTextToolTip.GetToolTipLines())
                    {
                        addLabel(line);
                    }

                    g.ToolTip = sp;
                }

                g.MouseDown += (sender, e) =>
                {
                    DialogResult  = true;
                    SelectedAsset = asset;
                    Close();
                };
                stack.Children.Add(g);
            }
        }
Exemple #4
0
        void SetupAssets()
        {
            ClearList();

            IEnumerable <GameAsset> assets = GameAssetManager.GetAllAssets(assetType);

            IEnumerable <GameAsset> orderedAssets;

            switch (orderMode)
            {
            case EOrderByMode.ID_A:
                orderedAssets = assets.OrderBy(d => d.origin).ThenBy(d => d.id);
                break;

            case EOrderByMode.ID_D:
                orderedAssets = assets.OrderBy(d => d.origin).ThenByDescending(d => d.id);
                break;

            case EOrderByMode.Name_A:
                orderedAssets = assets.OrderBy(d => d.origin).ThenBy(d =>
                {
                    if (d is IHasNameOverride nameOverride)
                    {
                        return(nameOverride.NameOverride);
                    }
                    else
                    {
                        return(d.name);
                    }
                });
                break;

            case EOrderByMode.Name_D:
                orderedAssets = assets.OrderBy(d => d.origin).ThenByDescending(d =>
                {
                    if (d is IHasNameOverride nameOverride)
                    {
                        return(nameOverride.NameOverride);
                    }
                    else
                    {
                        return(d.name);
                    }
                });
                break;

            default:
                orderedAssets = assets;
                break;
            }

            foreach (var asset in orderedAssets)
            {
                Grid g = new Grid()
                {
                    Margin = new Thickness(5),
                    Tag    = asset
                };

                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                g.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });

                TextBlock tb = new TextBlock();
                Label     l  = new Label()
                {
                    Content = tb
                };
                TextBlock tbid = new TextBlock();
                Label     lid  = new Label()
                {
                    Content = tbid
                };

                if (asset is IHasNameOverride gda)
                {
                    markup.Markup(tb, gda.NameOverride);
                }
                else
                {
                    markup.Markup(tb, asset.name);
                }

                tbid.Text = asset.id.ToString();

                g.Children.Add(l);
                g.Children.Add(lid);

                if (asset is IHasIcon hasIcon)
                {
                    Image icon = new Image()
                    {
                        Source = ThumbnailManager.CreateThumbnail(hasIcon.ImagePath),
                        Width  = 32,
                        Height = 32,
                        Margin = new Thickness(1)
                    };

                    g.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    g.Children.Add(icon);

                    Grid.SetColumn(icon, 0);
                    Grid.SetColumn(lid, 1);
                    Grid.SetColumn(l, 2);
                }
                else if (asset is IHasThumbnail hasThumbnail)
                {
                    Image icon = new Image()
                    {
                        Source = hasThumbnail.Thumbnail,
                        Width  = 32,
                        Height = 32,
                        Margin = new Thickness(1)
                    };

                    g.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    g.Children.Add(icon);

                    Grid.SetColumn(icon, 0);
                    Grid.SetColumn(lid, 1);
                    Grid.SetColumn(l, 2);
                }
                else if (asset is IHasAnimatedThumbnail hasAnimatedThumbnail)
                {
                    var thumbs = hasAnimatedThumbnail.Thumbnails.ToList();

                    if (thumbs.Count > 0)
                    {
                        Image icon = new Image()
                        {
                            Source = thumbs.First(),
                            Width  = 32,
                            Height = 32,
                            Margin = new Thickness(1)
                        };

                        DispatcherTimer dt = new DispatcherTimer()
                        {
                            Interval = new TimeSpan(0, 0, 3)
                        };
                        int last = 0;
                        dt.Tick += (sender, e) =>
                        {
                            last++;
                            if (last >= thumbs.Count)
                            {
                                last = 0;
                            }

                            icon.Source = thumbs[last];
                        };
                        dt.Start();

                        g.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = GridLength.Auto
                        });
                        g.Children.Add(icon);

                        Grid.SetColumn(icon, 0);
                        Grid.SetColumn(lid, 1);
                        Grid.SetColumn(l, 2);
                    }
                    else
                    {
                        Grid.SetColumn(lid, 0);
                        Grid.SetColumn(l, 1);
                    }
                }
                else
                {
                    tpbarGrid.ColumnDefinitions[0].Width = new GridLength(0);
                    Grid.SetColumn(lid, 0);
                    Grid.SetColumn(l, 1);
                }

                if (asset is IHasToolTip hasToolTip)
                {
                    g.ToolTip = hasToolTip.ToolTipContent;
                }
                else if (asset is IHasTextToolTip hasTextToolTip)
                {
                    var sp = new StackPanel()
                    {
                        Orientation = Orientation.Vertical
                    };

                    void addLabel(string text)
                    {
                        sp.Children.Add(new Label()
                        {
                            Content = new TextBlock()
                            {
                                Text = text,
                                VerticalAlignment   = VerticalAlignment.Center,
                                HorizontalAlignment = HorizontalAlignment.Left,
                                TextAlignment       = TextAlignment.Left
                            },
                            VerticalAlignment   = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Margin = new Thickness(5)
                        });
                    }

                    foreach (var line in hasTextToolTip.GetToolTipLines())
                    {
                        addLabel(line);
                    }

                    g.ToolTip = sp;
                }

                g.MouseDown += (sender, e) =>
                {
                    DialogResult  = true;
                    SelectedAsset = asset;
                    Close();
                };
                stack.Children.Add(g);
            }
        }
        private async Task ImportGameAssets(string mainPath)
        {
            GameIntegration.GameAssetManager.Purge();

            if (AppConfig.Instance.importVanilla)
            {
                stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Unturned");

                await GameIntegration.GameAssetManager.Import(mainPath, GameIntegration.EGameAssetOrigin.Unturned, (index, total) =>
                {
                    updateProgress(index, total);
                }, tokenSource);

                clearProgress();

                if (tokenSource.IsCancellationRequested)
                {
                    await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE);

                    GameIntegration.GameAssetManager.Purge();
                    ThumbnailManager.Purge();
                    return;
                }

                GameAssetManager.HasImportedVanilla = true;
            }

            if (AppConfig.Instance.importWorkshop)
            {
                string workshopPath = PathUtility.GetUnturnedWorkshopPathFromUnturnedPath(mainPath);

                stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Workshop");

                await GameIntegration.GameAssetManager.Import(workshopPath, GameIntegration.EGameAssetOrigin.Workshop, (index, total) =>
                {
                    updateProgress(index, total);
                }, tokenSource);

                clearProgress();

                if (tokenSource.IsCancellationRequested)
                {
                    await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE);

                    GameIntegration.GameAssetManager.Purge();
                    ThumbnailManager.Purge();
                    return;
                }

                GameAssetManager.HasImportedWorkshop = true;
            }

            if (AppConfig.Instance.generateThumbnailsBeforehand && GameAssetManager.HasImportedAssets)
            {
                stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Thumbnails");

                IHasIcon[] assetsWithIcons = GameIntegration.GameAssetManager.GetAllAssetsWithIcons().ToArray();

                for (int i = 0; i < assetsWithIcons.Length; i++)
                {
                    IHasIcon a = assetsWithIcons[i];

                    if (i % 25 == 0)
                    {
                        if (tokenSource.IsCancellationRequested)
                        {
                            await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE);

                            GameIntegration.GameAssetManager.Purge();
                            ThumbnailManager.Purge();
                            return;
                        }

                        updateProgress(i, assetsWithIcons.Length);

                        await Task.Delay(1);
                    }
                    else
                    {
                        await Task.Yield();
                    }

                    ThumbnailManager.CreateThumbnail(a.ImagePath);
                }

                clearProgress();

                if (tokenSource.IsCancellationRequested)
                {
                    await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE);

                    GameIntegration.GameAssetManager.Purge();
                    ThumbnailManager.Purge();
                    return;
                }
            }

            hasDone = true;

            Close();
        }