Exemplo n.º 1
0
        internal static void Load()
        {
            TomletMain.RegisterMapper(WriteColor, ReadColor);

            FilePath = Path.Combine(Core.FolderPath, "Config.cfg");
            General  = CreateCat <cGeneral>(FilePath, nameof(General));

            bool UseDefault = true;

            if (!string.IsNullOrEmpty(General.Theme) &&
                !General.Theme.Equals("Default") &&
                !General.Theme.Equals("Random"))
            {
                try
                {
                    // To-Do: Sanatize themeName
                    General.Theme = General.Theme
                                    .Replace("\\", "")
                                    .Replace("/", "");

                    ThemePath = Path.Combine(Core.ThemesFolderPath, General.Theme);
                    if (Directory.Exists(ThemePath))
                    {
                        UseDefault = false;
                    }
                    else
                    {
                        throw new DirectoryNotFoundException(ThemePath);
                    }
                }
                catch (Exception ex) { MelonLogger.Error($"Failed to find Start Screen Theme: {ex}"); }
            }

            if (General.Theme.Equals("Random"))
            {
                ThemePath  = UIUtils.RandomFolder(Core.ThemesFolderPath);
                UseDefault = false;
            }

            if (UseDefault)
            {
                General.Theme = "Default";
                ThemePath     = Path.Combine(Core.ThemesFolderPath, General.Theme);
                if (!Directory.Exists(ThemePath))
                {
                    Directory.CreateDirectory(ThemePath);
                }
            }

            MelonLogger.Msg($"Using Start Screen Theme: \"{General.Theme}\"");

            Background   = CreateCat <cBackground>(nameof(Background), true);
            LogoImage    = CreateCat <LogoImageSettings>(nameof(LogoImage), true);
            LoadingImage = CreateCat <LoadingImageSettings>(nameof(LoadingImage), true);
            VersionText  = CreateCat <VersionTextSettings>(nameof(VersionText), true);
            ProgressText = CreateCat <ProgressTextSettings>(nameof(ProgressText), true);
            ProgressBar  = CreateCat <cProgressBar>(nameof(ProgressBar), true);

            MelonPreferences.SaveCategory <cGeneral>(nameof(General), false);
        }
Exemplo n.º 2
0
        public void should_clean_html_using_sanitizer()
        {
            string markdown = @"@@warningbox:ENTER YOUR CONTENT HERE

here is some more content

@@";

            string expectedHtml = @"<div class=""alert alert-warning"">ENTER YOUR CONTENT HERE

here is some more content

</div><br style=""clear:both""/>";

            var pagehtml = new PageHtml()
            {
                Html = markdown
            };

            var settings = new TextSettings();

            settings.CustomTokensPath = Path.Combine(Directory.GetCurrentDirectory(), "Text", "CustomTokens", "customvariables.xml");

            var customTokenParser = new CustomTokenParser(settings, _logger);
            var middleware        = new CustomTokenMiddleware(customTokenParser);

            // Act
            PageHtml actualPageHtml = middleware.Invoke(pagehtml);

            actualPageHtml.Html = actualPageHtml.Html.Replace(Environment.NewLine, "", StringComparison.Ordinal);
            expectedHtml        = expectedHtml.Replace(Environment.NewLine, "", StringComparison.Ordinal);

            // Assert
            Assert.Equal(expectedHtml, actualPageHtml.Html);
        }
Exemplo n.º 3
0
        public HtmlWhiteListProviderTests()
        {
            var logger = Substitute.For <ILogger <HtmlWhiteListProvider> >();

            _textSettings          = new TextSettings();
            _htmlWhiteListProvider = new HtmlWhiteListProvider(_textSettings, logger);
        }
Exemplo n.º 4
0
        public ImageSrcParserTests()
        {
            _textSettings = new TextSettings();
            _urlHelper    = Substitute.For <IUrlHelper>();

            _srcParser = new ImageSrcParser(_textSettings, _urlHelper);
        }
Exemplo n.º 5
0
    void Start()
    {
        var path = Path.Combine(Application.dataPath, fontDataPath);

        if (File.Exists(path))
        {
            var source = File.ReadAllText(path);

            fontData = JsonConvert.DeserializeObject <MSDFFontData>(source);

            MeshInfo info = MSDFTextMesh.GetMeshInfo("hello", fontData, true);
            Debug.Log(info.uvs.Length);
        }

        //numTextGroups = GetTextGroupCount();

        textSettings = new TextSettings[1];

        var text = "";

        for (var i = 0; i < textSettings.Length; ++i)
        {
            text            = quotes[Random.Range(0, quotes.Count)];
            textSettings[i] = new TextSettings(text, MSDFTextMesh.GetMeshInfo(text, fontData, true));
        }

        instanceMesh = CreateMesh();

        instanceMaterial = new Material(Shader.Find("Unlit/InstanceShader"));
        instanceMaterial.SetColor("_Color", Random.ColorHSV());
        instanceMaterial.SetTexture("_MainTex", msdfTexture);

        argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
        UpdateBuffers();
    }
Exemplo n.º 6
0
        public PresentationLogSource(ITaskScheduler scheduler, ILogSource source, TimeSpan maximumWaitTime, TextSettings textSettings)
            : base(scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _maximumWaitTime = maximumWaitTime;
            _textSettings    = textSettings;
            _source          = source;

            _indices = new LogBufferList(IndexedColumns);

            _array = new LogBufferArray(MaximumLineCount, Core.Columns.RawContent);
            _pendingModifications = new ConcurrentQueue <PendingModification>();
            _syncRoot             = new object();

            _source.AddListener(this, _maximumWaitTime, MaximumLineCount);
            StartTask();
        }
Exemplo n.º 7
0
        public static void CreateTextSettingsAsset()
        {
            Object target = Selection.activeObject;

            // Make sure the selection is a font file
            if (target == null)
            {
                //Debug.LogWarning("A Font file must first be selected in order to create a Font Asset.");
                return;
            }

            string targetPath = AssetDatabase.GetAssetPath(target);
            string folderPath = Path.GetDirectoryName(targetPath);
            string newAssetFilePathWithName = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/Text Settings.asset");

            //// Create new TM Font Asset.
            TextSettings textSettings = ScriptableObject.CreateInstance <TextSettings>();

            AssetDatabase.CreateAsset(textSettings, newAssetFilePathWithName);

            // Not sure if this is still necessary in newer versions of Unity.
            EditorUtility.SetDirty(textSettings);

            AssetDatabase.SaveAssets();
        }
Exemplo n.º 8
0
        protected override void UpdateWidth(ILogSource logSource, TextSettings textSettings)
        {
            int lineNumberCharacterCount;

            if (logSource != null)
            {
                var lineCount = logSource.GetProperty(TextProperties.LineCount);
                if (lineCount > 0)
                {
                    lineNumberCharacterCount = (int)Math.Ceiling(Math.Log10(lineCount));
                }
                else
                {
                    lineNumberCharacterCount = 0;
                }
            }
            else
            {
                lineNumberCharacterCount = 0;
            }

            // We always reserve space for at least 3 characters.
            _lineNumberWidth = textSettings.EstimateWidthUpperLimit(Math.Max(lineNumberCharacterCount, val2: 3));
            Width            = _lineNumberWidth + textSettings.LineNumberSpacing;
        }
Exemplo n.º 9
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            TextSettings other = obj as TextSettings;

            if ((object)other == null)
            {
                return(false);
            }

            return((fontMaterial == other.fontMaterial) &&
                   (pixelsPerUnit == other.pixelsPerUnit) &&
                   (richText == other.richText) &&
                   (alignByGeometry == other.alignByGeometry) &&
                   (font == other.font) &&
                   (textWidth == other.textWidth) &&
                   (textHeight == other.textHeight) &&
                   (fontSize == other.fontSize) &&
                   (minDynamicSize == other.minDynamicSize) &&
                   (maxDynamicSize == other.maxDynamicSize) &&
                   (anchor == other.anchor) &&
                   (alignment == other.alignment) &&
                   (color == other.color) &&
                   (bestFit == other.bestFit) &&
                   (lineSpacing == other.lineSpacing) &&
                   (horizontalWrap == other.horizontalWrap) &&
                   (verticalWrap == other.verticalWrap) &&
                   (fontStyle == other.fontStyle));
        }
Exemplo n.º 10
0
        public TextLine(LogLine logLine,
                        HashSet <LogLineIndex> hoveredIndices,
                        HashSet <LogLineIndex> selectedIndices,
                        bool colorByLevel,
                        TextSettings textSettings,
                        TextBrushes textBrushes)
        {
            if (logLine == null)
            {
                throw new ArgumentNullException(nameof(logLine));
            }
            if (hoveredIndices == null)
            {
                throw new ArgumentNullException(nameof(hoveredIndices));
            }
            if (selectedIndices == null)
            {
                throw new ArgumentNullException(nameof(selectedIndices));
            }
            if (textBrushes == null)
            {
                throw new ArgumentNullException(nameof(textBrushes));
            }

            _logLine         = logLine;
            _hoveredIndices  = hoveredIndices;
            _selectedIndices = selectedIndices;
            _segments        = new List <TextSegment>();
            _colorByLevel    = colorByLevel;
            _textSettings    = textSettings;
            _textBrushes     = textBrushes;
            _isFocused       = true;
        }
Exemplo n.º 11
0
        public void TestForegroundBrush1()
        {
            var textSettings = new TextSettings();
            var textBrushes  = new TextBrushes(new LogViewerSettings());

            var textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Fatal), _hovered, _selected, true, textSettings, textBrushes);

            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultFatal.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Error), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultError.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Warning), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultWarning.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Info), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultInfo.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Debug), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultDebug.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Trace), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultTrace.ForegroundColor);

            textLine = new TextLine(new LogLine(0, 0, "foobar", LevelFlags.Other), _hovered, _selected, true, textSettings, textBrushes);
            BrushColor(textLine.ForegroundBrush).Should().Be(LogViewerSettings.DefaultInfo.ForegroundColor);
        }
Exemplo n.º 12
0
        public string GetText(ObjectId id, TextSettings settings)
        {
            // read the file json of the text generator file
            string filePath = settings.PathTextGeneratorProvider + settings.Culture.Name + ".json";
            string generatedText;

            if (File.Exists(filePath))
            {
                var parsedObject = JSONPref.ParseJSON(System.IO.File.ReadAllText(filePath));

                // get only the translator sections in JSON
                string translator = parsedObject[CommonVariables.KEY_JSON_TRANSLATOR_FILE_TRANSLATOR].ToString();

                // deserialize the JSON section
                var obj = JsonConvert.DeserializeObject <IDictionary <string, object> >(translator);
                generatedText = (obj.ContainsKey(id.Id))? (string)obj[id.Id]:"[WARNING] The key " + id.Id + " does not exist in the translator file " + settings.Culture.Name + ".json";
            }
            else
            {
                throw new FileNotFoundException("The translator file " + filePath + " does not exist. It is required when we use the text generation from a FILE. Basically it is a translator <key, value>");
            }

            // return the text of the given id
            return(generatedText);
        }
Exemplo n.º 13
0
        /**
         * Get the description of the template
         *
         * @param preference's entity that contain the model
         * @param target's audience for the description
         *
         * @return the description (text) of the model
         */
        public IDescriptionModel GetDescriptions(PreferenceDataStructure model, TextSettings settings)
        {
            // We need to keep the attributes OrderVertical and OrderHorizontal in the interface IDescription. To sort the elements

            // if there is not language at the beginning
            if (settings.Culture == null)
            {
                // default language
                string language = CommonVariables.KEY_DEFAULT_LANGUAGE;

                // identify the language with the target audience, if there is one.
                IDictionary <string, object> audience = FindTargetAudience(settings.Audience);
                if (audience != null && audience.ContainsKey(CommonVariables.KEY_JSON_TEMPLATES_LANGUAGE_TEXT))
                {
                    language = (string)audience[CommonVariables.KEY_JSON_TEMPLATES_LANGUAGE_TEXT];
                }

                settings.Culture = new System.Globalization.CultureInfo(language, false);
            }

            List <IDescriptionModel> ListDescriptionsByRegion = new();

            // for each region
            foreach (ITemplate region in Regions)
            {
                // add the list description of the region
                ListDescriptionsByRegion.Add(region.GetDescriptions(model, settings));
            }

            // store the atributes and the list of text generated of the sequence
            IDescriptionModel descriptions = new DescriptionModelSequence(Attributes, ListDescriptionsByRegion);

            // return description model of the sequence
            return(descriptions);
        }
Exemplo n.º 14
0
        public void LoadContent(string contentPath, VideoSettings videoSettings, TextSettings textSettings, string contentId, bool startPlayback, string objective = "", Action callback = null)
        {
            callbackOnStop = callback;
            filePath       = contentPath + videoSettings.File;

            if (!File.Exists(filePath))
            {
                DebugConsole.ThrowError("No video found at: " + filePath);
                DisposeVideo(null, null);
                return;
            }

            if (currentVideo != null)
            {
                currentVideo.Dispose();
                currentVideo = null;
            }

            currentVideo = CreateVideo();
            title.Text   = textSettings != null?TextManager.Get(contentId) : string.Empty;

            textContent.Text   = textSettings != null ? textSettings.Text : string.Empty;
            objectiveText.Text = objective;

            AdjustFrames(videoSettings, textSettings);

            if (startPlayback)
            {
                Play();
            }
        }
Exemplo n.º 15
0
        protected override void UpdateWidth(ILogFile logFile, TextSettings textSettings)
        {
            var culture = CultureInfo.CurrentCulture;
            var values  = Enum.GetValues(typeof(LevelFlags)).Cast <LevelFlags>().ToList();
            var width   = values.Max(x => textSettings.EstimateWidthUpperLimit(LevelFormatter.ToString(x, culture)));

            Width = width;
        }
Exemplo n.º 16
0
        protected override void UpdateWidth(ILogFile logFile, TextSettings textSettings)
        {
            var culture      = CultureInfo.CurrentCulture;
            var maximum      = ElapsedTimePresenter.ToString(logFile.GetValue(LogFileProperties.EndTimestamp) - logFile.GetValue(LogFileProperties.StartTimestamp), culture);
            var maximumWidth = textSettings.EstimateWidthUpperLimit(maximum);

            Width = maximumWidth;
        }
Exemplo n.º 17
0
        protected override void UpdateWidth(ILogFile logFile, TextSettings textSettings)
        {
            // I guess it is fair to assume that dates have the same length, no matter which date we're formatting.
            var value   = new DateTime(1970, 1, 1, 0, 0, 0);
            var culture = CultureInfo.CurrentCulture;

            Width = textSettings.EstimateWidthUpperLimit(TimestampFormatter.ToString(value, culture));
        }
Exemplo n.º 18
0
 public void Init(TextSettings _textSettings, Action <int> _clickAction, int _code)
 {
     GetComponent <RectTransform>().localPosition = Vector2.zero;
     mTextSetting        = _textSettings;
     clickAction         = _clickAction;
     code                = _code;
     currentPointerState = PointerState.None;
 }
Exemplo n.º 19
0
        public static char Char(TextSettings settings = DefaultTextSettings)
        {
            var smallLettersRange = (min : 97, max : 122);
            var bigLettersRange   = (min : 65, max : 90);
            var numbersRange      = (min : 48, max : 57);
            var spaceRange        = (min : 32, max : 32);

            var punctuationRanges = new[]
 private void Start()
 {
     baseTextSettings = new TextSettings
     {
         fontColor = dialogTextBox.color,
         fontSize  = dialogTextBox.fontSize,
         alignment = dialogTextBox.alignment
     };
 }
Exemplo n.º 21
0
        public DataSourceCanvas(TextSettings textSettings)
        {
            _textSettings          = textSettings;
            _dataSourcesPerLogLine = new List <FormattedText>();
            _maximumWidth          = textSettings.EstimateWidthUpperLimit(MaximumDataSourceCharacters);

            ClipToBounds        = true;
            SnapsToDevicePixels = true;
        }
Exemplo n.º 22
0
 void Awake()
 {
     mText          = GetComponent <Text>();
     mTextSettings  = new TextSettings();
     mRectTransform = GetComponent <RectTransform>();
     if (mText == null)
     {
         mText = gameObject.AddComponent <Text>();
     }
 }
Exemplo n.º 23
0
        public LinkHrefParserTests()
        {
            _pageRepository = Substitute.For <IPageRepository>();
            _textSettings   = new TextSettings();
            _urlHelperMock  = Substitute.For <IUrlHelper>();
            _urlHelperMock
            .Content(Arg.Any <string>())
            .Returns <string>(callInfo => callInfo.Arg <string>());

            _linkHrefParser = new LinkHrefParser(_pageRepository, _textSettings, _urlHelperMock);
        }
Exemplo n.º 24
0
        private PreferenceTemplateConstructor CreateTemplateCatalogConstructor()
        {
            // var CurrentDirectory = Directory.GetCurrentDirectory();

            TextSettings setting = new TextSettings {
                PathTemplates         = Path.GetFullPath("./Catalogs/Company/"),
                TextGeneratorProvider = "FILE"
            };

            return(new PreferenceTemplateConstructor(setting));
        }
    private void SetUpTextSettings()
    {
        var textSettings = new TextSettings
        {
            alignment = TextAnchor.MiddleCenter,
            fontColor = Color.red,
            fontSize  = 40,
        };

        dialogController.ChangeTextParams(textSettings);
    }
Exemplo n.º 26
0
 bool IsAutoIndentation(char character)
 {
     if (TextSettings != null)
     {
         return(TextSettings.IsAutoIndentation(character));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 27
0
        protected AbstractLogColumnPresenter(ILogFileColumn <T> column, TextSettings textSettings)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            _column       = column;
            _textSettings = textSettings;
            _values       = new List <AbstractLogEntryValuePresenter>();
            ClipToBounds  = true;
        }
Exemplo n.º 28
0
 protected override FormattedText CreateFormattedText(string text,
                                                      CultureInfo culture,
                                                      TextSettings textSettings)
 {
     return(new FormattedText(text,
                              culture,
                              FlowDirection.LeftToRight,
                              textSettings.Typeface,
                              textSettings.FontSize,
                              TextBrushes.LineNumberForegroundBrush,
                              1.25));
 }
        private TextMiddlewareBuilder CreateBuilderWithoutParser()
        {
            var builder           = new TextMiddlewareBuilder(_logger);
            var settings          = new TextSettings();
            var whiteListProvider = Substitute.For <IHtmlWhiteListProvider>();

            builder.Use(new CustomTokenMiddleware(new CustomTokenParser(settings, _logger)))
            .Use(new HarmfulTagMiddleware(new HtmlSanitizerFactory(settings, whiteListProvider)))
            .Use(new TextPluginAfterParseMiddleware(new TextPluginRunner()));

            return(builder);
        }
Exemplo n.º 30
0
        public void TestBackgroundBrush3()
        {
            var textSettings = new TextSettings();
            var textBrushes  = new TextBrushes(new LogViewerSettings());

            _selected.Add(new LogLineIndex(0));

            foreach (LevelFlags level in Enum.GetValues(typeof(LevelFlags)))
            {
                var textLine = new TextLine(new LogLine(0, 0, "foobar", level), _hovered, _selected, true, textSettings, textBrushes);
                textLine.BackgroundBrush.Should().Be(TextBrushes.SelectedBackgroundBrush);
            }
        }