Exemple #1
0
        public bool ReleaseProp(bool dispatchPlacementEffect)
        {
            CheckPropStillExists();

            if (stillExists == false)
            {
                return(false);
            }
            else
            {
                if (Singleton <PropManager> .instance.m_props.m_buffer[(int)((UIntPtr)propPlacementInfo.propID)].m_flags != 0)
                {
                    PropManager instance = Singleton <PropManager> .instance;
                    instance.ReleaseProp(propPlacementInfo.propID);
                    if (dispatchPlacementEffect)
                    {
                        PropLineTool.DispatchPlacementEffect(propPlacementInfo.position, true);
                    }

                    return(true);
                }

                return(false);
            }
        }
Exemple #2
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);
            Debug.Log("[PropLineTool, hereafter PLT]: start PropLineToolMod.OnLevelLoaded");
            m_loadMode = mode;
            m_onLevelLoadedCount++;

            Debug.Log("[PLT]: Build Version: " + BUILD_VERSION);

            string _ordinal = Util.OrdinalSuffix(m_onLevelLoadedCount);

            Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): This is the " + m_onLevelLoadedCount + _ordinal + " time this method has been called, and the LoadMode is " + mode.ToString() + ".");
            Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): ItemClass.Availabilty of TMC tool controller is " + ToolsModifierControl.toolController.m_mode.ToString() + ".");

            bool _initializeToolMan = false;

            _initializeToolMan = ToolMan.ToolMan.Initialize();

            //PropLineTool Initialization
            PropLineTool.PopulateRandIntArray(0, 10000);

            if (_initializeToolMan == true)
            {
                Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): ToolMan.Initialize() returned true.");
                Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): Adding/Initializing UI components...");

                if (optionPanel == null)
                {
                    optionPanel = (UIView.GetAView().AddUIComponent(typeof(UIOptionPanel)) as UIOptionPanel);
                }

                if (basicControlPanel == null)
                {
                    basicControlPanel = (UIView.GetAView().AddUIComponent(typeof(UIBasicControlPanel)) as UIBasicControlPanel);
                }

                Debug.Log("[PLT]: PropLineToolMod.OnLevelLoaded(): UI components addition/initialization finished.");

                //debug purposes only
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("[DEBUG] Prop Line Tool [PLT] Success in Initialization", "Prop Line Tool succeeded in registering itself with the game's tool controllers!", false);
            }
            else
            {
                Debug.LogError("[PLT]: PropLineToolMod.OnLevelLoaded(): ToolMan.Initialize() returned false.");

                //special thanks to RushHour.Compatibility for this
                UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Prop Line Tool [PLT] Failed to Initialize", "Prop Line Tool failed to register itself with the game's tool controllers. Please save your output_log from this game session and post a link to it on the workshop page for PLT.", true);
            }

            Debug.Log("[PLT]: end PropLineToolMod.OnLevelLoaded");
        }
        private static bool SetUpPropLineTool(ref ToolController toolController, ref List <ToolBase> extraTools)
        {
            PropLineTool propLineTool = toolController.gameObject.GetComponent <PropLineTool>();

            if (propLineTool == null)
            {
                propLineTool = toolController.gameObject.AddComponent <PropLineTool>();
                extraTools.Add(propLineTool);

                Debug.Log("[PLT]: ToolMan.SetupPropLineTool(): Added PropLineTool to toolController. Returning true...");
                return(true);
            }
            else
            {
                Debug.Log("[PLT]: ToolMan.SetupPropLineTool(): PropLineTool already exists in the toolController. Returning false...");
                return(false);
            }
        }
Exemple #4
0
        public override void OnLevelUnloading()
        {
            base.OnLevelUnloading();

            PropLineTool.OnLevelUnloading();

            //new as of 160816 0041
            //in reference to NetworkSkinsMod.OnLevelUnloading
            //destroy in reverse order of creation
            if (basicControlPanel != null)
            {
                UnityEngine.GameObject.Destroy(basicControlPanel);
            }
            if (optionPanel != null)
            {
                UnityEngine.GameObject.Destroy(optionPanel);
            }
        }
Exemple #5
0
        public bool ReleaseTree(bool dispatchPlacementEffect)
        {
            CheckTreeStillExists();

            if (stillExists == false)
            {
                return(false);
            }
            else
            {
                TreeManager instance = Singleton <TreeManager> .instance;
                instance.ReleaseTree(treePlacementInfo.treeID);
                if (dispatchPlacementEffect)
                {
                    PropLineTool.DispatchPlacementEffect(treePlacementInfo.position, true);
                }

                return(true);
            }
        }
        //Last Updated 160622
        private static bool AddExtraToolsToController(ref ToolController toolController, List <ToolBase> extraTools)
        {
            bool _result = false;

            Debug.Log("[PLT]: Begin ToolMan.AddExtraToolsToController().");
            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Progress: 0/4 [    ]");

            if (toolController == null)
            {
                Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Failed to append PropLineTool to tool controllers: toolController parameter is null.");
                return(false);
            }
            if (extraTools == null)
            {
                Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Failed to append PropLineTool to tool controllers: extraTools parameter is null.");
                return(false);
            }
            if (extraTools.Count < 1)
            {
                Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): No tools were found in the extraTools parameter.");
                return(false);
            }

            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Progress: 1/4 [=   ]");

            var _toolsFieldInfo = typeof(ToolController).GetField("m_tools", BindingFlags.Instance | BindingFlags.NonPublic);

            var _tools = (ToolBase[])_toolsFieldInfo.GetValue(toolController);

            if (_tools == null)
            {
                //old
                //Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Failed to append PropLineTool to tool controllers: Could not FieldInfo.GetValue() from ToolController.m_tools.");
                //return false;

                //new
                Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): toolController.m_tools was detected to be null from FieldInfo.GetValue().");
                Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Attempting to pre-populate toolController.m_tools by calling toolController.GetComponents<ToolBase>().");

                _tools = toolController.GetComponents <ToolBase>();

                var _tools2 = (ToolBase[])_toolsFieldInfo.GetValue(toolController);

                if (_tools2 == null)
                {
                    Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Failed to pre-populate toolController.m_tools. Returning false...");
                    return(false);
                }
                else if (_tools.Length > 0)
                {
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): The attempt to pre-populate toolController.m_tools appears to have been successful...");
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Pre-populated toolController.m_tools with >>" + _tools.Length + "<< tools.");
                }
                else
                {
                    Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): The attempt to pre-populate toolController.m_tools failed. No tools were found. Returning false...");
                    return(false);
                }
            }
            if (_tools.Length < 1)
            {
                Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): Initial ToolController.m_tools has a length < 1. Its length is: " + _tools.Length + ".");

                if (extraTools.Count < 1)
                {
                    Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Returning false since both toolController.m_tools and extraTools have a length < 1.");
                    return(false);
                }
            }

            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Progress: 2/4 [==  ]");

            //Prepare toolController.m_tools for appending new elements
            int _initialLength = _tools.Length;

            Array.Resize <ToolBase>(ref _tools, _initialLength + extraTools.Count);
            var index = 0;

            //find ToolsModifierControl tool dictionary
            var _dictionary = (Dictionary <Type, ToolBase>) typeof(ToolsModifierControl).GetField("m_Tools", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            if (_dictionary == null)
            {
                //old
                //Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): Failed to append PropLineTool to tool controllers: Could not find ToolsModifierControl.m_Tools dictionary.");
                //return false;

                //new
                Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): ToolsModifierControl.m_Tools dictionary was detected to be null from FieldInfo.GetField().");

                Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Attempting to pre-populate ToolsModifierControl.m_Tools dictionary by calling ToolsModifierControl.GetTool<PropTool>()...");
                var _propTool = ToolsModifierControl.GetTool <PropTool>();

                var _dictionary2 = (Dictionary <Type, ToolBase>) typeof(ToolsModifierControl).GetField("m_Tools", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

                if (_dictionary2 == null)
                {
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Failed in pre-populating ToolsModifierControl.m_Tools by calling ToolsModifierControl.GetTool<PropTool>()...");

                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Attempting to pre-populate ToolsModifierControl.m_Tools by copying the >>" + _tools.Length + "<< elements of toolController.m_tools.");
                    //Our own version of ToolsModifierControl.CollectTools()
                    _dictionary = new Dictionary <Type, ToolBase>(_initialLength + extraTools.Count);
                    for (int i = 0; i < _tools.Length; i++)
                    {
                        _dictionary.Add(_tools[i].GetType(), _tools[i]);
                    }

                    var _dictionary3 = (Dictionary <Type, ToolBase>) typeof(ToolsModifierControl).GetField("m_Tools", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

                    if (_dictionary3 == null)
                    {
                        Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Failed in pre-populating ToolsModifierControl.m_Tools by copying the >>" + _tools.Length + "<< elements of toolController.m_tools.");

                        Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): All attempts to pre-populate ToolsModifierControl.m_Tools failed. ): Returning false...");
                        return(false);
                    }
                    else
                    {
                        _dictionary = _dictionary3;
                        Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): The attempt to pre-populate ToolsModifierControl.m_Tools dictionary by copying the >>" + _tools.Length + "<< elements of toolController.m_tools appears to have been successful...");
                    }
                }
                else
                {
                    _dictionary = _dictionary2;
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): The attempt to pre-populate ToolsModifierControl.m_Tools dictionary by calling ToolsModifierControl.GetTool<PropTool>() appears to have been successful...");
                }

                Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Verifying the length of the ToolBase collections for both tool controllers...");
                //check that lengths match
                if (_dictionary == null)
                {
                    Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): _dictionary is null! Returning false...");
                    return(false);
                }
                if (_dictionary.Count == _tools.Length)
                {
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Successfully pre-populated ToolsModifierControl.m_Tools dictionary. Its Count is: " + _dictionary2.Count + ".");
                }
                else
                {
                    //actually since we resized _tools earlier, _tools should be extraTools.Length (1) longer than _dictionary.
                    Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): ToolsModifierControl.m_Tools.Count does not equal toolController.m_tools.Length");
                    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): ToolsModifierControl.m_Tools.Count = " + _dictionary2.Count + ", and toolController.m_tools.Length = " + _tools.Length + ".");
                }
            }
            else if (_dictionary.Count < 1)
            {
                Debug.LogWarning("[PLT]: ToolMan.AddExtraToolsToController(): Initial ToolsModifierControl.m_Tools dictionary has a count < 1. Its count is: " + _dictionary.Count + ".");
            }

            //append PropLineTool to ToolBase collections
            foreach (var _currentTool in extraTools)
            {
                _dictionary.Add(_currentTool.GetType(), _currentTool);
                _tools[_initialLength + index] = _currentTool;
                index++;
            }

            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Progress: 3/4 [=== ]");

            _toolsFieldInfo.SetValue(toolController, _tools);

            PropLineTool _propLineTool = ToolsModifierControl.GetTool <PropLineTool>();

            if (_propLineTool == null)
            {
                Debug.LogError("[PLT]: ToolMan.AddExtraToolsToController(): PropLineTool was not found in ToolsModifierControl after appending to the tool dictionary.");
                return(false);
            }

            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Progress: 4/4 [====]");
            Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Success in appending PropLineTool to tool controllers!");

            //160815 2306
            //These are only really necessary as I suspect two instances of PropLineTool are being created for some users (NullReferenceException when placing each line).
            //I no longer believe this ^ to be the case, so we comment these out.
            //Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): Outputting toolController lists:");
            //Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): toolController.m_tools array has " + _tools.Length + " members:");
            //for (int i = 0; i < _tools.Length; i++)
            //{
            //    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): toolController.m_tools[" + i + "] = " + _tools[i]);
            //}
            //Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): ToolsModifierControl.m_Tools dictionary has " + _dictionary.Count + " members:");
            //var _keys = _dictionary.Keys.ToList<Type>();
            //foreach (Type _type in _keys)
            //{
            //    Debug.Log("[PLT]: ToolMan.AddExtraToolsToController(): ToolsModifierControl.m_Tools[" + _type + "] = " + _dictionary[_type]);
            //}

            _result = true;
            return(_result);
        }
Exemple #7
0
        //Works BEAUTIFULLY!! :DDD
        public static void SwitchTools(out bool allNull)
        {
            allNull                 = true;
            m_wasPLTActive          = m_PLTActive;
            m_wasBulldozeToolActive = m_bulldozeToolActive;

            ICities.LoadMode _loadMode = PropLineToolMod.GetLoadMode();

            PropTool     _propTool     = ToolsModifierControl.GetCurrentTool <PropTool>();
            TreeTool     _treeTool     = ToolsModifierControl.GetCurrentTool <TreeTool>();
            PropLineTool _propLineTool = ToolsModifierControl.GetCurrentTool <PropLineTool>();

            BulldozeTool _bulldozeTool = ToolsModifierControl.GetCurrentTool <BulldozeTool>();

            if ((_propTool == null) && (_treeTool == null) && (_propLineTool == null))
            {
                allNull = true;
                if (!m_wasBulldozeToolActive)
                {
                    m_PLTActive = false;
                }

                if (m_wasPLTActive == true)
                {
                    PropLineTool.m_keepActiveState = true;
                }

                if (_bulldozeTool != null)
                {
                    m_bulldozeToolActive = true;
                }
                else
                {
                    m_bulldozeToolActive = false;
                }

                if (m_resetCounterActive && resetCounterElapsedTimeSeconds > RESET_THRESHOLD_SECONDS)
                {
                    m_resetCounterActive  = false;
                    m_resetCounterExpired = true;
                }
                else if (!m_resetCounterExpired && !m_resetCounterActive)
                {
                    m_resetCounterActive           = true;
                    m_resetCounterStartTimeSeconds = Time.time;

                    //Debug.Log("[PLTDEBUG]: m_resetCounterStartTimeSeconds = " + m_resetCounterStartTimeSeconds);
                }

                return;
            }
            else
            {
                allNull = false;
                if (_propLineTool != null)
                {
                    m_PLTActive = true;
                }
                //continue along
            }

            //single mode: signal tool switch
            //not-single mode: signal standby
            bool _PLTActiveExclusive = ((_propLineTool != null) && (_propTool == null) && (_treeTool == null));

            //single mode: signal standby
            //not-single mode: signal tool switch
            bool _PLTInactiveButPropOrTreeActive = ((_propLineTool == null) && ((_propTool != null) || (_treeTool != null)));

            //error checking?
            bool _multipleActivePropTreeTools = ((_propLineTool != null) && ((_propTool != null) || (_treeTool != null)));

            if (_multipleActivePropTreeTools)
            {
                Debug.LogError("[PLT]: ToolSwitch: More than one active tool!");
                return;
            }

            //loadmode is in-game
            bool _inGame = ((_loadMode == ICities.LoadMode.NewGame) || (_loadMode == ICities.LoadMode.LoadGame));
            //loadmode is map-editor or asset-editor [EDIT: ACTUALLY JUST MAP EDITOR]
            //bool flag4 = (  (_loadMode == ICities.LoadMode.LoadMap) || (_loadMode == ICities.LoadMode.LoadAsset) || (_loadMode == ICities.LoadMode.NewAsset) || (_loadMode == ICities.LoadMode.NewMap)  );
            bool _mapEditor = ((_loadMode == ICities.LoadMode.LoadMap) || (_loadMode == ICities.LoadMode.NewMap));

            //test if BrushPanel was found
            m_brushPanelFound = (m_brushPanel != null);

            switch (PropLineTool.drawMode)
            {
            case PropLineTool.DrawMode.Single:
            {
                //reset active state
                PropLineTool.m_keepActiveState = false;

                if (_PLTActiveExclusive)
                {
                    switch (PropLineTool.objectMode)
                    {
                    case PropLineTool.ObjectMode.Undefined:
                    {
                        Debug.LogError("[PLT]: ToolSwitch: Object mode is undefined!");
                        break;
                    }

                    case PropLineTool.ObjectMode.Props:
                    {
                        PropInfo oldPropInfo = _propLineTool.propPrefab;
                        PropTool newPropTool = ToolsModifierControl.SetTool <PropTool>();
                        if (oldPropInfo == null)
                        {
                            Debug.LogError("[PLT]: ToolSwitch: PropLineTool prop prefab is null!");
                            return;
                        }
                        newPropTool.m_prefab = oldPropInfo;

                        //new as of 190809
                        FindBrushPanel();

                        if (_mapEditor && m_brushPanelFound)
                        {
                            m_brushPanel.Show();
                        }
                        break;
                    }

                    case PropLineTool.ObjectMode.Trees:
                    {
                        TreeInfo oldTreeInfo = _propLineTool.treePrefab;
                        TreeTool newTreeTool = ToolsModifierControl.SetTool <TreeTool>();
                        if (oldTreeInfo == null)
                        {
                            Debug.LogError("[PLT]: ToolSwitch: PropLineTool tree prefab is null!");
                            return;
                        }
                        newTreeTool.m_prefab = _propLineTool.treePrefab;

                        //new as of 190809
                        FindBrushPanel();

                        if ((_mapEditor || (_inGame)) && m_brushPanelFound)
                        {
                            m_brushPanel.Show();
                        }
                        break;
                    }
                    }
                    return;
                }
                else if (_PLTInactiveButPropOrTreeActive)
                {
                    return;
                }
                else
                {
                    Debug.LogError("[PLT]: ToolSwitch: PropLineTool -> mismatch!");
                    return;
                }
            }

            case PropLineTool.DrawMode.Straight:
            case PropLineTool.DrawMode.Curved:
            case PropLineTool.DrawMode.Freeform:
            case PropLineTool.DrawMode.Circle:
            {
                if (_PLTInactiveButPropOrTreeActive)
                {
                    if (m_wasPLTActive == true)
                    {
                        PropLineTool.m_keepActiveState = true;
                    }
                    else
                    {
                        if (pendingReset)
                        {
                            PropLineTool.m_keepActiveState = false;
                        }
                        else         //do not reset
                        {
                            PropLineTool.m_keepActiveState = true;
                        }
                    }

                    m_resetCounterExpired = false;
                    m_resetCounterActive  = false;

                    //continue along (no "return;" on this line)
                    if (_propTool != null)
                    {
                        PropInfo     oldPropInfo     = _propTool.m_prefab;
                        PropLineTool newPropLineTool = ToolsModifierControl.SetTool <PropLineTool>();
                        //PropLineTool.objectMode = PropLineTool.ObjectMode.Props;
                        if (oldPropInfo == null)
                        {
                            Debug.LogError("[PLT]: ToolSwitch: PropTool prop prefab is null!");
                            return;
                        }
                        newPropLineTool.propPrefab = oldPropInfo;
                        //calling after setting prefab
                        PropLineTool.objectMode = PropLineTool.ObjectMode.Props;

                        //new as of 190809
                        FindBrushPanel();

                        if (m_brushPanelFound)
                        {
                            m_brushPanel.Hide();
                        }
                        return;
                    }
                    if (_treeTool != null)
                    {
                        TreeInfo     oldTreeInfo     = _treeTool.m_prefab;
                        PropLineTool newPropLineTool = ToolsModifierControl.SetTool <PropLineTool>();
                        //PropLineTool.objectMode = PropLineTool.ObjectMode.Trees;
                        if (oldTreeInfo == null)
                        {
                            Debug.LogError("[PLT]: ToolSwitch: TreeTool tree prefab is null!");
                            return;
                        }
                        newPropLineTool.treePrefab = oldTreeInfo;
                        //calling after setting prefab
                        PropLineTool.objectMode = PropLineTool.ObjectMode.Trees;

                        //new as of 190809
                        FindBrushPanel();

                        if (m_brushPanelFound)
                        {
                            m_brushPanel.Hide();
                        }
                        return;
                    }
                }
                else if (_PLTActiveExclusive)
                {
                    if ((_propLineTool.propPrefab == null) && (_propLineTool.treePrefab == null))
                    {
                        Debug.LogError("[PLT]: ToolSwitch: PropLineTool prop and tree prefabs are null!");
                    }
                    return;
                }
                break;
            }

            default:
            {
                Debug.LogError("[PLT]: ToolSwitch: Draw Mode is out of bounds!");
                return;
            }
            }

            //safety-net return
            Debug.LogError("[PLT]: Reached safety-net return of ToolSwitch.SwitchTools");
            return;
        }
Exemple #8
0
 protected void RenderCircle(RenderManager.CameraInfo cameraInfo, Vector3 position, float size, Color color, bool renderLimits, bool alphaBlend)
 {
     PropLineTool.RenderCircle(cameraInfo, position, size, color, renderLimits, alphaBlend);
 }