Ejemplo n.º 1
0
 public void ReloadData()
 {
     foreach (var tab in tabContainer.GetComponentsInChildren <ITLMConfigOptionsTab>())
     {
         try
         {
             tab.ReloadData();
         }
         catch (Exception e)
         {
             LogUtils.DoErrorLog($"Error reloading data for {tab}: {e.Message}\n{e.StackTrace}");
         }
     }
 }
Ejemplo n.º 2
0
        private static void ToolbarEvents_ToolbarOpened()
        {
            // For compatibility with Enhanced Build Panel, we have to check if the UIScrollablePanel has not been patched.
            UITabContainer    tsContainer = GameObject.Find(GameObjectDefs.ID_TSCONTAINER).GetComponent <UITabContainer>();
            UIScrollablePanel panel       = tsContainer.GetComponentsInChildren <UIScrollablePanel>().FirstOrDefault(p => p.isVisible);

            if (panel.name != "ScrollablePanel")
            {
                toggleToolbarWidthButton.isVisible = false;
                Mod.Instance.Log.Debug("Toolbar opened; ToggleToolbarWidthButton not visible due to panel not having its original name; expected: ScrollablePanel, actual: {0}", panel.name);
                return;
            }
            else
            {
                // We will keep a small compatibility problem however. This method gets called before Enhanced Build Panel changes
                // the name of the panel for the first opening of each panel. So we check it once after a small delay to see if the name
                // has been changed.
                Timer timer = new Timer(100);
                timer.Elapsed += (sender, e) =>
                {
                    timer.Stop();
                    if (panel.name != "ScrollablePanel")
                    {
                        toggleToolbarWidthButton.isVisible = false;
                        Mod.Instance.Log.Debug("ToggleToolbarWidthButton not visible after delay due to panel not having its original name; expected: ScrollablePanel, actual: {0}", panel.name);
                    }
                    timer.Dispose();
                };
                timer.Start();
                Mod.Instance.Log.Debug("Toolbar opened; timer started to check if EnhancedBuildPanel changes the name of the scrollable panel after us");
            }


            // We need to check if the size and position of TSContainer is still the same as we left it.
            // If not, then another mod has probably overwritten some stuff and we cannot enable the button.
            // Sorry Sapphire users, but I assume your skin already patches the width of the toolbar ;)
            if (tsContainer.absolutePosition.x >= lastTSContainerX - measureRange && tsContainer.absolutePosition.x <= lastTSContainerX + measureRange &&
                tsContainer.width >= lastTSContainerWidth - measureRange && tsContainer.width <= lastTSContainerWidth + measureRange)
            {
                toolbarControlBox.isVisible        = true;
                toggleToolbarWidthButton.isVisible = true;
                Mod.Instance.Log.Debug("Toolbar opened; ToolbarControlBox and ToggleToolbarWidthButton visibility = true");
            }
        }
Ejemplo n.º 3
0
        private void RefreshBuildingsButtons()
        {
            if (buildingsTabContainer == null)
            {
                return;
            }

            // This creates objects on heap, but it won't cause memory pressure because it's not called
            // in the simulation loop
            var items = buildingsTabContainer.GetComponentsInChildren <UIButton>()?
                        .Select(b => new { Info = b.objectUserData as PrefabInfo, Button = b })
                        .Where(i => i.Info is BuildingInfo || i.Info is NetInfo);

            if (items == null)
            {
                return;
            }

            foreach (var item in items)
            {
                item.Button.tooltip = item.Info.GetLocalizedTooltip();
            }
        }