コード例 #1
0
        private BitmapSource PrintVersionTag(BitmapSource image, TankInstance tank)
        {
            var versionTag = new VersionTag();

            versionTag.Width             = image.PixelWidth;
            versionTag.VerticalAlignment = VerticalAlignment.Bottom;
            versionTag.TankInstance      = tank;
            versionTag.MeasureAndArrange();
            var versionTagImage = versionTag.RenderToBitmap();

            var composite = new WriteableBitmap(image);

            var pixels = new int[(int)versionTagImage.Width * (int)versionTagImage.Height];
            var stride = (int)(4 * versionTagImage.Width);

            versionTagImage.CopyPixels(pixels, stride, 0);
            var rect = new Int32Rect(0,
                                     (int)(image.PixelHeight - versionTagImage.Height),
                                     (int)versionTagImage.Width,
                                     (int)versionTagImage.Height);

            composite.WritePixels(rect, pixels, stride, 0);

            return(composite);
        }
コード例 #2
0
        public ArmorViewVM(TankInstance tankInstance)
            : base(tankInstance)
        {
            this.RegularArmorValues = new DoubleCollection(tankInstance.GetArmorValues(false));
            this.SpacedArmorValues  = new DoubleCollection(tankInstance.GetArmorValues(true));

            var thickestArmor       = this.TankInstance.GetThickestArmor(false);
            var thinnestArmor       = this.TankInstance.GetThinnestArmor(false);
            var thickestSpacedArmor = this.TankInstance.GetThickestArmor(true);
            var thinnestSpacedArmor = this.TankInstance.GetThinnestArmor(true);

            this.CollisionModelRenderParameters = new CollisionModelRenderParameters()
            {
                TankThickestArmor         = thickestArmor,
                TankThinnestArmor         = thinnestArmor,
                TankThickestSpacingArmor  = thickestSpacedArmor,
                TankThinnestSpacingArmor  = thinnestSpacedArmor,
                RegularArmorSpectrumStops = DefaultRegularArmorSpectrumStops,
                SpacingArmorSpectrumStops = DefaultSpacingArmorSpectrumStops,
                //TBD
                RegularArmorValueSelectionBegin = thinnestArmor,
                RegularArmorValueSelectionEnd   = thickestArmor,
                SpacingArmorValueSelectionBegin = thinnestSpacedArmor,
                SpacingArmorValueSelectionEnd   = thickestSpacedArmor,
            };
        }
コード例 #3
0
    private TankUnit CreateTankUnit(EnemyTankBehaviour behaviour, int count)
    {
        var instances = new TankInstance[count];

        for (int i = 0; i < count; i++)
        {
            instances[i] = new TankInstance(Instantiate(behaviour.prefab));
            instances[i].tank.gameObject.SetActive(false);

            const float colorRandomRange = 0.8f;
            var         hsv = tankBaseColor;
            hsv.value      += Random.value * colorRandomRange - colorRandomRange / 2f;
            hsv.saturation += Random.value * colorRandomRange - colorRandomRange / 2f;

            var renderers = instances[i].tank.GetComponentsInChildren <MeshRenderer>();
            for (int ii = 0; ii < renderers.Length; ii++)
            {
                renderers[ii].material.color = hsv;
            }
        }

        return(new TankUnit
        {
            behaviour = behaviour,
            instances = instances,
            activeIndicesMap = new int[count],
            activeCount = 0,
            nextIndex = 0
        });
    }
コード例 #4
0
 private void UnhandleTankInstanceEvents(TankInstance tank)
 {
     tank.TankConfiguration.GunChanged -= OnGunChanged;
     tank.Transform.TurretYawChanged   -= Transform_TurretYawChanged;
     tank.Transform.VehicleYawChanged  -= Transform_VehicleYawChanged;
     tank.Transform.GunPitchChanged    -= Transform_GunPitchChanged;
 }
コード例 #5
0
        public FrameworkElement CreateStatChangesView(TankInstance before, TankInstance after)
        {
            var vm   = new StatChangesVM(before, after);
            var view = new StatChangesView();

            view.ViewModel = vm;
            return(view);
        }
コード例 #6
0
 public ModelViewVM(TankInstance tankInstance)
     : base(tankInstance)
 {
     this.ShowCamouflage = true;
     this.FileSource     = FileSource.Package;
     this.TextureMode    = TextureMode.Normal;
     this.ModelType      = ModelType.Undamaged;
 }
コード例 #7
0
 public ArmorDocumentVM(ArmorDocumentService modelDocumentService,
                        CommandBindingCollection commandBindings,
                        TankInstance tank,
                        string persistentInfo)
     : base(commandBindings, tank, persistentInfo)
 {
     this.ModelDocumentService = modelDocumentService;
     this.Capture = new CaptureVM(this);
 }
コード例 #8
0
 public ModelVMBase(TankInstance tankInstance)
 {
     this.GraphicsSettings = new GraphicsSettings();
     this.TankInstance     = tankInstance;
     this.ShowGun          = true;
     this.ShowTurret       = true;
     this.ShowChassis      = true;
     this.ShowHull         = true;
 }
コード例 #9
0
        public TankModuleTreeDocumentVM(TankModuleTreeDocumentService service,
                                        CommandBindingCollection commandBindings,
                                        TankInstance tankInstance,
                                        string persistentInfo)
        {
            this.TankInstance = tankInstance;

            Task.Factory.StartNew(this.AnalyseUnlocks);
        }
コード例 #10
0
        public ModelDocumentVMBase(CommandBindingCollection commandBindings, TankInstance tankInstance, string persistentInfo)
        {
            this.ModelView      = this.CreateModelVM(tankInstance);
            this.TankInstance   = tankInstance;
            this.PersistentInfo = this.LoadPersistentInfo(persistentInfo);
            _commandBindings    = commandBindings;
            this.InitializeCommands();

            this.Camera.RotationYawChanged += Camera_RotationYawChanged;
        }
コード例 #11
0
        public void BeginCreateDocument(TankInstance tank, IProgressScope progress, Action <CreateDocumentResult> callback)
        {
            Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                progress.ReportStatusMessage(this.L("stat_inspector", "status_analysing"));
                progress.ReportIsIndetermine();

                this.LogInfo("creating document from template file '{0}'", this.Filename);
                var document = this.LoadTemplate();
                progress.ReportProgress(0);

                var decendants = LogicalTreeHelperEx.GetDecendants <TextElement>(document).ToArray();
                var statVms    = new Dictionary <IStat, StatVM>();

                var completedDecendant = 0;

                foreach (var decendant in decendants)
                {
                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        var key = StatBehaviors.GetKey(decendant);
                        if (key != null)
                        {
                            var stat = StatsProviderManager.Instance.GetStat(key);
                            if (stat == null)
                            {
                                this.LogWarning("unknown stat: key='{0}'", key);
                                return;
                            }

                            var statVm = statVms.GetOrCreate(stat, () => new StatVM(stat, tank));

                            decendant.DataContext = statVm;

                            if (decendant is IAddChild)
                            {
                                this.ApplyTemplate(decendant);
                            }

                            ++completedDecendant;
                            progress.ReportProgress((double)completedDecendant / decendants.Length);
                        }
                    }), DispatcherPriority.Background);
                }

                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                {
                    progress.ReportIsIndetermine();
                    callback(new CreateDocumentResult(document, statVms.Values));
                    progress.ReportProgress(1.0);
                }), DispatcherPriority.Background);
            }), DispatcherPriority.Background);
        }
コード例 #12
0
        public StatVMBase(IStat stat, TankInstance tank)
        {
            this.Model = stat;
            this.Tank  = tank;

            this.InstanceValueString = this.L("common", "loading");
            this.BaseValueString     = this.L("common", "loading");

            Dispatcher.CurrentDispatcher.BeginInvoke(new Action(this.UpdateValue), DispatcherPriority.Normal);
            //this.UpdateValue();

            this.Tank.TankConfigurationChanged += this.Tank_TankConfigurationChanged;
        }
コード例 #13
0
        public ModuleModel(TankInstance tankInstance, Module module)
        {
            if (!(tankInstance.Repository is LocalGameClient))
            {
                throw new ArgumentException("tankInstance");
            }

            this.TankInstance = tankInstance;

            this.Camouflage = new CamouflageInfo(tankInstance, module);

            _module = module;
        }
コード例 #14
0
        public TankModel(TankInstance tankInstance)
        {
            this.TankInstance = tankInstance;
            this.Camouflage   = new CamouflageInfo(tankInstance);

            this.LoadHullModel();
            this.LoadChassisModel();
            this.LoadTurretModel();
            this.LoadGunModel();

            this.TankInstance.TankConfiguration.TurretChanged  += TankConfiguration_TurretChanged;
            this.TankInstance.TankConfiguration.GunChanged     += TankConfiguration_GunChanged;
            this.TankInstance.TankConfiguration.ChassisChanged += TankConfiguration_ChassisChanged;
        }
コード例 #15
0
        public StatChangesVM(TankInstance before, TankInstance after)
        {
            _statChanges = new List <StatChangeVM>();

            foreach (var stat in StatsProviderManager.Instance.Stats.Where(s => s.IsStatic))
            {
                var originalValue = stat.GetValue(before, before.Repository, false);
                var changedValue  = stat.GetValue(after, after.Repository, false);

                if (stat.Comparer.Compare(originalValue, changedValue) != 0)
                {
                    _statChanges.Add(new StatChangeVM(stat, originalValue, changedValue));
                }
            }
        }
コード例 #16
0
        private void OnAlternativeTankInstanceChanged(TankInstance tankInstance)
        {
            if (tankInstance == null && _alternativeDXElement != null)
            {
                this.RemoveAlternativeView();
                return;
            }

            if (_alternativeDXElement == null)
            {
                this.InitializeAlternativeView();
            }

            _alternativeHangarScene.TankModel = new TankModel(tankInstance);
        }
コード例 #17
0
        public override void BeginCapture(ISnapshotProvider snapshotProvider, TankInstance tank, Rect clippingRectangle, Color shadeColor, string outputFilename)
        {
            DialogManager.Instance.ShowProgressAsync(this.CapturingDialogTitle,
                                                     string.Format(this.CapturingDialogMessage, tank.Name),
                                                     isCancellable: false)
            .ContinueWith(t =>
            {
                t.Result.SetIndeterminate();

                var captureCompleted = false;

                var dispatcherTimer = new DispatcherTimer(DispatcherPriority.Background,
                                                          Application.Current.Dispatcher);
                dispatcherTimer.Interval = TimeSpan.FromSeconds(0.5);
                dispatcherTimer.Tick    +=
                    (o, e) =>
                {
                    dispatcherTimer.Stop();

                    var bitmapSource = snapshotProvider.Snapshot(clippingRectangle, (float)this.SampleFactor, StaticCapturerBase.GetStaticShadeColor(shadeColor));
                    using (var file = File.OpenWrite(outputFilename))
                    {
                        var encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                        encoder.Save(file);
                    }

                    captureCompleted = true;
                };

                dispatcherTimer.Start();


                while (!captureCompleted)
                {
                    Thread.Sleep(100);
                }

                t.Result.SetTitle(this.CaptureCompletedDialogTitle);
                t.Result.SetMessage(string.Format(this.CaptureCompletedDialogMessage, outputFilename));
                Thread.Sleep(1000);
                t.Result.CloseAsync();
            });
        }
コード例 #18
0
        public StatsDocumentVM(StatsDocumentService service, CommandBindingCollection commandBindings, TankInstance tank, string persistentInfo)
            : base(commandBindings)
        {
            this.StatsDocumentService = service;
            this.Tank = tank;

            this.PersistentInfo = DocumentPersistentInfoProviderBase.Load(persistentInfo,
                                                                          () => new StatsDocumentPersistentInfo(tank),
                                                                          this.GetLogger());
            this.CreateDocument();
        }
コード例 #19
0
 private void OnTankInstanceChanged(TankInstance tankInstance)
 {
     this.HangarScene.TankModel = new TankModel(tankInstance);
 }
コード例 #20
0
        public override void BeginCapture(ISnapshotProvider snapshotProvider, TankInstance tank, Rect clippingRectangle, Color shadeColor, string outputFilename)
        {
            DialogManager.Instance.ShowProgressAsync(this.CaptureDialogTitle,
                                                     string.Format(this.CaptureDialogMessage, tank.Name),
                                                     isCancellable: true)
            .ContinueWith(t =>
            {
                Thread.Sleep(500);

                DialogManager.AssignTask(
                    t.Result,
                    ActionTask.Create("ExportAnimationCapture",
                                      progress =>
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        var takeSnapshotProgress = progress.AddChildScope("TakeSnapshot", 80);
                        var encodeProgress       = progress.AddChildScope("EncodeGIF", 20);

                        var frameSources = this.CaptureFrames(snapshotProvider, clippingRectangle, shadeColor, takeSnapshotProgress, () => t.Result.IsCanceled);

                        if (t.Result.IsCanceled)
                        {
                            return;
                        }

                        var encoder = new AnimatedGifEncoder();

                        using (var file = File.OpenWrite(outputFilename))
                        {
                            encoder.Start(file);

                            encoder.SetRepeat(0);
                            encoder.SetDelay((int)(this.FrameTime * 1000));
                            for (var i = 0; i < frameSources.Length; ++i)
                            {
                                encodeProgress.ReportProgress((double)i / frameSources.Length);

                                if (t.Result.IsCanceled)
                                {
                                    return;
                                }

                                if (this.IsBackgroundTransparent)
                                {
                                    encoder.SetTransparentColor(shadeColor);
                                }

                                encoder.AddFrame(frameSources[i]);
                            }

                            encoder.Finish();
                        }

                        progress.ReportIsIndetermine();

                        t.Result.SetTitle(this.CaptureCompletedDialogTitle);
                        t.Result.SetMessage(string.Format(this.CaptureCompletedDialogMessage, outputFilename));
                        Thread.Sleep(1000);

                        progress.ReportProgress(1.0);
                    }));
                }));
            });
        }
コード例 #21
0
 public StatVM(IStat stat, TankInstance tank)
     : base(stat, tank)
 {
     // must be true to ensure the document to be generated correctly
     this.ShouldShow = true;
 }
コード例 #22
0
 public ModelComparerRivalVM(TankInstance tank)
 {
     _tank = tank;
 }
コード例 #23
0
 protected abstract ModelVMBase CreateModelVM(TankInstance tankInstance);
コード例 #24
0
 public StatsDocumentPersistentInfo(TankInstance instance)
 {
     this.ViewingMode      = StatsInspectorSettings.Default.StatDocumentViewingMode;
     this.ValueMode        = (StatValueMode)StatsInspectorSettings.Default.StatValueMode;
     this.TemplateFilename = StatsInspectorSettings.Default.LastTemplateFilename;
 }
コード例 #25
0
 private CamouflageInfo(TankInstance tankInstance, string exclusionMask)
 {
     _tankInstance      = tankInstance;
     this.ExclusionMask = exclusionMask;
 }
コード例 #26
0
 public CamouflageInfo(TankInstance tankInstance)
     : this(tankInstance, tankInstance["camouflage/exclusionMask"])
 {
 }
コード例 #27
0
 public abstract void BeginCapture(ISnapshotProvider snapshotProvider, TankInstance tank, Rect clippingRectangle, Color shadeColor, string outputFilename);
コード例 #28
0
 public CamouflageInfo(TankInstance tankInstance, Module module)
     : this(tankInstance, module["camouflage/exclusionMask"])
 {
 }
コード例 #29
0
 protected override ModelVMBase CreateModelVM(TankInstance tankInstance)
 {
     return(new ArmorViewVM(tankInstance));
 }
コード例 #30
0
 public StatVM(IStatValueGroup group, IStat stat, TankInstance tank)
     : base(stat, tank)
 {
     this.Group     = group;
     this.IsLoading = true;
 }