Пример #1
0
 public PatchnoteGeneratorModule()
 {
     _newPatchnoteMenuItem = new MenuItemVM(this.L("patchnote_generator", "new_patchnote_menu_item"))
     {
         Icon = BitmapImageEx.LoadAsFrozen("Resources/Images/Patchnote_16.png")
     };
 }
Пример #2
0
 private static void DownImageAndSave(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         string text = WebImageHelper.GetImageFileName(url);
         FileEx.DeleteWithoutException(text);
         using (WebClient webClient = new WebClient())
         {
             try
             {
                 webClient.DownloadFile(url, text);
             }
             catch (Exception e)
             {
                 Log.Exception(e);
                 Log.Info("无法下载图片,url=" + url);
             }
         }
         try
         {
             BitmapImageEx.ResizeImageAndSave(text, 300);
         }
         catch (Exception e2)
         {
             Log.Exception(e2);
         }
     }
 }
Пример #3
0
        public static BitmapSource Load(string databaseRootPath, string package, string entryKey, double dpi = 96)
        {
            var packageFile = Path.Combine(databaseRootPath, package);
            var cacheKey    = $"{packageFile}:{entryKey}";

            return(PackageImageCache.GetOrCreate(cacheKey,
                                                 () =>
            {
                try
                {
                    using (var stream = new PackageStream(packageFile, entryKey))
                    {
                        var image = BitmapImageEx.FromStream(stream);
                        if (image.DpiX != dpi || image.DpiY != dpi)
                        {
                            return image.ChangeDPI(dpi);
                        }
                        return image;
                    }
                }
                catch (Exception)
                {
                    return null;
                }
            }));
        }
Пример #4
0
        private string SelectImageFile(string parnFnOld = null)
        {
            string imageName = null;

            try
            {
                imageName = OpenFileDialogEx.GetOpenFileName("选择图片", "图片文件|*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff", null);
                if (!string.IsNullOrEmpty(imageName))
                {
                    if (FileEx.IsFileLengthMoreKB(imageName, 1024))
                    {
                        throw new Exception("图片大小不能超过1MB");
                    }
                    BitmapImage bitmapImage;
                    if (!BitmapImageEx.TryCreateFromFile(imageName, out bitmapImage))
                    {
                        throw new Exception("无法解析图片,请选择正常的图片");
                    }
                    imageName = ShortcutImageHelper.AddNewImage(imageName, parnFnOld);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                MsgBox.ShowErrTip(ex.Message, null);
            }
            return(imageName);
        }
        public static ImageSource Load(string packagePath, string localPath, double dpi = 96)
        {
            return(s_packageImageCache.GetOrCreate(UnifiedPath.Combine(packagePath, localPath),
                                                   () =>
            {
                try
                {
                    using (var stream = new PackageStream(packagePath, localPath))
                    {
                        BitmapSource image = BitmapImageEx.FromStream(stream);

                        if (image.DpiX != dpi || image.DpiY != dpi)
                        {
                            image = image.ChangeDPI(dpi);
                        }

                        image.Freeze();
                        return (ImageSource)image;
                    }
                }
                catch (Exception)
                {
                    return null;
                }
            }));
        }
        public ImageSource GetNodeIcon(string nodeType, bool isOpen = false)
        {
            string imageFileName = null;

            if (nodeType.StartsWith(NodeTypes.FileProtocal))
            {
                var extensionName = nodeType.Substring(NodeTypes.FileProtocal.Length);

                if (extensionName == "pkg")
                {
                    imageFileName = "Package_16.png";
                }
                else
                {
                    var iconSource = FileDocumentService.Instance.GetIconSource(extensionName);
                    if (iconSource == null)
                    {
                        imageFileName = "File_16.png";
                    }
                    else
                    {
                        return(iconSource);
                    }
                }
            }
            else if (nodeType.StartsWith(NodeTypes.TankClassProtocal))
            {
                var tankClass = nodeType.Substring(NodeTypes.TankClassProtocal.Length);
                return(ApplicationImages.TryGetTankClassIcon(tankClass));
            }
            else
            {
                if (isOpen)
                {
                    s_openFileIconMapping.TryGetValue(nodeType, out imageFileName);
                }

                if (imageFileName == null)
                {
                    s_normalFileIconMapping.TryGetValue(nodeType, out imageFileName);
                }

                if (imageFileName == null)
                {
                    imageFileName = "Unknown_16.png";
                }
            }

            try
            {
                return(BitmapImageEx.LoadAsFrozen(string.Format("Resources/Images/NodeIcons/{0}", imageFileName)));
            }
            catch (Exception)
            {
                return(BitmapImageEx.LoadAsFrozen("Resources/Images/NodeIcons/Unknown_16.png"));
            }
        }
        public override void Initialize()
        {
            DocumentServiceManager.Instance.Register(TankModuleTreeDocumentService.Instance);

            TankCommandManager.Instance.Register(new TankCommand(guid: TankModuleTreeDocumentServiceBase.ViewTankModuleTreeCommandGuid,
                                                                 name: "View Module Tree",
                                                                 execute: this.ViewModuleTree,
                                                                 priority: TankModuleTreeDocumentServiceBase.ViewTankModuleTreeCommandPriority,
                                                                 icon: BitmapImageEx.LoadAsFrozen("Resources/Images/ModuleTree_16.png")));
        }
Пример #8
0
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();

            list.Add(new ExplorerTreeContextMenuItemVM(150,
                                                       this.L("game_client_explorer", "locate_in_files_menu_item"),
                                                       new RelayCommand(this.LocateInFiles),
                                                       BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/Locate_16.png")));

            return(list);
        }
Пример #9
0
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();

            list.Add(new ExplorerTreeContextMenuItemVM(100,
                                                       this.L("game_client_explorer", "copy_to_mod_folder_menu_item"),
                                                       new RelayCommand(() => this.CopyToModFolder()),
                                                       BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/Copy_16.png")));

            return(list);
        }
Пример #10
0
 public void UploadImageIfServerHaveNot(string partFn)
 {
     if (!string.IsNullOrEmpty(partFn))
     {
         string fn    = this.GetFullName(partFn);
         var    image = BitmapImageEx.CreateFromFile(fn, 3);
         if (image != null)
         {
             BotApi.UpoadImageFile(fn);
         }
     }
 }
Пример #11
0
        public override void Initialize()
        {
            DocumentServiceManager.Instance.Register(ModelDocumentService.Instance);

            TankCommandManager.Instance.Register(new TankCommand(guid: ModelDocumentServiceBase.InspectModelCommandGuid,
                                                                 name: this.L("model_inspector", "inspect_model_menu_item"),
                                                                 execute: this.InspectModel,
                                                                 priority: ModelDocumentServiceBase.InspectModelCommandPriority,
                                                                 icon: BitmapImageEx.LoadAsFrozen("Resources/Images/InspectModel_16.png")));

            this.InitializeMenu();
        }
Пример #12
0
        public override void Initialize()
        {
            DocumentServiceManager.Instance.Register(StatsDocumentService.Instance);

            TankCommandManager.Instance.Register(new TankCommand(guid: StatsDocumentServiceBase.InspectStatsCommandGuid,
                                                                 name: this.L("stats_inspector", "inspect_stats_menu_item"),
                                                                 execute: this.InspectStats,
                                                                 priority: StatsDocumentServiceBase.InspectStatsCommandPriority,
                                                                 icon: BitmapImageEx.LoadAsFrozen("Resources/Images/InspectStats_16.png")));

            base.Initialize();
        }
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();


            if (!this.IsInPackage)
            {
                list.Add(new ExplorerTreeContextMenuItemVM(0,
                                                           this.L("game_client_explorer", "show_in_explorer_menu_item"),
                                                           this.ShowInExplorerCommand,
                                                           BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/Explorer_16.png")));
            }

            return(list);
        }
Пример #14
0
        public override void Initialize()
        {
            base.Initialize();

            DocumentServiceManager.Instance.Register(PatchnoteGeneratorDocumentService.Instance);

            ((INotifyCollectionChanged)RepositoryManager.Instance.Repositories).CollectionChanged += Repositories_CollectionChanged;

            MenuManager.Instance.Register(_newPatchnoteMenuItem, MenuAnchor.New);
            this.UpdateNewMenuItems();

            RepositoryCommandManager.Instance.Register(new RepositoryCommand(guid: s_createPatchnoteCommandGuid,
                                                                             name: this.L("patchnote_generator", "create_patchnote_menu_item"),
                                                                             execute: this.ExecuteCreatePatchnote,
                                                                             icon: BitmapImageEx.LoadAsFrozen("Resources/Images/Patchnote_16.png")));
        }
        private void InitializeMenuItems()
        {
            Application.Current.MainWindow.CommandBindings.Add(new CommandBinding(Commands.NewComparison, ExecuteNewComparison));

            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "new_stat_comparison_menu_item"), Commands.NewComparison)
            {
                Icon = BitmapImageEx.LoadAsFrozen("Resources/Images/Compare_16.png")
            }, MenuAnchor.New);

            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "export_to_csv_sheet_menu_item"), Commands.ExportCsv)
            {
                Icon = BitmapImageEx.LoadAsFrozen("Resources/Images/CSV_16.png")
            }, MenuAnchor.Export);


            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "configuration_panel_menu_item"), Commands.ToggleConfigPanel)
            {
                Icon        = BitmapImageEx.LoadAsFrozen("Resources/Images/ConfigPanel_16.png"),
                IsCheckable = true,
            }, MenuAnchor.View);


            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "base_values_menu_item"), Commands.SelectBaseValueMode)
            {
                Icon = BitmapImageEx.LoadAsFrozen(typeof(StatVMBase).Assembly,
                                                  "Resources/Images/BaseValue_16.png"),
                IsCheckable = true,
            }, MenuAnchor.View);

            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "instance_values_menu_item"), Commands.SelectInstanceValueMode)
            {
                Icon = BitmapImageEx.LoadAsFrozen(typeof(StatVMBase).Assembly,
                                                  "Resources/Images/InstanceValue_16.png"),
                IsCheckable = true,
            }, MenuAnchor.View);


            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "tanks_as_columns_menu_item"), Commands.SelectTanksColumnMode)
            {
                IsCheckable = true,
            }, MenuAnchor.View);

            MenuManager.Instance.Register(new MenuItemVM(this.L("stat_comparer", "stats_as_columns_menu_item"), Commands.SelectStatsColumnMode)
            {
                IsCheckable = true,
            }, MenuAnchor.View);
        }
Пример #16
0
        public async void UseImage(string imageName, System.Windows.Controls.Image imageControl)
        {
            if (!string.IsNullOrEmpty(imageName))
            {
                var         fullName = this.GetFullName(imageName);
                BitmapImage img      = BitmapImageEx.CreateFromFile(fullName, 3);
                if (img == null)
                {
                    imageControl.Source = WebImageHelper.ImgLoading;
                    await Task.Factory.StartNew <bool>(() => BotApi.DownloadImageFile(imageName, fullName), TaskCreationOptions.LongRunning);

                    img = BitmapImageEx.CreateFromFile(fullName, 3);
                }
                imageControl.Source = img;
                img = null;
            }
        }
Пример #17
0
        private static BitmapImage ReadImageFromCachedFile(string url)
        {
            BitmapImage img = null;

            lock (_synobj)
            {
                try
                {
                    string filename = WebImageHelper.GetImageFileName(url);
                    img = BitmapImageEx.CreateFromFile(filename, 3);
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                }
            }
            return(img);
        }
Пример #18
0
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();

            foreach (var command in RepositoryCommandManager.Instance.Commands)
            {
                list.Add(new ExplorerTreeContextMenuItemVM(command.Priority,
                                                           command.Name,
                                                           command,
                                                           this.Model.ID,
                                                           command.Icon));
            }

            list.Add(new ExplorerTreeContextMenuItemVM(order: 0,
                                                       name: this.L("game_client_explorer", "properties_menu_item"),
                                                       command: this.ShowPropertiesCommand,
                                                       iconSource: BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/ShowProperties_16.png")));
            return(list);
        }
Пример #19
0
        public override void Initialize()
        {
            FileDocumentService.Instance.RegisterViewer(new XmlViewerService(this));

            TankCommandManager.Instance.Register(new TankCommand(guid: XmlViewerConstants.ViewTankXmlCommandGuid,
                                                                 name: this.L("xml_viewer_service", "view_xml_menu_item"),
                                                                 execute: this.ViewXML,
                                                                 priority: XmlViewerConstants.ViewTankXmlCommandPriority,
                                                                 icon: BitmapImageEx.LoadAsFrozen("Resources/Images/ViewXML_16.png")));

            if (XmlViewerServiceSettings.Default.DeveloperMode)
            {
                TankCommandManager.Instance.Register(new TankCommand(guid: XmlViewerConstants.ViewTankInstanceXmlSnapshotCommandGuid,
                                                                     name: this.L("xml_viewer_service", "view_instance_xml_menu_item"),
                                                                     execute: this.ViewInstanceXMLSnapshot,
                                                                     priority: XmlViewerConstants.ViewTankInstanceXmlSnapshotCommandPriority,
                                                                     icon: BitmapImageEx.LoadAsFrozen("Resources/Images/ViewXML_16.png")));
            }
        }
Пример #20
0
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();

            foreach (var command in TankCommandManager.Instance.Commands)
            {
                list.Add(new ExplorerTreeContextMenuItemVM(command.Priority - 60,
                                                           command.Name,
                                                           command,
                                                           _unikey,
                                                           command.Icon));
            }

            list.Add(new ExplorerTreeContextMenuItemVM(-50,
                                                       this.L("game_client_explorer", "copy_all_files_to_mod_folder_menu_item"),
                                                       new RelayCommand(this.CopyAllFilesToModFolder),
                                                       BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/Copy_16.png")));

            return(list);
        }
Пример #21
0
        public async void UseImage(string imageName, Action <BitmapImage> cb)
        {
            if (!string.IsNullOrEmpty(imageName))
            {
                var         imagePath = this.GetFullName(imageName);
                BitmapImage img       = BitmapImageEx.CreateFromFile(imagePath, 3);
                if (img == null)
                {
                    await Task.Factory.StartNew <bool>(() => BotApi.DownloadImageFile(imageName, imagePath), TaskCreationOptions.LongRunning);

                    img = BitmapImageEx.CreateFromFile(imagePath, 3);
                    if (img == null)
                    {
                        img = AssetImageHelper.GetImageFromWpfCache(AssetImageEnum.imgCantFindImage);
                    }
                }
                cb(img);
                img = null;
            }
        }
Пример #22
0
        public static ImageSource GetIcon(IStat stat, string originalValue, string changedValue)
        {
            if (stat.CompareStrategy == CompareStrategy.NotComparable)
            {
                return(null);
            }

            double?difference;

            if (stat.BenchmarkThreshold.Type == BenchmarkThresholdType.Relative)
            {
                difference = stat.GetDifferenceRatio(changedValue, originalValue);
            }
            else
            {
                difference = stat.GetDifference(changedValue, originalValue);
            }

            if (difference == null)
            {
                return(null);
            }

            var imageName = "Comparison";

            if (stat.CompareStrategy == CompareStrategy.Plain)
            {
                imageName += "Plain";
            }

            var differenceLevel = ((int)(difference.Value / stat.BenchmarkThreshold.Value * 4)).Clamp(-3, 3);

            imageName += differenceLevel.ToString();

            return(s_benchmarkIcons.GetOrCreate(imageName,
                                                () =>
            {
                var image = (ImageSource)BitmapImageEx.LoadAsFrozen(string.Format("Resources/Images/{0}_16.png", imageName));
                return image;
            }));
        }
Пример #23
0
        public override void Initialize()
        {
            _cameraControllerVm             = new CameraControllerVM();
            _cameraControllerView           = new CameraControllerView();
            _cameraControllerView.ViewModel = _cameraControllerVm;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("72B29BFF-9421-467B-84F8-730CC39BA8E0"),
                new[] { typeof(IHasCamera) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("camera_controller", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Content    = _cameraControllerView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/Camera_12.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
        public override void Initialize()
        {
            _configView           = new TankConfigView();
            _configVm             = new TankConfigVM();
            _configView.ViewModel = _configVm;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("090B35D3-1760-4A37-8589-4F8C66A8D30B"),
                new[] { typeof(ITankConfigurable) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("tank_configurator", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Width      = 200,
                Content    = _configView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/Config_16.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
        public override void Initialize()
        {
            _controllerVm             = new TurretControllerVM();
            _controllerView           = new TurretControllerView();
            _controllerView.ViewModel = _controllerVm;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("7262E37C-3C56-4E55-81BB-30DF8ACC1E23"),
                new[] { typeof(ITurretControllable) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("turret_controller", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Width      = 200,
                Content    = _controllerView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/Icon_16.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
        public override void Initialize()
        {
            _xmlToolsView           = new XmlToolsView();
            _xmlToolsVM             = new XmlToolsVM(this);
            _xmlToolsView.ViewModel = _xmlToolsVM;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("3DDAF122-D17F-4866-AA22-0EC514218AC6"),
                new[] { typeof(IXmlViewer) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("xml_tools", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Width      = 200,
                Content    = _xmlToolsView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/XmlTools_16.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
        public override void Initialize()
        {
            _configView           = new CrewConfigView();
            _configVm             = new CrewConfigVM();
            _configView.ViewModel = _configVm;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("ADCC6DC1-160B-48D3-BAD0-12D624C4514C"),
                new[] { typeof(ICrewConfigurable) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("crew_configurator", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Width      = 200,
                Content    = _configView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/Crew_16.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
Пример #28
0
        protected override List <ExplorerTreeContextMenuItemVM> CreateContextMenuItems()
        {
            var list = base.CreateContextMenuItems();

            if (!this.IsInPackage)
            {
                list.Add(new ExplorerTreeContextMenuItemVM(-100,
                                                           this.L("game_client_explorer", "open_menu_item"),
                                                           new RelayCommand(this.OpenFileWithDefaultProgram),
                                                           BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/OpenExternal_16.png")));
            }

            if (FileDocumentService.Instance.HasFileViewerService(this.ExtensionName))
            {
                list.Add(new ExplorerTreeContextMenuItemVM(-1000,
                                                           this.L("game_client_explorer", "view_menu_item"),
                                                           this.DefaultCommand,
                                                           BitmapImageEx.LoadAsFrozen("Resources/Images/Actions/OpenInternal_16.png")));
            }

            return(list);
        }
Пример #29
0
        public override void Initialize()
        {
            _configView           = new CustomizationConfigView();
            _configVm             = new CustomizationConfigVM();
            _configView.ViewModel = _configVm;

            var panel = new FeaturedPanelInfo(
                Guid.Parse("D7C7755E-47E7-4EB0-8904-2FD24D181CDB"),
                new[] { typeof(ICustomizationConfigurable) },
                this.OnRequiredFeaturesSatisficationChanged)
            {
                Title      = this.L("customization_configurator", "panel_title"),
                CanHide    = true,
                CanClose   = true,
                CanFloat   = true,
                Width      = 200,
                Content    = _configView,
                IconSource = BitmapImageEx.LoadAsFrozen("Resources/Images/Pencil_16.png"),
            };

            DockingViewManager.Instance.PanelManager.Register(panel);
        }
        private void UpdateTankFigure()
        {
            switch (this.TankFigureType)
            {
            case TankFigureType.Tank:
                this.HullFigure.Source   = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/TankHull.png");
                this.TurretFigure.Source = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/TankTurret.png");
                break;

            case TankFigureType.TankDestroyer:
                this.HullFigure.Source   = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/TDHull.png");
                this.TurretFigure.Source = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/TDGun.png");
                break;

            case TankFigureType.SelfPropelledGun:
                this.HullFigure.Source   = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/SPGHull.png");
                this.TurretFigure.Source = BitmapImageEx.LoadAsFrozen("Resources/Images/Figures/SPGGun.png");
                break;

            default:
                throw new ArgumentException();
            }
        }