Exemple #1
0
    public void SelectObject(CanInspect _object)
    {
        if (!TryDeselectSelectedObject())
        {
            return;
        }

        SelectedObject = _object.GetComponent <CanInspect>();

        // if something is picked up and a component was clicked, open the secondary info window
        // CanInspect objectToPlace = ObjectPlacing.GetObjectToPlace();
        // if (objectToPlace != null && ((ObjectPlacing.GetObjectToPlace().GetComponent<ComponentObject>() && SelectedObject.GetComponent<ComponentObject>()) || ObjectPlacing.GetObjectToPlace().GetComponent<ComponentHolder>())){
        //  GUIManager.Instance.OpenNewWindow(SelectedObject, CanInspect.State.Default, GUIManager.WindowType.Basic_SecondWindow);
        // }
        // else{// else just open default window
        //  GUIManager.Instance.OpenNewWindow(SelectedObject, CanInspect.State.Default, SelectedObject.Window_Inspector);
        // }
    }
Exemple #2
0
    private void TryGetNewObjectToPlace(CanInspect _newPickedUpObject = null)
    {
        // if (_newPickedUpObject != null) {
        //     if (PickedUpObject != null)
        //         throw new System.Exception("Tried to assign PickedUpObject, but " + PickedUpObject.name + " was already assigned!");

        //     PickedUpObject = _newPickedUpObject;
        // }
        // else if (activeTemporarily) // shouldn't reload UISelectedObject when we're not planning on staying in this tool
        //     return;
        // else if (PickedUpObject == null) {
        //     for (int i = 0; i < ObjectButtons.Length; i++) { // skipping 0 because it's currently the None-button
        //         if (ObjectButtons[i].isOn) {
        //             selectedObjectButtonHasChanged = oldObjectButtonIndex != i;
        //             oldObjectButtonIndex = i;
        //             break;
        //         }
        //     }

        //     // return if didn't actually change object
        //     if (UISelectedObject != null && !selectedObjectButtonHasChanged)
        //         return;

        //     if (UISelectedObject != null) {
        //         GUIManager.Instance.CloseInfoWindow(UISelectedObject);
        //         Object.Destroy(UISelectedObject.gameObject);
        //         UISelectedObject = null;
        //     }

        //  PrefabReference prefabRef = ObjectButtons[oldObjectButtonIndex].GetComponent<PrefabReference>();
        //  if (prefabRef != null){
        //      UISelectedObject = Object.Instantiate(prefabRef.Prefab).GetComponent<CanInspect>();
        //      UISelectedObject.Setup();
        //      SetAssetBottomAndTop(UISelectedObject);
        //  }
        // }

        // CanInspect objectToPlace = GetObjectToPlace();
        // if (objectToPlace != null){
        //  GetObjectToPlace().PickUp();
        // }
    }
Exemple #3
0
    public void CloseInfoWindow(CanInspect _io, int _index = -1)
    {
        if (_index == -1)
        {
            _index = currentInfoWindows.FindIndex(x => x.User == _io);
            if (_index == -1)
            {
                return;
            }
        }

        currentInfoWindows[_index].Window.HideWindow();
        UITrackObject _tracker = currentInfoWindows[_index].Window.GetComponent <UITrackObject>();

        if (_tracker != null)
        {
            _tracker.trackTransform = null;
        }

        //trackedComponent = null;
        currentInfoWindows.RemoveAt(_index);
    }
Exemple #4
0
    public void UpdateButtonGraphics(CanInspect _io)
    {
        int _index = currentInfoWindows.FindIndex(x => x.User == _io);

        if (_index == -1 || currentInfoWindows[_index].Window.UI_ComponentSlots.Length == 0)
        {
            return;
        }

        UIInfoWindow _window = currentInfoWindows[_index].Window;
        Button       _button = null;

        ComponentHolder.ComponentSlot _slot = null;
        for (int i = 0; i < _window.UI_ComponentSlots.Length; i++)
        {
            _button = _window.UI_ComponentSlots[i];
            _slot   = currentComponentHolder.ComponentSlots[i];

            if (_slot.HeldComponent == null)
            {
                _button.GetComponent <Image>().color = Color.black;
                continue;
            }
            if (_slot.HeldComponent._Current_ == 0)
            {
                _button.GetComponent <Image>().color = Color.red;
                continue;
            }
            if (_slot.HeldComponent.TypeID != _slot.SlotTypeID)
            {
                _button.GetComponent <Image>().color = Color.yellow;
                continue;
            }

            // everything's fine
            _button.GetComponent <Image>().color = Color.green;
        }
    }
Exemple #5
0
    public override void UpdateDefault()
    {
        base.UpdateDefault();

        if (Input.GetKeyUp(KeyCode.P))
        {
            Debug.Break();
        }

        // disable UI-stuff
        // for (int i = 0; i < AllButtons.Length; i++) {
        //  AllButtons[i].interactable = (ObjectPlacing.PickedUpObject == null);
        // }

        // for testing purposes only
        if (Input.GetKeyUp(KeyCode.O))
        {
            Character[] _actor = FindObjectsOfType <Character>();
            for (int i = 0; i < _actor.Length; i++)
            {
                _actor[i].enabled = !_actor[i].enabled;
            }
        }

        inspectableInRange = null;
        CanClick _clickable = null;

        for (int i = 0; i < CanClick.AllClickables.Count; i++)
        {
            _clickable = CanClick.AllClickables[i];

            if (!_clickable.Enabled)
            {
                continue;
            }
            if (!_clickable.IsOnGUI && BuildMode != BuildModeEnum.None && BuildMode != BuildModeEnum.PlaceObject)
            {
                continue;
            }
            if (!_clickable.IsOnGUI && IsOverGUI)
            {
                continue;
            }
            if (!_clickable.IsVisible())
            {
                continue;
            }

            if (_clickable.IsMouseWithinRange())
            {
                if (_clickable._OnWithinRange != null)
                {
                    _clickable._OnWithinRange();
                }

                inspectableInRange = _clickable.GetComponent <CanInspect> ();
                break;
            }
        }

        // stop here if no input
        if (StateLMB == StateEnum.Idle && StateRMB == StateEnum.Idle)
        {
            return;
        }

        // left click
        switch (StateLMB)
        {
        case StateEnum.Click:
            return;

        case StateEnum.Hold:
            return;

        case StateEnum.Release:
            // if clicked nothing, with something selected, deselect
            if (inspectableInRange == null && !IsOverGUI)
            {
                TryDeselectSelectedObject();
            }

            // else if clicked something, with something selected, switch selected object
            else if (inspectableInRange != null)
            {
                _clickable.OnLeftClickRelease();

                if (!IsOverGUI)
                {
                    SelectObject(inspectableInRange);
                }
                return;
            }

            return;
        }
        switch (StateRMB)
        {
        case StateEnum.Click:
            return;

        case StateEnum.Hold:
            return;

        case StateEnum.Release:
            if (inspectableInRange != null)
            {
                _clickable.OnRightClickRelease();

                if (!IsOverGUI)                           // picking up stuff on GUI is currently handled by GUI-buttons, so not this
                {
                    if (!(SelectedObject != null && SelectedObject.GetComponent <ComponentHolder>() && _clickable.GetComponent <Component>()))
                    {
                        TryDeselectSelectedObject();
                    }

                    // CanInspect _formerlyPickedUpObject;
                    // ObjectPlacing.TrySwitchComponents (inspectableInRange, inspectableInRange.MyTileObject.Parent, true, /*false, */out _formerlyPickedUpObject);
                }
            }
            return;
        }
    }
Exemple #6
0
 void Awake()
 {
     myRenderer  = GetComponentInChildren <Renderer>();
     myInspector = GetComponent <CanInspect>();
 }
Exemple #7
0
 public override void AwakeDefault()
 {
     myInspector = GetComponent <CanInspect>();
 }
Exemple #8
0
 public override void AwakeDefault()
 {
     Inspectable  = GetComponent <CanInspect>();
     MyTileObject = GetComponent <NodeObject>();
 }
Exemple #9
0
 public void ShowWindow(CanInspect _newIO, ComponentObject _trackedComponent = null)
 {
     ToggleVisible(true, _newIO, _trackedComponent);
 }
Exemple #10
0
    //public void ToggleWindow(InteractiveObject _io, InteractiveObject.State _state, WindowType _type) { // currently only support for 1 window, but maybe more later?
    //    if (currentInfoWindow != null && currentInfoWindow.OwnerIO == _io)
    //        CloseCurrentInfoWindow();
    //    else
    //        OpenNewWindow(_io, _state, _type);
    //}

    public void OpenNewWindow(CanInspect _inspectable, CanInspect.State _state, WindowType _type)
    {
        int          _index         = currentInfoWindows.FindIndex(x => x.User == _inspectable);
        UIInfoWindow _currentWindow = null;

        if (_index > -1)
        {
            _currentWindow = currentInfoWindows[_index].Window;

            if (_currentWindow.OwnerInspectable == _inspectable)
            {
                if (_state != _currentWindow.State)
                {
                    _currentWindow.ChangeState(_state);
                }

                return;
            }

            CloseInfoWindow(_inspectable, _index); // not sure if needed
        }

        switch (_type)
        {
        case WindowType.Basic:
            _currentWindow = ComponentWindow_Main;
            break;

        case WindowType.Basic_SecondWindow:
            _currentWindow = ComponentWindow_Sub;
            break;

        case WindowType.ComponentHolder_x6:
            _currentWindow = ComponentHolderWindow_x6;
            break;

        case WindowType.ComponentHolder_x9:
            _currentWindow = ComponentHolderWindow_x9;
            break;

        case WindowType.ComponentHolder_15:
            _currentWindow = ComponentHolderWindow_x15;
            break;

        case WindowType.ComponentHolder_x24:
            _currentWindow = ComponentHolderWindow_x24;
            break;
        }

        // make sure no on else is using this window
        for (int i = 0; i < currentInfoWindows.Count; i++)
        {
            if (currentInfoWindows [i].Window == _currentWindow)
            {
                CloseInfoWindow(currentInfoWindows[i].User, i);
            }
        }

        ComponentObject _trackedComponent = null;

        switch (_type)
        {
        case WindowType.Basic:
        case WindowType.Basic_SecondWindow:
            _trackedComponent = _inspectable.GetComponent <ComponentObject>();
            break;

        case WindowType.ComponentHolder_x6:
        case WindowType.ComponentHolder_x9:
        case WindowType.ComponentHolder_15:
        case WindowType.ComponentHolder_x24:
            currentComponentHolder = _inspectable.GetComponent <ComponentHolder>();

            // set button-names to be the same as in the component-slots
            ComponentObject.ComponentType _compType;
            int _compTypeID;
            for (int i = 0; i < _currentWindow.Buttons.Length; i++)
            {
                _compType   = currentComponentHolder.ComponentSlots[i].SlotType;
                _compTypeID = currentComponentHolder.ComponentSlots[i].SlotTypeID;
                _currentWindow.Buttons[i].GetComponentInChildren <Text>().text = ComponentInfoManager.Instance.AllComponentsInfo[_compType][_compTypeID].Name;
            }
            break;
        }

        _currentWindow.UI_Image.sprite = _inspectable.Selected_Sprite;
        _currentWindow.UI_Name.text    = _inspectable.Selected_Name;
        _currentWindow.UI_Desc.text    = _inspectable.Selected_Desc;

        UITrackObject _tracker = _currentWindow.GetComponent <UITrackObject>();

        if (_tracker != null)
        {
            _tracker.trackTransform = _inspectable.transform;
        }

        _currentWindow.ChangeState(_state);
        _currentWindow.ShowWindow(_inspectable, _trackedComponent);
        currentInfoWindows.Add(new InfoWindowUser(_currentWindow, _inspectable));

        UpdateButtonGraphics(_inspectable);
    }
Exemple #11
0
 public InfoWindowUser(UIInfoWindow _window, CanInspect _inspectable)
 {
     Window = _window;
     User   = _inspectable;
 }