public void HudTiltMeterViewModelToolCanBeSerializedDeserializedWithProtobuf()
        {
            var hudLayoutToolExpected = new HudLayoutTiltMeterTool();

            var hudElement = new HudElementViewModel
            {
                Seat = 1,
            };

            var hudToolViewModelExpected = hudLayoutToolExpected.CreateViewModel(hudElement) as HudTiltMeterViewModel;

            hudToolViewModelExpected.Width    = 100;
            hudToolViewModelExpected.Height   = 75;
            hudToolViewModelExpected.Position = new System.Windows.Point(5, 5);
            hudToolViewModelExpected.Opacity  = 60;

            Assert.IsNotNull(hudToolViewModelExpected);

            var hudToolViewModelActual = SerializerHelper.GetSerializedDeserializedObject(hudToolViewModelExpected);

            Assert.That(hudToolViewModelActual.Id, Is.EqualTo(hudToolViewModelExpected.Id));
            Assert.That(hudToolViewModelActual.ToolType, Is.EqualTo(hudToolViewModelExpected.ToolType));
            Assert.That(hudToolViewModelActual.Width, Is.EqualTo(hudToolViewModelExpected.Width));
            Assert.That(hudToolViewModelActual.Height, Is.EqualTo(hudToolViewModelExpected.Height));
            Assert.That(hudToolViewModelActual.Position, Is.EqualTo(hudToolViewModelExpected.Position));
            Assert.That(hudToolViewModelActual.Opacity, Is.EqualTo(hudToolViewModelExpected.Opacity));
        }
示例#2
0
        /// <summary>
        /// Creates tilt meter view model
        /// </summary>
        /// <param name="creationInfo"><see cref="HudToolCreationInfo"/></param>
        /// <returns>Tilt meter view model</returns>
        private HudBaseToolViewModel CreateTiltMeterTool(HudToolCreationInfo creationInfo)
        {
            Check.Require(creationInfo.Layout != null, "Layout isn't defined. 4-stat box has not been created.");

            var layoutTool = new HudLayoutTiltMeterTool
            {
                UIPositions = GetHudUIPositions(EnumTableType.HU, EnumTableType.HU, creationInfo.Position)
            };

            layoutTool.UIPositions.ForEach(x =>
            {
                x.Width  = HudDefaultSettings.TiltMeterWidth;
                x.Height = HudDefaultSettings.TiltMeterHeight;
            });

            var toolViewModel = layoutTool.CreateViewModel(creationInfo.HudElement);

            toolViewModel.InitializePositions();

            if (toolViewModel.Parent != null)
            {
                toolViewModel.Parent.TiltMeter = HudDefaultSettings.TiltMeterDesignerValue;
            }

            creationInfo.Layout.LayoutTools.Add(layoutTool);

            return(toolViewModel);
        }