Exemple #1
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"));
            }
        }
        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 #3
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]}.");
        }
        private string GetAddressLegendText()
        {
            var result = new List <string>();

            for (int i = 0; Locale.Exists("K45_ADR_ADDRESS_FORMAT_LEGEND", i); i++)
            {
                result.Add(Locale.Get("K45_ADR_ADDRESS_FORMAT_LEGEND", i));
            }
            return(string.Join("\n", result.ToArray()));
        }
Exemple #5
0
 private static string SafeGetAssetString(string localeID, string assetName, Package package)
 {
     if (package != null)
     {
         string key = package.packageName + "." + assetName + "_Data";
         if (Locale.Exists(localeID, key))
         {
             return(Locale.Get(localeID, key));
         }
     }
     return(assetName);
 }
Exemple #6
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 #7
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);
            }
        }
        /// <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);
                }
            }
        }
Exemple #10
0
 public static string GetPrefabName(PropInfo prop)
 {
     if (prop == null)
     {
         return(string.Empty);
     }
     else if (Locale.Exists("PROPS_TITLE", prop.name))
     {
         return(Locale.Get("PROPS_TITLE", prop.name));
     }
     else
     {
         return(prop.name);
     }
 }
        private string GetPostalCodeLegendText()
        {
            var result = new List <string>();

            for (int i = 0; Locale.Exists("K45_ADR_POSTAL_CODE_FORMAT_LEGEND_V3", i); i++)
            {
                result.Add(Locale.Get("K45_ADR_POSTAL_CODE_FORMAT_LEGEND_V3", i));
            }
            result.Add("");
            for (int i = 0; Locale.Exists("K45_ADR_POSTAL_CODE_FORMAT_OBSERVATION_V3", i); i++)
            {
                result.Add($"<color yellow>{Locale.Get("K45_ADR_POSTAL_CODE_FORMAT_OBSERVATION_V3", i)}</color>");
            }
            return(string.Join("\n", result.ToArray()));
        }
Exemple #12
0
 public static string GetPrefabName(TreeInfo tree)
 {
     if (tree == null)
     {
         return(string.Empty);
     }
     else if (Locale.Exists("TREE_TITLE", tree.name))
     {
         return(Locale.Get("TREE_TITLE", tree.name));
     }
     else
     {
         return(tree.name);
     }
 }
Exemple #13
0
 public static string GetPrefabName(NetInfo network)
 {
     if (network == null)
     {
         return(string.Empty);
     }
     else if (Locale.Exists("NET_TITLE", network.name))
     {
         return(Locale.Get("NET_TITLE", network.name));
     }
     else
     {
         return(network.name);
     }
 }
Exemple #14
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 OnBindingKeyDown(UIComponent comp, UIKeyEventParameter e)
        {
            var key = e.keycode;

            if (_editingBinding == null || KeyHelper.IsModifierKey(key))
            {
                return;
            }

            e.Use();
            UIView.PopModal();

            InputKey newKey;

            switch (key)
            {
            case KeyCode.Backspace:
                newKey = SavedInputKey.Empty;
                break;

            case KeyCode.Escape:
                newKey = _editingBinding.value;
                break;

            default:
                newKey = SavedInputKey.Encode(key, e.control, e.shift, e.alt);
                break;
            }

            if (IsAlreadyBound(_editingBinding, newKey, out var currentAssigned))
            {
                var text = currentAssigned.Count <= 1
          ? (
                    Locale.Exists("KEYMAPPING", currentAssigned[0].name)
              ? Locale.Get("KEYMAPPING", currentAssigned[0].name)
              : Options.GetShortcutName(currentAssigned[0].name)
                    )
          : Locale.Get("KEYMAPPING_MULTIPLE");
                var message = StringUtils.SafeFormat(Locale.Get("CONFIRM_REBINDKEY", "Message"),
                                                     SavedInputKey.ToLocalizedString("KEYNAME", newKey), text);

                ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, (c, ret) =>
                {
                    var btn = (UIButton)comp;
                    if (ret == 1)
                    {
                        _editingBinding.value = newKey;
                        foreach (var asigned in currentAssigned)
                        {
                            asigned.value = SavedInputKey.Empty;
                        }
                        UpdateKeyBinding(newKey, btn, false);
                        RefreshKeyMapping();
                    }
                    _editingBinding = null;
                    btn.text        = ((SavedInputKey)btn.objectUserData).ToLocalizedString("KEYNAME");
                });
            }
            else
            {
                UpdateKeyBinding(newKey, (UIButton)comp, false);
            }
        }
Exemple #16
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;
            }
        }
Exemple #17
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;
            }
        }
Exemple #18
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);
            }
        }
        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);
            }
        }
        public override void SimulationStep(ushort disasterID, ref DisasterData data)
        {
            //Begin Disaster AI SimulationStep
            if ((data.m_flags & DisasterData.Flags.Clearing) != DisasterData.Flags.None)
            {
                if (!this.IsStillClearing(disasterID, ref data))
                {
                    this.EndDisaster(disasterID, ref data);
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Active) != DisasterData.Flags.None)
            {
                if (!this.IsStillActive(disasterID, ref data))
                {
                    this.DeactivateDisaster(disasterID, ref data);
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Emerging) != DisasterData.Flags.None)
            {
                if (!this.IsStillEmerging(disasterID, ref data))
                {
                    this.ActivateDisaster(disasterID, ref data);
                }
            }
            if ((data.m_flags & DisasterData.Flags.Detected) != DisasterData.Flags.None)
            {
                if ((data.m_flags & DisasterData.Flags.Warning) != DisasterData.Flags.None)
                {
                    if (data.m_broadcastCooldown > 0)
                    {
                        data.m_broadcastCooldown -= 1;
                    }
                    if (data.m_broadcastCooldown == 0)
                    {
                        data.m_broadcastCooldown = 36;
                        if (this.m_info.m_warningBroadcast != null)
                        {
                            Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_warningBroadcast);
                        }
                    }
                }
                else
                {
                    StatisticBase statisticBase = Singleton <StatisticsManager> .instance.Acquire <StatisticInt32>(StatisticType.DisasterCount);

                    statisticBase.Add(16);
                    InstanceID id = default(InstanceID);
                    id.Disaster = disasterID;
                    InstanceManager.Group group = Singleton <InstanceManager> .instance.GetGroup(id);

                    if (data.m_broadcastCooldown >= 200)
                    {
                        if (data.m_broadcastCooldown > 200)
                        {
                            data.m_broadcastCooldown -= 1;
                        }
                        if (data.m_broadcastCooldown == 200 && (group == null || group.m_refCount >= 2))
                        {
                            data.m_broadcastCooldown = 236;
                            if (this.m_info.m_activeBroadcast != null)
                            {
                                Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_activeBroadcast);
                            }
                        }
                    }
                    else
                    {
                        if (data.m_broadcastCooldown > 0)
                        {
                            data.m_broadcastCooldown -= 1;
                        }
                        if (data.m_broadcastCooldown == 0)
                        {
                            data.m_broadcastCooldown = 236;
                            if (this.m_info.m_activeBroadcast != null)
                            {
                                Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_activeBroadcast);
                            }
                        }
                    }
                    if (group == null || group.m_refCount >= 2)
                    {
                        if (data.m_chirpCooldown > 0)
                        {
                            data.m_chirpCooldown -= 1;
                        }
                        else if (this.m_info.m_prefabDataIndex != -1)
                        {
                            string key = PrefabCollection <DisasterInfo> .PrefabName((uint)this.m_info.m_prefabDataIndex);

                            if (Locale.Exists("CHIRP_DISASTER", key))
                            {
                                string disasterName = Singleton <DisasterManager> .instance.GetDisasterName(disasterID);

                                Singleton <MessageManager> .instance.TryCreateMessage("CHIRP_DISASTER", key, Singleton <MessageManager> .instance.GetRandomResidentID(), disasterName);

                                data.m_chirpCooldown = (byte)Singleton <SimulationManager> .instance.m_randomizer.Int32(8, 24);
                            }
                        }
                    }
                }
                GuideController properties = Singleton <GuideManager> .instance.m_properties;
                if (this.m_info.m_disasterWarningGuide != null && properties != null)
                {
                    this.m_info.m_disasterWarningGuide.Activate(properties.m_disasterWarning, this.m_info);
                }
            }
            if ((data.m_flags & DisasterData.Flags.Repeat) != DisasterData.Flags.None && ((data.m_flags & (DisasterData.Flags.Finished | DisasterData.Flags.UnReported)) == DisasterData.Flags.Finished || (data.m_flags & (DisasterData.Flags.Clearing | DisasterData.Flags.UnDetected)) == (DisasterData.Flags.Clearing | DisasterData.Flags.UnDetected)))
            {
                this.StartDisaster(disasterID, ref data);
            }
            //End DisasterAI.Simulation Step
            if ((data.m_flags & DisasterData.Flags.Emerging) != DisasterData.Flags.None)
            {
                if (data.m_activationFrame != 0u)
                {
                    uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                    if (currentFrameIndex + 1755u >= data.m_activationFrame)
                    {
                        if ((data.m_flags & DisasterData.Flags.Significant) != DisasterData.Flags.None)
                        {
                            Singleton <DisasterManager> .instance.DetectDisaster(disasterID, false);
                        }
                        if ((data.m_flags & DisasterData.Flags.SelfTrigger) != DisasterData.Flags.None)
                        {
                            Singleton <WeatherManager> .instance.m_forceWeatherOn = 2f;
                            Singleton <WeatherManager> .instance.m_targetFog      = 0f;
                            //Begin Edit
                            float newThunderstormTargetRain = Mathf.Clamp(((float)data.m_intensity) / 100, 0.25f, 1.0f);
                            Singleton <WeatherManager> .instance.m_targetRain = newThunderstormTargetRain;
                            Debug.Log("[RF]ThunderStormAIDetour Limtied Thunderstorm Rain to " + Singleton <WeatherManager> .instance.m_targetRain);
                            Singleton <WeatherManager> .instance.m_targetCloud = newThunderstormTargetRain;
                            //end edit
                        }
                    }
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Active) != DisasterData.Flags.None && (data.m_flags & DisasterData.Flags.SelfTrigger) != DisasterData.Flags.None)
            {
                Singleton <WeatherManager> .instance.m_forceWeatherOn = 2f;
                Singleton <WeatherManager> .instance.m_targetFog      = 0f;
                //Begin Edit
                float newThunderstormTargetRain = Mathf.Clamp(((float)data.m_intensity) / 100, 0.25f, 1.0f);
                Singleton <WeatherManager> .instance.m_targetRain = newThunderstormTargetRain;
                Debug.Log("[RF]ThunderStormAIDetour Limtied Thunderstorm Rain to " + Singleton <WeatherManager> .instance.m_targetRain);
                Singleton <WeatherManager> .instance.m_targetCloud = newThunderstormTargetRain;
                //end edit
                uint currentFrameIndex2 = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                int  num = 100;
                num = Mathf.Min(num, (int)(currentFrameIndex2 - data.m_activationFrame >> 3));
                num = Mathf.Min(num, (int)(data.m_activationFrame + this.m_activeDuration - currentFrameIndex2 >> 3));
                num = (num * (int)data.m_intensity + 50) / 100;
                Randomizer randomizer = new Randomizer(data.m_randomSeed ^ (ulong)(currentFrameIndex2 >> 8));
                int        num2       = randomizer.Int32(Mathf.Max(1, num / 20), Mathf.Max(1, 1 + num / 10));
                float      num3       = this.m_radius * (0.25f + (float)data.m_intensity * 0.0075f);
                InstanceID id         = default(InstanceID);
                id.Disaster = disasterID;
                InstanceManager.Group group = Singleton <InstanceManager> .instance.GetGroup(id);

                for (int i = 0; i < num2; i++)
                {
                    float   f              = (float)randomizer.Int32(10000u) * 0.0006283185f;
                    float   num4           = Mathf.Sqrt((float)randomizer.Int32(10000u) * 0.0001f) * num3;
                    uint    startFrame     = currentFrameIndex2 + randomizer.UInt32(256u);
                    Vector3 targetPosition = data.m_targetPosition;
                    targetPosition.x += Mathf.Cos(f) * num4;
                    targetPosition.z += Mathf.Sin(f) * num4;
                    targetPosition.y  = Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(targetPosition, false, 0f);

                    Quaternion quaternion = Quaternion.AngleAxis((float)randomizer.Int32(360u), Vector3.up);
                    quaternion *= Quaternion.AngleAxis((float)randomizer.Int32(-15, 15), Vector3.right);
                    Singleton <WeatherManager> .instance.QueueLightningStrike(startFrame, targetPosition, quaternion, group);
                }
            }
        }
Exemple #21
0
        public override void SimulationStep(ushort disasterID, ref DisasterData data)
        {
            //Begin Disaster AI SimulationStep
            if ((data.m_flags & DisasterData.Flags.Clearing) != DisasterData.Flags.None)
            {
                if (!this.IsStillClearing(disasterID, ref data))
                {
                    this.EndDisaster(disasterID, ref data);
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Active) != DisasterData.Flags.None)
            {
                if (!this.IsStillActive(disasterID, ref data))
                {
                    this.DeactivateDisaster(disasterID, ref data);
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Emerging) != DisasterData.Flags.None)
            {
                if (!this.IsStillEmerging(disasterID, ref data))
                {
                    this.ActivateDisaster(disasterID, ref data);
                }
            }
            if ((data.m_flags & DisasterData.Flags.Detected) != DisasterData.Flags.None)
            {
                if ((data.m_flags & DisasterData.Flags.Warning) != DisasterData.Flags.None)
                {
                    if (data.m_broadcastCooldown > 0)
                    {
                        data.m_broadcastCooldown -= 1;
                    }
                    if (data.m_broadcastCooldown == 0)
                    {
                        data.m_broadcastCooldown = 36;
                        if (this.m_info.m_warningBroadcast != null)
                        {
                            Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_warningBroadcast);
                        }
                    }
                }
                else
                {
                    StatisticBase statisticBase = Singleton <StatisticsManager> .instance.Acquire <StatisticInt32>(StatisticType.DisasterCount);

                    statisticBase.Add(16);
                    InstanceID id = default(InstanceID);
                    id.Disaster = disasterID;
                    InstanceManager.Group group = Singleton <InstanceManager> .instance.GetGroup(id);

                    if (data.m_broadcastCooldown >= 200)
                    {
                        if (data.m_broadcastCooldown > 200)
                        {
                            data.m_broadcastCooldown -= 1;
                        }
                        if (data.m_broadcastCooldown == 200 && (group == null || group.m_refCount >= 2))
                        {
                            data.m_broadcastCooldown = 236;
                            if (this.m_info.m_activeBroadcast != null)
                            {
                                Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_activeBroadcast);
                            }
                        }
                    }
                    else
                    {
                        if (data.m_broadcastCooldown > 0)
                        {
                            data.m_broadcastCooldown -= 1;
                        }
                        if (data.m_broadcastCooldown == 0)
                        {
                            data.m_broadcastCooldown = 236;
                            if (this.m_info.m_activeBroadcast != null)
                            {
                                Singleton <AudioManager> .instance.QueueBroadcast(this.m_info.m_activeBroadcast);
                            }
                        }
                    }
                    if (group == null || group.m_refCount >= 2)
                    {
                        if (data.m_chirpCooldown > 0)
                        {
                            data.m_chirpCooldown -= 1;
                        }
                        else if (this.m_info.m_prefabDataIndex != -1)
                        {
                            string key = PrefabCollection <DisasterInfo> .PrefabName((uint)this.m_info.m_prefabDataIndex);

                            if (Locale.Exists("CHIRP_DISASTER", key))
                            {
                                string disasterName = Singleton <DisasterManager> .instance.GetDisasterName(disasterID);

                                Singleton <MessageManager> .instance.TryCreateMessage("CHIRP_DISASTER", key, Singleton <MessageManager> .instance.GetRandomResidentID(), disasterName);

                                data.m_chirpCooldown = (byte)Singleton <SimulationManager> .instance.m_randomizer.Int32(8, 24);
                            }
                        }
                    }
                }
                GuideController properties = Singleton <GuideManager> .instance.m_properties;
                if (this.m_info.m_disasterWarningGuide != null && properties != null)
                {
                    this.m_info.m_disasterWarningGuide.Activate(properties.m_disasterWarning, this.m_info);
                }
            }
            if ((data.m_flags & DisasterData.Flags.Repeat) != DisasterData.Flags.None && ((data.m_flags & (DisasterData.Flags.Finished | DisasterData.Flags.UnReported)) == DisasterData.Flags.Finished || (data.m_flags & (DisasterData.Flags.Clearing | DisasterData.Flags.UnDetected)) == (DisasterData.Flags.Clearing | DisasterData.Flags.UnDetected)))
            {
                this.StartDisaster(disasterID, ref data);
            }
            //End DisasterAI.Simulation Step
            if ((data.m_flags & DisasterData.Flags.Emerging) != DisasterData.Flags.None)
            {
                uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                if (currentFrameIndex + 1755u > data.m_activationFrame)
                {
                    Singleton <DisasterManager> .instance.DetectDisaster(disasterID, false);

                    Singleton <WeatherManager> .instance.m_forceWeatherOn = 2f;
                    Singleton <WeatherManager> .instance.m_targetFog      = 0f;
                    //Begin Edit
                    float newTornadoTargetRain = Mathf.Clamp(((float)data.m_intensity) / 100, 0.25f, 1.0f);
                    Singleton <WeatherManager> .instance.m_targetRain = newTornadoTargetRain;
                    Debug.Log("[RF]TornadoAIDetour Limtied Tornado Rain to " + Singleton <WeatherManager> .instance.m_targetRain);
                    //End Edit
                    Singleton <WeatherManager> .instance.m_targetCloud = 1f;
                }
            }
            else if ((data.m_flags & DisasterData.Flags.Active) != DisasterData.Flags.None)
            {
                Singleton <WeatherManager> .instance.m_forceWeatherOn = 2f;
                Singleton <WeatherManager> .instance.m_targetFog      = 0f;
                //Begin Edit
                float newTornadoTargetRain = Mathf.Clamp(((float)data.m_intensity) / 100, 0.25f, 1.0f);
                Singleton <WeatherManager> .instance.m_targetRain = newTornadoTargetRain;
                Debug.Log("[RF]TornadoAIDetour Limtied Tornado Rain to " + Singleton <WeatherManager> .instance.m_targetRain);
                //End Edit
                Singleton <WeatherManager> .instance.m_targetCloud = 1f;
            }
        }
Exemple #22
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);
            }
        }