Exemple #1
0
    // Select people in rect
    public void SelectPeople(Rect selection)
    {
        if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
        {
            PersonScript.DeselectAll();
        }

        foreach (PersonScript ps in PersonScript.allPeople)
        {
            Vector3 pos = Camera.main.WorldToScreenPoint(ps.transform.position);
            if (selection.Contains(new Vector2(pos.x, pos.y)))
            {
                ps.OnSelect();
            }
        }
    }
Exemple #2
0
    // update selection
    private void SelectUnits()
    {
        // only update if not building and pointer is not over a UI Element
        if (EventSystem.current.IsPointerOverGameObject() ||
            BuildManager.placing)
        {
            LeftClickHandled = true;
        }

        if (Input.GetMouseButtonDown(0) && !LeftClickHandled)
        {
            // mouse click is handled
            LeftClickHandled = true;

            dragging = true;

            // set start position of drag
            startPos = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0) && dragging)
        {
            dragging = false;
            // if selection box is too small, just select highlighted person
            if (selection.width * selection.height >= 100)
            {
                SelectPeople(selection);
            }
            else
            {
                // only deselect units if shift-key is not hold
                if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
                {
                    PersonScript.DeselectAll();
                }
                foreach (PersonScript ps in PersonScript.allPeople)
                {
                    if (ps.highlighted)
                    {
                        ps.OnClick();
                    }
                }
            }

            // make the selectio nsquare invisible
            selectionBoxImage.gameObject.SetActive(false);
        }
        if (Input.GetMouseButton(0) && dragging)
        {
            // make the selection square visible
            if (!selectionBoxImage.gameObject.activeInHierarchy)
            {
                selectionBoxImage.gameObject.SetActive(true);
            }
            endPos = Input.mousePosition;

            // make sure the rect has non-negative size
            selection.xMin = startPos.x < endPos.x ? startPos.x : endPos.x;
            selection.xMax = startPos.x < endPos.x ? endPos.x : startPos.x;
            selection.yMin = startPos.y < endPos.y ? startPos.y : endPos.y;
            selection.yMax = startPos.y < endPos.y ? endPos.y : startPos.y;

            // set the selection square rectTransform
            selectionBoxImage.offsetMin = selection.min;
            selectionBoxImage.offsetMax = selection.max;
        }
    }
Exemple #3
0
    void LateUpdate()
    {
        // exit ui and building mode
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (BuildManager.placing)
            {
                BuildManager.EndPlacing();
            }
            else if (ChatManager.IsChatActive())
            {
                ChatManager.ToggleChat();
            }
            else
            {
                if (uiManager.InMenu())
                {
                    uiManager.ExitMenu();
                }
                else if (uiManager.HideObjectInfo())
                {
                }
                else if (uiManager.HidePersonInfo())
                {
                }
                else
                {
                    uiManager.ShowMenu(6);
                }
            }
        }

        if (!ChatManager.IsChatActive())
        {
            // open build menu if exactly one person is selected
            if (Input.GetKeyDown(KeyCode.B))
            {
                if (PersonScript.selectedPeople.Count == 1)
                {
                    uiManager.ShowMenu(7);
                }
            }

            // open job overview if no person selected
            if (Input.GetKeyDown(KeyCode.J))
            {
                if (PersonScript.selectedPeople.Count == 0)
                {
                    uiManager.ShowMenu(1);
                    uiManager.OnPopulationTab(1);
                }
            }

            // open minimap overview
            if (Input.GetKeyDown(KeyCode.M))
            {
                uiManager.ToggleMiniMap();
            }

            BuildingScript selb = uiManager.GetSelectedBuilding();
            // destroy building if selected
            if (Input.GetKeyDown(KeyCode.Period))
            {
                if (selb && !BuildManager.placing)
                {
                    /* TODO: show warning when destroying buildings */
                    //selb.DestroyBuilding();
                }
            }
            // move building if selected
            if (Input.GetKeyDown(KeyCode.Comma))
            {
                if (selb && !BuildManager.placing)
                {
                    BuildManager.StartMoving(selb);
                }
            }

            // Toggle Cheats
            if (Input.GetKeyDown(KeyCode.O))
            {
                GameManager.ToggleDebugging();
                ChatManager.Msg("Cheats " + (GameManager.IsDebugging() ? "aktiviert" : "deaktiviert"), MessageType.Debug);
            }

            // Toggle Deubg window
            if (Input.GetKeyDown(KeyCode.P))
            {
                UIManager.Instance.ShowMenu(10);
            }

            // Person Groups
            int numberInput = -1;
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                numberInput = 0;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                numberInput = 1;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                numberInput = 2;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                numberInput = 3;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                numberInput = 4;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                numberInput = 5;
            }
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                numberInput = 6;
            }
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                numberInput = 7;
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                numberInput = 8;
            }
            if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                numberInput = 9;
            }

            if (numberInput >= 0)
            {
                List <int> group = GameManager.GetPeopleGroup(numberInput);
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    group = new List <int>();
                    foreach (PersonScript ps in PersonScript.selectedPeople)
                    {
                        group.Add(ps.Nr);
                    }
                    GameManager.SetPeopleGroup(numberInput, group);
                    ChatManager.Msg("Personengruppe " + numberInput + " erstellt!");
                }
                else
                {
                    PersonScript.DeselectAll();
                    if (group != null)
                    {
                        foreach (PersonScript ps in PersonScript.allPeople)
                        {
                            if (group.Contains(ps.Nr))
                            {
                                ps.OnSelect();
                            }
                        }
                    }
                }
            }
        }
        // enter chat
        if (!IsInputFieldFocused() && Input.GetKeyDown(KeyCode.Return))
        {
            ChatManager.CommitMsg();
            ChatManager.ToggleChat();
        }

        // if click is not already handled, select units
        SelectUnits();

        LeftClickHandled  = false;
        RightClickHandled = false;
    }