Exemple #1
0
        private TextureSet CreateVanillaTextureSet(TrainCarType trainCarType)
        {
            var    ts = new TextureSet();
            string path;

            switch (trainCarType)
            {
            case TrainCarType.LocoShunter:
                path = TexPath + "[Vanilla]/loco_621/";
                ImageConversion.LoadImage(ts.d = new Texture2D(1024, 1024), File.ReadAllBytes(path + "shunt_gauges_01d.png"));
                ImageConversion.LoadImage(ts.n = new Texture2D(1024, 1024), File.ReadAllBytes(path + "shunt_gauges_01n.png"));
                ImageConversion.LoadImage(ts.s = new Texture2D(1024, 1024), File.ReadAllBytes(path + "shunt_gauges_01s.png"));
                ImageConversion.LoadImage(ts.e = new Texture2D(1024, 1024), File.ReadAllBytes(path + "shunt_gauges_01e.png"));
                break;

            case TrainCarType.LocoSteamHeavy:
                path = TexPath + "[Vanilla]/loco_steam_H/";
                ImageConversion.LoadImage(ts.d = new Texture2D(1024, 1024), File.ReadAllBytes(path + "SH_gauges_01d.png"));
                break;

            case TrainCarType.LocoDiesel:
                path = TexPath + "[Vanilla]/LocoDiesel/";
                ImageConversion.LoadImage(ts.d = new Texture2D(2048, 1024), File.ReadAllBytes(path + "LocoDiesel_gauges_01d.png"));
                ImageConversion.LoadImage(ts.e = new Texture2D(2048, 1024), File.ReadAllBytes(path + "LocoDiesel_gauges_01e.png"));
                break;

            default: break;
            }

            return(ts);
        }
Exemple #2
0
        public static void Apply(TrainCarType carType, SoundType soundType, Config.SoundDefinition?soundDefinition, ref AudioClip[] clips)
        {
            var key = new DefaultKey(carType, soundType);

            Main.DebugLog(() => $"Loading {key}: {soundDefinition}");
            if (!Defaults.ContainsKey(key))
            {
                Defaults[key] = new AudioSettings()
                {
                    clips = clips
                }
            }
            ;

            if (soundDefinition != null && (soundDefinition.filenames?.Length ?? 0) > 0)
            {
                clips = soundDefinition.filenames.Select(FileAudio.Load).ToArray();
            }
            else if (soundDefinition?.filename != null)
            {
                clips = new AudioClip[] { FileAudio.Load(soundDefinition.filename) }
            }
            ;
            else
            {
                clips = Defaults[key].clips !;
            }
        }
Exemple #3
0
    private void OnQuestUncompleted(TrainCarType carType)
    {
        Debug.Log($"Handling uncomleted for {carType}, isBarSpawned: {isBarSpawned}, isHeadSpawned: {isHeadSpawned}");
        switch (carType)
        {
        case TrainCarType.Restaraunt:
            if (isBarSpawned)
            {
                isBarSpawned = false;
                RemoveOneTrainCar();
            }
            break;

        case TrainCarType.Head:
            if (isHeadSpawned)
            {
                isHeadSpawned = false;
                RemoveOneTrainCar();
            }
            break;

        default:
            Debug.Log($"Don't care about uncompleted {carType}");
            break;
        }
    }
Exemple #4
0
        public static void Apply(TrainCarType carType, SoundType soundType, Config.SoundDefinition?soundDefinition, AudioSource source)
        {
            var key = new DefaultKey(carType, soundType);

            Main.DebugLog(() => $"Loading {key}: {soundDefinition}");
            if (!Defaults.ContainsKey(key))
            {
                Defaults[key] = new AudioSettings()
                {
                    clip  = source.clip,
                    pitch = source.pitch,
                };
            }

            var defaults = Defaults[key];

            if (soundDefinition == null)
            {
                source.clip  = defaults.clip;
                source.pitch = defaults.pitch;
                return;
            }

            source.clip  = soundDefinition.filename.Map(FileAudio.Load) ?? defaults.clip;
            source.pitch = soundDefinition.pitch ?? defaults.pitch;
        }
 private void OnQuestStarted(TrainCarType carType)
 {
     if (carType == TrainCarType.Restaraunt)
     {
         isNextStarted = true;
     }
 }
Exemple #6
0
        private static void SetHorn(TrainCarType carType, CustomLocoAudioDiesel audio, SoundSet soundSet)
        {
            var hornHitSource = audio.hornAudio.transform.Find("train_horn_01_hit").GetComponent <AudioSource>();

            AudioUtils.Apply(carType, SoundType.HornHit, soundSet[SoundType.HornHit], hornHitSource);
            AudioUtils.Apply(carType, SoundType.HornLoop, soundSet[SoundType.HornLoop], audio.hornAudio);
        }
Exemple #7
0
 private static HashSet <string> GetBlockList(TrainCarType carType)
 {
     return(SpecialConsistManager.TrainDefinitions
            .SelectMany(train => train.Skins)
            .Where(skin => (skin.CarType == carType) && skin.ExpressOnly)
            .Select(skin => skin.Name)
            .ToHashSet());
 }
Exemple #8
0
 public static bool IsSelfLap(TrainCarType carType)
 {
     return(carType switch
     {
         TrainCarType.LocoShunter => Main.settings.shunterSelfLap,
         TrainCarType.LocoSteamHeavy => Main.settings.steamHeavySelfLap,
         TrainCarType.LocoDiesel => Main.settings.dieselSelfLap,
         _ => true,
     });
Exemple #9
0
        public static void Apply(TrainCarType carType, SoundType soundType, Config.SoundDefinition?soundDefinition, LayeredAudio audio)
        {
            var key = new DefaultKey(carType, soundType);

            Main.DebugLog(() => $"Loading {key}: {soundDefinition}");
            var mainLayer = audio.layers[0];

            if (!Defaults.ContainsKey(key))
            {
                Defaults[key] = new AudioSettings()
                {
                    clip        = mainLayer.source.clip,
                    pitch       = mainLayer.startPitch,
                    minPitch    = audio.minPitch,
                    maxPitch    = audio.maxPitch,
                    pitchCurve  = mainLayer.pitchCurve,
                    volumeCurve = mainLayer.volumeCurve,
                };
                Main.DebugLog(() => $"Saved default settings for {key}: {Defaults[key]}");
            }

            var defaults = Defaults[key];

            if (soundDefinition == null)
            {
                audio.minPitch        = defaults.minPitch !;
                audio.maxPitch        = defaults.maxPitch !;
                mainLayer.source.clip = defaults.clip;
                mainLayer.startPitch  = defaults.pitch;
                mainLayer.pitchCurve  = defaults.pitchCurve;
                mainLayer.volumeCurve = defaults.volumeCurve;
                for (int i = 1; i < audio.layers.Length; i++)
                {
                    audio.layers[i].source.mute = false;
                }
            }
            else
            {
                audio.minPitch        = soundDefinition.minPitch ?? defaults.minPitch * defaults.pitch;
                audio.maxPitch        = soundDefinition.maxPitch ?? defaults.maxPitch * defaults.pitch;
                mainLayer.source.clip = soundDefinition.filename.Map(FileAudio.Load) ?? defaults.clip;
                mainLayer.startPitch  = 1f;
                mainLayer.pitchCurve  = AnimationCurve.EaseInOut(
                    0f, soundDefinition.minPitch ?? defaults.pitchCurve.Evaluate(0),
                    1f, soundDefinition.maxPitch ?? defaults.pitchCurve.Evaluate(1));
                mainLayer.volumeCurve = AnimationCurve.EaseInOut(
                    0f, soundDefinition.minVolume ?? defaults.volumeCurve.Evaluate(0),
                    1f, soundDefinition.maxVolume ?? defaults.volumeCurve.Evaluate(1));

                for (int i = 1; i < audio.layers.Length; i++)
                {
                    audio.layers[i].source.mute = true;
                }
            }
        }
Exemple #10
0
        static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            GUILayout.BeginVertical();

            bool newAniso = GUILayout.Toggle(settings.aniso5, "Increase Anisotropic Filtering (Requires Manual Game Restart)");

            if (newAniso != settings.aniso5)
            {
                settings.aniso5 = newAniso;
            }
            GUILayout.Space(2);

            GUILayout.Label("Export Textures");

            GUILayout.BeginHorizontal(GUILayout.Width(250));

            GUILayout.BeginVertical();

            if (GUILayout.Button(trainCarSelected == TrainCarType.NotSet ? "Select Train Car" : prefabMap[trainCarSelected], GUILayout.Width(220)))
            {
                showDropdown = !showDropdown;
            }

            if (showDropdown)
            {
                scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, GUILayout.Height(350));

                foreach (var entry in prefabMap)
                {
                    if (GUILayout.Button(entry.Value, GUILayout.Width(220)))
                    {
                        showDropdown     = false;
                        trainCarSelected = entry.Key;
                    }
                }

                GUILayout.EndScrollView();
            }

            GUILayout.EndVertical();

            GUILayout.EndVertical();

            if (trainCarSelected != TrainCarType.NotSet)
            {
                if (GUILayout.Button("Export Textures", GUILayout.Width(180)))
                {
                    DumpTextures(trainCarSelected);
                }
            }

            GUILayout.EndHorizontal();
        }
        public static bool IsPassengerCar(TrainCarType carType)
        {
            switch (carType)
            {
            case TrainCarType.PassengerBlue:
            case TrainCarType.PassengerGreen:
            case TrainCarType.PassengerRed:
                return(true);

            default:
                return(false);
            }
        }
        private void UpdateAvailableSkinsList(TrainCarType carType)
        {
            if (Main.skinGroups.TryGetValue(carType, out SkinGroup skinGroup))
            {
                SkinsForCarType = skinGroup.skins;
            }
            else
            {
                SkinsForCarType = null;
            }

            SelectedSkinIdx = 0;
        }
Exemple #13
0
        public static void Register(TrainCarType carType)
        {
            Registry.Register(carType, tractiveEffortProvider);
            Registry.Register(carType, adhesionProvider);
            Registry.Register(carType, new QueryDataProvider(
                                  "Slip",
                                  () => Main.settings.ShowSlip,
                                  car => car.GetComponent <DrivingForce>().wheelslip * 100,
                                  f => $"{f.ToString("F1")} %"));

            if (CarTypes.IsSteamLocomotive(carType))
            {
                SteamLocoProviders.Register(carType);
            }
        }
Exemple #14
0
        static void Prefix(JObject savedData)
        {
            if (savedData == null)
            {
                Debug.LogError((object)"Given save data is null, loading will not be performed");
                return;
            }

            JObject carsSaveData = SaveGameManager.data.GetJObject("Mod_Skins");

            if (carsSaveData != null)
            {
                JObject[] jobjectArray = carsSaveData.GetJObjectArray("carsData");

                if (jobjectArray != null)
                {
                    foreach (JObject jobject in jobjectArray)
                    {
                        var guid = jobject.GetString("guid");
                        var name = jobject.GetString("name");

                        if (!Main.trainCarState.ContainsKey(guid))
                        {
                            Main.trainCarState.Add(guid, name);
                        }
                    }
                }

                JObject[] jobjectSkinArray = carsSaveData.GetJObjectArray("carSkins");

                if (jobjectArray != null)
                {
                    foreach (JObject jobject in jobjectSkinArray)
                    {
                        TrainCarType type = (TrainCarType)jobject.GetInt("type").Value;
                        string       skin = jobject.GetString("skin");

                        if (Main.selectedSkin.ContainsKey(type))
                        {
                            Main.selectedSkin[type] = skin;
                        }
                    }
                }
            }
        }
 public static List <CargoType> GetCargoTypesForCarType(TrainCarType trainCarType)
 {
     if (!trainCarTypeToCargoTypes.ContainsKey(trainCarType))
     {
         CargoContainerType containerType = CargoTypes.CarTypeToContainerType[trainCarType];
         Dictionary <CargoType, List <CargoContainerType> > cargoTypeToSupportedContainerTypes
             = Traverse.Create(typeof(CargoTypes))
               .Field("cargoTypeToSupportedCarContainer")
               .GetValue <Dictionary <CargoType, List <CargoContainerType> > >();
         trainCarTypeToCargoTypes[trainCarType] = (
             from ct in Enum.GetValues(typeof(CargoType)).Cast <CargoType>().ToList <CargoType>()
             where cargoTypeToSupportedContainerTypes.ContainsKey(ct) &&
             cargoTypeToSupportedContainerTypes[ct].Contains(containerType)
             select ct
             ).ToList();
     }
     return(trainCarTypeToCargoTypes[trainCarType]);
 }
Exemple #16
0
        private static void SetEngine(TrainCarType carType, CustomLocoAudioDiesel audio, SoundSet soundSet)
        {
            soundSet.sounds.TryGetValue(SoundType.EngineStartup, out var startup);
            AudioUtils.Apply(carType, SoundType.EngineStartup, startup, ref audio.engineOnClip);
            soundSet.sounds.TryGetValue(SoundType.EngineShutdown, out var shutdown);
            AudioUtils.Apply(carType, SoundType.EngineShutdown, shutdown, ref audio.engineOffClip);
            EngineFade.SetFadeSettings(audio, new EngineFade.Settings
            {
                fadeInStart     = startup?.fadeStart ?? 0.15f * audio.engineOnClip.length,
                fadeOutStart    = shutdown?.fadeStart ?? 0.10f * audio.engineOffClip.length,
                fadeInDuration  = startup?.fadeDuration ?? 2f,
                fadeOutDuration = shutdown?.fadeDuration ?? 1f,
            });

            AudioUtils.Apply(carType, SoundType.EngineLoop, soundSet[SoundType.EngineLoop], audio.engineAudio);
            AudioUtils.Apply(carType, SoundType.EngineLoadLoop, soundSet[SoundType.EngineLoadLoop], audio.enginePistonAudio);
            AudioUtils.Apply(carType, SoundType.TractionMotors, soundSet[SoundType.TractionMotors], audio.electricMotorAudio);
        }
Exemple #17
0
    public void AddTrainCarToTrain(TrainCarType carType)
    {
        if (carType == TrainCarType.Restaraunt && isBarSpawned)
        {
            return;
        }
        if (carType == TrainCarType.Head && isHeadSpawned)
        {
            return;
        }
        isBarSpawned  = carType == TrainCarType.Restaraunt;
        isHeadSpawned = carType == TrainCarType.Head;

        int indexOfLast = trainCars.Count - 1;
        var oldCar      = trainCars[indexOfLast];

        trainCars.Remove(oldCar);
        oldCar.transform.Translate(-oldCar.transform.localPosition.x, 0f, 0f);
        var newCar   = Instantiate <TrainCar>(trainCarPrefabs[(int)carType], transform);
        var plainCar = Instantiate <TrainCar>(trainCarPrefabs[(int)TrainCarType.Plain], transform);

        trainCars.Add(newCar);
        trainCars.Add(plainCar);
        trainCars.Add(oldCar);
        ConnectTrainCars(trainCars[indexOfLast - 1], newCar);
        ConnectTrainCars(newCar, plainCar);
        ConnectTrainCars(plainCar, oldCar);

        if (carType == TrainCarType.Head)
        {
            var first = trainCars[0];
            var last  = trainCars[trainCars.Count - 1];

            trainCars.Remove(first);
            trainCars.Remove(last);
            first.PlayerEntered -= OnPlayerReachedLeft;
            last.PlayerEntered  -= OnPlayerReachedRight;
            Destroy(first.gameObject);
            Destroy(last.gameObject);
        }
    }
Exemple #18
0
        static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            GUILayout.Label("Export Textures");

            GUILayout.BeginHorizontal(GUILayout.Width(250));

            GUILayout.BeginVertical();

            if (GUILayout.Button(trainCarSelected == TrainCarType.NotSet ? "Select Train Car" : prefabMap[trainCarSelected], GUILayout.Width(220)))
            {
                showDropdown = !showDropdown;
            }

            if (showDropdown)
            {
                scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, GUILayout.Height(350));

                foreach (var entry in prefabMap)
                {
                    if (GUILayout.Button(entry.Value, GUILayout.Width(220)))
                    {
                        showDropdown     = false;
                        trainCarSelected = entry.Key;
                    }
                }

                GUILayout.EndScrollView();
            }

            GUILayout.EndVertical();

            if (trainCarSelected != TrainCarType.NotSet)
            {
                if (GUILayout.Button("Export Textures", GUILayout.Width(180)))
                {
                    DumpTextures(trainCarSelected);
                }
            }

            GUILayout.EndHorizontal();
        }
Exemple #19
0
        private static decimal GetBasePrice(TrainCarType Type, TrainCarClass Class)
        {
            switch (Type)
            {
            case TrainCarType.Beds:
                return(45.99m);

            case TrainCarType.Compartments:
                switch (Class)
                {
                case TrainCarClass.Business: return(34.99m);

                case TrainCarClass.First: return(29.99m);

                case TrainCarClass.Second: return(20.99m);
                }
                break;
            }

            return(-1m);
        }
Exemple #20
0
        public static void SetSuperGauges(bool restoreDefaults = false, params TrainCarType[] types)
        {
            if (types == null || types.Length == 0)
            {
                types = new TrainCarType[] { TrainCarType.LocoShunter, TrainCarType.LocoSteamHeavy, TrainCarType.LocoDiesel }
            }
            ;

            if (restoreDefaults)
            {
                if (types.Contains(TrainCarType.LocoShunter))
                {
                    SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoShunter), true);
                }
                if (types.Contains(TrainCarType.LocoSteamHeavy))
                {
                    SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoSteamHeavy), true);
                }
                if (types.Contains(TrainCarType.LocoDiesel))
                {
                    SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoDiesel), true);
                }
                return;
            }

            if (types.Contains(TrainCarType.LocoShunter))
            {
                SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoShunter), !Main.settings.LocoShunterTRUE);
            }
            if (types.Contains(TrainCarType.LocoSteamHeavy))
            {
                SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoSteamHeavy), !Main.settings.LocoSteamerHeavyTRUE);
            }
            if (types.Contains(TrainCarType.LocoDiesel))
            {
                SetSuperGauge(CarTypes.GetCarPrefab(TrainCarType.LocoDiesel), !Main.settings.LocoDieselTRUE);
            }
        }
Exemple #21
0
        private static void GetPlainSkinsForCoachType(List <string> dest, TrainCarType carType, HashSet <string> blockList)
        {
            object skinGroup = SkinGroups[carType];

            if (skinsField.GetValue(skinGroup) is IList skinList)
            {
                foreach (object skin in skinList)
                {
                    if (skinNameField.GetValue(skin) is string skinName)
                    {
                        if (!blockList.Contains(skinName))
                        {
                            dest.Add(skinName);
                        }
                    }
                }
            }
            else
            {
                PassengerJobs.ModEntry.Logger.Error("Couldn't get skins list from skingroup");
                return;
            }
        }
Exemple #22
0
        public static void Apply(TrainCarType carType, SoundType soundType, Config.SoundDefinition?soundDefinition, ref AudioClip clip)
        {
            var key = new DefaultKey(carType, soundType);

            Main.DebugLog(() => $"Loading {key}: {soundDefinition}");
            if (!Defaults.ContainsKey(key))
            {
                Defaults[key] = new AudioSettings()
                {
                    clip = clip
                }
            }
            ;

            if (soundDefinition?.filename != null)
            {
                clip = FileAudio.Load(soundDefinition.filename);
            }
            else
            {
                clip = Defaults[key].clip !;
            }
        }
Exemple #23
0
        public static JobChainControllerWithEmptyHaulGeneration GenerateShuntingUnloadJobWithCarSpawning(
            StationController destinationStation,
            bool forceLicenseReqs,
            System.Random rng)
        {
            Debug.Log("[PersistentJobs] unload: generating with car spawning");
            YardTracksOrganizer yto = YardTracksOrganizer.Instance;
            List <CargoGroup>   availableCargoGroups = destinationStation.proceduralJobsRuleset.inputCargoGroups;
            int countTrainCars = rng.Next(
                destinationStation.proceduralJobsRuleset.minCarsPerJob,
                destinationStation.proceduralJobsRuleset.maxCarsPerJob);

            if (forceLicenseReqs)
            {
                Debug.Log("[PersistentJobs] unload: forcing license requirements");
                if (!LicenseManager.IsJobLicenseAcquired(JobLicenses.Shunting))
                {
                    Debug.LogError("[PersistentJobs] unload: Trying to generate a ShuntingUnload job with " +
                                   "forceLicenseReqs=true should never happen if player doesn't have Shunting license!");
                    return(null);
                }
                availableCargoGroups
                    = (from cg in availableCargoGroups
                       where LicenseManager.IsLicensedForJob(cg.CargoRequiredLicenses)
                       select cg).ToList();
                countTrainCars
                    = Math.Min(countTrainCars, LicenseManager.GetMaxNumberOfCarsPerJobWithAcquiredJobLicenses());
            }
            if (availableCargoGroups.Count == 0)
            {
                Debug.LogWarning("[PersistentJobs] unload: no available cargo groups");
                return(null);
            }

            CargoGroup chosenCargoGroup = Utilities.GetRandomFromEnumerable(availableCargoGroups, rng);

            // choose cargo & trainCar types
            Debug.Log("[PersistentJobs] unload: choosing cargo & trainCar types");
            List <CargoType>    availableCargoTypes  = chosenCargoGroup.cargoTypes;
            List <CargoType>    orderedCargoTypes    = new List <CargoType>();
            List <TrainCarType> orderedTrainCarTypes = new List <TrainCarType>();

            for (int i = 0; i < countTrainCars; i++)
            {
                CargoType chosenCargoType = Utilities.GetRandomFromEnumerable(availableCargoTypes, rng);
                List <CargoContainerType> availableContainers
                    = CargoTypes.GetCarContainerTypesThatSupportCargoType(chosenCargoType);
                CargoContainerType  chosenContainerType = Utilities.GetRandomFromEnumerable(availableContainers, rng);
                List <TrainCarType> availableTrainCarTypes
                    = CargoTypes.GetTrainCarTypesThatAreSpecificContainerType(chosenContainerType);
                TrainCarType chosenTrainCarType = Utilities.GetRandomFromEnumerable(availableTrainCarTypes, rng);
                orderedCargoTypes.Add(chosenCargoType);
                orderedTrainCarTypes.Add(chosenTrainCarType);
            }
            float approxTrainLength = yto.GetTotalCarTypesLength(orderedTrainCarTypes)
                                      + yto.GetSeparationLengthBetweenCars(countTrainCars);

            // choose starting track
            Debug.Log("[PersistentJobs] unload: choosing starting track");
            Track startingTrack
                = Utilities.GetTrackThatHasEnoughFreeSpace(yto, destinationStation.logicStation.yard.TransferInTracks, approxTrainLength);

            if (startingTrack == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Couldn't find startingTrack with enough free space for train!");
                return(null);
            }

            // choose random starting station
            // no need to ensure it has has free space; this is just a back story
            Debug.Log("[PersistentJobs] unload: choosing origin (inconsequential)");
            List <StationController> availableOrigins = new List <StationController>(chosenCargoGroup.stations);
            StationController        startingStation  = Utilities.GetRandomFromEnumerable(availableOrigins, rng);

            // spawn trainCars
            Debug.Log("[PersistentJobs] unload: spawning trainCars");
            RailTrack       railTrack        = SingletonBehaviour <LogicController> .Instance.LogicToRailTrack[startingTrack];
            List <TrainCar> orderedTrainCars = CarSpawner.SpawnCarTypesOnTrack(
                orderedTrainCarTypes,
                railTrack,
                true,
                0.0,
                false,
                true);

            if (orderedTrainCars == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Failed to spawn trainCars!");
                return(null);
            }

            JobChainControllerWithEmptyHaulGeneration jcc = GenerateShuntingUnloadJobWithExistingCars(
                startingStation,
                startingTrack,
                destinationStation,
                orderedTrainCars,
                orderedCargoTypes,
                rng,
                true);

            if (jcc == null)
            {
                Debug.LogWarning("[PersistentJobs] unload: Couldn't generate job chain. Deleting spawned trainCars!");
                SingletonBehaviour <CarSpawner> .Instance.DeleteTrainCars(orderedTrainCars, true);

                return(null);
            }

            return(jcc);
        }
Exemple #24
0
 public DefaultKey(TrainCarType cartype, SoundType soundType)
 {
     this.cartype   = cartype;
     this.soundType = soundType;
 }
Exemple #25
0
 public SkinGroup(TrainCarType trainCarType)
 {
     this.trainCarType = trainCarType;
 }
 public static bool IsPatched(TrainCarType type) => (patchedMask & (1 << (int)type)) > 0;
Exemple #27
0
        private static Skin CreateDefaultSkin(TrainCarType carType, string typeName)
        {
            GameObject carPrefab = CarTypes.GetCarPrefab(carType);

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

            Skin defSkin = new Skin($"Default_{typeName}");

            var cmps = carPrefab.gameObject.GetComponentsInChildren <MeshRenderer>();

            foreach (var cmp in cmps)
            {
                if (!cmp.material)
                {
                    continue;
                }

                if (GetMaterialTexture(cmp, "_MainTex") is Texture2D diffuse)
                {
                    defSkin.skinTextures.Add(new SkinTexture(diffuse.name, diffuse));
                }

                if (GetMaterialTexture(cmp, "_BumpMap") is Texture2D normal)
                {
                    defSkin.skinTextures.Add(new SkinTexture(normal.name, normal));
                }

                if (GetMaterialTexture(cmp, "_MetallicGlossMap") is Texture2D specular)
                {
                    defSkin.skinTextures.Add(new SkinTexture(specular.name, specular));
                }

                if (GetMaterialTexture(cmp, "_EmissionMap") is Texture2D emission)
                {
                    defSkin.skinTextures.Add(new SkinTexture(emission.name, emission));
                }
            }

            var trainCar = carPrefab.GetComponent <TrainCar>();

            if (trainCar?.interiorPrefab != null)
            {
                foreach (var cmp in trainCar.interiorPrefab.GetComponentsInChildren <MeshRenderer>())
                {
                    if (!cmp.material)
                    {
                        continue;
                    }

                    if (GetMaterialTexture(cmp, "_MainTex") is Texture2D diffuse)
                    {
                        defSkin.skinTextures.Add(new SkinTexture(diffuse.name, diffuse));
                    }

                    if (GetMaterialTexture(cmp, "_BumpMap") is Texture2D normal)
                    {
                        defSkin.skinTextures.Add(new SkinTexture(normal.name, normal));
                    }

                    if (GetMaterialTexture(cmp, "_MetallicGlossMap") is Texture2D specular)
                    {
                        defSkin.skinTextures.Add(new SkinTexture(specular.name, specular));
                    }

                    if (GetMaterialTexture(cmp, "_EmissionMap") is Texture2D emission)
                    {
                        defSkin.skinTextures.Add(new SkinTexture(emission.name, emission));
                    }
                }
            }

            return(defSkin);
        }
Exemple #28
0
        public static void DumpTextures(TrainCarType trainCarType)
        {
            MeshRenderer[] cmps;
            Dictionary <string, Texture> textureList;

            var obj = CarTypes.GetCarPrefab(trainCarType);

            var path = modPath + "Exported\\" + obj.name;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            cmps        = obj.GetComponentsInChildren <MeshRenderer>();
            textureList = new Dictionary <string, Texture>();

            foreach (var cmp in cmps)
            {
                if (!cmp.material)
                {
                    continue;
                }

                var diffuse  = GetMaterialTexture(cmp, "_MainTex");
                var normal   = GetMaterialTexture(cmp, "_BumpMap");
                var specular = GetMaterialTexture(cmp, "_MetallicGlossMap");
                var emission = GetMaterialTexture(cmp, "_EmissionMap");

                ExportTexture(path, diffuse, textureList);
                ExportTexture(path, normal, textureList, true);
                ExportTexture(path, specular, textureList);
                ExportTexture(path, emission, textureList);
            }

            var trainCar = obj.GetComponent <TrainCar>();

            if (trainCar.interiorPrefab != null)
            {
                cmps        = trainCar.interiorPrefab.GetComponentsInChildren <MeshRenderer>();
                textureList = new Dictionary <string, Texture>();

                foreach (var cmp in cmps)
                {
                    if (!cmp.material)
                    {
                        continue;
                    }

                    var diffuse  = GetMaterialTexture(cmp, "_MainTex");
                    var normal   = GetMaterialTexture(cmp, "_BumpMap");
                    var specular = GetMaterialTexture(cmp, "_MetallicGlossMap");
                    var emission = GetMaterialTexture(cmp, "_EmissionMap");

                    ExportTexture(path, diffuse, textureList);
                    ExportTexture(path, normal, textureList, true);
                    ExportTexture(path, specular, textureList);
                    ExportTexture(path, emission, textureList);
                }
            }
        }
Exemple #29
0
        public static void DrawModUI()
        {
            if (!isEnabled)
            {
                showDropdown = false;
                return;
            }

            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = true;

            GameObject   carToSpawn = SingletonBehaviour <CarSpawner> .Instance.carToSpawn;
            TrainCar     trainCar   = carToSpawn.GetComponent <TrainCar>();
            TrainCarType carType    = trainCar.carType;

            SkinGroup skinGroup  = Main.skinGroups[carType];
            string    selectSkin = Main.selectedSkin[carType];

            float menuHeight = 60f;

            float menuWidth   = 270f;
            float buttonWidth = 240f;
            bool  isMaxHeight = false;
            float maxHeight   = Screen.height - 200f;

            if (showDropdown)
            {
                float totalItemHeight = skinGroup.skins.Count * 23f;

                if (totalItemHeight > maxHeight)
                {
                    totalItemHeight = maxHeight;
                    isMaxHeight     = true;
                }

                menuHeight += totalItemHeight + 46f;
            }

            if (isMaxHeight)
            {
                buttonWidth -= 20f;
            }

            GUI.skin = DVGUI.skin;
            GUI.skin.label.fontSize  = 11;
            GUI.skin.button.fontSize = 10;
            GUI.color = new Color32(0, 0, 0, 200);
            GUI.Box(new Rect(20f, 20f, menuWidth, menuHeight), "");
            GUILayout.BeginArea(new Rect(30f, 20f, menuWidth, menuHeight));
            GUI.color = Color.yellow;
            GUILayout.Label("Skin Manager Menu :: " + carToSpawn.name);
            GUI.color = Color.white;
            GUILayout.Space(5f);

            if (showDropdown)
            {
                if (GUILayout.Button("=== " + selectSkin + " ===", GUILayout.Width(240f)))
                {
                    showDropdown = false;
                }

                if (isMaxHeight)
                {
                    scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, GUILayout.Width(245f), GUILayout.Height(menuHeight - 55f));
                }

                if (GUILayout.Button("Random", GUILayout.Width(buttonWidth)))
                {
                    showDropdown = false;
                    Main.selectedSkin[carType] = "Random";
                }

                if (GUILayout.Button("Default", GUILayout.Width(buttonWidth)))
                {
                    showDropdown = false;
                    Main.selectedSkin[carType] = "Default";
                }

                foreach (Skin skin in skinGroup.skins)
                {
                    if (GUILayout.Button(skin.name, GUILayout.Width(buttonWidth)))
                    {
                        showDropdown = false;
                        Main.selectedSkin[carType] = skin.name;
                    }
                }

                if (isMaxHeight)
                {
                    GUILayout.EndScrollView();
                }
            }
            else
            {
                if (GUILayout.Button("=== " + selectSkin + " ===", GUILayout.Width(240f)))
                {
                    showDropdown = true;
                }
            }

            GUILayout.EndArea();
        }
 public static void SetPatched(TrainCarType type) => patchedMask |= 1 << (int)type;