From 7bb34a4b51a62726bd0db41ee6436337c81636a3 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Sun, 16 Mar 2025 12:45:09 +0100 Subject: [PATCH] first full rendering sample of pop% cap with styling --- Stars Assistant/Assets/DataGridStyles.axaml | 26 ++++++++ Stars Assistant/Assets/GridCellStyles.axaml | 13 ---- .../DataGridColumn/PopulationCapacity.cs | 19 ------ .../ViewModels/PlayerPlanetViewModel.cs | 3 +- Stars Assistant/Views/BuColView.axaml | 31 +++++++--- .../Views/Helpers/PlanetStyleConverters.cs | 62 +++++++++++++++++++ 6 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 Stars Assistant/Assets/DataGridStyles.axaml delete mode 100644 Stars Assistant/Assets/GridCellStyles.axaml delete mode 100644 Stars Assistant/ViewModels/DataGridColumn/PopulationCapacity.cs create mode 100644 Stars Assistant/Views/Helpers/PlanetStyleConverters.cs diff --git a/Stars Assistant/Assets/DataGridStyles.axaml b/Stars Assistant/Assets/DataGridStyles.axaml new file mode 100644 index 0000000..2ff96aa --- /dev/null +++ b/Stars Assistant/Assets/DataGridStyles.axaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + diff --git a/Stars Assistant/Assets/GridCellStyles.axaml b/Stars Assistant/Assets/GridCellStyles.axaml deleted file mode 100644 index 55e7160..0000000 --- a/Stars Assistant/Assets/GridCellStyles.axaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - diff --git a/Stars Assistant/ViewModels/DataGridColumn/PopulationCapacity.cs b/Stars Assistant/ViewModels/DataGridColumn/PopulationCapacity.cs deleted file mode 100644 index da3e021..0000000 --- a/Stars Assistant/ViewModels/DataGridColumn/PopulationCapacity.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ReactiveUI.SourceGenerators; -using Avalonia.Media; - -namespace StarsAssistant.ViewModels.DataGridColumn; - -public partial class PopulationCapacity(int value) : ViewModelBase -{ - [Reactive] private int _value = value; - - public IBrush BackgroundColor => _value switch - { - < 25 => Brushes.Khaki, - <= 33 => Brushes.PaleGreen, - <= 50 => Brushes.Khaki, - > 100 => Brushes.LightCoral, - > 99 => Brushes.LightGray, - _ => Brushes.White - }; -} \ No newline at end of file diff --git a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs index 990883e..203fad1 100644 --- a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs @@ -189,8 +189,7 @@ public partial class PlayerPlanetViewModel : ViewModelBase public int MaxTerraforming => Planet.MaxTerraforming ?? 0; - // public int CapacityPercent => Planet.CapacityPercent ?? 0; - public DataGridColumn.PopulationCapacity CapacityPercent => new(Planet.CapacityPercent ?? 0); + public int CapacityPercent => Planet.CapacityPercent ?? 0; public int ScanRange => Planet.ScanRange ?? 0; diff --git a/Stars Assistant/Views/BuColView.axaml b/Stars Assistant/Views/BuColView.axaml index 6fc78fb..82248e5 100644 --- a/Stars Assistant/Views/BuColView.axaml +++ b/Stars Assistant/Views/BuColView.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:StarsAssistant.ViewModels" + xmlns:helpers="using:StarsAssistant.Views.Helpers" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="200" x:Class="StarsAssistant.Views.BuColView" x:DataType="vm:BuColViewModel"> @@ -16,15 +17,9 @@ RowHeight="24" FontSize="12" BorderThickness="1" BorderBrush="Gray" > - - - - - - - + @@ -32,7 +27,27 @@ - + + + + + + + + + + + diff --git a/Stars Assistant/Views/Helpers/PlanetStyleConverters.cs b/Stars Assistant/Views/Helpers/PlanetStyleConverters.cs new file mode 100644 index 0000000..39d7e6d --- /dev/null +++ b/Stars Assistant/Views/Helpers/PlanetStyleConverters.cs @@ -0,0 +1,62 @@ +using Avalonia.Data.Converters; + +namespace StarsAssistant.Views.Helpers; + +public static class PlanetStyleConverters +{ + /// + /// Check, if the planet pop percentage is in the warning range + /// + public static FuncValueConverter PopulationPercentWarning { get; } + = new((value) => + { + return value switch + { + null => false, + > 0 and < 25 or > 33 and <= 50 => true, + _ => false + }; + }); + + /// + /// Check, if the planet pop percentage is in a bad range (overpop) + /// + public static FuncValueConverter PopulationPercentBad { get; } + = new((value) => + { + return value switch + { + null => false, + > 100 => true, + _ => false + }; + }); + + /// + /// Check, if the planet pop percentage is in a good range (growth-wise) + /// + public static FuncValueConverter PopulationPercentGood { get; } + = new((value) => + { + return value switch + { + null => false, + >= 25 and <= 33 => true, + _ => false + }; + }); + + /// + /// Check, if the planet pop percentage is not relevant (100%) + /// + public static FuncValueConverter PopulationPercentInactive { get; } + = new((value) => + { + return value switch + { + null => false, + > 99 and <= 100 => true, + _ => false + }; + }); +} \ No newline at end of file