Exemple #1
0
        private void DrawLanguageSelectionPrompt(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            if (languageSelectionFont == null)
            {
                languageSelectionFont = new ScalableFont("Content/Fonts/NotoSans/NotoSans-Bold.ttf",
                                                         (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice);
            }
            if (languageSelectionFontCJK == null)
            {
                languageSelectionFontCJK = new ScalableFont("Content/Fonts/NotoSans/NotoSansCJKsc-Bold.otf",
                                                            (uint)(30 * (GameMain.GraphicsHeight / 1080.0f)), graphicsDevice, dynamicLoading: true);
            }
            if (languageSelectionCursor == null)
            {
                languageSelectionCursor = new Sprite("Content/UI/cursor.png", Vector2.Zero);
            }

            Vector2 textPos     = new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight * 0.3f);
            Vector2 textSpacing = new Vector2(0.0f, (GameMain.GraphicsHeight * 0.5f) / TextManager.AvailableLanguages.Count());

            foreach (string language in TextManager.AvailableLanguages)
            {
                string localizedLanguageName = TextManager.GetTranslatedLanguageName(language);
                var    font = TextManager.IsCJK(localizedLanguageName) ? languageSelectionFontCJK : languageSelectionFont;

                Vector2 textSize = font.MeasureString(localizedLanguageName);
                bool    hover    =
                    Math.Abs(PlayerInput.MousePosition.X - textPos.X) < textSize.X / 2 &&
                    Math.Abs(PlayerInput.MousePosition.Y - textPos.Y) < textSpacing.Y / 2;

                font.DrawString(spriteBatch, localizedLanguageName, textPos - textSize / 2,
                                hover ? Color.White : Color.White * 0.6f);
                if (hover && PlayerInput.PrimaryMouseButtonClicked())
                {
                    GameMain.Config.Language = language;
                    //reload tip in the selected language
                    selectedTip = TextManager.Get("LoadingScreenTip", true);
                    GameMain.Config.SetDefaultBindings(legacy: false);
                    GameMain.Config.CheckBindings(useDefaults: true);
                    WaitForLanguageSelection = false;
                    languageSelectionFont?.Dispose(); languageSelectionFont       = null;
                    languageSelectionFontCJK?.Dispose(); languageSelectionFontCJK = null;
                    break;
                }

                textPos += textSpacing;
            }

            languageSelectionCursor.Draw(spriteBatch, PlayerInput.LatestMousePosition, scale: 0.5f);
        }