public override void OnPhysicsRaycast(RaycastHit hit, Vector3 transformedPoint) { previousHit = hit; transformed = transformedPoint; CalculateTimes(hit, out _, out float realTime, out _, out _, out _); Vector3 position = hit.point; if (!IsSelecting) { SelectedTypes.Clear(); if (hit.transform.GetComponentInParent <EventPlacement>()) { SelectedTypes.Add(BeatmapObject.Type.EVENT); } if (hit.transform.GetComponentInParent <NotePlacement>()) { SelectedTypes.Add(BeatmapObject.Type.NOTE); } if (hit.transform.GetComponentInParent <ObstaclePlacement>()) { SelectedTypes.Add(BeatmapObject.Type.OBSTACLE); } if (hit.transform.GetComponentInParent <CustomEventPlacement>()) { SelectedTypes.Add(BeatmapObject.Type.CUSTOM_EVENT); } instantiatedContainer.transform.localScale = Vector3.one; Vector3 localScale = instantiatedContainer.transform.localScale; startTime = realTime; position = new Vector3(position.x, position.y, (startTime - atsc.CurrentBeat) * EditorScaleController.EditorScale); instantiatedContainer.transform.position = position; instantiatedContainer.transform.localPosition -= new Vector3(localScale.x / 2, 0, localScale.z / 2); } else { instantiatedContainer.transform.localPosition = originPos; Vector3 instantiatedSpacePosition = instantiatedContainer.transform.parent.InverseTransformPoint(hit.point); Vector3 newLocalScale = instantiatedSpacePosition - originPos; newLocalScale = new Vector3(newLocalScale.x, Mathf.Max(newLocalScale.y, 1), newLocalScale.z); instantiatedContainer.transform.localScale = newLocalScale; selected.Clear(); OverlapBox((containerBoye) => { if (!alreadySelected.Contains(containerBoye) && !selected.Contains(containerBoye)) { selected.Add(containerBoye); SelectionController.Select(containerBoye, true, false, false); } }); SelectionController.RefreshSelectionMaterial(false); foreach (BeatmapObjectContainer combinedObj in new HashSet <BeatmapObjectContainer>(SelectionController.SelectedObjects)) { if (!selected.Contains(combinedObj) && !alreadySelected.Contains(combinedObj)) { SelectionController.Deselect(combinedObj); } } } }
/// <summary> /// Deletes a <see cref="BeatmapObject"/>. /// </summary> /// <param name="obj">To delete.</param> /// <param name="triggersAction">Whether or not it triggers a <see cref="BeatmapObjectDeletionAction"/></param> /// <param name="refreshesPool">Whether or not the pool will be refreshed as a result of this deletion.</param> /// <param name="comment">A comment that provides further description on why it was deleted.</param> public void DeleteObject(BeatmapObject obj, bool triggersAction = true, bool refreshesPool = true, string comment = "No comment.") { var removed = UnsortedObjects.Remove(obj); var removed2 = LoadedObjects.Remove(obj); if (removed && removed2) { //Debug.Log($"Deleting container with hash code {toDelete.GetHashCode()}"); SelectionController.Deselect(obj, triggersAction); if (triggersAction) { BeatmapActionContainer.AddAction(new BeatmapObjectDeletionAction(obj, comment)); } RecycleContainer(obj); if (refreshesPool) { RefreshPool(); } OnObjectDelete(obj); } else { // The objects are not in the collection, but are still being removed. // This could be because of ghost blocks, so let's try forcefully recycling that container. Debug.LogError($"Object could not be deleted, please report this ({removed}, {removed2})"); } }
internal virtual void OnMouseOver() { if (KeybindsController.CtrlHeld && Input.GetMouseButton(0)) { if (!SelectionController.IsObjectSelected(this)) { SelectionController.Select(this, true); } } if (!KeybindsController.ShiftHeld) { return; } if (Input.GetMouseButtonDown(0)) { //Selects if it's not already selected, deselect if it is. if (SelectionController.IsObjectSelected(this)) { SelectionController.Deselect(this); } else { SelectionController.Select(this, true); } } else if (Input.GetMouseButtonDown(2)) { FlaggedForDeletionEvent?.Invoke(this); } }
private void OnDestroy() { if (SelectionController.IsObjectSelected(this)) { SelectionController.Deselect(this); } }
public void OnSelectObjects(InputAction.CallbackContext context) { if (customStandaloneInputModule.IsPointerOverGameObject <GraphicRaycaster>(-1, true) || ObstaclePlacement.IsPlacing) { return; } isSelecting = context.performed; if (context.performed) { timeWhenFirstSelecting = Time.time; RaycastFirstObject(out T firstObject); if (firstObject == null) { return; } BeatmapObject obj = firstObject.objectData; if (massSelect && SelectionController.SelectedObjects.Count() == 1 && SelectionController.SelectedObjects.First() != obj) { SelectionController.SelectBetween(SelectionController.SelectedObjects.First(), obj, true); } else if (SelectionController.IsObjectSelected(obj)) { SelectionController.Deselect(obj); firstObject.SelectionStateChanged = true; } else if (!SelectionController.IsObjectSelected(obj)) { SelectionController.Select(obj, true); firstObject.SelectionStateChanged = true; } } }
public override void CancelPlacement() { IsSelecting = false; foreach (BeatmapObjectContainer selectedObject in selected) { SelectionController.Deselect(selectedObject); } }
private void Update() { /* * While this may be a copy of PlacementController code and BeatmapObjectContainer selecting, this is actually to help * select objects that are under the placement grid (such as walls) */ if (KeybindsController.ShiftHeld && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(2))) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, 999f, 1 << 11)) { if (Physics.Raycast(ray, out _, hit.distance, 1 << 9)) { return; //Do not select under grid if something is already selected. } Ray gridRay = new Ray(hit.point, ray.direction); if (Physics.Raycast(gridRay, out RaycastHit gridHit, 999f, 1 << 9)) { BeatmapObjectContainer con = gridHit.transform.gameObject.GetComponent <BeatmapObjectContainer>(); if (con is null) { return; } if (Input.GetMouseButtonDown(0)) { if (SelectionController.IsObjectSelected(con)) { SelectionController.Deselect(con); } else { SelectionController.Select(con, true); } } else if (Input.GetMouseButtonDown(2)) { BeatmapObjectContainer.FlaggedForDeletionEvent?.Invoke(con); } } } } }
public override void Redo(BeatmapActionContainer.BeatmapActionParams param) { if (_originalObject != _editedObject || _editedData._time.CompareTo(_originalData._time) != 0) { _collection.DeleteObject(_originalObject, false, false); SelectionController.Deselect(_originalObject, false); _editedObject.Apply(_editedData); _collection.SpawnObject(_editedObject, false, !InCollection); } else { // This is an optimisation only possible if the object has not changed position in the SortedSet _editedObject.Apply(_editedData); if (!InCollection) { RefreshPools(Data); } } SelectionController.Select(_editedObject, _addToSelection, true, !InCollection); }
public void OnSelectObjects(InputAction.CallbackContext context) { if (customStandaloneInputModule.IsPointerOverGameObject <GraphicRaycaster>(-1, true)) { return; } isSelecting = context.performed; if (context.performed) { RaycastFirstObject(out T firstObject); if (firstObject != null && SelectionController.IsObjectSelected(firstObject)) { SelectionController.Deselect(firstObject); firstObject.SelectionStateChanged = true; } else if (firstObject != null && !SelectionController.IsObjectSelected(firstObject)) { SelectionController.Select(firstObject, true); firstObject.SelectionStateChanged = true; } timeWhenFirstSelecting = Time.time; } }
private void SelectOrDeselect <T>(T container) where T : BeatmapObjectContainer { if (SelectionController.HasSelectedObjects() && Input.GetKey(KeyCode.LeftControl)) { if (SelectionController.SelectedObjects.Last().objectData.beatmapType == container.objectData.beatmapType && container.objectData._time >= SelectionController.SelectedObjects.Last().objectData._time) { SelectionController.MassSelect(SelectionController.SelectedObjects.Last(), container, Input.GetKey(KeyCode.LeftShift)); return; } } if (!Input.GetKey(KeyCode.LeftShift)) { return; } if (SelectionController.IsObjectSelected(container)) //Shift Right-Click on a selected object will deselect. { SelectionController.Deselect(container); } else //Else it will try to select again. { SelectionController.Select(container, Input.GetKey(KeyCode.LeftShift)); } }
void Update() { if (Input.GetKey(KeyCode.LeftAlt)) { return; } BaseButtonInputs(); if (Input.GetKeyDown(KeyCode.F)) { myCamera.Focus(selectionController.selectionPivot.position); } RaycastHit hit; ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (slotManager.selectedSlot.slotInfo.itemType != ItemType.move || selectionController.selectedList.Count == 0) { selectionController.controlPoint.gameObject.SetActive(false); } else { selectionController.controlPoint.gameObject.SetActive(true); } if (Physics.Raycast(ray, out hit, Mathf.Infinity, buttonMask)) { switch (slotManager.selectedSlot.slotInfo.itemType) { case ItemType.block: if (Input.GetMouseButtonUp(0)) { blockController.Do(hit); } break; case ItemType.axe: if (Input.GetMouseButtonUp(0)) { //if it is selected, remove from lists if (selectionController.selectedDict.ContainsKey(hit.transform)) { selectionController.Deselect(hit.transform); } Destroy(hit.transform.parent.gameObject); } break; case ItemType.paintBucket: if (Input.GetMouseButton(0)) { paintManager.Paint(hit.transform.GetComponent <FaceButton>(), ColorPickerController.singletonInstance.GetSelectedColor()); } break; case ItemType.select: case ItemType.move: if (hit.transform.tag == "EditHandle") { break; } if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0)) { selectionController.OnSelect(hit); } else { if (Input.GetMouseButtonDown(0)) { selectionController.OnDeselectAll(); selectionController.OnSelect(hit); } } break; } } else { if (Input.GetMouseButtonDown(0)) { selectionController.OnDeselectAll(); } } }
public void HandlePathFindingInput(Vector3 blockCenter, int3 block) { if (!didStartPathFinding) { didStartPathFinding = true; Vector3 pos = Utils.CentrifyPosition(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z)); currentPathFinding = new PathFinding(pos, blockCenter); if (isOnManualPathFinding) { var moves = currentPathFinding.OpenPossibleNewMoves(pos); RemoveFromBlocksUIIfExists(moves); foreach (var node in moves) { var bUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(pos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(blockCenter), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } else { StartCoroutine(currentPathFinding.BuildPathToTarget(() => { if (currentPathFinding.isClosed) { foreach (var bbbUI in blocksUI) { GameObject.Destroy(bbbUI.gameObject); } foreach (var node in currentPathFinding.pathNodes) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } else { var poppedBottom = currentBlockDestroying.PopBottomBlock(); selectionController.Deselect(); aiState.mode = AIStateMode.Idle; currentBlockDestroying.UpdateDestroyBlockQueueUI(); } })); } } else if (blocksUI.Find(b => b.pos.Equals(blockCenter)) != null) { var n = currentPathFinding.SuggestNextNode(); var bUI = blocksUI.Find(b => b.pos.Equals(n.pos)); bUI.ToggleSelection(); var moves = currentPathFinding.OpenPossibleNewMoves(bUI.pos, n); RemoveFromBlocksUIIfExists(moves); foreach (var node in moves) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } if (currentPathFinding.CheckIfEnd(n)) { foreach (var bbbUI in blocksUI) { GameObject.Destroy(bbbUI.gameObject); } foreach (var node in currentPathFinding.pathNodes) { var bbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(node.pos), int3.zero, String.Format("{0}\n{1}\n{2}", node.startValue, node.value, node.endValue)); blocksUI.Add(bbUI); } var sbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.startPos), int3.zero, "Start"); sbUI.ToggleSelection(); blocksUI.Add(sbUI); var fbUI = BlockUI.Create(Utils.WorldBlockPosForCenter(currentPathFinding.endPos), int3.zero, "Finish"); fbUI.ToggleSelection(); blocksUI.Add(fbUI); } } else { didStartPathFinding = false; foreach (var bUI in blocksUI) { GameObject.Destroy(bUI.gameObject); } blocksUI = new List <BlockUI>(); } }
public override void OnPhysicsRaycast(RaycastHit hit, Vector3 transformedPoint) { //this mess of localposition and position assignments are to align the shits up with the grid //and to hopefully not cause IndexOutOfRangeExceptions instantiatedContainer.transform.localPosition = parentTrack.InverseTransformPoint(hit.point); //f**k transformedpoint we're doing it ourselves Vector3 localMax = parentTrack.InverseTransformPoint(hit.collider.bounds.max); Vector3 localMin = parentTrack.InverseTransformPoint(hit.collider.bounds.min); float farRightPoint = localMax.x; float farLeftPoint = localMin.x; float farTopPoint = localMax.y; float farBottomPoint = localMin.y; Vector3 roundedHit = parentTrack.InverseTransformPoint(hit.point); roundedHit = new Vector3(Mathf.Ceil(roundedHit.x), Mathf.Ceil(roundedHit.y), roundedHit.z); instantiatedContainer.transform.localPosition = roundedHit - new Vector3(0.5f, 1, 0); float x = instantiatedContainer.transform.localPosition.x; //Clamp values to prevent exceptions float y = instantiatedContainer.transform.localPosition.y; CalculateTimes(hit, out _, out float realTime, out _, out _, out float offset); instantiatedContainer.transform.localPosition = new Vector3( Mathf.Clamp(x, farLeftPoint + 0.5f, farRightPoint - 0.5f), Mathf.Clamp(y, 0, farTopPoint), instantiatedContainer.transform.localPosition.z); previousHit = hit; transformed = transformedPoint; if (!IsSelecting) { SelectedTypes.Clear(); if (hit.transform.GetComponentInParent <EventPlacement>()) { SelectedTypes.Add(BeatmapObject.Type.EVENT); } if (hit.transform.GetComponentInParent <NotePlacement>()) { SelectedTypes.Add(BeatmapObject.Type.NOTE); } if (hit.transform.GetComponentInParent <ObstaclePlacement>()) { SelectedTypes.Add(BeatmapObject.Type.OBSTACLE); } if (hit.transform.GetComponentInParent <CustomEventPlacement>()) { SelectedTypes.Add(BeatmapObject.Type.CUSTOM_EVENT); } instantiatedContainer.transform.localScale = Vector3.one; Vector3 localScale = instantiatedContainer.transform.localScale; startTime = realTime; Vector3 localpos = instantiatedContainer.transform.localPosition; instantiatedContainer.transform.localPosition -= new Vector3(localScale.x / 2, 0, localScale.z / 2); } else { instantiatedContainer.transform.localPosition = originPos; Vector3 newLocalScale = roundedHit + new Vector3(0, 0, 0.5f) - originPos; newLocalScale = new Vector3(newLocalScale.x, Mathf.Max(newLocalScale.y, 1), newLocalScale.z); instantiatedContainer.transform.localScale = newLocalScale; selected.Clear(); OverlapBox((containerBoye) => { if (!alreadySelected.Contains(containerBoye) && !selected.Contains(containerBoye)) { selected.Add(containerBoye); SelectionController.Select(containerBoye, true, false, false); } }); SelectionController.RefreshSelectionMaterial(false); foreach (BeatmapObjectContainer combinedObj in new HashSet <BeatmapObjectContainer>(SelectionController.SelectedObjects)) { if (!selected.Contains(combinedObj) && !alreadySelected.Contains(combinedObj)) { SelectionController.Deselect(combinedObj); } } selected.Clear(); } }
public override void OnPhysicsRaycast(RaycastHit hit, Vector3 transformedPoint) { previousHit = hit; transformed = transformedPoint; Vector3 roundedHit = parentTrack.InverseTransformPoint(hit.point); roundedHit = new Vector3( Mathf.Ceil(Math.Min(Math.Max(roundedHit.x, bounds.min.x + 0.01f), bounds.max.x)), Mathf.Ceil(Math.Min(Math.Max(roundedHit.y, 0.01f), 3f)), roundedHit.z ); instantiatedContainer.transform.localPosition = roundedHit - new Vector3(0.5f, 1, 0); if (!IsSelecting) { bounds = default; SelectedTypes.Clear(); TestForType <EventPlacement>(hit, BeatmapObject.Type.EVENT); TestForType <NotePlacement>(hit, BeatmapObject.Type.NOTE); TestForType <ObstaclePlacement>(hit, BeatmapObject.Type.OBSTACLE); TestForType <CustomEventPlacement>(hit, BeatmapObject.Type.CUSTOM_EVENT); TestForType <BPMChangePlacement>(hit, BeatmapObject.Type.BPM_CHANGE); instantiatedContainer.transform.localScale = Vector3.right + Vector3.up; Vector3 localScale = instantiatedContainer.transform.localScale; Vector3 localpos = instantiatedContainer.transform.localPosition; instantiatedContainer.transform.localPosition -= new Vector3(localScale.x / 2, 0, 0); } else { Vector3 originShove = originPos; float xOffset = 0; float yOffset = 0; // When moving from right to left, move the origin to the right and make // the selection larger as the origin points are on the left if (roundedHit.x <= originPos.x + 1) { xOffset = -1; originShove.x += 1; } if (roundedHit.y <= originPos.y) { yOffset = -1; originShove.y += 1; } instantiatedContainer.transform.localPosition = originShove; Vector3 newLocalScale = roundedHit + new Vector3(xOffset, yOffset, 0.5f) - originShove; float newLocalScaleY = Mathf.Max(newLocalScale.y, 1); if (yOffset < 0) { newLocalScaleY = Mathf.Min(-1, newLocalScale.y); } newLocalScale = new Vector3(newLocalScale.x, newLocalScaleY, newLocalScale.z); instantiatedContainer.transform.localScale = newLocalScale; float startBeat = instantiatedContainer.transform.localPosition.z / EditorScaleController.EditorScale; float endBeat = (instantiatedContainer.transform.localPosition.z + newLocalScale.z) / EditorScaleController.EditorScale; if (startBeat > endBeat) { (startBeat, endBeat) = (endBeat, startBeat); } SelectionController.ForEachObjectBetweenTimeByGroup(startBeat, endBeat, true, true, true, (bocc, bo) => { if (!SelectedTypes.Contains(bo.beatmapType)) { return; // Must be a type we can select } var left = instantiatedContainer.transform.localPosition.x + instantiatedContainer.transform.localScale.x; var right = instantiatedContainer.transform.localPosition.x; if (right < left) { (left, right) = (right, left); } var top = instantiatedContainer.transform.localPosition.y + instantiatedContainer.transform.localScale.y; var bottom = instantiatedContainer.transform.localPosition.y; if (top < bottom) { (top, bottom) = (bottom, top); } var p = new Vector2(left, bottom); if (bo is IBeatmapObjectBounds obj) { p = obj.GetCenter(); } else if (bo is MapEvent evt) { var position = evt.GetPosition(labels, eventsContainer.PropagationEditing, eventsContainer.EventTypeToPropagate); // Not visible = notselectable if (position == null) { return; } p = new Vector2(position?.x + bounds.min.x ?? 0, position?.y ?? 0); } else if (bo is BeatmapCustomEvent custom) { p = new Vector2(customCollection.CustomEventTypes.IndexOf(custom._type) + bounds.min.x + 0.5f, 0.5f); } // Check if calculated position is outside bounds if (p.x < left || p.x > right || p.y < bottom || p.y >= top) { return; } if (!alreadySelected.Contains(bo) && selected.Add(bo)) { SelectionController.Select(bo, true, false, false); } }); foreach (BeatmapObject combinedObj in SelectionController.SelectedObjects.ToArray()) { if (!selected.Contains(combinedObj) && !alreadySelected.Contains(combinedObj)) { //Id imagine if you select an object, and that object is unloaded, then it should stay selected...? if (BeatmapObjectContainerCollection.GetCollectionForType(combinedObj.beatmapType).LoadedContainers.ContainsKey(combinedObj)) { SelectionController.Deselect(combinedObj, false); } } } selected.Clear(); } }
void Update() { bool buildValue = inputManager.BuildValue; bool destroyValue = inputManager.DestroyValue; if (inventory.isInventoryUIVisible) { return; } RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward, out hitInfo, maxDist, groundLayer)) { if (destroyValue && destroyValue == lastDestroyValue) { return; } if (buildValue && buildValue == lastBuildValue) { return; } Vector3 pointInTargetBlock; //destroy if (destroyValue) { pointInTargetBlock = hitInfo.point + transform.forward * .01f; } else if (buildValue || Input.GetKey(KeyCode.LeftShift)) { pointInTargetBlock = hitInfo.point - transform.forward * .01f; } else { pointInTargetBlock = hitInfo.point + transform.forward * .01f; } int4 chunkPos = Utils.ChunkPosbyPosition(pointInTargetBlock); Chunk chunk = WorldSettings.Chunks[chunkPos]; var coord = Utils.CoordByPosition(pointInTargetBlock); int index = Utils.to1D(coord); var block = chunk.blocks[index]; var blockPos = Utils.WorldBlockPosition(coord, chunkPos); selectionController.SelectBlockAt(block, blockPos); if (destroyValue) { if (chunk.CanDestroyBlockAt(index)) { player.aIController.AddOrRemoveBlock(blockPos, block); } } else if (buildValue) { if (inventory.HasSelectedItem() && !CheckIfPlayerIsOnIndex(coord)) { Item selectedItem = inventory.GetSelectedItem(); Block?newBlock = Item.GetWoldBLock(selectedItem.type, selectedItem.level); if (newBlock != null && chunk.BuildBlock(newBlock.Value, index)) { inventory.ReduceSelectedBlockAmount(); } } } } else { selectionController.Deselect(); } lastBuildValue = buildValue; lastDestroyValue = destroyValue; }