override public void Activate() { if (state != States.Active) { // Do stack handling here. If we do it in the update object we have no // clue which order things get pushed and popped and madness ensues. CommandStack.Push(commandMap); // Recreate the MyWorlds and Downloads menus since we may have added new files to them. UIGridWorldTile.SharedRenderTarget.ResetAll(); BokuGame.Unload(shared.myWorldsGrid); BokuGame.Unload(shared.downloadsGrid); shared.myWorldsGrid = shared.CreateGrid(BokuGame.Settings.MediaPath + @"Xml\Levels" + @"\" + myWorldsPath, @"*.Xml"); if (shared.myWorldsGrid != null) { // Sort and set top item as initial selection. LevelSort.SortGrid(shared.myWorldsGrid, LevelSort.SortBy.Date); shared.myWorldsGrid.SelectionIndex = new Point(0, 0); } shared.downloadsGrid = shared.CreateGrid(BokuGame.Settings.MediaPath + @"Xml\Levels" + @"\" + downloadsPath, @"*.Xml"); if (shared.downloadsGrid != null) { // Sort and set top item as initial selection. LevelSort.SortGrid(shared.downloadsGrid, LevelSort.SortBy.Date); shared.downloadsGrid.SelectionIndex = new Point(0, 0); } BokuGame.Load(shared.myWorldsGrid); BokuGame.Load(shared.downloadsGrid); pendingState = States.Active; BokuGame.objectListDirty = true; } }
public override void Update() { // Our children have input focus but we can still steal away the buttons we care about. GamePadInput pad = GamePadInput.GetGamePad1(); UIGrid curGrid = shared.GetGridFromCurTab(); bool sortNeeded = false; // Do we or our children have input focus? This is so we can steal some inputs from them. if (CommandStack.Peek() == parent.commandMap || (curGrid != null && CommandStack.Peek() == curGrid.commandMap)) { if (pad.RightShoulder.WasPressed || pad.DPadRight.WasPressed || pad.LeftStickRight.WasPressed) { parent.curTab = (Tab)(((int)parent.curTab + 1) % (int)Tab.NumTabs); #if HIDE_MISSIONS if (parent.curTab == Tab.Missions) { parent.curTab = (Tab)(((int)parent.curTab + 1) % (int)Tab.NumTabs); } #endif // Update active state. if (curGrid != null) { curGrid.Active = false; } curGrid = shared.GetGridFromCurTab(); if (curGrid != null) { curGrid.Active = true; } sortNeeded = true; } if (pad.LeftShoulder.WasPressed || pad.DPadLeft.WasPressed || pad.LeftStickLeft.WasPressed) { parent.curTab = (Tab)(((int)parent.curTab + (int)Tab.NumTabs - 1) % (int)Tab.NumTabs); #if HIDE_MISSIONS if (parent.curTab == Tab.Missions) { parent.curTab = (Tab)(((int)parent.curTab + (int)Tab.NumTabs - 1) % (int)Tab.NumTabs); } #endif // Update active state. if (curGrid != null) { curGrid.Active = false; } curGrid = shared.GetGridFromCurTab(); if (curGrid != null) { curGrid.Active = true; } sortNeeded = true; } if (pad.ButtonY.WasPressed) { shared.curSortOrder = (LevelSort.SortBy)(((int)shared.curSortOrder + 1) % (int)LevelSort.SortBy.NumSorts); sortNeeded = true; shared.bottomBarDirty = true; BokuGame.Audio.GetCue("programming add").Play(); } if (shared.curSortOrder == LevelSort.SortBy.UnSorted) { shared.curSortOrder = LevelSort.SortBy.Date; sortNeeded = true; } if (sortNeeded && curGrid != null) { LevelSort.SortGrid(curGrid, shared.curSortOrder); sortNeeded = false; } if (pad.ButtonB.WasPressed) { // Back to Main Menu. parent.Deactivate(); MainMenu.Instance.Activate(); } // Only allow deletions from Downloads or MyWorlds. if (pad.ButtonX.WasPressed && (parent.curTab == Tab.Downloads || parent.curTab == Tab.MyWorlds)) { // TODO delete file. Ask are you sure??? // Delete the file. If curGrid is null then there's no file to delete. if (curGrid != null) { UIGridWorldTile tile = (UIGridWorldTile)curGrid.SelectionElement; String filename = tile.FullPath; if (Storage.Exists(filename)) { // NOTE: It is not safe to delete the following files since they could // be shared by multiple worlds: // // - The "stuff" file // - The terrain heightmap file // - The terrain texture select file // Delete world xml file Storage.Delete(filename); // Delete thumbnail image Storage.TextureDelete(Path.GetDirectoryName(filename) + @"\" + Path.GetFileNameWithoutExtension(filename)); if (InGame.CurrentWorldId.ToString() == Path.GetFileNameWithoutExtension(filename)) { // Reset the current world information InGame.AutoSaved = false; InGame.XmlWorldData = null; } } // Remove the shared render targets from all elements. UIGridWorldTile.SharedRenderTarget.ResetAll(); // Remove the element from the grid. if (curGrid.RemoveAndCollapse(curGrid.SelectionIndex)) { // This was last element in grid. Delete it. // Pop its command map. CommandStack.Pop(curGrid.commandMap); // Remove the grid itself. switch (parent.curTab) { case Tab.Missions: shared.missionsGrid = null; break; case Tab.MyWorlds: shared.myWorldsGrid = null; break; case Tab.StarterWorlds: shared.starterWorldsGrid = null; break; case Tab.Downloads: shared.downloadsGrid = null; break; } curGrid = null; } } // end if curGrid != null } // end if 'X' was pressed. } // end of if we have input focus // If we're not shutting down, update the tabs and the child grids. if (parent.pendingState != States.Inactive) { Matrix world = Matrix.Identity; // Set the backdrop color and unfade current tab. switch (parent.curTab) { case Tab.Missions: shared.missionsTab.Selected = true; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = false; break; case Tab.MyWorlds: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = true; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = false; break; case Tab.StarterWorlds: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = true; shared.downloadsTab.Selected = false; break; case Tab.Downloads: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = true; break; } shared.missionsTab.Update(); shared.myWorldsTab.Update(); shared.starterWorldsTab.Update(); shared.downloadsTab.Update(); shared.UpdateBottomBarTexture(); shared.bottomBar.Update(); if (shared.missionsGrid != null) { shared.missionsGrid.Update(ref world); } if (shared.myWorldsGrid != null) { shared.myWorldsGrid.Update(ref world); } if (shared.starterWorldsGrid != null) { shared.starterWorldsGrid.Update(ref world); } if (shared.downloadsGrid != null) { shared.downloadsGrid.Update(ref world); } // Make sure the visible elements for the current grid have render targets. if (curGrid != null) { int focus = curGrid.SelectionIndex.Y; int start = Math.Max(focus - 3, 0); int end = Math.Min(focus + 3, curGrid.ActualDimensions.Y - 1); for (int i = start; i <= end; i++) { UIGridWorldTile tile = (UIGridWorldTile)curGrid.Get(0, i); if (tile.SRT == null) { // Get a rendertarget and assign to current tile. UIGridWorldTile.SharedRenderTarget srt = UIGridWorldTile.SharedRenderTarget.Get(curGrid); srt.Grid = curGrid; srt.Index = i; tile.SRT = srt; } } } } // end if not shutting down. } // end of Update()