// constructor auto builds pie from a complete heirarchy public PieMenu(PieRecipeItem rootRecipe, Vector2 desiredLocation) { this.desiredLocation = desiredLocation; this.rootRecipe = rootRecipe; // remember this one.... this.rootDisk = new PieDisk(this, rootRecipe); this.rootDisk.ScreenPosition = desiredLocation; }
public void Update() { camera.Update(); if (Active) { bool canceled = false; activeDisk.Update(out canceled); if (canceled && CurrentDiskNo >= 0) { if (CurrentDiskNo == 0) { // we are done. no more menu Active = false; if (activeDisk != null) { activeDisk.OnCancel(); } } else { focusedDiskNo--; activeDisk.Visible = false; activeDisk.OnCancel(); activeDisk = (activeDisk.Parent as PieDisk); } //activeDisk.OnCancel(); } } // TODO check for user UI interation... }
// builds either the sing disk or, if given the complete hierarchy public void BakePie(bool isVisible) { Visible = isVisible; if (rootRecipe.subList != null && (rootRecipe.subList.Count > 0)) { // build full pie! for (int i = 0; i < rootRecipe.subList.Count; i++) { PieRecipeItem pieRecipeSlice = rootRecipe.subList[i]; PieMenuSlice slice = new PieMenuSlice(pieRecipeSlice); AddSlice(slice); if (pieRecipeSlice.subList != null && pieRecipeSlice.subList.Count > 0) { // this is a "group node" with another pie structure below PieDisk fullPie = new PieDisk(this, pieRecipeSlice); slice.subDisk = fullPie; subList.Add(fullPie); fullPie.BakePie(false); //subList[subList.Count - 1].BakePie(false); } } } else if (slices.Count == 0) { // something whent wrong.. we have nothing to build! return; } if (Visible) { BuildSlices(); } }
private void BuildAllSlices() { bool drawPie = false; Debug.Assert(rootDisk != null); if (CurrentDiskNo == 0) { drawPie = true; } activeDisk = rootDisk; // build pie slices rootDisk.BakePie(drawPie); }
private void RenderDisk(PieDisk disk, int depth) { Matrix invWorld = Matrix.Invert(disk.worldMatrix); Vector2 orthoPos = TouchInput.GetHitOrtho(disk.ScreenPosition, camera, ref invWorld, useRtCoords: false); for (int i = 0; i < disk.slices.Count; i++) { PieMenuSlice pieSlice = disk.slices[i]; RenderBastardPieSlice(pieSlice, orthoPos, disk.ScreenOffset, depth); } for (int i = 0; i < disk.slices.Count; i++) { PieMenuSlice pieSlice = disk.slices[i]; if (pieSlice.sliceType == PieSelector.SliceType.group) { PieDisk subDisk = pieSlice.subDisk; if (subDisk.Visible) { RenderDisk(subDisk, depth + 1); } } } }
private void RenderDisk(PieDisk disk) { RenderDisk(disk, 0); }
// constructor EMPTY PIE! public PieMenu(Vector2 desiredLocation) { this.desiredLocation = desiredLocation; this.rootDisk = new PieDisk(null); }
public void Update(out bool cancelRing) { sliceActivated = false; cancelRing = false; Vector2 hitUV = Vector2.Zero; Matrix invWorld = Matrix.Invert(worldMatrix); // user clicked on me? GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; // Center on screen and just high enough to clear bottom help overlay text. Vector2 screenSize = new Vector2(device.Viewport.Width, device.Viewport.Height); int sliceIndex = -1; for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchPos = touch.position; touchPos = touch.position - ScreenOffset; hitUV = TouchInput.GetHitOrtho(touchPos, camera, ref invWorld, useRtCoords: false); if (gotTouchBegan) { if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { if (WithinPieRing(hitUV)) { sliceIndex = GetSliceAtAngle(hitUV); SetFocus(sliceIndex); indexLastHoverItem = indexCurrentHoverItem; } } else if (TouchGestureManager.Get().TapGesture.WasTapped()) //cancel? { float len = hitUV.Length(); if (len > outerRadius) { cancelRing = true; sliceActivated = false; } } // is this a group slice? open its pie! if (!cancelRing && (touch.phase == TouchPhase.Ended)) { if (WithinPieRing(hitUV)) { sliceIndex = GetSliceAtAngle(hitUV); if (sliceIndex > -1) { PieDisk nextDisk = slices[sliceIndex].subDisk; if (nextDisk != null && nextDisk.SliceCount() > 0) { Object rootParent = Parent; while ((rootParent as PieMenu) == null) { rootParent = (rootParent as PieDisk).Parent; } (rootParent as PieMenu).activeDisk = nextDisk; (rootParent as PieMenu).focusedDiskNo++; nextDisk.Visible = true; nextDisk.ScreenPosition = touch.position; nextDisk.BuildSlices(); } else { indexPickedItem = sliceIndex; sliceActivated = true; } } else { Debug.Assert(false);// && "something unexpected failed here."); } } } else { sliceActivated = false; } } if (touch.phase == TouchPhase.Began) { gotTouchBegan = true; } else if (touch.phase == TouchPhase.Ended) { gotTouchBegan = false; } } if (TouchInput.TouchCount == 0) { indexCurrentHoverItem = -1; SetFocus(sliceIndex); } if ((sliceIndex == -1)) { indexCurrentHoverItem = -1; SetFocus(sliceIndex); indexLastHoverItem = -1; } }
// constructor public PieDisk(PieDisk parentPie) { parent = parentPie; }