public TestSceneComposeSelectBox() { SelectionBox selectionBox = null; AddStep("create box", () => Child = selectionArea = new Container { Size = new Vector2(400), Position = -new Vector2(150), Anchor = Anchor.Centre, Children = new Drawable[] { selectionBox = new SelectionBox { CanRotate = true, CanScaleX = true, CanScaleY = true, OnRotation = handleRotation, OnScale = handleScale } } }); AddToggleStep("toggle rotation", state => selectionBox.CanRotate = state); AddToggleStep("toggle x", state => selectionBox.CanScaleX = state); AddToggleStep("toggle y", state => selectionBox.CanScaleY = state); }
void Update() { if (SelectionBox != null) { SelectionBox.SetActive(IsSelected); } if (Task != null && Task.IsComplete) { Task = null; } if (this.UseMouseLeftRelease()) { if (this.IsPointedAt()) { if (Scene.Main.UnitInterface.Unit == null || !Scene.Main.UnitInterface.Unit.IsPointedAt() || (this.HasComponent <Motile>() && !Scene.Main.UnitInterface.Unit.HasComponent <Motile>())) { Scene.Main.UnitInterface.Unit = this; } } } }
void UnitSelection() { RaycastHit unitHit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out unitHit, 1000.0f, unitLayerMask)) { if (selectedUnit == null) { selectedUnit = unitHit.collider.gameObject; if (SelectedUnit.gameObject.GetComponent <UnitStats>().isRed == ScriptLink.flowController.IsRedTurn) { ScriptLink.unitMenuControl.HideUnitMenus(); ScriptLink.preDefinedActionTileSpawning.MovementTilesWithAttackRange(); busyWithAllyUnit = true; SelectionBox.GetComponent <SpriteRenderer>().sprite = selectionBoxBlue; } else { selectedUnit = null; } } else { GameObject oldSelection = SelectedUnit; selectedUnit = unitHit.collider.gameObject; if (oldSelection.gameObject.GetComponent <UnitStats>().isRed != ScriptLink.flowController.IsRedTurn) //This is keeping sure that we can't select enemy pieces { selectedUnit = oldSelection; } } } }
static public void AddSelectionBox(MenuCommand menuCommand) { var go = CreateNewUI(); go.name = "Selection Box"; GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject); RectTransform rect = go.transform as RectTransform; rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.anchoredPosition = Vector2.zero; rect.sizeDelta = Vector2.zero; Image image = go.AddComponent <Image>(); image.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kBackgroundSpriteResourcePath); image.type = Image.Type.Sliced; image.fillCenter = false; image.color = new Color(1f, 1f, 1f, 0.392f); SelectionBox selectableArea = go.AddComponent <SelectionBox>(); selectableArea.selectionMask = rect; selectableArea.color = new Color(0.816f, 0.816f, 0.816f, 0.353f); GameObject childSelectableItem = CreateUIObject("Selectable", go); childSelectableItem.AddComponent <Image>(); childSelectableItem.AddComponent <ExampleSelectable>(); Selection.activeGameObject = go; }
public static void MouseDrag(SelectionBox box) { if (OnMouseDrag != null) { OnMouseDrag(box); } }
/// <summary> /// Title screen constructor. /// </summary> public OptionsScreen(GameMain parent) { _list = new ComponentList(); SelectionBox resolution = new SelectionBox("Resolution"); resolution.AddOption("800x600"); resolution.AddOption("1280x720"); resolution.AddOption("1920x1080"); resolution.SelectOption(OptionsManager.CurrentOptions.ResolutionWidth + "x" + OptionsManager.CurrentOptions.ResolutionHeight); _list.AddComponent(resolution); SelectionBox fullscreen = new SelectionBox("Fullscreen"); fullscreen.AddOption("On"); fullscreen.AddOption("Off"); fullscreen.SelectOption(OptionsManager.CurrentOptions.Fullscreen ? "On" : "Off"); _list.AddComponent(fullscreen); SelectionBox inverted = new SelectionBox("Inverted Aim"); inverted.AddOption("On"); inverted.AddOption("Off"); inverted.SelectOption(OptionsManager.CurrentOptions.InvertAim ? "On" : "Off"); _list.AddComponent(inverted); _list.ValueChanged += new ValueChangeDelegate(() => { string res = _list.GetValue("Resolution"); string ful = _list.GetValue("Fullscreen"); string aim = _list.GetValue("Inverted Aim"); OptionsManager.CurrentOptions.ResolutionWidth = Convert.ToInt32(res.Split('x')[0]); OptionsManager.CurrentOptions.ResolutionHeight = Convert.ToInt32(res.Split('x')[1]); OptionsManager.CurrentOptions.Fullscreen = (ful == "On"); OptionsManager.CurrentOptions.InvertAim = (aim == "On"); }); _list.AddComponent(new Button("Delete All Save Data", new SelectDelegate(() => { GameStateManager.DeleteAllSaves(); }))); _list.AddComponent(new Button("Save", new SelectDelegate(() => { OptionsManager.SaveOptions(); _parent.ChangeState(GameState.MainMenu); }))); _list.AddComponent(new Button("Cancel", new SelectDelegate(() => { OptionsManager.LoadOptions(); _parent.ChangeState(GameState.MainMenu); }))); _window = Rectangle.Empty; _parent = parent; }
/// <summary> /// OnMouseMove /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderControl_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // If user resized the selectionbox, then resize the element if (SelectionBox.OnMouseMove(e)) { CurrentElement.Rectangle = SelectionBox.Rectangle; } }
/// <summary> /// Select colliders inside provided box /// </summary> /// <param name="box">Box provides attributes for Physics OverlapBox to determine overlapping colliders</param> private void UpdateUnitSelections(SelectionBox box) { Collider[] overlappingObjects = Physics.OverlapBox(box.Center, box.Extents, Quaternion.identity); foreach (Collider overlappingObject in overlappingObjects) { Select(overlappingObject.gameObject); } }
private void leftMouseHoldRelease() { //Debug.Log("hold released"); SelectionBox sb = player.mHud.mSelectionBox; player.mSelectedList = sb.getSelection(); sb.setActive(false); }
/// <summary> /// Updates whether this <see cref="SelectionHandler{T}"/> is visible. /// </summary> private void updateVisibility() { // fix the case that only selected blueprint in current handler can show selection box. // todo : this is the temp way, might remove after official fix that. bool visible = containsSelectionInCurrentBlueprintContainer(); SelectionBox.FadeTo(visible ? 1f : 0.0f); }
protected StudioTool() { _stopwatch = Stopwatch.StartNew(); _selectionBoxes = new ConcurrentDictionary <PVInstance, SelectionBox>(); _hoverBox = new SelectionBox { Name = "SelectToolMouseOverBox", Parent = Game.CoreGui }; InputService.Service.InputBegan.Event += i => { if (IsEquipped) { OnMouseInput(i); } }; InputService.Service.InputChanged.Event += i => { if (IsEquipped) { OnMouseInput(i); } }; InputService.Service.InputEnded.Event += i => { if (IsEquipped) { OnMouseInput(i); } }; Game.Selection.Selected.Event += i => { if (IsEquipped) { OnItemSelected(i); } }; Game.Selection.Deselected.Event += i => { if (IsEquipped) { OnItemDeselected(i); } }; RunService.Service.Heartbeat.Event += elapsed => { if (_isEquipped) { OnHeartbeat(elapsed); } }; ToolManager.PrimaryItemChanged += OnPrimaryItemChanged; }
private void onPhysicsTickCallback(float dtFac) { if (ShouldDespawn || !Alive) { return; } if (World is IClientWorldAccessor || World.ElapsedMilliseconds <= msCollide + 500) { return; } if (ServerPos.Motion.X == 0 && ServerPos.Motion.Y == 0 && ServerPos.Motion.Z == 0) { return; // don't do damage if stuck in ground } Cuboidd projectileBox = SelectionBox.ToDouble().Translate(ServerPos.X, ServerPos.Y, ServerPos.Z); if (ServerPos.Motion.X < 0) { projectileBox.X1 += ServerPos.Motion.X * dtFac; } else { projectileBox.X2 += ServerPos.Motion.X * dtFac; } if (ServerPos.Motion.Y < 0) { projectileBox.Y1 += ServerPos.Motion.Y * dtFac; } else { projectileBox.Y2 += ServerPos.Motion.Y * dtFac; } if (ServerPos.Motion.Z < 0) { projectileBox.Z1 += ServerPos.Motion.Z * dtFac; } else { projectileBox.Z2 += ServerPos.Motion.Z * dtFac; } ep.WalkEntities(ServerPos.XYZ, 5f, (e) => { if (e.EntityId == this.EntityId || !e.IsInteractable || (FiredBy != null && e.EntityId == FiredBy.EntityId && World.ElapsedMilliseconds - msLaunch < 500)) { return(true); } Cuboidd eBox = e.SelectionBox.ToDouble().Translate(e.ServerPos.X, e.ServerPos.Y, e.ServerPos.Z); if (eBox.IntersectsOrTouches(projectileBox)) { impactOnEntity(e); return(false); } return(true); }); }
// Start is called before the first frame update void Start() { this.world = new World(new Vector2(300, 300)); this.player = this.world.AddPlayer(); this.selectionBox = null; this.uIManager.spawnShip += this.SpawnShip; this.uIManager.SetWorld(this.world); this.player.spawnerPosition = this.spawner.position; this.world.onShipAdded += this.OnShipCreated; }
//selection box drawing private void OnGUI() { if (dragSelecting) { // Create a rect from both mouse positions var rect = SelectionBox.GetScreenRect(playerMouse, Input.mousePosition); SelectionBox.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f)); SelectionBox.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f)); } }
protected virtual void Awake() { selectionBox = FindObjectOfType <SelectionBox>(); buttonManager = GetComponent <ButtonManager>(); levelTimer = GetComponentInChildren <LevelTimer>(); startPipe = FindObjectOfType <StartPipe>(); soundManager = FindObjectOfType <SoundManagerScript>(); currentLevelName = PlayerPrefs.GetInt("currentLevel"); }
public void RegisterComponent(Component c) { if (c is Selectable) { m_Components.Add(c as Selectable); } else if (c is SelectionBox) { m_SelectionBox = c as SelectionBox; } }
//checks if it is within bounds public bool IsWithinSelectionBounds(GameObject gameObject) { if (!dragSelecting) { return(false); } var viewportBounds = SelectionBox.GetViewportBounds(cam, playerMouse, Input.mousePosition); return(viewportBounds.Contains(cam.WorldToViewportPoint(gameObject.transform.position))); }
void OnGUI() { if (isSelecting) { // Create a rect from both mouse positions var rect = SelectionBox.GetScreenRect(mousePosition1, Input.mousePosition); //Draws a transparent rectangle in the center SelectionBox.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f)); //Draws a bordered rectangle SelectionBox.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f)); } }
private async void Image_MouseUp(object sender, MouseButtonEventArgs e) { if (!DrawSelectionBox) { return; } // Release the mouse capture and stop tracking it. DrawSelectionBox = false; OuterGrid.ReleaseMouseCapture(); // Hide the drag selection box. SelectionBox.Visibility = Visibility.Collapsed; var l = RenderImage.TranslatePoint(new Point(0, 0), OuterGrid); var mouseUpPos = e.GetPosition(OuterGrid); if (mouseUpPos.X < l.X || mouseUpPos.X > l.X + RenderImage.ActualWidth) { return; } if (!(DataContext is MandelbrotViewModel dc) || !dc.CanRender()) { return; } var topLeft = SelectionBox.TranslatePoint(new Point(0, 0), RenderImage); var downRight = topLeft; downRight.X += SelectionBox.Width; downRight.Y += SelectionBox.Height; var oldL = dc.LeftEdge; var oldR = dc.RightEdge; var oldD = dc.BottomEdge; var oldU = dc.UpperEdge; var newL = oldL + (oldR - oldL) * topLeft.X / dc.CurrentBitmap.PixelWidth * MandelbrotViewModel.DpiScale; var newR = oldL + (oldR - oldL) * downRight.X / dc.CurrentBitmap.PixelWidth * MandelbrotViewModel.DpiScale; var newU = oldU - (oldU - oldD) * topLeft.Y / dc.CurrentBitmap.PixelHeight * MandelbrotViewModel.DpiScale; var newD = oldU - (oldU - oldD) * downRight.Y / dc.CurrentBitmap.PixelHeight * MandelbrotViewModel.DpiScale; dc.LeftEdge = newL; dc.RightEdge = newR; dc.UpperEdge = newU; dc.BottomEdge = newD; await dc.ExecuteRender(); }
//------------------------------------------------------------------------------------------------- // unity methods //------------------------------------------------------------------------------------------------- void Awake() { UI.StoreSelectBoxSkin(mSelectBoxSkin); setPlayingArea(); mSideBar = GetComponentInChildren <SideBar>(); if (!mSideBar) { Debug.LogError("Can't find SideBar in HUD"); } mSelectionBox = GetComponentInChildren <SelectionBox>(); if (!mSelectionBox) { Debug.Log("Can't find SelectionBox in HUD. I disabled it."); } mPopMenu = GetComponentInChildren <PopMenu>(); if (!mPopMenu) { Debug.LogError("Can't find PopMenu in HUD"); } //mPopMenu.gameObject.SetActive(false); mExchangeMenu = GetComponentInChildren <ExchangeMenu>(); if (!mExchangeMenu) { Debug.LogError("Can't find ExchangeMenu in HUD"); } mExchangeMenu.gameObject.SetActive(false); mEquipMenu = GetComponentInChildren <EquipMenu>(); if (!mEquipMenu) { Debug.LogError("Can't find EquipMenu in HUD"); } mEquipMenu.gameObject.SetActive(false); //get the canvases List <Canvas> clist = new List <Canvas>(GetComponentsInChildren <Canvas>()); foreach (Canvas c in clist) { if (c.gameObject.name == "ScreenBarsCanvas") { mScreenBarsCanvas = c; } else if (c.gameObject.name == "CameraSpaceCanvas") { mCameraSpaceCanvas = c; } else { Debug.LogWarning("Canvas with name " + c.gameObject.name + " not recognised"); } } }
public void RemoveComponent(Component c) { if (c.Entity.HasProperty <Int32>("Layer")) { if (m_Components.Contains(c as Selectable)) { m_Components.Remove(c as Selectable); } } if (c == m_SelectionBox) { m_SelectionBox = null; } }
public bool IsWithinSelectionBounds(GameObject gameObject) //Checks to see if game object passed in is within the selection bounds { if (!isSelecting) { return(false); } var camera = Camera.main; var viewportBounds = SelectionBox.GetViewportBounds(camera, mousePosition1, Input.mousePosition); return(viewportBounds.Contains( camera.WorldToViewportPoint(gameObject.transform.position))); }
private void leftMouseHeld() { //Debug.Log("mouse held"); SelectionBox sb = player.mHud.mSelectionBox; if (sb.isActive() == false) { sb.setActive(true); sb.setTopLeftCorner(mHoldMouseStart); } else { sb.setBottonRightCorner(Input.mousePosition); } }
public GameScreen(GraphicsDevice graphicsDevice, ref Director director, Map.Map map, Camera camera, FogOfWar fow) { mDrawables = new LinkedList <IDraw>(); mUpdateables = new LinkedList <IUpdate>(); mSpatialObjects = new LinkedList <ISpatial>(); mMap = map; mCamera = camera; mFow = fow; mUistarted = false; mDirector = director; mSelBox = new SelectionBox(Color.White, mCamera, ref mDirector); AddObject(mSelBox); }
public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { base.Initialize(properties, api, InChunkIndex3d); msLaunch = World.ElapsedMilliseconds; collisionTestBox = SelectionBox.Clone().OmniGrowBy(0.05f); if (api.Side == EnumAppSide.Server) { GetBehavior <EntityBehaviorPassivePhysics>().OnPhysicsTickCallback = onPhysicsTickCallback; ep = api.ModLoader.GetModSystem <EntityPartitioning>(); } GetBehavior <EntityBehaviorPassivePhysics>().collisionYExtra = 0f; // Slightly cheap hax so that stones/arrows don't collid with fences }
/// <summary> /// Time to paint my dear ! /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RenderControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { RenderControl.MakeCurrent(); // Stop the draw timer DrawTimer.Stop(); // Clear the background Display.ClearBuffers(); Batch.Begin(); // Background texture // Background texture Rectangle dst = new Rectangle(Point.Empty, RenderControl.Size); Batch.Draw(CheckerBoard, dst, dst, Color.White); // Draw the layout CurrentLayout.Draw(Batch); // Draw the selection box SelectionBox.Draw(Batch); // If no action and mouse over an element, draw its bounding box if (SelectionBox.MouseTool == MouseTools.NoTool) { Control elem = FindElementAt(RenderControl.PointToClient(System.Windows.Forms.Control.MousePosition)); if (elem != null) { //Display.DrawRectangle(elem.Rectangle, Color.White); } } Batch.End(); RenderControl.SwapBuffers(); // Start the draw timer DrawTimer.Start(); }
// Update(): is called once per frame void Update() { RaycastHit hitRaycast; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitRaycast)) { // if: The hitpoint of the raycast is a selection box if (hitRaycast.transform.CompareTag("SelectionBox")) { // if: There is a previous selection box if (m_selectionBoxPrevious != null) { // if: The current selection box is not the same as the previous selection box if (hitRaycast.transform != m_selectionBoxPrevious.transform) { m_selectionBoxPrevious.ColorNormal(); m_selectionBoxPrevious = hitRaycast.transform.GetComponent <SelectionBox>(); m_selectionBoxPrevious.ColorHightlight(); } } else { m_selectionBoxPrevious = hitRaycast.transform.GetComponent <SelectionBox>(); m_selectionBoxPrevious.ColorHightlight(); } // if: The player clicks on one of the selection box if (Input.GetMouseButtonDown(0)) { m_selectionBoxPrevious.TransitionSelect(); UI_PlayerTurn.Instance.SelectionClick(m_selectionBoxPrevious.transform.position); } } } else { // if: There is a selection box in the previous frame (but not this) if (m_selectionBoxPrevious != null) { m_selectionBoxPrevious.ColorNormal(); m_selectionBoxPrevious = null; } } }
private bool isBoxSelected() { Vector3 selectionPointPosition; for (int x = 0; x != selectionBox.Count; x++) { selectionPointPosition = Camera.main.WorldToScreenPoint(selectionBox[x].transform.position); selectionPointPosition.y = SelectionBox.InvertMouseY(selectionPointPosition.y); if (SelectionBox.selection.Contains(selectionPointPosition)) { addToSelectionGroup(); return(true); } } return(false); }
private void selectBuildings(Vector2 start, Vector2 end) { Vector2 newStart = camera.ScreenToWorldPoint(start); Vector2 newEnd = camera.ScreenToWorldPoint(end); float width = Math.Abs(newStart.x - newEnd.x); float height = Math.Abs(newStart.y - newEnd.y); if (Math.Abs(width) > .25f || Math.Abs(height) > .25f) { GameObject selectorBox = new GameObject(); BoxCollider2D box = selectorBox.AddComponent <BoxCollider2D>(); SelectionBox select = selectorBox.AddComponent <SelectionBox>(); Rigidbody2D body = selectorBox.AddComponent <Rigidbody2D>(); select.setGameRun(this); body.gravityScale = 0; box.isTrigger = true; if (newStart.x > newEnd.x) { box.transform.position = newEnd; } else if (newStart.x <= newEnd.x) { box.transform.position = newStart; } if (newStart.y < newEnd.y) { box.transform.position = new Vector3(box.transform.position.x, newEnd.y); } else if (newStart.y >= newEnd.y) { box.transform.position = new Vector3(box.transform.position.x, newStart.y); } box.offset = new Vector3(width / 2, -height / 2); box.size = new Vector2(width, height); selectedBuildings.AddRange(select.getBuildings()); } }
public void UnselectUnit() { busyWithAllyUnit = false; if (selectedUnit.GetComponent <Unit>().canMove == false && SelectedUnit.GetComponent <Unit>().canAttack == true) //We are attacking { selectedUnit.GetComponent <Unit>().canAttack = false; ScriptLink.unitMenuControl.unitInventory.SetActive(false); } if (selectedUnit.GetComponent <Unit>().canMove == false && SelectedUnit.GetComponent <Unit>().canAttack == false) //Unit done moving { ScriptLink.mouseController.SelectedUnit.GetComponent <Unit>().DarkenUnit(); } if (selectedUnit != null) //We are moving { selectedUnit = null; ScriptLink.unitMenuControl.HideUnitMenus(); ScriptLink.tileSpreadingManager.ClearActionTiles(); SelectionBox.GetComponent <SpriteRenderer>().sprite = SelectionBoxYellow; } }
void Awake() { S = this; }