Example #1
0
        private void processControlGroupSelection(KeyCode keyCode, int i)
        {
            string        unitToSelect = SettingsManager.controlGroupSettlers[i];
            ALivingEntity settler      = UnitManager.getInstance().playerUnits.Find(x => x.unitName == unitToSelect);

            if (settler == null || !settler.isAlive())
            {
                SettingsManager.controlGroupSettlers[i] = string.Empty;
                return;
            }

            MonoBehaviour selectedObject = UnitManager.getInstance().controllerObj.GetComponent <ControlPlayer>().selectedObject;

            bool openSettlerWindow = false;

            if (selectedObject != null && selectedObject.gameObject.tag == "ControllableUnit" && AManager <GUIManager> .getInstance().GetComponent <HumanSettlerWindow>().entity == selectedObject)
            {
                openSettlerWindow = true;
            }
            AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().SelectObject(settler.transform, openSettlerWindow);

            if (doubleTapDelayArray[i] > 0 && numberOfTapsArray[i] == 1)
            {
                AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().MoveToPosition(settler.coordinate.world);
            }
            else
            {
                resetDobuleTap(i);
            }
        }
Example #2
0
        /// <summary>
        /// This function will move through idle settlers forward and backwords depending on the bool
        /// </summary>
        /// <param name="next">Go to the next idle settler or the previous idle settler.</param>
        private void idleSettlerTab(bool next)
        {
            if (idleSettlers.Count == 0)
            {
                return;
            }

            ControlPlayer controlPlayer = AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>();

            MonoBehaviour selectedObject    = UnitManager.getInstance().controllerObj.GetComponent <ControlPlayer>().selectedObject;
            bool          openSettlerWindow = false;

            if (selectedObject != null && selectedObject.gameObject.tag == "ControllableUnit" && AManager <GUIManager> .getInstance().GetComponent <HumanSettlerWindow>().entity == selectedObject)
            {
                openSettlerWindow = true;
            }
            if (!AManager <GUIManager> .getInstance().gameOver)
            {
                if (next)
                {
                    currentIdleSettlerIndex++;                         //go to next settler
                    if (currentIdleSettlerIndex >= idleSettlers.Count) //do we need to go to the begining of hte list?
                    {
                        currentIdleSettlerIndex = 0;
                    }
                    while (!idleSettlers[currentIdleSettlerIndex].isAlive())   //make sure it is not dead, if it is go to the next one.
                    {
                        currentIdleSettlerIndex++;
                        if (currentIdleSettlerIndex >= idleSettlers.Count)
                        {
                            currentIdleSettlerIndex = 0;
                        }
                    }
                }
                else
                {
                    currentIdleSettlerIndex--;       //go to the previous settler
                    if (currentIdleSettlerIndex < 0) //if we are at the begining of the list go to the last
                    {
                        currentIdleSettlerIndex = idleSettlers.Count - 1;
                    }
                    while (!idleSettlers[currentIdleSettlerIndex].isAlive())   //make sure we are not selecting dead settlers
                    {
                        currentIdleSettlerIndex--;
                        if (currentIdleSettlerIndex < 0)
                        {
                            currentIdleSettlerIndex = idleSettlers.Count - 1;
                        }
                    }
                }
            }

            //move to the settler and select him
            AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().MoveToPosition(idleSettlers[currentIdleSettlerIndex].coordinate.world);

            AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().SelectObject(idleSettlers[currentIdleSettlerIndex].transform, openSettlerWindow);
        }
Example #3
0
        //This function just displays the Gmae Speed GUI at the top right of the screen.
        private void GameSpeedGUI()
        {
            int num  = Screen.width - 120;
            int num2 = 88;

            if (Screen.width > 1520)
            {
                num2 -= 40;
            }
            guiMgr.DrawWindow(new Rect((float)(num - 10), (float)(num2 + 5), 128f, 24f), string.Empty, false, true);

            if (GUI.Button(new Rect((float)(num - 5), (float)(num2 + 4), 26f, 26f), "3x", this.guiMgr.blankButtonStyle))
            {
                AManager <TimeManager> .getInstance().play(3f);

                GUIManager.getInstance().AddTextLine("3x Speed");
            }
            if (GUI.Button(new Rect((float)(num + 27), (float)(num2 + 4), 26f, 26f), "4x", this.guiMgr.blankButtonStyle))
            {
                AManager <TimeManager> .getInstance().play(4f);

                GUIManager.getInstance().AddTextLine("4x Speed");
            }
            if (GUI.Button(new Rect((float)(num + 58), (float)(num2 + 4), 26f, 26f), "5x", this.guiMgr.blankButtonStyle))
            {
                AManager <TimeManager> .getInstance().play(5f);

                GUIManager.getInstance().AddTextLine("5x Speed");
            }
            if (GUI.Button(new Rect((float)(num + 84), (float)(num2 + 4), 26f, 26f), "6x", this.guiMgr.blankButtonStyle))
            {
                AManager <TimeManager> .getInstance().play(6f);

                GUIManager.getInstance().AddTextLine("6x Speed");
            }
            if (Time.timeScale == 3f)
            {
                GUI.DrawTexture(new Rect((float)(num - 8), (float)(num2 + 1), 32f, 32f), this.guiMgr.gameSpeedSelector);
            }
            else
            {
                if (Time.timeScale == 4f)
                {
                    GUI.DrawTexture(new Rect((float)(num + 26), (float)(num2 + 1), 32f, 32f), this.guiMgr.gameSpeedSelector);
                }
                else if (Time.timeScale == 5f)
                {
                    GUI.DrawTexture(new Rect((float)(num + 57), (float)(num2 + 1), 32f, 32f), this.guiMgr.gameSpeedSelector);
                }
                else if (Time.timeScale == 6f)
                {
                    GUI.DrawTexture(new Rect((float)(num + 83), (float)(num2 + 1), 32f, 32f), this.guiMgr.gameSpeedSelector);
                }
            }
        }
Example #4
0
        //This is called alot less then ongui and can have some model data manipulation in it.
        //This is also were any hotkeys are intercepted.
        void Update()
        {
            if (Input.GetKeyDown(SettingsManager.hotKeys["toggleTripleSpeedHotKey"]))
            {
                if (SettingsManager.boolSettings[(int)Preferences.toggleTripleSpeed] == false)
                {
                    SettingsManager.boolSettings[(int)Preferences.toggleTripleSpeed] = true;
                    AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().DeSelect();

                    AManager <GUIManager> .getInstance().GetComponent <MainMenus>().CloseAll();
                }
                else
                {
                    SettingsManager.boolSettings[(int)Preferences.toggleTripleSpeed] = false;
                }
            }
        }
Example #5
0
        //This is called alot less then ongui and can have some model data manipulation in it.
        //This is also were any hotkeys are intercepted.
        void Update()
        {
            if (selectSettler && settlerToSelect != null)   //if we are suppose to select a settler and there is a settler to select
            {
                MonoBehaviour selectedObject    = UnitManager.getInstance().controllerObj.GetComponent <ControlPlayer>().selectedObject;
                bool          openSettlerWindow = false;
                if (selectedObject != null && selectedObject.gameObject.tag == "ControllableUnit" && AManager <GUIManager> .getInstance().GetComponent <HumanSettlerWindow>().entity == selectedObject)
                {
                    openSettlerWindow = true;
                }

                AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().MoveToPosition(settlerToSelect.coordinate.world);

                AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().SelectObject(settlerToSelect.transform, openSettlerWindow);

                selectSettler = false;
            }

            if (Input.GetKeyDown(SettingsManager.hotKeys["previousIdleSettler"]))
            {
                idleSettlerTab(false);
            }

            if (Input.GetKeyDown(SettingsManager.hotKeys["nextIdleSettler"]))
            {
                idleSettlerTab(true);
            }

            if (Input.GetKeyDown(SettingsManager.hotKeys["toggleIdleSettlersHotKey"]))
            {
                if (SettingsManager.boolSettings[(int)Preferences.toggleIdleSettlers] == false)
                {
                    SettingsManager.boolSettings[(int)Preferences.toggleIdleSettlers] = true;
                    AManager <WorldManager> .getInstance().controllerObj.GetComponent <ControlPlayer>().DeSelect();

                    AManager <GUIManager> .getInstance().GetComponent <MainMenus>().CloseAll();
                }
                else
                {
                    SettingsManager.boolSettings[(int)Preferences.toggleIdleSettlers] = false;
                }
            }
        }
        private Vector3 getRandomPosition()
        {
            int   num  = UnityEngine.Random.Range(1, 5);
            float num2 = 0f;
            float num3 = 0f;

            if (num == 1)
            {
                num3 = 1f;
                num2 = 0f;
            }
            else
            {
                if (num == 2)
                {
                    num3 = -1f;
                    num2 = 0f;
                }
                else
                {
                    if (num == 3)
                    {
                        num3 = 0f;
                        num2 = -1f;
                    }
                    else
                    {
                        if (num == 4)
                        {
                            num3 = 0f;
                            num2 = 1f;
                        }
                    }
                }
            }
            return(new Vector3(AManager <WorldManager> .getInstance().GetEdgePosition() * num2 + num3 * (0.1f + (float)UnityEngine.Random.Range(-256, 257) * 0.1f), 0f, AManager <WorldManager> .getInstance().GetEdgePosition() * num3 + num2 * (0.1f + (float)UnityEngine.Random.Range(-256, 257) * 0.1f)));
        }
        /// <summary>
        /// This function will load the plugin. It will take hte plugin info make sure the file exsits
        /// and then load the dll, find the class that needs to be loaded and then load that class.
        /// There is no checking in place to make sure the plugins do not conflict.
        /// </summary>
        /// <param name="pluginInfo">This is the plugin that will be loaded.</param>
        public static void loadPlugin(PluginInfo pluginInfo)
        {
            if (pluginInfo.isLoaded)
            {
                return;
            }

            pluginInfo.shouldLoadPlugin = true;
            FileInfo info = new FileInfo("./saves/" + pluginInfo.fileName);

            if (info != null && info.Exists == true)   //make sure the file is there
            {
                try {
                    //loading new domains do not work for some reason
                    //pluginInfo.appDomain = AppDomain.CreateDomain("Testdomain");
                    //AssemblyName assemblyName = new AssemblyName();
                    //assemblyName.CodeBase = pluginInfo.fileName;
                    //pluginInfo.assembly = pluginInfo.appDomain.Load(pluginInfo.fileName);

                    pluginInfo.assembly = Assembly.LoadFile("./saves/" + pluginInfo.fileName); //load file
                    if (pluginInfo.assembly != null)
                    {
                        Type[] types = pluginInfo.assembly.GetTypes(); //get all classes out of file
                        for (int i = 0; i < types.Length; i++)
                        {
                            Type type = types[i];
                            if (typeof(IPlugin).IsAssignableFrom(type) && type.IsClass)      //find the one that is a plugin
                            {
                                pluginInfo.plugin = (IPlugin)Activator.CreateInstance(type); //create that class
                            }
                        }
                    }
                    else
                    {
                        GUIWindowModOptions.displayErrorMessage("Assemply is null on load of '" + pluginInfo.fileName + "'");
                        AManager <GUIManager> .getInstance().AddTextLine("Assemply is null on load of '" + pluginInfo.fileName + "'");
                    }
                } catch (Exception ex) {
                    GUIWindowModOptions.displayErrorMessage("Could not load assembly: '" + pluginInfo.fileName + "'");
                    AManager <GUIManager> .getInstance().AddTextLine("Could not load assembly: '" + pluginInfo.fileName + "'");

                    AManager <GUIManager> .getInstance().AddTextLine(" " + ex.Message);

                    pluginInfo.shouldLoadPlugin = false;
                    pluginInfo.isLoaded         = false;
                }

                if (pluginInfo.plugin != null)   //make sure we created the class
                {
                    try {
                        pluginInfo.plugin.OnLoad(); //load hte plugin
                    } catch (Exception ex) {
                        GUIWindowModOptions.displayErrorMessage("Assembly " + pluginInfo.assembly.GetName().Name + " crashed in OnLoad");
                        AManager <GUIManager> .getInstance().AddTextLine("Assembly " + pluginInfo.assembly.GetName().Name + " crashed in OnLoad with exception: " + ex.Message);

                        pluginInfo.shouldLoadPlugin = false;
                        pluginInfo.isLoaded         = false;
                    }

                    try {
                        pluginInfo.plugin.OnEnable(); //enable the plugin
                    } catch (Exception ex) {
                        GUIWindowModOptions.displayErrorMessage("Assembly " + pluginInfo.assembly.GetName().Name + " crashed in OnEnable");
                        AManager <GUIManager> .getInstance().AddTextLine("Assembly " + pluginInfo.assembly.GetName().Name + " crashed in OnEnable with exception: " + ex.Message);

                        pluginInfo.shouldLoadPlugin = false;
                        pluginInfo.isLoaded         = false;
                    }
                    pluginInfo.isLoaded = true;
                }
                else
                {
                    GUIWindowModOptions.displayErrorMessage("Plugin is null");
                    AManager <GUIManager> .getInstance().AddTextLine("Plugin is null");

                    pluginInfo.shouldLoadPlugin = false;
                    pluginInfo.isLoaded         = false;
                }
            }
            else
            {
                GUIWindowModOptions.displayErrorMessage("File name does not exist: '" + pluginInfo.fileName + "'");
                AManager <GUIManager> .getInstance().AddTextLine("File name does not exist: '" + pluginInfo.fileName + "'");

                pluginInfo.shouldLoadPlugin = false;
                pluginInfo.isLoaded         = false;
            }
        }