Exemplo n.º 1
0
        void UpdateLocalization()
        {
            if (m_localizationInitialized)
            {
                return;
            }

            try
            {
                // Localization
                Locale locale = (Locale)typeof(LocaleManager).GetFieldByName("m_Locale").GetValue(SingletonLite <LocaleManager> .instance);
                if (locale == null)
                {
                    throw new KeyNotFoundException("Locale is null");
                }

                Locale.Key k = new Locale.Key()
                {
                    m_Identifier = "NET_TITLE",
                    m_Key        = "Zonable Pedestrian Pavement"
                };
                locale.AddLocalizedString(k, "Pedestrian Road");

                k = new Locale.Key()
                {
                    m_Identifier = "NET_DESC",
                    m_Key        = "Zonable Pedestrian Pavement"
                };
                locale.AddLocalizedString(k, "Paved roads are nicer to walk on than gravel. They offer access to pedestrians and can be used by public service vehicles.");

                m_localizationInitialized = true;
            }
            catch (ArgumentException) {}
        }
Exemplo n.º 2
0
        private void SetTutorialLocale()
        {
            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic)
                            .GetValue(LocaleManager.instance);

            Locale.Key tutorialAdviserTitleKey = new Locale.Key
            {
                m_Identifier = "TUTORIAL_ADVISER_TITLE",
                m_Key        = kToggleButton,
            };
            if (!locale.Exists(tutorialAdviserTitleKey))
            {
                locale.AddLocalizedString(tutorialAdviserTitleKey, Translation.Instance.GetTranslation("FOREST-BRUSH-MODNAME"));
            }

            Locale.Key tutorialAdviserKey = new Locale.Key
            {
                m_Identifier = "TUTORIAL_ADVISER",
                m_Key        = kToggleButton
            };
            if (!locale.Exists(tutorialAdviserKey))
            {
                locale.AddLocalizedString(tutorialAdviserKey, Translation.Instance.GetTranslation("FOREST-BRUSH-TUTORIAL"));
            }
        }
Exemplo n.º 3
0
        private void ShowNetwork(string name, string desc, GeneratedScrollPanel panel, int constructionCost, int maintenanceCost, string prefixIcon)
        {
            UIButton button = panel.Find <UIButton>(name);

            if (button != null && button.name == name)
            {
                GameObject.DestroyImmediate(button);
            }

            NetInfo netInfo = PrefabCollection <NetInfo> .FindLoaded(name);

            if (netInfo == null)
            {
                DebugUtils.Warning("Couldn't find NetInfo named '" + name + "'");
                return;
            }

            //DebugUtils.Log("NetInfo named '" + name + "' found.");

            PlayerNetAI netAI = netInfo.m_netAI as PlayerNetAI;

            // Adding cost
            netAI.m_constructionCost = constructionCost;
            netAI.m_maintenanceCost  = maintenanceCost;

            // Making the prefab valid
            netInfo.m_availableIn    = ItemClass.Availability.All;
            netInfo.m_placementStyle = ItemClass.Placement.Manual;
            typeof(NetInfo).GetField("m_UICategory", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(netInfo, "PublicTransportPlane");

            // Adding icons
            netInfo.m_Atlas     = m_atlas;
            netInfo.m_Thumbnail = prefixIcon;

            // Adding missing locale
            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite <LocaleManager> .instance);

            Locale.Key key = new Locale.Key()
            {
                m_Identifier = "NET_TITLE", m_Key = name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, name);
            }
            key = new Locale.Key()
            {
                m_Identifier = "NET_DESC", m_Key = name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, desc);
            }

            typeof(GeneratedScrollPanel).GetMethod("CreateAssetItem", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, new object[] { netInfo });
        }
Exemplo n.º 4
0
        private void InstallLocalization()
        {
            if (sm_localizationInitialized)
            {
                return;
            }

            Logger.LogInfo("Updating Localization.");

            try
            {
                // Localization
                Locale locale = (Locale)typeof(LocaleManager).GetFieldByName("m_Locale").GetValue(SingletonLite <LocaleManager> .instance);
                if (locale == null)
                {
                    throw new KeyNotFoundException("Locale is null");
                }

                // Road Customizer Tool Advisor
                Locale.Key k = new Locale.Key()
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = "RoadCustomizer"
                };
                locale.AddLocalizedString(k, "Road Customizer Tool");

                k = new Locale.Key()
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = "RoadCustomizer"
                };
                locale.AddLocalizedString(k, "Vehicle and Speed Restrictions:\n\n" +
                                          "1. Hover over roads to display their lanes\n" +
                                          "2. Left-click to toggle selection of lane(s), right-click clears current selection(s)\n" +
                                          "3. With lanes selected, set vehicle and speed restrictions using the menu icons\n\n\n" +
                                          "Lane Changer:\n\n" +
                                          "1. Hover over roads and find an intersection (circle appears), then click to edit it\n" +
                                          "2. Entry points will be shown, click one to select it (right-click goes back to step 1)\n" +
                                          "3. Click the exit routes you wish to allow (right-click goes back to step 2)" +
                                          "\n\nUse PageUp/PageDown to toggle Underground View.");

                sm_localizationInitialized = true;
            }
            catch (ArgumentException e)
            {
                Logger.LogInfo("Unexpected " + e.GetType().Name + " updating localization: " + e.Message + "\n" + e.StackTrace + "\n");
            }

            Logger.LogInfo("Localization successfully updated.");
        }
Exemplo n.º 5
0
        public static void DefineLocalization(this INetInfoBuilder builder, Locale locale)
        {
            locale.AddLocalizedString(new Locale.Key
            {
                m_Identifier = "NET_TITLE",
                m_Key        = builder.Name
            }, builder.Name);

            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_DESC",
                m_Key        = builder.Name
            }, builder.Description);
        }
        public static void AddPrefabLocalizedStrings(this Locale locale, string name, string desc)
        {
            locale.AddLocalizedString(new Locale.Key
            {
                m_Identifier = "NET_TITLE",
                m_Key        = name
            }, name);

            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_DESC",
                m_Key        = name
            }, desc);
        }
Exemplo n.º 7
0
        public static void AddString(this LocaleManager localeManager, LocalizedString localizedString)
        {
            Locale locale = localeManager.GetLocale();

            // Construct 0-index id for the localized string from argument
            Locale.Key id;
            id.m_Identifier = localizedString.Identifier;
            id.m_Key        = localizedString.Key;
            id.m_Index      = 0;

            // Check if the id already exists; if so find next index
            if (locale.Exists(id))
            {
                // Log message lags game on large namelists
                // Log($"Localized string {localizedString.Identifier}[{localizedString.Key}] already exists, adding it with next available index.");
                id.m_Index = locale.CountUnchecked(id);
            }

            // Add the localized string
            locale.AddLocalizedString(id, localizedString.Value);

            // Set the string counts accordingly
            Dictionary <Locale.Key, int> localizedStringCounts = locale.GetLocalizedStringsCount();

            // The count at the exact index appears to always be 0
            localizedStringCounts[id] = 0;

            // index = 0 appears to be a special case and indicates the count of localized strings with the same identifier and key
            Locale.Key zeroIndexID = id;
            zeroIndexID.m_Index = 0;
            localizedStringCounts[zeroIndexID] = id.m_Index + 1;

            // Log message lags game on large namelists
            // Log($"Added localized string {id} = '{localizedString.Value}', count = {localizedStringCounts[zeroIndexID]}.");
        }
 public static void CreateNetTitleLocalizedString(this Locale locale, string key, string label)
 {
     locale.AddLocalizedString(new Locale.Key
     {
         m_Identifier = "NET_TITLE",
         m_Key        = key
     }, label);
 }
 public static void CreateNetDescriptionLocalizedString(this Locale locale, string key, string label)
 {
     locale.AddLocalizedString(new Locale.Key
     {
         m_Identifier = "NET_DESC",
         m_Key        = key
     }, label);
 }
 public static void AddCategoryLocalizedString(this Locale locale)
 {
     locale.AddLocalizedString(new Locale.Key()
     {
         m_Identifier = "MAIN_CATEGORY",
         m_Key        = Mod.NEXT_CATEGORY_NAME
     }, Mod.NEXT_CATEGORY_NAME);
 }
 public static void CreateMenuTitleLocalizedString(this Locale locale, string key, string label)
 {
     locale.AddLocalizedString(new Locale.Key()
     {
         m_Identifier = "MAIN_CATEGORY",
         m_Key        = key
     }, label);
 }
Exemplo n.º 12
0
        public void Load()
        {
            GameObject newRoad = GameObject.Instantiate <GameObject>(PrefabCollection <NetInfo> .FindLoaded(baseNetwork).gameObject);

            if (newRoad == null)
            {
                Debug.Log("newRoad is null");
            }
            newRoad.name = name;
            NetInfo ni = newRoad.GetComponent <NetInfo>();

            ni.m_prefabInitialized = false;
            ni.m_netAI             = null;
            typeof(NetInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ni, category);

            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite <LocaleManager> .instance);

            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_TITLE", m_Key = name
            }, title);
            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_DESC", m_Key = name
            }, description);

            MethodInfo initMethod = typeof(NetCollection).GetMethod("InitializePrefabs", BindingFlags.Static | BindingFlags.NonPublic);

            Singleton <LoadingManager> .instance.QueueLoadingAction((IEnumerator)initMethod.Invoke(null, new object[] {
                category,
                new[] { ni },
                new string[] { }
            }));

            Singleton <LoadingManager> .instance.QueueLoadingAction(inCoroutine(() =>
            {
                setup(ni);
                PrefabCollection <NetInfo> .BindPrefabs();
                GameObject.Find(category + "Panel").GetComponent <GeneratedScrollPanel>().RefreshPanel();
            }));
        }
Exemplo n.º 13
0
        public static void CreateMenuTitleLocalizedString(this Locale locale, string key, string label)
        {
            var k = new Locale.Key()
            {
                m_Identifier = "MAIN_CATEGORY",
                m_Key        = key
            };

            if (!Locale.Exists("MAIN_CATEGORY", key))
            {
                locale.AddLocalizedString(k, label);
            }
        }
Exemplo n.º 14
0
        public static void CreateNetDescriptionLocalizedString(this Locale locale, string key, string label)
        {
            var k = new Locale.Key()
            {
                m_Identifier = "NET_DESC",
                m_Key        = key
            };

            if (!Locale.Exists("NET_DESC", key))
            {
                locale.AddLocalizedString(k, label);
            }
        }
Exemplo n.º 15
0
        private void SetupLocalization()
        {
            var delivery_construction_key = new Locale.Key
            {
                m_Identifier = "VEHICLE_STATUS_CARGOTRUCK_DELIVER",
                m_Key        = "124",
                m_Index      = 0
            };
            var delivery_operation_key = new Locale.Key
            {
                m_Identifier = "VEHICLE_STATUS_CARGOTRUCK_DELIVER",
                m_Key        = "125",
                m_Index      = 0
            };

            var loc = new Locale();

            loc.AddLocalizedString(delivery_construction_key, Localization.Get("TRANSFER_CONSTRUCTION_RESOURCE_TO"));
            loc.AddLocalizedString(delivery_operation_key, Localization.Get("TRANSFER_OPERATION_RESOURCE_TO"));

            loc.appendOverride    = true;
            Locale.LocaleOverride = loc;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Setup the tutorial panel
        /// </summary>
        private void SetupTutorialPanel()
        {
            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);

            Locale.Key key = new Locale.Key
            {
                m_Identifier = "TUTORIAL_ADVISER_TITLE",
                m_Key        = m_toolbarButton.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, ModInfo.ModName);
            }
            key = new Locale.Key
            {
                m_Identifier = "TUTORIAL_ADVISER",
                m_Key        = m_toolbarButton.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, "Work in progress...");
            }
        }
        public static void ReloadTutorialTranslations()
        {
            Locale locale = (Locale)typeof(LocaleManager)
                            .GetField(
                "m_Locale",
                BindingFlags.Instance | BindingFlags.NonPublic)
                            ?.GetValue(SingletonLite <LocaleManager> .instance);

            foreach (KeyValuePair <string, string> entry in _translations)
            {
                if (!entry.Key.StartsWith(TUTORIAL_KEY_PREFIX))
                {
                    continue;
                }

                string identifier;
                string tutorialKey;

                if (entry.Key.StartsWith(TUTORIAL_HEAD_KEY_PREFIX))
                {
                    identifier  = "TUTORIAL_ADVISER_TITLE";
                    tutorialKey = TUTORIAL_KEY_PREFIX +
                                  entry.Key.Substring(TUTORIAL_HEAD_KEY_PREFIX.Length);
                }
                else if (entry.Key.StartsWith(TUTORIAL_BODY_KEY_PREFIX))
                {
                    identifier  = "TUTORIAL_ADVISER";
                    tutorialKey = TUTORIAL_KEY_PREFIX +
                                  entry.Key.Substring(TUTORIAL_BODY_KEY_PREFIX.Length);
                }
                else
                {
                    continue;
                }

                // Log._Debug($"Adding tutorial translation for id {identifier}, key={tutorialKey}
                //     value={entry.Value}");
                Locale.Key key = new Locale.Key()
                {
                    m_Identifier = identifier,
                    m_Key        = tutorialKey
                };

                if (locale != null && !locale.Exists(key))
                {
                    locale.AddLocalizedString(key, entry.Value);
                }
            }
        }
Exemplo n.º 18
0
        private bool RefreshUnits(string displayUnit)
        {
            customLocale.Reset();

            IDictionary <string, string> overridden = localizationProvider.GetOverriddenTranslations(OverrddenTranslationType);

            if (overridden == null || overridden.Count == 0)
            {
                return(false);
            }

            foreach (KeyValuePair <string, string> value in overridden)
            {
                string translated = value.Value.Replace(UnitPlaceholder, displayUnit);
                customLocale.AddLocalizedString(new Locale.Key {
                    m_Identifier = value.Key
                }, translated);
            }

            mainLocale.Merge(null, customLocale);
            return(true);
        }
Exemplo n.º 19
0
        private static Locale LocaleFromFile(string file)
        {
            var locale = new Locale();

            using (var reader = new StreamReader(File.OpenRead(file)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var rows = line.Split('\t');
                    if (rows.Length < 2)
                    {
                        Debug.LogErrorFormat("Not enough tabs in locale string from {0}:\n'{1}'", file, line);
                        continue;
                    }
                    locale.AddLocalizedString(new Locale.Key {
                        m_Identifier = rows[0]
                    }, rows[1]);
                }
            }
            return(locale);
        }
Exemplo n.º 20
0
        public override void Start()
        {
            try
            {
                UIView view = GetUIView();

                name             = "AdvancedVehicleOptions";
                backgroundSprite = "UnlockingPanel2";
                isVisible        = false;
                canFocus         = true;
                isInteractive    = true;
                width            = WIDTHLEFT + WIDTHRIGHT;
                height           = HEIGHT;
                relativePosition = new Vector3(Mathf.Floor((view.fixedWidth - width) / 2), Mathf.Floor((view.fixedHeight - height) / 2));

                // Get camera controller
                GameObject go = GameObject.FindGameObjectWithTag("MainCamera");
                if (go != null)
                {
                    m_cameraController = go.GetComponent <CameraController>();
                }

                // Setting up UI
                SetupControls();

                // Adding main button
                UITabstrip toolStrip = view.FindUIComponent <UITabstrip>("MainToolstrip");
                m_button = AddUIComponent <UIButton>();

                m_button.normalBgSprite  = "InfoIconTrafficCongestion";
                m_button.focusedFgSprite = "ToolbarIconGroup6Focused";
                m_button.hoveredFgSprite = "ToolbarIconGroup6Hovered";

                m_button.size             = new Vector2(43f, 47f);
                m_button.name             = AVOMod.ModName;
                m_button.tooltip          = "Modify various Vehicle properties";
                m_button.relativePosition = new Vector3(0, 5);

                // GUI Button is pressed in game
                m_button.eventButtonStateChanged += (c, s) =>
                {
                    if (s == UIButton.ButtonState.Focused)
                    {
                        if (!isVisible)
                        {
                            isVisible = true;
                            m_fastList.DisplayAt(m_fastList.listPosition);
                            m_optionPanel.Show(m_fastList.rowsData[m_fastList.selectedIndex] as VehicleOptions);
                            m_followVehicle.isVisible = m_preview.parent.isVisible = true;
                            AdvancedVehicleOptions.UpdateOptionPanelInfo();
                        }
                    }
                    else
                    {
                        isVisible = false;
                        m_button.Unfocus();
                    }
                };

                toolStrip.AddTab("Advanced Vehicle Options", m_button.gameObject, null, null);

                FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic);
                m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1);

                m_title.closeButton.eventClick += (component, param) =>
                {
                    toolStrip.closeButton.SimulateClick();
                };

                Locale     locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);
                Locale.Key key    = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = m_button.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, m_button.name);
                }
                key = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = m_button.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "");
                }

                view.FindUIComponent <UITabContainer>("TSContainer").AddUIComponent <UIPanel>().color = new Color32(0, 0, 0, 0);

                optionList = AdvancedVehicleOptions.config.options;
                Logging.Message("UI initialized.");
            }
            catch (Exception e)
            {
                Logging.Error("UI initialization failed.");
                Logging.LogException(e);

                if (m_button != null)
                {
                    Destroy(m_button.gameObject);
                }

                Destroy(gameObject);
            }
        }
Exemplo n.º 21
0
        private void SaveAsset(string assetName, string packageName)
        {
            if (m_info == null || string.IsNullOrEmpty(assetName) || string.IsNullOrEmpty(packageName))
            {
                return;
            }

            Debug.Log("Starting save for asset " + assetName + " in package " + packageName);

            Package package = new Package(packageName);

            // Create lead vehicle prefab object
            VehicleInfo leadInfo = Util.InstantiateVehicleCopy(m_info);

            leadInfo.name = assetName;

            string[] steamTags = leadInfo.GetSteamTags();

            // Set up trailers
            if (m_info.m_trailers != null && m_info.m_trailers.Length > 0)
            {
                // Keep track of added trailer prefabs to prevent duplicates
                Dictionary <string, VehicleInfo> addedTrailers = new Dictionary <string, VehicleInfo>();

                for (int i = 0; i < m_info.m_trailers.Length; i++)
                {
                    VehicleInfo trailerInfo;
                    if (!addedTrailers.TryGetValue(m_info.m_trailers[i].m_info.name, out trailerInfo))
                    {
                        Debug.Log("Trailer " + m_info.m_trailers[i].m_info.name + " not yet in package " + packageName);

                        // Trailer not yet added to package
                        trailerInfo = Util.InstantiateVehicleCopy(m_info.m_trailers[i].m_info);

                        // Set placment mode to Procedural, this seems to be the only difference between engines (Automatic) and trailers (Procedural)
                        trailerInfo.m_placementStyle = ItemClass.Placement.Procedural;

                        // Include packagename in trailer, fixes Duplicate Prefab errors with multi .crp workshop uploads
                        if (m_namingDropdown.selectedIndex == 0)
                        {
                            // TrailerPackageName0
                            trailerInfo.name = "Trailer" + packageName + addedTrailers.Count;
                            Debug.Log("Renaming copy of trailer " + m_info.m_trailers[i].m_info.name + " to " + trailerInfo.name + " in package " + packageName);
                        }
                        else
                        {
                            // Default, Trailer0
                            trailerInfo.name = "Trailer" + addedTrailers.Count;
                        }


                        // Fix for 1.6
                        try { trailerInfo.m_mesh.name += packageName; } catch (Exception e) { Debug.LogException(e); Debug.Log("me"); };
                        try { trailerInfo.m_lodMesh.name += packageName; } catch (Exception e) { Debug.LogException(e); Debug.Log("lme"); };
                        try { trailerInfo.m_material.name += packageName; } catch (Exception e) { Debug.LogException(e); Debug.Log("m"); };
                        try { trailerInfo.m_lodMaterial.name += packageName; } catch (Exception e) { Debug.LogException(e); Debug.Log("lm"); };

                        // Needed because of the 'set engine' feature.
                        trailerInfo.m_trailers = null;

                        // Add stuff to package
                        //PackVariationMasksInSubMeshNames(trailerInfo);    // Don't actually do it for trailers, they should already have the name set correctly
                        Package.Asset trailerAsset = package.AddAsset(trailerInfo.name, trailerInfo.gameObject);

                        package.AddAsset(packageName + "_trailer" + addedTrailers.Count, new CustomAssetMetaData
                        {
                            assetRef  = trailerAsset,
                            name      = trailerInfo.name,
                            guid      = Guid.NewGuid().ToString(),
                            steamTags = steamTags,
                            type      = CustomAssetMetaData.Type.Trailer,
                            timeStamp = DateTime.Now,
                            dlcMask   = AssetImporterAssetTemplate.GetAssetDLCMask(trailerInfo),
                            mods      = EmbedModInfo()
                        }, UserAssetType.CustomAssetMetaData);

                        // Don't need the locale

                        // Update dictonary
                        addedTrailers.Add(m_info.m_trailers[i].m_info.name, trailerInfo);

                        Debug.Log("Finished adding trailer " + trailerInfo.name + " to package " + packageName);
                    }

                    leadInfo.m_trailers[i].m_info = trailerInfo;
                }
            }

            // Add lead vehicle to package

            var assetImport = FindObjectOfType <AssetImporterAssetImport>();

            if (assetImport == null)
            {
                Util.LogWarning("Unable to find AssetImporterAssetImport object");
            }
            else if (string.IsNullOrEmpty(leadInfo.m_Thumbnail)) // Regenerate thumbnails because they are pretty
            {
                var thumbnails = new Texture2D[5];
                thumbnails[0] = null;
                assetImport.m_PreviewCamera.target = leadInfo.gameObject;
                AssetImporterThumbnails.CreateThumbnails(leadInfo.gameObject, null, assetImport.m_PreviewCamera);
            }

            FixSubmeshInfoNames(leadInfo);
            PackVariationMasksInSubMeshNames(leadInfo, true);
            Package.Asset leadAsset = package.AddAsset(assetName + "_Data", leadInfo.gameObject);

            // Previews
            Package.Asset steamPreviewRef = null;
            Package.Asset imageRef        = null;

            // Add snapshot image
            if (m_snapshotPaths.Count > 0)
            {
                Image image = new Image(m_snapshotPaths[m_currentSnapshot]);
                image.Resize(644, 360);
                steamPreviewRef = package.AddAsset(assetName + "_SteamPreview", image, false, Image.BufferFileFormat.PNG, false, false);
                image           = new Image(m_snapshotPaths[m_currentSnapshot]);
                image.Resize(400, 224);
                imageRef = package.AddAsset(assetName + "_Snapshot", image, false, Image.BufferFileFormat.PNG, false, false);
            }

            package.AddAsset(packageName, new CustomAssetMetaData
            {
                // Name of asset
                name = assetName,
                // Time created?
                timeStamp = DateTime.Now,
                // Reference to Asset (VehicleInfo GameObject) added to the package earlier
                assetRef = leadAsset,
                // Snapshot
                imageRef = imageRef,
                // Steam Preview
                steamPreviewRef = steamPreviewRef,
                // Steam tags
                steamTags = steamTags,
                // Asset GUID
                guid = Guid.NewGuid().ToString(),
                // Type of this asset
                type = CustomAssetMetaData.Type.Vehicle,
                // DLCs required for this asset
                dlcMask = AssetImporterAssetTemplate.GetAssetDLCMask(leadInfo),
                // Mods active when making asset
                mods = EmbedModInfo()
            }, UserAssetType.CustomAssetMetaData, false);

            // Set main asset to lead vehicle
            package.packageMainAsset = packageName;

            // Create and add locale
            Locale locale = new Locale();

            locale.AddLocalizedString(new Locale.Key
            {
                m_Identifier = "VEHICLE_TITLE",
                m_Key        = assetName + "_Data"
            }, assetName);
            package.AddAsset(assetName + "_Locale", locale, false);

            // Save package to file
            package.Save(GetSavePathName(packageName));

            Debug.Log("Finished save for asset " + assetName + " in package " + packageName);

            m_info    = null;
            isVisible = false;
        }
Exemplo n.º 22
0
        // TODO: Put this in its own class
        void UpdateLocalization()
        {
            if (sm_localizationInitialized)
            {
                return;
            }

            Debug.Log("Traffic++: Updating Localization.");

            try
            {
                // Localization
                Locale locale = (Locale)typeof(LocaleManager).GetFieldByName("m_Locale").GetValue(SingletonLite <LocaleManager> .instance);
                if (locale == null)
                {
                    throw new KeyNotFoundException("Locale is null");
                }

                // Pedestrian Pavement
                Locale.Key k = new Locale.Key()
                {
                    m_Identifier = "NET_TITLE",
                    m_Key        = "Zonable Pedestrian Pavement"
                };
                locale.AddLocalizedString(k, "Pedestrian Road");

                k = new Locale.Key()
                {
                    m_Identifier = "NET_DESC",
                    m_Key        = "Zonable Pedestrian Pavement"
                };
                locale.AddLocalizedString(k, "Paved roads are nicer to walk on than gravel. They offer access to pedestrians and can be used by public service vehicles.");

                // Pedestrian Gravel
                k = new Locale.Key()
                {
                    m_Identifier = "NET_TITLE",
                    m_Key        = "Zonable Pedestrian Gravel"
                };
                locale.AddLocalizedString(k, "Pedestrian Gravel Road");

                k = new Locale.Key()
                {
                    m_Identifier = "NET_DESC",
                    m_Key        = "Zonable Pedestrian Gravel"
                };
                locale.AddLocalizedString(k, "Gravel roads allow pedestrians to walk fast and easy. They can also be used by public service vehicles.");

                // Large road with bus
                k = new Locale.Key()
                {
                    m_Identifier = "NET_TITLE",
                    m_Key        = "Large Road With Bus Lanes"
                };
                locale.AddLocalizedString(k, "Six-Lane Road With Bus Lanes");

                k = new Locale.Key()
                {
                    m_Identifier = "NET_DESC",
                    m_Key        = "Large Road With Bus Lanes"
                };
                locale.AddLocalizedString(k, "A six-lane road with parking spaces and dedicated bus lanes. The bus lanes can be used by vehicles in emergency. Supports high-traffic.");

                sm_localizationInitialized = true;
            }
            catch (ArgumentException e)
            {
                Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " updating localization: " + e.Message + "\n" + e.StackTrace + "\n");
            }

            Debug.Log("Traffic++: Localization successfully updated.");
        }
Exemplo n.º 23
0
        public void Start()
        {
            try
            {
                GameObject gameObject = GameObject.Find("FindItMainButton");
                if (gameObject != null)
                {
                    return;
                }

                isRicoEnabled     = IsRicoEnabled();
                isPOEnabled       = IsPOEnabled();
                isTVPPatchEnabled = IsTVPPatchEnabled();

                if (isPOEnabled)
                {
                    POTool = new ProceduralObjectsTool();
                }

                list = AssetTagList.instance;

                UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip;

                m_defaultXPos = tabstrip.relativePosition.x;
                UpdateMainToolbar();

                GameObject asGameObject  = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
                GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate");

                mainButton       = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton;
                mainButton.atlas = atlas;

                mainButton.normalBgSprite   = "ToolbarIconGroup6Normal";
                mainButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
                mainButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
                mainButton.pressedBgSprite  = "ToolbarIconGroup6ressed";
                mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled";

                mainButton.normalFgSprite   = "FindIt";
                mainButton.focusedFgSprite  = "FindItFocused";
                mainButton.hoveredFgSprite  = "FindItHovered";
                mainButton.pressedFgSprite  = "FindItPressed";
                mainButton.disabledFgSprite = "FindItDisabled";

                mainButton.tooltip = "Find It! " + (ModInfo.isBeta ? "[BETA] " : "") + ModInfo.version;

                Locale     locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);
                Locale.Key key    = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Find It! " + ModInfo.version);
                }
                key = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Thanks for subscribing to Find It! 2.\n\nStart typing some keywords into the input field to find the desired asset.\n\nCheck the workshop page occasionally for new features or bug reports.");
                }

                FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic);
                m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1);

                mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name;
                m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel;

                if (m_groupPanel != null)
                {
                    m_groupPanel.name    = "FindItGroupPanel";
                    m_groupPanel.enabled = true;
                    m_groupPanel.component.isInteractive   = true;
                    m_groupPanel.m_OptionsBar              = ToolsModifierControl.mainToolbar.m_OptionsBar;
                    m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas;
                    if (ToolsModifierControl.mainToolbar.enabled)
                    {
                        m_groupPanel.RefreshPanel();
                    }

                    scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>());
                    scrollPanel.eventClicked           += OnButtonClicked;
                    scrollPanel.eventVisibilityChanged += (c, p) =>
                    {
                        HideAllOptionPanels();

                        if (p && scrollPanel.selectedItem != null)
                        {
                            // Simulate item click
                            UIScrollPanelItem.ItemData item = scrollPanel.selectedItem;

                            UIScrollPanelItem panelItem = scrollPanel.GetItem(0);
                            panelItem.Display(scrollPanel.selectedItem, 0);
                            panelItem.component.SimulateClick();

                            scrollPanel.selectedItem = item;

                            scrollPanel.Refresh();
                        }
                    };

                    scrollPanel.eventTooltipEnter += (c, p) =>
                    {
                        UIScrollPanelItem.RefreshTooltipAltas(p.source);
                    };

                    searchBox                  = scrollPanel.parent.AddUIComponent <UISearchBox>();
                    searchBox.scrollPanel      = scrollPanel;
                    searchBox.relativePosition = new Vector3(0, 0);
                    searchBox.Search();
                }
                else
                {
                    Debugging.Message("GroupPanel not found");
                }

                m_roadsPanel          = FindObjectOfType <RoadsPanel>();
                m_beautificationPanel = FindObjectOfType <BeautificationPanel>();

                defaultPanel                 = GameObject.Find("FindItDefaultPanel").GetComponent <UIPanel>();
                defaultPanelAtlas            = defaultPanel.atlas;
                defaultPanelBackgroundSprite = defaultPanel.backgroundSprite;
                UpdateDefaultPanelBackground();

                Debugging.Message("Initialized");
            }
            catch (Exception e)
            {
                Debugging.Message("Start failed");
                Debugging.LogException(e);
                enabled = false;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Set up access to airport roads. Modified from SamsamTS's Airport Roads mod
        /// </summary>
        public void SetAirplaneRoads(PrefabInfo prefab)
        {
            int    constructionCost = 0;
            int    maintenanceCost  = 0;
            string thumbnail        = "";

            if (prefab.name == "Airplane Runway")
            {
                constructionCost = 7000;
                maintenanceCost  = 600;
                thumbnail        = "Runway";
            }
            else if (prefab.name == "Aviation Club Runway")
            {
                constructionCost     = 7000;
                maintenanceCost      = 600;
                thumbnail            = "Runway";
                prefab.m_dlcRequired = SteamHelper.DLC_BitMask.UrbanDLC; // Sunset Harbor
            }
            else if (prefab.name == "Airplane Taxiway")
            {
                constructionCost = 4000;
                maintenanceCost  = 200;
                thumbnail        = "Taxiway";
            }

            // Adding cost
            NetInfo netInfo = prefab as NetInfo;

            if (netInfo == null)
            {
                return;
            }
            PlayerNetAI netAI = netInfo.m_netAI as PlayerNetAI;

            netAI.m_constructionCost = constructionCost;
            netAI.m_maintenanceCost  = maintenanceCost;

            // Making the prefab valid
            netInfo.m_availableIn    = ItemClass.Availability.All;
            netInfo.m_placementStyle = ItemClass.Placement.Manual;
            typeof(NetInfo).GetField("m_UICategory", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(netInfo, "PublicTransportPlane");

            // Adding icons
            netInfo.m_Atlas            = SamsamTS.UIUtils.GetAtlas("FindItAtlas");
            netInfo.m_Thumbnail        = thumbnail;
            netInfo.m_InfoTooltipAtlas = SamsamTS.UIUtils.GetAtlas("FindItAtlas");

            // Adding missing locale
            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite <LocaleManager> .instance);

            Locale.Key key = new Locale.Key()
            {
                m_Identifier = "NET_TITLE", m_Key = prefab.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, prefab.name);
            }
            key = new Locale.Key()
            {
                m_Identifier = "NET_DESC", m_Key = prefab.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, thumbnail);
            }
        }
Exemplo n.º 25
0
        public void Start()
        {
            try
            {
                isRicoEnabled = IsRicoEnabled();

                GameObject gameObject = GameObject.Find("FindItMainButton");
                if (gameObject != null)
                {
                    return;
                }

                list = AssetTagList.instance;

                UITabstrip tabstrip = ToolsModifierControl.mainToolbar.component as UITabstrip;


                // TODO: temporary

                /*tabstrip.eventComponentAdded += (c, p) =>
                 * {
                 *  foreach (UIComponent tab in tabstrip.tabPages.components)
                 *  {
                 *      DebugUtils.Log(tab.name);
                 *
                 *      if(tab.name == "LandscapingPanel")
                 *      {
                 *          tab.components[0].relativePosition = new Vector3(0, -134);
                 *          tab.components[1].relativePosition = new Vector3(0, -109);
                 *          tab.components[1].height = 218;
                 *          foreach(UIScrollablePanel panel in tab.components[1].GetComponentsInChildren<UIScrollablePanel>())
                 *          {
                 *              panel.autoLayoutStart = LayoutStart.TopLeft;
                 *              panel.scrollWheelDirection = UIOrientation.Vertical;
                 *              panel.scrollWheelAmount = 104;
                 *              panel.wrapLayout = true;
                 *              panel.width = 764;
                 *          }
                 *      }
                 *  }
                 * };*/

                m_defaultXPos = tabstrip.relativePosition.x;
                UpdateMainToolbar();

                GameObject asGameObject  = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
                GameObject asGameObject2 = UITemplateManager.GetAsGameObject("ScrollableSubPanelTemplate");

                mainButton       = tabstrip.AddTab("FindItMainButton", asGameObject, asGameObject2, new Type[] { typeof(UIGroupPanel) }) as UIButton;
                mainButton.atlas = atlas;

                Locale     locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(LocaleManager.instance);
                Locale.Key key    = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER_TITLE",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Find It! " + ModInfo.version);
                }
                key = new Locale.Key
                {
                    m_Identifier = "TUTORIAL_ADVISER",
                    m_Key        = mainButton.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, "Thanks for subscribing to Find It!\n\nStart typing some keywords into the input field to find the desired asset.\n\nIf you like the mod please consider leaving a rating on the steam workshop.");
                }

                FieldInfo m_ObjectIndex = typeof(MainToolbar).GetField("m_ObjectIndex", BindingFlags.Instance | BindingFlags.NonPublic);
                m_ObjectIndex.SetValue(ToolsModifierControl.mainToolbar, (int)m_ObjectIndex.GetValue(ToolsModifierControl.mainToolbar) + 1);

                mainButton.gameObject.GetComponent <TutorialUITag>().tutorialTag = name;
                m_groupPanel = tabstrip.GetComponentInContainer(mainButton, typeof(UIGroupPanel)) as UIGroupPanel;

                if (m_groupPanel != null)
                {
                    m_groupPanel.name    = "FindItGroupPanel";
                    m_groupPanel.enabled = true;
                    m_groupPanel.component.isInteractive   = true;
                    m_groupPanel.m_OptionsBar              = ToolsModifierControl.mainToolbar.m_OptionsBar;
                    m_groupPanel.m_DefaultInfoTooltipAtlas = ToolsModifierControl.mainToolbar.m_DefaultInfoTooltipAtlas;
                    if (ToolsModifierControl.mainToolbar.enabled)
                    {
                        m_groupPanel.RefreshPanel();
                    }

                    scrollPanel = UIScrollPanel.Create(m_groupPanel.GetComponentInChildren <UIScrollablePanel>());
                    scrollPanel.eventClicked           += OnButtonClicked;
                    scrollPanel.eventVisibilityChanged += (c, p) =>
                    {
                        HideAllOptionPanels();

                        if (p && scrollPanel.selectedItem != null)
                        {
                            // Simulate item click
                            UIScrollPanelItem.ItemData item = scrollPanel.selectedItem;

                            UIScrollPanelItem panelItem = scrollPanel.GetItem(0);
                            panelItem.Display(scrollPanel.selectedItem, 0);
                            panelItem.component.SimulateClick();

                            scrollPanel.selectedItem = item;

                            scrollPanel.Refresh();
                        }
                    };

                    scrollPanel.eventTooltipEnter += (c, p) =>
                    {
                        UIScrollPanelItem.RefreshTooltipAltas(p.source);
                    };

                    searchBox                  = scrollPanel.parent.AddUIComponent <UISearchBox>();
                    searchBox.scrollPanel      = scrollPanel;
                    searchBox.relativePosition = new Vector3(0, 0);
                    searchBox.Search();
                }
                else
                {
                    DebugUtils.Warning("GroupPanel not found");
                }

                mainButton.normalBgSprite   = "ToolbarIconGroup6Normal";
                mainButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
                mainButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
                mainButton.pressedBgSprite  = "ToolbarIconGroup6ressed";
                mainButton.disabledBgSprite = "ToolbarIconGroup6Disabled";

                mainButton.normalFgSprite   = "FindIt";
                mainButton.focusedFgSprite  = "FindItFocused";
                mainButton.hoveredFgSprite  = "FindItHovered";
                mainButton.pressedFgSprite  = "FindItPressed";
                mainButton.disabledFgSprite = "FindItDisabled";

                mainButton.tooltip = "Find It! " + ModInfo.version;

                m_beautificationPanel = FindObjectOfType <BeautificationPanel>();

                DebugUtils.Log("Initialized");
            }
            catch (Exception e)
            {
                DebugUtils.Log("Start failed");
                DebugUtils.LogException(e);
                enabled = false;
            }
        }