コード例 #1
0
            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()
コード例 #2
0
            }   // end of Shared c'tor

            /// <summary>
            /// Creates and populates a grid with file elements based on the input path and filter.
            /// </summary>
            /// <param name="path">Path where files reside.</param>
            /// <param name="filter">Filter for valid file names.</param>
            /// <returns>The created grid.  Grids are created in the InActive state.  Will return null if no files found.</returns>
            public UIGrid CreateGrid(String path, String filter)
            {
                // Create a list of files in the path.
                String[] files = null;

                try
                {
#if !XBOX360
                    files = Storage.GetFiles(path, filter, SearchOption.TopDirectoryOnly);
#else
                    files = Storage.GetFiles(path, filter);
#endif
                }
                catch (DirectoryNotFoundException)
                {
                    // The directory will be empty, so no need to get files again
                    // we do this as a convenience and its really not needed.
                }

                UIGrid grid = null;

                if (files != null && files.Length > 0)
                {
                    List <string> filteredFiles = new List <string>();

                    // Filter AutoSave.Xml
                    for (int i = 0; i < files.Length; ++i)
                    {
                        if (files[i].ToUpper().Contains("AUTOSAVE"))
                        {
                            continue;
                        }
                        filteredFiles.Add(files[i]);
                    }

                    files = filteredFiles.ToArray();
                }

                if (files != null && files.Length > 0)
                {
                    // Create and populate grid.
                    grid = new UIGrid(parent.OnSelect, parent.OnCancel, new Point(1, files.Length), "App.LoadLevelMenu");

                    // Set up the blob for info common to all tiles.
                    UIGridWorldTile.ParamBlob blob = new UIGridWorldTile.ParamBlob();
                    blob.width            = 8.5f;
                    blob.height           = 1.25f;
                    blob.edgeSize         = 0.125f;
                    blob.selectedColor    = selectedColor;
                    blob.unselectedColor  = unselectedColor;
                    blob.textColor        = Color.White;
                    blob.dropShadowColor  = Color.Black;
                    blob.useDropShadow    = true;
                    blob.invertDropShadow = false;
                    blob.normalMapName    = @"QuarterRoundNormalMap";

                    int index = 0;
                    for (int i = 0; i < files.Length; i++)
                    {
                        DateTime dateTime = Storage.GetLastWriteTime(files[i]);

                        String filename = files[i].Substring(path.Length);
                        String fullPath = path + filename;

                        XmlWorldData xmlWorldData = XmlWorldData.Load(fullPath);

                        Texture thumb = null;
                        try
                        {
                            string thumbFilename = xmlWorldData.GetThumbFilenameWithoutExtension();
                            thumb = Storage.TextureLoad(path + thumbFilename);
                        }
                        catch { }

                        UIGridWorldTile tile = new UIGridWorldTile(
                            blob,
                            xmlWorldData.id,
                            fullPath,
                            xmlWorldData.name,
                            xmlWorldData.description,
                            xmlWorldData.creator,
                            dateTime,
                            xmlWorldData.rating,
                            thumb
                            );
                        grid.Add(tile, 0, index++);
                    }

                    grid.Spacing    = new Vector2(0.0f, 0.05f); // The first number doesn't really matter since we're doing a 1d column.
                    grid.Scrolling  = true;
                    grid.SlopOffset = true;
                }

                return(grid);
            }   // end of CreateGrid()