private void Unload(UIGridLevelElement e) { if (e != null) { e.UnloadInstanceContent(); } }
private void Unload(int index) { UIGridLevelElement e = (UIGridLevelElement)grid[index, 0]; if (e != null) { Unload(e); grid[index, 0] = null; } }
public UIGridLevelElement CreateElement(LevelMetadata level) { UIGridLevelElement tile = new UIGridLevelElement(blob); BokuGame.Load(tile, true); if (level == null) { return(tile); } tile.Level = level; return(tile); }
public void Shift(int amount) { while (amount != 0) { if (amount > 0) { // Cursor goes right, grid elements go left. UIGridLevelElement e = Get(0); for (int i = 0; i < kWidth - 1; i++) { Add(Get(i + 1), i, 0); } Add(e, kWidth - 1, 0); if (e != null) { e.Level = null; e.Dirty = true; e.SetOrientation(baseOrients[kWidth - 1]); Foley.PlayShuffle(); } --amount; } else { // Cursor goes left, grid elements go right. UIGridLevelElement e = Get(kWidth - 1); for (int i = kWidth - 1; i > 0; i--) { Add(Get(i - 1), i, 0); } Add(e, 0, 0); if (e != null) { e.Level = null; e.Dirty = true; e.SetOrientation(baseOrients[0]); Foley.PlayShuffle(); } ++amount; } if (!NoValidLevels) { Foley.PlayShuffle(); } } } // end of Shift()
} // end of Update(); /* * public void test() * { * //foo("pre test"); * for (int i = 0; i < kWidth-1; i++) * { * UIGridLevelElement ei = (UIGridLevelElement)grid[i, 0]; * for (int j = i + 1; j < kWidth; j++) * { * UIGridLevelElement ej = (UIGridLevelElement)grid[j, 0]; * * if (ei != null && ej != null && ei.uniqueNum == ej.uniqueNum) * { * // boom! * } * } * } * } * * public void foo(string label) * { * Debug.Print("===== " + label + " ====="); * for (int i = 0; i < kWidth; i++) * { * UIGridLevelElement e = (UIGridLevelElement)grid[i, 0]; * if (e == null) * { * Debug.Print(i.ToString() + " null"); * } * else * { * Debug.Print(i.ToString() + " " + e.uniqueNum.ToString() + " " + e.Level.Name); * } * } * } */ public override void UnloadContent() { for (int i = 0; i < kWidth; ++i) { UIGridLevelElement e = (UIGridLevelElement)grid[i, 0]; if (e != null) { BokuGame.Unload(e); // Remove from the INeedsDeviceReset Dictionary. e.UnloadContent(); } grid[i, 0] = null; } base.UnloadContent(); }
/// <summary> /// Loads the correct "level" data to each of the grid elements, /// </summary> /// <param name="cursor"></param> public void Reload(ILevelSetCursor cursor) { Log("Begin Reload"); for (int i = 0; i < kWidth; ++i) { LevelMetadata level = cursor[i - kFront]; UIGridLevelElement existing = Get(i); // If they already match then we're good. if (existing != null && existing.Level == level) { continue; } // If there's no element and no level, also good. if (existing == null && level == null) { continue; } if (level != null) { // Need to create a new element if (existing == null) { existing = CreateElement(level); Add(existing, i, 0); existing.SetOrientation(baseOrients[i]); } existing.Level = level; } else { // No level, so set element's ref to null. existing.Level = null; } } Log("End Reload"); }
} // end of SplitAt() /// <summary> /// Removes the element at index, collapses the rest of the list, /// and then adds the removed element back to the end of the list. /// </summary> /// <param name="index"></param> public void Remove(int index) { index += kFront; if (index >= 0 && index < ActualDimensions.X) { UIGridLevelElement e = Get(index); for (int i = index; i < kWidth - 1; i++) { Add(grid[i + 1, 0], i, 0); } Add(e, kWidth - 1, 0); if (e != null) { e.Level = null; e.Dirty = true; e.SetOrientation(baseOrients[kWidth - 1]); } } }
private bool SlideByX(float xMove) { if (Math.Abs(xMove) >= ELEMENT_SPACING_X) { // Instant jumps of greater than a single tab stop are not needed, nor supported atm. return(false); } float newSelectionXPos = currentOrients[SelectionIndex.X].position.X + xMove; // Before performing the movement, we need to find out if the movement causes a transition // either left or right. First, compute which tab stop we are currently at, and which one // we will be after this move. // We goto the new tab when we're closer to the next element than we are to our current element. float currentTab = (currentOrients[SelectionIndex.X].position.X / ELEMENT_SPACING_X); currentTab += (currentTab >= 0) ? 0.5f : -0.5f; float newTab = (newSelectionXPos / ELEMENT_SPACING_X); newTab += (newTab >= 0) ? 0.5f : -0.5f; int tabDiff = (int)newTab - (int)currentTab; Debug.Assert(Math.Abs(tabDiff) <= 1); if (tabDiff == 1) { UIGridLevelElement leftElement = Get(SelectionIndex.X - 1); if ((leftElement == null) || (leftElement.Level == null)) { // Nothing to go to. return(false); } MoveLeft(); // The result of the left move will cause all the grid elements to "Shift()" to the left by 1. // Our orientations must move accordingly to line up. for (int i = 0; i < kWidth; i++) { currentOrients[i].position.X -= ELEMENT_SPACING_X; } } else if (tabDiff == -1) { UIGridLevelElement rightElement = Get(SelectionIndex.X + 1); if ((rightElement == null) || (rightElement.Level == null)) { // Nothing to go to. return(false); } MoveRight(); // The result of the right move will cause all the elements to "Shift()" to the right by 1. // Our orientations must move accordingly to line up. for (int i = 0; i < kWidth; i++) { currentOrients[i].position.X += ELEMENT_SPACING_X; } } // Now that the grid has been modified (if necessary), perform the actual slide move and // interpolate the orientation of each element to its new values. for (int i = 0; i < kWidth; i++) { float newElementXPos = currentOrients[i].position.X + xMove; Orientation nextOrientation = null; Orientation prevOrientation = null; for (int j = 0; j < kWidth; j++) { // Find the lowest base X orientation that matches this element if (baseOrients[j].position.X >= newElementXPos) { // We know that base orientation 'j' is the next orientation, // and 'j-1' contains the previous one. nextOrientation = baseOrients[j]; if ((j - 1) >= 0) { prevOrientation = baseOrients[j - 1]; } break; } } if ((nextOrientation == null) || (prevOrientation == null)) { // This orientation is such that it is beyond the bounds covered by the base orientations. // Therefore no changes to orientation are performed other than an X translation. currentOrients[i].position.X = newElementXPos; } else { // We have a next and a previous orientation to interpolate between. Compute lerp factor float prevToNewX = newElementXPos - prevOrientation.position.X; float prevToNextX = nextOrientation.position.X - prevOrientation.position.X; float lerpFactor = prevToNewX / prevToNextX; // Discover differences between our orientations Vector3 prevToNextPos = nextOrientation.position - prevOrientation.position; float prevToNextScale = nextOrientation.scale - prevOrientation.scale; float prevToNextRotation = nextOrientation.rotation - prevOrientation.rotation; // Using the lerp factor, compute the delta values to add to our orientation. Vector3 posDelta = prevToNextPos * lerpFactor; float scaleDelta = prevToNextScale * lerpFactor; float rotationDelta = prevToNextRotation * lerpFactor; currentOrients[i].position = prevOrientation.position + posDelta; currentOrients[i].scale = prevOrientation.scale + scaleDelta; currentOrients[i].rotation = prevOrientation.rotation + rotationDelta; } } return(true); }
} // end of Refresh() public override void Update(ref Matrix parentMatrix) { focusIndex.X = kFront; focusIndex.Y = 0; UIGridLevelElement e = Get(kFront); if (e != null) { e.Selected = true; } // Update orientations. if (!isDragging) { //if (!hasResidualVelocity) //{ // // Settle a dragged grid back into fixed positions. // SettleGrid(); //} //else //{ if (hasResidualVelocity) { // Residual velocity still affecting the grid. UpdateResidualVelocity(); for (int i = 0; i < kWidth; i++) { e = Get(i); if (e != null) { e.SetOrientation(currentOrients[i]); } } } else { hasResidualVelocity = false; residualVelocity = 0.0f; // Settle elements back into base orientation. for (int i = 0; i < kWidth; i++) { e = Get(i); if (e != null) { e.TwitchOrientation(baseOrients[i]); } } } } else { for (int i = 0; i < kWidth; i++) { e = Get(i); if (e != null) { e.SetOrientation(currentOrients[i]); } } } base.Update(ref parentMatrix); } // end of Update();