using Noesis; using System.Collections.Generic; using Vector2 = UnityEngine.Vector2; using Grid = Noesis.Grid; namespace StellarConquest.Presentation.Unity.UI { public partial class ViewboxGridControl : Grid { public static readonly DependencyProperty ScalingEnabledProperty = DependencyProperty.Register("ScalingEnabled", typeof(bool), typeof(ViewboxGridControl), new PropertyMetadata(true)); public static readonly List AspectRatios = new List() { new Vector2(7680, 4320), // 0 new Vector2(3840, 2160), // 1 new Vector2(2560, 1440), // 2 new Vector2(1920, 1080), // 3 new Vector2(1600, 900), // 4 new Vector2(1366, 768), // 5 new Vector2(1280, 720), // 6 new Vector2(1152, 648), // 7 new Vector2(1024, 576), // 8 }; public static int DefaultAspectRatioIndex = 5; public ViewboxGridControl() { Loaded += (sender, e) => { if (PlayerPreferences.Instance != null) SetScale(PlayerPreferences.Instance.UserInterfaceSize); else SetScale(DefaultAspectRatioIndex); }; } public void SetScale(int index) { if (ScalingEnabled) { Width = AspectRatios[index].x; Height = AspectRatios[index].y; } } public Vector2 GetViewboxScale() { Viewbox viewbox = this.Parent as Viewbox; if (viewbox == null) return new Vector2(1, 1); float x = viewbox.ActualWidth / ActualWidth; float y = viewbox.ActualHeight / ActualHeight; return new Vector2(x, y); } public bool ScalingEnabled { get { return (bool)GetValue(ScalingEnabledProperty); } set { SetValue(ScalingEnabledProperty, value); } } } }