Пример #1
0
        bool Initialize()
        {
            ModDebug.Log("Initializing UI");

            if (UIUtils.Instance == null)
            {
                return(false);
            }

            roadsOptionPanel = UIUtils.Instance.FindComponent <UIComponent>("RoadsOptionPanel(RoadsPanel)", null, UIUtils.FindOptions.NameContains);
            if (roadsOptionPanel == null || !roadsOptionPanel.gameObject.activeInHierarchy)
            {
                return(false);
            }

            builtinTabstrip = UIUtils.Instance.FindComponent <UITabstrip>("ToolMode", roadsOptionPanel);
            if (builtinTabstrip == null || !builtinTabstrip.gameObject.activeInHierarchy)
            {
                return(false);
            }

            tabstrip = UIUtils.Instance.FindComponent <UITabstrip>("ExtendedRoadUpgradePanel");
            if (tabstrip != null)
            {
                DestroyView();
            }

            CreateView();
            if (tabstrip == null)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
 void DestroyBuildTool()
 {
     if (buildTool != null)
     {
         ModDebug.Log("Tool destroyed");
         BuildTool118.Destroy(buildTool);
         buildTool = null;
     }
 }
Пример #3
0
 void SafelySetBuiltinTabstripSelectedIndex(int index)
 {
     ignoreBuiltinTabstripEvents = true;
     try {
         ModDebug.Log("Setting builtin tabstrip mode: " + index);
         builtinTabstrip.selectedIndex = index;
     }
     catch (Exception e) {
         ModDebug.Error(e);
     }
     ignoreBuiltinTabstripEvents = false;
 }
Пример #4
0
        public void Show()
        {
            if (!initialized)
            {
                if (!Initialize())
                {
                    return;
                }
            }

            ModDebug.Log("Showing UI");
            isVisible = true;
        }
Пример #5
0
        System.Collections.IEnumerator FinishCreatingView()
        {
            yield return(null);

            tabstrip.selectedIndex              = -1;
            tabstrip.eventSelectedIndexChanged += (UIComponent component, int index) => {
                ToolMode newMode = (ToolMode)(index + 1);
                ModDebug.Log("tabstrip.eventSelectedIndexChanged: " + newMode);
                if (selectedToolModeChanged != null)
                {
                    selectedToolModeChanged(newMode);
                }
            };
        }
        void FindUIRoot()
        {
            ModDebug.Log("Finding UIRoot");
            uiRoot = null;

            foreach (UIView view in UIView.FindObjectsOfType <UIView>())
            {
                if (view.transform.parent == null && view.name == "UIView")
                {
                    ModDebug.Log("Found UIRoot");
                    uiRoot = view;
                    break;
                }
            }
        }
Пример #7
0
        void FindRoadPrefabs()
        {
            foreach (NetCollection collection in NetCollection.FindObjectsOfType <NetCollection>())
            {
                if (collection.name == "Road")
                {
                    foreach (NetInfo prefab in collection.m_prefabs)
                    {
                        roadPrefabNames[prefab.GetInstanceID()] = prefab.name;
                        roadPrefabs[prefab.name] = prefab;
                    }
                }
            }

            ModDebug.Log("Found " + roadPrefabs.Count + " road prefabs");
        }
Пример #8
0
 void CreateBuildTool()
 {
     if (buildTool == null)
     {
         buildTool = ToolsModifierControl.toolController.gameObject.GetComponent <BuildTool118>();
         if (buildTool == null)
         {
             buildTool = ToolsModifierControl.toolController.gameObject.AddComponent <BuildTool118>();
             ModDebug.Log("Tool created: " + buildTool);
         }
         else
         {
             ModDebug.Log("Found existing tool: " + buildTool);
         }
     }
 }
Пример #9
0
        void SetToolMode(ToolMode mode, bool resetNetToolModeToStraight = false)
        {
            if (mode == toolMode)
            {
                return;
            }

            if (mode != ToolMode.None)
            {
                FindRoadPrefabs();
                CreateBuildTool();
                ToolsModifierControl.toolController.CurrentTool = buildTool;

                if (mode == ToolMode.Oneway)
                {
                    ModDebug.Log("One-way mode activated");
                    toolMode = ToolMode.Oneway;
                }
                else if (mode == ToolMode.Twoway)
                {
                    ModDebug.Log("Two-way mode activated");
                    toolMode = ToolMode.Twoway;
                }

                ui.toolMode = toolMode;
            }
            else
            {
                ModDebug.Log("Tool disabled");
                toolMode = ToolMode.None;

                if (ToolsModifierControl.toolController.CurrentTool == buildTool || ToolsModifierControl.toolController.CurrentTool == null)
                {
                    ToolsModifierControl.toolController.CurrentTool = netTool;
                }

                DestroyBuildTool();

                ui.toolMode = toolMode;

                if (resetNetToolModeToStraight)
                {
                    netTool.m_mode = NetTool.Mode.Straight;
                    ModDebug.Log("Reseted netTool mode: " + netTool.m_mode);
                }
            }
        }
Пример #10
0
        void FindRoadPrefabs()
        {
            foreach (NetCollection collection in NetCollection.FindObjectsOfType <NetCollection>())
            {
                //ModDebug.Log("Collection: " + collection.name);
                foreach (NetInfo prefab in collection.m_prefabs)
                {
                    bool isRoadPrefab = prefab.GetComponent <NetInfo>() != null && prefab.GetComponent <RoadBaseAI>() != null;

                    if (isRoadPrefab)
                    {
                        roadPrefabNames[prefab.GetInstanceID()] = prefab.name;
                        roadPrefabs[prefab.name] = prefab;
                        //ModDebug.Log("Road Prefab: " + prefab.name + "(" + isRoadPrefab + ")");
                    }
                }
            }

            ModDebug.Log("Found " + roadPrefabs.Count + " road prefabs");
        }
Пример #11
0
        void CreateView()
        {
            ModDebug.Log("Creating view");

            GameObject rootObject = new GameObject("ExtendedRoadUpgradePanel");

            tabstrip = rootObject.AddComponent <UITabstrip>();

            UIButton tabTemplate = (UIButton)builtinTabstrip.tabs[0];

            int spriteWidth  = 31;
            int spriteHeight = 31;

            string[] spriteNames =
            {
                "ERUButtonBg",
                "ERUButtonBgPressed",
                "ERUButtonBgHovered",
                "ERUIconTwoway",
                "ERUIconTwowayPressed",
                "ERUIconOneway",
                "ERUIconOnewayPressed"
            };

            UITextureAtlas atlas = CreateTextureAtlas("sprites.png", "ExtendedRoadUpgradeUI", tabTemplate.atlas.material, spriteWidth, spriteHeight, spriteNames);

            List <UIButton> tabs = new List <UIButton>();

            tabs.Add(tabstrip.AddTab("", null, false));
            tabs.Add(tabstrip.AddTab("", null, false));

            foreach (UIButton tab in tabs)
            {
                tab.name             = "ExtendedRoadUpgradeButton";
                tab.atlas            = atlas;
                tab.size             = new Vector2(spriteWidth, spriteHeight);
                tab.normalBgSprite   = "ERUButtonBg";
                tab.disabledBgSprite = "ERUButtonBg";
                tab.hoveredBgSprite  = "ERUButtonBgHovered";
                tab.pressedBgSprite  = "ERUButtonBgPressed";
                tab.focusedBgSprite  = "ERUButtonBgPressed";
                tab.playAudioEvents  = true;
            }

            tabs[0].name            = "ExtendedRoadUpgradeButtonTwoWay";
            tabs[0].tooltip         = "Upgrade To Two-Way Road";
            tabs[0].normalFgSprite  = tabs[0].disabledFgSprite = tabs[0].hoveredFgSprite = "ERUIconTwoway";
            tabs[0].pressedFgSprite = tabs[0].focusedFgSprite = "ERUIconTwowayPressed";

            tabs[1].name            = "ExtendedRoadUpgradeButtonOneWay";
            tabs[1].tooltip         = "Upgrade To One-Way Road";
            tabs[1].normalFgSprite  = tabs[1].disabledFgSprite = tabs[1].hoveredFgSprite = "ERUIconOneway";
            tabs[1].pressedFgSprite = tabs[1].focusedFgSprite = "ERUIconOnewayPressed";


            roadsOptionPanel.AttachUIComponent(tabstrip.gameObject);
            tabstrip.relativePosition = new Vector3(169, 38);
            tabstrip.width            = 80;
            tabstrip.selectedIndex    = -1;
            tabstrip.padding          = new RectOffset(0, 1, 0, 0);

            if (builtinModeChangedHandler == null)
            {
                builtinModeChangedHandler = (UIComponent component, int index) => {
                    ModDebug.Log(string.Format("Builtin mode changed to: {0}, ignore: {1}", index, ignoreBuiltinTabstripEvents));
                    if (!ignoreBuiltinTabstripEvents)
                    {
                        if (selectedToolModeChanged != null)
                        {
                            selectedToolModeChanged(ToolMode.None);
                        }
                    }
                };
            }

            builtinTabstrip.eventSelectedIndexChanged += builtinModeChangedHandler;

            // Setting selectedIndex needs to be delayed for some reason
            tabstrip.StartCoroutine(FinishCreatingView());
        }
Пример #12
0
        void _OnUpdate()
        {
            if (loadingLevel)
            {
                return;
            }

            /*if (Input.GetKeyDown(KeyCode.Delete)) {
             *  if (UIInput.hoveredComponent != null) {
             *      ModDebug.Log(UIUtils.Instance.GetTransformPath(UIInput.hoveredComponent.transform) + " (" + UIInput.hoveredComponent.GetType() + ")");
             *  }
             * }*/

            if (Input.GetKeyDown(KeyCode.Return))
            {
                ModDebug.Log(netTool.m_prefab + " " + netTool.m_mode);
            }

            if (roadsPanel == null)
            {
                roadsPanel = UIView.Find <UIPanel>("RoadsPanel");
            }

            if (roadsPanel == null || !roadsPanel.isVisible)
            {
                if (toolMode != ToolMode.None)
                {
                    ModDebug.Log("Roads panel no longer visible");
                    SetToolMode(ToolMode.None, true);
                }
                return;
            }

            if (netTool == null)
            {
                foreach (var tool in ToolsModifierControl.toolController.Tools)
                {
                    NetTool nt = tool as NetTool;
                    if (nt != null && nt.m_prefab != null)
                    {
                        ModDebug.Log("NetTool found: " + nt.name);
                        netTool = nt;
                        break;
                    }
                }

                if (netTool == null)
                {
                    return;
                }

                raycastService = new ToolBase.RaycastService(netTool.m_prefab.m_class.m_service, netTool.m_prefab.m_class.m_subService, netTool.m_prefab.m_class.m_layer);

                ModDebug.Log("UI visible: " + ui.isVisible);
            }

            if (!ui.isVisible)
            {
                ui.Show();
            }

            /*if (Input.GetKeyDown(KeyCode.Comma)) {
             *  SetToolMode(ToolMode.Twoway);
             * }
             * else if (Input.GetKeyDown(KeyCode.Period)) {
             *  SetToolMode(ToolMode.Oneway);
             * }*/

            if (toolMode != ToolMode.None)
            {
                mouseDown      = Input.GetMouseButton(0);
                mouseRayValid  = !ToolsModifierControl.toolController.IsInsideUI && Cursor.visible;
                mouseRay       = Camera.main.ScreenPointToRay(Input.mousePosition);
                mouseRayLength = Camera.main.farClipPlane;
                currentTime    = Time.time;

                if (ToolsModifierControl.toolController.CurrentTool != buildTool)
                {
                    ModDebug.Log("Another tool selected");
                    SetToolMode(ToolMode.None);
                }
            }
            else
            {
                ui.toolMode = ToolMode.None;

                if (ToolsModifierControl.toolController.CurrentTool == buildTool)
                {
                    ToolsModifierControl.toolController.CurrentTool = netTool;
                }
            }
        }
Пример #13
0
 public void OnLevelLoaded(LoadMode mode)
 {
     loadingLevel = false;
     ModDebug.Log("OnLevelLoaded, UI visible: " + ui.isVisible);
 }