Exemple #1
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]}.");
        }
Exemple #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"));
            }
        }
Exemple #3
0
        public static void RemoveRange(this LocaleManager localeManager, Locale.Key id)
        {
            var locale = localeManager.GetLocale();

            // Set index to 0 so we can check for the string count
            id.m_Index = 0;

            if (!locale.Exists(id))
            {
                Log._Debug($"[{nameof(LocaleManagerExtensions)}.{nameof(RemoveRange)}] Could not remove locale range {id}; localized string {id} does not exist!");

                return;
            }

            var localizedStrings      = locale.GetLocalizedStrings();
            var localizedStringsCount = locale.GetLocalizedStringsCount();

            for (int index = 0, lastIndex = locale.CountUnchecked(id); index <= lastIndex; index++, id.m_Index = index)
            {
                localizedStrings.Remove(id);
                localizedStringsCount.Remove(id);
            }

            Log._Debug($"[{nameof(LocaleManagerExtensions)}.{nameof(RemoveRange)}] Removed locale range {id.m_Identifier}[{id.m_Key}].");
        }
Exemple #4
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) {}
        }
Exemple #5
0
        public static void ReplaceTrackIcon(NetInfo prefab, NetInfoVersion version)
        {
            if (version != NetInfoVersion.Ground)
            {
                return;
            }
            var metroTrack = PrefabCollection <NetInfo> .FindLoaded("Metro Track");

            prefab.m_Atlas                = metroTrack.m_Atlas;
            prefab.m_Thumbnail            = metroTrack.m_Thumbnail;
            prefab.m_InfoTooltipAtlas     = metroTrack.m_InfoTooltipAtlas;
            prefab.m_InfoTooltipThumbnail = metroTrack.m_InfoTooltipThumbnail;
            prefab.m_isCustomContent      = false;
            prefab.m_availableIn          = ItemClass.Availability.All;
            var locale = LocaleManager.instance.GetLocale();
            var key    = new Locale.Key {
                m_Identifier = "NET_TITLE", m_Key = prefab.name
            };

            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, locale.Get(new Locale.Key {
                    m_Identifier = "NET_TITLE", m_Key = "Metro Track"
                }));
            }
            key = new Locale.Key {
                m_Identifier = "NET_DESC", m_Key = prefab.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, locale.Get(new Locale.Key {
                    m_Identifier = "NET_DESC", m_Key = "Metro Track"
                }));
            }
        }
        public static void AddLocale(string idBase, string key, string title, string description)
        {
            var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
            var locale      = (Locale)localeField.GetValue(SingletonLite <LocaleManager> .instance);
            var localeKey   = new Locale.Key()
            {
                m_Identifier = $"{idBase}_TITLE", m_Key = key
            };

            if (!locale.Exists(localeKey))
            {
                locale.AddLocalizedString(localeKey, title);
            }
            localeKey = new Locale.Key()
            {
                m_Identifier = $"{idBase}_DESC", m_Key = key
            };
            if (!locale.Exists(localeKey))
            {
                locale.AddLocalizedString(localeKey, description);
            }
            localeKey = new Locale.Key()
            {
                m_Identifier = $"{idBase}", m_Key = key
            };
            if (!locale.Exists(localeKey))
            {
                locale.AddLocalizedString(localeKey, description);
            }
        }
Exemple #7
0
        public void AddMissingGuideString(string localeKey)
        {
            var locale = this.locale;

            if (locale == null)
            {
                Log.Warning("Can't update guides because locale object is null");
                return;
            }

            {
                var key1 = new Locale.Key()
                {
                    m_Identifier = "TUTORIAL_TITLE",
                    m_Key        = GUIDE_KEY_PREFIX + localeKey,
                };
                string value1 = TMPE_TITLE_PREFIX + "¶" + GUIDE_HEAD_KEY_PREFIX + localeKey;
                resetFun?.Invoke(locale, new object[] { key1 });
                locale.AddLocalizedString(key1, value1);
            }
            {
                var key2 = new Locale.Key()
                {
                    m_Identifier = "TUTORIAL_TEXT",
                    m_Key        = GUIDE_KEY_PREFIX + localeKey,
                };
                string value2 = "¶" + GUIDE_BODY_KEY_PREFIX + localeKey;
                resetFun?.Invoke(locale, new object[] { key2 });
                locale.AddLocalizedString(key2, value2);
            }
        }
        public void ReloadTutorialTranslations()
        {
            var locale = (Locale)typeof(LocaleManager)
                         .GetField(
                "m_Locale",
                BindingFlags.Instance | BindingFlags.NonPublic)
                         ?.GetValue(SingletonLite <LocaleManager> .instance);

            if (locale == null)
            {
                Log.Warning("Can't update tutorials because locale object is null");
                return;
            }

            string lang = GetCurrentLanguage();

            // Reset is private method used to delete the key before re-adding it
            MethodInfo resetFun = typeof(Locale)
                                  .GetMethod(
                "ResetOverriddenLocalizedStrings",
                BindingFlags.Instance | BindingFlags.NonPublic);

            foreach (KeyValuePair <string, string> entry in tutorialsLookup_.AllLanguages[lang])
            {
                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;
                }

                var key = new Locale.Key()
                {
                    m_Identifier = identifier,
                    m_Key        = tutorialKey
                };

                resetFun?.Invoke(locale, new object[] { key });
                locale.AddLocalizedString(key, entry.Value);
            }
        }
Exemple #9
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);
            var prefab = PrefabCollection <TreeInfo> .FindLoaded("CherryTree01");

            if (prefab == null)
            {
                UnityEngine.Debug.LogWarning("CherryTree01 wasn't found");
                return;
            }
            prefab.m_availableIn = ItemClass.Availability.All;
            var field = typeof(PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic);

            field.SetValue(prefab, "BeautificationProps");
            var thumb   = Util.LoadTextureFromAssembly($"{typeof (ZenGardenTreeUnlocker).Name}.thumb.png", false);
            var tooltip = Util.LoadTextureFromAssembly($"{typeof(ZenGardenTreeUnlocker).Name}.tooltip.png", false);
            var atlas   = Util.CreateAtlas(new[] { thumb, tooltip });

            prefab.m_Atlas                = atlas;
            prefab.m_Thumbnail            = thumb.name;
            prefab.m_InfoTooltipAtlas     = atlas;
            prefab.m_InfoTooltipThumbnail = tooltip.name;


            var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
            var locale      = (Locale)localeField.GetValue(SingletonLite <LocaleManager> .instance);
            var key         = new Locale.Key()
            {
                m_Identifier = "TREE_TITLE", m_Key = prefab.name
            };

            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, "Zen Garden Cherry Blossom");
            }
            key = new Locale.Key()
            {
                m_Identifier = "TREE_DESC", m_Key = prefab.name
            };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, "A Cherry Blossom tree that is bundled with Zen Garden");
            }

            switch (mode)
            {
            case LoadMode.NewGame:
            case LoadMode.LoadGame:
                GameObject.Find("BeautificationPropsPanel").GetComponent <BeautificationPanel>().RefreshPanel();
                break;

            case LoadMode.NewMap:
            case LoadMode.LoadMap:
                GameObject.Find("ForestPanel").GetComponent <ForestGroupPanel>().RefreshPanel();
                break;
            }
        }
        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 });
        }
Exemple #11
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);
            }
        }
Exemple #12
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);
            }
        }
Exemple #13
0
        public void ReloadTutorialTranslations()
        {
            var locale = this.locale;

            if (locale == null)
            {
                Log.Warning("Can't update tutorials because locale object is null");
                return;
            }

            string lang = GetCurrentLanguage();


            foreach (KeyValuePair <string, string> entry in tutorialsLookup_.AllLanguages[lang])
            {
                if (!entry.Key.StartsWith(TUTORIAL_KEY_PREFIX))
                {
                    continue;
                }

                string identifier;
                string tutorialKey;
                string value = entry.Value;
                if (entry.Key.StartsWith(TUTORIAL_HEAD_KEY_PREFIX))
                {
                    identifier  = "TUTORIAL_ADVISER_TITLE";
                    tutorialKey = TUTORIAL_KEY_PREFIX +
                                  entry.Key.Substring(TUTORIAL_HEAD_KEY_PREFIX.Length);
                    value = TMPE_TITLE_PREFIX + value;
                }
                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;
                }

                var key = new Locale.Key()
                {
                    m_Identifier = identifier,
                    m_Key        = tutorialKey
                };

                resetFun?.Invoke(locale, new object[] { key });
                locale.AddLocalizedString(key, value);
            }
        }
Exemple #14
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.");
        }
        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);
                }
            }
        }
        private void SelectSub(UIComponent component, UIMouseEventParameter param)
        {
            if (_idList == null)
            {
                return;
            }
            var buildingId = _idList[selectedIndex];
            var building   = BuildingManager.instance.m_buildings.m_buffer[buildingId];

            if (building.Info != null)
            {
                var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
                var locale      = (Locale)localeField.GetValue(SingletonLite <LocaleManager> .instance);
                var key         = new Locale.Key {
                    m_Identifier = "BUILDING_TITLE", m_Key = building.Info.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, building.Info.name);
                }
                key = new Locale.Key {
                    m_Identifier = "BUILDING_DESC", m_Key = building.Info.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, string.Empty);
                }
                key = new Locale.Key {
                    m_Identifier = "BUILDING_SHORT_DESC", m_Key = building.Info.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, string.Empty);
                }
            }
            var button = GameObject.Find("RelocateAction").GetComponent <UIButton>();

            if (selectedIndex == 0)
            {
                button.Show();
            }
            else
            {
                button.Hide();
            }
            DefaultTool.OpenWorldInfoPanel(new InstanceID {
                Building = buildingId
            }, new Vector2(0, 0));
        }
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);
            var prefab = PrefabCollection<TreeInfo>.FindLoaded("CherryTree01");
            if (prefab == null)
            {
                UnityEngine.Debug.LogWarning("CherryTree01 wasn't found");
                return;
            }
            prefab.m_availableIn = ItemClass.Availability.All;
            var field = typeof (PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic);
            field.SetValue(prefab, "BeautificationProps");
            var thumb = Util.LoadTextureFromAssembly($"{typeof (ZenGardenTreeUnlocker).Name}.thumb.png", false);
            var tooltip = Util.LoadTextureFromAssembly($"{typeof(ZenGardenTreeUnlocker).Name}.tooltip.png", false);
            var atlas = Util.CreateAtlas(new[] {thumb, tooltip});
            prefab.m_Atlas = atlas;
            prefab.m_Thumbnail = thumb.name;
            prefab.m_InfoTooltipAtlas = atlas;
            prefab.m_InfoTooltipThumbnail = tooltip.name;


            var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
            var locale = (Locale)localeField.GetValue(SingletonLite<LocaleManager>.instance);
            var key = new Locale.Key() { m_Identifier = "TREE_TITLE", m_Key = prefab.name };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, "Zen Garden Cherry Blossom");
            }
            key = new Locale.Key() { m_Identifier = "TREE_DESC", m_Key = prefab.name };
            if (!locale.Exists(key))
            {
                locale.AddLocalizedString(key, "A Cherry Blossom tree that is bundled with Zen Garden");
            }

            switch (mode)
            {
                case LoadMode.NewGame:
                case LoadMode.LoadGame:
                    GameObject.Find("BeautificationPropsPanel").GetComponent<BeautificationPanel>().RefreshPanel();
                    break;
                case LoadMode.NewMap:
                case LoadMode.LoadMap:
                    GameObject.Find("ForestPanel").GetComponent<ForestGroupPanel>().RefreshPanel();
                    break;
            }
        }
Exemple #18
0
 public static void AddLocale(string idBase, string key, string title, string description)
 {
     var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
     var locale = (Locale)localeField.GetValue(SingletonLite<LocaleManager>.instance);
     var localeKey = new Locale.Key() { m_Identifier = $"{idBase}_TITLE", m_Key = key };
     if (!locale.Exists(localeKey))
     {
         locale.AddLocalizedString(localeKey, title);
     }
     localeKey = new Locale.Key() { m_Identifier = $"{idBase}_DESC", m_Key = key };
     if (!locale.Exists(localeKey))
     {
         locale.AddLocalizedString(localeKey, description);
     }
     localeKey = new Locale.Key() { m_Identifier = $"{idBase}", m_Key = key };
     if (!locale.Exists(localeKey))
     {
         locale.AddLocalizedString(localeKey, description);
     }
 }
 private static void Modify(string id, string oldValue, string newValue)
 {
     try
     {
         Dictionary <Locale.Key, string> dictionary = Utils.GetPrivate <Dictionary <Locale.Key, string> >((object)Utils.GetPrivate <Locale>((object)SingletonLite <LocaleManager> .instance, "m_Locale"), "m_LocalizedStrings");
         Locale.Key key = new Locale.Key()
         {
             m_Identifier = id
         };
         string str;
         if (!dictionary.TryGetValue(key, out str))
         {
             return;
         }
         dictionary[key] = str.Replace(oldValue, newValue);
     }
     catch (Exception ex)
     {
         Utils.LogWarning((object)("Unexpected " + ex.GetType().Name + " updating localization: " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine));
     }
 }
        private static FieldInfo FixPrefabsMetadata()
        {
            var uiCategory = typeof(PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic);
            var locale     =
                (Locale)
                typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance)
                .GetValue(SingletonLite <LocaleManager> .instance);

            for (uint i = 0; i < PrefabCollection <PropInfo> .PrefabCount(); i++)
            {
                var prefab = PrefabCollection <PropInfo> .GetPrefab(i);

                if (prefab == null)
                {
                    continue;
                }
                if (prefab.editorCategory == "PropsRocks")
                {
                    uiCategory.SetValue(prefab, "LandscapingRocks");
                    prefab.m_availableIn = ItemClass.Availability.All;
                }
                var key = new Locale.Key {
                    m_Identifier = "PROPS_TITLE", m_Key = prefab.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, prefab.name);
                }
                key = new Locale.Key {
                    m_Identifier = "PROPS_DESC", m_Key = prefab.name
                };
                if (!locale.Exists(key))
                {
                    locale.AddLocalizedString(key, prefab.name);
                }
            }
            return(uiCategory);
        }
        /// <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...");
            }
        }
Exemple #22
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;
        }
Exemple #23
0
        public static void RemoveRange(this LocaleManager localeManager, Locale.Key id)
        {
            Locale locale = localeManager.GetLocale();

            // Set index to 0 so we can check for the string count
            id.m_Index = 0;

            if (!locale.Exists(id))
            {
                DebugUtils.Log($"Could not remove locale range {id}; localized string {id} does not exist!");
                return;
            }

            Dictionary <Locale.Key, string> localizedStrings      = locale.GetLocalizedStrings();
            Dictionary <Locale.Key, int>    localizedStringsCount = locale.GetLocalizedStringsCount();

            for (int index = 0, lastIndex = locale.CountUnchecked(id); index <= lastIndex; index++, id.m_Index = index)
            {
                localizedStrings.Remove(id);
                localizedStringsCount.Remove(id);
            }

            DebugUtils.Log($"Removed locale range {id.m_Identifier}[{id.m_Key}].");
        }
        private void loadLocaleIntern(string localeId, bool setLocale, string prefix, string packagePrefix)
        {
            KlyteUtils.doLog($"{GetType()} localeId: {localeId}");
            string load = Singleton <R> .instance.loadResourceString("UI.i18n." + localeId + ".properties");

            if (load == null)
            {
                KlyteUtils.doLog("File UI.i18n." + localeId + ".properties not found. Probably this translation doesn't exists for this mod.");
                load = "";
            }
            var locale = KlyteUtils.GetPrivateField <Locale>(LocaleManager.instance, "m_Locale");

            Locale.Key k;


            foreach (var myString in load.Split(lineSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                if (myString.StartsWith(commentChar))
                {
                    continue;
                }
                if (!myString.Contains(kvSeparator))
                {
                    continue;
                }
                bool   noPrefix  = myString.StartsWith(ignorePrefixChar);
                var    array     = myString.Split(kvSeparator.ToCharArray(), 2);
                string value     = array[1];
                int    idx       = 0;
                string localeKey = null;
                if (array[0].Contains(idxSeparator))
                {
                    var arrayIdx = array[0].Split(idxSeparator.ToCharArray());
                    if (!int.TryParse(arrayIdx[1], out idx))
                    {
                        continue;
                    }
                    array[0] = arrayIdx[0];
                }
                if (array[0].Contains(localeKeySeparator))
                {
                    array     = array[0].Split(localeKeySeparator.ToCharArray());
                    localeKey = array[1];
                }

                k = new Locale.Key()
                {
                    m_Identifier = noPrefix ? array[0].Substring(1) : prefix + array[0],
                    m_Key        = localeKey,
                    m_Index      = idx
                };
                if (!locale.Exists(k))
                {
                    locale.AddLocalizedString(k, value.Replace("\\n", "\n"));
                }
            }

            if (localeId != "en")
            {
                loadLocaleIntern("en", false, prefix, packagePrefix);
            }
            if (setLocale)
            {
                language = localeId;
            }
        }
        private static void loadLocaleIntern(string localeId, bool setLocale = false)
        {
            string load = ResourceLoader.loadResourceString("UI.i18n." + localeId + ".properties");

            if (load == null)
            {
                load = ResourceLoader.loadResourceString("UI.i18n.en.properties");
                if (load == null)
                {
                    TLMUtils.doErrorLog("LOCALE NOT LOADED!!!!");
                    return;
                }
                localeId = "en";
            }
            var locale = TLMUtils.GetPrivateField <Locale>(LocaleManager.instance, "m_Locale");

            Locale.Key k;


            foreach (var myString in load.Split(new string[] { lineSeparator }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (myString.StartsWith(commentChar))
                {
                    continue;
                }
                if (!myString.Contains(kvSeparator))
                {
                    continue;
                }
                var    array     = myString.Split(kvSeparator.ToCharArray(), 2);
                string value     = array[1];
                int    idx       = 0;
                string localeKey = null;
                if (array[0].Contains(idxSeparator))
                {
                    var arrayIdx = array[0].Split(idxSeparator.ToCharArray());
                    if (!int.TryParse(arrayIdx[1], out idx))
                    {
                        continue;
                    }
                    array[0] = arrayIdx[0];
                }
                if (array[0].Contains(localeKeySeparator))
                {
                    array     = array[0].Split(localeKeySeparator.ToCharArray());
                    localeKey = array[1];
                }

                k = new Locale.Key()
                {
                    m_Identifier = "TLM_" + array[0],
                    m_Key        = localeKey,
                    m_Index      = idx
                };
                if (!locale.Exists(k))
                {
                    locale.AddLocalizedString(k, value.Replace("\\n", "\n"));
                }
            }

            if (localeId != "en")
            {
                loadLocaleIntern("en");
            }
            if (setLocale)
            {
                language = localeId;
            }
        }
Exemple #26
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;
            }
        }
 private static PropInfo Clone(PropInfo prop, Flag modification, bool isWall)
 {
     var gameObject = GameObject.Find("MoreFlags") ?? new GameObject("MoreFlags");
     var clone = Util.ClonePrefab(prop, prop.name + $"_{modification.id}", gameObject.transform);
     PrefabCollection<PropInfo>.InitializePrefabs("MoreFlags", new[] { clone }, null);
     clone.m_material = Object.Instantiate(prop.m_material);
     clone.m_material.name = prop.m_material.name + $"_{modification.id}";
     clone.m_material.mainTexture = modification.texture;
     clone.m_lodMaterial = Object.Instantiate(prop.m_lodMaterial);
     clone.m_lodMaterial.name = prop.m_lodMaterial.name + $"_{modification.id}";
     clone.m_lodMaterial.mainTexture = modification.textureLod;
     clone.m_placementStyle = ItemClass.Placement.Manual;
     clone.m_createRuining = false;
     clone.m_Atlas = _atlas;
     clone.m_InfoTooltipAtlas = _atlas;
     var thumb = isWall ? modification.thumbWall : modification.thumb;
     if (thumb != null)
     {
         clone.m_Thumbnail = thumb.name;
         clone.m_InfoTooltipThumbnail = thumb.name;
     }
     var locale = (Locale)LocaleField.GetValue(SingletonLite<LocaleManager>.instance);
     var key = new Locale.Key { m_Identifier = "PROPS_TITLE", m_Key = clone.name };
     var versionStr = isWall ? "wall" : "ground";
     var extendedDescription =
         modification.extendedDescripton == string.Empty ? modification.description : modification.extendedDescripton;
     if (!locale.Exists(key))
     {
         locale.AddLocalizedString(key, $"{modification.description} ({versionStr} version)");
     }
     key = new Locale.Key { m_Identifier = "PROPS_DESC", m_Key = clone.name };
     if (!locale.Exists(key))
     {
         locale.AddLocalizedString(key, $"{extendedDescription} ({versionStr} version)");
     }
     return clone;
 }
Exemple #28
0
 public static void SetLocaleEntry(Locale.Key key, string value) => m_localeStringsDictionary(m_localeManagerLocale(LocaleManager.instance))[key] = value;
        public static void ReplaceTrackIcon(NetInfo prefab, NetInfoVersion version)
        {
            if (version != NetInfoVersion.Ground)
            {
                return;
            }

            prefab.m_InfoTooltipAtlas = InfoToolTipAtlas();
            string netTitle;
            string netDescription;

            if (prefab.name.Contains("Large"))
            {
                var atlas = UI.UIHelper.GenerateLinearAtlas("MOM_QuadMetroTrackAtlas", UI.UIHelper.QuadMetroTracks);
                prefab.m_Atlas                = atlas;
                prefab.m_Thumbnail            = atlas.name + "Bg";
                prefab.m_InfoTooltipThumbnail = QUAD_TRACK_INFOTOOLTIP;
                prefab.m_UIPriority           = 3;
                netTitle       = "Quad Metro Track";
                netDescription = "A four-lane metro track suitable for heavy traffic. Designate separate local and express lines for best results.";
            }
            else if (prefab.name.Contains("Small"))
            {
                var atlas = UI.UIHelper.GenerateLinearAtlas("MOM_SingleMetroTrackAtlas", UI.UIHelper.SingleMetroTracks);
                prefab.m_Atlas                = atlas;
                prefab.m_Thumbnail            = atlas.name + "Bg";
                prefab.m_InfoTooltipThumbnail = SINGLE_TRACK_INFOTOOLTIP;
                prefab.m_UIPriority           = 1;
                netTitle       = "Single Metro Track";
                netDescription = "A one-lane metro track. This track is suitable for light traffic or as a connector to other tracks.";
            }
            else
            {
                var atlas = UI.UIHelper.GenerateLinearAtlas("MOM_DualMetroTrackAtlas", UI.UIHelper.DualMetroTracks);
                prefab.m_Atlas                = atlas;
                prefab.m_Thumbnail            = atlas.name + "Bg";
                prefab.m_InfoTooltipThumbnail = DUAL_TRACK_INFOTOOLTIP;
                prefab.m_UIPriority           = 2;
                netTitle       = "Dual Metro Track";
                netDescription = "A two-lane metro track. This track supports moderate traffic and is adequate for most situations.";
            }
            prefab.m_isCustomContent = false;
            prefab.m_availableIn     = ItemClass.Availability.All;
            var locale = LocaleManager.instance.GetLocale();
            var key    = new Locale.Key {
                m_Identifier = "NET_TITLE", m_Key = prefab.name
            };

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

            if (!Locale.Exists("NET_DESC", prefab.name))
            {
                locale.AddLocalizedString(dkey, netDescription);
            }
        }
Exemple #30
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);
            }
        }
 private void SelectSub(UIComponent component, UIMouseEventParameter param)
 {
     if (_idList == null)
     {
         return;
     }
     var buildingId = _idList[selectedIndex];
     var building = BuildingManager.instance.m_buildings.m_buffer[buildingId];
     if (building.Info != null)
     {
         var localeField = typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance);
         var locale = (Locale)localeField.GetValue(SingletonLite<LocaleManager>.instance);
         var key = new Locale.Key { m_Identifier = "BUILDING_TITLE", m_Key = building.Info.name };
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, building.Info.name);
         }
         key = new Locale.Key { m_Identifier = "BUILDING_DESC", m_Key = building.Info.name };
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, string.Empty);
         }
         key = new Locale.Key { m_Identifier = "BUILDING_SHORT_DESC", m_Key = building.Info.name };
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, string.Empty);
         }
     }
     DefaultTool.OpenWorldInfoPanel(new InstanceID { Building = buildingId }, new Vector2(0, 0));
 }
Exemple #32
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;
            }
        }
 private void Import()
 {
     if (File.Exists(localeo_path.Text) && File.Exists(ipo_path.Text) && Directory.Exists(Path.GetDirectoryName(olocale_path.Text)))
     {
         if (import_msg.InvokeRequired)
         {
             SetTextCallback d = new SetTextCallback(SetText);
             this.Invoke(d, new object[] { "" });
         }
         using (Stream stream = new FileStream(localeo_path.Text, FileMode.Open, FileAccess.Read))
         {
             Locale m_Locale = DataSerializer.Deserialize <Locale>(stream, DataSerializer.Mode.File);
             Dictionary <Locale.Key, string> m_LocalizedStrings = Utils.GetPrivateField <Dictionary <Locale.Key, string> >(m_Locale, "m_LocalizedStrings");
             Dictionary <Locale.Key, string> l_LocalizedStrings = new Dictionary <Locale.Key, string>(m_LocalizedStrings);
             List <string> lines = new List <string>();
             using (StreamReader file = new StreamReader(ipo_path.Text))
             {
                 string line;
                 while ((line = file.ReadLine()) != null)
                 {
                     lines.Add(line);
                 }
             }
             if (progress.InvokeRequired)
             {
                 SetMaximum d = new SetMaximum(SetMaximum);
                 this.Invoke(d, new object[] { lines.Count });
             }
             if (progress.InvokeRequired)
             {
                 SetVisible d = new SetVisible(SetVisible);
                 this.Invoke(d, new object[] { true });
             }
             Regex regex        = new Regex(@"#. ""(.+)\[(.+)\]:(\d+)""|#. ""(.+):(\d+)""");
             Regex regex_msgid  = new Regex(@"msgid ""(.+)""");
             Regex regex_msgstr = new Regex(@"msgstr ""(.+)""");
             for (int i = 0; i < lines.Count; i++)
             {
                 if (progress.InvokeRequired)
                 {
                     SetValue d = new SetValue(SetValue);
                     this.Invoke(d, new object[] { i + 1 });
                 }
                 if (i + 2 < lines.Count && regex.IsMatch(lines[i]))
                 {
                     string m_Identifier = regex.Match(lines[i]).Groups[1].Value.Length != 0 ? regex.Match(lines[i]).Groups[1].Value : regex.Match(lines[i]).Groups[4].Value;
                     string m_Index      = regex.Match(lines[i]).Groups[3].Value.Length != 0 ? regex.Match(lines[i]).Groups[3].Value : regex.Match(lines[i]).Groups[5].Value;
                     string m_Key        = regex.Match(lines[i]).Groups[2].Value.Length != 0 ? regex.Match(lines[i]).Groups[2].Value : null;
                     string msgid        = regex_msgid.Match(lines[i + 1]).Groups[1].Value;
                     string msgstr       = regex_msgstr.Match(lines[i + 2]).Groups[1].Value;
                     if (msgid.Length != 0)
                     {
                         Locale.Key key = new Locale.Key();
                         key.m_Identifier = m_Identifier;
                         key.m_Index      = int.Parse(m_Index);
                         key.m_Key        = m_Key;
                         if (l_LocalizedStrings.ContainsKey(key))
                         {
                             l_LocalizedStrings.Remove(key);
                             l_LocalizedStrings.Add(key, msgid.Replace(@"\r", "\r").Replace(@"\n", "\n"));
                         }
                         else
                         {
                             l_LocalizedStrings.Add(key, msgid.Replace(@"\r", "\r").Replace(@"\n", "\n"));
                         }
                     }
                 }
             }
             string m_EnglishName = language_e.Text;
             string m_NativeName  = language.Text;
             if (m_EnglishName.Length != 0)
             {
                 Utils.SetPrivateField <string>(m_Locale, "m_EnglishName", m_EnglishName);
             }
             if (m_NativeName.Length != 0)
             {
                 Utils.SetPrivateField <string>(m_Locale, "m_NativeName", m_NativeName);
             }
             Utils.SetPrivateField <Dictionary <Locale.Key, string> >(m_Locale, "m_LocalizedStrings", l_LocalizedStrings);
             Utils.ExportFile(olocale_path.Text, m_Locale);
             if (import_msg.InvokeRequired)
             {
                 SetTextCallback d = new SetTextCallback(SetText);
                 this.Invoke(d, new object[] { "import success !" });
             }
             if (progress.InvokeRequired)
             {
                 SetVisible d = new SetVisible(SetVisible);
                 this.Invoke(d, new object[] { false });
             }
         }
     }
     else
     {
         if (import_msg.InvokeRequired)
         {
             SetTextCallback d = new SetTextCallback(SetText);
             this.Invoke(d, new object[] { "file or directory not exist !" });
         }
     }
 }
 public override void OnLevelLoaded(LoadMode mode)
 {
     base.OnLevelLoaded(mode);
     if (!IsHooked())
     {
         UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Missing dependency", "'More Network Stuff' mod requires the 'Prefab Hook' mod to work properly. Please subscribe to the mod and restart the game!", false);
         return;
     }
     if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame)
     {
         BulldozeToolDetour.Deploy();
     }
     else if (mode == LoadMode.LoadAsset || mode == LoadMode.NewAsset)
     {
         var pedestrianConnection = PrefabCollection<NetInfo>.FindLoaded("Pedestrian Connection");
         pedestrianConnection.m_class.m_layer = ItemClass.Layer.Default | ItemClass.Layer.MetroTunnels;
     }
     var locale = (Locale) typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite<LocaleManager>.instance);
     var field = typeof(PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic);
     for (uint i = 0; i < PrefabCollection<NetInfo>.PrefabCount(); i++)
     {
         var info = PrefabCollection<NetInfo>.GetPrefab(i);
         if (info == null)
         {
             continue;
         }
         var key = new Locale.Key {m_Identifier = "NET_TITLE", m_Key = info.name};
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, info.name);
         }
         key = new Locale.Key {m_Identifier = "NET_DESC", m_Key = info.name};
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, info.name);
         }
         var thumb = Util.LoadTextureFromAssembly($"{typeof(MoreNetworkStuff).Name}.resource.thumb.png", false);
         var tooltip = Util.LoadTextureFromAssembly($"{typeof(MoreNetworkStuff).Name}.resource.tooltip.png", false);
         var atlas = Util.CreateAtlas(new[] {thumb, tooltip});
         if (ConnectionNetworks.Contains(info.name))
         {
             info.m_Atlas = atlas;
             info.m_Thumbnail = thumb.name;
             info.m_InfoTooltipAtlas = atlas;
             info.m_InfoTooltipThumbnail = tooltip.name;
             info.m_maxHeight = 5;
             info.m_minHeight = -5;
         }
         else if (mode == LoadMode.LoadAsset || mode == LoadMode.NewAsset)
         {
             var category = (string) field.GetValue(info);
             if (category == "LandscapingWaterStructures")
             {
                 field.SetValue(info, "BeautificationPaths");
             }
         }
     }
     switch (mode)
     {
         case LoadMode.NewGame:
         case LoadMode.LoadGame:
             RefreshPanelInGame();
             break;
     }
 }
 private static FieldInfo FixPrefabsMetadata()
 {
     var uiCategory = typeof(PrefabInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic);
     var locale =
         (Locale)
             typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance)
                 .GetValue(SingletonLite<LocaleManager>.instance);
     for (uint i = 0; i < PrefabCollection<PropInfo>.PrefabCount(); i++)
     {
         var prefab = PrefabCollection<PropInfo>.GetPrefab(i);
         if (prefab == null)
         {
             continue;
         }
         if (prefab.editorCategory == "PropsRocks")
         {
             uiCategory.SetValue(prefab, "LandscapingRocks");
             prefab.m_availableIn = ItemClass.Availability.All;
         }
         var key = new Locale.Key { m_Identifier = "PROPS_TITLE", m_Key = prefab.name };
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, prefab.name);
         }
         key = new Locale.Key { m_Identifier = "PROPS_DESC", m_Key = prefab.name };
         if (!locale.Exists(key))
         {
             locale.AddLocalizedString(key, prefab.name);
         }
     }
     return uiCategory;
 }
        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.");
        }
Exemple #37
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);
            }
        }