示例#1
0
文件: Haircut.cs 项目: ExAtom/GTA6
        private void EditorThreadLoop(object state)
        {
            Haircut haircut = (Haircut)state;

            void Rerender()
            {
                if (haircut.HairNeedsRender)
                {
                    haircut.Hair.RenderImage();
                    haircut.HairNeedsRender = false;
                }
                if (haircut.AreaToCutNeedsRender)
                {
                    haircut.AreaToCut.RenderImage();
                    haircut.AreaToCutNeedsRender = false;
                }
                if (haircut.FailedCutsNeedsRender)
                {
                    haircut.FailedCuts.RenderImage();
                    haircut.FailedCutsNeedsRender = false;
                }
            }

            int cycle = 0;

            while (true)
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                while (haircut.EditActions.Count > 0)
                {
                    if (stopWatch.ElapsedMilliseconds > 1000)
                    {
                        Rerender();
                    }
                    var job = haircut.EditActions.Take();
                    job();
                }
                stopWatch.Stop();
                Rerender();
                cycle++;
                if (cycle >= 20)
                {
                    cycle = 0;

                    haircut.AreaToCut.Lock();
                    int completePercent = haircut.CalculateCompletePercent();
                    haircut.AreaToCut.Unlock();

                    haircut.FailedCuts.Lock();
                    int failPercent = haircut.CalculateFailPercent();
                    haircut.FailedCuts.Unlock();

                    haircut.SetPercents(completePercent, failPercent);
                }
                Thread.Sleep(100);
            }
        }
示例#2
0
        public HaircutMinigameVM()
        {
            Shape = GetRandomShape();

            CameraOrientation = new CameraOrientation(Orientation.Top);
            CameraOrientation.PropertyChanged += OnCameraOrientationChanged;

            HaircutState = new HaircutState(Shape);
            HaircutState.PropertyChanged += OnHaircutStateChanged;

            CurrentSide.PropertyChanged += OnCurrentSideChanged;
            LastSide = CurrentSide;

            HUDVisibility = Visibility.Visible;
        }
示例#3
0
        private void OnCameraOrientationChanged(object sender, PropertyChangedEventArgs e)
        {
            OnPropertyChanged(nameof(CameraOrientation), GetNestedPropertyName(nameof(CameraOrientation), e));

            if (e.PropertyName == nameof(CameraOrientation.CurrentOrientation))
            {
                OnPropertyChanged(nameof(CurrentSide));

                LastSide.PropertyChanged -= OnCurrentSideChanged;
                LastSide.Hair.DetachCanvas();

                CurrentSide.PropertyChanged += OnCurrentSideChanged;
                LastSide = CurrentSide;
            }
        }
示例#4
0
        public HaircutState(DesiredShape shape)
        {
            Top = new Haircut(Orientation.Top, (Bitmap)shape.Top.Clone());
            Top.PropertyChanged += OnTopChanged;

            Front = new Haircut(Orientation.Front, (Bitmap)shape.Front.Clone());
            Front.PropertyChanged += OnFrontChanged;

            Left = new Haircut(Orientation.Left, (Bitmap)shape.Left.Clone());
            Left.PropertyChanged += OnLeftChanged;

            Rear = new Haircut(Orientation.Rear, (Bitmap)shape.Rear.Clone());
            Rear.PropertyChanged += OnRearChanged;

            Right = new Haircut(Orientation.Right, (Bitmap)shape.Right.Clone());
            Right.PropertyChanged += OnRightChanged;
        }