コード例 #1
0
        public static bool Load()
        {
            bool result = false;

            Stream stream = null;

            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(SiteID));

                stream = Storage4.OpenRead(MyFilename, StorageSource.UserSpace);

                Instance = (SiteID)xml.Deserialize(stream);

                result = true;
            }
            catch { }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Attempts to read Locales.xml from local storage.
        /// </summary>
        private static void GetLocalesFromFile()
        {
            // DebugLog.WriteLine("GetLocalesFromFile()");
            try
            {
                // DebugLog.WriteLine("    open stream for read.");
                var localesFileStream = Storage4.OpenRead(LocalesFilePath, StorageSource.All);
                // DebugLog.WriteLine("    read.");
                PopulatesLocalesFromXmlStream(localesFileStream);
#if LOCALES_DEBUG
                LocalesDebugPrint("In GetLocalesFromFile()");
                foreach (Locale loc in Locales)
                {
                    LocalesDebugPrint(loc.ToString());
                }
#endif
            }
            catch (Exception e)
            {
                // Keep the compiler quiet when LOCALES_DEBUG not defined.
                if (e != null)
                {
                    // DebugLog.WriteException(e, "GetLocalesFromFile()");
                }
#if LOCALES_DEBUG
                LocalesDebugPrint("Exception thrown in GetLocalesFromFile()\n" + e.ToString());
#endif
            }
        }
コード例 #3
0
        /// <summary>
        /// Load current options data.
        /// </summary>
        /// <returns></returns>
        private static XmlOptionsData Load()
        {
            XmlOptionsData xmlData = null;

            Stream stream = null;

            DateTime xmlFileTime = new DateTime();//used to compare against InstallLanguage.txt

            try
            {
                // Try the real filename first.
                string xmlFileName = FileName();

                if (Storage4.FileExists(xmlFileName, StorageSource.All))
                {
                    xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All);
                    stream      = Storage4.OpenRead(xmlFileName, StorageSource.All);
                    XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData));
                    xmlData = serializer.Deserialize(stream) as XmlOptionsData;
                }
                else
                {
                    // If not there, try the back compat version.
                    xmlFileName = BackCompatFileName();

                    if (Storage4.FileExists(xmlFileName, StorageSource.All))
                    {
                        xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All);
                        stream      = Storage4.OpenRead(xmlFileName, StorageSource.All);
                        XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData));
                        xmlData = serializer.Deserialize(stream) as XmlOptionsData;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            if (stream != null)
            {
                Storage4.Close(stream);
            }

            //Check for override of language.
            if (xmlData != null && Storage4.FileExists(InstalledLanguageFileName(), StorageSource.All))
            {
                var langFileTime = Storage4.GetLastWriteTimeUtc(InstalledLanguageFileName(), StorageSource.All);
                //If InstallerLanguage.txt is later than selected language.
                if (langFileTime > xmlFileTime)
                {
                    //Update language to match newly installed version.
                    xmlData.langauge = GetInstallerLanguageOrDefault();
                    Save();
                }
            }

            return(xmlData);
        }   // end of Load()
コード例 #4
0
        public static SiteOptions Load(StorageSource sources)
        {
            XmlSerializer xml = new XmlSerializer(typeof(SiteOptions));

            Stream stream = Storage4.OpenRead(MyFilename, sources);

            SiteOptions result = (SiteOptions)xml.Deserialize(stream);

            stream.Close();

            return(result);
        }
コード例 #5
0
        public HeightMap(string filename, Point size, Vector3 scale)
        {
            this.filename = filename;
            Init(Vector2.Zero, size, scale);
            // Load the heightmap.
            Stream       fs = Storage4.OpenRead(filename, StorageSource.All);
            BinaryReader br = new BinaryReader(fs);

            Load(br);

#if NETFX_CORE
            br.Dispose();
#else
            br.Close();
#endif
            Storage4.Close(fs);
        }   // end of HeightMap c'tor
コード例 #6
0
        }   // end of XmlHelpScreensData ReadFromXml()

        private static XmlHelpScreensData Load(string filename)
        {
            // Fix up the filename with the full path.
            filename = BokuGame.Settings.MediaPath + @"Xml\" + filename;

            XmlHelpScreensData data = null;

            try
            {
                Stream stream = Storage4.OpenRead(filename, StorageSource.All);

                XmlSerializer serializer = new XmlSerializer(typeof(XmlHelpScreensData));
                data = (XmlHelpScreensData)serializer.Deserialize(stream);
                Storage4.Close(stream);
            }
            catch (Exception)
            {
                data = null;
            }

            return(data);
        } // end of XmlHelpScreensData Load()
コード例 #7
0
        static protected CommandMap Deserialize(string filepath)
        {
            string     oldPathName = Storage4.TitleLocation + MapFolder + filepath;
            string     pathName    = MapFolder + filepath;
            CommandMap profile;

//            try
            {
                Stream        stream     = Storage4.OpenRead(pathName, StorageSource.TitleSpace);
                XmlSerializer serializer = new XmlSerializer(typeof(CommandMap));
                profile = (CommandMap)serializer.Deserialize(stream);
                Storage4.Close(stream);
            }

/*
 *          catch (FileNotFoundException ex)
 *          {
 *              profile = new CommandMap();
 *              profile.Serialize(pathName);
 *          }
 */
            return(profile);
        }
コード例 #8
0
        /// <summary>
        /// Load a named resource, assuming file naming convention.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static XmlGameActor Deserialize(string name)
        {
            XmlGameActor xmlActor    = null;
            string       xmlFileName = Prefix + name + Suffix;

            if (Storage4.FileExists(xmlFileName, StorageSource.TitleSpace))
            {
                Stream        stream     = Storage4.OpenRead(xmlFileName, StorageSource.TitleSpace);
                XmlSerializer serializer = new XmlSerializer(typeof(XmlGameActor));
                xmlActor = serializer.Deserialize(stream) as XmlGameActor;
                Storage4.Close(stream);
                xmlActor.XmlFileName = xmlFileName;
                if (xmlActor != null)
                {
                    xmlActor.OnLoad();
                    allActors.Add(xmlActor);
                }
            }
            else
            {
                //Debug.Assert(false, "Missing actor file");
            }
            return(xmlActor);
        }
コード例 #9
0
ファイル: Crumb.cs プロジェクト: Yash-Codemaster/KoduGameLab
        }   // end of Init()

        #endregion

        #region Internal

        /// <summary>
        /// Loads the Crumb information.  Will first try the downloaded
        /// version.  If that fails, will then try the TitleSpace version.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="source">Where to look for the file.</param>
        /// <returns></returns>
        private static CrumbList Load(string filename, StorageSource source)
        {
            CrumbList data   = null;
            Stream    stream = null;

            // First try with StorageSoruce.All so we get the version downloaded
            // from the servers.  If that fails then get the TitleSpace version.
            try
            {
                stream = Storage4.OpenRead(filename, source);

                XmlSerializer serializer = new XmlSerializer(typeof(CrumbList));
                data = (CrumbList)serializer.Deserialize(stream);
            }
            catch (Exception e)
            {
                data = null;
                if (e != null)
                {
#if !NETFX_CORE
                    string message = e.Message;
                    if (e.InnerException != null)
                    {
                        message += e.InnerException.Message;
                    }
                    System.Windows.Forms.MessageBox.Show(
                        message,
                        "Error reading TutorialCrumbs.Xml",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Error
                        );
#endif
                }
            }
            finally
            {
                Storage4.Close(stream);
            }

            // If we don't have data.  Delete the server version of
            // the file and try loading the TitleSpace version.
            if (data == null)
            {
                // Don't delete the server version since this might actually be someone
                // trying to do a localization.
                //Storage4.Delete(filename);

                try
                {
                    stream = Storage4.OpenRead(filename, StorageSource.TitleSpace);

                    XmlSerializer serializer = new XmlSerializer(typeof(CrumbList));
                    data = (CrumbList)serializer.Deserialize(stream);
                }
                catch (Exception)
                {
                    data = null;
                }
                finally
                {
                    Storage4.Close(stream);
                }
            }

            return(data);
        }   // end of Load()
コード例 #10
0
            /// <summary>
            /// Shows the current file.  Should be called each frame with
            /// the same name until this returns true indicating that the
            /// frame has been displayed for enough time.
            /// </summary>
            /// <param name="filename"></param>
            /// <returns>True when done</returns>
            private bool ShowFile(string filename)
            {
                // New file has been sent.  Init.
                if (filename != curFilename)
                {
                    curFilename = filename;
                    curPage     = -1;
                    startTime   = 0;

                    try
                    {
                        stream = Storage4.OpenRead(BokuGame.Settings.MediaPath + filename, StorageSource.All);
                    }
                    catch
                    {
                        return(true);
                    }

                    if (stream == null)
                    {
                        return(true);
                    }

                    fileSize = (int)stream.Length;

                    numPages = fileSize / bytesPerPage;
                    if (numPages * bytesPerPage != fileSize)
                    {
                        ++numPages;
                    }
                }

                if (setStartTime)
                {
                    startTime    = Time.WallClockTotalSeconds;
                    setStartTime = false;
                }

                // If we timed out, then either load/show next
                // page or return done if on last page.
                Double curTime = Time.WallClockTotalSeconds;

                if (startTime + kPageTime < curTime)
                {
                    ++curPage;
                    if (curPage >= numPages)
                    {
                        // Done with this file.
                        Storage4.Close(stream);

                        // Allow the same file to be sent twice in a row.
                        curFilename = null;

                        return(true);
                    }
                    else
                    {
                        // Not done so send the next block.

                        setStartTime = true;
                        startTime    = curTime;

                        // Clear the data block.
                        for (int j = 0; j < blockH; j++)
                        {
                            for (int i = 0; i < blockW; i++)
                            {
                                shared.data[i + j * blockW] = 0;
                            }
                        }

                        // Load next page of data.
                        int n = fileSize - curPage * bytesPerPage;
                        if (n > bytesPerPage)
                        {
                            n = bytesPerPage;
                        }
                        for (int i = 0; i < n; i++)
                        {
                            shared.data[i] = (byte)stream.ReadByte();
                        }

                        // Put file length on line blockH - 4 starting at x = 0
                        int index = (blockH - 4) * blockW;
                        shared.data[index++] = (byte)(fileSize & 0x000000ff);
                        shared.data[index++] = (byte)((fileSize & 0x0000ff00) >> 8);
                        shared.data[index++] = (byte)((fileSize & 0x00ff0000) >> 16);
                        shared.data[index++] = (byte)((fileSize & 0xff000000) >> 24);

                        // numPages
                        shared.data[index++] = (byte)(numPages & 0x000000ff);
                        shared.data[index++] = (byte)((numPages & 0x0000ff00) >> 8);
                        shared.data[index++] = (byte)((numPages & 0x00ff0000) >> 16);
                        shared.data[index++] = (byte)((numPages & 0xff000000) >> 24);

                        // bytesPerPage
                        shared.data[index++] = (byte)(bytesPerPage & 0x000000ff);
                        shared.data[index++] = (byte)((bytesPerPage & 0x0000ff00) >> 8);
                        shared.data[index++] = (byte)((bytesPerPage & 0x00ff0000) >> 16);
                        shared.data[index++] = (byte)((bytesPerPage & 0xff000000) >> 24);

                        // curPage
                        shared.data[index++] = (byte)(curPage & 0x000000ff);
                        shared.data[index++] = (byte)((curPage & 0x0000ff00) >> 8);
                        shared.data[index++] = (byte)((curPage & 0x00ff0000) >> 16);
                        shared.data[index++] = (byte)((curPage & 0xff000000) >> 24);

                        // Put filename on line blockH - 3.
                        index = (blockH - 3) * blockW;
                        for (int i = 0; i < curFilename.Length; i++)
                        {
                            char c = curFilename[i];
                            shared.data[index++] = (byte)(c & 0x00ff);
                            shared.data[index++] = (byte)((c >> 8) & 0x00ff);
                        }

                        // Calc CRC32 for block, skipping bottom row.
                        byte[] crc = MyMath.CRC32(shared.data, blockW * (blockH - 1));

                        // Set CRC32 data in bottom line.
                        for (int i = 0; i < 4; i++)
                        {
                            shared.data[i + (blockH - 1) * blockW] = crc[i];
                        }

                        shared.dataChanged = true;
                    } // end of setting up next block
                }     // end if timed out

                return(false);
            }   // end of ShowFile()
コード例 #11
0
        public static Dictionary <string, List <string> > ReadToDictionary(string fileName, int startDepth, StorageSource source, string testName)
        {
            // DebugLog.WriteLine("ReadToDictionary2");
            // Setup our result dictionary
            var result = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase);

            // If we can't find the given file, we'll return the empty dictionary
            if (!Storage4.FileExists(fileName, source))
            {
                // DebugLog.WriteLine("    failed read, can't find file : " + fileName + " " + source.ToString());
                Debug.Assert(false, "We're trying to read a localization file that doesn't exist!");
                Localizer.ReportMissing(Path.GetFileName(fileName), "CAN'T FIND FILE!");
                return(result);
            }

#if NETFX_CORE
            XmlReader reader = null;
#else
            XmlTextReader reader = null;
#endif
            Stream stream = null;

            try
            {
                // Open our file
                // DebugLog.WriteLine("    open : " + fileName);
                stream = Storage4.OpenRead(fileName, StorageSource.All);

                // Create our xml reader
#if NETFX_CORE
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                settings.IgnoreWhitespace = true;
                settings.IgnoreComments   = true;
                reader = XmlReader.Create(stream, settings);
#else
                // DebugLog.WriteLine("    create reader");
                reader = new XmlTextReader(stream);
#endif

                // DebugLog.WriteLine("    advance reader");
                // Advance the reader to the specified start depth
                while (reader.Depth < startDepth && reader.Read())
                {
                    ;
                }

                // Create a stack that will be used as a scratch var for
                // keeping track of the current node tree.
                var nodeTree = new Stack <string>();

                var  attributeDepth = 0;     // Tracks the number of attributes we've read
                var  isEmpty        = false; // Is the element our reader is in empty?
                bool firstElement   = true;  // Is this the first element we've found?

                // DebugLog.WriteLine("    read XML");

                // Read the XML
                {
LoopStart:
                    // Push to the tree
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (!reader.IsEmptyElement || reader.HasAttributes)
                        {
                            const char trimChar = '_';
                            nodeTree.Push(reader.LocalName.TrimStart(trimChar));
                            isEmpty = reader.IsEmptyElement;
                        }
                        break;

                    case XmlNodeType.Attribute:
                        nodeTree.Push(reader.LocalName);
                        break;
                    }

                    // Grab reader value
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Attribute:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                        // Grab the element list
                        var es = nodeTree.ToArray();
                        // Change LIFO to FIFO ordering
                        Array.Reverse(es);
                        // Concat with dots
                        var key = String.Join(".", es);
                        // Get or create a dictionary value
                        List <string> val;
                        if (!result.TryGetValue(key, out val))
                        {
                            result[key] = val = new List <string>();
                        }
                        // Add localization text to dictionary
                        val.Add(reader.Value);
                        break;
                    }

                    // Pop from the tree
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        nodeTree.Pop();
                        break;

                    case XmlNodeType.Attribute:
                        nodeTree.Pop();
                        if (reader.AttributeCount == attributeDepth && isEmpty)
                        {
                            nodeTree.Pop();
                        }
                        break;
                    }

                    if (reader.IsEmptyElement)
                    {
                    }

                    // If this node has attributes or if the reader still has
                    // content at the desired depth, keep reading
                    if (reader.MoveToNextAttribute())
                    {
                        attributeDepth++;
                        goto LoopStart;
                    }
                    else if (reader.Read() && reader.Depth >= startDepth)
                    {
                        // The way this code is set up we can't tell the difference between one file and another.
                        // So, we pass in testName which should be the name of the first element in the file.
                        // If this doesn't match, assume we've got a bad file and bail.
                        if (firstElement)
                        {
                            if (!string.IsNullOrWhiteSpace(testName) && reader.Name != testName)
                            {
                                //throw new Exception();
                            }
                            firstElement = false;
                        }

                        attributeDepth = 0;
                        goto LoopStart;
                    }
                }
            }
            catch
            {
                result = null;
            }

#if NETFX_CORE
            if (reader != null)
            {
                reader.Dispose();
            }
#else
            if (reader != null)
            {
                reader.Close();
            }
#endif
            if (stream != null)
            {
                stream.Close();
            }

            return(result);
        }
コード例 #12
0
        private void InitGrid()
        {
            grid                     = new UIGrid(OnSelect, OnCancel, new Point(1, 10), "OptionsMenuGrid");
            grid.LocalMatrix         = Matrix.CreateTranslation(0.25f / 96.0f, 0.25f / 96.0f, 0.0f);
            grid.RenderEndsIn        = true;
            grid.UseMouseScrollWheel = true;

            // Create a blob of common parameters.
            UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob();
            //blob.width = 5.0f;
            //blob.height = 1.0f;
            blob.width            = 512.0f / 96.0f;
            blob.height           = blob.width / 5.0f;
            blob.edgeSize         = 0.06f;
            blob.Font             = UI2D.Shared.GetGameFont24Bold;
            blob.textColor        = Color.White;
            blob.dropShadowColor  = Color.Black;
            blob.useDropShadow    = true;
            blob.invertDropShadow = false;
            blob.unselectedColor  = new Color(new Vector3(4, 100, 90) / 255.0f);
            blob.selectedColor    = new Color(new Vector3(5, 180, 160) / 255.0f);
            blob.normalMapName    = @"Slant0Smoothed5NormalMap";
            blob.justify          = UIGridModularCheckboxElement.Justification.Left;


            //
            // Create elements here.
            //

            int index = 0;

            {
                showToolTips         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showToolTips"));
                showToolTips.OnCheck = delegate() { XmlOptionsData.ShowToolTips = true; };
                showToolTips.OnClear = delegate() { XmlOptionsData.ShowToolTips = false; };
                showToolTips.HelpID  = "ShowToolTips";
                // Add to grid.
                grid.Add(showToolTips, 0, index++);
            }

            {
                showHints         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showHints"));
                showHints.OnCheck = delegate() { XmlOptionsData.ShowHints = true; };
                showHints.OnClear = delegate() { XmlOptionsData.ShowHints = false; };
                showHints.HelpID  = "ShowHints";
                // Add to grid.
                grid.Add(showHints, 0, index++);
            }

            {
                restoreDisabledHints         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.restoreDisabledHints"));
                restoreDisabledHints.OnCheck = delegate() { XmlOptionsData.RestoreDisabledHints(); };
                restoreDisabledHints.OnClear = delegate() { restoreDisabledHints.Check = true; };
                restoreDisabledHints.HelpID  = "RestoreDisabledHints";
                // Add to grid.
                grid.Add(restoreDisabledHints, 0, index++);
            }

            {
                showFramerate         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showFramerate"));
                showFramerate.OnCheck = delegate() { XmlOptionsData.ShowFramerate = true; };
                showFramerate.OnClear = delegate() { XmlOptionsData.ShowFramerate = false; };
                showFramerate.HelpID  = "ShowFramerate";
                // Add to grid.
                grid.Add(showFramerate, 0, index++);
            }

            /*
             * {
             *  helpLevel = new UIGridModularRadioBoxElement(blob, Strings.Localize("optionsParams.helpLevel"));
             *  helpLevel.AddText(Strings.Localize("optionsParams.lowHelp"));
             *  helpLevel.AddText(Strings.Localize("optionsParams.midHelp"));
             *  helpLevel.AddText(Strings.Localize("optionsParams.highHelp"));
             *  helpLevel.CurIndex = XmlOptionsData.HelpLevel;
             *  helpLevel.OnChange = delegate(UIGridModularRadioBoxElement.ListEntry entry)
             *  {
             *      XmlOptionsData.HelpLevel = helpLevel.CurIndex;
             *  };
             *  helpLevel.HelpID = "HelpOverlayAmount";
             *  // Add to grid.
             *  grid.Add(helpLevel, 0, index++);
             * }
             */

            {
                float oldWidth = blob.width;
                blob.width += 0.5f;
                language    = new UIGridModularRadioBoxElement(blob, Strings.Localize("optionsParams.language"));
                blob.width  = oldWidth;
                IEnumerable <LocalizationResourceManager.SupportedLanguage> langs = LocalizationResourceManager.SupportedLanguages;

                // Copy to a List so we can sort.
                List <LocalizationResourceManager.SupportedLanguage> languageList = new List <LocalizationResourceManager.SupportedLanguage>();
                foreach (LocalizationResourceManager.SupportedLanguage lang in langs)
                {
                    languageList.Add(lang);
                }
                languageList.Sort(LanguageSortComp);

                // Add the sorted languages to the UI element.
                foreach (LocalizationResourceManager.SupportedLanguage lang in languageList)
                {
#if NETFX_CORE
                    if (lang.NameInEnglish.Equals("hebrew", StringComparison.OrdinalIgnoreCase))
#else
                    if (lang.NameInEnglish.Equals("hebrew", StringComparison.InvariantCultureIgnoreCase))
#endif
                    {
                        // RtoL code seems to have trouble with NSM characters 0x05b0 and 0x05b4.
                        // Strip them out.
                        string native = "";
                        char[] a      = lang.NameInNative.ToCharArray();
                        foreach (char c in a)
                        {
                            if (c != 0x05b0 && c != 0x05b4)
                            {
                                native += c;
                            }
                        }

                        language.AddText(lang.NameInEnglish + " : " + native, lang.Language);
                    }
                    else
                    {
                        language.AddText(lang.NameInEnglish + " : " + lang.NameInNative, lang.Language);
                    }
                }
                language.NumColumns = 2;
                language.SetValueByKey(XmlOptionsData.Language);

                language.OnChange = delegate(UIGridModularRadioBoxElement.ListEntry entry)
                {
                    // Note we can only get away with this since the language won't change for real until restart.
                    XmlOptionsData.Language = language.CurKey;
                };
                language.HelpID = "Language";
                // Add to grid.
                grid.Add(language, 0, index++);
            }

            {
                modalToolMenu         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.ModalToolMenu"));
                modalToolMenu.OnCheck = delegate() { XmlOptionsData.ModalToolMenu = true; };
                modalToolMenu.OnClear = delegate() { XmlOptionsData.ModalToolMenu = false; };
                modalToolMenu.HelpID  = "ModalToolMenu";
                // Add to grid.
                grid.Add(modalToolMenu, 0, index++);
            }

            #region Stick Inverting
            {
                invertYAxis         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertYAxis"));
                invertYAxis.OnCheck = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertYAxis(lastTouched, true);
                };
                invertYAxis.OnClear = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertYAxis(lastTouched, false);
                };
                invertYAxis.HelpID = "InvertYAxis";
                grid.Add(invertYAxis, 0, index++);
            }

            {
                invertXAxis         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertXAxis"));
                invertXAxis.OnCheck = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertXAxis(lastTouched, true);
                };
                invertXAxis.OnClear = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertXAxis(lastTouched, false);
                };
                invertXAxis.HelpID = "InvertXAxis";
                grid.Add(invertXAxis, 0, index++);
            }
            {
                invertCamY         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertCamY"));
                invertCamY.OnCheck = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertCamY(lastTouched, true);
                };
                invertCamY.OnClear = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertCamY(lastTouched, false);
                };
                invertCamY.HelpID = "InvertCamY";
                grid.Add(invertCamY, 0, index++);
            }

            {
                invertCamX         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.invertCamX"));
                invertCamX.OnCheck = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertCamX(lastTouched, true);
                };
                invertCamX.OnClear = delegate()
                {
                    PlayerIndex lastTouched = GamePadInput.RealToLogical(GamePadInput.LastTouched);
                    GamePadInput.SetInvertCamX(lastTouched, false);
                };
                invertCamX.HelpID = "InvertCamX";
                grid.Add(invertCamX, 0, index++);
            }
            #endregion Stick Inverting

            #region Terrain Edit Speed
            {
                // Restore default.
                blob.height                        = blob.width / 5.0f;
                terrainSpeed                       = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.terrainSpeed"));
                terrainSpeed.MinValue              = 0.25f;
                terrainSpeed.MaxValue              = 4.0f;
                terrainSpeed.IncrementByAmount     = 0.25f;
                terrainSpeed.NumberOfDecimalPlaces = 2;
                terrainSpeed.OnChange              = delegate(float speed) { XmlOptionsData.TerrainSpeed = speed; };
                terrainSpeed.HelpID                = "TerrainSpeed";
                grid.Add(terrainSpeed, 0, index++);
            }
            #endregion Terrain Edit Speed

            #region Audio Volumes
            {
                // Restore default.
                blob.height                    = blob.width / 5.0f;
                uiVolume                       = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.uiVolume"));
                uiVolume.MinValue              = 0.0f;
                uiVolume.MaxValue              = 100.0f;
                uiVolume.IncrementByAmount     = 5.0f;
                uiVolume.NumberOfDecimalPlaces = 0;
                uiVolume.OnChange              = delegate(float volume) { XmlOptionsData.UIVolume = volume * 0.01f; };
                uiVolume.HelpID                = "UIVolume";
                grid.Add(uiVolume, 0, index++);
            }
            {
                foleyVolume                       = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.foleyVolume"));
                foleyVolume.MinValue              = 0.0f;
                foleyVolume.MaxValue              = 100.0f;
                foleyVolume.IncrementByAmount     = 5.0f;
                foleyVolume.NumberOfDecimalPlaces = 0;
                foleyVolume.OnChange              = delegate(float volume) { XmlOptionsData.FoleyVolume = volume * 0.01f; };
                foleyVolume.HelpID                = "EffectsVolume";
                grid.Add(foleyVolume, 0, index++);
            }
            {
                musicVolume                       = new UIGridModularFloatSliderElement(blob, Strings.Localize("optionsParams.musicVolume"));
                musicVolume.MinValue              = 0.0f;
                musicVolume.MaxValue              = 100.0f;
                musicVolume.IncrementByAmount     = 5.0f;
                musicVolume.NumberOfDecimalPlaces = 0;
                musicVolume.OnChange              = delegate(float volume) { XmlOptionsData.MusicVolume = volume * 0.01f; };
                musicVolume.HelpID                = "MusicVolume";
                grid.Add(musicVolume, 0, index++);
            }
            #endregion Audio Volumes

            #region Privacy Settings
            {
                checkForUpdates         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.checkForUpdates"));
                checkForUpdates.OnCheck = delegate() { XmlOptionsData.CheckForUpdates = true; };
                checkForUpdates.OnClear = delegate() { XmlOptionsData.CheckForUpdates = false; };
                checkForUpdates.HelpID  = "CheckForUpdates";
                // Add to grid.
                grid.Add(checkForUpdates, 0, index++);
            }
            {
                sendInstrumentation         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.sendInstrumentation"));
                sendInstrumentation.OnCheck = delegate() { XmlOptionsData.SendInstrumentation = true; };
                sendInstrumentation.OnClear = delegate() { XmlOptionsData.SendInstrumentation = false; };
                sendInstrumentation.HelpID  = "SendInstrumentation";
                // Add to grid.
                grid.Add(sendInstrumentation, 0, index++);
            }
            {
                UIGridModularButtonElement.UIButtonElementEvent onA = delegate()
                {
                    Stream       stream  = Storage4.OpenRead(BokuGame.Settings.MediaPath + @"Text\Kodu_Game_Lab_Code_of_Conduct.txt", StorageSource.TitleSpace);
                    StreamReader reader  = new StreamReader(stream);
                    string       content = reader.ReadToEnd();
                    reader.Close();
                    InGame.inGame.shared.scrollableTextDisplay.Activate(null, content, UIGridElement.Justification.Left, false, false, false);
                };

                showCodeOfConduct        = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewCodeOfConduct"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null);
                showCodeOfConduct.HelpID = "ShowCodeOfConduct";
                grid.Add(showCodeOfConduct, 0, index++);
            }
            {
                UIGridModularButtonElement.UIButtonElementEvent onA = delegate()
                {
#if NETFX_CORE
                    Launcher.LaunchUriAsync(new Uri(Program2.SiteOptions.KGLUrl + @"/Link/PrivacyStatement"));
#else
                    Process.Start(Program2.SiteOptions.KGLUrl + @"/Link/PrivacyStatement");
#endif
                };

                showPrivacyStatement        = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewPrivacyStatement"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null);
                showPrivacyStatement.HelpID = "ShowPrivacyStatement";
                grid.Add(showPrivacyStatement, 0, index++);
            }
            {
                UIGridModularButtonElement.UIButtonElementEvent onA = delegate()
                {
                    Stream       stream  = Storage4.OpenRead(BokuGame.Settings.MediaPath + @"Text\Kodu_Game_Lab_EULA.txt", StorageSource.TitleSpace);
                    StreamReader reader  = new StreamReader(stream);
                    string       content = reader.ReadToEnd();
                    reader.Close();
                    InGame.inGame.shared.scrollableTextDisplay.Activate(null, content, UIGridElement.Justification.Left, false, false, false);
                };

                showEULA        = new UIGridModularButtonElement(blob, Strings.Localize("optionsParams.viewEULA"), Strings.Localize("optionsParams.viewButtonLabel"), onA, null, null);
                showEULA.HelpID = "ShowEULA";
                grid.Add(showEULA, 0, index++);
            }
            #endregion

            #region ShowIntroVideo
            {
                showIntroVideo         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showIntroVideo"));
                showIntroVideo.OnCheck = delegate() { XmlOptionsData.ShowIntroVideo = true; };
                showIntroVideo.OnClear = delegate() { XmlOptionsData.ShowIntroVideo = false; };
                showIntroVideo.HelpID  = "ShowIntroVideo";
                // Add to grid.
                grid.Add(showIntroVideo, 0, index++);
            }
            #endregion

            #region ShowTutorialDebug
            {
                showTutorialDebug         = new UIGridModularCheckboxElement(blob, Strings.Localize("optionsParams.showTutorialDebug"));
                showTutorialDebug.OnCheck = delegate() { XmlOptionsData.ShowTutorialDebug = true; };
                showTutorialDebug.OnClear = delegate() { XmlOptionsData.ShowTutorialDebug = false; };
                showTutorialDebug.HelpID  = "ShowTutorialDebug";
                // Add to grid.
                grid.Add(showTutorialDebug, 0, index++);
            }
            #endregion


            showVersion        = new UIGridModularButtonElement(blob, Strings.Localize("shareHub.appName") + " (" + Program2.ThisVersion.ToString() + ", " + Program2.SiteOptions.Product + ")", null, null, null, null);
            showVersion.HelpID = "Version";
            grid.Add(showVersion, 0, index++);


            //
            // Set grid properties.
            //
            grid.Spacing     = new Vector2(0.0f, 0.1f); // The first number doesn't really matter since we're doing a 1d column.
            grid.Scrolling   = true;
            grid.Wrap        = false;
            grid.LocalMatrix = Matrix.Identity;

            // Loop over al the elements in the grid.  For any that have
            // help, set the flag so they display Y button for help.
            for (int i = 0; i < grid.ActualDimensions.Y; i++)
            {
                UIGridElement e        = grid.Get(0, i);
                string        helpID   = e.HelpID;
                string        helpText = TweakScreenHelp.GetHelp(helpID);
                if (helpText != null)
                {
                    e.ShowHelpButton = true;
                }
            }
        }   // end of InitGrid