< Summary

Class:MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts.ResolutionSizeControlController
Assembly:SettingsPanelHUDDesktop
File(s):/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ResolutionSizeControlController.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:77
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ResolutionSizeControlController()0%2100%
Initialize()0%2100%
SetupAvailableResolutions()0%6200%
SetupLabels()0%6200%
GetLabel(...)0%2100%
GetStoredValue()0%2100%
GetAspectRatio(...)0%6200%
UpdateSetting(...)0%2100%

File(s)

/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ResolutionSizeControlController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using MainScripts.DCL.Controllers.SettingsDesktop;
 5using MainScripts.DCL.Controllers.SettingsDesktop.SettingsControllers;
 6using MainScripts.DCL.ScriptableObjectsDesktop;
 7using UnityEngine;
 8
 9namespace MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts
 10{
 11    [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Resolution Size",
 12        fileName = "ResolutionSizeControlController")]
 13    public class ResolutionSizeControlController : SpinBoxSettingsControlControllerDesktop
 14    {
 015        private List<Resolution> possibleResolutions = new List<Resolution>();
 16
 17        public override void Initialize()
 18        {
 019            SetupAvailableResolutions();
 020            base.Initialize();
 021            SetupLabels();
 022        }
 23
 24        // Filter the smallest resolutions as no one will ever use them
 25        private void SetupAvailableResolutions()
 26        {
 027            possibleResolutions.AddRange(ScreenResolutionUtils.Resolutions.SkipWhile(r => r.width <= 1024));
 028        }
 29
 30        private void SetupLabels()
 31        {
 032            var length = possibleResolutions.Count;
 033            var resolutionLabels = new string[length];
 034            for (var i = 0; i < length; i++)
 35            {
 036                var resolution = possibleResolutions[i];
 37
 38                // by design we want the list to be inverted so the biggest resolutions stay on top
 39                // our resolutionSizeIndex is based on this decision
 040                resolutionLabels[length - 1 - i] = GetLabel(resolution);
 41            }
 42
 043            RaiseOnOverrideIndicatorLabel(resolutionLabels);
 044        }
 45
 46        private static string GetLabel(Resolution resolution)
 47        {
 048            return $"{resolution.width}x{resolution.height} {GetAspectRatio(resolution.width, resolution.height)} {resol
 49        }
 50
 51        public override object GetStoredValue()
 52        {
 053            return currentDisplaySettings.resolutionSizeIndex;
 54        }
 55
 56        private static string GetAspectRatio(int width, int height)
 57        {
 58            int rest;
 059            int tempWidth = width;
 060            int tempHeight = height;
 061            while (height != 0)
 62            {
 063                rest = width % height;
 064                width = height;
 065                height = rest;
 66            }
 067            return (tempWidth / width) + ":" + (tempHeight / width);
 68        }
 69
 70        public override void UpdateSetting(object newValue)
 71        {
 072            var value = (int)newValue;
 073            currentDisplaySettings.resolutionSizeIndex = value;
 074            ScreenResolutionUtils.Apply(currentDisplaySettings);
 075        }
 76    }
 77}