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); // } }
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; } }
//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); }