예제 #1
0
 private void UnloadDriverModel()
 {
     Remove(_driver);
     DisposeHelper.Dispose(ref _driver);
     _driverSteerAnimator = null;
     ObjectsChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #2
0
        private void LoadDriverModel()
        {
            if (_driver != null)
            {
                return;
            }

            var driverDescription = _carData.GetDriverDescription();

            if (driverDescription == null || !File.Exists(_driverModelFilename))
            {
                return;
            }

            var driver = new Kn5RenderableDriver(Kn5.FromFile(_driverModelFilename), Matrix.Translation(driverDescription.Offset),
                                                 _currentSkin == null ? null : Path.Combine(_skinsDirectory, _currentSkin),
                                                 AsyncTexturesLoading, _asyncOverrideTexturesLoading, _converter)
            {
                LiveReload     = LiveReload,
                MagickOverride = MagickOverride
            };

            _driver = driver;

            if (File.Exists(_driverHierarchyFilename))
            {
                driver.AlignNodes(Knh.FromFile(_driverHierarchyFilename));
            }

            _driverSteerAnimator = Lazier.Create(() => {
                var animator = CreateAnimator(RootDirectory, driverDescription.SteerAnimation,
                                              clampEnabled: false, skipFixed: false);
                if (animator == null)
                {
                    return(null);
                }

                animator.Reset += OnSteerAnimatorReset;
                return(animator);
            });
            _driverSteerLock = driverDescription.SteerAnimationLock;

            driver.LocalMatrix = RootObject.LocalMatrix;
            Add(driver);
            ObjectsChanged?.Invoke(this, EventArgs.Empty);

            if (_steerDeg != 0 || OptionFixKnh)
            {
                UpdateDriverSteerAnimation(GetSteerOffset());
            }

            if (DebugMode)
            {
                driver.DebugMode = true;
            }
        }
예제 #3
0
 void Config_NewConfig(object sender, ConfigurationChangeArgs e)
 {
     if (e.Param == "Ray.ReflectionLimit" || e.FullReload == true)
     {
         if (ObjectsChanged != null)
         {
             ObjectsChanged.Invoke(this, new EventArgs());
         }
     }
 }
예제 #4
0
 public void RaiseObjectsChange()
 {
     if (OnObjectsRaysChange != null)
     {
         OnObjectsRaysChange.Invoke(this, new EventArgs());
     }
     if (ObjectsChanged != null)
     {
         ObjectsChanged.Invoke(this, new EventArgs());
     }
 }
예제 #5
0
        private void InitializeDriver()
        {
            if (_driverSet)
            {
                return;
            }
            _driverSet = true;

            if (_driverHierarchyFilename == null)
            {
                _driverHierarchyFilename = Path.Combine(RootDirectory, "driver_base_pos.knh");
                _driverHierarchyWatcher  = SimpleDirectoryWatcher.WatchFile(_driverHierarchyFilename, () => {
                    _driver?.AlignNodes(Knh.FromFile(_driverHierarchyFilename));
                });
            }

            var driver = _carData.GetDriverDescription();

            if (driver == null)
            {
                return;
            }

            var contentDirectory = Path.GetDirectoryName(Path.GetDirectoryName(RootDirectory));

            if (contentDirectory == null)
            {
                return;
            }

            var driversDirectory = Path.Combine(contentDirectory, "driver");

            _driverModelFilename = Path.Combine(driversDirectory, driver.Name + ".kn5");
            _driverModelWatcher  = SimpleDirectoryWatcher.WatchFile(_driverModelFilename, ReloadDriverModel);
            LoadDriverModel();

            ObjectsChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #6
0
 public void MoveTo(string name, Point fromPoint, Point toPoint, bool Ray = false)
 {
     if (!Ray)
     {
         var obj = GetObjectByName(name);
         if (obj != null)
         {
             obj.MoveTo(toPoint, fromPoint);
             if (ObjectsChanged != null)
             {
                 ObjectsChanged.Invoke(this, new EventArgs());
             }
         }
     }
     else
     {
         var obj = GetRayByName(name);
         if (obj != null)
         {
             obj.MoveTo(toPoint, fromPoint);
             ((Ray)obj).ObjectsChanged(this, new EventArgs());
         }
     }
 }
예제 #7
0
        /////////////////////////////////////////

        public Component_Sensor()
        {
            _objects = new ReferenceList <Component_ObjectInSpace>(this, () => ObjectsChanged?.Invoke(this));
        }
예제 #8
0
        public int AddObject(ObjectProto ObjectToAdd)
        {
            int count = 0;

            foreach (ObjectProto x in objects)
            {
                if (!(x is BrightPoint))
                {
                    count++;
                }
            }
            if (WarnedObjects == false && WarnedObjectsFinalized == false && count >= 10)
            {
                DialogResult dr =
                    MessageBox.Show(STranslation.T["WarnObject"] + '\n' + STranslation.T["WantToContinue"],
                                    STranslation.T["Warning"], MessageBoxButtons.OKCancel);
                if (dr == DialogResult.OK)
                {
                    WarnedObjects = false;
                }
                else
                {
                    WarnedObjects = true;
                }
                WarnedObjectsFinalized = true;
            }
            if (WarnedObjectsFinalized == false || WarnedObjects == false)
            {
                ObjectToAdd.ID = objMaxID;
                CheckExistObj  = ObjectToAdd;
                ObjectProto Found = Objects.Find(CheckExistance);
                if (Found != null)
                {
                    MessageBox.Show(STranslation.T["FoundAnotherObjectWithThisName"]);
                    return(-1);
                }
                Objects.Add(ObjectToAdd);
                objMaxID++;
                if (Rays.Count != 0)
                {
                    ObjectsChanged.Invoke(this, new EventArgs());
                }
                if (OnObjectsRaysChange != null)
                {
                    OnObjectsRaysChange.Invoke(this, new EventArgs());
                }
                return(objMaxID - 1);
            }
            else if (ObjectToAdd is BrightPoint)
            {
                ObjectToAdd.ID = objMaxID;
                CheckExistObj  = ObjectToAdd;
                ObjectProto Found = Objects.Find(CheckExistance);
                if (Found != null)
                {
                    MessageBox.Show(STranslation.T["FoundAnotherObjectWithThisName"]);
                    return(-1);
                }
                Objects.Add(ObjectToAdd);
                objMaxID++;
                if (Rays.Count != 0)
                {
                    ObjectsChanged.Invoke(this, new EventArgs());
                }
                if (OnObjectsRaysChange != null)
                {
                    OnObjectsRaysChange.Invoke(this, new EventArgs());
                }
                return(objMaxID - 1);
            }
            return(-1);
        }