Example #1
0
    void ChangeUpgradeCostText(int buttonIndex, string newText)
    {
        HoverContextElement el = upgradeButton[buttonIndex].GetComponent <HoverContextElement> ();

        el.text = newText;
        el.ForceUpdate();
    }
Example #2
0
    public static void ChangeButtons(bool state)
    {
        int index = 0;

        foreach (Button butt in game.disabledDuringWaves)
        {
            butt.interactable = state;
            HoverContextElement ele = butt.GetComponent <HoverContextElement> ();
            if (ele)
            {
                if (state)
                {
                    ele.text = butt.gameObject.name;
                }
                else
                {
                    ele.text = game.disabledDuringWavesText[index];
                }
                HoverContextElement.activeElement = null;
            }
            index++;
        }
        if (game.saveGameMenu.activeSelf)
        {
            game.ToggleSaveGameMenu();
        }
    }
Example #3
0
    public void Init(Inventory.Slot buttonSlot)
    {
        itemImage = GetComponentInChildren<RawImage> ();
        countText = GetComponentInChildren<Text> ();
        slot = buttonSlot;

        element = GetComponent<HoverContextElement> ();
    }
    public void UpdateFlushBattlefieldHoverContextElement()
    {
        HoverContextElement element = flushBattlefieldButton.GetComponent <HoverContextElement> ();

        HoverContextElement.activeElement = null;

        flushBattlefieldSlider.value        = (float)flushTimer / cur.flushTime;
        flushBattlefieldButton.interactable = flushTimer <= 0;

        if (!EnemyManager.waveStarted)
        {
            flushBattlefieldButton.interactable = false;
        }

        if (flushBattlefieldSure)
        {
            element.text = "Are you sure?";
            return;
        }

        if (EnemyManager.waveStarted == true)
        {
            if (cur.flushBattlefieldButton.interactable)
            {
                element.text = "Flush memory\n" + Utility.ConstructDescriptionText("Obliterates all vira on the screen.", 100);
                return;
            }
            else
            {
                element.text = "Flush available in " + flushTimer + " waves";
                return;
            }
        }
        else
        {
            if (flushTimer <= 0)
            {
                element.text = "Not available between waves.";
            }
            else
            {
                element.text = "Flush available in " + flushTimer + " waves";
            }
            return;
        }

        //element.text = "Flush memory";
    }
    void CheckHit(bool raycast, RaycastHit hit)
    {
        if (hit.collider && IsReachable(hit.collider.transform))
        {
            hoveringButton = hit.collider.gameObject;

            HoverContextElement hoverHit = hit.collider.GetComponent <HoverContextElement>();
            // This code might cause cancer, need optimizations if possible. I mean, you might as well just use Rect.Contains ().
            if (HoverContextElement.activeElement == null)
            {
                if (raycast)
                {
                    hit.collider.SendMessage("OnMouseEnterElement", SendMessageOptions.DontRequireReceiver);
                    HoverContextElement.activeElement = hoverHit;
                }
            }
            else
            {
                if (HoverContextElement.activeElement != hoverHit || !raycast)
                {
                    HoverContextElement.activeElement.SendMessage("OnMouseExitElement", SendMessageOptions.DontRequireReceiver);
                    HoverContextElement.activeElement = null;
                }
            }

            if (HoverContextElement.activeElement == hoverHit && Input.GetMouseButtonDown(0))
            {
                hit.collider.SendMessage("OnMouseDownElement", SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (HoverContextElement.activeElement)
        {
            HoverContextElement.activeElement.SendMessage("OnMouseExitElement", SendMessageOptions.DontRequireReceiver);
            HoverContextElement.activeElement = null;
        }
        else if (!PlayerInput.cur.isEditingWalls && !PlayerInput.cur.isPlacing)
        {
            HoverContextElement.activeElement = null;
            ChangeText("");
        }
    }
Example #6
0
    public static void ToggleFastGameSpeed()
    {
        HoverContextElement ele = EnemyManager.cur.waveStartedIndicator.GetComponentInParent <HoverContextElement> ();

        if (ele)
        {
            if (fastGame)
            {
                SetGameSpeed(1f);
                EnemyManager.cur.waveStartedIndicator.color = Color.red;
                ele.text = "Speed up the game";
            }
            else
            {
                SetGameSpeed(2f);
                EnemyManager.cur.waveStartedIndicator.color = Color.magenta;
                ele.text = "Slow down the game";
            }
            HoverContextElement.activeElement = null;
            fastGame = !fastGame;
        }
    }
Example #7
0
 public void UpdateHoverContextElement()
 {
     if (isRoot && Game.currentScene == Scene.Play)
     {
         HoverContextElement el = GetComponent <HoverContextElement> ();
         if (Game.game && PlayerInput.cur.isUpgrading)
         {
             if (IsAssemblyUpgradeable(-1))
             {
                 el.text = "Upgrade Cost: " + GetFullUpgradeCost() + " LoC" +
                           "\n\tLevels - R/D/T: " + GetAssemblyUpgradeLevel(Type.Base) + "/" + GetAssemblyUpgradeLevel(Type.Weapon) + "/" + GetAssemblyUpgradeLevel(Type.Rotator);
             }
             else
             {
                 el.text = "Maxed out";
             }
         }
         else
         {
             el.text = assemblyName + " - " + ((int)GetAssemblyDPS()).ToString() + " DPS";
         }
     }
 }
Example #8
0
    public void UpdateModuleTree()
    {
        if (moduleTreeButtons != null)
        {
            foreach (GameObject obj in moduleTreeButtons)
            {
                Destroy(obj);
            }
        }

        // OpenRangeIndicator ();

        Dictionary <string, int> loc = new Dictionary <string, int>();
        // List<string> indexedNames = new List<string>();
        int count = 0;

        for (int i = 0; i < modules.Count; i++)
        {
            string lName = modules[i].moduleName;

            if (loc.ContainsKey(lName))
            {
                loc[lName]++;
            }
            else
            {
                count++;
                loc.Add(lName, 1);
            }
        }

        moduleTreeButtons = new GameObject[count];
        for (int i = 0; i < count; i++)
        {
            string lName = loc.Keys.ElementAt(i);
            Module m     = PurchaseMenu.cur.GetModulePrefab(lName).GetComponent <Module>();

            GameObject button = (GameObject)Instantiate(treeButtonPrefab, treeButtonParent.position + Vector3.down * buttonSize * i, Quaternion.identity);
            button.transform.SetParent(treeButtonParent, true);

            button.transform.Find("Image").GetComponent <Image>().sprite = m.transform.Find("Sprite").GetComponent <SpriteRenderer>().sprite;
            button.GetComponentInChildren <Text>().text = "x " + loc[lName];

            Button butt = button.GetComponent <Button> ();
            HoverContextElement element = button.GetComponent <HoverContextElement> ();
            if (m.moduleMods.Length == 0)
            {
                butt.interactable = false;
                element.text      = "No mods available";
            }
            else if (GetModulesOfName(lName).Length == 1)
            {
                AddTreeButtonListener(butt, GetModulesOfName(lName)[0], button.transform, true);
                element.text = "Open mods for this module";
            }
            else
            {
                AddTreeButtonListener(button.GetComponent <Button> (), lName);
                element.text = "Open submenu for these modules";
            }

            moduleTreeButtons[i] = button;
        }

        float dist = count * buttonSize + 5;

        treeScrollContext.sizeDelta = new Vector2(subModScrollContext.sizeDelta.x, Mathf.Max(dist, treeScrollParent.sizeDelta.y));
        if (Game.currentScene == Scene.Play)
        {
            UpdateStats();
            UpdateDescText();
        }
    }
 public void ForceUpdate()
 {
     activeElement = null;
 }
Example #10
0
    public GameObject LoadAssembly(Assembly assembly, bool directToWorld = false)
    {
        GameObject modulePrefab = null;
        GameObject rootModule   = null;
        Module     module       = null;
        int        totalCost    = 0;

        // Instantiate, give position and indicies.
        for (int i = 0; i < assembly.parts.Count; i++)
        {
            Assembly.Part part = assembly.parts[i];

            modulePrefab = PurchaseMenu.cur.GetModulePrefab(part.type);
            if (modulePrefab)
            {
                moduleObjects.Add((GameObject)Instantiate(modulePrefab, Vector3.zero, Quaternion.identity));
                //moduleObjects[moduleObjects.Count - 1].SetActive (false);
                moduleObjects[moduleObjects.Count - 1].transform.parent = transform;
                module         = moduleObjects[moduleObjects.Count - 1].GetComponent <Module>();
                module.enabled = false;
                totalCost     += module.moduleCost;
            }
            else
            {
                Debug.LogWarning("Tried to load a non-existing.");
                return(null);
            }

            if (modulePrefab)
            {
                if (part.isRoot)
                {
                    rootModule         = module.gameObject;
                    module.moduleIndex = 1;

                    module.assemblyName = assembly.assemblyName;
                    module.assemblyDesc = assembly.assemblyDesc;
                    module.assembly     = assembly;

                    HoverContextElement el = module.gameObject.AddComponent <HoverContextElement> ();
                    el.isWorldElement = true;
                }

                module.moduleIndex = part.index;
                module.parentIndex = part.parentIndex;

                module.transform.localPosition = new Vector3(part.x, part.y);
                module.transform.eulerAngles   = new Vector3(0, 0, part.angle);

                //rootModule.GetComponent<Module> ().modules.Add (module);
            }
        }

        // Set parents
        foreach (GameObject obj in moduleObjects)
        {
            Module m = obj.GetComponent <Module>();
            if (m.parentIndex != 0)
            {
                m.transform.parent   = FindModuleFromIndex(m.parentIndex).transform;
                m.transform.position = new Vector3(m.transform.position.x,
                                                   m.transform.position.y,
                                                   m.transform.parent.position.z - 1);
            }
            rootModule.GetComponent <Module> ().modules.Add(m);
        }

        // Activate gameObject, but disable module components
        if (!directToWorld)
        {
            PlayerInput.cur.SelectPurchaseable(rootModule, true);
            PlayerInput.cur.SetPurchaseableFromSceneObject(PlayerInput.cur.placementParent.GetChild(0).gameObject);
            PlayerInput.cur.placementParent.GetChild(0).transform.eulerAngles -= new Vector3(0, 0, 90);
            PlayerInput.cur.currentCost = totalCost;
        }
        else
        {
            foreach (GameObject obj in moduleObjects)
            {
                obj.GetComponent <Module> ().enabled = true;
            }
        }

        return(rootModule);
    }
 public void ForceUpdate()
 {
     activeElement = null;
 }